From 9b1c4054673700efd3453592dfe7d4bdd1be6213 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Tue, 3 Jan 2023 22:16:42 +0100 Subject: [PATCH] On store creation checks that each record has a different RecordId. --- apps/openmw/mwworld/esmstore.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 6f39a3e602..d69d4e8804 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -219,6 +219,35 @@ namespace MWWorld return false; } + template + static unsigned int hasSameRecordId(const Store& store, ESM::RecNameInts RecName) + { + if constexpr (HasRecordId::value) + { + return T::sRecordId == RecName ? 1 : 0; + } + else + { + return 0; + } + } + + template + static void testRecNameIntCount(const Store& store, const ESMStore::StoreTuple& stores) + { + if constexpr (HasRecordId::value) + { + const unsigned int recordIdCount + = std::apply([](auto&&... x) { return (hasSameRecordId(x, T::sRecordId) + ...); }, stores); + assert(recordIdCount == 1); + } + } + + static void testAllRecNameIntUnique(const ESMStore::StoreTuple& stores) + { + std::apply([&stores](auto&&... x) { (testRecNameIntCount(x, stores), ...); }, stores); + } + static bool readRecord(ESM4::Reader& reader, ESMStore& store) { return std::apply([&reader](auto&... x) { return (ESMStoreImp::typedReadRecordESM4(reader, x) || ...); }, @@ -250,6 +279,7 @@ namespace MWWorld { mStoreImp = std::make_unique(); std::apply([this](auto&... x) { (ESMStoreImp::assignStoreToIndex(*this, x), ...); }, mStoreImp->mStores); + ESMStoreImp::testAllRecNameIntUnique(mStoreImp->mStores); mDynamicCount = 0; getWritable().setCells(getWritable()); }