Particle Engine with no Limits?
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?
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.
p.s. I think you could use a templated base class to do this.
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.
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.
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.
Creating and deleting many small items can lead to memory fragmentation. Also deleting items can be very slow.
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.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement