Monday, June 7, 2010

Switching Stardust Particle Collection Type

Stardust project homepage

Paq from WonderFL made a quick performance test with different particle collection types provided by Stardust, and the result turned out to be quite different from my own previous tests. I think the difference is due to the fact that we conducted the tests with different numbers of particles. Hence, it's reasonable to choose which particle collection type to use according to the roughly estimated number of particles that will be present.

For this reason, also as one of the new feature of Stardust version 1.1.161, I've added the Emitter.particleCollectionType getter/setter to allow users to switch between different particle collection types. Valid types are mapped by integers defined in the ParticleCollectionType class.

Now the Emitter constructor accepts a second parameter for the integer corresponding to a particle collection type, which is the ParticleFastArray class by default.

This is how you set the underlying particle collection type of an emitter to a linked list.

And this is how you switch an emitter's particle collection to a different type, say, an array.

There's no specific rule in deciding whether a collection type is the best for your specific particle system. In terms of performance, fast arrays are approximately as good as linked lists. However, if you insist on finding the exact best one, you just have to try them all and then determine which works the best.

No comments: