diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-08-23 13:43:17 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-08-23 13:43:17 +0000 |
commit | 4b8df221acc3bd3e681357df912bdbc7a1ce6c3f (patch) | |
tree | 3b3d196dcbeacc67b1479d56e3eccc14dfef07e1 | |
parent | 4346b429cc875a85095fff271a8d82a46c2cfc91 (diff) | |
download | mana-4b8df221acc3bd3e681357df912bdbc7a1ce6c3f.tar.gz mana-4b8df221acc3bd3e681357df912bdbc7a1ce6c3f.tar.bz2 mana-4b8df221acc3bd3e681357df912bdbc7a1ce6c3f.tar.xz mana-4b8df221acc3bd3e681357df912bdbc7a1ce6c3f.zip |
Removed two useless popup related methods, used generic close button
functionality for the debug window and renamed Particle::mVector to
Particle::mVelocity for clarity.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/being.cpp | 28 | ||||
-rw-r--r-- | src/gui/debugwindow.cpp | 14 | ||||
-rw-r--r-- | src/gui/debugwindow.h | 9 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 16 | ||||
-rw-r--r-- | src/gui/viewport.h | 12 | ||||
-rw-r--r-- | src/particle.cpp | 69 | ||||
-rw-r--r-- | src/particle.h | 84 | ||||
-rw-r--r-- | src/particleemitter.cpp | 30 | ||||
-rw-r--r-- | src/textparticle.cpp | 11 | ||||
-rw-r--r-- | src/textparticle.h | 17 |
11 files changed, 129 insertions, 172 deletions
@@ -1,4 +1,13 @@ -2007-08-22 Bjørn Lindeijer <bjorn@lindeijer.nl> +2007-08-23 Bjørn Lindeijer <bjorn@lindeijer.nl> + + * src/gui/viewport.h, src/gui/viewport.cpp: Removed two useless popup + related methods. + * src/gui/debugwindow.h, src/gui/debugwindow.cpp: Use generic close + button functionality. + * src/particle.h, src/particleemitter.cpp, src/particle.cpp: Renamed + Particle::mVector to Particle::mVelocity for clarity. + +2007-08-22 Bjørn Lindeijer <bjorn@lindeijer.nl> * src/gui/itemshortcutcontainer.h: Fixed compiler warning. * src/CMakeLists.txt, src/Makefile.am: Updated source lists. diff --git a/src/being.cpp b/src/being.cpp index 4c3c03f6..a1c8faf3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -162,7 +162,7 @@ Being::setSpeech(const std::string &text, Uint32 time) void Being::takeDamage(int amount) { - gcn::Font* font; + gcn::Font *font; std::string damage = amount ? toString(amount) : "miss"; // Selecting the right color @@ -172,8 +172,9 @@ Being::takeDamage(int amount) } else { - // hit particle effect - controlParticle(particleEngine->addEffect("graphics/particles/hit.particle.xml", 0, 0)); + // Hit particle effect + controlParticle(particleEngine->addEffect( + "graphics/particles/hit.particle.xml", 0, 0)); if (getType() == MONSTER) { @@ -185,7 +186,7 @@ Being::takeDamage(int amount) } } - // show damage number + // Show damage number particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, mPx + 16, mPy + 16); } @@ -193,13 +194,11 @@ Being::takeDamage(int amount) void Being::showXP(int amount) { - gcn::Font* font; - std::string xp = (amount ? toString(amount) : "") + " xp"; + const std::string xp = toString(amount) + " xp"; - font = hitYellowFont; - - // show xp number - particleEngine->addTextRiseFadeOutEffect(xp, font, mPx + 16, mPy - 16); + // Show XP number + particleEngine->addTextRiseFadeOutEffect(xp, hitYellowFont, + mPx + 16, mPy - 16); } void @@ -214,7 +213,7 @@ void Being::setMap(Map *map) { // Remove sprite from potential previous map - if (mMap != NULL) + if (mMap) { mMap->removeSprite(mSpriteIterator); } @@ -222,12 +221,12 @@ Being::setMap(Map *map) mMap = map; // Add sprite to potential new map - if (mMap != NULL) + if (mMap) { mSpriteIterator = mMap->addSprite(this); } - //clear particle effect list because child particles became invalid + // Clear particle effect list because child particles became invalid mChildParticleEffects.clear(); } @@ -236,7 +235,8 @@ Being::controlParticle(Particle *particle) { if (particle) { - particle->disableAutoDelete(); //the effect may not die without the beings permission or we segvault + // The effect may not die without the beings permission or we segfault + particle->disableAutoDelete(); mChildParticleEffects.push_back(particle); } } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index ebf7d974..d6d99307 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -44,6 +44,7 @@ DebugWindow::DebugWindow(): setWindowName("Debug"); setResizable(true); + setCloseButton(true); setDefaultSize(0, 0, 400, 100); loadWindowState(); @@ -62,15 +63,11 @@ DebugWindow::DebugWindow(): mParticleCountLabel = new gcn::Label("[Particle count: 0]"); mParticleCountLabel->setPosition(100, 60); - Button *closeButton = new Button("Close", "close", this); - closeButton->setPosition(5, 60); - add(mFPSLabel); add(mMusicFileLabel); add(mMapFileLabel); add(mTileMouseLabel); add(mParticleCountLabel); - add(closeButton); } void @@ -108,12 +105,3 @@ DebugWindow::logic() +"]"); mParticleCountLabel->adjustSize(); } - -void -DebugWindow::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "close") - { - setVisible(false); - } -} diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index d082b2ca..9b6f2017 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -33,11 +33,11 @@ #include "../guichanfwd.h" /** - * The chat window. + * The debug window. * * \ingroup Interface */ -class DebugWindow : public Window, public gcn::ActionListener +class DebugWindow : public Window { public: /** @@ -50,11 +50,6 @@ class DebugWindow : public Window, public gcn::ActionListener */ void logic(); - /** - * Performs action. - */ - void action(const gcn::ActionEvent &event); - private: gcn::Label *mMusicFileLabel, *mMapFileLabel; gcn::Label *mTileMouseLabel, *mFPSLabel; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 6c89d107..4c64c627 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -371,12 +371,12 @@ Viewport::mousePressed(gcn::MouseEvent &event) if ((being = beingManager->findBeing(tilex, tiley)) && being->getType() != Being::LOCALPLAYER) { - showPopup(event.getX(), event.getY(), being); + mPopupMenu->showPopup(event.getX(), event.getY(), being); return; } else if((floorItem = floorItemManager->findByCoordinates(tilex, tiley))) { - showPopup(event.getX(), event.getY(), floorItem); + mPopupMenu->showPopup(event.getX(), event.getY(), floorItem); return; } } @@ -474,18 +474,6 @@ Viewport::showPopup(int x, int y, Item *item) } void -Viewport::showPopup(int x, int y, FloorItem *floorItem) -{ - mPopupMenu->showPopup(x, y, floorItem); -} - -void -Viewport::showPopup(int x, int y, Being *being) -{ - mPopupMenu->showPopup(x, y, being); -} - -void Viewport::optionChanged(const std::string &name) { mScrollLaziness = (int) config.getValue("ScrollLaziness", 32); diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 16136cee..eeb31bae 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -130,18 +130,6 @@ class Viewport : public WindowContainer, public gcn::MouseListener, private: /** - * Shows a popup for a floor item. - * TODO Find some way to get rid of FloorItem here - */ - void showPopup(int x, int y, FloorItem *floorItem); - - /** - * Shows a popup for a being. - * TODO Find some way to get rid of Being here - */ - void showPopup(int x, int y, Being *being); - - /** * Helper function for loading target cursors */ void diff --git a/src/particle.cpp b/src/particle.cpp index 8e47fb06..2d0873ff 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -59,7 +59,7 @@ Particle::Particle(Map *map): mFadeIn(0), mAutoDelete(true), mMap(map), - mVectorX(0.0f), mVectorY(0.0f), mVectorZ(0.0f), + mVelocityX(0.0f), mVelocityY(0.0f), mVelocityZ(0.0f), mGravity(0.0f), mRandomnes(0), mBounce(0.0f), @@ -117,9 +117,9 @@ Particle::update() if (mMomentum != 1.0f) { - mVectorX *= mMomentum; - mVectorY *= mMomentum; - mVectorZ *= mMomentum; + mVelocityX *= mMomentum; + mVelocityY *= mMomentum; + mVelocityZ *= mMomentum; } if (mTarget && mAcceleration != 0.0f) @@ -152,25 +152,25 @@ Particle::update() mAlive = false; } float accFactor = invHypotenuse * mAcceleration; - mVectorX -= distX * accFactor; - mVectorY -= distY * accFactor; - mVectorZ -= distZ * accFactor; + mVelocityX -= distX * accFactor; + mVelocityY -= distY * accFactor; + mVelocityZ -= distZ * accFactor; } } if (mRandomnes > 0) { - mVectorX += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVectorY += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; - mVectorZ += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocityX += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocityY += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; + mVelocityZ += (rand()%mRandomnes - rand()%mRandomnes) / 1000.0f; } - mVectorZ -= mGravity; + mVelocityZ -= mGravity; // Update position - mPosX += mVectorX; - mPosY += mVectorY * SIN45; - mPosZ += mVectorZ * SIN45; + mPosX += mVelocityX; + mPosY += mVelocityY * SIN45; + mPosZ += mVelocityZ * SIN45; // Update other stuff if (mLifetimeLeft > 0) @@ -184,9 +184,9 @@ Particle::update() if (mBounce > 0.0f) { mPosZ *= -mBounce; - mVectorX *= mBounce; - mVectorY *= mBounce; - mVectorZ *= -mBounce; + mVelocityX *= mBounce; + mVelocityY *= mBounce; + mVelocityZ *= -mBounce; } else { mAlive = false; @@ -195,10 +195,8 @@ Particle::update() } // Update child particles - for ( ParticleIterator p = mChildParticles.begin(); - p != mChildParticles.end(); - - ) + for (ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end();) { if ((*p)->update()) { @@ -217,14 +215,9 @@ Particle::update() return true; } - -void Particle::draw(Graphics *graphics, int offsetX, int offsetY) const -{ -} - - Particle* -Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) +Particle::addEffect(const std::string &particleEffectFile, + int pixelX, int pixelY) { Particle *newParticle = NULL; @@ -317,17 +310,16 @@ Particle::addEffect(std::string particleEffectFile, int pixelX, int pixelY) Particle* -Particle::addTextSplashEffect(std::string text, +Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, int x, int y) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, font); newParticle->setPosition(x, y, 0); - newParticle->setVector ( ((rand()%100) - 50) / 200.0f, // X vector - ((rand()%100) - 50) / 200.0f, // Y vector - ((rand()%100) / 200.0f) + 4.0f // Z vector - ); + newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X + ((rand() % 100) - 50) / 200.0f, // Y + ((rand() % 100) / 200.0f) + 4.0f); // Z newParticle->setGravity(0.1f); newParticle->setBounce(0.5f); newParticle->setLifetime(200); @@ -339,15 +331,12 @@ Particle::addTextSplashEffect(std::string text, } Particle* -Particle::addTextRiseFadeOutEffect(std::string text, gcn::Font *font, - int x, int y) +Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, + int x, int y) { Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); newParticle->setPosition(x, y, 0); - newParticle->setVector ( 0.0f, // X vector - 0.0f, // Y vector - 0.5f // Z vector - ); + newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); newParticle->setLifetime(300); newParticle->setFadeOut(50); @@ -363,8 +352,6 @@ Particle::setMap(Map *map) { mMap = map; if (mMap) setSpriteIterator(mMap->addSprite(this)); - - // TODO: Create map emitters based on emitter data in map data } diff --git a/src/particle.h b/src/particle.h index 6d180ecc..e8b835ba 100644 --- a/src/particle.h +++ b/src/particle.h @@ -67,43 +67,37 @@ class Particle : public Sprite ~Particle(); /** - * Deletes all child particles and emitters + * Deletes all child particles and emitters. */ void clear(); /** * Gives a particle the properties of an engine root particle and loads - * the particle-related config settings + * the particle-related config settings. */ void setupEngine(); /** * Updates particle position, returns false when the particle should - * be deleted + * be deleted. */ virtual bool update(); /** - * Draws the particle image + * Draws the particle image. */ virtual void - draw(Graphics *graphics, int offsetX, int offsetY) const; + draw(Graphics *graphics, int offsetX, int offsetY) const {} /** - * Necessary for sorting with the other sprites + * Necessary for sorting with the other sprites. */ virtual int getPixelY() const - { - return (int)(mPosY + mPosZ) - 64; - }; - - /* - Basic Particle properties: - */ + { return (int) (mPosY + mPosZ) - 64; } /** * Sets the map the particle is on. @@ -115,21 +109,23 @@ class Particle : public Sprite * particleEffectFile. */ Particle* - addEffect(std::string particleEffectFile, int pixelX, int pixelY); + addEffect(const std::string &particleEffectFile, + int pixelX, int pixelY); /** * Creates a standalone text particle. */ Particle* - addTextSplashEffect(std::string text, int colorR, int colorG, int colorB, + addTextSplashEffect(const std::string &text, + int colorR, int colorG, int colorB, gcn::Font *font, int x, int y); /** * Creates a standalone text particle. */ Particle* - addTextRiseFadeOutEffect(std::string text, gcn::Font *font, - int x, int y); + addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, + int x, int y); /** * Adds an emitter to the particle. @@ -139,14 +135,14 @@ class Particle : public Sprite { mChildEmitters.push_back(emitter); } /** - * Sets the position in 3 dimensional space in pixels relative to map + * Sets the position in 3 dimensional space in pixels relative to map. */ void setPosition(float x, float y, float z) { mPosX = x; mPosY = y; mPosZ = z; } /** - * Sets the position in 2 dimensional space in pixels relative to map + * Sets the position in 2 dimensional space in pixels relative to map. */ void setPosition(float x, float y) @@ -177,7 +173,7 @@ class Particle : public Sprite /** * Sets the age of the pixel in game ticks where the particle has - * faded in completely + * faded in completely. */ void setFadeOut (int fadeOut) @@ -185,7 +181,7 @@ class Particle : public Sprite /** * Sets the remaining particle lifetime where the particle starts to - * fade out + * fade out. */ void setFadeIn (int fadeIn) @@ -193,32 +189,32 @@ class Particle : public Sprite /** * 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 + * it easier to remove the particle from the map when it is destroyed. */ void setSpriteIterator(std::list<Sprite*>::iterator spriteIterator) { mSpriteIterator = spriteIterator; } /** - * Gets the sprite iterator of the particle on the current map + * Gets the sprite iterator of the particle on the current map. */ std::list<Sprite*>::iterator getSpriteIterator() const { return mSpriteIterator; } /** - * Sets the current velocity in 3 dimensional space + * Sets the current velocity in 3 dimensional space. */ void - setVector(float x, float y, float z) - { mVectorX = x; mVectorY = y; mVectorZ = z; } + setVelocity(float x, float y, float z) + { mVelocityX = x; mVelocityY = y; mVelocityZ = z; } /** - * Sets the downward acceleration + * Sets the downward acceleration. */ void - setGravity(float g) - { mGravity = g; } + setGravity(float gravity) + { mGravity = gravity; } /** * Sets the ammount of random vector changes @@ -244,8 +240,8 @@ class Particle : public Sprite /** * Sets the distance in pixel the particle can come near the target - * particle before it is destroyed. Does only make sense after a - * target particle has been set using setDestination. + * particle before it is destroyed. Does only make sense after a target + * particle has been set using setDestination. */ void setDieDistance(float dist) { mInvDieDistance = 1.0f / dist; } @@ -254,7 +250,7 @@ class Particle : public Sprite { return mAlive; } /** - * Manually marks the particle for deletion + * Manually marks the particle for deletion. */ void kill() { mAlive = false; mAutoDelete = true; } @@ -276,17 +272,21 @@ class Particle : public Sprite private: // generic properties - bool mAutoDelete; /**< May the particle request its deletion by the parent particle?*/ - Map *mMap; /**< Map the particle is on*/ + bool mAutoDelete; /**< May the particle request its deletion by the parent particle? */ + Map *mMap; /**< Map the particle is on. */ std::list<Sprite*>::iterator mSpriteIterator; /**< iterator of the particle on the current map */ - Emitters mChildEmitters; /**< List of child emitters*/ - Particles mChildParticles; /**< List of particles controlled by this particle*/ - //dynamic particle - float mVectorX, mVectorY, mVectorZ; /**< Speed in 3 dimensional space in pixels per game-tick */ - float mGravity; /**< Downward acceleration in pixels per game-tick²*/ - int mRandomnes; /**< Ammount of random vector change*/ - float mBounce; /**< How much the particle bounces off when hitting the ground*/ - //follow-point particles + Emitters mChildEmitters; /**< List of child emitters. */ + Particles mChildParticles; /**< List of particles controlled by this particle */ + + // dynamic particle + float mVelocityX; /**< X speed in pixels per game-tick. */ + float mVelocityY; /**< Y speed in pixels per game-tick. */ + float mVelocityZ; /**< Z speed in pixels per game-tick. */ + float mGravity; /**< Downward acceleration in pixels per game-tick² */ + int mRandomnes; /**< Ammount of random vector change */ + float mBounce; /**< How much the particle bounces off when hitting the ground */ + + // follow-point particles Particle *mTarget; /**< The particle that attracts this particle*/ float mAcceleration; /**< Acceleration towards the target particle in pixels per game-tick²*/ float mInvDieDistance; /**< Distance in pixels from the target particle that causes the destruction of the particle*/ diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 5b5e86b9..ea7b87d6 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -248,10 +248,9 @@ ParticleEmitter::readMinMax(xmlNodePtr propertyNode, T def) {
MinMax<T> retval;
- def = (T)XML::getFloatProperty(propertyNode, "value", (double)def);
- retval.set ( (T)XML::getFloatProperty(propertyNode, "min", (double)def),
- (T)XML::getFloatProperty(propertyNode, "max", (double)def)
- );
+ def = (T) XML::getFloatProperty(propertyNode, "value", (double) def);
+ retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def),
+ (T) XML::getFloatProperty(propertyNode, "max", (double) def));
return retval;
}
@@ -284,19 +283,17 @@ ParticleEmitter::createParticles() newParticle->setPosition(
- mParticlePosX.value(),
- mParticlePosY.value(),
- mParticlePosZ.value()
- );
+ mParticlePosX.value(),
+ mParticlePosY.value(),
+ mParticlePosZ.value());
float angleH = mParticleAngleHorizontal.value();
float angleV = mParticleAngleVertical.value();
float power = mParticlePower.value();
- newParticle->setVector(
- cos(angleH) * cos(angleV) * power,
- sin(angleH) * cos(angleV) * power,
- sin(angleV) * power
- );
+ newParticle->setVelocity(
+ cos(angleH) * cos(angleV) * power,
+ sin(angleH) * cos(angleV) * power,
+ sin(angleV) * power);
newParticle->setRandomnes(mParticleRandomnes.value());
newParticle->setGravity(mParticleGravity.value());
@@ -312,10 +309,9 @@ ParticleEmitter::createParticles() newParticle->setFadeOut(mParticleFadeOut.value());
newParticle->setFadeIn(mParticleFadeIn.value());
- for ( std::list<ParticleEmitter>::iterator i = mParticleChildEmitters.begin();
- i != mParticleChildEmitters.end();
- i++
- )
+ for (std::list<ParticleEmitter>::iterator i = mParticleChildEmitters.begin();
+ i != mParticleChildEmitters.end();
+ i++)
{
newParticle->addEmitter(new ParticleEmitter(*i));
}
diff --git a/src/textparticle.cpp b/src/textparticle.cpp index dd01d2fe..4ea4dbdc 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -26,7 +26,8 @@ #include "graphics.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, gcn::Font *font): + int colorR, int colorG, int colorB, + gcn::Font *font): Particle(map), mText(text), mTextFont(font), @@ -41,8 +42,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const if (!mAlive) return; - int screenX = (int)mPosX + offsetX; - int screenY = (int)mPosY - int(mPosZ) + offsetY; + int screenX = (int) mPosX + offsetX; + int screenY = (int) mPosY - (int) mPosZ + offsetY; int alpha = 255; @@ -50,7 +51,7 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const { alpha *= mLifetimeLeft; alpha /= mFadeOut; - }; + } if (mLifetimePast < mFadeIn) { @@ -59,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, alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index b365c885..134405bb 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,21 +33,26 @@ class TextParticle : public Particle { public: + /** + * Constructor. + */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, gcn::Font *font); + int colorR, int colorG, int colorB, + gcn::Font *font); /** - * Draws the particle image + * Draws the particle image. */ virtual void draw(Graphics *graphics, int offsetX, int offsetY) const; // hack to improve text visibility - virtual int getPixelY() const { return (int)(mPosY + mPosZ); } + virtual int getPixelY() const + { return (int) (mPosY + mPosZ); } private: - std::string mText; /**< Text of the particle */ - gcn::Font *mTextFont; /**< Font used for drawing the text */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text */ + std::string mText; /**< Text of the particle. */ + gcn::Font *mTextFont; /**< Font used for drawing the text. */ + int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ }; #endif |