mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-23 18:11:34 +00:00
mids and mStaticIds moved to mStoreImp
renamed recordid to storeid
This commit is contained in:
parent
87224e3007
commit
0967c11128
2 changed files with 47 additions and 37 deletions
|
@ -129,7 +129,7 @@ namespace
|
||||||
|
|
||||||
static int sRecordTypeCounter = 0;
|
static int sRecordTypeCounter = 0;
|
||||||
|
|
||||||
#define OPENMW_ESM_ADD_STORE_TYPE(__Type)template<> const int MWWorld::SRecordType<__Type>::sRecordId = sRecordTypeCounter++
|
#define OPENMW_ESM_ADD_STORE_TYPE(__Type)template<> const int MWWorld::SRecordType<__Type>::sStoreIndex = sRecordTypeCounter++
|
||||||
|
|
||||||
OPENMW_ESM_ADD_STORE_TYPE(ESM::Activator);
|
OPENMW_ESM_ADD_STORE_TYPE(ESM::Activator);
|
||||||
OPENMW_ESM_ADD_STORE_TYPE(ESM::Potion);
|
OPENMW_ESM_ADD_STORE_TYPE(ESM::Potion);
|
||||||
|
@ -185,6 +185,9 @@ static const int sRecordTypeCount = sRecordTypeCounter;
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
|
using IDMap = std::unordered_map<std::string, int, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>;
|
||||||
|
|
||||||
|
|
||||||
struct ESMStoreImp
|
struct ESMStoreImp
|
||||||
{
|
{
|
||||||
//These 3 don't inherit from store base
|
//These 3 don't inherit from store base
|
||||||
|
@ -192,9 +195,14 @@ namespace MWWorld
|
||||||
Store<ESM::Skill> mSkills;
|
Store<ESM::Skill> mSkills;
|
||||||
Store<ESM::Attribute> mAttributes;
|
Store<ESM::Attribute> mAttributes;
|
||||||
|
|
||||||
std::map<ESM::RecNameInts, StoreBase*> mESM3RecordToStore;
|
std::map<ESM::RecNameInts, StoreBase*> mESM3RecordToStore;
|
||||||
std::unordered_map<const StoreBase*, ESM::RecNameInts> mStoreToEsm3Record;
|
std::unordered_map<const StoreBase*, ESM::RecNameInts> mStoreToEsm3Record;
|
||||||
|
|
||||||
|
// Lookup of all IDs. Makes looking up references faster. Just
|
||||||
|
// maps the id name to the record type.
|
||||||
|
IDMap mIds;
|
||||||
|
IDMap mStaticIds;
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static const T* esm3StoreInsert(ESMStore& stores, const T &toInsert)
|
static const T* esm3StoreInsert(ESMStore& stores, const T &toInsert)
|
||||||
|
@ -216,7 +224,7 @@ namespace MWWorld
|
||||||
|
|
||||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||||
{
|
{
|
||||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +237,7 @@ namespace MWWorld
|
||||||
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
||||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||||
{
|
{
|
||||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +259,7 @@ namespace MWWorld
|
||||||
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
||||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||||
{
|
{
|
||||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -308,11 +316,31 @@ namespace MWWorld
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void createStore(ESMStore& stores)
|
static void createStore(ESMStore& stores)
|
||||||
{
|
{
|
||||||
stores.mStores[SRecordType<T>::sRecordId] = std::make_unique<Store<T>>();
|
stores.mStores[SRecordType<T>::sStoreIndex] = std::make_unique<Store<T>>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int ESMStore::find(const std::string& id) const
|
||||||
|
{
|
||||||
|
|
||||||
|
IDMap::const_iterator it = mStoreImp->mIds.find(id);
|
||||||
|
if (it == mStoreImp->mIds.end()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int ESMStore::findStatic(const std::string& id) const
|
||||||
|
{
|
||||||
|
IDMap::const_iterator it = mStoreImp-> mStaticIds.find(id);
|
||||||
|
if (it == mStoreImp->mStaticIds.end()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
ESMStore::ESMStore()
|
ESMStore::ESMStore()
|
||||||
{
|
{
|
||||||
mStores.resize(sRecordTypeCount);
|
mStores.resize(sRecordTypeCount);
|
||||||
|
@ -492,7 +520,7 @@ ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const
|
||||||
|
|
||||||
void ESMStore::setUp()
|
void ESMStore::setUp()
|
||||||
{
|
{
|
||||||
mIds.clear();
|
mStoreImp->mIds.clear();
|
||||||
|
|
||||||
std::map<ESM::RecNameInts, StoreBase*>::iterator storeIt = mStoreImp->mESM3RecordToStore.begin();
|
std::map<ESM::RecNameInts, StoreBase*>::iterator storeIt = mStoreImp->mESM3RecordToStore.begin();
|
||||||
for (; storeIt != mStoreImp->mESM3RecordToStore.end(); ++storeIt) {
|
for (; storeIt != mStoreImp->mESM3RecordToStore.end(); ++storeIt) {
|
||||||
|
@ -504,13 +532,13 @@ void ESMStore::setUp()
|
||||||
storeIt->second->listIdentifier(identifiers);
|
storeIt->second->listIdentifier(identifiers);
|
||||||
|
|
||||||
for (std::vector<std::string>::const_iterator record = identifiers.begin(); record != identifiers.end(); ++record)
|
for (std::vector<std::string>::const_iterator record = identifiers.begin(); record != identifiers.end(); ++record)
|
||||||
mIds[*record] = storeIt->first;
|
mStoreImp->mIds[*record] = storeIt->first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mStaticIds.empty())
|
if (mStoreImp->mStaticIds.empty())
|
||||||
for (const auto& [k, v] : mIds)
|
for (const auto& [k, v] : mStoreImp->mIds)
|
||||||
mStaticIds.emplace(Misc::StringUtils::lowerCase(k), v);
|
mStoreImp->mStaticIds.emplace(Misc::StringUtils::lowerCase(k), v);
|
||||||
|
|
||||||
getWritable<ESM::Skill>().setUp();
|
getWritable<ESM::Skill>().setUp();
|
||||||
getWritable<ESM::MagicEffect>().setUp();;
|
getWritable<ESM::MagicEffect>().setUp();;
|
||||||
|
@ -812,7 +840,7 @@ void ESMStore::removeMissingObjects(Store<T>& store)
|
||||||
record.mId = id;
|
record.mId = id;
|
||||||
|
|
||||||
ESM::NPC *ptr = npcs.insert(record);
|
ESM::NPC *ptr = npcs.insert(record);
|
||||||
mIds[ptr->mId] = ESM::REC_NPC_;
|
mStoreImp->mIds[ptr->mId] = ESM::REC_NPC_;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace MWWorld
|
||||||
struct ESMStoreImp;
|
struct ESMStoreImp;
|
||||||
template<typename T> struct SRecordType
|
template<typename T> struct SRecordType
|
||||||
{
|
{
|
||||||
static const int sRecordId;
|
static const int sStoreIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ESMStore
|
class ESMStore
|
||||||
|
@ -36,12 +36,6 @@ namespace MWWorld
|
||||||
friend struct ESMStoreImp; //This allows StoreImp to extend esmstore without beeing included everywhere
|
friend struct ESMStoreImp; //This allows StoreImp to extend esmstore without beeing included everywhere
|
||||||
std::unique_ptr<ESMStoreImp> mStoreImp;
|
std::unique_ptr<ESMStoreImp> mStoreImp;
|
||||||
|
|
||||||
// Lookup of all IDs. Makes looking up references faster. Just
|
|
||||||
// maps the id name to the record type.
|
|
||||||
using IDMap = std::unordered_map<std::string, int, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>;
|
|
||||||
IDMap mIds;
|
|
||||||
std::unordered_map<std::string, int> mStaticIds;
|
|
||||||
|
|
||||||
std::unordered_map<std::string, int> mRefCount;
|
std::unordered_map<std::string, int> mRefCount;
|
||||||
|
|
||||||
std::vector<std::unique_ptr< StoreBase >> mStores;
|
std::vector<std::unique_ptr< StoreBase >> mStores;
|
||||||
|
@ -51,7 +45,7 @@ namespace MWWorld
|
||||||
mutable std::unordered_map<std::string, std::weak_ptr<MWMechanics::SpellList>, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mSpellListCache;
|
mutable std::unordered_map<std::string, std::weak_ptr<MWMechanics::SpellList>, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mSpellListCache;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Store<T>& getWritable() {return static_cast<Store<T>&>(*mStores[SRecordType<T>::sRecordId]);}
|
Store<T>& getWritable() {return static_cast<Store<T>&>(*mStores[SRecordType<T>::sStoreIndex]);}
|
||||||
|
|
||||||
/// Validate entries in store after setup
|
/// Validate entries in store after setup
|
||||||
void validate();
|
void validate();
|
||||||
|
@ -82,22 +76,10 @@ namespace MWWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Look up the given ID in 'all'. Returns 0 if not found.
|
/// Look up the given ID in 'all'. Returns 0 if not found.
|
||||||
int find(std::string_view id) const
|
int find(const std::string& id) const;
|
||||||
{
|
|
||||||
IDMap::const_iterator it = mIds.find(id);
|
int findStatic(const std::string& id) const;
|
||||||
if (it == mIds.end()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
int findStatic(const std::string &id) const
|
|
||||||
{
|
|
||||||
IDMap::const_iterator it = mStaticIds.find(id);
|
|
||||||
if (it == mStaticIds.end()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
ESMStore();
|
ESMStore();
|
||||||
~ESMStore();
|
~ESMStore();
|
||||||
|
@ -112,7 +94,7 @@ namespace MWWorld
|
||||||
void load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue);
|
void load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
const Store<T>& get() const {return static_cast<const Store<T>&>(*mStores[SRecordType<T>::sRecordId]);}
|
const Store<T>& get() const {return static_cast<const Store<T>&>(*mStores[SRecordType<T>::sStoreIndex]);}
|
||||||
|
|
||||||
/// Insert a custom record (i.e. with a generated ID that will not clash will pre-existing records)
|
/// Insert a custom record (i.e. with a generated ID that will not clash will pre-existing records)
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
Loading…
Reference in a new issue