From bccb486d184b26638d3e47507bc6260383950b8b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 3 Mar 2016 20:32:53 +0300 Subject: Split particles update into two functions. --- src/particle/particle.cpp | 27 +++++++++++++++++++++------ src/particle/particle.h | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/particle') diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index f6b951004..4e583d0ab 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -106,16 +106,11 @@ void Particle::draw(Graphics *restrict const, { } -bool Particle::update() restrict2 +void Particle::updateSelf() restrict2 { - if (!mMap) - return false; - if (mLifetimeLeft == 0 && mAlive == AliveStatus::ALIVE) mAlive = AliveStatus::DEAD_TIMEOUT; - const Vector oldPos = mPos; - if (mAlive == AliveStatus::ALIVE) { // calculate particle movement @@ -235,9 +230,29 @@ bool Particle::update() restrict2 } mAlive = AliveStatus::DEAD_LONG_AGO; } +} + +bool Particle::update() restrict2 +{ + if (!mMap) + return false; + + const Vector oldPos = mPos; + + updateSelf(); const Vector change = mPos - oldPos; + if (mChildParticles.empty()) + { + if (mAlive != AliveStatus::ALIVE && + mAutoDelete) + { + return false; + } + return true; + } + // Update child particles const int cameraX = viewport->getCameraX(); diff --git a/src/particle/particle.h b/src/particle/particle.h index 72c40493d..eff89553e 100644 --- a/src/particle/particle.h +++ b/src/particle/particle.h @@ -281,6 +281,8 @@ class Particle notfinal : public Actor { mDeathEffect = effectFile; mDeathEffectConditions = conditions; } protected: + void updateSelf() restrict2; + // Opacity of the graphical representation of the particle float mAlpha; -- cgit v1.2.3-60-g2f50