Righty, everyone must have tinkered with this at some point, so I’m interested in different ways people have done particle effects in their games.
The very basic structure I was thinking of was a Particle class for each one, a ParticleSystem for a single effect (basically an emmiter + a collection of particles) and a global ParticleManager to organise all the systems. Structure shamlessly ripped from a Gamasutra article from ages ago. ;D
-
Object pooling. Obviously we can’t go creating new particle objects contantly, or the GC would kill our performance and our first born. An initial idea would be to hold a single big pool in the manager, and dish them out to systems as they requested them. But since each effect is likely to just use a static amount of particles anyway, why not just just let each system allocate its own particles and pool the systems? Anyone any suggestions which may be a better idea?
-
Parallel arrays vs. Objects. The OO way is obviously with a Particle object for each on screen particle, yet with high numbers allocated this may be GC and pool unfriendly. How about parallel arrays in each system for the required properties? This would imply system pooling rather than particle pooling. The downside being that we can’t just create a new Particle subclass for new behaviour, and probably a whole load of duplicate code if we have multiple particle system classes.
-
Emmiters vs. complex systems. Should a particle system control emmision rate & properties (implying multiple ParticleSystem classes) or perhaps a single ParticleSystem class and allow different emmiters to be plugged into it?
-
Single generic Particle class vs. Particle interface + several implementations. Things like dust, fire, smoke all need different behaviour, which is easiest to add with different particle classes. Or a generic particle class (essencially a no-code struct) with different controller classes to alter movement behaviour. Problems: becomes awkward when new controller behaviour needs extra data stored in particle object. Or with the other method, multiple particle subclasses makes pooling more tricky.
Ideas?
