summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-05-19 19:44:42 +0300
committerAndrei Karas <akaras@inbox.ru>2016-05-19 19:44:42 +0300
commitd07f27c128e946b49971f4d3d9e6dfec81ce2b8b (patch)
treedb7e20ef579cb042c57d04b56f4b97b40bc3c445 /src
parentb3b6477339cf98c31ca42bd88ef20f0b8c1290f5 (diff)
downloadmanaverse-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.gz
manaverse-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.bz2
manaverse-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.tar.xz
manaverse-d07f27c128e946b49971f4d3d9e6dfec81ce2b8b.zip
Split childs update code depend is current particle alive or not.
Diffstat (limited to 'src')
-rw-r--r--src/particle/particle.cpp66
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;
}