From 8615f1bbad630602009c04a317cd83e03aaa620c Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 3 Jun 2010 14:12:42 -0600 Subject: Unload loaded DBs before loading them again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This greatly simplifies handling DBs when changing states. No more need to manage unloading in Client (except when exiting). Reviewed-by: Thorbjørn Lindeijer --- src/client.cpp | 16 ++++++++-------- src/resources/colordb.cpp | 2 +- src/resources/emotedb.cpp | 2 +- src/resources/itemdb.cpp | 2 +- src/resources/monsterdb.cpp | 2 +- src/resources/npcdb.cpp | 2 +- src/statuseffect.cpp | 10 ++++++++++ src/statuseffect.h | 1 + 8 files changed, 24 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index aa48591f..93450805 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -422,6 +422,14 @@ Client::~Client() SDL_RemoveTimer(mLogicCounterId); SDL_RemoveTimer(mSecondsCounterId); + // Unload XML databases + ColorDB::unload(); + EmoteDB::unload(); + ItemDB::unload(); + MonsterDB::unload(); + NPCDB::unload(); + StatusEffect::unload(); + // Before config.write() since it writes the shortcuts to the config delete itemShortcut; delete emoteShortcut; @@ -575,14 +583,6 @@ int Client::exec() { delete game; game = 0; - - // Unload XML databases - ColorDB::unload(); - EmoteDB::unload(); - ItemDB::unload(); - MonsterDB::unload(); - NPCDB::unload(); - StatusEffect::unload(); } mOldState = mState; diff --git a/src/resources/colordb.cpp b/src/resources/colordb.cpp index 0041cee4..c35a5660 100644 --- a/src/resources/colordb.cpp +++ b/src/resources/colordb.cpp @@ -36,7 +36,7 @@ namespace void ColorDB::load() { if (mLoaded) - return; + unload(); XML::Document *doc = new XML::Document("hair.xml"); xmlNodePtr root = doc->rootNode(); diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 117c0bab..fddab500 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -36,7 +36,7 @@ namespace void EmoteDB::load() { if (mLoaded) - return; + unload(); mLastEmote = 0; diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 4638f00e..077012c7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -108,7 +108,7 @@ static std::string normalized(const std::string &name) void ItemDB::load() { if (mLoaded) - return; + unload(); logger->log("Initializing item database..."); diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index e9afa7ef..5a796f5f 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -43,7 +43,7 @@ namespace void MonsterDB::load() { if (mLoaded) - return; + unload(); mUnknown.addSprite("error.xml"); diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp index 4bc5a6e4..bc36a3b4 100644 --- a/src/resources/npcdb.cpp +++ b/src/resources/npcdb.cpp @@ -35,7 +35,7 @@ namespace void NPCDB::load() { if (mLoaded) - return; + unload(); NPCsprite *unknownSprite = new NPCsprite; unknownSprite->sprite = "error.xml"; diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index 49619f8a..6ab0b8fa 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -32,6 +32,8 @@ #define STATUS_EFFECTS_FILE "status-effects.xml" +bool StatusEffect::mLoaded = false; + StatusEffect::StatusEffect() : mPersistentParticleEffect(false) {} @@ -113,6 +115,9 @@ StatusEffect *StatusEffect::getStunEffect(int index, bool enabling) void StatusEffect::load() { + if (mLoaded) + unload(); + XML::Document doc(STATUS_EFFECTS_FILE); xmlNodePtr rootNode = doc.rootNode(); @@ -175,8 +180,13 @@ void unloadMap(std::map map) void StatusEffect::unload() { + if (!mLoaded) + return; + unloadMap(statusEffects[0]); unloadMap(statusEffects[1]); unloadMap(stunEffects[0]); unloadMap(stunEffects[1]); + + mLoaded = false; } diff --git a/src/statuseffect.h b/src/statuseffect.h index 0fed5748..fc0e7336 100644 --- a/src/statuseffect.h +++ b/src/statuseffect.h @@ -98,6 +98,7 @@ public: static void unload(); private: + static bool mLoaded; std::string mMessage; std::string mSFXEffect; -- cgit v1.2.3-70-g09d2