# particle pool bi-directional linked list

This topic is 5173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have been reading an article called "The Ocean Spray in Your Face" by Jeff Lander and I want to ask you guys if I'm implementing this particle pool correctlly. The AddParticle function begins like this (code copied directly from the article): bool AddParticle(tEmitter *emitter)
tParticle *particle;

if (emitter != NULL && n_ParticlePool != NULL &&
emitter->particleCount < emitter->totalParticles)
{
particle = n_ParticlePool;                  // The Current Particle
n_ParticlePool = n_ParticlePool->next;      // Fix The Pool Pointers
if (emitter->particle != NULL)
emitter->particle->prev = particle;     // Set Back Link

particle->next = emitter->particle;         // Set Its Next Pointer
particle->prev = NULL;                      // It Has No back Pointer
emitter->particle = particle;               // Set It In The Emitter
...

Now, I declare n_ParticlePool as a global variable: tParticle *n_ParticlePool; and here is how I initialize the structure (coded by myself)
for (i = 0; i < NUM_PARTICLES; i++)
{
n_ParticlePool = (tParticle *) malloc(sizeof(tParticle));

{
back->prev = NULL;
}
else
{
prev->next = n_ParticlePool;
back = n_ParticlePool;
back->prev = prev;
}

n_ParticlePool->next = NULL;

prev = n_ParticlePool;
}
n_ParticlePool = n_ParticlePool->next;
...

the tParticle structure looks like thise:
typedef struct t_Particle
{
struct t_Particle *prev, *next;     // Link
tVector pos;                        // Current Position
tVector prevPos;                    // Previous Position
tVector dir;                        // Current Direction With Speed
int life;                           // How Long It Will Last
tColor color;                       // Current Color Of Particle
tColor prevColor;                   // Last Color Of Particle
tColor deltaColor;                  // Change Of Color

}tParticle;

Did I initialize the linked list the right way, the reason I'm asking is because I have never written a bi-directional linked list. What do you guys think/recommend?

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 52