diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 322a60aec9..0993bc181f 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -204,6 +204,41 @@ namespace MWWorld } return ptr; } + + template + static const T * ESM3overrideRecord(ESMStore& stores, const T &x) { + Store &store = const_cast &>( stores.get()); + + T *ptr = store.insert(x); + for (ESMStore::iterator it = stores.mStores.begin(); it != stores.mStores.end(); ++it) { + if (it->second == &store) { + stores.mIds[ptr->mId] = it->first; + } + } + return ptr; + } + + template + static const T *ESM3insertStatic(ESMStore& stores, const T &x) + { + const std::string id = "$dynamic" + std::to_string(stores.mDynamicCount++); + + Store &store = const_cast &>( stores.get()); + if (store.search(id) != nullptr) + { + const std::string msg = "Try to override existing record '" + id + "'"; + throw std::runtime_error(msg); + } + T record = x; + + T *ptr = store.insertStatic(record); + for (ESMStore::iterator it = stores.mStores.begin(); it != stores.mStores.end(); ++it) { + if (it->second == &store) { + stores.mIds[ptr->mId] = it->first; + } + } + return ptr; + } }; ESMStore::ESMStore() @@ -699,6 +734,24 @@ void ESMStore::removeMissingObjects(Store& store) ESM3Insert(ESM::Spell); #undef ESM3Insert +#define ESM3InsertStatic(__Type) template<> const __Type* ESMStore::insertStatic<__Type>(const __Type &toInsert) { return ESMStoreImp::ESM3insertStatic(*this, toInsert); } + ESM3InsertStatic(ESM::GameSetting); + ESM3InsertStatic(ESM::Static); + ESM3InsertStatic(ESM::Door); + ESM3InsertStatic(ESM::Global); + ESM3InsertStatic(ESM::NPC); +#undef ESM3InsertStatic + + +#define ESM3overrideRecord(__Type) template<> const __Type* ESMStore::overrideRecord<__Type>(const __Type &toInsert) { return ESMStoreImp::ESM3overrideRecord(*this, toInsert); } + ESM3overrideRecord(ESM::Container); + ESM3overrideRecord(ESM::Creature); + ESM3overrideRecord(ESM::CreatureLevList); + ESM3overrideRecord(ESM::Door); + ESM3overrideRecord(ESM::ItemLevList); + ESM3overrideRecord(ESM::NPC); +#undef ESM3overrideRecord + template <> const Store &ESMStore::get() const { return mStoreImp->mActivators; diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 4f6f250103..1eba766e05 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -119,36 +119,10 @@ namespace MWWorld /// Insert a record with set ID, and allow it to override a pre-existing static record. template - const T *overrideRecord(const T &x) { - Store &store = const_cast &>(get()); - - T *ptr = store.insert(x); - for (iterator it = mStores.begin(); it != mStores.end(); ++it) { - if (it->second == &store) { - mIds[ptr->mId] = it->first; - } - } - return ptr; - } + const T *overrideRecord(const T &x); template - const T *insertStatic(const T &x) - { - Store &store = const_cast &>(get()); - if (store.search(x.mId) != nullptr) - { - const std::string msg = "Try to override existing record '" + x.mId + "'"; - throw std::runtime_error(msg); - } - - T *ptr = store.insertStatic(x); - for (iterator it = mStores.begin(); it != mStores.end(); ++it) { - if (it->second == &store) { - mIds[ptr->mId] = it->first; - } - } - return ptr; - } + const T *insertStatic(const T &x); // This method must be called once, after loading all master/plugin files. This can only be done // from the outside, so it must be public.