diff --git a/apps/esmtool/tes4.cpp b/apps/esmtool/tes4.cpp index 78e5931c0e..1b85c37c11 100644 --- a/apps/esmtool/tes4.cpp +++ b/apps/esmtool/tes4.cpp @@ -595,14 +595,14 @@ namespace EsmTool } auto visitorRec = [¶ms](ESM4::Reader& reader) { return readRecord(params, reader); }; - auto visistorGroup = [¶ms](ESM4::Reader& reader) { + auto visitorGroup = [¶ms](ESM4::Reader& reader) { if (params.mQuite) return; auto groupType = static_cast(reader.hdr().group.type); std::cout << "\nGroup: " << toString(groupType) << " " << ESM::NAME(reader.hdr().group.typeId).toStringView() << '\n'; }; - ESM4::ReaderUtils::readAll(reader, visitorRec, visistorGroup); + ESM4::ReaderUtils::readAll(reader, visitorRec, visitorGroup); } catch (const std::exception& e) { diff --git a/apps/openmw/mwworld/esmloader.cpp b/apps/openmw/mwworld/esmloader.cpp index be2b3abda9..e0280c91b5 100644 --- a/apps/openmw/mwworld/esmloader.cpp +++ b/apps/openmw/mwworld/esmloader.cpp @@ -60,13 +60,10 @@ namespace MWWorld } case ESM::Format::Tes4: { - if (mEncoder != nullptr) - { - ESM4::Reader readerESM4(std::move(stream), filepath); - auto statelessEncoder = mEncoder->getStatelessEncoder(); - readerESM4.setEncoder(&statelessEncoder); - mStore.loadESM4(readerESM4, listener, mDialogue); - } + ESM4::Reader readerESM4(std::move(stream), filepath); + auto statelessEncoder = mEncoder->getStatelessEncoder(); + readerESM4.setEncoder(&statelessEncoder); + mStore.loadESM4(readerESM4); break; } } diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index 6f39a3e602..71f4e1e40d 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -186,16 +186,6 @@ namespace MWWorld } } - template > - struct HasRecordId : std::false_type - { - }; - - template - struct HasRecordId> : std::true_type - { - }; - template static bool typedReadRecordESM4(ESM4::Reader& reader, Store& store) { @@ -382,7 +372,7 @@ namespace MWWorld } } - void ESMStore::loadESM4(ESM4::Reader& reader, Loading::Listener* listener, ESM::Dialogue*& dialogue) + void ESMStore::loadESM4(ESM4::Reader& reader) { auto visitorRec = [this](ESM4::Reader& reader) { return ESMStoreImp::readRecord(reader, *this); }; ESM4::ReaderUtils::readAll(reader, visitorRec, [](ESM4::Reader&) {}); diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index 61083b3ec0..9d737c3f53 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -173,7 +173,7 @@ namespace MWWorld void validateDynamic(); void load(ESM::ESMReader& esm, Loading::Listener* listener, ESM::Dialogue*& dialogue); - void loadESM4(ESM4::Reader& esm, Loading::Listener* listener, ESM::Dialogue*& dialogue); + void loadESM4(ESM4::Reader& esm); template const Store& get() const @@ -264,6 +264,16 @@ namespace MWWorld template <> const ESM::NPC* ESMStore::insert(const ESM::NPC& npc); + + template > + struct HasRecordId : std::false_type + { + }; + + template + struct HasRecordId> : std::true_type + { + }; } #endif diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index b69678c4d6..19363064f0 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -295,42 +295,10 @@ TEST_F(StoreTest, delete_test) ASSERT_TRUE(mEsmStore.get().getSize() == 1); } -template > -struct HasRecordId : std::false_type -{ -}; - -template -struct HasRecordId> : std::true_type -{ -}; - -struct RecNameIntChar -{ - char name[6]; - RecNameIntChar(ESM::RecNameInts recName) - { - unsigned int FourCC = recName & ~ESM::sEsm4RecnameFlag; // Removes the flag - name[0] = FourCC & 0xFF; - name[1] = (FourCC >> 8) & 0xFF; - name[2] = (FourCC >> 16) & 0xFF; - name[3] = (FourCC >> 24) & 0xFF; - if (ESM::isESM4Rec(recName)) - { - name[4] = '4'; - name[5] = '\0'; - } - else - { - name[4] = '\0'; - } - } -}; - template static unsigned int hasSameRecordId(const MWWorld::Store& store, ESM::RecNameInts RecName) { - if constexpr (HasRecordId::value) + if constexpr (MWWorld::HasRecordId::value) { return T::sRecordId == RecName ? 1 : 0; } @@ -343,16 +311,15 @@ static unsigned int hasSameRecordId(const MWWorld::Store& store, ESM::RecName template static void testRecNameIntCount(const MWWorld::Store& store, const MWWorld::ESMStore::StoreTuple& stores) { - if constexpr (HasRecordId::value) + if constexpr (MWWorld::HasRecordId::value) { const unsigned int recordIdCount = std::apply([](auto&&... x) { return (hasSameRecordId(x, T::sRecordId) + ...); }, stores); - if (recordIdCount != 1) - { - std::cout << "The same RecNameInt is used twice ESM::REC_" + std::string(RecNameIntChar(T::sRecordId).name) - << std::endl; - } - ASSERT_TRUE(recordIdCount == 1); + std::string RecordIdName(ESM::NAME(T::sRecordId & ~ESM::sEsm4RecnameFlag).toStringView()); + if (ESM::isESM4Rec(T::sRecordId)) + RecordIdName += '4'; + + ASSERT_EQ(recordIdCount, 1) << "The same RecNameInt is used twice ESM::REC_" << RecordIdName; } } @@ -361,7 +328,7 @@ static void testAllRecNameIntUnique(const MWWorld::ESMStore::StoreTuple& stores) std::apply([&stores](auto&&... x) { (testRecNameIntCount(x, stores), ...); }, stores); } -TEST_F(StoreTest, recordId_Unique) // Test that each type has a unique recordId +TEST_F(StoreTest, eachRecordTypeShouldHaveUniqueRecordId) { testAllRecNameIntUnique(MWWorld::ESMStore::StoreTuple()); } diff --git a/components/to_utf8/to_utf8.hpp b/components/to_utf8/to_utf8.hpp index f7197fe553..11a466e44c 100644 --- a/components/to_utf8/to_utf8.hpp +++ b/components/to_utf8/to_utf8.hpp @@ -68,7 +68,7 @@ namespace ToUTF8 /// ASCII-only string. Otherwise returns a view to the input. std::string_view getLegacyEnc(std::string_view input); - const StatelessUtf8Encoder getStatelessEncoder() const { return mImpl; } + StatelessUtf8Encoder getStatelessEncoder() const { return mImpl; } private: std::string mBuffer;