summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being.cpp25
-rw-r--r--src/being.h10
-rw-r--r--src/gui/emotecontainer.cpp2
-rw-r--r--src/gui/emotecontainer.h2
-rw-r--r--src/gui/emoteshortcutcontainer.cpp4
-rw-r--r--src/gui/emoteshortcutcontainer.h2
-rw-r--r--src/main.cpp2
-rw-r--r--src/resources/emotedb.cpp24
-rw-r--r--src/resources/emotedb.h9
9 files changed, 31 insertions, 49 deletions
diff --git a/src/being.cpp b/src/being.cpp
index bf49e852..60fb8d13 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -61,7 +61,6 @@
int Being::mNumberOfHairColors = 1;
int Being::mNumberOfHairstyles = 1;
std::vector<std::string> Being::hairColors;
-std::vector<AnimatedSprite*> Being::emotionSet;
static const int X_SPEECH_OFFSET = 18;
static const int Y_SPEECH_OFFSET = 60;
@@ -487,7 +486,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
const int emotionIndex = mEmotion - 1;
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
- emotionSet[emotionIndex]->draw(graphics, px, py);
+ EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py);
}
void Being::drawSpeech(int offsetX, int offsetY)
@@ -770,7 +769,7 @@ std::string Being::getHairColor(int index)
return hairColors[index];
}
-void Being::initializeHair()
+void Being::load()
{
// Hairstyles are encoded as negative numbers. Count how far negative
// we can go.
@@ -809,23 +808,3 @@ void Being::initializeHair()
}
}
}
-
-void Being::load()
-{
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); i++)
- {
- EmoteInfo info = EmoteDB::get(i);
-
- std::string file = "graphics/sprites/" + info.sprites.front()->sprite;
- int variant = info.sprites.front()->variant;
- emotionSet.push_back(AnimatedSprite::load(file, variant));
- }
-
- initializeHair();
-}
-
-void Being::cleanup()
-{
- delete_all(emotionSet);
-} \ No newline at end of file
diff --git a/src/being.h b/src/being.h
index 754c163a..b9b57a0d 100644
--- a/src/being.h
+++ b/src/being.h
@@ -392,8 +392,6 @@ class Being : public Sprite
*/
void untarget() { mUsedTargetCursor = NULL; }
- AnimatedSprite* getEmote(int index) { return emotionSet[index]; }
-
void setEmote(Uint8 emotion, Uint8 emote_time)
{
mEmotion = emotion;
@@ -447,8 +445,6 @@ class Being : public Sprite
static void load();
- static void cleanup();
-
protected:
/**
* Sets the new path for this being.
@@ -511,7 +507,7 @@ class Being : public Sprite
Uint16 mHairStyle, mHairColor;
Gender mGender;
int mPx, mPy; /**< Pixel coordinates */
- Uint16 mStunMode; /**< Stun mode; zero if not stunned */
+ Uint16 mStunMode; /**< Stun mode; zero if not stunned */
std::set<int> mStatusEffects; /**< set of active status effects */
gcn::Color mNameColor;
@@ -524,8 +520,6 @@ class Being : public Sprite
ParticleList mChildParticleEffects;
private:
- static void initializeHair();
-
/**
* Calculates the offset in the given directions.
* If walking in direction 'neg' the value is negated.
@@ -540,8 +534,6 @@ class Being : public Sprite
// Target cursor being used
SimpleAnimation* mUsedTargetCursor;
-
- static std::vector<AnimatedSprite*> emotionSet; /**< Emoticons used by beings */
};
#endif
diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp
index ad3f5c83..ececd9aa 100644
--- a/src/gui/emotecontainer.cpp
+++ b/src/gui/emotecontainer.cpp
@@ -53,7 +53,7 @@ EmoteContainer::EmoteContainer():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); i++)
{
- mEmoteImg.push_back(player_node->getEmote(i));
+ mEmoteImg.push_back(EmoteDB::getAnimation(i));
}
mSelImg = resman->getImage("graphics/gui/selection.png");
diff --git a/src/gui/emotecontainer.h b/src/gui/emotecontainer.h
index fefce793..88df29fc 100644
--- a/src/gui/emotecontainer.h
+++ b/src/gui/emotecontainer.h
@@ -121,7 +121,7 @@ class EmoteContainer : public gcn::Widget,
*/
void distributeValueChangedEvent(void);
- std::vector<AnimatedSprite*> mEmoteImg;
+ std::vector<const AnimatedSprite*> mEmoteImg;
Image *mSelImg;
int mSelectedEmoteIndex;
diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp
index df1bf74c..c96ea855 100644
--- a/src/gui/emoteshortcutcontainer.cpp
+++ b/src/gui/emoteshortcutcontainer.cpp
@@ -59,7 +59,7 @@ EmoteShortcutContainer::EmoteShortcutContainer():
// Setup emote sprites
for (int i = 0; i <= EmoteDB::getLast(); i++)
{
- mEmoteImg.push_back(player_node->getEmote(i));
+ mEmoteImg.push_back(EmoteDB::getAnimation(i));
}
mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS;
@@ -112,7 +112,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
if (mEmoteMoved)
{
// Draw the emote image being dragged by the cursor.
- AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
+ const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1];
if (sprite)
{
const int tPosX = mCursorPosX - (sprite->getWidth() / 2);
diff --git a/src/gui/emoteshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h
index d32a9f79..2997cb09 100644
--- a/src/gui/emoteshortcutcontainer.h
+++ b/src/gui/emoteshortcutcontainer.h
@@ -68,7 +68,7 @@ class EmoteShortcutContainer : public ShortcutContainer
void mouseReleased(gcn::MouseEvent &event);
private:
- std::vector<AnimatedSprite*> mEmoteImg;
+ std::vector<const AnimatedSprite*> mEmoteImg;
bool mEmoteClicked;
int mEmoteMoved;
diff --git a/src/main.cpp b/src/main.cpp
index 306514e4..0034fc60 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -482,8 +482,6 @@ void exit_engine()
// Shutdown sound
sound.close();
- Being::cleanup();
-
// Unload XML databases
ColorDB::unload();
EmoteDB::unload();
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 5e9a146c..5bc8407a 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -21,6 +21,7 @@
#include "emotedb.h"
+#include "../animatedsprite.h"
#include "../log.h"
#include "../utils/xml.h"
@@ -41,9 +42,8 @@ void EmoteDB::load()
mLastEmote = 0;
EmoteSprite *unknownSprite = new EmoteSprite;
- unknownSprite->sprite = "error.xml";
+ unknownSprite->sprite = AnimatedSprite::load("error.xml");
unknownSprite->name = "unknown";
- unknownSprite->variant = 0;
mUnknown.sprites.push_back(unknownSprite);
logger->log("Initializing emote database...");
@@ -77,8 +77,10 @@ void EmoteDB::load()
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
EmoteSprite *currentSprite = new EmoteSprite;
- currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content;
- currentSprite->variant = XML::getProperty(spriteNode, "variant", 0);
+ std::string file = "graphics/sprites/" + (std::string)
+ (const char*) spriteNode->xmlChildrenNode->content;
+ currentSprite->sprite = AnimatedSprite::load(file,
+ XML::getProperty(spriteNode, "variant", 0));
currentInfo->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
@@ -102,6 +104,7 @@ void EmoteDB::unload()
{
while (!i->second->sprites.empty())
{
+ delete i->second->sprites.front()->sprite;
delete i->second->sprites.front();
i->second->sprites.pop_front();
}
@@ -112,6 +115,7 @@ void EmoteDB::unload()
while (!mUnknown.sprites.empty())
{
+ delete mUnknown.sprites.front()->sprite;
delete mUnknown.sprites.front();
mUnknown.sprites.pop_front();
}
@@ -119,21 +123,27 @@ void EmoteDB::unload()
mLoaded = false;
}
-const EmoteInfo& EmoteDB::get(int id)
+const EmoteInfo *EmoteDB::get(int id)
{
EmoteInfosIterator i = mEmoteInfos.find(id);
if (i == mEmoteInfos.end())
{
logger->log("EmoteDB: Warning, unknown emote ID %d requested", id);
- return mUnknown;
+ return &mUnknown;
}
else
{
- return *(i->second);
+ return i->second;
}
}
+const AnimatedSprite* EmoteDB::getAnimation(int id)
+{
+ const EmoteInfo *info = get(id);
+ return info->sprites.front()->sprite;
+}
+
const int& EmoteDB::getLast()
{
return mLastEmote;
diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h
index ad21722a..691881c8 100644
--- a/src/resources/emotedb.h
+++ b/src/resources/emotedb.h
@@ -26,11 +26,12 @@
#include <map>
#include <string>
+class AnimatedSprite;
+
struct EmoteSprite
{
- std::string sprite;
+ const AnimatedSprite *sprite;
std::string name;
- int variant;
};
struct EmoteInfo
@@ -50,7 +51,9 @@ namespace EmoteDB
void unload();
- const EmoteInfo& get(int id);
+ const EmoteInfo *get(int id);
+
+ const AnimatedSprite *getAnimation(int id);
const int& getLast();