Friday, March 6, 2009
Okay, I was able to get the particle generator code back together at the 360 iDev conference. I now must put this project on the shelf because I am backed up on my paying work, but I'm putting it out there for anyone who's interested.
First, let me say that I am not an OpenGL expert. I wrote this to help me learn OpenGL and particle systems better, but it's almost certain that there's room for improvement in many places.
Second, there are a couple doozie bugs in here that keep it from being production ready. First and foremost is that any attempt to free the particles ends up in an infinite loop. The memory for particles is not released, it is constantly reused. There are two linked lists, one that holds the particles that are visible, and another to hold those that are no longer visible. When a particle reaches the end of its lifespan, it is moved from one list to the other. When a new particle is needed, one is grabbed from the pool if there is one there. This way, we avoid the overhead of constant memory allocation and deallocation. But, when the particle is done emitting, I'd like the option to free the memory, but right now, that causes a gnarly infinite loop.
Third, the sample app puts a whole bunch of emitters into an array. If you tap the screen, it tells the current emitter to stop emitting, and tells the next one to start. When it gets to the end, it tells the last one to stop, and goes back to tell the first one to start again, but when that happens, we get a pthread lock contention issue where two threads are each waiting for the other, causing the application to freeze. I'm not manually creating any threads, so tracking down this one could be really hard.
You can find the Google Code project right here.. If you prefer not to use subversion, you can download the initial version as a zip file right here.