1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-20 16:30:54 +00:00

Changed MagicEffect from IndexedStore to TypedDynamicStore in ESMStore.

This commit is contained in:
Telvanni 4Life 2025-11-30 09:01:48 -05:00
parent bf5e7ba3f6
commit 90fce49d17
6 changed files with 34 additions and 28 deletions

View file

@ -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<ESM::MagicEffect>().find(mId);
const ESM::MagicEffect* magicEffect = store->get<ESM::MagicEffect>().search(mId);
return getMagicEffectString(
*magicEffect, store->get<ESM::Attribute>().search(mArg), store->get<ESM::Skill>().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)

View file

@ -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";
<<iter->mData.mEffectID.getRefIdString() << " effect";
changed = true;
}
@ -525,7 +525,7 @@ namespace MWWorld
store->setUp();
getWritable<ESM::Skill>().setUp(get<ESM::GameSetting>());
getWritable<ESM::MagicEffect>().setUp();
getWritable<ESM::MagicEffect>().setUp(get<ESM::GameSetting>());
getWritable<ESM::Attribute>().setUp(get<ESM::GameSetting>());
getWritable<ESM4::Land>().updateLandPositions(get<ESM4::Cell>());
getWritable<ESM4::Reference>().preprocessReferences(get<ESM4::Cell>());

View file

@ -110,9 +110,6 @@ namespace MWWorld
return ptr;
}
// Need to instantiate these before they're used
template class IndexedStore<ESM::MagicEffect>;
template <class T, class Id>
TypedDynamicStore<T, Id>::TypedDynamicStore()
{
@ -380,6 +377,9 @@ namespace MWWorld
}
}
// Need to instantiate these before they're used
template class TypedDynamicStore<ESM::MagicEffect>;
// LandTexture
//=========================================================================
Store<ESM::LandTexture>::Store() = default;
@ -978,7 +978,10 @@ namespace MWWorld
// Magic effect
//=========================================================================
Store<ESM::MagicEffect>::Store() {}
void Store<ESM::MagicEffect>::setUp(const MWWorld::Store<ESM::GameSetting>& settings)
{
// MGEF record is complete. No further instantiation of fields is required.
}
// Attribute
//=========================================================================

View file

@ -19,6 +19,7 @@
#include <components/esm3/loadland.hpp>
#include <components/esm3/loadpgrd.hpp>
#include <components/esm3/loadskil.hpp>
#include <components/esm3/loadmgef.hpp>
#include <components/esm4/loadachr.hpp>
#include <components/esm4/loadcell.hpp>
#include <components/esm4/loadland.hpp>
@ -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<ESM::MagicEffect> : public IndexedStore<ESM::MagicEffect>
class Store<ESM::MagicEffect> : public TypedDynamicStore<ESM::MagicEffect>
{
using TypedDynamicStore<ESM::MagicEffect>::setUp;
public:
Store();
Store() = default;
void setUp(const MWWorld::Store<ESM::GameSetting>& settings);
};
template <>

View file

@ -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<std::size_t>(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)

View file

@ -261,8 +261,8 @@ namespace ESM
static const std::array<std::string, Length> sGmstEffectIds;
static const std::map<std::string_view, int, Misc::StringUtils::CiComp> 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);