From 6fe25419922ffa2c97119b87ad8f05a4d0fb228f Mon Sep 17 00:00:00 2001 From: DelinWorks Date: Thu, 26 May 2022 21:34:15 +0300 Subject: [PATCH] =?UTF-8?q?Put=20loops=20inside=20ifs=20statements=20not?= =?UTF-8?q?=20the=20opposite=20=F0=9F=A4=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/2d/CCParticleSystem.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/2d/CCParticleSystem.cpp b/core/2d/CCParticleSystem.cpp index 3f6b1b2cf5..59e9bdeb5e 100644 --- a/core/2d/CCParticleSystem.cpp +++ b/core/2d/CCParticleSystem.cpp @@ -1316,9 +1316,9 @@ void ParticleSystem::update(float dt) if (_isLifeAnimated || _isEmitterAnimated || _isLoopAnimated) { - for (int i = 0; i < _particleCount; ++i) + if (_isEmitterAnimated && !_animations.empty()) { - if (_isEmitterAnimated && !_animations.empty()) + for (int i = 0; i < _particleCount; ++i) { _particleData.animTimeDelta[i] += (_animationTimescaleInd ? pureDt : dt); if (_particleData.animTimeDelta[i] > _particleData.animTimeLength[i]) @@ -1332,7 +1332,10 @@ void ParticleSystem::update(float dt) _particleData.animTimeDelta[i] = 0; } } - if (_isLifeAnimated && _animations.empty()) + } + if (_isLifeAnimated && _animations.empty()) + { + for (int i = 0; i < _particleCount; ++i) { float percent = (_particleData.totalTimeToLive[i] - _particleData.timeToLive[i]) / _particleData.totalTimeToLive[i]; @@ -1340,7 +1343,10 @@ void ParticleSystem::update(float dt) _particleData.animCellIndex[i] = (unsigned short)MIN(percent * _animIndexCount, _animIndexCount - 1); } - if (_isLifeAnimated && !_animations.empty()) + } + if (_isLifeAnimated && !_animations.empty()) + { + for (int i = 0; i < _particleCount; ++i) { auto& anim = _animations.at(_particleData.animIndex[i]); @@ -1352,7 +1358,10 @@ void ParticleSystem::update(float dt) _particleData.animCellIndex[i] = anim.animationIndices[MIN(percent * anim.animationIndices.size(), anim.animationIndices.size() - 1)]; } - if (_isLoopAnimated && !_animations.empty()) + } + if (_isLoopAnimated && !_animations.empty()) + { + for (int i = 0; i < _particleCount; ++i) { auto& anim = _animations.at(_particleData.animIndex[i]); @@ -1367,9 +1376,9 @@ void ParticleSystem::update(float dt) _particleData.animCellIndex[i] = anim.animationIndices[MIN(percent * anim.animationIndices.size(), anim.animationIndices.size() - 1)]; } - if (_isLoopAnimated && _animations.empty()) - std::fill_n(_particleData.animTimeDelta, _particleCount, 0); } + if (_isLoopAnimated && _animations.empty()) + std::fill_n(_particleData.animTimeDelta, _particleCount, 0); } for (int i = 0; i < _particleCount; ++i)