diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/being.cpp | 27 | ||||
-rw-r--r-- | src/being.h | 11 | ||||
-rw-r--r-- | src/engine.cpp | 11 | ||||
-rw-r--r-- | src/engine.h | 7 |
5 files changed, 38 insertions, 25 deletions
@@ -1,4 +1,9 @@ -2007-02-01 Eugenio Favalli <elvenprogrammer@gmail.com> +2007-02-02 Bjørn Lindeijer <bjorn@lindeijer.nl> + + * src/engine.h, src/engine.cpp, src/being.h, src/being.cpp: Moved + responsibility of loading emoticons to the Being class. + +2007-02-01 Eugenio Favalli <elvenprogrammer@gmail.com> * src/gui/updatewindow.cpp: File handle should be closed before attempting to remove/rename files. diff --git a/src/being.cpp b/src/being.cpp index d4f68fac..bfed2d51 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -31,6 +31,7 @@ #include "log.h" #include "map.h" +#include "resources/resourcemanager.h" #include "resources/spriteset.h" #include "gui/gui.h" @@ -38,12 +39,8 @@ #include "utils/dtor.h" #include "utils/tostring.h" -extern Spriteset *emotionset; - -PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY): - x(iX), y(iY) -{ -} +int Being::instances = 0; +Spriteset *Being::emotionset = NULL; Being::Being(Uint32 id, Uint16 job, Map *map): mJob(job), @@ -67,6 +64,16 @@ Being::Being(Uint32 id, Uint16 job, Map *map): mEquipmentSpriteIDs(VECTOREND_SPRITE, 0) { setMap(map); + + if (instances == 0) + { + // Load the emotion set + ResourceManager *rm = ResourceManager::getInstance(); + emotionset = rm->getSpriteset("graphics/sprites/emotions.png", 30, 32); + if (!emotionset) logger->error("Unable to load emotions spriteset!"); + } + + instances++; } Being::~Being() @@ -74,6 +81,14 @@ Being::~Being() std::for_each(mSprites.begin(), mSprites.end(), make_dtor(mSprites)); clearPath(); setMap(NULL); + + instances--; + + if (instances == 0) + { + emotionset->decRef(); + emotionset = NULL; + } } void diff --git a/src/being.h b/src/being.h index 38f44fb4..91913385 100644 --- a/src/being.h +++ b/src/being.h @@ -43,12 +43,17 @@ class Map; class Graphics; class Spriteset; +/** + * A position along a being's path. + */ struct PATH_NODE { /** * Constructor. */ - PATH_NODE(unsigned short x, unsigned short y); + PATH_NODE(unsigned short x, unsigned short y): + x(x), y(y) + { } unsigned short x; unsigned short y; @@ -375,6 +380,10 @@ class Being : public Sprite std::vector<AnimatedSprite*> mSprites; std::vector<int> mEquipmentSpriteIDs; + + private: + static int instances; /**< Number of Being instances */ + static Spriteset *emotionset; /**< Emoticons used by beings */ }; #endif diff --git a/src/engine.cpp b/src/engine.cpp index 6ed02a9d..be195c9f 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -57,21 +57,10 @@ extern Minimap *minimap; char itemCurrenyQ[10] = "0"; -Spriteset *emotionset; - Engine::Engine(Network *network): mCurrentMap(NULL), mNetwork(network) { - // Load the emotion set - ResourceManager *resman = ResourceManager::getInstance(); - emotionset = resman->getSpriteset("graphics/sprites/emotions.png", 30, 32); - if (!emotionset) logger->error("Unable to load emotions spriteset!"); -} - -Engine::~Engine() -{ - emotionset->decRef(); } void Engine::changeMap(const std::string &mapPath) diff --git a/src/engine.h b/src/engine.h index 90cee9c0..eb6891ad 100644 --- a/src/engine.h +++ b/src/engine.h @@ -31,7 +31,7 @@ class Network; /** * Game engine. Actually hardly does anything anymore except keeping track of - * the current map and loading the emotes. + * the current map. */ class Engine { @@ -42,11 +42,6 @@ class Engine Engine(Network *network); /** - * Destructor. - */ - ~Engine(); - - /** * Returns the currently active map. */ Map *getCurrentMap() { return mCurrentMap; } |