mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:15:37 +00:00
Applied review advice
better deals with templated functions meant for esm3 used by esm4s. simplified loading of esm4 and dealing with unhandled record types.
This commit is contained in:
parent
e9190bedc8
commit
3b2d9161c4
5 changed files with 12 additions and 19 deletions
|
@ -184,7 +184,7 @@ namespace EsmTool
|
|||
if constexpr (hasFormId<T>)
|
||||
std::cout << "\n FormId: " << value.mFormId;
|
||||
if constexpr (hasRefId<T>)
|
||||
std::cout << "\n RefId: " << value.mId;
|
||||
std::cout << "\n FormId: " << value.mId;
|
||||
if constexpr (hasFlags<T>)
|
||||
std::cout << "\n Record flags: " << recordFlags(value.mFlags);
|
||||
if constexpr (hasEditorId<T>)
|
||||
|
@ -196,7 +196,6 @@ namespace EsmTool
|
|||
if constexpr (hasKf<T>)
|
||||
std::cout << "\n Kf:" << WriteArray("\n - ", value.mKf);
|
||||
std::cout << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
bool readRecord(const Params& params, ESM4::Reader& reader)
|
||||
|
|
|
@ -28,10 +28,6 @@ namespace MWWorld
|
|||
{
|
||||
|
||||
auto stream = Files::openBinaryInputFileStream(filepath);
|
||||
if (!stream->is_open())
|
||||
{
|
||||
throw std::runtime_error(std::string("File Failed to open file: ") + std::strerror(errno) + "\n");
|
||||
}
|
||||
const ESM::Format format = ESM::readFormat(*stream);
|
||||
stream->seekg(0);
|
||||
|
||||
|
@ -64,13 +60,14 @@ namespace MWWorld
|
|||
}
|
||||
case ESM::Format::Tes4:
|
||||
{
|
||||
if (mEncoder)
|
||||
if (mEncoder != nullptr)
|
||||
{
|
||||
ESM4::Reader readerESM4(std::move(stream), filepath);
|
||||
auto statelessEncoder = mEncoder->getStatelessEncoder();
|
||||
readerESM4.setEncoder(&statelessEncoder);
|
||||
mStore.loadESM4(readerESM4, listener, mDialogue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ namespace MWWorld
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
static void typedReadRecordESM4(ESM4::Reader& reader, ESMStore& stores, Store<T>& store, int& found)
|
||||
static bool typedReadRecordESM4(ESM4::Reader& reader, Store<T>& store)
|
||||
{
|
||||
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
|
||||
|
||||
|
@ -212,20 +212,17 @@ namespace MWWorld
|
|||
T value;
|
||||
value.load(reader);
|
||||
store.insertStatic(value);
|
||||
found++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool readRecord(ESM4::Reader& reader, ESMStore& store)
|
||||
{
|
||||
int found = 0;
|
||||
std::apply([&reader, &store, &found](
|
||||
auto&... x) { (ESMStoreImp::typedReadRecordESM4(reader, store, x, found), ...); },
|
||||
return std::apply([&reader](auto&... x) { return (ESMStoreImp::typedReadRecordESM4(reader, x) || ...); },
|
||||
store.mStoreImp->mStores);
|
||||
assert(found <= 1);
|
||||
return found;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -164,8 +164,9 @@ namespace MWWorld
|
|||
std::stringstream msg;
|
||||
if constexpr (!ESM::isESM4Rec(T::sRecordId))
|
||||
{
|
||||
msg << T::getRecordType() << " '" << id << "' not found";
|
||||
msg << T::getRecordType();
|
||||
}
|
||||
msg << " '" << id << "' not found";
|
||||
throw std::runtime_error(msg.str());
|
||||
}
|
||||
return ptr;
|
||||
|
@ -298,13 +299,12 @@ namespace MWWorld
|
|||
{
|
||||
for (typename Dynamic::const_iterator iter(mDynamic.begin()); iter != mDynamic.end(); ++iter)
|
||||
{
|
||||
writer.startRecord(T::sRecordId);
|
||||
if constexpr (!ESM::isESM4Rec(T::sRecordId))
|
||||
{
|
||||
writer.startRecord(T::sRecordId);
|
||||
iter->second.save(writer);
|
||||
writer.endRecord(T::sRecordId);
|
||||
}
|
||||
|
||||
writer.endRecord(T::sRecordId);
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
#include <stdexcept>
|
||||
|
||||
#include "reader.hpp"
|
||||
// #include "writer.hpp"
|
||||
|
||||
#include <components/esm/refid.hpp>
|
||||
// #include "writer.hpp"
|
||||
|
||||
// TODO: Try loading only EDID and XCLC (along with mFormId, mFlags and mParent)
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue