Archived

This topic is now archived and is closed to further replies.

neonfaktory

Particle Engine with no Limits?

Recommended Posts

Just a quick issue that came up. My particle engine is not unlike many others, except that it is held in a dynamic Linked List. I already recieved comments against this, as expected, to which I explained my system. My particle system includes essential and non-essential particles. Essential being weapons (bullets, mines, etc.), non-essential being smoke effects and what not. The fact of the matter is that I don''t know how else you could do it... Well, at least without complicating it beyond reason. If I kept them in a fixed array there could be the possibility of not being able to allocate room for weapons or the effects, or jumping into the "complicating" scenario by swapping non-essentials with essentials, which still leaves the possibility of running out of room for them, etc. Any suggestions?

Share this post


Link to post
Share on other sites
Why not keep an active list and an inactive list of particals. Then when you need a new partical check to see if there is a partical avalible on the inactive. If there is use and place it on the active list else create a new one and place it on the active list. When you are done with a partical place it on the inactive for reuse.



p.s. I think you could use a templated base class to do this.


Share this post


Link to post
Share on other sites
The problem I''m talking about is when the total # you allocate is not enough for all the active particles.
Meaning when a player shoots thier weapon, theres no spot to fit that particle, so the gameplay suffers as the weapon does not seem to fire.
Or perhaps it starts looking real shoddy because a wrecked object no longer emits smoke because theres no more room to fit the next smoke particle, etc.
That''s why I''m using a dynamic linked list for my particles and was wondering if anyone could think of a different way.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
wait a minute. what exactly is the problem with just using the dynamic list?

Share this post


Link to post
Share on other sites
If you need to create an essential particle and there is no more room left then simply iterate through your non essential particles, and if necessary your essential list, and remove/recycle the oldest one for your new particle.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Creating and deleting many small items can lead to memory fragmentation. Also deleting items can be very slow.

Share this post


Link to post
Share on other sites
Well duh.
I, as I''m sure others, are not suggesting to create nor delete them. You recycle them, hence the only creation or deletion of the particle system happens at run time and shutdown.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

Creating and deleting many small items can lead to memory fragmentation. Also deleting items can be very slow.



why don''t you resize the array like this...

if( ItemsFreeInArray == 0 )
ResizeParticleArray( NumItemsInArray+100 );

...instead of resizing the array for every item you need to delete/add.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
For more information on object pooling, b/c it seems to be popular nowadays, visit the ''Discuss this Article'' thread about Enginuity part II by Richard Fine. On page 6 and 7, there''s a lot of Object pooling/ Garbage collection source code being dumped with no copyrights.

Share this post


Link to post
Share on other sites
What you might want to do is have a fixed number of particles, and have a priority number attached to each. That way, if there are no unused particles, a higher priority particle can take over a lower priority particle, and you don''t have to deal with memory fragmentation.

Share this post


Link to post
Share on other sites
Why set a limit to the number of particle systems at all? Take a look at this article at gamasutra (you may need to register first but it''s free and it really worth it). It takes a three step approach:

1) Particle systems manager
2) Particle systems
3) Particles

The manager keeps a std::vector to keep track of the particle systems. There''s no limit to the amount of systems. Each system dynamically allocates enough memory to hold all the particles in that one system. These particles get reused over and over again until the system dies or is shut down. After that, the memory block for the particles is being released.

If you would combine this method with the memory garbage collection from the Enginuity part II article, you''d have a nice, memory friendly particle system with unlimited capacity (well, maybe physical memory and rendering speed. But it''s not limited in your code anymore).

Quick example: Say you want some smoke coming from your gun. You would call something like this:

ParticleManager.Init(SMOKE_SYSTEM, numParticles, position);

SMOKE_SYSTEM is just a predefined integer to indicate the type, position is a vector. The manager pushes a new smoke system, derived from a generic particle system class, into the std::vector. The newly created system then dynamically creates an array like particles = new CParticles[numParticles]; to hold all the particles. When the system dies, the smoke system deletes[] the particles and after that, the manager removes the system from the std::vector.


Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]


GSACP: GameDev Society Against Crap Posting
To join: Put these lines in your signature and don''t post crap!

Share this post


Link to post
Share on other sites