summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-02-02 19:54:42 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-02-02 19:54:42 +0000
commitaf6d41608a32266ed0251ba4909daa4fa81baca6 (patch)
tree93e8f90ee849ed21d8cb352ecd38710a4ed48b8d /src
parent63dcf62ec17992b8993dcab5ace8f3af5c7f8277 (diff)
downloadmana-client-af6d41608a32266ed0251ba4909daa4fa81baca6.tar.gz
mana-client-af6d41608a32266ed0251ba4909daa4fa81baca6.tar.bz2
mana-client-af6d41608a32266ed0251ba4909daa4fa81baca6.tar.xz
mana-client-af6d41608a32266ed0251ba4909daa4fa81baca6.zip
Made Engine class even more useless by moving emoticon loading into Being.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp27
-rw-r--r--src/being.h11
-rw-r--r--src/engine.cpp11
-rw-r--r--src/engine.h7
4 files changed, 32 insertions, 24 deletions
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; }