From c7e88344d0ae3f38ae31a86f97bec7cfaba49d46 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 8 Sep 2022 20:52:00 +0200 Subject: [PATCH 01/11] cellstore refactor first version, simply replaces each individual reflist by a tuple and makes the necessary related changes --- apps/openmw/mwworld/cellreflist.hpp | 4 +- apps/openmw/mwworld/cellstore.cpp | 227 +++++++++++---------- apps/openmw/mwworld/cellstore.hpp | 294 +++++++++------------------- 3 files changed, 224 insertions(+), 301 deletions(-) diff --git a/apps/openmw/mwworld/cellreflist.hpp b/apps/openmw/mwworld/cellreflist.hpp index 30be4a6610..9d6d63fb4f 100644 --- a/apps/openmw/mwworld/cellreflist.hpp +++ b/apps/openmw/mwworld/cellreflist.hpp @@ -7,9 +7,11 @@ namespace MWWorld { + struct CellRefListBase {}; + /// \brief Collection of references of one type template - struct CellRefList + struct CellRefList : public CellRefListBase { typedef LiveCellRef LiveRef; typedef std::list List; diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 951b1ab6fe..88679bf3f6 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -233,6 +233,22 @@ namespace namespace MWWorld { + struct CellStoreImp + { + CellStoreTuple mRefLists; + + template + static void assignStoreToIndex(CellStore& stores, CellRefList& refList) + { + const std::size_t storeIndex = CellStore::getTypeIndex(); + if (stores.mCellRefLists.size() <= storeIndex) + stores.mCellRefLists.resize(storeIndex + 1); + + assert(&store == &std::get>(stores.mCellStoreImp->mRefLists)); + + stores.mCellRefLists[storeIndex] = &refList; + } + }; template void CellRefList::load(ESM::CellRef &ref, bool deleted, const MWWorld::ESMStore &esmStore) @@ -397,10 +413,15 @@ namespace MWWorld , mHasState(false) , mLastRespawn(0, 0) , mRechargingItemsUpToDate(false) + , mCellStoreImp(std::make_unique()) { + std::apply([this](auto& ...x) {(CellStoreImp::assignStoreToIndex(*this, x), ...); }, mCellStoreImp->mRefLists); mWaterLevel = cell->mWater; } + CellStore::~CellStore() = default; + CellStore::CellStore(CellStore&&) = default; + const ESM::Cell *CellStore::getCell() const { return mCell; @@ -466,10 +487,10 @@ namespace MWWorld Ptr CellStore::searchViaActorId (int id) { - if (Ptr ptr = ::searchViaActorId (mNpcs, id, this, mMovedToAnotherCell)) + if (Ptr ptr = ::searchViaActorId (get(), id, this, mMovedToAnotherCell)) return ptr; - if (Ptr ptr = ::searchViaActorId (mCreatures, id, this, mMovedToAnotherCell)) + if (Ptr ptr = ::searchViaActorId (get(), id, this, mMovedToAnotherCell)) return ptr; for (const auto& [base, _] : mMovedHere) @@ -683,13 +704,13 @@ namespace MWWorld mHasState = true; - if (Ptr ptr = searchInContainerList (mContainers, id)) + if (Ptr ptr = searchInContainerList (get(), id)) return ptr; - if (Ptr ptr = searchInContainerList (mCreatures, id)) + if (Ptr ptr = searchInContainerList (get(), id)) return ptr; - if (Ptr ptr = searchInContainerList (mNpcs, id)) + if (Ptr ptr = searchInContainerList (get(), id)) return ptr; mHasState = oldState; @@ -711,27 +732,27 @@ namespace MWWorld // refID was modified, make sure we don't end up with duplicated refs switch (store.find(it->second)) { - case ESM::REC_ACTI: mActivators.remove(ref.mRefNum); break; - case ESM::REC_ALCH: mPotions.remove(ref.mRefNum); break; - case ESM::REC_APPA: mAppas.remove(ref.mRefNum); break; - case ESM::REC_ARMO: mArmors.remove(ref.mRefNum); break; - case ESM::REC_BOOK: mBooks.remove(ref.mRefNum); break; - case ESM::REC_CLOT: mClothes.remove(ref.mRefNum); break; - case ESM::REC_CONT: mContainers.remove(ref.mRefNum); break; - case ESM::REC_CREA: mCreatures.remove(ref.mRefNum); break; - case ESM::REC_DOOR: mDoors.remove(ref.mRefNum); break; - case ESM::REC_INGR: mIngreds.remove(ref.mRefNum); break; - case ESM::REC_LEVC: mCreatureLists.remove(ref.mRefNum); break; - case ESM::REC_LEVI: mItemLists.remove(ref.mRefNum); break; - case ESM::REC_LIGH: mLights.remove(ref.mRefNum); break; - case ESM::REC_LOCK: mLockpicks.remove(ref.mRefNum); break; - case ESM::REC_MISC: mMiscItems.remove(ref.mRefNum); break; - case ESM::REC_NPC_: mNpcs.remove(ref.mRefNum); break; - case ESM::REC_PROB: mProbes.remove(ref.mRefNum); break; - case ESM::REC_REPA: mRepairs.remove(ref.mRefNum); break; - case ESM::REC_STAT: mStatics.remove(ref.mRefNum); break; - case ESM::REC_WEAP: mWeapons.remove(ref.mRefNum); break; - case ESM::REC_BODY: mBodyParts.remove(ref.mRefNum); break; + case ESM::REC_ACTI: get().remove(ref.mRefNum); break; + case ESM::REC_ALCH: get().remove(ref.mRefNum); break; + case ESM::REC_APPA: get().remove(ref.mRefNum); break; + case ESM::REC_ARMO: get().remove(ref.mRefNum); break; + case ESM::REC_BOOK: get().remove(ref.mRefNum); break; + case ESM::REC_CLOT: get().remove(ref.mRefNum); break; + case ESM::REC_CONT: get().remove(ref.mRefNum); break; + case ESM::REC_CREA: get().remove(ref.mRefNum); break; + case ESM::REC_DOOR: get().remove(ref.mRefNum); break; + case ESM::REC_INGR: get().remove(ref.mRefNum); break; + case ESM::REC_LEVC: get().remove(ref.mRefNum); break; + case ESM::REC_LEVI: get().remove(ref.mRefNum); break; + case ESM::REC_LIGH: get().remove(ref.mRefNum); break; + case ESM::REC_LOCK: get().remove(ref.mRefNum); break; + case ESM::REC_MISC: get().remove(ref.mRefNum); break; + case ESM::REC_NPC_: get().remove(ref.mRefNum); break; + case ESM::REC_PROB: get().remove(ref.mRefNum); break; + case ESM::REC_REPA: get().remove(ref.mRefNum); break; + case ESM::REC_STAT: get().remove(ref.mRefNum); break; + case ESM::REC_WEAP: get().remove(ref.mRefNum); break; + case ESM::REC_BODY: get().remove(ref.mRefNum); break; default: break; } @@ -740,27 +761,27 @@ namespace MWWorld switch (store.find (ref.mRefID)) { - case ESM::REC_ACTI: mActivators.load(ref, deleted, store); break; - case ESM::REC_ALCH: mPotions.load(ref, deleted,store); break; - case ESM::REC_APPA: mAppas.load(ref, deleted, store); break; - case ESM::REC_ARMO: mArmors.load(ref, deleted, store); break; - case ESM::REC_BOOK: mBooks.load(ref, deleted, store); break; - case ESM::REC_CLOT: mClothes.load(ref, deleted, store); break; - case ESM::REC_CONT: mContainers.load(ref, deleted, store); break; - case ESM::REC_CREA: mCreatures.load(ref, deleted, store); break; - case ESM::REC_DOOR: mDoors.load(ref, deleted, store); break; - case ESM::REC_INGR: mIngreds.load(ref, deleted, store); break; - case ESM::REC_LEVC: mCreatureLists.load(ref, deleted, store); break; - case ESM::REC_LEVI: mItemLists.load(ref, deleted, store); break; - case ESM::REC_LIGH: mLights.load(ref, deleted, store); break; - case ESM::REC_LOCK: mLockpicks.load(ref, deleted, store); break; - case ESM::REC_MISC: mMiscItems.load(ref, deleted, store); break; - case ESM::REC_NPC_: mNpcs.load(ref, deleted, store); break; - case ESM::REC_PROB: mProbes.load(ref, deleted, store); break; - case ESM::REC_REPA: mRepairs.load(ref, deleted, store); break; - case ESM::REC_STAT: mStatics.load(ref, deleted, store); break; - case ESM::REC_WEAP: mWeapons.load(ref, deleted, store); break; - case ESM::REC_BODY: mBodyParts.load(ref, deleted, store); break; + case ESM::REC_ACTI: get().load(ref, deleted, store); break; + case ESM::REC_ALCH: get().load(ref, deleted,store); break; + case ESM::REC_APPA: get().load(ref, deleted, store); break; + case ESM::REC_ARMO: get().load(ref, deleted, store); break; + case ESM::REC_BOOK: get().load(ref, deleted, store); break; + case ESM::REC_CLOT: get().load(ref, deleted, store); break; + case ESM::REC_CONT: get().load(ref, deleted, store); break; + case ESM::REC_CREA: get().load(ref, deleted, store); break; + case ESM::REC_DOOR: get().load(ref, deleted, store); break; + case ESM::REC_INGR: get().load(ref, deleted, store); break; + case ESM::REC_LEVC: get().load(ref, deleted, store); break; + case ESM::REC_LEVI: get().load(ref, deleted, store); break; + case ESM::REC_LIGH: get().load(ref, deleted, store); break; + case ESM::REC_LOCK: get().load(ref, deleted, store); break; + case ESM::REC_MISC: get().load(ref, deleted, store); break; + case ESM::REC_NPC_: get().load(ref, deleted, store); break; + case ESM::REC_PROB: get().load(ref, deleted, store); break; + case ESM::REC_REPA: get().load(ref, deleted, store); break; + case ESM::REC_STAT: get().load(ref, deleted, store); break; + case ESM::REC_WEAP: get().load(ref, deleted, store); break; + case ESM::REC_BODY: get().load(ref, deleted, store); break; case 0: Log(Debug::Error) << "Cell reference '" + ref.mRefID + "' not found!"; return; @@ -809,27 +830,27 @@ namespace MWWorld void CellStore::writeReferences (ESM::ESMWriter& writer) const { - writeReferenceCollection (writer, mActivators); - writeReferenceCollection (writer, mPotions); - writeReferenceCollection (writer, mAppas); - writeReferenceCollection (writer, mArmors); - writeReferenceCollection (writer, mBooks); - writeReferenceCollection (writer, mClothes); - writeReferenceCollection (writer, mContainers); - writeReferenceCollection (writer, mCreatures); - writeReferenceCollection (writer, mDoors); - writeReferenceCollection (writer, mIngreds); - writeReferenceCollection (writer, mCreatureLists); - writeReferenceCollection (writer, mItemLists); - writeReferenceCollection (writer, mLights); - writeReferenceCollection (writer, mLockpicks); - writeReferenceCollection (writer, mMiscItems); - writeReferenceCollection (writer, mNpcs); - writeReferenceCollection (writer, mProbes); - writeReferenceCollection (writer, mRepairs); - writeReferenceCollection (writer, mStatics); - writeReferenceCollection (writer, mWeapons); - writeReferenceCollection (writer, mBodyParts); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); + writeReferenceCollection (writer, get()); for (const auto& [base, store] : mMovedToAnotherCell) { @@ -871,107 +892,107 @@ namespace MWWorld { case ESM::REC_ACTI: - readReferenceCollection (reader, mActivators, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_ALCH: - readReferenceCollection (reader, mPotions, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_APPA: - readReferenceCollection (reader, mAppas, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_ARMO: - readReferenceCollection (reader, mArmors, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_BOOK: - readReferenceCollection (reader, mBooks, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_CLOT: - readReferenceCollection (reader, mClothes, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_CONT: - readReferenceCollection (reader, mContainers, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_CREA: - readReferenceCollection (reader, mCreatures, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_DOOR: - readReferenceCollection (reader, mDoors, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_INGR: - readReferenceCollection (reader, mIngreds, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_LEVC: - readReferenceCollection (reader, mCreatureLists, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_LEVI: - readReferenceCollection (reader, mItemLists, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_LIGH: - readReferenceCollection (reader, mLights, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_LOCK: - readReferenceCollection (reader, mLockpicks, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_MISC: - readReferenceCollection (reader, mMiscItems, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_NPC_: - readReferenceCollection (reader, mNpcs, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_PROB: - readReferenceCollection (reader, mProbes, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_REPA: - readReferenceCollection (reader, mRepairs, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_STAT: - readReferenceCollection (reader, mStatics, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_WEAP: - readReferenceCollection (reader, mWeapons, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; case ESM::REC_BODY: - readReferenceCollection (reader, mBodyParts, cref, contentFileMap, this); + readReferenceCollection (reader, get(), cref, contentFileMap, this); break; default: @@ -1067,7 +1088,7 @@ namespace MWWorld { if (mState == State_Loaded) { - for (CellRefList::List::iterator it (mCreatures.mList.begin()); it!=mCreatures.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0) @@ -1075,7 +1096,7 @@ namespace MWWorld MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats(ptr, hours, true); } } - for (CellRefList::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0) @@ -1093,7 +1114,7 @@ namespace MWWorld if (mState == State_Loaded) { - for (CellRefList::List::iterator it (mCreatures.mList.begin()); it!=mCreatures.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0) @@ -1101,7 +1122,7 @@ namespace MWWorld ptr.getClass().getContainerStore(ptr).rechargeItems(duration); } } - for (CellRefList::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); if (!ptr.isEmpty() && ptr.getRefData().getCount() > 0) @@ -1109,7 +1130,7 @@ namespace MWWorld ptr.getClass().getContainerStore(ptr).rechargeItems(duration); } } - for (CellRefList::List::iterator it (mContainers.mList.begin()); it!=mContainers.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); if (!ptr.isEmpty() && ptr.getRefData().getCustomData() != nullptr && ptr.getRefData().getCount() > 0 @@ -1131,29 +1152,29 @@ namespace MWWorld if (MWBase::Environment::get().getWorld()->getTimeStamp() - mLastRespawn > 24*30*iMonthsToRespawn) { mLastRespawn = MWBase::Environment::get().getWorld()->getTimeStamp(); - for (CellRefList::List::iterator it (mContainers.mList.begin()); it!=mContainers.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); ptr.getClass().respawn(ptr); } } - for (CellRefList::List::iterator it (mCreatures.mList.begin()); it!=mCreatures.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); clearCorpse(ptr); ptr.getClass().respawn(ptr); } - for (CellRefList::List::iterator it (mNpcs.mList.begin()); it!=mNpcs.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); clearCorpse(ptr); ptr.getClass().respawn(ptr); } - for (CellRefList::List::iterator it (mCreatureLists.mList.begin()); it!=mCreatureLists.mList.end(); ++it) + for (CellRefList::List::iterator it (get().mList.begin()); it!=get().mList.end(); ++it) { Ptr ptr = getCurrentPtr(&*it); - // no need to clearCorpse, handled as part of mCreatures + // no need to clearCorpse, handled as part of get() ptr.getClass().respawn(ptr); } } @@ -1188,10 +1209,10 @@ namespace MWWorld } }; - update(mWeapons.mList); - update(mArmors.mList); - update(mClothes.mList); - update(mBooks.mList); + update(get().mList); + update(get().mList); + update(get().mList); + update(get().mList); } void MWWorld::CellStore::checkItem(const Ptr& ptr) diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 72d17b40dd..4076357ee5 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -2,16 +2,19 @@ #define GAME_MWWORLD_CELLSTORE_H #include +#include #include #include #include #include #include #include +#include #include "livecellref.hpp" #include "cellreflist.hpp" +#include #include #include #include @@ -44,15 +47,61 @@ namespace ESM struct CellState; struct CellId; struct RefNum; + struct Activator; + struct Potion; + struct Apparatus; + struct Armor; + struct Book; + struct Clothing; + struct Container; + struct Creature; + struct Door; + struct Ingredient; + struct CreatureLevList; + struct ItemLevList; + struct Light; + struct Lockpick; + struct Miscellaneous; + struct NPC; + struct Probe; + struct Repair; + struct Static; + struct Weapon; + struct BodyPart; } namespace MWWorld { class ESMStore; + struct CellStoreImp; + + using CellStoreTuple = std::tuple < + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList, + CellRefList>; /// \brief Mutable state of a cell class CellStore { + friend struct CellStoreImp; public: enum State @@ -78,28 +127,29 @@ namespace MWWorld MWWorld::TimeStamp mLastRespawn; - // List of refs owned by this cell - CellRefList mActivators; - CellRefList mPotions; - CellRefList mAppas; - CellRefList mArmors; - CellRefList mBooks; - CellRefList mClothes; - CellRefList mContainers; - CellRefList mCreatures; - CellRefList mDoors; - CellRefList mIngreds; - CellRefList mCreatureLists; - CellRefList mItemLists; - CellRefList mLights; - CellRefList mLockpicks; - CellRefList mMiscItems; - CellRefList mNpcs; - CellRefList mProbes; - CellRefList mRepairs; - CellRefList mStatics; - CellRefList mWeapons; - CellRefList mBodyParts; + template + static constexpr std::size_t getTypeIndex() + { + static_assert(Misc::TupleHasType, CellStoreTuple>::value); + return Misc::TupleTypeIndex, CellStoreTuple>::value; + } + + std::unique_ptr mCellStoreImp; + std::vector mCellRefLists; + + + template + CellRefList& get() + { + mHasState = true; + return static_cast&>(*mCellRefLists[getTypeIndex()]); + } + + template + const CellRefList& get() const + { + return static_cast&>(*mCellRefLists[getTypeIndex()]); + } typedef std::map MovedRefTracker; // References owned by a different cell that have been moved here. @@ -151,34 +201,29 @@ namespace MWWorld bool forEachInternal (Visitor& visitor) { return - forEachImp (visitor, mActivators) && - forEachImp (visitor, mPotions) && - forEachImp (visitor, mAppas) && - forEachImp (visitor, mArmors) && - forEachImp (visitor, mBooks) && - forEachImp (visitor, mClothes) && - forEachImp (visitor, mContainers) && - forEachImp (visitor, mDoors) && - forEachImp (visitor, mIngreds) && - forEachImp (visitor, mItemLists) && - forEachImp (visitor, mLights) && - forEachImp (visitor, mLockpicks) && - forEachImp (visitor, mMiscItems) && - forEachImp (visitor, mProbes) && - forEachImp (visitor, mRepairs) && - forEachImp (visitor, mStatics) && - forEachImp (visitor, mWeapons) && - forEachImp (visitor, mBodyParts) && - forEachImp (visitor, mCreatures) && - forEachImp (visitor, mNpcs) && - forEachImp (visitor, mCreatureLists); + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()) && + forEachImp (visitor, get()); } - /// @note If you get a linker error here, this means the given type can not be stored in a cell. The supported types are - /// defined at the bottom of this file. - template - CellRefList& get(); - public: /// Should this reference be accessible to the outside world (i.e. to scripts / game logic)? @@ -214,6 +259,8 @@ namespace MWWorld /// @param readerList The readers to use for loading of the cell on-demand. CellStore(const ESM::Cell* cell, const MWWorld::ESMStore& store, ESM::ReadersCache& readers); + CellStore(CellStore&&); + ~CellStore(); const ESM::Cell *getCell() const; @@ -362,11 +409,11 @@ namespace MWWorld // Should be phased out when we have const version of forEach inline const CellRefList& getReadOnlyDoors() const { - return mDoors; + return get(); } inline const CellRefList& getReadOnlyStatics() const { - return mStatics; + return get(); } bool isExterior() const; @@ -414,153 +461,6 @@ namespace MWWorld /// Invalid \a ref objects are silently dropped. }; - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mActivators; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mPotions; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mAppas; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mArmors; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mBooks; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mClothes; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mContainers; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mCreatures; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mDoors; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mIngreds; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mCreatureLists; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mItemLists; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mLights; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mLockpicks; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mMiscItems; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mNpcs; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mProbes; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mRepairs; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mStatics; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mWeapons; - } - - template<> - inline CellRefList& CellStore::get() - { - mHasState = true; - return mBodyParts; - } - bool operator== (const CellStore& left, const CellStore& right); bool operator!= (const CellStore& left, const CellStore& right); } From 0a5c863f272e91e6316875470adc64a9e862b0ae Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 8 Sep 2022 21:08:59 +0200 Subject: [PATCH 02/11] fewer header includes --- apps/openmw/mwclass/activator.cpp | 2 ++ apps/openmw/mwclass/apparatus.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 1 + apps/openmw/mwclass/bodypart.cpp | 2 ++ apps/openmw/mwclass/clothing.cpp | 1 + apps/openmw/mwclass/ingredient.cpp | 1 + apps/openmw/mwclass/light.cpp | 1 + apps/openmw/mwclass/lockpick.cpp | 1 + apps/openmw/mwclass/misc.cpp | 3 +++ apps/openmw/mwclass/npc.cpp | 1 + apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/probe.cpp | 1 + apps/openmw/mwclass/repair.cpp | 1 + apps/openmw/mwclass/weapon.cpp | 1 + apps/openmw/mwdialogue/filter.cpp | 1 + apps/openmw/mwgui/travelwindow.cpp | 1 + apps/openmw/mwlua/cellbindings.cpp | 2 +- apps/openmw/mwmechanics/actors.cpp | 2 ++ apps/openmw/mwmechanics/obstacle.cpp | 2 ++ apps/openmw/mwmechanics/spellcasting.cpp | 1 + apps/openmw/mwmechanics/spelleffects.cpp | 3 +++ apps/openmw/mwrender/actoranimation.cpp | 1 + apps/openmw/mwrender/animation.cpp | 3 +++ apps/openmw/mwscript/miscextensions.cpp | 2 ++ apps/openmw/mwworld/cellstore.cpp | 2 +- apps/openmw/mwworld/cellstore.hpp | 20 -------------------- apps/openmw/mwworld/localscripts.cpp | 3 +++ apps/openmw/mwworld/scene.cpp | 1 + apps/openmw/mwworld/worldimp.cpp | 2 ++ 29 files changed, 42 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 2c32fa33c8..a651a1f0b5 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 88dae17a63..885fbb3bbc 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -3,7 +3,7 @@ #include #include - +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 85d831a544..b4a9d73c5c 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwclass/bodypart.cpp b/apps/openmw/mwclass/bodypart.cpp index c341799ab4..427203c383 100644 --- a/apps/openmw/mwclass/bodypart.cpp +++ b/apps/openmw/mwclass/bodypart.cpp @@ -1,5 +1,7 @@ #include "bodypart.hpp" +#include + #include "../mwrender/renderinginterface.hpp" #include "../mwrender/objects.hpp" diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index fab3d35464..3413c271ff 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index e3f5c26899..d7b313a4f9 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 3fd61ad995..49974f9461 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 8a9495d603..0c09027d25 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index a55b2b1f09..0658212b84 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -3,6 +3,9 @@ #include #include +#include +#include + #include #include "../mwbase/environment.hpp" diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 0958c4e23a..6a0637576f 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 2b15379aa7..874d33c598 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -3,7 +3,7 @@ #include #include - +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index fd152c1906..94bb574b92 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index ce6a2fee4b..85a014a1bf 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -3,6 +3,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 9dbdbfecb0..3e58f68e7e 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/apps/openmw/mwdialogue/filter.cpp b/apps/openmw/mwdialogue/filter.cpp index 6e202a1c2f..54e853e12b 100644 --- a/apps/openmw/mwdialogue/filter.cpp +++ b/apps/openmw/mwdialogue/filter.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwgui/travelwindow.cpp b/apps/openmw/mwgui/travelwindow.cpp index 1104653c62..9533e00375 100644 --- a/apps/openmw/mwgui/travelwindow.cpp +++ b/apps/openmw/mwgui/travelwindow.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwlua/cellbindings.cpp b/apps/openmw/mwlua/cellbindings.cpp index 2a077b4270..63ea583a6c 100644 --- a/apps/openmw/mwlua/cellbindings.cpp +++ b/apps/openmw/mwlua/cellbindings.cpp @@ -1,6 +1,6 @@ #include "luabindings.hpp" -#include +#include #include "../mwworld/cellstore.hpp" diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 2c423cafd1..ee1d02aaaa 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -14,6 +14,8 @@ #include #include +#include +#include #include "../mwworld/esmstore.hpp" diff --git a/apps/openmw/mwmechanics/obstacle.cpp b/apps/openmw/mwmechanics/obstacle.cpp index 0f73890eb7..c7573c3158 100644 --- a/apps/openmw/mwmechanics/obstacle.cpp +++ b/apps/openmw/mwmechanics/obstacle.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include "../mwworld/class.hpp" #include "../mwworld/cellstore.hpp" diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index c845cfab04..63a9b0ba4c 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../mwbase/windowmanager.hpp" #include "../mwbase/soundmanager.hpp" diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index af71ed416a..78ec41e2de 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/mechanicsmanager.hpp" diff --git a/apps/openmw/mwrender/actoranimation.cpp b/apps/openmw/mwrender/actoranimation.cpp index b73a9d8a76..a6caef852e 100644 --- a/apps/openmw/mwrender/actoranimation.cpp +++ b/apps/openmw/mwrender/actoranimation.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 28dea789e5..55f444b90d 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index a005594490..632e00708c 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -22,6 +22,8 @@ #include #include +#include +#include #include diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 88679bf3f6..ef7192104b 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "../mwbase/environment.hpp" #include "../mwbase/luamanager.hpp" diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 4076357ee5..8c0fca4bf0 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -15,26 +15,6 @@ #include "cellreflist.hpp" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include "timestamp.hpp" diff --git a/apps/openmw/mwworld/localscripts.cpp b/apps/openmw/mwworld/localscripts.cpp index 2cc9261fae..ec8706320a 100644 --- a/apps/openmw/mwworld/localscripts.cpp +++ b/apps/openmw/mwworld/localscripts.cpp @@ -2,6 +2,9 @@ #include #include +#include +#include +#include #include "esmstore.hpp" #include "cellstore.hpp" diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 29c8b6f76b..3c85f52d1b 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index fc90a14b25..401ba7e24c 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include From bcc004ecf5a4dd8183b57c9bc76f1a9747a6b575 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 8 Sep 2022 23:39:05 +0200 Subject: [PATCH 03/11] Simplified read reference, by associating the types to the recNameInt using tuple + template + fold expresions magic --- apps/openmw/mwworld/cellstore.cpp | 111 +++++++----------------------- 1 file changed, 25 insertions(+), 86 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index ef7192104b..96239cc48d 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -182,14 +182,14 @@ namespace fixRestocking(record, state); if (state.mVersion < 17) { - if constexpr (std::is_same_v) + if constexpr (std::is_same_v && std::is_same_v) MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory); - else if constexpr (std::is_same_v) + else if constexpr (std::is_same_v&& std::is_same_v) MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory, &state.mNpcStats); } else if(state.mVersion < 20) { - if constexpr (std::is_same_v || std::is_same_v) + if constexpr ((std::is_same_v && std::is_same_v )|| (std::is_same_v&& std::is_same_v)) MWWorld::convertStats(state.mCreatureStats); } @@ -248,6 +248,15 @@ namespace MWWorld stores.mCellRefLists[storeIndex] = &refList; } + + template + static void ReadReferenceSwitcher(CellRefList& collection, ESM::ESMReader& reader,const ESM::CellRef& cref, const std::map& contentFileMap, MWWorld::CellStore* cellstore, ESM::RecNameInts recnNameInt) + { + if (RecordType::sRecordId == recnNameInt) + { + readReferenceCollection(reader, collection, cref, contentFileMap, cellstore); + } + } }; template @@ -891,110 +900,40 @@ namespace MWWorld switch (type) { case ESM::REC_ACTI: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_ALCH: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_APPA: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_ARMO: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_BOOK: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_CLOT: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); + case ESM::REC_INGR: + case ESM::REC_LEVI: + case ESM::REC_LIGH: + case ESM::REC_LOCK: + case ESM::REC_MISC: + case ESM::REC_PROB: + case ESM::REC_REPA: + case ESM::REC_STAT: + case ESM::REC_WEAP: + case ESM::REC_BODY: + std::apply([&reader, this, &cref, &contentFileMap, type](auto& ...x){ + (CellStoreImp::ReadReferenceSwitcher(x, reader, cref, contentFileMap, this, (ESM::RecNameInts)type),... ); + }, this->mCellStoreImp->mRefLists); break; - case ESM::REC_CONT: - readReferenceCollection (reader, get(), cref, contentFileMap, this); break; - case ESM::REC_CREA: - readReferenceCollection (reader, get(), cref, contentFileMap, this); break; - case ESM::REC_DOOR: - readReferenceCollection (reader, get(), cref, contentFileMap, this); break; - - case ESM::REC_INGR: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_LEVC: - readReferenceCollection (reader, get(), cref, contentFileMap, this); break; - - case ESM::REC_LEVI: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_LIGH: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_LOCK: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_MISC: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_NPC_: - readReferenceCollection (reader, get(), cref, contentFileMap, this); break; - - case ESM::REC_PROB: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_REPA: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_STAT: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_WEAP: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - - case ESM::REC_BODY: - - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - default: throw std::runtime_error ("unknown type in cell reference section"); From 65bd007baa267a6e8f1ec9f5d9374cac31a0e275 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Fri, 9 Sep 2022 18:28:48 +0200 Subject: [PATCH 04/11] simplified some big switch/case --- apps/openmw/mwworld/cellstore.cpp | 99 ++++++++++++------------------- components/misc/tuplemeta.hpp | 6 ++ 2 files changed, 44 insertions(+), 61 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 96239cc48d..2be8db1bf4 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -36,6 +36,7 @@ namespace { + template MWWorld::Ptr searchInContainerList(MWWorld::CellRefList& containerList, std::string_view id) { @@ -244,17 +245,18 @@ namespace MWWorld if (stores.mCellRefLists.size() <= storeIndex) stores.mCellRefLists.resize(storeIndex + 1); - assert(&store == &std::get>(stores.mCellStoreImp->mRefLists)); + assert(&refList == &std::get>(stores.mCellStoreImp->mRefLists)); stores.mCellRefLists[storeIndex] = &refList; } - template - static void ReadReferenceSwitcher(CellRefList& collection, ESM::ESMReader& reader,const ESM::CellRef& cref, const std::map& contentFileMap, MWWorld::CellStore* cellstore, ESM::RecNameInts recnNameInt) + //this function allows us to link a CellRefList to the associated recNameInt, and apply a function + template + static void recNameSwitcher(CellRefList& store, Callable&& f, ESM::RecNameInts recnNameInt) { if (RecordType::sRecordId == recnNameInt) { - readReferenceCollection(reader, collection, cref, contentFileMap, cellstore); + f(store); } } }; @@ -421,8 +423,8 @@ namespace MWWorld , mState(State_Unloaded) , mHasState(false) , mLastRespawn(0, 0) - , mRechargingItemsUpToDate(false) , mCellStoreImp(std::make_unique()) + , mRechargingItemsUpToDate(false) { std::apply([this](auto& ...x) {(CellStoreImp::assignStoreToIndex(*this, x), ...); }, mCellStoreImp->mRefLists); mWaterLevel = cell->mWater; @@ -739,64 +741,35 @@ namespace MWWorld if (it->second != ref.mRefID) { // refID was modified, make sure we don't end up with duplicated refs - switch (store.find(it->second)) - { - case ESM::REC_ACTI: get().remove(ref.mRefNum); break; - case ESM::REC_ALCH: get().remove(ref.mRefNum); break; - case ESM::REC_APPA: get().remove(ref.mRefNum); break; - case ESM::REC_ARMO: get().remove(ref.mRefNum); break; - case ESM::REC_BOOK: get().remove(ref.mRefNum); break; - case ESM::REC_CLOT: get().remove(ref.mRefNum); break; - case ESM::REC_CONT: get().remove(ref.mRefNum); break; - case ESM::REC_CREA: get().remove(ref.mRefNum); break; - case ESM::REC_DOOR: get().remove(ref.mRefNum); break; - case ESM::REC_INGR: get().remove(ref.mRefNum); break; - case ESM::REC_LEVC: get().remove(ref.mRefNum); break; - case ESM::REC_LEVI: get().remove(ref.mRefNum); break; - case ESM::REC_LIGH: get().remove(ref.mRefNum); break; - case ESM::REC_LOCK: get().remove(ref.mRefNum); break; - case ESM::REC_MISC: get().remove(ref.mRefNum); break; - case ESM::REC_NPC_: get().remove(ref.mRefNum); break; - case ESM::REC_PROB: get().remove(ref.mRefNum); break; - case ESM::REC_REPA: get().remove(ref.mRefNum); break; - case ESM::REC_STAT: get().remove(ref.mRefNum); break; - case ESM::REC_WEAP: get().remove(ref.mRefNum); break; - case ESM::REC_BODY: get().remove(ref.mRefNum); break; - default: - break; - } + ESM::RecNameInts foundType = (ESM::RecNameInts)store.find(it->second); + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, foundType](auto& x) {CellStoreImp::recNameSwitcher(x, [&ref](auto& storeIn) + { + storeIn.remove(ref.mRefNum); + }, foundType); + }); } } - switch (store.find (ref.mRefID)) + ESM::RecNameInts foundType = (ESM::RecNameInts)store.find(ref.mRefID); + bool handledType = false; + if (foundType != 0) { - case ESM::REC_ACTI: get().load(ref, deleted, store); break; - case ESM::REC_ALCH: get().load(ref, deleted,store); break; - case ESM::REC_APPA: get().load(ref, deleted, store); break; - case ESM::REC_ARMO: get().load(ref, deleted, store); break; - case ESM::REC_BOOK: get().load(ref, deleted, store); break; - case ESM::REC_CLOT: get().load(ref, deleted, store); break; - case ESM::REC_CONT: get().load(ref, deleted, store); break; - case ESM::REC_CREA: get().load(ref, deleted, store); break; - case ESM::REC_DOOR: get().load(ref, deleted, store); break; - case ESM::REC_INGR: get().load(ref, deleted, store); break; - case ESM::REC_LEVC: get().load(ref, deleted, store); break; - case ESM::REC_LEVI: get().load(ref, deleted, store); break; - case ESM::REC_LIGH: get().load(ref, deleted, store); break; - case ESM::REC_LOCK: get().load(ref, deleted, store); break; - case ESM::REC_MISC: get().load(ref, deleted, store); break; - case ESM::REC_NPC_: get().load(ref, deleted, store); break; - case ESM::REC_PROB: get().load(ref, deleted, store); break; - case ESM::REC_REPA: get().load(ref, deleted, store); break; - case ESM::REC_STAT: get().load(ref, deleted, store); break; - case ESM::REC_WEAP: get().load(ref, deleted, store); break; - case ESM::REC_BODY: get().load(ref, deleted, store); break; + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType, &handledType](auto& x) {CellStoreImp::recNameSwitcher(x, [&ref, &deleted, &store, &handledType](auto& storeIn) + { + handledType = true; + storeIn.load(ref, deleted, store); + }, foundType); + }); + } + else + { + Log(Debug::Error) << "Cell reference '" + ref.mRefID + "' not found!"; return; + } - case 0: Log(Debug::Error) << "Cell reference '" + ref.mRefID + "' not found!"; return; - - default: - Log(Debug::Error) << "Error: Ignoring reference '" << ref.mRefID << "' of unhandled type"; - return; + if (!handledType) + { + Log(Debug::Error) << "Error: Ignoring reference '" << ref.mRefID << "' of unhandled type"; + return; } refNumToID[ref.mRefNum] = ref.mRefID; @@ -915,9 +888,13 @@ namespace MWWorld case ESM::REC_STAT: case ESM::REC_WEAP: case ESM::REC_BODY: - std::apply([&reader, this, &cref, &contentFileMap, type](auto& ...x){ - (CellStoreImp::ReadReferenceSwitcher(x, reader, cref, contentFileMap, this, (ESM::RecNameInts)type),... ); - }, this->mCellStoreImp->mRefLists); + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&reader, this, &cref, &contentFileMap, type](auto&& x) { + CellStoreImp::recNameSwitcher( + x, + [&reader, this, &cref, &contentFileMap]( + auto& store) { readReferenceCollection(reader, store, cref, contentFileMap, this); }, + (ESM::RecNameInts)type); + }); break; case ESM::REC_CONT: readReferenceCollection (reader, get(), cref, contentFileMap, this); diff --git a/components/misc/tuplemeta.hpp b/components/misc/tuplemeta.hpp index fda6fb32e3..af92066959 100644 --- a/components/misc/tuplemeta.hpp +++ b/components/misc/tuplemeta.hpp @@ -30,6 +30,12 @@ namespace Misc { static constexpr std::size_t value = 1 + TupleTypeIndex>::value; }; + + template + void tupleForEach(TupleType& tuple, Callable&& f) + { + std::apply([&f](auto& ...x) {(f(x), ...); }, tuple); + } } #endif From 158eea934dab866737249b1706466f093db8879c Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 10:03:13 +0200 Subject: [PATCH 05/11] removed more code from the header simplified forEachInternal function using tupleForEach moved some function that were in CellStoreImp that didn't need to be --- apps/openmw/mwworld/cellstore.cpp | 49 ++++++++++++++++++++++++------- apps/openmw/mwworld/cellstore.hpp | 42 -------------------------- 2 files changed, 38 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 2be8db1bf4..a32a1ac24a 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -230,6 +230,31 @@ namespace MWWorld::LiveCellRefBase* base = &collection.mList.back(); MWBase::Environment::get().getLuaManager()->registerObject(MWWorld::Ptr(base, cellstore)); } + + //this function allows us to link a CellRefList to the associated recNameInt, and apply a function + template + static void recNameSwitcher(MWWorld::CellRefList& store, Callable&& f, ESM::RecNameInts recnNameInt) + { + if (RecordType::sRecordId == recnNameInt) + { + f(store); + } + } + + // helper function for forEachInternal + template + bool forEachImp (Visitor& visitor, List& list, MWWorld::CellStore* cellStore) + { + for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end(); + ++iter) + { + if (!MWWorld::CellStore::isAccessible(iter->mData, iter->mRef)) + continue; + if (!visitor (MWWorld::Ptr(&*iter, cellStore))) + return false; + } + return true; + } } namespace MWWorld @@ -250,14 +275,16 @@ namespace MWWorld stores.mCellRefLists[storeIndex] = &refList; } - //this function allows us to link a CellRefList to the associated recNameInt, and apply a function - template - static void recNameSwitcher(CellRefList& store, Callable&& f, ESM::RecNameInts recnNameInt) + + // listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved objects are accounted for. + template + static bool forEachInternal (Visitor& visitor, MWWorld::CellStore& cellStore) { - if (RecordType::sRecordId == recnNameInt) - { - f(store); - } + bool returnValue = true; + + Misc::tupleForEach(cellStore.mCellStoreImp->mRefLists, [&visitor, &returnValue, &cellStore](auto& store) { returnValue = returnValue && forEachImp(visitor, store, &cellStore); }); + + return returnValue; } }; @@ -401,7 +428,7 @@ namespace MWWorld mMergedRefs.clear(); mRechargingItemsUpToDate = false; MergeVisitor visitor(mMergedRefs, mMovedHere, mMovedToAnotherCell); - forEachInternal(visitor); + CellStoreImp::forEachInternal(visitor, *this); visitor.merge(); } @@ -742,7 +769,7 @@ namespace MWWorld { // refID was modified, make sure we don't end up with duplicated refs ESM::RecNameInts foundType = (ESM::RecNameInts)store.find(it->second); - Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, foundType](auto& x) {CellStoreImp::recNameSwitcher(x, [&ref](auto& storeIn) + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, foundType](auto& x) {recNameSwitcher(x, [&ref](auto& storeIn) { storeIn.remove(ref.mRefNum); }, foundType); @@ -754,7 +781,7 @@ namespace MWWorld bool handledType = false; if (foundType != 0) { - Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType, &handledType](auto& x) {CellStoreImp::recNameSwitcher(x, [&ref, &deleted, &store, &handledType](auto& storeIn) + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType, &handledType](auto& x) {recNameSwitcher(x, [&ref, &deleted, &store, &handledType](auto& storeIn) { handledType = true; storeIn.load(ref, deleted, store); @@ -889,7 +916,7 @@ namespace MWWorld case ESM::REC_WEAP: case ESM::REC_BODY: Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&reader, this, &cref, &contentFileMap, type](auto&& x) { - CellStoreImp::recNameSwitcher( + recNameSwitcher( x, [&reader, this, &cref, &contentFileMap]( auto& store) { readReferenceCollection(reader, store, cref, contentFileMap, this); }, diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 8c0fca4bf0..7897d8587c 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -161,48 +161,6 @@ namespace MWWorld void rechargeItems(float duration); void checkItem(const Ptr& ptr); - // helper function for forEachInternal - template - bool forEachImp (Visitor& visitor, List& list) - { - for (typename List::List::iterator iter (list.mList.begin()); iter!=list.mList.end(); - ++iter) - { - if (!isAccessible(iter->mData, iter->mRef)) - continue; - if (!visitor (MWWorld::Ptr(&*iter, this))) - return false; - } - return true; - } - - // listing only objects owned by this cell. Internal use only, you probably want to use forEach() so that moved objects are accounted for. - template - bool forEachInternal (Visitor& visitor) - { - return - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()) && - forEachImp (visitor, get()); - } public: From 73e3c0adf6319dd0af8bd8fa7f9c5ad455e9bb46 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 19:48:48 +0200 Subject: [PATCH 06/11] applies some review changes fixed c style cast fixed useless includes fixed callback not last member fixed situation where type==0 and therefore function call isn't necessary --- apps/openmw/mwworld/cellstore.cpp | 53 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index a32a1ac24a..cab0606bfe 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -18,7 +18,28 @@ #include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/luamanager.hpp" @@ -233,7 +254,7 @@ namespace //this function allows us to link a CellRefList to the associated recNameInt, and apply a function template - static void recNameSwitcher(MWWorld::CellRefList& store, Callable&& f, ESM::RecNameInts recnNameInt) + static void recNameSwitcher(MWWorld::CellRefList& store, ESM::RecNameInts recnNameInt, Callable&& f) { if (RecordType::sRecordId == recnNameInt) { @@ -768,24 +789,24 @@ namespace MWWorld if (it->second != ref.mRefID) { // refID was modified, make sure we don't end up with duplicated refs - ESM::RecNameInts foundType = (ESM::RecNameInts)store.find(it->second); - Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, foundType](auto& x) {recNameSwitcher(x, [&ref](auto& storeIn) - { - storeIn.remove(ref.mRefNum); - }, foundType); - }); + ESM::RecNameInts foundType = static_cast(store.find(it->second)); + if (foundType != 0) + { + Misc::tupleForEach(this->mCellStoreImp->mRefLists, + [&ref, foundType](auto& x) { recNameSwitcher(x, foundType, [&ref](auto& storeIn) { storeIn.remove(ref.mRefNum); }); }); + } } } - ESM::RecNameInts foundType = (ESM::RecNameInts)store.find(ref.mRefID); + ESM::RecNameInts foundType = static_cast(store.find(ref.mRefID)); bool handledType = false; if (foundType != 0) { - Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType, &handledType](auto& x) {recNameSwitcher(x, [&ref, &deleted, &store, &handledType](auto& storeIn) - { + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&ref, &deleted, &store, foundType, &handledType](auto& x) { + recNameSwitcher(x, foundType, [&ref, &deleted, &store, &handledType](auto& storeIn) { handledType = true; storeIn.load(ref, deleted, store); - }, foundType); + }); }); } else @@ -916,11 +937,9 @@ namespace MWWorld case ESM::REC_WEAP: case ESM::REC_BODY: Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&reader, this, &cref, &contentFileMap, type](auto&& x) { - recNameSwitcher( - x, - [&reader, this, &cref, &contentFileMap]( - auto& store) { readReferenceCollection(reader, store, cref, contentFileMap, this); }, - (ESM::RecNameInts)type); + recNameSwitcher(x, static_cast(type), [&reader, this, &cref, &contentFileMap](auto& store) { + readReferenceCollection(reader, store, cref, contentFileMap, this); + }); }); break; case ESM::REC_CONT: From 256d8a699a79f4fd2d9e8e54ff4011f0a5ea190d Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 20:13:18 +0200 Subject: [PATCH 07/11] moves one function from tuplemeta.hpp to newly created tuplehelpers.hpp --- apps/openmw/mwworld/cellstore.cpp | 1 + components/CMakeLists.txt | 2 +- components/misc/tuplemeta.hpp | 6 ------ 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index cab0606bfe..9117e40de0 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -5,6 +5,7 @@ #include +#include #include #include #include diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 9dc752e4aa..f418fe669c 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -197,7 +197,7 @@ add_component_dir (esm4 add_component_dir (misc constants utf8stream resourcehelpers rng messageformatparser weakcache thread - compression osguservalues errorMarker color + compression osguservalues errorMarker color tuplemeta tuplehelpers ) add_component_dir (stereo diff --git a/components/misc/tuplemeta.hpp b/components/misc/tuplemeta.hpp index af92066959..fda6fb32e3 100644 --- a/components/misc/tuplemeta.hpp +++ b/components/misc/tuplemeta.hpp @@ -30,12 +30,6 @@ namespace Misc { static constexpr std::size_t value = 1 + TupleTypeIndex>::value; }; - - template - void tupleForEach(TupleType& tuple, Callable&& f) - { - std::apply([&f](auto& ...x) {(f(x), ...); }, tuple); - } } #endif From cdc7864863a9b59041d4413adb370fc5d452f9d1 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 20:25:18 +0200 Subject: [PATCH 08/11] missing file --- components/misc/tuplehelpers.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 components/misc/tuplehelpers.hpp diff --git a/components/misc/tuplehelpers.hpp b/components/misc/tuplehelpers.hpp new file mode 100644 index 0000000000..09e61c1539 --- /dev/null +++ b/components/misc/tuplehelpers.hpp @@ -0,0 +1,15 @@ +#ifndef OPENMW_COMPONENTS_MISC_TUPLEHELPER_H +#define OPENMW_COMPONENTS_MISC_TUPLEHELPER_H + +#include + +namespace Misc +{ + template + void tupleForEach(TupleType& tuple, Callable&& f) + { + std::apply([&f](auto&... x) { (f(x), ...); }, tuple); + } +} + +#endif From 10de4a51561827e84c128ddd8875d5a5118832ec Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 22:20:47 +0200 Subject: [PATCH 09/11] created a relationship between the record type and the corresponding state used in readReferences and writeReferences. Simplifies the calls to those functions --- apps/openmw/mwworld/cellstore.cpp | 117 +++++++++++++----------------- 1 file changed, 50 insertions(+), 67 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 9117e40de0..486425156b 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -59,6 +59,38 @@ namespace { + template + struct RecordToState + { + using StateType = ESM::ObjectState; + }; + + template <> + struct RecordToState + { + using StateType = ESM::NpcState; + }; + template <> + struct RecordToState + { + using StateType = ESM::CreatureState; + }; + template <> + struct RecordToState + { + using StateType = ESM::DoorState; + }; + template <> + struct RecordToState + { + using StateType = ESM::ContainerState; + }; + template <> + struct RecordToState + { + using StateType = ESM::CreatureLevListState; + }; + template MWWorld::Ptr searchInContainerList(MWWorld::CellRefList& containerList, std::string_view id) { @@ -99,7 +131,7 @@ namespace return MWWorld::Ptr(); } - template + template void writeReferenceCollection (ESM::ESMWriter& writer, const MWWorld::CellRefList& collection) { @@ -120,8 +152,8 @@ namespace // Deleted reference that did not come from a content file -> ignore continue; } - - RecordType state; + using StateType = RecordToState::StateType; + StateType state; iter->save (state); // recordId currently unused @@ -171,13 +203,14 @@ namespace fixRestockingImpl(base, state); } - template + template void readReferenceCollection (ESM::ESMReader& reader, MWWorld::CellRefList& collection, const ESM::CellRef& cref, const std::map& contentFileMap, MWWorld::CellStore* cellstore) { const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); - RecordType state; + using StateType = RecordToState::StateType; + StateType state; state.mRef = cref; state.load(reader); @@ -205,14 +238,14 @@ namespace fixRestocking(record, state); if (state.mVersion < 17) { - if constexpr (std::is_same_v && std::is_same_v) + if constexpr (std::is_same_v) MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory); - else if constexpr (std::is_same_v&& std::is_same_v) + else if constexpr (std::is_same_v) MWWorld::convertMagicEffects(state.mCreatureStats, state.mInventory, &state.mNpcStats); } else if(state.mVersion < 20) { - if constexpr ((std::is_same_v && std::is_same_v )|| (std::is_same_v&& std::is_same_v)) + if constexpr (std::is_same_v|| std::is_same_v) MWWorld::convertStats(state.mCreatureStats); } @@ -861,27 +894,7 @@ namespace MWWorld void CellStore::writeReferences (ESM::ESMWriter& writer) const { - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); - writeReferenceCollection (writer, get()); + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&writer](auto& cellRefList) { writeReferenceCollection(writer, cellRefList); }); for (const auto& [base, store] : mMovedToAnotherCell) { @@ -919,48 +932,18 @@ namespace MWWorld continue; } - switch (type) + if (type != 0) { - case ESM::REC_ACTI: - case ESM::REC_ALCH: - case ESM::REC_APPA: - case ESM::REC_ARMO: - case ESM::REC_BOOK: - case ESM::REC_CLOT: - case ESM::REC_INGR: - case ESM::REC_LEVI: - case ESM::REC_LIGH: - case ESM::REC_LOCK: - case ESM::REC_MISC: - case ESM::REC_PROB: - case ESM::REC_REPA: - case ESM::REC_STAT: - case ESM::REC_WEAP: - case ESM::REC_BODY: - Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&reader, this, &cref, &contentFileMap, type](auto&& x) { - recNameSwitcher(x, static_cast(type), [&reader, this, &cref, &contentFileMap](auto& store) { - readReferenceCollection(reader, store, cref, contentFileMap, this); + bool foundCorrespondingStore = false; + Misc::tupleForEach(this->mCellStoreImp->mRefLists, [&reader, this, &cref, &contentFileMap, &foundCorrespondingStore, type](auto&& x) { + recNameSwitcher(x, static_cast(type), [&reader, this, &cref, &contentFileMap, &foundCorrespondingStore](auto& store) { + foundCorrespondingStore = true; + readReferenceCollection(reader, store, cref, contentFileMap, this); }); }); - break; - case ESM::REC_CONT: - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_CREA: - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_DOOR: - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_LEVC: - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - case ESM::REC_NPC_: - readReferenceCollection (reader, get(), cref, contentFileMap, this); - break; - default: - throw std::runtime_error ("unknown type in cell reference section"); + if (!foundCorrespondingStore) + throw std::runtime_error("unknown type in cell reference section"); } } From 9a19bb84a4d7e96b3ff94b944a3c8902109b9ebb Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sat, 10 Sep 2022 22:58:15 +0200 Subject: [PATCH 10/11] fixed Clang and whitespace difference with master --- apps/openmw/mwworld/cellstore.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 486425156b..bfd7cf966c 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -41,7 +41,6 @@ #include #include - #include "../mwbase/environment.hpp" #include "../mwbase/luamanager.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -152,7 +151,7 @@ namespace // Deleted reference that did not come from a content file -> ignore continue; } - using StateType = RecordToState::StateType; + using StateType = typename RecordToState::StateType; StateType state; iter->save (state); @@ -209,7 +208,7 @@ namespace { const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); - using StateType = RecordToState::StateType; + using StateType = typename RecordToState::StateType; StateType state; state.mRef = cref; state.load(reader); @@ -245,7 +244,7 @@ namespace } else if(state.mVersion < 20) { - if constexpr (std::is_same_v|| std::is_same_v) + if constexpr (std::is_same_v || std::is_same_v) MWWorld::convertStats(state.mCreatureStats); } From 10899ed6808db2be0313ab3e19a041713bfd4141 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Sun, 11 Sep 2022 13:18:56 +0200 Subject: [PATCH 11/11] typo --- components/misc/tuplehelpers.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/misc/tuplehelpers.hpp b/components/misc/tuplehelpers.hpp index 09e61c1539..0bec07f6d8 100644 --- a/components/misc/tuplehelpers.hpp +++ b/components/misc/tuplehelpers.hpp @@ -1,5 +1,5 @@ -#ifndef OPENMW_COMPONENTS_MISC_TUPLEHELPER_H -#define OPENMW_COMPONENTS_MISC_TUPLEHELPER_H +#ifndef OPENMW_COMPONENTS_MISC_TUPLEHELPERS_H +#define OPENMW_COMPONENTS_MISC_TUPLEHELPERS_H #include