Jump to content
  • Advertisement
Sign in to follow this  
subflood

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.

If you intended to correct an error in the post then please contact us.

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));

    if (head == NULL)
    {
        head = n_ParticlePool;
        back = head;
        back->prev = NULL;
    }
    else
    {
        prev->next = n_ParticlePool;
        back = n_ParticlePool;
        back->prev = prev;
    }

    n_ParticlePool->next = NULL;

    prev = n_ParticlePool;
}
    n_ParticlePool = head;
    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?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!