summaryrefslogtreecommitdiff
path: root/src/particle.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-03-10 23:20:37 +0300
committerAndrei Karas <akaras@inbox.ru>2013-03-10 23:37:18 +0300
commitb38844700debb737dad4090774ad0426a0ebcc02 (patch)
tree83a0cfbda2e8a1ef8ac9854469e77d8774779981 /src/particle.cpp
parent1c423d3301cc1a04c11a8605822699e13d473a8a (diff)
downloadmv-b38844700debb737dad4090774ad0426a0ebcc02.tar.gz
mv-b38844700debb737dad4090774ad0426a0ebcc02.tar.bz2
mv-b38844700debb737dad4090774ad0426a0ebcc02.tar.xz
mv-b38844700debb737dad4090774ad0426a0ebcc02.zip
Improve particle classes.
Diffstat (limited to 'src/particle.cpp')
-rw-r--r--src/particle.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/particle.cpp b/src/particle.cpp
index 19d732653..a0a01a09a 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -207,10 +207,11 @@ bool Particle::update()
FOR_EACH (EmitterConstIterator, e, mChildEmitters)
{
Particles newParticles = (*e)->createParticles(mLifetimePast);
- FOR_EACH (ParticleConstIterator, p, newParticles)
+ FOR_EACH (ParticleConstIterator, it, newParticles)
{
- (*p)->moveBy(mPos);
- mChildParticles.push_back (*p);
+ Particle *const p = *it;
+ p->moveBy(mPos);
+ mChildParticles.push_back (p);
}
}
}
@@ -236,18 +237,19 @@ bool Particle::update()
for (ParticleIterator p = mChildParticles.begin(),
p2 = mChildParticles.end(); p != p2; )
{
+ Particle *const particle = *p;
//move particle with its parent if desired
- if ((*p)->doesFollow())
- (*p)->moveBy(change);
+ if (particle->doesFollow())
+ particle->moveBy(change);
//update particle
- if ((*p)->update())
+ if (particle->update())
{
++p;
}
else
{
- delete (*p);
+ delete particle;
p = mChildParticles.erase(p);
}
}
@@ -262,8 +264,9 @@ void Particle::moveBy(const Vector &change)
mPos += change;
FOR_EACH (ParticleConstIterator, p, mChildParticles)
{
- if ((*p)->doesFollow())
- (*p)->moveBy(change);
+ Particle *const particle = *p;
+ if (particle->doesFollow())
+ particle->moveBy(change);
}
}
@@ -285,11 +288,9 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
{
Particle *newParticle = nullptr;
- size_t pos = particleEffectFile.find('|');
- std::string dyePalettes;
- if (pos != std::string::npos)
- dyePalettes = particleEffectFile.substr(pos + 1);
-
+ const size_t pos = particleEffectFile.find('|');
+ const std::string dyePalettes = (pos != std::string::npos)
+ ? particleEffectFile.substr(pos + 1) : "";
XML::Document doc(particleEffectFile.substr(0, pos));
const XmlNodePtr rootNode = doc.rootNode();
@@ -346,9 +347,9 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
effectChildNode, "position-y", 0));
const float offsetZ = static_cast<float>(XML::getFloatProperty(
effectChildNode, "position-z", 0));
- Vector position (mPos.x + static_cast<float>(pixelX) + offsetX,
- mPos.y + static_cast<float>(pixelY) + offsetY,
- mPos.z + offsetZ);
+ const Vector position (mPos.x + static_cast<float>(pixelX) + offsetX,
+ mPos.y + static_cast<float>(pixelY) + offsetY,
+ mPos.z + offsetZ);
newParticle->moveTo(position);
const int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);
@@ -363,14 +364,13 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
{
if (xmlNameEqual(emitterNode, "emitter"))
{
- ParticleEmitter *newEmitter;
- newEmitter = new ParticleEmitter(emitterNode, newParticle,
- mMap, rotation, dyePalettes);
+ ParticleEmitter *const newEmitter = new ParticleEmitter(
+ emitterNode, newParticle, mMap, rotation, dyePalettes);
newParticle->addEmitter(newEmitter);
}
else if (xmlNameEqual(emitterNode, "deatheffect"))
{
- std::string deathEffect = reinterpret_cast<const char*>(
+ const std::string deathEffect = reinterpret_cast<const char*>(
emitterNode->xmlChildrenNode->content);
char deathEffectConditions = 0x00;