December 04, 2020, 04:43:54 am

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Frags example.

Started by Ionic Wind Support Team, May 17, 2006, 05:11:19 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Protected

Yes, Java is the slowest language I've ever used. I never compared it with IBasic standard, but it probably ends up being slower. That's why Aurora is the perfect language for what I want to do!

I'm brainwashed against C++, teachers in my university don't like it. Too many weird combinations of symbols, they say ;P I think they'd make us write everything in assembly if they could, but since they can't, it ends up being mostly C!

Mike Stefanik

Quote from: Protected on May 20, 2006, 06:46:31 pm
I'm brainwashed against C++, teachers in my university don't like it.


I've heard of some universities that don't like to teach C++ because its not a "pure" OOP language and prefer to teach using Smalltalk, or that it's not "safe" and think it's better to teach Java or C#. But to not teach it because of it's syntax? Ouch. At least they do teach C, and while assembly language may seem archaic, it's important to at least have a fundamental understanding of things like registers, stack frames, pointers, etc. With the advent of Java and C#, there's going to be a generation of programmers coming up that don't really understand how pointers work, what heaps are and how to manage memory and how the core Windows operating system actually functions. They see a world of classes and object references, with virtual methods that get magically invoked without any real fundamental understanding of what's going on inside the "black box" so to speak. I'm not sure that's such a good thing.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Protected

Quote from: Mike Stefanik on May 20, 2006, 09:56:09 pm
With the advent of Java and C#, there's going to be a generation of programmers coming up that don't really understand how pointers work, what heaps are and how to manage memory and how the core Windows operating system actually functions. They see a world of classes and object references, with virtual methods that get magically invoked without any real fundamental understanding of what's going on inside the "black box" so to speak. I'm not sure that's such a good thing.


Well, we computer engineers (in my university) are required to learn how computers work from the transistor and up. Not only we studied circuits, processors and memory, but we also had to write a pong game in assembly (in a simulator) and our first class on algorithms (sorting and search) and data structures was in C. We also learned synchronization and sockets in C, and right now we're writing a compiler. Expect me to bug you partner developers when the conflicts in yacc become too frustrating  ;D I still don't know how to properly write the shift/reduce/goto table of LR grammars on paper... Fortunately it will only come for my second test which is in July 1. Last year Paul gave me some valuable tips to solve the conflicts with the if and while blocks and we managed to pass the project with 15/20 (and that's without the compiler having all the required functionality :P). Unfortunately I failed the theoretical exam.

We use Java and LISP and such in classes about programming paradigms, design patterns or higher level programming, like 3D object rendering and AI.

EDIT: On the other hand, we learn NOTHING of Windows. It's all linux there  ::)


Parker

If you're doing compilers, you may want to (if you don't already have it) get the dragon book. There are some cheap (much less than $110) copies there, I got a new one for $30 a couple weeks ago.

I have to say that after using pointers and having to worry about freeing memory, it is kind of nice to program in java or C# where I can just say x=new X(); and not track down where I don't need it anymore, but I really think that everyone should learn C++ or C first, or any other language that requires you to delete/free the memory and work with actual pointers. Even though I said it's nice, I really prefer working in Aurora and C++ over java and C#. One thing I really hate is the forcing you to use classes when a procedural implementation would do just fine.

Protected

The Dragon book is supposed to be our only reliable book source (although it's said to be 'heavy'), but I never found it here in Portugal (it's always sold out) and I never bothered to order it yet. My teacher is very good, so I could make it with just the theoretical lessons if I hadn't missed two or three of them for... valid reasons ;P There is a portuguese book we can use but the teacher continuously reminds us of the opinion he has of it - Basically, it's a complete piece of crap, it seems the author of the book didn't really know what he was writing about, so I don't want to risk it...

kryton9

August 08, 2006, 08:11:17 pm #30 Last Edit: August 08, 2006, 08:20:13 pm by kryton9
I look at the frag's example a lot and am using it heavily in my studies of Aurora, but was confused by it also. Anyways, today I got it to where I wanted it, to use it as a base for some cooler things with it in the near future.
Thought it might help others in the same boat and wanting to play with this stuff, so here is the base code:
Code Select
/* Compile as Windows
The frags demo.ÂÃ,  Hold down the left mouse button and move around to generate the fragments.
Press ESC to exit.
For Aurora Alpha 3 or greater
*/


class Frags
{
declare Frags();
declare _Frags();
declare CreateFrags(int mx,int my);
declare UpdateFrags();
declare RenderFrags();
declare Run(),int;
//variable of the app
C2DScreen screen;
C2DSurface *back;
CPointerList pListOfFrags;
void *pos;
float gravity;
int ptx,pty,speed;
int width;
int height;
int intensity;
struct FragsStruct
{
float x;
float y;
float xs;
float ys;
int r;
int g;
int b;
}
FragsStruct *f;
}

Frags::Frags()
{
gravity = .1f;
temp = 0;
ptx = 0;
pty = 0;
done=0;
speed = 0;
width = 640;
height = 480;
ÂÃ,  ÂÃ,  intensity = 20;
//create the linked list of frags.
pListOfFrags.Create();
}

Frags::_Frags()
{
pListOfFrags.RemoveAll(true);
}

Frags::Run(),int
{
//Create the screen
if(screen.CreateWindowed(0,0,width,height,AWS_VISIBLE | AWS_POPUP ,0,"test",0) < 0)
{
MessageBox(0,"Couldn't creat the screen..sorry","Error");
return false;
}
//turn off the cursor
screen.SetCursor(CS_CUSTOM,0);
//get a pointer to the back buffer
back = screen.GetBack();
do
{
back->Fill(0);
UpdateFrags();
ptx = screen.MouseX();
pty = screen.MouseY();
if( GETKEYSTATE(0x01) )
CreateFrags(ptx,pty);
back->Lock();
back->DrawRect( ptx,pty-3,1,7,RGB(255,255,255) );
back->DrawRect( ptx-3,pty,7,1,RGB(255,255,255) );
RenderFrags();
back->Unlock();
screen.WriteText(4,20,"FPS: " + NumToStr(speed,0) + " Esc to exit");
speed = screen.Flip(1);

}Until GetKeyState(0x1B);
screen.CloseScreen();
return true;
}

Frags::UpdateFrags()
{
pos = pListOfFrags.GetFirst();
while pos
{
f = pListOfFrags.GetData(pos);
f->x += f->xs;
f->y += f->ys;
f->ys += gravity;
If((f->x < 0) || (f->x >= width) || (f->y >= height))
{
pos = pListOfFrags.Remove(pos,TRUE);
f = NULL;
}
Else If (f->b > 0)
{
f->b -= 5;
}
Else If (f->g > 0)
{
f->g -= 3;
}
Else If (f->r > 0)
{
f->r -= 1;
If f->r=0
{
pos = pListOfFrags.Remove(pos,TRUE);
f = NULL;
}
}
if( f )
pos = pListOfFrags.GetNext(pos);
}
}

Frags::CreateFrags(int mx,int my)
{
int count = RAND(intensity)+intensity;
float an,anstep = 360.0f/count;
an=RND(anstep);
for(int k=1;k <= count; k++)
{
f = pListOfFrags.Add(NEW(FragsStruct,1));
f->x=mx;
f->y=my;
f->xs=FCosD(an) * (Rnd( 1 ) + 3f);
f->ys=FSinD(an) * (Rnd( 1 ) + 3f);
f->r=255;
f->g=255;
f->b=255;
an += anstep;
}
RETURN;
}

Frags::RenderFrags()
{
back = screen.GetBack();
pos = pListOfFrags.GetFirst();
while(pos)
{
f = pListOfFrags.GetData(pos);
back->DrawRect( f->x-1,f->y-1,3,3,RGB(f->r,f->g,f->b) );
pos = pListOfFrags.GetNext(pos);
}
}

global sub main ()
{
Frags App;
App.Run();
}

Ionic Wind Support Team

Just so you don't get more confused.  A struct is just a definition.  Putting it within the class defintion does nothing more for you than having it outside the defintion, no more then putting a #define within a class defintion would.
Ionic Wind Support Team

J B Wood (Zumwalt)

Actually putting a struct within a class makes it a member of the class, so you have to make an instance of the class to use it.
right?

kryton9

August 08, 2006, 08:55:54 pm #33 Last Edit: August 08, 2006, 08:57:29 pm by kryton9
And this way it is protected from being altered by outside functions, right? In addition it looks slick and all OOPy :)

Ionic Wind Support Team

A varaible can be part of a class, and that varaible can be a structure type.  But the definition of a structure is just that, a defintion.  Doing this:

class myclass
{
  struct mystruct
  {
  }
}

Is no different than

struct mystruct
{
}

class myclass
{
}

Which was the point I was trying to make, having the structure defintion within a class defintion doesn't give you any benefit whatsoever. However.

class myclass {
   mystruct str1;  //  this is a member variable of type 'mystruct'. 
}

Then your statement would be true.  'str1' is only accessable from an instance of the class.
Ionic Wind Support Team