I am creating a particle system in XNA4 and I've bumped into problem. My first particle system was a simple list of particles, whose instances are created when needed. But then I read about using pools.
My second system consists of a pool, filled with particles, and an emitter/controller. My pool is pretty basic, 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 pool system is much more hungry for CPU. Every time I take out particle from pool to my emitter I'm forced to re-initialize and reset particles, due the constructor absence and this is a problem.
Is there any point at using pools, if I re-init those particles or I should leave pools for arrays of completely identical objects that never changes?