From d07f27c128e946b49971f4d3d9e6dfec81ce2b8b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 19 May 2016 19:44:42 +0300 Subject: Split childs update code depend is current particle alive or not. --- src/particle/particle.cpp | 66 +++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'src/particle') diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index 8ebde0a2b..b28e3a819 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -235,10 +235,10 @@ void Particle::updateSelf() restrict2 bool Particle::update() restrict2 { - const Vector oldPos = mPos; - if (mAlive == AliveStatus::ALIVE) { + const Vector oldPos = mPos; + if (mLifetimeLeft == 0) { mAlive = AliveStatus::DEAD_TIMEOUT; @@ -308,6 +308,30 @@ bool Particle::update() restrict2 // move particle with its parent if desired (*p)->moveBy(change); } + + // Update child particles + for (ParticleIterator p = mChildParticles.begin(), + fp2 = mChildParticles.end(); p != fp2; ) + { + Particle *restrict const particle = *p; + // update particle + if (particle->update()) + { + ++p; + } + else + { + mChildMoveParticles.remove(*p); + delete particle; + p = mChildParticles.erase(p); + } + } + if (mAlive != AliveStatus::ALIVE && + mChildParticles.empty() && + mAutoDelete) + { + return false; + } } else { @@ -317,31 +341,29 @@ bool Particle::update() restrict2 return false; return true; } - } - - // Update child particles - for (ParticleIterator p = mChildParticles.begin(), - fp2 = mChildParticles.end(); p != fp2; ) - { - Particle *restrict const particle = *p; - // update particle - if (particle->update()) + // Update child particles + for (ParticleIterator p = mChildParticles.begin(), + fp2 = mChildParticles.end(); p != fp2; ) { - ++p; + Particle *restrict const particle = *p; + // update particle + if (particle->update()) + { + ++p; + } + else + { + mChildMoveParticles.remove(*p); + delete particle; + p = mChildParticles.erase(p); + } } - else + if (mChildParticles.empty() && + mAutoDelete) { - mChildMoveParticles.remove(*p); - delete particle; - p = mChildParticles.erase(p); + return false; } } - if (mAlive != AliveStatus::ALIVE && - mChildParticles.empty() && - mAutoDelete) - { - return false; - } return true; } -- cgit v1.2.3-70-g09d2