diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/being.cpp | 90 | ||||
-rw-r--r-- | src/being.h | 10 | ||||
-rw-r--r-- | src/game.cpp | 4 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 5 | ||||
-rw-r--r-- | src/player.h | 8 | ||||
-rw-r--r-- | src/vector.cpp | 28 | ||||
-rw-r--r-- | src/vector.h | 68 |
9 files changed, 105 insertions, 113 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4803230..4e8654e6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -342,6 +342,8 @@ SET(SRCS textparticle.h tileset.h vector.h + effectmanager.cpp + effectmanager.h ) ADD_EXECUTABLE(aethyra ${SRCS}) diff --git a/src/Makefile.am b/src/Makefile.am index 5c759135..76773d49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -242,6 +242,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ configlistener.h \ configuration.cpp \ configuration.h \ + effectmanager.cpp \ + effectmanager.h \ engine.cpp \ engine.h \ equipment.cpp \ @@ -313,6 +315,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ textparticle.cpp \ textparticle.h \ tileset.h \ + vector.cpp \ vector.h # set the include path found by configure diff --git a/src/being.cpp b/src/being.cpp index 27bd0c57..ded3abd8 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -571,93 +571,3 @@ int Being::getHeight() const } } -struct EffectDescription -{ - std::string mGFXEffect; - std::string mSFXEffect; -}; - -static EffectDescription *default_effect = NULL; -static std::map<int, EffectDescription *> effects; -static bool effects_initialized = false; - -static EffectDescription *getEffectDescription(xmlNodePtr node, int *id) -{ - EffectDescription *ed = new EffectDescription; - - *id = atoi(XML::getProperty(node, "id", "-1").c_str()); - ed->mSFXEffect = XML::getProperty(node, "audio", ""); - ed->mGFXEffect = XML::getProperty(node, "particle", ""); - - return ed; -} - -static EffectDescription *getEffectDescription(int effectId) -{ - if (!effects_initialized) - { - XML::Document doc(BEING_EFFECTS_FILE); - xmlNodePtr root = doc.rootNode(); - - if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects")) - { - logger->log("Error loading being effects file: " - BEING_EFFECTS_FILE); - return NULL; - } - - for_each_xml_child_node(node, root) - { - int id; - - if (xmlStrEqual(node->name, BAD_CAST "effect")) - { - EffectDescription *EffectDescription = - getEffectDescription(node, &id); - effects[id] = EffectDescription; - } else if (xmlStrEqual(node->name, BAD_CAST "default")) - { - EffectDescription *EffectDescription = - getEffectDescription(node, &id); - - if (default_effect) - delete default_effect; - - default_effect = EffectDescription; - } - } - - effects_initialized = true; - } // done initializing - - EffectDescription *ed = effects[effectId]; - - if (!ed) - return default_effect; - else - return ed; -} - -void Being::internalTriggerEffect(int effectId, bool sfx, bool gfx) -{ - logger->log("Special effect #%d on %s", effectId, - getId() == player_node->getId() ? "self" : "other"); - - EffectDescription *ed = getEffectDescription(effectId); - - if (!ed) { - logger->log("Unknown special effect and no default recorded"); - return; - } - - if (gfx && ed->mGFXEffect != "" && mParticleEffects) { - Particle *selfFX; - - selfFX = particleEngine->addEffect(ed->mGFXEffect, 0, 0); - controlParticle(selfFX); - } - - if (sfx && ed->mSFXEffect != "") { - sound.playSfx(ed->mSFXEffect); - } -} diff --git a/src/being.h b/src/being.h index 325ec51a..958e8f60 100644 --- a/src/being.h +++ b/src/being.h @@ -29,6 +29,7 @@ #include <vector> #include "animatedsprite.h" +#include "effectmanager.h" #include "map.h" #include "sprite.h" @@ -358,15 +359,6 @@ class Being : public Sprite mEmotionTime = emote_time; } - /** - * Triggers a visual effect, such as `level up' - * - * Only draws the visual effect, does not play sound effects - * - * \param effectId ID of the effect to trigger - */ - virtual void triggerEffect(int effectId) { internalTriggerEffect(effectId, false, true); } - // Target cursor being used by the being Image *mTargetCursor; diff --git a/src/game.cpp b/src/game.cpp index 16bc082b..e8ba9046 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -31,6 +31,7 @@ #include "beingmanager.h" #include "configuration.h" +#include "effectmanager.h" #include "engine.h" #include "flooritemmanager.h" #include "graphics.h" @@ -126,6 +127,7 @@ ItemShortcutWindow *itemShortcutWindow; BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; Particle* particleEngine = NULL; +EffectManager *effectManager = NULL; const int MAX_TIME = 10000; @@ -277,6 +279,8 @@ Game::Game(Network *network): beingManager = new BeingManager(network); floorItemManager = new FloorItemManager(); + effectManager = new EffectManager(); + particleEngine = new Particle(NULL); particleEngine->setupEngine(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 8a7e61a1..b016b5cf 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -28,6 +28,7 @@ #include "../being.h" #include "../beingmanager.h" +#include "../effectmanager.h" #include "../game.h" #include "../localplayer.h" #include "../log.h" @@ -269,8 +270,10 @@ void BeingHandler::handleMessage(MessageIn *msg) break; int effectType = msg->readInt32(); + Being* being = beingManager->findBeing(id); - beingManager->findBeing(id)->triggerEffect(effectType); + effectManager->trigger(effectType, (int) being->getPixelX(), + (int) being->getPixelY()); break; } diff --git a/src/player.h b/src/player.h index 8b1c8dcb..c91ad3c2 100644 --- a/src/player.h +++ b/src/player.h @@ -78,14 +78,6 @@ class Player : public Being */ void flash(int time); - /** - * Triggers a visual/audio effect, such as `level up' - * - * \param effect_id ID of the effect to trigger - */ - virtual void - triggerEffect(int effectId) { internalTriggerEffect(effectId, true, true); } - protected: void updateCoords(); private: diff --git a/src/vector.cpp b/src/vector.cpp new file mode 100644 index 00000000..7d5f055a --- /dev/null +++ b/src/vector.cpp @@ -0,0 +1,28 @@ +/* + * The Mana World + * Copyright 2007 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "vector.h" + +std::ostream& operator <<(std::ostream &os, const Vector &v) +{ + os << "Vector(" << v.x << ", " << v.y << ", " << v.z << ")"; + return os; +} diff --git a/src/vector.h b/src/vector.h index b19f6c64..f32b201a 100644 --- a/src/vector.h +++ b/src/vector.h @@ -22,6 +22,10 @@ #ifndef _TMW_VECTOR_H_ #define _TMW_VECTOR_H_ +#include <math.h> + +#include <iostream> + /** * Vector class. Represents either a 3D point in space, a velocity or a force. * Provides several convenient operator overloads. @@ -41,7 +45,7 @@ class Vector /** * Constructor. */ - Vector(float x, float y, float z): + Vector(float x, float y, float z = 0.0f): x(x), y(y), z(z) @@ -69,11 +73,12 @@ class Vector /** * In-place scale vector operator. */ - void operator*=(float c) + Vector &operator*=(float c) { x *= c; y *= c; z *= c; + return *this; } /** @@ -87,6 +92,17 @@ class Vector } /** + * In-place scale vector operator. + */ + Vector &operator/=(float c) + { + x /= c; + y /= c; + z /= c; + return *this; + } + + /** * Add vector operator. */ Vector operator+(const Vector &v) const @@ -99,11 +115,12 @@ class Vector /** * In-place add vector operator. */ - void operator+=(const Vector &v) + Vector &operator+=(const Vector &v) { x += v.x; y += v.y; z += v.z; + return *this; } /** @@ -119,14 +136,55 @@ class Vector /** * In-place substract vector operator. */ - void operator-=(const Vector &v) + Vector &operator-=(const Vector &v) { x -= v.x; y -= v.y; z -= v.z; + return *this; + } + + /** + * Returns the length of this vector. This method does a relatively + * slow square root. + */ + float length() const + { + return sqrtf(x * x + y * y + z * z); + } + + /** + * Returns the squared length of this vector. Avoids the square root. + */ + float squaredLength() const + { + return x * x + y * y + z * z; + } + + /** + * Returns the manhattan length of this vector. + */ + float manhattanLength() const + { + return fabsf(x) + fabsf(y) + fabsf(z); + } + + /** + * Returns a normalized version of this vector. This is a unit vector + * running parallel to it. + */ + Vector normalized() const + { + const float l = length(); + return Vector(x / l, y / l, z / l); } float x, y, z; }; -#endif +/** + * Appends a string representation of a vector to the output stream. + */ +std::ostream& operator <<(std::ostream &os, const Vector &v); + +#endif // _TMW_VECTOR_H_ |