# particle pool bi-directional linked list

This topic is 4837 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?

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633328
• Total Posts
3011379
• ### Who's Online (See full list)

There are no registered users currently online

×