mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-16 06:09:41 +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
apps/openmw/mwworld
|
@ -129,7 +129,7 @@ namespace
|
|||
|
||||
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::Potion);
|
||||
|
@ -185,6 +185,9 @@ static const int sRecordTypeCount = sRecordTypeCounter;
|
|||
|
||||
namespace MWWorld
|
||||
{
|
||||
using IDMap = std::unordered_map<std::string, int, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual>;
|
||||
|
||||
|
||||
struct ESMStoreImp
|
||||
{
|
||||
//These 3 don't inherit from store base
|
||||
|
@ -192,9 +195,14 @@ namespace MWWorld
|
|||
Store<ESM::Skill> mSkills;
|
||||
Store<ESM::Attribute> mAttributes;
|
||||
|
||||
std::map<ESM::RecNameInts, StoreBase*> mESM3RecordToStore;
|
||||
std::map<ESM::RecNameInts, StoreBase*> mESM3RecordToStore;
|
||||
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>
|
||||
static const T* esm3StoreInsert(ESMStore& stores, const T &toInsert)
|
||||
|
@ -216,7 +224,7 @@ namespace MWWorld
|
|||
|
||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||
{
|
||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
@ -229,7 +237,7 @@ namespace MWWorld
|
|||
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||
{
|
||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
@ -251,7 +259,7 @@ namespace MWWorld
|
|||
auto esm3RecordType_find = stores.mStoreImp->mStoreToEsm3Record.find(&stores.get<T>());
|
||||
if (esm3RecordType_find != stores.mStoreImp->mStoreToEsm3Record.end())
|
||||
{
|
||||
stores.mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
stores.mStoreImp->mIds[ptr->mId] = esm3RecordType_find->second;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
@ -308,11 +316,31 @@ namespace MWWorld
|
|||
template<typename T>
|
||||
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()
|
||||
{
|
||||
mStores.resize(sRecordTypeCount);
|
||||
|
@ -492,7 +520,7 @@ ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const
|
|||
|
||||
void ESMStore::setUp()
|
||||
{
|
||||
mIds.clear();
|
||||
mStoreImp->mIds.clear();
|
||||
|
||||
std::map<ESM::RecNameInts, StoreBase*>::iterator storeIt = mStoreImp->mESM3RecordToStore.begin();
|
||||
for (; storeIt != mStoreImp->mESM3RecordToStore.end(); ++storeIt) {
|
||||
|
@ -504,13 +532,13 @@ void ESMStore::setUp()
|
|||
storeIt->second->listIdentifier(identifiers);
|
||||
|
||||
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())
|
||||
for (const auto& [k, v] : mIds)
|
||||
mStaticIds.emplace(Misc::StringUtils::lowerCase(k), v);
|
||||
if (mStoreImp->mStaticIds.empty())
|
||||
for (const auto& [k, v] : mStoreImp->mIds)
|
||||
mStoreImp->mStaticIds.emplace(Misc::StringUtils::lowerCase(k), v);
|
||||
|
||||
getWritable<ESM::Skill>().setUp();
|
||||
getWritable<ESM::MagicEffect>().setUp();;
|
||||
|
@ -812,7 +840,7 @@ void ESMStore::removeMissingObjects(Store<T>& store)
|
|||
record.mId = id;
|
||||
|
||||
ESM::NPC *ptr = npcs.insert(record);
|
||||
mIds[ptr->mId] = ESM::REC_NPC_;
|
||||
mStoreImp->mIds[ptr->mId] = ESM::REC_NPC_;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace MWWorld
|
|||
struct ESMStoreImp;
|
||||
template<typename T> struct SRecordType
|
||||
{
|
||||
static const int sRecordId;
|
||||
static const int sStoreIndex;
|
||||
};
|
||||
|
||||
class ESMStore
|
||||
|
@ -36,12 +36,6 @@ namespace MWWorld
|
|||
friend struct ESMStoreImp; //This allows StoreImp to extend esmstore without beeing included everywhere
|
||||
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::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;
|
||||
|
||||
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
|
||||
void validate();
|
||||
|
@ -82,22 +76,10 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
/// Look up the given ID in 'all'. Returns 0 if not found.
|
||||
int find(std::string_view id) const
|
||||
{
|
||||
IDMap::const_iterator it = mIds.find(id);
|
||||
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;
|
||||
}
|
||||
int find(const std::string& id) const;
|
||||
|
||||
int findStatic(const std::string& id) const;
|
||||
|
||||
|
||||
ESMStore();
|
||||
~ESMStore();
|
||||
|
@ -112,7 +94,7 @@ namespace MWWorld
|
|||
void load(ESM::ESMReader &esm, Loading::Listener* listener, ESM::Dialogue*& dialogue);
|
||||
|
||||
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)
|
||||
template <class T>
|
||||
|
|
Loading…
Reference in a new issue