# How should I design my particle system to make it easy to add new particle effect types?

Recently I started designing a particle system for a game I develop. But I have some issues with it. I mean, it works but I have a feeling that my design isn't good enough.

So, basically I have a Particle class which contains the particle's vars and couple of functions:

class OBJECTATTRIBUTE_API Particle
{
protected:
Vector3d position;
Vector3d direction;
Vector3d gravity;

float life;

float red;
float green;
float blue;

bool isActive;
bool isInit;

public:
void Deinitialize();

void SetPosition(Vector3d position);

bool IsActive();
};


And I derive from that class the types of particles. Like this:

class OBJECTATTRIBUTE_API ParticleExplosion : public Particle
{
public:
void Initialize();

void Update();
void Render();

void Rejuvenate();
};


And at the end is the emitter. This is actually where I think my design fails. I make an emitter for every particle system and, at some point, I may have too much different emitters.

Here is an example of the particle emitter realisation:

// The base class
class OBJECTATTRIBUTE_API ParticleEmitter
{
protected:
Vector3d emitterPosition;

unsigned int particleTextureID;
unsigned int particleCount;
bool isEmitterStopped;

public:
ParticleEmitter();
ParticleEmitter(Vector3d emitterPosition);
};

// The derived emitter.
class OBJECTATTRIBUTE_API ParticleEmitter_Explosion : public ParticleEmitter
{
private:
ParticleExplosion *particles;

public:

void Initialize();

void Start();
void Stop();

void Reposition(Vector3d newPosition);
void SetParticleTextureID(unsigned int particleTextureID);
};


And the question - Is my particle system design good? If not, what can I do to improve it?

EDIT : I was told that the question was too subjective, so I will try to add couple of specifications.

Firstly, I started making the particle system for explosion simulation and also some attack animations in my game. It works very well with that, so I think this goal is achieved.

Secondly, the performance hit is acceptable and I am OK with that.

And finally, the question was about is this design good for flexible adding of new particle effects implementation?

• What makes you think your system is not good? It does work and follows common OOP guidelines. You're concerned about having multiple emitters, but... how would you do it otherwise? One emitter with multiple emission points? Why would you want that? – kaoD Feb 17 '12 at 13:54
• Well, I thought of making one emitter class and define the particles in it like that: Particle *particles. After that the particle type is set by the user and we have one emitter class for multiple purposes. I left that idea because it was not so flexible(maybe we want a different emitter to do different things and so on). – Tsvetan Feb 17 '12 at 14:00
• It all depends on what your end-goal is. Is it efficient enough that you can get as many particles on the screen as you need without a performance hit? Does it look good? If it meets those two criteria I would say that you're fine. – Nic Foster Feb 17 '12 at 15:08
• Well, I get a performance hit at about 100k particles(+- 10k), but I don't need so many of them, so I am OK with that. And yes, it looks good. So, I guess the design is OK. – Tsvetan Feb 17 '12 at 15:12
• Definitely add a virtual destructor to the base classes – Maik Semder Feb 18 '12 at 16:23