Wednesday, September 15, 2010

Particle Engine Rewrite

Last night I rewrote the particle engine to use a Container instead of an Array.  The problem with arrays was that they could get messy when considering the way in which particles are created and removed from them on a regular basis.  I haven't fully decided if it's any faster, as of yet, but it doesn't appear to be a slowdown.  I had run into an issue in the latest version of Chrome where the ParticleEngine.sortParticles() method was "freezing" the browser when called.  I have determined that it's due to just calling Array.sort() with a compare function.  If the comparison did anything with the actual objects (even just checking if they were null), the browser would stop for a moment.

By replacing the Array with a Container, I can use an Iterator which will inherently skip destroyed objects.  Containers are simply linked lists, so when an entry is removed the link is broken, rather than coalescing the list.  Some operations, such as adding one Container to another, are simply pointer operations.  Adding one Container to another results in a single list which contains pointers to both.  Modifying the second Container will affect the first, so one need to proceed with caution.  At some point, I'll probably add "deep copy" methods which will be slower, but will ensure that the two lists won't affect each other.

No comments:

Post a Comment