Skip to main content
added 985 characters in body
Source Link
ratchet freak
  • 8.1k
  • 20
  • 16

Particles is something that doesn't fit inside a component.

Instead you want spawning particles as a possible behavior of the collision component.

Then the particles themselves are in a flat array that you can loop over and update positions and render them all easily.

class ParticleSystem{

    std::vector<Particle> particles;
    
    public:
    void spawn(...); //push_back some new particles based on args

    void update(TimeDelta dt){
    
        for(auto it = particles.begin(); it != particles.end();++it){
            do{
            it->ttl -= dt;
            if(it->ttl < 0) {
                //particle died, remove from list;
                swap(it*, particles.back());
                particles.pop_back();
                if(it == particles.end())return;
            }
            while(it->ttl < 0);

            //update pos and vel of it*
            it->pos+=it->val * dt;
            it->vel+=it->accel*dt;
        }
    
    }

}

Particle system can always update and will usually have some particles to move but the spawn is only called from other components based on certain triggers.

This changes from poll notification to push notifications. WhishWhich if things are idle most of the time is much better for performance.

Particles is something that doesn't fit inside a component.

Instead you want spawning particles as a possible behavior of the collision component.

Then the particles themselves are in a flat array that you can loop over and update positions and render them all easily.

This changes from poll notification to push notifications. Whish if things are idle most of the time is much better for performance.

Particles is something that doesn't fit inside a component.

Instead you want spawning particles as a possible behavior of the collision component.

Then the particles themselves are in a flat array that you can loop over and update positions and render them all easily.

class ParticleSystem{

    std::vector<Particle> particles;
    
    public:
    void spawn(...); //push_back some new particles based on args

    void update(TimeDelta dt){
    
        for(auto it = particles.begin(); it != particles.end();++it){
            do{
            it->ttl -= dt;
            if(it->ttl < 0) {
                //particle died, remove from list;
                swap(it*, particles.back());
                particles.pop_back();
                if(it == particles.end())return;
            }
            while(it->ttl < 0);

            //update pos and vel of it*
            it->pos+=it->val * dt;
            it->vel+=it->accel*dt;
        }
    
    }

}

Particle system can always update and will usually have some particles to move but the spawn is only called from other components based on certain triggers.

This changes from poll notification to push notifications. Which if things are idle most of the time is much better for performance.

Source Link
ratchet freak
  • 8.1k
  • 20
  • 16

Particles is something that doesn't fit inside a component.

Instead you want spawning particles as a possible behavior of the collision component.

Then the particles themselves are in a flat array that you can loop over and update positions and render them all easily.

This changes from poll notification to push notifications. Whish if things are idle most of the time is much better for performance.