From ee6298f520b05967bd395ac7351e8b5648190981 Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 19:33:45 -0400 Subject: [PATCH 1/6] Added Flag_Bound flag for ItemStack to check against but the system behind it is probably not the best --- apps/openmw/mwbase/world.hpp | 3 +++ apps/openmw/mwgui/itemmodel.cpp | 7 +++++++ apps/openmw/mwgui/itemmodel.hpp | 3 ++- apps/openmw/mwworld/worldimp.cpp | 35 +++++++++++++++++++++++++++++++- apps/openmw/mwworld/worldimp.hpp | 5 +++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index f07bb3eb9..85f2116e6 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -220,6 +220,9 @@ namespace MWBase virtual int getMonth() const = 0; virtual int getYear() const = 0; + virtual bool isBoundItemID(const std::string &id) = 0; + /// \return Returns whether or not the id refers to a bound item. + virtual std::string getMonthName (int month = -1) const = 0; ///< Return name of month (-1: current month) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 59b54e171..96ec308ec 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -2,6 +2,10 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/esmstore.hpp" + +#include "../mwbase/world.hpp" +#include "../mwbase/environment.hpp" namespace MWGui { @@ -15,6 +19,9 @@ namespace MWGui { if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; + + if (MWBase::Environment::get().getWorld()->isBoundItemID(base.getCellRef().getRefId())) + mFlags |= Flag_Bound; } ItemStack::ItemStack() diff --git a/apps/openmw/mwgui/itemmodel.hpp b/apps/openmw/mwgui/itemmodel.hpp index 21c5477d0..c1b243a76 100644 --- a/apps/openmw/mwgui/itemmodel.hpp +++ b/apps/openmw/mwgui/itemmodel.hpp @@ -26,7 +26,8 @@ namespace MWGui enum Flags { - Flag_Enchanted = (1<<0) + Flag_Enchanted = (1<<0), + Flag_Bound = (1<<1) }; int mFlags; diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 6a8322d4d..bc8c314ca 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -191,6 +191,29 @@ namespace MWWorld mGlobalVariables.fill (mStore); mWorldScene = new Scene(*mRendering, mPhysics); + + // Build a list of known bound item ID's + const MWWorld::Store &gameSettings = mStore.get(); + + for (MWWorld::Store::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration) + { + const ESM::GameSetting ¤tSetting = *currentIteration; + try + { + std::string currentGMSTID = currentSetting.mId; + std::transform(currentGMSTID.begin(), currentGMSTID.end(), currentGMSTID.begin(), ::tolower); + + // Don't bother checking this GMST if it's not a sMagicBound* one. + if (currentGMSTID.find("smagicbound") != 0) + continue; + + std::string currentGMSTValue = currentSetting.getString(); + std::transform(currentGMSTValue.begin(), currentGMSTValue.end(), currentGMSTValue.begin(), ::tolower); + + mBoundID[currentGMSTValue] = true; + } + catch(...){} + } } void World::startNewGame (bool bypass) @@ -879,6 +902,16 @@ namespace MWWorld return mGlobalVariables["timescale"].getFloat(); } + bool World::isBoundItemID(const std::string &id) + { + std::string id_temp = id; + std::transform(id_temp.begin(), id_temp.end(), id_temp.begin(), ::tolower); + + if (mBoundID.count(id_temp) != 0) + return true; + return false; + } + void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { mPhysics->clearQueuedMovement(); @@ -2501,7 +2534,7 @@ namespace MWWorld if (!selectedSpell.empty()) { const ESM::Spell* spell = getStore().get().search(selectedSpell); - + // A power can be used once per 24h if (spell->mData.mType == ESM::Spell::ST_Power) stats.getSpells().usePower(spell->mId); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 54827d042..bc85ab199 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -99,6 +99,8 @@ namespace MWWorld std::string mStartCell; + std::map mBoundID; + void updateWeather(float duration); int getDaysPerMonth (int month) const; @@ -308,6 +310,9 @@ namespace MWWorld virtual float getTimeScaleFactor() const; + virtual bool isBoundItemID(const std::string &id); + ///< \return Whether or not the specified id refers to a bound item. + virtual void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); ///< Move to interior cell. From 83868bca23f11bff1c4c28e26e6a6b9b02ec38e2 Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 19:37:00 -0400 Subject: [PATCH 2/6] Removed unused include left over from experimentation --- apps/openmw/mwgui/itemmodel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 96ec308ec..857fd5939 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -2,7 +2,6 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" -#include "../mwworld/esmstore.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" From ea43a2350532ab0693d20459bc399fdff5e716d7 Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 20:45:22 -0400 Subject: [PATCH 3/6] All GMST logic is done in itemmodel.cpp now with usage of a static cache std::map --- apps/openmw/mwbase/world.hpp | 3 --- apps/openmw/mwworld/worldimp.cpp | 33 -------------------------------- apps/openmw/mwworld/worldimp.hpp | 3 --- 3 files changed, 39 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 85f2116e6..f07bb3eb9 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -220,9 +220,6 @@ namespace MWBase virtual int getMonth() const = 0; virtual int getYear() const = 0; - virtual bool isBoundItemID(const std::string &id) = 0; - /// \return Returns whether or not the id refers to a bound item. - virtual std::string getMonthName (int month = -1) const = 0; ///< Return name of month (-1: current month) diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index bc8c314ca..615b072e1 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -191,29 +191,6 @@ namespace MWWorld mGlobalVariables.fill (mStore); mWorldScene = new Scene(*mRendering, mPhysics); - - // Build a list of known bound item ID's - const MWWorld::Store &gameSettings = mStore.get(); - - for (MWWorld::Store::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration) - { - const ESM::GameSetting ¤tSetting = *currentIteration; - try - { - std::string currentGMSTID = currentSetting.mId; - std::transform(currentGMSTID.begin(), currentGMSTID.end(), currentGMSTID.begin(), ::tolower); - - // Don't bother checking this GMST if it's not a sMagicBound* one. - if (currentGMSTID.find("smagicbound") != 0) - continue; - - std::string currentGMSTValue = currentSetting.getString(); - std::transform(currentGMSTValue.begin(), currentGMSTValue.end(), currentGMSTValue.begin(), ::tolower); - - mBoundID[currentGMSTValue] = true; - } - catch(...){} - } } void World::startNewGame (bool bypass) @@ -902,16 +879,6 @@ namespace MWWorld return mGlobalVariables["timescale"].getFloat(); } - bool World::isBoundItemID(const std::string &id) - { - std::string id_temp = id; - std::transform(id_temp.begin(), id_temp.end(), id_temp.begin(), ::tolower); - - if (mBoundID.count(id_temp) != 0) - return true; - return false; - } - void World::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) { mPhysics->clearQueuedMovement(); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index bc85ab199..94224e9a5 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -310,9 +310,6 @@ namespace MWWorld virtual float getTimeScaleFactor() const; - virtual bool isBoundItemID(const std::string &id); - ///< \return Whether or not the specified id refers to a bound item. - virtual void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); ///< Move to interior cell. From efaa820ee2d8299622e25523473242c8179eaa89 Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 20:46:21 -0400 Subject: [PATCH 4/6] Managed to forget the itemmodel.cpp code --- apps/openmw/mwgui/itemmodel.cpp | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 857fd5939..36c2d5b78 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -2,6 +2,8 @@ #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwworld/store.hpp" +#include "../mwworld/esmstore.hpp" #include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" @@ -19,7 +21,37 @@ namespace MWGui if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; - if (MWBase::Environment::get().getWorld()->isBoundItemID(base.getCellRef().getRefId())) + static std::map boundItemIDCache; + + // If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason + if (boundItemIDCache.empty()) + { + // Build a list of known bound item ID's + const MWWorld::Store &gameSettings = MWBase::Environment::get().getWorld()->getStore().get(); + + for (MWWorld::Store::iterator currentIteration = gameSettings.begin(); currentIteration != gameSettings.end(); ++currentIteration) + { + const ESM::GameSetting ¤tSetting = *currentIteration; + std::string currentGMSTID = currentSetting.mId; + Misc::StringUtils::toLower(currentGMSTID); + + // Don't bother checking this GMST if it's not a sMagicBound* one. + if (currentGMSTID.find("smagicbound") != 0) + continue; + + // All sMagicBound* GMST's should be of type string + std::string currentGMSTValue = currentSetting.getString(); + Misc::StringUtils::toLower(currentGMSTValue); + + boundItemIDCache[currentGMSTValue] = true; + } + } + + // Perform bound item check and assign the Flag_Bound bit if it passes + std::string tempItemID = base.getCellRef().getRefId(); + Misc::StringUtils::toLower(tempItemID); + + if (boundItemIDCache.count(tempItemID) != 0) mFlags |= Flag_Bound; } From f9e2fd0f3de8db77f17a06b3d28f6f1140c5975c Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 20:47:14 -0400 Subject: [PATCH 5/6] Also forgot to remove a now unused variable I introduced --- apps/openmw/mwworld/worldimp.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 94224e9a5..54827d042 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -99,8 +99,6 @@ namespace MWWorld std::string mStartCell; - std::map mBoundID; - void updateWeather(float duration); int getDaysPerMonth (int month) const; From e105202ee2a76cbc2880e7772fea4def6c0ed9df Mon Sep 17 00:00:00 2001 From: Ragora Date: Thu, 11 Sep 2014 22:45:30 -0400 Subject: [PATCH 6/6] Use std::set instead of std::map --- apps/openmw/mwgui/itemmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/itemmodel.cpp b/apps/openmw/mwgui/itemmodel.cpp index 36c2d5b78..17f787dcb 100644 --- a/apps/openmw/mwgui/itemmodel.cpp +++ b/apps/openmw/mwgui/itemmodel.cpp @@ -21,7 +21,7 @@ namespace MWGui if (base.getClass().getEnchantment(base) != "") mFlags |= Flag_Enchanted; - static std::map boundItemIDCache; + static std::set boundItemIDCache; // If this is empty then we haven't executed the GMST cache logic yet; or there isn't any sMagicBound* GMST's for some reason if (boundItemIDCache.empty()) @@ -43,7 +43,7 @@ namespace MWGui std::string currentGMSTValue = currentSetting.getString(); Misc::StringUtils::toLower(currentGMSTValue); - boundItemIDCache[currentGMSTValue] = true; + boundItemIDCache.insert(currentGMSTValue); } }