summaryrefslogtreecommitdiff
path: root/src/particle/particleengine.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-03-16 19:13:22 +0300
committerAndrei Karas <akaras@inbox.ru>2016-03-16 19:36:44 +0300
commitea31dc2bd04362265449afa9e54398f4cf628e74 (patch)
tree7ae86f9638dbd2658048537e7a4ced52d5c5c21f /src/particle/particleengine.cpp
parentac65e2c9b72e35a9e5a1a84da57ecdbd41e5923e (diff)
downloadmv-ea31dc2bd04362265449afa9e54398f4cf628e74.tar.gz
mv-ea31dc2bd04362265449afa9e54398f4cf628e74.tar.bz2
mv-ea31dc2bd04362265449afa9e54398f4cf628e74.tar.xz
mv-ea31dc2bd04362265449afa9e54398f4cf628e74.zip
Remove unused functions from ParticleEngine.
Diffstat (limited to 'src/particle/particleengine.cpp')
-rw-r--r--src/particle/particleengine.cpp234
1 files changed, 5 insertions, 229 deletions
diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp
index 1a65b51d8..cb43f5059 100644
--- a/src/particle/particleengine.cpp
+++ b/src/particle/particleengine.cpp
@@ -56,28 +56,8 @@ bool ParticleEngine::enabled = true;
const float ParticleEngine::PARTICLE_SKY = 800.0F;
ParticleEngine::ParticleEngine() :
- Actor(),
- mAlpha(1.0F),
- mLifetimeLeft(-1),
- mLifetimePast(0),
- mFadeOut(0),
- mFadeIn(0),
- mVelocity(),
- mAlive(AliveStatus::ALIVE),
- mChildEmitters(),
mChildParticles(),
- mDeathEffect(),
- mGravity(0.0F),
- mBounce(0.0F),
- mAcceleration(0.0F),
- mInvDieDistance(-1.0F),
- mMomentum(1.0F),
- mTarget(nullptr),
- mRandomness(0),
- mDeathEffectConditions(0x00),
- mAutoDelete(true),
- mAllowSizeAdjust(false),
- mFollow(false)
+ mMap(nullptr)
{
ParticleEngine::particleCount++;
}
@@ -97,161 +77,13 @@ void ParticleEngine::setupEngine() restrict2
if (!ParticleEngine::emitterSkip)
ParticleEngine::emitterSkip = 1;
ParticleEngine::enabled = config.getBoolValue("particleeffects");
- disableAutoDelete();
logger->log1("Particle engine set up");
}
-void ParticleEngine::draw(Graphics *restrict const,
- const int, const int) const restrict2
-{
-}
-
-void ParticleEngine::updateSelf() restrict2
-{
- if (mLifetimeLeft == 0 && mAlive == AliveStatus::ALIVE)
- mAlive = AliveStatus::DEAD_TIMEOUT;
-
- if (mAlive == AliveStatus::ALIVE)
- {
- // calculate particle movement
- if (mMomentum != 1.0F)
- mVelocity *= mMomentum;
-
- if (mTarget && mAcceleration != 0.0F)
- {
- Vector dist = mPos - mTarget->mPos;
- dist.x *= SIN45;
- float invHypotenuse;
-
- switch (ParticleEngine::fastPhysics)
- {
- case 1:
- invHypotenuse = fastInvSqrt(
- dist.x * dist.x + dist.y * dist.y + dist.z * dist.z);
- break;
- case 2:
- if (!dist.x)
- {
- invHypotenuse = 0;
- break;
- }
-
- invHypotenuse = 2.0F / (static_cast<float>(fabs(dist.x))
- + static_cast<float>(fabs(dist.y))
- + static_cast<float>(fabs(dist.z)));
- break;
- default:
- invHypotenuse = 1.0F / static_cast<float>(sqrt(
- dist.x * dist.x + dist.y * dist.y + dist.z * dist.z));
- break;
- }
-
- if (invHypotenuse)
- {
- if (mInvDieDistance > 0.0F && invHypotenuse > mInvDieDistance)
- mAlive = AliveStatus::DEAD_IMPACT;
- const float accFactor = invHypotenuse * mAcceleration;
- mVelocity -= dist * accFactor;
- }
- }
-
- if (mRandomness > 0)
- {
- mVelocity.x += static_cast<float>((rand() % mRandomness - rand()
- % mRandomness)) / 1000.0F;
- mVelocity.y += static_cast<float>((rand() % mRandomness - rand()
- % mRandomness)) / 1000.0F;
- mVelocity.z += static_cast<float>((rand() % mRandomness - rand()
- % mRandomness)) / 1000.0F;
- }
-
- mVelocity.z -= mGravity;
-
- // Update position
- mPos.x += mVelocity.x;
- mPos.y += mVelocity.y * SIN45;
- mPos.z += mVelocity.z * SIN45;
-
- // Update other stuff
- if (mLifetimeLeft > 0)
- mLifetimeLeft--;
-
- mLifetimePast++;
-
- if (mPos.z < 0.0F)
- {
- if (mBounce > 0.0F)
- {
- mPos.z *= -mBounce;
- mVelocity *= mBounce;
- mVelocity.z = -mVelocity.z;
- }
- else
- {
- mAlive = AliveStatus::DEAD_FLOOR;
- }
- }
- else if (mPos.z > PARTICLE_SKY)
- {
- mAlive = AliveStatus::DEAD_SKY;
- }
-
- // Update child emitters
- if (ParticleEngine::emitterSkip && (mLifetimePast - 1)
- % ParticleEngine::emitterSkip == 0)
- {
- FOR_EACH (EmitterConstIterator, e, mChildEmitters)
- {
- std::vector<Particle*> newParticles;
- (*e)->createParticles(mLifetimePast, newParticles);
- FOR_EACH (std::vector<Particle*>::const_iterator,
- it,
- newParticles)
- {
- Particle *const p = *it;
- p->moveBy(mPos);
- mChildParticles.push_back(p);
- }
- }
- }
- }
-
- // create death effect when the particle died
- if (mAlive != AliveStatus::ALIVE &&
- mAlive != AliveStatus::DEAD_LONG_AGO)
- {
- if ((CAST_U32(mAlive) & mDeathEffectConditions)
- > 0x00 && !mDeathEffect.empty())
- {
- Particle *restrict const deathEffect = particleEngine->addEffect(
- mDeathEffect, 0, 0);
- if (deathEffect)
- deathEffect->moveBy(mPos);
- }
- mAlive = AliveStatus::DEAD_LONG_AGO;
- }
-}
-
bool ParticleEngine::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;
- }
+ if (mChildParticles.empty() || !mMap)
return true;
- }
// Update child particles
@@ -273,10 +105,6 @@ bool ParticleEngine::update() restrict2
++p;
continue;
}
- // move particle with its parent if desired
- if (particle->mFollow)
- particle->moveBy(change);
-
// update particle
if (particle->update())
{
@@ -288,32 +116,9 @@ bool ParticleEngine::update() restrict2
p = mChildParticles.erase(p);
}
}
- if (mAlive != AliveStatus::ALIVE &&
- mChildParticles.empty() &&
- mAutoDelete)
- {
- return false;
- }
-
return true;
}
-void ParticleEngine::moveBy(const Vector &restrict change) restrict2
-{
- mPos += change;
- FOR_EACH (ParticleConstIterator, p, mChildParticles)
- {
- Particle *restrict const particle = *p;
- if (particle->mFollow)
- particle->moveBy(change);
- }
-}
-
-void ParticleEngine::moveTo(const float x, const float y) restrict2
-{
- moveTo(Vector(x, y, mPos.z));
-}
-
Particle *ParticleEngine::createChild() restrict2
{
Particle *const newParticle = new Particle();
@@ -394,9 +199,9 @@ Particle *ParticleEngine::addEffect(const std::string &restrict
effectChildNode, "position-y", 0));
const float offsetZ = static_cast<float>(XML::getFloatProperty(
effectChildNode, "position-z", 0));
- const Vector position(mPos.x + static_cast<float>(pixelX) + offsetX,
- mPos.y + static_cast<float>(pixelY) + offsetY,
- mPos.z + offsetZ);
+ const Vector position(static_cast<float>(pixelX) + offsetX,
+ static_cast<float>(pixelY) + offsetY,
+ offsetZ);
newParticle->moveTo(position);
const int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);
@@ -522,37 +327,8 @@ Particle *ParticleEngine::addTextRiseFadeOutEffect(const std::string &restrict
return newParticle;
}
-void ParticleEngine::adjustEmitterSize(const int w, const int h) restrict2
-{
- if (mAllowSizeAdjust)
- {
- FOR_EACH (EmitterConstIterator, e, mChildEmitters)
- (*e)->adjustSize(w, h);
- }
-}
-
-void ParticleEngine::prepareToDie() restrict2
-{
- FOR_EACH (ParticleIterator, p, mChildParticles)
- {
- Particle *restrict const particle = *p;
- if (!particle)
- continue;
- particle->prepareToDie();
- if (particle->isAlive() &&
- particle->mLifetimeLeft == -1 &&
- particle->mAutoDelete)
- {
- particle->kill();
- }
- }
-}
-
void ParticleEngine::clear() restrict2
{
- delete_all(mChildEmitters);
- mChildEmitters.clear();
-
delete_all(mChildParticles);
mChildParticles.clear();
}