diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-10-23 08:02:22 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-10-23 08:02:22 +0000 |
commit | 8eda6c18fd391e34f180aaece96140a374f274f9 (patch) | |
tree | 9598ebf5280790951b30befe9c84d4bba57198e4 /src/resources | |
parent | c9f618b5c50f759cf172d8e37063ef56e05812cf (diff) | |
download | mana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.gz mana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.bz2 mana-8eda6c18fd391e34f180aaece96140a374f274f9.tar.xz mana-8eda6c18fd391e34f180aaece96140a374f274f9.zip |
Merged changesets 3653, 3655-3657, 3659-3560, 3671-3672 from trunk to
0.0. Mostly memory leak fixes by Guillaume.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/action.cpp | 11 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 14 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 3 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 2 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 16 |
5 files changed, 26 insertions, 20 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp index 247455db..6b3c2f52 100644 --- a/src/resources/action.cpp +++ b/src/resources/action.cpp @@ -45,10 +45,11 @@ Action::getAnimation(int direction) const { Animations::const_iterator i = mAnimations.find(direction); - // When the direction isn't defined, try the default + // When the given direction is not available, return the first one. + // (either DEFAULT, or more usually DOWN). if (i == mAnimations.end()) { - i = mAnimations.find(0); + i = mAnimations.begin(); } return (i == mAnimations.end()) ? NULL : i->second; @@ -57,11 +58,5 @@ Action::getAnimation(int direction) const void Action::setAnimation(int direction, Animation *animation) { - // Set first direction as default direction - if (mAnimations.empty()) - { - mAnimations[0] = animation; - } - mAnimations[direction] = animation; } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index b5b25ac0..3b32ec71 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -103,22 +103,16 @@ ItemInfo::setAttackType(const std::string &attackType) void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) { - if (mSounds.find(event) == mSounds.end()) - { - mSounds[event] = new std::vector<std::string>; - } - - mSounds[event]->push_back("sfx/" + filename); + mSounds[event].push_back("sfx/" + filename); } const std::string& ItemInfo::getSound(EquipmentSoundEvent event) const { - static const std::string empty = ""; - std::map<EquipmentSoundEvent, std::vector<std::string>*>::const_iterator i; + static const std::string empty; + std::map< EquipmentSoundEvent, std::vector<std::string> >::const_iterator i; i = mSounds.find(event); - return (i == mSounds.end()) ? empty : - i->second->at(rand() % i->second->size()); + return i == mSounds.end() ? empty : i->second[rand() % i->second.size()]; } diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 457daf7f..b016f27b 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -49,7 +49,6 @@ class ItemInfo * Constructor. */ ItemInfo(): - mImageName(""), mImage(NULL), mType(0), mWeight(0), @@ -138,7 +137,7 @@ class ItemInfo std::map<int, std::string> mAnimationFiles; /** Stores the names of sounds to be played at certain event. */ - std::map<EquipmentSoundEvent, std::vector<std::string>* > mSounds; + std::map< EquipmentSoundEvent, std::vector<std::string> > mSounds; }; #endif diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index f4864eea..7bdafdc2 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -144,6 +144,8 @@ MonsterDB::load() mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo; } + xmlFreeDoc(doc); + mLoaded = true; } diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 24156be1..1e7c102d 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -21,6 +21,8 @@ * $Id$ */ +#include <set> + #include "spritedef.h" #include "../log.h" @@ -292,6 +294,20 @@ SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) SpriteDef::~SpriteDef() { + // Actions are shared, so ensure they are deleted only once. + std::set< Action * > actions; + for (Actions::const_iterator i = mActions.begin(), + i_end = mActions.end(); i != i_end; ++i) + { + actions.insert(i->second); + } + + for (std::set< Action * >::const_iterator i = actions.begin(), + i_end = actions.end(); i != i_end; ++i) + { + delete *i; + } + for (ImageSetIterator i = mImageSets.begin(); i != mImageSets.end(); ++i) { |