Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Pathetic Little Particle Engine
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zero-impact




PostPosted: Sun Jun 08, 2008 9:37 pm   Post subject: Pathetic Little Particle Engine

I was bored so i made this little particle engine

I am pretty new to compsci so any pointers on how i could make this code better/more efficient would be much appreciated

It gets laggy pretty fast You Have Been Warned

I basically only need help making it more efficient

The controls are simple click to spawn more particles
hold space to attract them to the mouse



particles.t
 Description:

Download
 Filename:  particles.t
 Filesize:  4.52 KB
 Downloaded:  129 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
talyboy




PostPosted: Mon Jun 09, 2008 8:43 am   Post subject: RE:Pathetic Little Particle Engine

haha that's awesome!!
SNIPERDUDE




PostPosted: Tue Jun 10, 2008 7:20 am   Post subject: RE:Pathetic Little Particle Engine

hmmm, does get slow.
It doesn't look like you are recycling your variables - in other words, when a particle lands it will just be reset to fall again. That way you can have it running at a good speed the entire time.

Other than that, pretty good.
DemonWasp




PostPosted: Thu Jun 12, 2008 8:11 pm   Post subject: RE:Pathetic Little Particle Engine

Cool program. As sniperdude noted, you don't appear to be recycling your variables. Do that, and it should improve the system speed a whole lot.

The other thing that I noticed is that when you spawn new particles, you're increasing the size of your flexible array by 1 each time. That means that Turing has to make a new array (one larger than the previous one), copy everything over, then delete the old array. As you might imagine, that's incredibly slow.

The faster way is to increase your array size by a LOT more each time (like, doubling the size) every time you run out of space (not every time you spawn a new particle, so don't just change the code to *2 instead of +1). That will result in a whole lot less array allocation / copy / delete cycles, and should keep your program running quickly even if you had tens of thousands of particles.
SNIPERDUDE




PostPosted: Fri Jun 13, 2008 12:13 am   Post subject: RE:Pathetic Little Particle Engine

of course you wouldn't need to have the array to expand if you recycled the variables; You could just keep it at a fixed amount...
Saad




PostPosted: Fri Jun 13, 2008 6:37 am   Post subject: Re: Pathetic Little Particle Engine

For storing the particles and adding/deleting fast. Look into Linked Lists. Other then that, looking good.
DemonWasp




PostPosted: Fri Jun 13, 2008 6:45 am   Post subject: RE:Pathetic Little Particle Engine

Yes and no, sniperdude. He may have to store the set of particles that have already rained down on the ground below (although there are almost undoubtedly more efficient ways than using his existing array). It was more of a pointer in general.

Saad, yes, LinkedLists are much better for quick add-to-end operations like his spawn() procedure does...but they're pretty slow for iteration. Array-based lists are much, much faster if you have to do iteration.
SNIPERDUDE




PostPosted: Fri Jun 13, 2008 10:01 am   Post subject: RE:Pathetic Little Particle Engine

true, good point.
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: Sun Jan 11, 2009 10:18 am   Post subject: RE:Pathetic Little Particle Engine

cool, I see real potential for a bunch of different games using this engine. +bits
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: