summaryrefslogtreecommitdiff
path: root/src/particle
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-16 23:39:55 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-16 23:39:55 +0300
commit68151e88af407f5c45cd4fbf671c59645d8b4557 (patch)
tree5bb23c212922a53ad8d240b7e373b65a671ef629 /src/particle
parent9a8e4dd9e99abff3b6e9b8351edd6bd1c009ed0e (diff)
downloadmanaplus-68151e88af407f5c45cd4fbf671c59645d8b4557.tar.gz
manaplus-68151e88af407f5c45cd4fbf671c59645d8b4557.tar.bz2
manaplus-68151e88af407f5c45cd4fbf671c59645d8b4557.tar.xz
manaplus-68151e88af407f5c45cd4fbf671c59645d8b4557.zip
Improve performance in moving child particles.
Diffstat (limited to 'src/particle')
-rw-r--r--src/particle/particle.cpp19
-rw-r--r--src/particle/particle.h2
-rw-r--r--src/particle/particleengine.cpp3
-rw-r--r--src/particle/particleengine.h2
4 files changed, 21 insertions, 5 deletions
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index 0705c1ed1..94d5acd17 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -66,6 +66,7 @@ Particle::Particle() :
mImage(nullptr),
mChildEmitters(),
mChildParticles(),
+ mChildMoveParticles(),
mDeathEffect(),
mGravity(0.0F),
mBounce(0.0F),
@@ -213,6 +214,8 @@ void Particle::updateSelf() restrict2
Particle *const p = *it;
p->moveBy(mPos);
mChildParticles.push_back(p);
+ if (p->mFollow)
+ mChildMoveParticles.push_back(p);
}
}
}
@@ -305,15 +308,20 @@ bool Particle::update() restrict2
return true;
}
- // Update child particles
- for (ParticleIterator p = mChildParticles.begin(),
- fp2 = mChildParticles.end(); p != fp2; )
+ for (ParticleIterator p = mChildMoveParticles.begin(),
+ fp2 = mChildMoveParticles.end(); p != fp2; )
{
Particle *restrict const particle = *p;
// move particle with its parent if desired
if (particle->mFollow)
particle->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())
{
@@ -321,6 +329,7 @@ bool Particle::update() restrict2
}
else
{
+ mChildMoveParticles.remove(*p);
delete particle;
p = mChildParticles.erase(p);
}
@@ -338,7 +347,7 @@ bool Particle::update() restrict2
void Particle::moveBy(const Vector &restrict change) restrict2
{
mPos += change;
- FOR_EACH (ParticleConstIterator, p, mChildParticles)
+ FOR_EACH (ParticleConstIterator, p, mChildMoveParticles)
{
Particle *restrict const particle = *p;
if (particle->mFollow)
@@ -523,4 +532,6 @@ void Particle::clear() restrict2
delete_all(mChildParticles);
mChildParticles.clear();
+
+ mChildMoveParticles.clear();
}
diff --git a/src/particle/particle.h b/src/particle/particle.h
index dfe6ac4d1..c0e149c97 100644
--- a/src/particle/particle.h
+++ b/src/particle/particle.h
@@ -279,6 +279,8 @@ class Particle notfinal : public Actor
// List of particles controlled by this particle
Particles mChildParticles;
+ Particles mChildMoveParticles;
+
// Particle effect file to be spawned when the particle dies
std::string mDeathEffect;
diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp
index cb43f5059..648d3b62d 100644
--- a/src/particle/particleengine.cpp
+++ b/src/particle/particleengine.cpp
@@ -57,6 +57,7 @@ const float ParticleEngine::PARTICLE_SKY = 800.0F;
ParticleEngine::ParticleEngine() :
mChildParticles(),
+ mChildMoveParticles(),
mMap(nullptr)
{
ParticleEngine::particleCount++;
@@ -112,6 +113,7 @@ bool ParticleEngine::update() restrict2
}
else
{
+ mChildMoveParticles.remove(*p);
delete particle;
p = mChildParticles.erase(p);
}
@@ -331,4 +333,5 @@ void ParticleEngine::clear() restrict2
{
delete_all(mChildParticles);
mChildParticles.clear();
+ mChildMoveParticles.clear();
}
diff --git a/src/particle/particleengine.h b/src/particle/particleengine.h
index 93688f777..fef12ba64 100644
--- a/src/particle/particleengine.h
+++ b/src/particle/particleengine.h
@@ -118,7 +118,7 @@ class ParticleEngine final
private:
// List of particles controlled by this particle
Particles mChildParticles;
-
+ Particles mChildMoveParticles;
Map *mMap;
};