I am creating a particle system in XNA4 and I am facing a problem. My first particle system was a simple list of particles that are instantiated as needed. But then I read about using pools.
My second system consists of a pool full of particles and an emitter / controller. My pool is pretty simple, this is the code:
class Pool<T> where T: new () { public T[] pool; public int nextItem = 0; public Pool(int capacity) { pool = new T[capacity]; for (int i = 0; i < capacity; i++) { pool[i] = new T(); } } public T Create() { return pool[nextItem++]; } public void Destroy(T particle) { pool[--nextItem] = particle; } }
The problem is that the pool system is much more hungry for the processor. Every time I remove a particle from the pool to my emitter, I have to reinitialize and reset the particles due to the lack of a constructor, and this is a problem.
Does it make sense to use pools if I restart these particles or should I leave pools for arrays of completely identical objects that never change?
source share