mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 21:45:33 +00:00
Applies review advice.
This commit is contained in:
parent
e80dbd7c95
commit
631fa26872
6 changed files with 27 additions and 63 deletions
|
@ -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<ESM4::GroupType>(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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -186,16 +186,6 @@ namespace MWWorld
|
|||
}
|
||||
}
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasRecordId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasRecordId<T, std::void_t<decltype(T::sRecordId)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static bool typedReadRecordESM4(ESM4::Reader& reader, Store<T>& 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&) {});
|
||||
|
|
|
@ -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 <class T>
|
||||
const Store<T>& get() const
|
||||
|
@ -264,6 +264,16 @@ namespace MWWorld
|
|||
|
||||
template <>
|
||||
const ESM::NPC* ESMStore::insert<ESM::NPC>(const ESM::NPC& npc);
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasRecordId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasRecordId<T, std::void_t<decltype(T::sRecordId)>> : std::true_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -295,42 +295,10 @@ TEST_F(StoreTest, delete_test)
|
|||
ASSERT_TRUE(mEsmStore.get<RecordType>().getSize() == 1);
|
||||
}
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasRecordId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasRecordId<T, std::void_t<decltype(T::sRecordId)>> : 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 <typename T>
|
||||
static unsigned int hasSameRecordId(const MWWorld::Store<T>& store, ESM::RecNameInts RecName)
|
||||
{
|
||||
if constexpr (HasRecordId<T>::value)
|
||||
if constexpr (MWWorld::HasRecordId<T>::value)
|
||||
{
|
||||
return T::sRecordId == RecName ? 1 : 0;
|
||||
}
|
||||
|
@ -343,16 +311,15 @@ static unsigned int hasSameRecordId(const MWWorld::Store<T>& store, ESM::RecName
|
|||
template <typename T>
|
||||
static void testRecNameIntCount(const MWWorld::Store<T>& store, const MWWorld::ESMStore::StoreTuple& stores)
|
||||
{
|
||||
if constexpr (HasRecordId<T>::value)
|
||||
if constexpr (MWWorld::HasRecordId<T>::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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue