From 3925d9c41709dece19fe60c0e4bb111247f1886e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 26 Oct 2008 15:41:57 +0000 Subject: Merged revisions 4302,4338,4360-4362,4526,4528,4534,4547 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r4302 | crush_tmw | 2008-05-28 18:51:26 +0200 (Wed, 28 May 2008) | 1 line Changed the way particle emitter skip is handled to make linear and circular emitters work with particleEmitterSkip enabled. ........ r4338 | crush_tmw | 2008-06-05 20:41:39 +0200 (Thu, 05 Jun 2008) | 1 line Lowered default particle detail level. ........ r4360 | crush_tmw | 2008-06-23 16:44:20 +0200 (Mon, 23 Jun 2008) | 1 line Implemented "alpha" particle property. ........ r4361 | crush_tmw | 2008-06-23 22:20:05 +0200 (Mon, 23 Jun 2008) | 1 line Forgot changelog with last commit. ........ r4362 | crush_tmw | 2008-06-24 14:29:33 +0200 (Tue, 24 Jun 2008) | 1 line Added particle property "follow-parent" which makes the particle move when its parent particle is moved. ........ r4526 | crush_tmw | 2008-08-24 20:52:00 +0200 (Sun, 24 Aug 2008) | 1 line Added new particle emitter property "output-pause" which allows to define a fixed (or random) interval between two outputs. ........ r4528 | crush_tmw | 2008-08-24 20:58:39 +0200 (Sun, 24 Aug 2008) | 1 line fix for an error in the last commit ........ r4534 | b_lindeijer | 2008-08-27 20:48:13 +0200 (Wed, 27 Aug 2008) | 3 lines Renamed "randomnes" to "randomness", so that it won't show up as part of Fate's patch. ........ r4547 | crush_tmw | 2008-08-29 00:44:43 +0200 (Fri, 29 Aug 2008) | 1 line Added output-pause to copy constructor of particle emitters. ........ --- ChangeLog | 34 ++++++++++++++++++++++++++++++++++ src/imageparticle.cpp | 2 +- src/particle.cpp | 27 ++++++++++++++++++++------- src/particle.h | 33 ++++++++++++++++++++++++++++++--- src/particleemitter.cpp | 41 ++++++++++++++++++++++++++++++++++++----- src/particleemitter.h | 13 +++++++++---- src/textparticle.cpp | 4 ++-- 7 files changed, 132 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 938fd1db..52c3df51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -147,6 +147,22 @@ another template to make deleting all values in a container easier. Inspired by qDeleteAll() from Qt. +2008-08-28 Philipp Sehmisch + + * src/particleemitter.cpp: Added output-pause to copy constructor. + +2008-08-27 Bjørn Lindeijer + + * src/particleemitter.h, src/particle.h, src/particleemitter.cpp, + src/particle.cpp: Renamed "randomnes" to "randomness", so that it + won't show up as part of Fate's patch. + +2008-08-24 Philipp Sehmisch + + * src/particleemitter.cpp, src/particleemitter.h: Added new particle + emitter property "output-pause" which allows to define a fixed (or + random) interval between two outputs. + 2008-08-20 Roderic Morris * src/gui/guildlistbox.cpp, src/gui/guildwindow.h, @@ -292,6 +308,18 @@ * src/net/guildhandler.cpp, src/net/protocol.h: Handle guild list update events, and update protocol definitions. +2008-06-24 Philipp Sehmisch + + * src/particle.cpp, src/particle.h, src/particleemitter.cpp, + src/particleemitter.h: Added particle property "follow-parent" which + makes the particle move when its parent particle is moved. + +2008-06-23 Philipp Sehmisch + + * src/imageparticle.cpp, src/particle.cpp, src/particle.h, + src/particleemitter.cpp, src/particleemitter.h, src/textparticle.cpp: + Implemented "alpha" particle property. + 2008-06-14 Roderic Morris * src/gui/viewport.cpp, data/graphics/images/CMakeLists.txt, @@ -336,6 +364,12 @@ announce messages and private messages. Don't cut off the last character from pm recipient's name. Got rid of old eAthena code. +2008-05-28 Philipp Sehmisch + + * src/particle.cpp: Changed the way particle emitter skip is handled + to make linear and circular emitters work with particleEmitterSkip + enabled. + 2008-05-22 Roderic Morris * src/gui/widgets/tab.cpp, src/utils/sha256.cpp: Fix compile errors diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index 17581a2a..965434b0 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -56,7 +56,7 @@ void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const return; } - float alphafactor = 1.0f; + float alphafactor = mAlpha; if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) alphafactor *= (float) mLifetimeLeft / (float) mFadeOut; diff --git a/src/particle.cpp b/src/particle.cpp index ba5386f6..c59d2c03 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -57,11 +57,13 @@ Particle::Particle(Map *map): mLifetimePast(0), mFadeOut(0), mFadeIn(0), + mAlpha(1.0f), mAutoDelete(true), mMap(map), mGravity(0.0f), - mRandomnes(0), + mRandomness(0), mBounce(0.0f), + mFollow(false), mTarget(NULL), mAcceleration(0.0f), mInvDieDistance(-1.0f), @@ -77,7 +79,7 @@ Particle::setupEngine() { Particle::maxCount = (int)config.getValue("particleMaxCount", 3000); Particle::fastPhysics = (int)config.getValue("particleFastPhysics", 0); - Particle::emitterSkip = (int)config.getValue("particleEmitterSkip", 0) + 1; + Particle::emitterSkip = (int)config.getValue("particleEmitterSkip", 1) + 1; disableAutoDelete(); logger->log("Particle engine set up"); } @@ -94,6 +96,8 @@ Particle::update() mAlive = false; } + Vector oldPos = mPos; + if (mAlive) { //calculate particle movement @@ -135,11 +139,11 @@ Particle::update() } } - if (mRandomnes > 0) + if (mRandomness > 0) { - mVelocity.x += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVelocity.y += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVelocity.z += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocity.x += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; + mVelocity.y += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; + mVelocity.z += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; } mVelocity.z -= mGravity; @@ -170,7 +174,7 @@ Particle::update() } // Update child emitters - if (mLifetimePast%Particle::emitterSkip == 0) + if ((mLifetimePast-1)%Particle::emitterSkip == 0) { for ( EmitterIterator e = mChildEmitters.begin(); e != mChildEmitters.end(); @@ -190,10 +194,19 @@ Particle::update() } } + Vector change = mPos - oldPos; + // Update child particles + for (ParticleIterator p = mChildParticles.begin(); p != mChildParticles.end();) { + //move particle with its parent if desired + if ((*p)->doesFollow()) + { + (*p)->moveBy(change); + } + //update particle if ((*p)->update()) { p++; diff --git a/src/particle.h b/src/particle.h index 1859fe62..7b46a641 100644 --- a/src/particle.h +++ b/src/particle.h @@ -162,6 +162,10 @@ class Particle : public Sprite moveBy(float x, float y, float z) { mPos.x += x; mPos.y += y; mPos.z += z; } + void + moveBy (Vector change) + { mPos += change; } + /** * Sets the time in game ticks until the particle is destroyed. */ @@ -185,6 +189,13 @@ class Particle : public Sprite setFadeIn(int fadeIn) { mFadeIn = fadeIn; } + /** + * Sets the alpha value of the particle + */ + void + setAlpha(float alpha) + { mAlpha = alpha; } + /** * Sets the sprite iterator of the particle on the current map to make * it easier to remove the particle from the map when it is destroyed. @@ -218,8 +229,8 @@ class Particle : public Sprite * Sets the ammount of random vector changes */ void - setRandomnes(int r) - { mRandomnes = r; } + setRandomness(int r) + { mRandomness = r; } /** * Sets the ammount of velocity particles retain after @@ -229,6 +240,20 @@ class Particle : public Sprite setBounce(float bouncieness) { mBounce = bouncieness; } + /** + * Sets the flag if the particle is supposed to be moved by its parent + */ + void + setFollow(bool follow) + { mFollow = follow; } + + /** + * Gets the flag if the particle is supposed to be moved by its parent + */ + bool + doesFollow() + { return mFollow; } + /** * Makes the particle move toward another particle with a * given acceleration and momentum @@ -267,6 +292,7 @@ class Particle : public Sprite int mLifetimePast; /**< Age of the particle in game ticks*/ int mFadeOut; /**< Lifetime in game ticks left where fading out begins*/ int mFadeIn; /**< Age in game ticks where fading in is finished*/ + float mAlpha; /**< Opacity of the graphical representation of the particle */ private: // generic properties @@ -279,8 +305,9 @@ class Particle : public Sprite // dynamic particle Vector mVelocity; /**< Speed in pixels per game-tick. */ float mGravity; /**< Downward acceleration in pixels per game-tick. */ - int mRandomnes; /**< Ammount of random vector change */ + int mRandomness; /**< Ammount of random vector change */ float mBounce; /**< How much the particle bounces off when hitting the ground */ + bool mFollow; /**< is this particle moved when its parent particle moves? */ // follow-point particles Particle *mTarget; /**< The particle that attracts this particle*/ diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 23c6879e..cd80fb58 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -39,6 +39,7 @@ #define DEG_RAD_FACTOR 0.017453293f ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *map, int rotation): + mOutputPauseLeft(0), mParticleImage(0) { mMap = map; @@ -52,8 +53,9 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * mParticleAngleVertical.set(0.0f); mParticlePower.set(0.0f); mParticleGravity.set(0.0f); - mParticleRandomnes.set(0); + mParticleRandomness.set(0); mParticleBounce.set(0.0f); + mParticleFollow = false; mParticleAcceleration.set(0.0f); mParticleDieDistance.set(-1.0f); mParticleMomentum.set(1.0f); @@ -61,6 +63,8 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * mParticleFadeOut.set(0); mParticleFadeIn.set(0); mOutput.set(1); + mOutputPause.set(0); + mParticleAlpha.set(1.0f); for_each_xml_child_node(propertyNode, emitterNode) { @@ -114,9 +118,9 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * { mParticleGravity = readMinMax(propertyNode, 0.0f); } - else if (name == "randomnes") + else if (name == "randomnes" || name == "randomness") // legacy bug { - mParticleRandomnes = readMinMax(propertyNode, 0); + mParticleRandomness = readMinMax(propertyNode, 0); } else if (name == "bounce") { @@ -132,6 +136,11 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * mOutput = readMinMax(propertyNode, 0); mOutput.maxVal +=1; } + else if (name == "output-pause") + { + mOutputPause = readMinMax(propertyNode, 0); + mOutputPauseLeft = mOutputPause.value(); + } else if (name == "acceleration") { mParticleAcceleration = readMinMax(propertyNode, 0.0f); @@ -152,6 +161,14 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map * { mParticleFadeIn = readMinMax(propertyNode, 0); } + else if (name == "alpha") + { + mParticleAlpha = readMinMax(propertyNode, 1.0f); + } + else if (name == "follow-parent") + { + mParticleFollow = true; + } else { logger->log("Particle Engine: Warning, unknown emitter property \"%s\"", @@ -249,8 +266,9 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) mParticleAngleVertical = o.mParticleAngleVertical; mParticlePower = o.mParticlePower; mParticleGravity = o.mParticleGravity; - mParticleRandomnes = o.mParticleRandomnes; + mParticleRandomness = o.mParticleRandomness; mParticleBounce = o.mParticleBounce; + mParticleFollow = o.mParticleFollow; mParticleTarget = o.mParticleTarget; mParticleAcceleration = o.mParticleAcceleration; mParticleDieDistance = o.mParticleDieDistance; @@ -258,12 +276,16 @@ ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter &o) mParticleLifetime = o.mParticleLifetime; mParticleFadeOut = o.mParticleFadeOut; mParticleFadeIn = o.mParticleFadeIn; + mParticleAlpha = o.mParticleAlpha; mMap = o.mMap; mOutput = o.mOutput; + mOutputPause = o.mOutputPause; mParticleImage = o.mParticleImage; mParticleAnimation = o.mParticleAnimation; mParticleChildEmitters = o.mParticleChildEmitters; + mOutputPauseLeft = 0; + if (mParticleImage) mParticleImage->incRef(); return *this; @@ -294,6 +316,13 @@ ParticleEmitter::createParticles() { std::list newParticles; + if (mOutputPauseLeft > 0) + { + mOutputPauseLeft--; + return newParticles; + } + mOutputPauseLeft = mOutputPause.value(); + for (int i = mOutput.value(); i > 0; i--) { // Limit maximum particles @@ -328,9 +357,10 @@ ParticleEmitter::createParticles() sin(angleH) * cos(angleV) * power, sin(angleV) * power); - newParticle->setRandomnes(mParticleRandomnes.value()); + newParticle->setRandomness(mParticleRandomness.value()); newParticle->setGravity(mParticleGravity.value()); newParticle->setBounce(mParticleBounce.value()); + newParticle->setFollow(mParticleFollow); newParticle->setDestination(mParticleTarget, mParticleAcceleration.value(), @@ -341,6 +371,7 @@ ParticleEmitter::createParticles() newParticle->setLifetime(mParticleLifetime.value()); newParticle->setFadeOut(mParticleFadeOut.value()); newParticle->setFadeIn(mParticleFadeIn.value()); + newParticle->setAlpha(mParticleAlpha.value()); for (std::list::iterator i = mParticleChildEmitters.begin(); i != mParticleChildEmitters.end(); diff --git a/src/particleemitter.h b/src/particleemitter.h index f5ca6232..c237c1ba 100644 --- a/src/particleemitter.h +++ b/src/particleemitter.h @@ -97,8 +97,9 @@ class ParticleEmitter * Vector changing of particles: */ MinMax mParticleGravity; - MinMax mParticleRandomnes; + MinMax mParticleRandomness; MinMax mParticleBounce; + bool mParticleFollow; /* * Properties of targeting particles: @@ -118,11 +119,15 @@ class ParticleEmitter Map *mMap; /**< Map the particles are spawned on */ MinMax mOutput; /**< Number of particles spawned per update */ + MinMax mOutputPause; /**< Pause in frames between two spawns */ + int mOutputPauseLeft; + /* + * Graphical representation of the particle + */ Image *mParticleImage; /**< Particle image, if used */ - - /** Filename of particle animation file */ - Animation mParticleAnimation; + Animation mParticleAnimation; /**< Filename of particle animation file */ + MinMax mParticleAlpha; /**< Opacity of the graphical representation of the particles */ /** List of emitters the spawned particles are equipped with */ std::list mParticleChildEmitters; diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 4bc859cd..89466006 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -45,7 +45,7 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const int screenX = (int) mPos.x + offsetX; int screenY = (int) mPos.y - (int) mPos.z + offsetY; - int alpha = 255; + float alpha = mAlpha * 255.0f; if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) { @@ -60,6 +60,6 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); - graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, alpha)); + graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } -- cgit v1.2.3-70-g09d2