From bcc004ecf5a4dd8183b57c9bc76f1a9747a6b575 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Thu, 8 Sep 2022 23:39:05 +0200 Subject: [PATCH] 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");