diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-19 19:44:42 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-19 19:44:42 +0300 |
commit | d07f27c128e946b49971f4d3d9e6dfec81ce2b8b (patch) | |
tree | db7e20ef579cb042c57d04b56f4b97b40bc3c445 | |
parent | b3b6477339cf98c31ca42bd88ef20f0b8c1290f5 (diff) | |
download | plus-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.gz plus-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.bz2 plus-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.xz plus-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.zip |
Split childs update code depend is current particle alive or not.
-rw-r--r-- | src/particle/particle.cpp | 66 |
1 files changed, 44 insertions, 22 deletions
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; } |