diff options
Diffstat (limited to 'src/particle.cpp')
-rw-r--r-- | src/particle.cpp | 100 |
1 files changed, 66 insertions, 34 deletions
diff --git a/src/particle.cpp b/src/particle.cpp index 0c4a7d7e..f147a9f2 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -56,15 +56,15 @@ bool Particle::enabled = true; const float Particle::PARTICLE_SKY = 800.0f; Particle::Particle(Map *map): - mAlive(true), + mAlpha(1.0f), mLifetimeLeft(-1), mLifetimePast(0), mFadeOut(0), mFadeIn(0), - mAlpha(1.0f), + mAlive(ALIVE), mAutoDelete(true), - mMap(map), mAllowSizeAdjust(false), + mDeathEffectConditions(0x00), mGravity(0.0f), mRandomness(0), mBounce(0.0f), @@ -74,33 +74,31 @@ Particle::Particle(Map *map): mInvDieDistance(-1.0f), mMomentum(1.0f) { + setMap(map); Particle::particleCount++; - if (mMap) - setSpriteIterator(mMap->addSprite(this)); } Particle::~Particle() { - // Remove from map sprite list - if (mMap) - mMap->removeSprite(mSpriteIterator); // Delete child emitters and child particles clear(); + //update particle count Particle::particleCount--; } void Particle::setupEngine() { - Particle::maxCount = (int)config.getValue("particleMaxCount", 3000); - Particle::fastPhysics = (int)config.getValue("particleFastPhysics", 0); - Particle::emitterSkip = (int)config.getValue("particleEmitterSkip", 1) + 1; - Particle::enabled = (bool)config.getValue("particleeffects", true); + Particle::maxCount = config.getIntValue("particleMaxCount"); + Particle::fastPhysics = config.getIntValue("particleFastPhysics"); + Particle::emitterSkip = config.getIntValue("particleEmitterSkip") + 1; + Particle::enabled = config.getBoolValue("particleeffects"); disableAutoDelete(); logger->log("Particle engine set up"); } -void Particle::draw(Graphics *, int, int) const +bool Particle::draw(Graphics *, int, int) const { + return false; } bool Particle::update() @@ -108,12 +106,12 @@ bool Particle::update() if (!mMap) return false; - if (mLifetimeLeft == 0) - mAlive = false; + if (mLifetimeLeft == 0 && mAlive == ALIVE) + mAlive = DEAD_TIMEOUT; Vector oldPos = mPos; - if (mAlive) + if (mAlive == ALIVE) { //calculate particle movement if (mMomentum != 1.0f) @@ -147,7 +145,7 @@ bool Particle::update() { if (mInvDieDistance > 0.0f && invHypotenuse > mInvDieDistance) { - mAlive = false; + mAlive = DEAD_IMPACT; } float accFactor = invHypotenuse * mAcceleration; mVelocity -= dist * accFactor; @@ -175,7 +173,7 @@ bool Particle::update() } mLifetimePast++; - if (mPos.z > PARTICLE_SKY || mPos.z < 0.0f) + if (mPos.z < 0.0f) { if (mBounce > 0.0f) { @@ -185,9 +183,13 @@ bool Particle::update() } else { - mAlive = false; + mAlive = DEAD_FLOOR; } } + else if (mPos.z > PARTICLE_SKY) + { + mAlive = DEAD_SKY; + } // Update child emitters if ((mLifetimePast-1)%Particle::emitterSkip == 0) @@ -206,6 +208,17 @@ bool Particle::update() } } + // create death effect when the particle died + if (mAlive != ALIVE && mAlive != DEAD_LONG_AGO) + { + if ((mAlive & mDeathEffectConditions) > 0x00 && !mDeathEffect.empty()) + { + Particle* deathEffect = particleEngine->addEffect(mDeathEffect, 0, 0); + deathEffect->moveBy(mPos); + } + mAlive = DEAD_LONG_AGO; + } + Vector change = mPos - oldPos; // Update child particles @@ -229,7 +242,7 @@ bool Particle::update() p = mChildParticles.erase(p); } } - if (!mAlive && mChildParticles.empty() && mAutoDelete) + if (mAlive != ALIVE && mChildParticles.empty() && mAutoDelete) { return false; } @@ -329,13 +342,39 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, // Look for additional emitters for this particle for_each_xml_child_node(emitterNode, effectChildNode) { - if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter")) - continue; - - ParticleEmitter *newEmitter; - newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, - rotation); - newParticle->addEmitter(newEmitter); + if (xmlStrEqual(emitterNode->name, BAD_CAST "emitter")) + { + ParticleEmitter *newEmitter; + newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap, + rotation); + newParticle->addEmitter(newEmitter); + } + else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect")) + { + std::string deathEffect = (const char*)emitterNode->xmlChildrenNode->content; + char deathEffectConditions = 0x00; + if (XML::getBoolProperty(emitterNode, "on-floor", true)) + { + deathEffectConditions += Particle::DEAD_FLOOR; + } + if (XML::getBoolProperty(emitterNode, "on-sky", true)) + { + deathEffectConditions += Particle::DEAD_SKY; + } + if (XML::getBoolProperty(emitterNode, "on-other", false)) + { + deathEffectConditions += Particle::DEAD_OTHER; + } + if (XML::getBoolProperty(emitterNode, "on-impact", true)) + { + deathEffectConditions += Particle::DEAD_IMPACT; + } + if (XML::getBoolProperty(emitterNode, "on-timeout", true)) + { + deathEffectConditions += Particle::DEAD_TIMEOUT; + } + newParticle->setDeathEffect(deathEffect, deathEffectConditions); + } } mChildParticles.push_back(newParticle); @@ -406,13 +445,6 @@ float Particle::getCurrentAlpha() const return alpha; } -void Particle::setMap(Map *map) -{ - mMap = map; - if (mMap) - setSpriteIterator(mMap->addSprite(this)); -} - void Particle::clear() { delete_all(mChildEmitters); |