Author |
Message |
zero-impact
![](http://compsci.ca/v3/uploads/user_avatars/872397874480c7089d4888.gif)
|
Posted: 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
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
particles.t |
Filesize: |
4.52 KB |
Downloaded: |
129 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
talyboy
|
Posted: Mon Jun 09, 2008 8:43 am Post subject: RE:Pathetic Little Particle Engine |
|
|
haha that's awesome!!
|
|
|
|
|
![](images/spacer.gif) |
SNIPERDUDE
![](http://compsci.ca/v3/uploads/user_avatars/16932914504cbd0ad6ceaf1.jpg)
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
SNIPERDUDE
![](http://compsci.ca/v3/uploads/user_avatars/16932914504cbd0ad6ceaf1.jpg)
|
Posted: 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...
|
|
|
|
|
![](images/spacer.gif) |
Saad
![](http://compsci.ca/v3/uploads/user_avatars/182387547249e7ebb91fb8a.png)
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
SNIPERDUDE
![](http://compsci.ca/v3/uploads/user_avatars/16932914504cbd0ad6ceaf1.jpg)
|
Posted: Fri Jun 13, 2008 10:01 am Post subject: RE:Pathetic Little Particle Engine |
|
|
true, good point.
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
|