From 90fce49d17e825de561d80d460ea998f3e2b8fa0 Mon Sep 17 00:00:00 2001 From: Telvanni 4Life Date: Sun, 30 Nov 2025 09:01:48 -0500 Subject: [PATCH] Changed MagicEffect from IndexedStore to TypedDynamicStore in ESMStore. --- apps/openmw/mwmechanics/magiceffects.cpp | 12 +++++------- apps/openmw/mwworld/esmstore.cpp | 6 +++--- apps/openmw/mwworld/store.cpp | 11 +++++++---- apps/openmw/mwworld/store.hpp | 10 +++++++--- components/esm3/loadmgef.cpp | 19 ++++++++++--------- components/esm3/loadmgef.hpp | 4 ++-- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwmechanics/magiceffects.cpp b/apps/openmw/mwmechanics/magiceffects.cpp index e4210ed8fc..bba9e57781 100644 --- a/apps/openmw/mwmechanics/magiceffects.cpp +++ b/apps/openmw/mwmechanics/magiceffects.cpp @@ -26,7 +26,7 @@ namespace namespace MWMechanics { EffectKey::EffectKey() - : mId(0) + : mId(ESM::RefId{}) { } @@ -48,7 +48,7 @@ namespace MWMechanics std::string EffectKey::toString() const { const auto& store = MWBase::Environment::get().getESMStore(); - const ESM::MagicEffect* magicEffect = store->get().find(mId); + const ESM::MagicEffect* magicEffect = store->get().search(mId); return getMagicEffectString( *magicEffect, store->get().search(mArg), store->get().search(mArg)); } @@ -57,11 +57,9 @@ namespace MWMechanics { if (left.mId < right.mId) return true; - - if (left.mId > right.mId) - return false; - - return left.mArg < right.mArg; + if (left.mId == right.mId) + return left.mArg < right.mArg; + return false; } bool operator==(const EffectKey& left, const EffectKey& right) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 773e4a80e8..ec55de0b91 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -186,7 +186,7 @@ namespace iter->mData.mAttribute = -1; Log(Debug::Verbose) << RecordType::getRecordType() << " " << spell.mId << ": dropping unexpected attribute argument of " - << ESM::MagicEffect::indexToGmstString(iter->mData.mEffectID) << " effect"; + << iter->mData.mEffectID.getRefIdString() << " effect"; changed = true; } @@ -195,7 +195,7 @@ namespace iter->mData.mSkill = -1; Log(Debug::Verbose) << RecordType::getRecordType() << " " << spell.mId << ": dropping unexpected skill argument of " - << ESM::MagicEffect::indexToGmstString(iter->mData.mEffectID) << " effect"; + <mData.mEffectID.getRefIdString() << " effect"; changed = true; } @@ -525,7 +525,7 @@ namespace MWWorld store->setUp(); getWritable().setUp(get()); - getWritable().setUp(); + getWritable().setUp(get()); getWritable().setUp(get()); getWritable().updateLandPositions(get()); getWritable().preprocessReferences(get()); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 9d030dcea9..6158918193 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -110,9 +110,6 @@ namespace MWWorld return ptr; } - // Need to instantiate these before they're used - template class IndexedStore; - template TypedDynamicStore::TypedDynamicStore() { @@ -380,6 +377,9 @@ namespace MWWorld } } + // Need to instantiate these before they're used + template class TypedDynamicStore; + // LandTexture //========================================================================= Store::Store() = default; @@ -978,7 +978,10 @@ namespace MWWorld // Magic effect //========================================================================= - Store::Store() {} + void Store::setUp(const MWWorld::Store& settings) + { + // MGEF record is complete. No further instantiation of fields is required. + } // Attribute //========================================================================= diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 2ccf26f734..28e0dab777 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ namespace ESM { struct LandTexture; - struct MagicEffect; struct WeaponType; class ESMReader; class ESMWriter; @@ -453,10 +453,14 @@ namespace MWWorld }; template <> - class Store : public IndexedStore + class Store : public TypedDynamicStore { + using TypedDynamicStore::setUp; + public: - Store(); + Store() = default; + + void setUp(const MWWorld::Store& settings); }; template <> diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 037620fbcc..aac4981dc8 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -799,21 +799,22 @@ namespace ESM return color; } - const std::string& MagicEffect::indexToGmstString(int effectID) + std::string_view MagicEffect::refIdToGmstString(const RefId& effectId) { - if (effectID < 0 || static_cast(effectID) >= sGmstEffectIds.size()) - throw std::runtime_error(std::string("Unimplemented effect ID ") + std::to_string(effectID)); - - return sGmstEffectIds[effectID]; + if (effectId.empty()) + return {}; + int index = refIdToIndex(effectId); + if (index < 0 || index >= Length) + return effectId.getRefIdString(); + return sGmstEffectIds[index]; } - int MagicEffect::effectGmstIdToIndex(std::string_view gmstId) + RefId MagicEffect::effectGmstIdToRefId(std::string_view gmstId) { auto name = sGmstEffectIdToIndexMap.find(gmstId); if (name == sGmstEffectIdToIndexMap.end()) - throw std::runtime_error("Unimplemented effect " + std::string(gmstId)); - - return name->second; + return {}; + return sMagicEffectIds[name->second]; } RefId MagicEffect::indexToRefId(int index) diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index d5e62ee400..e732d2872e 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -261,8 +261,8 @@ namespace ESM static const std::array sGmstEffectIds; static const std::map sGmstEffectIdToIndexMap; - static const std::string& indexToGmstString(int effectID); - static int effectGmstIdToIndex(std::string_view gmstId); + static std::string_view refIdToGmstString(const RefId& effectId); + static RefId effectGmstIdToRefId(std::string_view gmstId); static RefId indexToRefId(int index); static int refIdToIndex(const RefId& effectId);