From 5d54ca6fdbdd2b87412c5499ef10bc5ca2dd03cc Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sun, 30 Jul 2023 21:55:36 +0200 Subject: [PATCH] Refactor components/esm4 --- apps/esmtool/tes4.cpp | 9 +-- apps/openmw/mwlua/luabindings.cpp | 2 +- apps/openmw/mwlua/types/door.cpp | 9 +-- apps/openmw/mwworld/cell.cpp | 2 +- apps/openmw/mwworld/cellref.hpp | 8 +-- apps/openmw/mwworld/store.cpp | 2 +- apps/openmw/mwworld/worldimp.cpp | 2 +- apps/openmw/mwworld/worldmodel.cpp | 2 +- apps/openmw/mwworld/worldmodel.hpp | 2 +- apps/openmw_test_suite/esm/testrefid.cpp | 10 ++-- apps/openmw_test_suite/esm4/includes.cpp | 1 - components/CMakeLists.txt | 1 - components/esm/formid.hpp | 8 +-- components/esm/refid.cpp | 2 +- components/esm/refid.hpp | 10 +++- components/esm4/actor.hpp | 4 +- components/esm4/cellgrid.hpp | 2 +- components/esm4/effect.hpp | 4 +- components/esm4/formid.cpp | 41 ------------- components/esm4/formid.hpp | 37 ------------ components/esm4/inventory.hpp | 6 +- components/esm4/loadachr.cpp | 11 +--- components/esm4/loadachr.hpp | 4 +- components/esm4/loadacti.cpp | 2 +- components/esm4/loadacti.hpp | 16 +++-- components/esm4/loadalch.cpp | 2 +- components/esm4/loadalch.hpp | 14 ++--- components/esm4/loadaloc.cpp | 47 +++------------ components/esm4/loadaloc.hpp | 20 ++++--- components/esm4/loadammo.cpp | 8 +-- components/esm4/loadammo.hpp | 20 +++---- components/esm4/loadanio.cpp | 3 +- components/esm4/loadanio.hpp | 8 ++- components/esm4/loadappa.cpp | 3 +- components/esm4/loadappa.hpp | 8 ++- components/esm4/loadarma.cpp | 9 +-- components/esm4/loadarma.hpp | 15 +++-- components/esm4/loadarmo.cpp | 9 +-- components/esm4/loadarmo.hpp | 16 +++-- components/esm4/loadaspc.cpp | 9 +-- components/esm4/loadaspc.hpp | 10 ++-- components/esm4/loadbook.cpp | 2 +- components/esm4/loadbook.hpp | 14 ++--- components/esm4/loadbptd.cpp | 3 +- components/esm4/loadbptd.hpp | 18 +++--- components/esm4/loadcell.cpp | 13 ++--- components/esm4/loadcell.hpp | 24 ++++---- components/esm4/loadclas.cpp | 3 +- components/esm4/loadclas.hpp | 6 +- components/esm4/loadclfm.cpp | 3 +- components/esm4/loadclfm.hpp | 6 +- components/esm4/loadclot.cpp | 2 +- components/esm4/loadclot.hpp | 10 ++-- components/esm4/loadcont.cpp | 2 +- components/esm4/loadcont.hpp | 11 ++-- components/esm4/loadcrea.cpp | 20 ++----- components/esm4/loadcrea.hpp | 22 +++---- components/esm4/loaddial.cpp | 15 +---- components/esm4/loaddial.hpp | 10 ++-- components/esm4/loaddobj.cpp | 3 +- components/esm4/loaddobj.hpp | 74 ++++++++++++------------ components/esm4/loaddoor.cpp | 2 +- components/esm4/loaddoor.hpp | 16 +++-- components/esm4/loadeyes.cpp | 3 +- components/esm4/loadeyes.hpp | 6 +- components/esm4/loadflor.cpp | 3 +- components/esm4/loadflor.hpp | 12 ++-- components/esm4/loadflst.cpp | 9 +-- components/esm4/loadflst.hpp | 8 ++- components/esm4/loadfurn.cpp | 2 +- components/esm4/loadfurn.hpp | 8 +-- components/esm4/loadglob.cpp | 3 +- components/esm4/loadglob.hpp | 6 +- components/esm4/loadgmst.cpp | 9 ++- components/esm4/loadgmst.hpp | 6 +- components/esm4/loadgras.cpp | 3 +- components/esm4/loadgras.hpp | 6 +- components/esm4/loadgrup.hpp | 27 +++++---- components/esm4/loadhair.cpp | 3 +- components/esm4/loadhair.hpp | 6 +- components/esm4/loadhdpt.cpp | 3 +- components/esm4/loadhdpt.hpp | 10 ++-- components/esm4/loadidle.cpp | 3 +- components/esm4/loadidle.hpp | 10 ++-- components/esm4/loadidlm.cpp | 5 +- components/esm4/loadidlm.hpp | 8 ++- components/esm4/loadimod.cpp | 3 +- components/esm4/loadimod.hpp | 6 +- components/esm4/loadinfo.cpp | 7 ++- components/esm4/loadinfo.hpp | 12 ++-- components/esm4/loadingr.cpp | 2 +- components/esm4/loadingr.hpp | 6 +- components/esm4/loadkeym.cpp | 3 +- components/esm4/loadkeym.hpp | 12 ++-- components/esm4/loadland.cpp | 18 ++---- components/esm4/loadland.hpp | 14 ++--- components/esm4/loadlgtm.cpp | 3 +- components/esm4/loadlgtm.hpp | 6 +- components/esm4/loadligh.cpp | 2 +- components/esm4/loadligh.hpp | 10 ++-- components/esm4/loadltex.cpp | 3 +- components/esm4/loadltex.hpp | 12 ++-- components/esm4/loadlvlc.cpp | 2 +- components/esm4/loadlvlc.hpp | 9 ++- components/esm4/loadlvli.cpp | 3 +- components/esm4/loadlvli.hpp | 7 ++- components/esm4/loadlvln.cpp | 2 +- components/esm4/loadlvln.hpp | 5 +- components/esm4/loadmato.cpp | 3 +- components/esm4/loadmato.hpp | 6 +- components/esm4/loadmisc.cpp | 2 +- components/esm4/loadmisc.hpp | 12 ++-- components/esm4/loadmset.cpp | 3 +- components/esm4/loadmset.hpp | 10 ++-- components/esm4/loadmstt.cpp | 3 +- components/esm4/loadmstt.hpp | 8 ++- components/esm4/loadmusc.cpp | 5 +- components/esm4/loadmusc.hpp | 6 +- components/esm4/loadnavi.cpp | 17 +++--- components/esm4/loadnavi.hpp | 18 +++--- components/esm4/loadnavm.cpp | 7 ++- components/esm4/loadnavm.hpp | 12 ++-- components/esm4/loadnote.cpp | 3 +- components/esm4/loadnote.hpp | 6 +- components/esm4/loadnpc.cpp | 22 ++----- components/esm4/loadnpc.hpp | 40 ++++++------- components/esm4/loadotft.cpp | 11 +--- components/esm4/loadotft.hpp | 8 ++- components/esm4/loadpack.cpp | 3 +- components/esm4/loadpack.hpp | 14 +++-- components/esm4/loadpgrd.cpp | 7 +-- components/esm4/loadpgrd.hpp | 8 ++- components/esm4/loadpgre.cpp | 3 +- components/esm4/loadpgre.hpp | 6 +- components/esm4/loadpwat.cpp | 3 +- components/esm4/loadpwat.hpp | 6 +- components/esm4/loadqust.cpp | 3 +- components/esm4/loadqust.hpp | 8 ++- components/esm4/loadrace.cpp | 22 +++---- components/esm4/loadrace.hpp | 26 ++++----- components/esm4/loadrefr.cpp | 16 ++--- components/esm4/loadrefr.hpp | 4 +- components/esm4/loadregn.cpp | 3 +- components/esm4/loadregn.hpp | 10 ++-- components/esm4/loadroad.cpp | 7 +-- components/esm4/loadroad.hpp | 8 ++- components/esm4/loadsbsp.cpp | 3 +- components/esm4/loadsbsp.hpp | 6 +- components/esm4/loadscol.cpp | 3 +- components/esm4/loadscol.hpp | 6 +- components/esm4/loadscpt.cpp | 3 +- components/esm4/loadscpt.hpp | 6 +- components/esm4/loadscrl.cpp | 3 +- components/esm4/loadscrl.hpp | 10 ++-- components/esm4/loadsgst.cpp | 3 +- components/esm4/loadsgst.hpp | 8 ++- components/esm4/loadslgm.cpp | 3 +- components/esm4/loadslgm.hpp | 8 ++- components/esm4/loadsndr.cpp | 3 +- components/esm4/loadsndr.hpp | 12 ++-- components/esm4/loadsoun.cpp | 3 +- components/esm4/loadsoun.hpp | 6 +- components/esm4/loadstat.cpp | 2 +- components/esm4/loadstat.hpp | 7 +-- components/esm4/loadtact.cpp | 3 +- components/esm4/loadtact.hpp | 14 +++-- components/esm4/loadterm.cpp | 3 +- components/esm4/loadterm.hpp | 12 ++-- components/esm4/loadtes4.cpp | 7 +-- components/esm4/loadtes4.hpp | 6 +- components/esm4/loadtree.cpp | 2 +- components/esm4/loadtree.hpp | 4 +- components/esm4/loadtxst.cpp | 3 +- components/esm4/loadtxst.hpp | 6 +- components/esm4/loadweap.cpp | 2 +- components/esm4/loadweap.hpp | 14 ++--- components/esm4/loadwrld.cpp | 6 +- components/esm4/loadwrld.hpp | 23 ++++---- components/esm4/reader.cpp | 15 +++-- components/esm4/reader.hpp | 32 +++++----- components/esm4/script.hpp | 9 +-- components/esm4/typetraits.hpp | 26 --------- 182 files changed, 721 insertions(+), 903 deletions(-) delete mode 100644 components/esm4/formid.cpp delete mode 100644 components/esm4/formid.hpp diff --git a/apps/esmtool/tes4.cpp b/apps/esmtool/tes4.cpp index e601d85d7d..0b1c07920f 100644 --- a/apps/esmtool/tes4.cpp +++ b/apps/esmtool/tes4.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -145,19 +146,15 @@ namespace EsmTool return; std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView(); - if constexpr (ESM4::hasFormId) - std::cout << "\n FormId: 0x" << ESM4::formIdToString(value.mFormId); if constexpr (ESM::hasId) { - if constexpr (std::is_same_v) - std::cout << "\n FormId: 0x" << ESM4::formIdToString(value.mId); + if constexpr (std::is_same_v) + std::cout << "\n " << ESM::RefId(value.mId); else std::cout << "\n Id: " << value.mId; } if constexpr (ESM4::hasFlags) std::cout << "\n Record flags: " << recordFlags(value.mFlags); - if constexpr (ESM4::hasParentFormId) - std::cout << "\n ParentFormId: 0x" << ESM4::formIdToString(value.mParentFormId); if constexpr (ESM4::hasParent) std::cout << "\n Parent: " << value.mParent; if constexpr (ESM4::hasEditorId) diff --git a/apps/openmw/mwlua/luabindings.cpp b/apps/openmw/mwlua/luabindings.cpp index efb64244e8..2a4368810c 100644 --- a/apps/openmw/mwlua/luabindings.cpp +++ b/apps/openmw/mwlua/luabindings.cpp @@ -127,7 +127,7 @@ namespace MWLua const std::vector& contentList = MWBase::Environment::get().getWorld()->getContentFiles(); for (size_t i = 0; i < contentList.size(); ++i) if (Misc::StringUtils::ciEqual(contentList[i], contentFile)) - return ESM::RefId(ESM::FormIdRefId(ESM::FormId{ index, int(i) })).serializeText(); + return ESM::RefId(ESM::FormId{ index, int(i) }).serializeText(); throw std::runtime_error("Content file not found: " + std::string(contentFile)); }; addTimeBindings(api, context, false); diff --git a/apps/openmw/mwlua/types/door.cpp b/apps/openmw/mwlua/types/door.cpp index 3f1e77f629..5a2cfc8aee 100644 --- a/apps/openmw/mwlua/types/door.cpp +++ b/apps/openmw/mwlua/types/door.cpp @@ -100,10 +100,11 @@ namespace MWLua addRecordFunctionBinding(door, context, "ESM4Door"); sol::usertype record = context.mLua->sol().new_usertype("ESM4_Door"); - record[sol::meta_function::to_string] - = [](const ESM4::Door& rec) -> std::string { return "ESM4_Door[" + rec.mId.toDebugString() + "]"; }; - record["id"] - = sol::readonly_property([](const ESM4::Door& rec) -> std::string { return rec.mId.serializeText(); }); + record[sol::meta_function::to_string] = [](const ESM4::Door& rec) -> std::string { + return "ESM4_Door[" + ESM::RefId(rec.mId).toDebugString() + "]"; + }; + record["id"] = sol::readonly_property( + [](const ESM4::Door& rec) -> std::string { return ESM::RefId(rec.mId).serializeText(); }); record["name"] = sol::readonly_property([](const ESM4::Door& rec) -> std::string { return rec.mFullName; }); record["model"] = sol::readonly_property([vfs](const ESM4::Door& rec) -> std::string { return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs); diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 3ea6766b90..7b535cacc7 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -21,7 +21,7 @@ namespace MWWorld if (!value.mEditorId.empty()) return value.mEditorId; - return value.mId.serializeText(); + return ESM::RefId(value.mId).serializeText(); } std::string getCellDescription(const ESM4::Cell& cell, const ESM4::World* world) diff --git a/apps/openmw/mwworld/cellref.hpp b/apps/openmw/mwworld/cellref.hpp index 98648f9467..73e721278e 100644 --- a/apps/openmw/mwworld/cellref.hpp +++ b/apps/openmw/mwworld/cellref.hpp @@ -125,13 +125,7 @@ namespace MWWorld // The NPC that owns this object (and will get angry if you steal it) ESM::RefId getOwner() const { - struct Visitor - { - ESM::RefId operator()(const ESM::CellRef& ref) { return ref.mOwner; } - ESM::RefId operator()(const ESM4::Reference& ref) { return ESM::RefId::formIdRefId(ref.mOwner); } - ESM::RefId operator()(const ESM4::ActorCharacter& ref) { return ESM::RefId::formIdRefId(ref.mOwner); } - }; - return std::visit(Visitor(), mCellRef.mVariant); + return std::visit([](auto&& ref) -> ESM::RefId { return ref.mOwner; }, mCellRef.mVariant); } void setOwner(const ESM::RefId& owner); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index ed105b56d9..8fd2aa81e9 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -172,7 +172,7 @@ namespace MWWorld if (!mShared.empty()) return mShared[Misc::Rng::rollDice(mShared.size(), prng)]; } - else + else if constexpr (!std::is_same_v) { std::vector results; std::copy_if(mShared.begin(), mShared.end(), std::back_inserter(results), diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index a09d5d4174..d196bb141b 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -711,7 +711,7 @@ namespace MWWorld if (!activeOnly) { - ret = mWorldModel.getPtr(name); + ret = mWorldModel.getPtrByRefId(name); if (!ret.isEmpty()) return ret; } diff --git a/apps/openmw/mwworld/worldmodel.cpp b/apps/openmw/mwworld/worldmodel.cpp index 10073152d0..4b72f6f238 100644 --- a/apps/openmw/mwworld/worldmodel.cpp +++ b/apps/openmw/mwworld/worldmodel.cpp @@ -342,7 +342,7 @@ namespace MWWorld } } -MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name) +MWWorld::Ptr MWWorld::WorldModel::getPtrByRefId(const ESM::RefId& name) { for (const auto& [cachedId, cellStore] : mIdCache) { diff --git a/apps/openmw/mwworld/worldmodel.hpp b/apps/openmw/mwworld/worldmodel.hpp index 965d6a21f4..85c0700578 100644 --- a/apps/openmw/mwworld/worldmodel.hpp +++ b/apps/openmw/mwworld/worldmodel.hpp @@ -65,7 +65,7 @@ namespace MWWorld CellStore& getCell(std::string_view name, bool forceLoad = true) const; - Ptr getPtr(const ESM::RefId& name); + Ptr getPtrByRefId(const ESM::RefId& name); Ptr getPtr(ESM::RefNum refNum) const { return mPtrRegistry.getOrEmpty(refNum); } diff --git a/apps/openmw_test_suite/esm/testrefid.cpp b/apps/openmw_test_suite/esm/testrefid.cpp index 6db0ef3907..4e9d297bc4 100644 --- a/apps/openmw_test_suite/esm/testrefid.cpp +++ b/apps/openmw_test_suite/esm/testrefid.cpp @@ -208,11 +208,12 @@ namespace ESM EXPECT_EQ(map.count(RefId::stringRefId("A")), 1); } - TEST(ESMRefIdTest, stringRefIdIsNotEqualToFormId) + TEST(ESMRefIdTest, emptyRefId) { - const RefId stringRefId = RefId::stringRefId("\0"); - const RefId formIdRefId = RefId::formIdRefId({ .mIndex = 0, .mContentFile = 0 }); - EXPECT_NE(stringRefId, formIdRefId); + EXPECT_EQ(RefId(), EmptyRefId()); + EXPECT_EQ(RefId(), RefId::stringRefId("\0")); + EXPECT_EQ(RefId(), RefId::formIdRefId({ .mIndex = 0, .mContentFile = 0 })); + EXPECT_EQ(RefId(), RefId::formIdRefId({ .mIndex = 0, .mContentFile = -1 })); } TEST(ESMRefIdTest, indexRefIdHashDiffersForDistinctValues) @@ -337,7 +338,6 @@ namespace ESM { RefId::stringRefId("foo"), "foo" }, { RefId::stringRefId("BAR"), "bar" }, { RefId::stringRefId(std::string({ 'a', 0, -1, '\n', '\t' })), { 'a', 0, -1, '\n', '\t' } }, - { RefId::formIdRefId({ .mIndex = 0, .mContentFile = 0 }), "FormId:0x0" }, { RefId::formIdRefId({ .mIndex = 1, .mContentFile = 0 }), "FormId:0x1" }, { RefId::formIdRefId({ .mIndex = 0x1f, .mContentFile = 0 }), "FormId:0x1f" }, { RefId::formIdRefId({ .mIndex = 0x1f, .mContentFile = 2 }), "FormId:0x200001f" }, diff --git a/apps/openmw_test_suite/esm4/includes.cpp b/apps/openmw_test_suite/esm4/includes.cpp index 049d6605d2..f2ea31241e 100644 --- a/apps/openmw_test_suite/esm4/includes.cpp +++ b/apps/openmw_test_suite/esm4/includes.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 70f0daaf17..b085eb52d7 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -155,7 +155,6 @@ add_component_dir (esm4 common dialogue effect - formid grid grouptype inventory diff --git a/components/esm/formid.hpp b/components/esm/formid.hpp index 9ddee5aca0..78fb948e5e 100644 --- a/components/esm/formid.hpp +++ b/components/esm/formid.hpp @@ -15,15 +15,15 @@ namespace ESM uint32_t mIndex = 0; int32_t mContentFile = -1; - bool hasContentFile() const { return mContentFile >= 0; } - bool isSet() const { return mIndex != 0 || mContentFile != -1; } + constexpr bool hasContentFile() const { return mContentFile >= 0; } + constexpr bool isSet() const { return mIndex != 0 || mContentFile != -1; } // Zero is used in ESM4 as a null reference - bool isZeroOrUnset() const { return mIndex == 0 && (mContentFile == 0 || mContentFile == -1); } + constexpr bool isZeroOrUnset() const { return mIndex == 0 && (mContentFile == 0 || mContentFile == -1); } std::string toString() const; FormId32 toUint32() const; - static FormId fromUint32(FormId32 v) { return { v & 0xffffff, static_cast(v >> 24) }; } + static constexpr FormId fromUint32(FormId32 v) { return { v & 0xffffff, static_cast(v >> 24) }; } }; inline constexpr bool operator==(const FormId& left, const FormId& right) diff --git a/components/esm/refid.cpp b/components/esm/refid.cpp index 8fdcc043f1..03d7cb06eb 100644 --- a/components/esm/refid.cpp +++ b/components/esm/refid.cpp @@ -227,7 +227,7 @@ namespace ESM uint64_t v = deserializeHexIntegral(formIdRefIdPrefix.size(), value); uint32_t index = static_cast(v) & 0xffffff; int contentFile = static_cast(v >> 24); - return ESM::RefId::formIdRefId({ index, contentFile }); + return ESM::FormId{ index, contentFile }; } if (value.starts_with(generatedRefIdPrefix)) diff --git a/components/esm/refid.hpp b/components/esm/refid.hpp index ed665d450d..ccc0417633 100644 --- a/components/esm/refid.hpp +++ b/components/esm/refid.hpp @@ -61,7 +61,7 @@ namespace ESM static RefId stringRefId(std::string_view value); // Constructs RefId from FormId storing the value in-place. - static RefId formIdRefId(FormId value) { return RefId(FormIdRefId(value)); } + static RefId formIdRefId(FormId value) { return RefId(value); } // Constructs RefId from uint64 storing the value in-place. Should be used for generated records where id is a // global counter. @@ -90,6 +90,14 @@ namespace ESM { } + constexpr RefId(FormId value) + { + if (value.isZeroOrUnset()) + mValue = EmptyRefId(); + else + mValue = FormIdRefId(value); + } + constexpr RefId(GeneratedRefId value) noexcept : mValue(value) { diff --git a/components/esm4/actor.hpp b/components/esm4/actor.hpp index e8a946f134..9a408ca33d 100644 --- a/components/esm4/actor.hpp +++ b/components/esm4/actor.hpp @@ -29,7 +29,7 @@ #include -#include "formid.hpp" +#include namespace ESM4 { @@ -109,7 +109,7 @@ namespace ESM4 struct ActorFaction { - FormId32 faction; + ESM::FormId32 faction; std::int8_t rank; std::uint8_t unknown1; std::uint8_t unknown2; diff --git a/components/esm4/cellgrid.hpp b/components/esm4/cellgrid.hpp index 7f1a2e8452..13ace783c9 100644 --- a/components/esm4/cellgrid.hpp +++ b/components/esm4/cellgrid.hpp @@ -29,8 +29,8 @@ #include -#include "formid.hpp" #include "grid.hpp" +#include namespace ESM4 { diff --git a/components/esm4/effect.hpp b/components/esm4/effect.hpp index f49a6749b4..bcf41f44cc 100644 --- a/components/esm4/effect.hpp +++ b/components/esm4/effect.hpp @@ -29,7 +29,7 @@ #include -#include "formid.hpp" +#include namespace ESM4 { @@ -42,7 +42,7 @@ namespace ESM4 struct ScriptEffect { - FormId32 formId; // Script effect (Magic effect must be SEFF) + ESM::FormId32 formId; // Script effect (Magic effect must be SEFF) std::int32_t school; // Magic school. See Magic schools for more information. EFI_Label visualEffect; // Visual effect name or 0x00000000 if None std::uint8_t flags; // 0x01 = Hostile diff --git a/components/esm4/formid.cpp b/components/esm4/formid.cpp deleted file mode 100644 index d091bdf8be..0000000000 --- a/components/esm4/formid.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright (C) 2016, 2020-2021 cc9cii - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - cc9cii cc9c@iinet.net.au - -*/ -#include "formid.hpp" - -#include -#include - -namespace ESM4 -{ - std::string formIdToString(const FormId& formId) - { - std::string str; - char buf[8 + 1]; - int res = snprintf(buf, 8 + 1, "%08X", formId.toUint32()); - if (res > 0 && res < 8 + 1) - str.assign(buf); - else - throw std::runtime_error("Possible buffer overflow while converting formId"); - return str; - } -} diff --git a/components/esm4/formid.hpp b/components/esm4/formid.hpp deleted file mode 100644 index 284da67ad7..0000000000 --- a/components/esm4/formid.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (C) 2016 cc9cii - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - cc9cii cc9c@iinet.net.au - -*/ -#ifndef ESM4_FORMID_H -#define ESM4_FORMID_H - -#include - -#include - -namespace ESM4 -{ - using FormId = ESM::FormId; - using FormId32 = uint32_t; - std::string formIdToString(const FormId& formId); -} - -#endif // ESM4_FORMID_H diff --git a/components/esm4/inventory.hpp b/components/esm4/inventory.hpp index eb49c5ef06..52c67dccb9 100644 --- a/components/esm4/inventory.hpp +++ b/components/esm4/inventory.hpp @@ -29,7 +29,7 @@ #include -#include "formid.hpp" +#include namespace ESM4 { @@ -39,14 +39,14 @@ namespace ESM4 { std::int16_t level; std::uint16_t unknown; // sometimes missing - FormId32 item; + ESM::FormId32 item; std::int16_t count; std::uint16_t unknown2; // sometimes missing }; struct InventoryItem // NPC_, CREA, CONT { - FormId32 item; + ESM::FormId32 item; std::uint32_t count; }; #pragma pack(pop) diff --git a/components/esm4/loadachr.cpp b/components/esm4/loadachr.cpp index 9560fc970d..537bb026ac 100644 --- a/components/esm4/loadachr.cpp +++ b/components/esm4/loadachr.cpp @@ -33,10 +33,9 @@ void ESM4::ActorCharacter::load(ESM4::Reader& reader) { - mId = reader.hdr().record.getFormId(); - reader.adjustFormId(mId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; - mParent = ESM::RefId::formIdRefId(reader.currCell()); + mParent = reader.currCell(); while (reader.getSubRecordHeader()) { @@ -50,12 +49,8 @@ void ESM4::ActorCharacter::load(ESM4::Reader& reader) reader.getZString(mFullName); break; case ESM4::SUB_NAME: - { - FormId baseId; - reader.getFormId(baseId); - mBaseObj = ESM::RefId::formIdRefId(baseId); + reader.getFormId(mBaseObj); break; - } case ESM4::SUB_DATA: reader.get(mPos); break; diff --git a/components/esm4/loadachr.hpp b/components/esm4/loadachr.hpp index 2d07c5a059..dd867bbafd 100644 --- a/components/esm4/loadachr.hpp +++ b/components/esm4/loadachr.hpp @@ -32,7 +32,7 @@ #include #include -#include "reference.hpp" // FormId, Placement, EnableParent +#include "reference.hpp" // Placement, EnableParent namespace ESM4 { @@ -48,7 +48,7 @@ namespace ESM4 std::string mEditorId; std::string mFullName; - ESM::RefId mBaseObj; + ESM::FormId mBaseObj; ESM::Position mPos; float mScale = 1.0f; diff --git a/components/esm4/loadacti.cpp b/components/esm4/loadacti.cpp index 3be8dfbe7e..54af0732e1 100644 --- a/components/esm4/loadacti.cpp +++ b/components/esm4/loadacti.cpp @@ -33,7 +33,7 @@ void ESM4::Activator::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadacti.hpp b/components/esm4/loadacti.hpp index c6d4090512..976af58e51 100644 --- a/components/esm4/loadacti.hpp +++ b/components/esm4/loadacti.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -42,21 +40,21 @@ namespace ESM4 struct Activator { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mFullName; std::string mModel; - FormId mScriptId; - FormId mLoopingSound; // SOUN - FormId mActivationSound; // SOUN + ESM::FormId mScriptId; + ESM::FormId mLoopingSound; // SOUN + ESM::FormId mActivationSound; // SOUN float mBoundRadius; - FormId mRadioTemplate; // SOUN - FormId mRadioStation; // TACT + ESM::FormId mRadioTemplate; // SOUN + ESM::FormId mRadioStation; // TACT std::string mActivationPrompt; diff --git a/components/esm4/loadalch.cpp b/components/esm4/loadalch.cpp index 0103b85598..35f6964b24 100644 --- a/components/esm4/loadalch.cpp +++ b/components/esm4/loadalch.cpp @@ -34,7 +34,7 @@ void ESM4::Potion::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadalch.hpp b/components/esm4/loadalch.hpp index 2644811a0e..de79e19c54 100644 --- a/components/esm4/loadalch.hpp +++ b/components/esm4/loadalch.hpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include "effect.hpp" // FormId, ScriptEffect @@ -52,13 +52,13 @@ namespace ESM4 { std::int32_t value; std::uint32_t flags; - FormId32 withdrawl; + ESM::FormId32 withdrawl; float chanceAddition; - FormId32 sound; + ESM::FormId32 sound; }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -67,10 +67,10 @@ namespace ESM4 std::string mIcon; // inventory std::string mMiniIcon; // inventory - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; - FormId mScriptId; + ESM::FormId mScriptId; ScriptEffect mEffect; float mBoundRadius; diff --git a/components/esm4/loadaloc.cpp b/components/esm4/loadaloc.cpp index 6414426c5a..690684df7c 100644 --- a/components/esm4/loadaloc.cpp +++ b/components/esm4/loadaloc.cpp @@ -29,15 +29,12 @@ #include #include -//#include "formid.hpp" // FIXME: - #include "reader.hpp" //#include "writer.hpp" void ESM4::MediaLocationController::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -52,53 +49,23 @@ void ESM4::MediaLocationController::load(ESM4::Reader& reader) reader.getZString(mFullName); break; case ESM4::SUB_GNAM: - { - FormId id; - reader.getFormId(id); - mBattleSets.push_back(id); - + reader.getFormId(mBattleSets.emplace_back()); break; - } case ESM4::SUB_LNAM: - { - FormId id; - reader.getFormId(id); - mLocationSets.push_back(id); - + reader.getFormId(mLocationSets.emplace_back()); break; - } case ESM4::SUB_YNAM: - { - FormId id; - reader.getFormId(id); - mEnemySets.push_back(id); - + reader.getFormId(mEnemySets.emplace_back()); break; - } case ESM4::SUB_HNAM: - { - FormId id; - reader.getFormId(id); - mNeutralSets.push_back(id); - + reader.getFormId(mNeutralSets.emplace_back()); break; - } case ESM4::SUB_XNAM: - { - FormId id; - reader.getFormId(id); - mFriendSets.push_back(id); - + reader.getFormId(mFriendSets.emplace_back()); break; - } case ESM4::SUB_ZNAM: - { - FormId id; - reader.getFormId(id); - mAllySets.push_back(id); - + reader.getFormId(mAllySets.emplace_back()); break; - } case ESM4::SUB_RNAM: reader.getFormId(mConditionalFaction); break; diff --git a/components/esm4/loadaloc.hpp b/components/esm4/loadaloc.hpp index 8773091eb9..78e5b46f73 100644 --- a/components/esm4/loadaloc.hpp +++ b/components/esm4/loadaloc.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -52,22 +53,22 @@ namespace ESM4 struct MediaLocationController { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mFullName; - std::vector mBattleSets; - std::vector mLocationSets; - std::vector mEnemySets; - std::vector mNeutralSets; - std::vector mFriendSets; - std::vector mAllySets; + std::vector mBattleSets; + std::vector mLocationSets; + std::vector mEnemySets; + std::vector mNeutralSets; + std::vector mFriendSets; + std::vector mAllySets; MLC_Flags mMediaFlags; - FormId mConditionalFaction; + ESM::FormId mConditionalFaction; float mLocationDelay; float mRetriggerDelay; @@ -79,6 +80,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ALOC4; }; } diff --git a/components/esm4/loadammo.cpp b/components/esm4/loadammo.cpp index 6bc3deb0c4..8dab2ba74c 100644 --- a/components/esm4/loadammo.cpp +++ b/components/esm4/loadammo.cpp @@ -33,7 +33,7 @@ void ESM4::Ammunition::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -128,12 +128,8 @@ void ESM4::Ammunition::load(ESM4::Reader& reader) reader.getLocalizedString(mAbbrev); break; case ESM4::SUB_RCIL: - { - FormId effect; - reader.getFormId(effect); - mAmmoEffects.push_back(effect); + reader.getFormId(mAmmoEffects.emplace_back()); break; - } case ESM4::SUB_SCRI: reader.getFormId(mScript); break; diff --git a/components/esm4/loadammo.hpp b/components/esm4/loadammo.hpp index 13592f4ff1..efeca3c156 100644 --- a/components/esm4/loadammo.hpp +++ b/components/esm4/loadammo.hpp @@ -32,9 +32,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -52,12 +50,12 @@ namespace ESM4 float mDamage{ 0.f }; std::uint8_t mClipRounds{ 0u }; std::uint32_t mProjPerShot{ 0u }; - FormId mProjectile; - FormId mConsumedAmmo; + ESM::FormId mProjectile; + ESM::FormId mConsumedAmmo; float mConsumedPercentage{ 0.f }; }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -69,17 +67,17 @@ namespace ESM4 std::string mIcon; // inventory std::string mMiniIcon; // inventory - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; float mBoundRadius; std::uint16_t mEnchantmentPoints; - FormId mEnchantment; + ESM::FormId mEnchantment; - std::vector mAmmoEffects; + std::vector mAmmoEffects; - FormId mScript; + ESM::FormId mScript; Data mData; diff --git a/components/esm4/loadanio.cpp b/components/esm4/loadanio.cpp index 23af184771..768e4d7822 100644 --- a/components/esm4/loadanio.cpp +++ b/components/esm4/loadanio.cpp @@ -33,8 +33,7 @@ void ESM4::AnimObject::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadanio.hpp b/components/esm4/loadanio.hpp index 4d27ed7a5c..c08e8662c0 100644 --- a/components/esm4/loadanio.hpp +++ b/components/esm4/loadanio.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct AnimObject { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -47,13 +48,14 @@ namespace ESM4 float mBoundRadius; - FormId mIdleAnim; // only in TES4 + ESM::FormId mIdleAnim; // only in TES4 std::string mUnloadEvent; // only in TES5 void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ANIO4; }; } diff --git a/components/esm4/loadappa.cpp b/components/esm4/loadappa.cpp index 4327d20964..45e12739b9 100644 --- a/components/esm4/loadappa.cpp +++ b/components/esm4/loadappa.cpp @@ -33,8 +33,7 @@ void ESM4::Apparatus::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadappa.hpp b/components/esm4/loadappa.hpp index ef4952b68e..e24e79e2d0 100644 --- a/components/esm4/loadappa.hpp +++ b/components/esm4/loadappa.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -47,7 +48,7 @@ namespace ESM4 float quality; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -58,7 +59,7 @@ namespace ESM4 float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; Data mData; @@ -66,6 +67,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_APPA4; }; } diff --git a/components/esm4/loadarma.cpp b/components/esm4/loadarma.cpp index 1c7b1429bf..8fa3dc8fc3 100644 --- a/components/esm4/loadarma.cpp +++ b/components/esm4/loadarma.cpp @@ -33,8 +33,7 @@ void ESM4::ArmorAddon::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); @@ -71,11 +70,7 @@ void ESM4::ArmorAddon::load(ESM4::Reader& reader) break; case ESM4::SUB_MODL: if ((esmVer == ESM::VER_094 || esmVer == ESM::VER_170) && subHdr.dataSize == 4) // TES5 - { - FormId formId; - reader.getFormId(formId); - mRaces.push_back(formId); - } + reader.getFormId(mRaces.emplace_back()); else reader.skipSubRecordData(); // FIXME: this should be mModelMale for FO3/FONV diff --git a/components/esm4/loadarma.hpp b/components/esm4/loadarma.hpp index d72aef0b13..24fa8b1093 100644 --- a/components/esm4/loadarma.hpp +++ b/components/esm4/loadarma.hpp @@ -31,8 +31,10 @@ #include #include +#include +#include + #include "actor.hpp" // BodyTemplate -#include "formid.hpp" namespace ESM4 { @@ -41,7 +43,7 @@ namespace ESM4 struct ArmorAddon { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -49,11 +51,11 @@ namespace ESM4 std::string mModelMale; std::string mModelFemale; - FormId mTextureMale; - FormId mTextureFemale; + ESM::FormId mTextureMale; + ESM::FormId mTextureFemale; - FormId mRacePrimary; - std::vector mRaces; // TES5 only + ESM::FormId mRacePrimary; + std::vector mRaces; // TES5 only BodyTemplate mBodyTemplate; // TES5 @@ -61,6 +63,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ARMA4; }; } diff --git a/components/esm4/loadarmo.cpp b/components/esm4/loadarmo.cpp index 24602a40a3..b2b90f2eb1 100644 --- a/components/esm4/loadarmo.cpp +++ b/components/esm4/loadarmo.cpp @@ -33,7 +33,7 @@ void ESM4::Armor::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); mIsFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; @@ -76,12 +76,7 @@ void ESM4::Armor::load(ESM4::Reader& reader) { // if (esmVer == ESM::VER_094 || esmVer == ESM::VER_170 || isFONV) if (subHdr.dataSize == 4) // FO3 has zstring even though VER_094 - { - FormId formId; - reader.getFormId(formId); - - mAddOns.push_back(formId); - } + reader.getFormId(mAddOns.emplace_back()); else { if (!reader.getZString(mModelMale)) diff --git a/components/esm4/loadarmo.hpp b/components/esm4/loadarmo.hpp index 29b5a75800..43832db00a 100644 --- a/components/esm4/loadarmo.hpp +++ b/components/esm4/loadarmo.hpp @@ -32,9 +32,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -151,7 +149,7 @@ namespace ESM4 }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details bool mIsTES4; // TODO: check that these match the general flags @@ -170,8 +168,8 @@ namespace ESM4 std::string mIconFemale; std::string mMiniIconFemale; - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; std::string mModel; // FIXME: for OpenCS @@ -179,11 +177,11 @@ namespace ESM4 std::uint32_t mArmorFlags; std::uint32_t mGeneralFlags; - FormId mScriptId; + ESM::FormId mScriptId; std::uint16_t mEnchantmentPoints; - FormId mEnchantment; + ESM::FormId mEnchantment; - std::vector mAddOns; // TES5 ARMA + std::vector mAddOns; // TES5 ARMA Data mData; void load(ESM4::Reader& reader); diff --git a/components/esm4/loadaspc.cpp b/components/esm4/loadaspc.cpp index 9c9303d883..0cb3590404 100644 --- a/components/esm4/loadaspc.cpp +++ b/components/esm4/loadaspc.cpp @@ -33,8 +33,7 @@ void ESM4::AcousticSpace::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -49,12 +48,8 @@ void ESM4::AcousticSpace::load(ESM4::Reader& reader) reader.get(mEnvironmentType); break; case ESM4::SUB_SNAM: - { - FormId id; - reader.getFormId(id); - mAmbientLoopSounds.push_back(id); + reader.getFormId(mAmbientLoopSounds.emplace_back()); break; - } case ESM4::SUB_RDAT: reader.getFormId(mSoundRegion); break; diff --git a/components/esm4/loadaspc.hpp b/components/esm4/loadaspc.hpp index 6979f59708..25a938e3da 100644 --- a/components/esm4/loadaspc.hpp +++ b/components/esm4/loadaspc.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,7 +41,7 @@ namespace ESM4 struct AcousticSpace { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -48,8 +49,8 @@ namespace ESM4 std::uint32_t mEnvironmentType; // 0 Dawn (5:00 start), 1 Afternoon (8:00), 2 Dusk (18:00), 3 Night (20:00) - std::vector mAmbientLoopSounds; - FormId mSoundRegion; + std::vector mAmbientLoopSounds; + ESM::FormId mSoundRegion; std::uint32_t mIsInterior; // if true only use mAmbientLoopSounds[0] @@ -57,6 +58,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ASPC4; }; } diff --git a/components/esm4/loadbook.cpp b/components/esm4/loadbook.cpp index 99c39ba998..df8697a608 100644 --- a/components/esm4/loadbook.cpp +++ b/components/esm4/loadbook.cpp @@ -33,7 +33,7 @@ void ESM4::Book::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; // std::uint32_t esmVer = reader.esmVersion(); // currently unused diff --git a/components/esm4/loadbook.hpp b/components/esm4/loadbook.hpp index 0281425701..2b2ccaaf08 100644 --- a/components/esm4/loadbook.hpp +++ b/components/esm4/loadbook.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -84,7 +82,7 @@ namespace ESM4 float weight; }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -94,15 +92,15 @@ namespace ESM4 float mBoundRadius; std::string mText; - FormId mScriptId; + ESM::FormId mScriptId; std::string mIcon; std::uint16_t mEnchantmentPoints; - FormId mEnchantment; + ESM::FormId mEnchantment; Data mData; - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; diff --git a/components/esm4/loadbptd.cpp b/components/esm4/loadbptd.cpp index faa1d1937f..a9edc2b145 100644 --- a/components/esm4/loadbptd.cpp +++ b/components/esm4/loadbptd.cpp @@ -45,8 +45,7 @@ void ESM4::BodyPartData::BodyPart::clear() void ESM4::BodyPartData::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; BodyPart bodyPart; diff --git a/components/esm4/loadbptd.hpp b/components/esm4/loadbptd.hpp index afb165fb48..b6884a3481 100644 --- a/components/esm4/loadbptd.hpp +++ b/components/esm4/loadbptd.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -68,14 +69,14 @@ namespace ESM4 std::uint8_t explExplosionChance; // % std::uint16_t explDebrisCount; - FormId32 explDebris; - FormId32 explExplosion; + ESM::FormId32 explDebris; + ESM::FormId32 explExplosion; float trackingMaxAngle; float explDebrisScale; std::int32_t sevDebrisCount; - FormId32 sevDebris; - FormId32 sevExplosion; + ESM::FormId32 sevDebris; + ESM::FormId32 sevExplosion; float sevDebrisScale; // Struct - Gore Effects Positioning @@ -86,8 +87,8 @@ namespace ESM4 float rotY; float rotZ; - FormId32 sevImpactDataSet; - FormId32 explImpactDataSet; + ESM::FormId32 sevImpactDataSet; + ESM::FormId32 explImpactDataSet; uint8_t sevDecalCount; uint8_t explDecalCount; uint16_t Unknown; @@ -108,7 +109,7 @@ namespace ESM4 void clear(); }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -121,6 +122,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_BPTD4; }; } diff --git a/components/esm4/loadcell.cpp b/components/esm4/loadcell.cpp index 00954f4d9d..0c320967d8 100644 --- a/components/esm4/loadcell.cpp +++ b/components/esm4/loadcell.cpp @@ -47,11 +47,10 @@ float ESM4::Cell::sInvalidWaterLevel = -200000.f; // longer/shorter/same as loading the subrecords. void ESM4::Cell::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); - mId = ESM::RefId::formIdRefId(mFormId); + ESM::FormId formId = reader.getFormIdFromHeader(); + mId = formId; mFlags = reader.hdr().record.flags; - mParent = ESM::RefId::formIdRefId(reader.currWorld()); + mParent = reader.currWorld(); mWaterHeight = sInvalidWaterLevel; reader.clearCellGrid(); // clear until XCLC FIXME: somehow do this automatically? @@ -70,7 +69,7 @@ void ESM4::Cell::load(ESM4::Reader& reader) // WARN: we need to call setCurrCell (and maybe setCurrCellGrid?) again before loading // cell child groups if we are loading them after restoring the context // (may be easier to update the context before saving?) - reader.setCurrCell(mFormId); // save for LAND (and other children) to access later + reader.setCurrCell(formId); // save for LAND (and other children) to access later std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; bool isSkyrim = (esmVer == ESM::VER_170 || esmVer == ESM::VER_094); @@ -155,8 +154,8 @@ void ESM4::Cell::load(ESM4::Reader& reader) } case ESM4::SUB_XCLR: // for exterior cells { - mRegions.resize(subHdr.dataSize / sizeof(FormId32)); - for (std::vector::iterator it = mRegions.begin(); it != mRegions.end(); ++it) + mRegions.resize(subHdr.dataSize / sizeof(ESM::FormId32)); + for (std::vector::iterator it = mRegions.begin(); it != mRegions.end(); ++it) { reader.getFormId(*it); #if 0 diff --git a/components/esm4/loadcell.hpp b/components/esm4/loadcell.hpp index 6bb04daff4..c2fb506975 100644 --- a/components/esm4/loadcell.hpp +++ b/components/esm4/loadcell.hpp @@ -31,14 +31,13 @@ #include #include -#include "formid.hpp" -#include "lighting.hpp" - #include #include #include #include +#include "lighting.hpp" + namespace ESM4 { class Reader; @@ -63,8 +62,7 @@ namespace ESM4 // The cells need to be organised under world spaces. struct Cell { - FormId mFormId; // from the header - ESM::RefId mId; + ESM::RefId mId; // from the header std::uint32_t mFlags = 0; // from the header, see enum type RecordFlag for details ESM::RefId mParent; // world formId (for grouping cells), from the loading sequence @@ -76,20 +74,20 @@ namespace ESM4 std::int32_t mX = 0; std::int32_t mY = 0; - FormId mOwner; - FormId mGlobal; - FormId mClimate; - FormId mWater; + ESM::FormId mOwner; + ESM::FormId mGlobal; + ESM::FormId mClimate; + ESM::FormId mWater; float mWaterHeight = sInvalidWaterLevel; - std::vector mRegions; + std::vector mRegions; Lighting mLighting; - FormId mLightingTemplate; // FO3/FONV + ESM::FormId mLightingTemplate; // FO3/FONV std::uint32_t mLightingTemplateFlags = 0; // FO3/FONV - FormId mMusic; // FO3/FONV - FormId mAcousticSpace; // FO3/FONV + ESM::FormId mMusic; // FO3/FONV + ESM::FormId mAcousticSpace; // FO3/FONV // TES4: 0 = default, 1 = public, 2 = dungeon // FO3/FONV have more types (not sure how they are used, however) std::uint8_t mMusicType = 0; diff --git a/components/esm4/loadclas.cpp b/components/esm4/loadclas.cpp index 14f81abfce..17d745baeb 100644 --- a/components/esm4/loadclas.cpp +++ b/components/esm4/loadclas.cpp @@ -33,8 +33,7 @@ void ESM4::Class::load(ESM4::Reader& reader) { - // mFormId = reader.adjustFormId(reader.hdr().record.id); // FIXME: use master adjusted? - mFormId = reader.hdr().record.getFormId(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadclas.hpp b/components/esm4/loadclas.hpp index cda3471142..567e0d4c7f 100644 --- a/components/esm4/loadclas.hpp +++ b/components/esm4/loadclas.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -44,7 +45,7 @@ namespace ESM4 std::uint32_t attr; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -57,6 +58,7 @@ namespace ESM4 // void save(ESM4::Writer& reader) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::REC_CLAS4; }; } diff --git a/components/esm4/loadclfm.cpp b/components/esm4/loadclfm.cpp index 78070d5f5b..cb03076fc8 100644 --- a/components/esm4/loadclfm.cpp +++ b/components/esm4/loadclfm.cpp @@ -33,8 +33,7 @@ void ESM4::Colour::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadclfm.hpp b/components/esm4/loadclfm.hpp index b9348800d3..9428efb56a 100644 --- a/components/esm4/loadclfm.hpp +++ b/components/esm4/loadclfm.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -48,7 +49,7 @@ namespace ESM4 struct Colour { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -61,6 +62,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::REC_CLFM4; }; } diff --git a/components/esm4/loadclot.cpp b/components/esm4/loadclot.cpp index 986c4e9778..c67ac3df6b 100644 --- a/components/esm4/loadclot.cpp +++ b/components/esm4/loadclot.cpp @@ -33,7 +33,7 @@ void ESM4::Clothing::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadclot.hpp b/components/esm4/loadclot.hpp index 4b0adc7581..00d112ce45 100644 --- a/components/esm4/loadclot.hpp +++ b/components/esm4/loadclot.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -50,7 +48,7 @@ namespace ESM4 }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -67,9 +65,9 @@ namespace ESM4 float mBoundRadius; std::uint32_t mClothingFlags; // see Armor::ArmorFlags for the values - FormId mScriptId; + ESM::FormId mScriptId; std::uint16_t mEnchantmentPoints; - FormId mEnchantment; + ESM::FormId mEnchantment; Data mData; diff --git a/components/esm4/loadcont.cpp b/components/esm4/loadcont.cpp index b054c7dd52..50a1c6b9bf 100644 --- a/components/esm4/loadcont.cpp +++ b/components/esm4/loadcont.cpp @@ -33,7 +33,7 @@ void ESM4::Container::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadcont.hpp b/components/esm4/loadcont.hpp index 945e93b101..e760916695 100644 --- a/components/esm4/loadcont.hpp +++ b/components/esm4/loadcont.hpp @@ -32,9 +32,8 @@ #include #include -#include +#include -#include "formid.hpp" #include "inventory.hpp" // InventoryItem namespace ESM4 @@ -44,7 +43,7 @@ namespace ESM4 struct Container { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -55,9 +54,9 @@ namespace ESM4 unsigned char mDataFlags; float mWeight; - FormId mOpenSound; - FormId mCloseSound; - FormId mScriptId; // TES4 only + ESM::FormId mOpenSound; + ESM::FormId mCloseSound; + ESM::FormId mScriptId; // TES4 only std::vector mInventory; diff --git a/components/esm4/loadcrea.cpp b/components/esm4/loadcrea.cpp index 8ba6d8a8f4..0c07eb92e3 100644 --- a/components/esm4/loadcrea.cpp +++ b/components/esm4/loadcrea.cpp @@ -37,7 +37,7 @@ void ESM4::Creature::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -63,19 +63,11 @@ void ESM4::Creature::load(ESM4::Reader& reader) break; } case ESM4::SUB_SPLO: - { - FormId id; - reader.getFormId(id); - mSpell.push_back(id); + reader.getFormId(mSpell.emplace_back()); break; - } case ESM4::SUB_PKID: - { - FormId id; - reader.getFormId(id); - mAIPackages.push_back(id); + reader.getFormId(mAIPackages.emplace_back()); break; - } case ESM4::SUB_SNAM: reader.get(mFaction); reader.adjustFormId(mFaction.faction); @@ -163,12 +155,8 @@ void ESM4::Creature::load(ESM4::Reader& reader) reader.getFormId(mBaseTemplate); break; // FO3 case ESM4::SUB_PNAM: // FO3/FONV/TES5 - { - FormId bodyPart; - reader.getFormId(bodyPart); - mBodyParts.push_back(bodyPart); + reader.getFormId(mBodyParts.emplace_back()); break; - } case ESM4::SUB_MODT: case ESM4::SUB_RNAM: case ESM4::SUB_CSDT: diff --git a/components/esm4/loadcrea.hpp b/components/esm4/loadcrea.hpp index 1830866773..30068daf89 100644 --- a/components/esm4/loadcrea.hpp +++ b/components/esm4/loadcrea.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include "actor.hpp" #include "inventory.hpp" @@ -106,25 +106,25 @@ namespace ESM4 }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mFullName; std::string mModel; - FormId mDeathItem; - std::vector mSpell; - FormId mScriptId; + ESM::FormId mDeathItem; + std::vector mSpell; + ESM::FormId mScriptId; AIData mAIData; - std::vector mAIPackages; + std::vector mAIPackages; ActorBaseConfig mBaseConfig; ActorFaction mFaction; Data mData; - FormId mCombatStyle; - FormId mSoundBase; - FormId mSound; + ESM::FormId mCombatStyle; + ESM::FormId mSoundBase; + ESM::FormId mSound; std::uint8_t mSoundChance; float mBaseScale; float mTurningSpeed; @@ -138,8 +138,8 @@ namespace ESM4 std::vector mInventory; - FormId mBaseTemplate; // FO3/FONV - std::vector mBodyParts; // FO3/FONV + ESM::FormId mBaseTemplate; // FO3/FONV + std::vector mBodyParts; // FO3/FONV void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; diff --git a/components/esm4/loaddial.cpp b/components/esm4/loaddial.cpp index 071642cf5c..9f7950e40c 100644 --- a/components/esm4/loaddial.cpp +++ b/components/esm4/loaddial.cpp @@ -34,8 +34,7 @@ void ESM4::Dialogue::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -50,19 +49,11 @@ void ESM4::Dialogue::load(ESM4::Reader& reader) reader.getZString(mTopicName); break; case ESM4::SUB_QSTI: - { - FormId questId; - reader.getFormId(questId); - mQuests.push_back(questId); + reader.getFormId(mQuests.emplace_back()); break; - } case ESM4::SUB_QSTR: // Seems never used in TES4 - { - FormId questRem; - reader.getFormId(questRem); - mQuestsRemoved.push_back(questRem); + reader.getFormId(mQuestsRemoved.emplace_back()); break; - } case ESM4::SUB_DATA: { if (subHdr.dataSize == 4) // TES5 diff --git a/components/esm4/loaddial.hpp b/components/esm4/loaddial.hpp index 6883db915d..b382e36b1f 100644 --- a/components/esm4/loaddial.hpp +++ b/components/esm4/loaddial.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,12 +41,12 @@ namespace ESM4 struct Dialogue { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; - std::vector mQuests; - std::vector mQuestsRemoved; // FONV only? + std::vector mQuests; + std::vector mQuestsRemoved; // FONV only? std::string mTopicName; std::string mTextDumb; // FIXME: temp name @@ -60,6 +61,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_DIAL4; }; } diff --git a/components/esm4/loaddobj.cpp b/components/esm4/loaddobj.cpp index b6a525e637..50135fc7a1 100644 --- a/components/esm4/loaddobj.cpp +++ b/components/esm4/loaddobj.cpp @@ -36,8 +36,7 @@ void ESM4::DefaultObj::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loaddobj.hpp b/components/esm4/loaddobj.hpp index 75530ac4bc..4e724eb756 100644 --- a/components/esm4/loaddobj.hpp +++ b/components/esm4/loaddobj.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,46 +42,46 @@ namespace ESM4 struct Defaults { - FormId stimpack; - FormId superStimpack; - FormId radX; - FormId radAway; - FormId morphine; - FormId perkParalysis; - FormId playerFaction; - FormId mysteriousStrangerNPC; - FormId mysteriousStrangerFaction; - FormId defaultMusic; - FormId battleMusic; - FormId deathMusic; - FormId successMusic; - FormId levelUpMusic; - FormId playerVoiceMale; - FormId playerVoiceMaleChild; - FormId playerVoiceFemale; - FormId playerVoiceFemaleChild; - FormId eatPackageDefaultFood; - FormId everyActorAbility; - FormId drugWearsOffImageSpace; + ESM::FormId stimpack; + ESM::FormId superStimpack; + ESM::FormId radX; + ESM::FormId radAway; + ESM::FormId morphine; + ESM::FormId perkParalysis; + ESM::FormId playerFaction; + ESM::FormId mysteriousStrangerNPC; + ESM::FormId mysteriousStrangerFaction; + ESM::FormId defaultMusic; + ESM::FormId battleMusic; + ESM::FormId deathMusic; + ESM::FormId successMusic; + ESM::FormId levelUpMusic; + ESM::FormId playerVoiceMale; + ESM::FormId playerVoiceMaleChild; + ESM::FormId playerVoiceFemale; + ESM::FormId playerVoiceFemaleChild; + ESM::FormId eatPackageDefaultFood; + ESM::FormId everyActorAbility; + ESM::FormId drugWearsOffImageSpace; // below FONV only - FormId doctorsBag; - FormId missFortuneNPC; - FormId missFortuneFaction; - FormId meltdownExplosion; - FormId unarmedForwardPA; - FormId unarmedBackwardPA; - FormId unarmedLeftPA; - FormId unarmedRightPA; - FormId unarmedCrouchPA; - FormId unarmedCounterPA; - FormId spotterEffect; - FormId itemDetectedEfect; - FormId cateyeMobileEffectNYI; + ESM::FormId doctorsBag; + ESM::FormId missFortuneNPC; + ESM::FormId missFortuneFaction; + ESM::FormId meltdownExplosion; + ESM::FormId unarmedForwardPA; + ESM::FormId unarmedBackwardPA; + ESM::FormId unarmedLeftPA; + ESM::FormId unarmedRightPA; + ESM::FormId unarmedCrouchPA; + ESM::FormId unarmedCounterPA; + ESM::FormId spotterEffect; + ESM::FormId itemDetectedEfect; + ESM::FormId cateyeMobileEffectNYI; }; struct DefaultObj { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -91,6 +92,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_DOBJ4; }; } diff --git a/components/esm4/loaddoor.cpp b/components/esm4/loaddoor.cpp index d1a8d8e6ed..0f51caf64d 100644 --- a/components/esm4/loaddoor.cpp +++ b/components/esm4/loaddoor.cpp @@ -33,7 +33,7 @@ void ESM4::Door::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loaddoor.hpp b/components/esm4/loaddoor.hpp index 808f80d536..fb94b7c1b2 100644 --- a/components/esm4/loaddoor.hpp +++ b/components/esm4/loaddoor.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -50,7 +48,7 @@ namespace ESM4 Flag_MinimalUse = 0x08 }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -60,11 +58,11 @@ namespace ESM4 float mBoundRadius; std::uint8_t mDoorFlags; - FormId mScriptId; - FormId mOpenSound; // SNDR for TES5, SOUN for others - FormId mCloseSound; // SNDR for TES5, SOUN for others - FormId mLoopSound; - FormId mRandomTeleport; + ESM::FormId mScriptId; + ESM::FormId mOpenSound; // SNDR for TES5, SOUN for others + ESM::FormId mCloseSound; // SNDR for TES5, SOUN for others + ESM::FormId mLoopSound; + ESM::FormId mRandomTeleport; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; diff --git a/components/esm4/loadeyes.cpp b/components/esm4/loadeyes.cpp index 253d7d3109..28f6d33c6e 100644 --- a/components/esm4/loadeyes.cpp +++ b/components/esm4/loadeyes.cpp @@ -33,8 +33,7 @@ void ESM4::Eyes::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadeyes.hpp b/components/esm4/loadeyes.hpp index 2ca765bb01..1607dba2b7 100644 --- a/components/esm4/loadeyes.hpp +++ b/components/esm4/loadeyes.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -46,7 +47,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -59,6 +60,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_EYES4; }; } diff --git a/components/esm4/loadflor.cpp b/components/esm4/loadflor.cpp index bdfe03a575..6bbc31ffe2 100644 --- a/components/esm4/loadflor.cpp +++ b/components/esm4/loadflor.cpp @@ -33,8 +33,7 @@ void ESM4::Flora::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadflor.hpp b/components/esm4/loadflor.hpp index ea907882d7..0988539f00 100644 --- a/components/esm4/loadflor.hpp +++ b/components/esm4/loadflor.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -57,7 +58,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -66,15 +67,16 @@ namespace ESM4 float mBoundRadius; - FormId mScriptId; - FormId mIngredient; - FormId mSound; + ESM::FormId mScriptId; + ESM::FormId mIngredient; + ESM::FormId mSound; Production mPercentHarvest; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_FLOR4; }; } diff --git a/components/esm4/loadflst.cpp b/components/esm4/loadflst.cpp index 4650f2f13f..a1e8e3ef16 100644 --- a/components/esm4/loadflst.cpp +++ b/components/esm4/loadflst.cpp @@ -33,8 +33,7 @@ void ESM4::FormIdList::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -46,12 +45,8 @@ void ESM4::FormIdList::load(ESM4::Reader& reader) reader.getZString(mEditorId); break; case ESM4::SUB_LNAM: - { - FormId formId; - reader.getFormId(formId); - mObjects.push_back(formId); + reader.getFormId(mObjects.emplace_back()); break; - } default: throw std::runtime_error("ESM4::FLST::load - Unknown subrecord " + ESM::printName(subHdr.typeId)); } diff --git a/components/esm4/loadflst.hpp b/components/esm4/loadflst.hpp index 53f3522b9f..816cb11f5e 100644 --- a/components/esm4/loadflst.hpp +++ b/components/esm4/loadflst.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,17 +41,18 @@ namespace ESM4 struct FormIdList { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; - std::vector mObjects; + std::vector mObjects; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_FLST4; }; } diff --git a/components/esm4/loadfurn.cpp b/components/esm4/loadfurn.cpp index 226bb42eb8..9d84312e26 100644 --- a/components/esm4/loadfurn.cpp +++ b/components/esm4/loadfurn.cpp @@ -33,7 +33,7 @@ void ESM4::Furniture::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadfurn.hpp b/components/esm4/loadfurn.hpp index 3bc88da4a5..eed4ea9699 100644 --- a/components/esm4/loadfurn.hpp +++ b/components/esm4/loadfurn.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -42,7 +40,7 @@ namespace ESM4 struct Furniture { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -51,7 +49,7 @@ namespace ESM4 float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; std::uint32_t mActiveMarkerFlags; void load(ESM4::Reader& reader); diff --git a/components/esm4/loadglob.cpp b/components/esm4/loadglob.cpp index 5c56e799bf..39593a4a7d 100644 --- a/components/esm4/loadglob.cpp +++ b/components/esm4/loadglob.cpp @@ -33,8 +33,7 @@ void ESM4::GlobalVariable::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadglob.hpp b/components/esm4/loadglob.hpp index 62e074247f..c9c83f58b4 100644 --- a/components/esm4/loadglob.hpp +++ b/components/esm4/loadglob.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct GlobalVariable { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -51,6 +52,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_GLOB4; }; } diff --git a/components/esm4/loadgmst.cpp b/components/esm4/loadgmst.cpp index d58c6d3d87..b403d09be9 100644 --- a/components/esm4/loadgmst.cpp +++ b/components/esm4/loadgmst.cpp @@ -10,7 +10,7 @@ namespace ESM4 { namespace { - GameSetting::Data readData(FormId formId, std::string_view editorId, Reader& reader) + GameSetting::Data readData(ESM::FormId formId, std::string_view editorId, Reader& reader) { if (editorId.empty()) { @@ -53,8 +53,7 @@ namespace ESM4 void GameSetting::load(Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -66,11 +65,11 @@ namespace ESM4 reader.getZString(mEditorId); break; case ESM4::SUB_DATA: - mData = readData(mFormId, mEditorId, reader); + mData = readData(mId, mEditorId, reader); break; default: throw std::runtime_error( - "Unknown ESM4 GMST (" + mFormId.toString() + ") subrecord " + ESM::printName(subHdr.typeId)); + "Unknown ESM4 GMST (" + mId.toString() + ") subrecord " + ESM::printName(subHdr.typeId)); } } } diff --git a/components/esm4/loadgmst.hpp b/components/esm4/loadgmst.hpp index 68095404a3..a8790bad26 100644 --- a/components/esm4/loadgmst.hpp +++ b/components/esm4/loadgmst.hpp @@ -5,7 +5,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -15,12 +16,13 @@ namespace ESM4 { using Data = std::variant; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; Data mData; void load(Reader& reader); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_GMST4; }; } diff --git a/components/esm4/loadgras.cpp b/components/esm4/loadgras.cpp index a18bfd7bb7..88147ecae9 100644 --- a/components/esm4/loadgras.cpp +++ b/components/esm4/loadgras.cpp @@ -33,8 +33,7 @@ void ESM4::Grass::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadgras.hpp b/components/esm4/loadgras.hpp index 29a5bd61d9..844fc58d37 100644 --- a/components/esm4/loadgras.hpp +++ b/components/esm4/loadgras.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -75,7 +76,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -89,6 +90,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_GRAS4; }; } diff --git a/components/esm4/loadgrup.hpp b/components/esm4/loadgrup.hpp index 7cc5abfff4..e99c2bff6a 100644 --- a/components/esm4/loadgrup.hpp +++ b/components/esm4/loadgrup.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + namespace ESM4 { // http://www.uesp.net/wiki/Tes4Mod:Mod_File_Format#Hierarchical_Top_Groups @@ -76,14 +79,14 @@ namespace ESM4 // struct WorldGroup { - FormId mWorld; // WRLD record for this group + ESM::FormId mWorld; // WRLD record for this group // occurs only after World Child (type 1) // since GRUP label may not be reliable, need to keep the formid of the current WRLD in // the reader's context - FormId mRoad; + ESM::FormId mRoad; - std::vector mCells; // FIXME should this be CellGroup* instead? + std::vector mCells; // FIXME should this be CellGroup* instead? }; // http://www.uesp.net/wiki/Tes4Mod:Mod_File_Format/CELL @@ -99,7 +102,7 @@ namespace ESM4 // NOTE: There may be many CELL records in one subblock struct CellGroup { - FormId mCell; // CELL record for this cell group + ESM::FormId mCell; // CELL record for this cell group int mCellModIndex; // from which file to get the CELL record (e.g. may have been updated) // For retrieving parent group size (for lazy loading or skipping) and sub-block number / grid @@ -129,20 +132,20 @@ namespace ESM4 // cache (modindex adjusted) formId's of children // FIXME: also need file index + file context of all those that has type 8 GRUP GroupTypeHeader mHdrPersist; - std::vector mPersistent; // REFR, ACHR, ACRE - std::vector mdelPersistent; + std::vector mPersistent; // REFR, ACHR, ACRE + std::vector mdelPersistent; // FIXME: also need file index + file context of all those that has type 10 GRUP GroupTypeHeader mHdrVisDist; - std::vector mVisibleDist; // REFR, ACHR, ACRE - std::vector mdelVisibleDist; + std::vector mVisibleDist; // REFR, ACHR, ACRE + std::vector mdelVisibleDist; // FIXME: also need file index + file context of all those that has type 9 GRUP GroupTypeHeader mHdrTemp; - FormId mLand; // if present, assume only one LAND per exterior CELL - FormId mPgrd; // if present, seems to be the first record after LAND in Temp Cell Child GRUP - std::vector mTemporary; // REFR, ACHR, ACRE - std::vector mdelTemporary; + ESM::FormId mLand; // if present, assume only one LAND per exterior CELL + ESM::FormId mPgrd; // if present, seems to be the first record after LAND in Temp Cell Child GRUP + std::vector mTemporary; // REFR, ACHR, ACRE + std::vector mdelTemporary; // need to keep modindex and context for lazy loading (of all the files that contribute // to this group) diff --git a/components/esm4/loadhair.cpp b/components/esm4/loadhair.cpp index 5b1f44afdf..3ab983d6b6 100644 --- a/components/esm4/loadhair.cpp +++ b/components/esm4/loadhair.cpp @@ -33,8 +33,7 @@ void ESM4::Hair::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadhair.hpp b/components/esm4/loadhair.hpp index 3b278fe4b4..1c643f60b0 100644 --- a/components/esm4/loadhair.hpp +++ b/components/esm4/loadhair.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -46,7 +47,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -62,6 +63,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_HAIR4; }; } diff --git a/components/esm4/loadhdpt.cpp b/components/esm4/loadhdpt.cpp index 679a52bb1f..53b8a401ac 100644 --- a/components/esm4/loadhdpt.cpp +++ b/components/esm4/loadhdpt.cpp @@ -35,8 +35,7 @@ void ESM4::HeadPart::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::optional type; diff --git a/components/esm4/loadhdpt.hpp b/components/esm4/loadhdpt.hpp index f36a163284..6f08d72961 100644 --- a/components/esm4/loadhdpt.hpp +++ b/components/esm4/loadhdpt.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,7 +41,7 @@ namespace ESM4 struct HeadPart { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -49,15 +50,16 @@ namespace ESM4 std::uint8_t mData; - FormId mAdditionalPart; + ESM::FormId mAdditionalPart; std::array mTriFile; - FormId mBaseTexture; + ESM::FormId mBaseTexture; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_HDPT4; }; } diff --git a/components/esm4/loadidle.cpp b/components/esm4/loadidle.cpp index be1f7393f9..e691addb18 100644 --- a/components/esm4/loadidle.cpp +++ b/components/esm4/loadidle.cpp @@ -33,8 +33,7 @@ void ESM4::IdleAnimation::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadidle.hpp b/components/esm4/loadidle.hpp index 7ca0528ee9..6dd262f407 100644 --- a/components/esm4/loadidle.hpp +++ b/components/esm4/loadidle.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct IdleAnimation { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -47,8 +48,8 @@ namespace ESM4 std::string mEvent; std::string mModel; - FormId mParent; // IDLE or AACT - FormId mPrevious; + ESM::FormId mParent; // IDLE or AACT + ESM::FormId mPrevious; float mBoundRadius; @@ -56,6 +57,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_IDLE4; }; } diff --git a/components/esm4/loadidlm.cpp b/components/esm4/loadidlm.cpp index 70321d790f..3c561e962f 100644 --- a/components/esm4/loadidlm.cpp +++ b/components/esm4/loadidlm.cpp @@ -33,8 +33,7 @@ void ESM4::IdleMarker::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); @@ -72,7 +71,7 @@ void ESM4::IdleMarker::load(ESM4::Reader& reader) } mIdleAnim.resize(mIdleCount); - for (FormId& value : mIdleAnim) + for (ESM::FormId& value : mIdleAnim) reader.getFormId(value); break; } diff --git a/components/esm4/loadidlm.hpp b/components/esm4/loadidlm.hpp index 937c1cd12d..5c7cabec0e 100644 --- a/components/esm4/loadidlm.hpp +++ b/components/esm4/loadidlm.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,7 +41,7 @@ namespace ESM4 struct IdleMarker { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -49,12 +50,13 @@ namespace ESM4 std::uint8_t mIdleFlags; std::uint8_t mIdleCount; float mIdleTimer; - std::vector mIdleAnim; + std::vector mIdleAnim; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_IDLM4; }; } diff --git a/components/esm4/loadimod.cpp b/components/esm4/loadimod.cpp index 278a4c9b35..7382946e2c 100644 --- a/components/esm4/loadimod.cpp +++ b/components/esm4/loadimod.cpp @@ -35,8 +35,7 @@ void ESM4::ItemMod::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadimod.hpp b/components/esm4/loadimod.hpp index aab191d3c7..f1faed978c 100644 --- a/components/esm4/loadimod.hpp +++ b/components/esm4/loadimod.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,7 +42,7 @@ namespace ESM4 struct ItemMod { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -50,6 +51,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_IMOD4; }; } diff --git a/components/esm4/loadinfo.cpp b/components/esm4/loadinfo.cpp index 107fa244ef..6f0e230300 100644 --- a/components/esm4/loadinfo.cpp +++ b/components/esm4/loadinfo.cpp @@ -29,16 +29,17 @@ #include #include +#include + #include "reader.hpp" //#include "writer.hpp" void ESM4::DialogInfo::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; - mEditorId = formIdToString(mFormId); // FIXME: quick workaround to use existing code + mEditorId = ESM::RefId(mId).serializeText(); // FIXME: quick workaround to use existing code static ScriptLocalVariableData localVar; bool ignore = false; diff --git a/components/esm4/loadinfo.hpp b/components/esm4/loadinfo.hpp index af87b9f96e..3f4beca476 100644 --- a/components/esm4/loadinfo.hpp +++ b/components/esm4/loadinfo.hpp @@ -30,8 +30,9 @@ #include #include -#include "formid.hpp" #include "script.hpp" // TargetCondition +#include +#include namespace ESM4 { @@ -54,13 +55,13 @@ namespace ESM4 struct DialogInfo { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; // FIXME: no such record for INFO, but keep here to avoid extra work for now - FormId mQuest; - FormId mSound; // unused? + ESM::FormId mQuest; + ESM::FormId mSound; // unused? TargetResponseData mResponseData; std::string mResponse; @@ -72,7 +73,7 @@ namespace ESM4 std::uint16_t mInfoFlags; // see above enum TargetCondition mTargetCondition; - FormId mParam3; // TES5 only + ESM::FormId mParam3; // TES5 only ScriptDefinition mScript; // FIXME: ignoring the second one after the NEXT sub-record @@ -80,6 +81,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_INFO4; }; } diff --git a/components/esm4/loadingr.cpp b/components/esm4/loadingr.cpp index a0cf0d66d0..b1dde9de02 100644 --- a/components/esm4/loadingr.cpp +++ b/components/esm4/loadingr.cpp @@ -34,7 +34,7 @@ void ESM4::Ingredient::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadingr.hpp b/components/esm4/loadingr.hpp index e34172a035..15e9d43a7c 100644 --- a/components/esm4/loadingr.hpp +++ b/components/esm4/loadingr.hpp @@ -31,7 +31,7 @@ #include #include -#include +#include #include "effect.hpp" @@ -56,7 +56,7 @@ namespace ESM4 }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -67,7 +67,7 @@ namespace ESM4 float mBoundRadius; std::vector mScriptEffect; // FIXME: prob. should be in a struct - FormId mScriptId; + ESM::FormId mScriptId; ScriptEffect mEffect; ENIT mEnchantment; diff --git a/components/esm4/loadkeym.cpp b/components/esm4/loadkeym.cpp index 14f3539659..a46aa95f88 100644 --- a/components/esm4/loadkeym.cpp +++ b/components/esm4/loadkeym.cpp @@ -33,8 +33,7 @@ void ESM4::Key::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadkeym.hpp b/components/esm4/loadkeym.hpp index 115f150ab6..1709df55ea 100644 --- a/components/esm4/loadkeym.hpp +++ b/components/esm4/loadkeym.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -47,7 +48,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -56,11 +57,11 @@ namespace ESM4 std::string mIcon; // inventory std::string mMiniIcon; // inventory - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; Data mData; @@ -68,6 +69,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_KEYM4; }; } diff --git a/components/esm4/loadland.cpp b/components/esm4/loadland.cpp index d4ec77d149..c448c29b29 100644 --- a/components/esm4/loadland.cpp +++ b/components/esm4/loadland.cpp @@ -51,12 +51,10 @@ // void ESM4::Land::load(ESM4::Reader& reader) { - ESM::FormId formId = reader.hdr().record.getFormId(); - reader.adjustFormId(formId); - mId = ESM::RefId::formIdRefId(formId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; mDataTypes = 0; - mCell = ESM::RefId::formIdRefId(reader.currCell()); + mCell = reader.currCell(); TxtLayer layer; std::int8_t currentAddQuad = -1; // for VTXT following ATXT @@ -181,19 +179,15 @@ void ESM4::Land::load(ESM4::Reader& reader) } case ESM4::SUB_VTEX: // only in Oblivion? { - int count = (int)reader.subRecordHeader().dataSize / sizeof(FormId32); - if ((reader.subRecordHeader().dataSize % sizeof(FormId32)) != 0) + int count = (int)reader.subRecordHeader().dataSize / sizeof(ESM::FormId32); + if ((reader.subRecordHeader().dataSize % sizeof(ESM::FormId32)) != 0) throw std::runtime_error("ESM4::LAND VTEX data size error"); if (count) { mIds.resize(count); - for (std::vector::iterator it = mIds.begin(); it != mIds.end(); ++it) - { - reader.getFormId(*it); - // FIXME: debug only - // std::cout << "VTEX: " << std::hex << *it << std::endl; - } + for (ESM::FormId& id : mIds) + reader.getFormId(id); } break; } diff --git a/components/esm4/loadland.hpp b/components/esm4/loadland.hpp index 77188f7649..cbd3941a2b 100644 --- a/components/esm4/loadland.hpp +++ b/components/esm4/loadland.hpp @@ -30,10 +30,8 @@ #include #include -#include "formid.hpp" - #include -#include +#include namespace ESM4 { @@ -76,7 +74,7 @@ namespace ESM4 struct BTXT { - FormId32 formId; + ESM::FormId32 formId; std::uint8_t quadrant; // 0 = bottom left, 1 = bottom right, 2 = top left, 3 = top right std::uint8_t unknown1; std::uint16_t unknown2; @@ -84,7 +82,7 @@ namespace ESM4 struct ATXT { - FormId32 formId; + ESM::FormId32 formId; std::uint8_t quadrant; // 0 = bottom left, 1 = bottom right, 2 = top left, 3 = top right std::uint8_t unknown; std::uint16_t layerIndex; // texture layer, 0..7 @@ -111,7 +109,7 @@ namespace ESM4 std::vector layers; }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::uint32_t mLandFlags; // from DATA subrecord @@ -125,8 +123,8 @@ namespace ESM4 unsigned char mVertColr[VERTS_PER_SIDE * VERTS_PER_SIDE * 3]; // from VCLR subrecord VHGT mHeightMap; Texture mTextures[4]; // 0 = bottom left, 1 = bottom right, 2 = top left, 3 = top right - std::vector mIds; // land texture (LTEX) formids - ESM::RefId mCell; + std::vector mIds; // land texture (LTEX) formids + ESM::FormId mCell; void load(Reader& reader); Land() = default; // void save(Writer& writer) const; diff --git a/components/esm4/loadlgtm.cpp b/components/esm4/loadlgtm.cpp index ff02c26956..0959be10a2 100644 --- a/components/esm4/loadlgtm.cpp +++ b/components/esm4/loadlgtm.cpp @@ -36,8 +36,7 @@ void ESM4::LightingTemplate::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadlgtm.hpp b/components/esm4/loadlgtm.hpp index ef32b24242..9505ed2eb8 100644 --- a/components/esm4/loadlgtm.hpp +++ b/components/esm4/loadlgtm.hpp @@ -32,8 +32,9 @@ #include #include -#include "formid.hpp" #include "lighting.hpp" +#include +#include namespace ESM4 { @@ -42,7 +43,7 @@ namespace ESM4 struct LightingTemplate { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -53,6 +54,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_LGTM4; }; } diff --git a/components/esm4/loadligh.cpp b/components/esm4/loadligh.cpp index 6fc86a8685..1ea88a490b 100644 --- a/components/esm4/loadligh.cpp +++ b/components/esm4/loadligh.cpp @@ -33,7 +33,7 @@ void ESM4::Light::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadligh.hpp b/components/esm4/loadligh.hpp index b6447853b8..ea33a91231 100644 --- a/components/esm4/loadligh.hpp +++ b/components/esm4/loadligh.hpp @@ -30,10 +30,8 @@ #include #include -#include "formid.hpp" - #include -#include +#include namespace ESM4 { @@ -84,7 +82,7 @@ namespace ESM4 float weight; }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -94,8 +92,8 @@ namespace ESM4 float mBoundRadius; - FormId mScriptId; - FormId mSound; + ESM::FormId mScriptId; + ESM::FormId mSound; float mFade; diff --git a/components/esm4/loadltex.cpp b/components/esm4/loadltex.cpp index c54e467d42..55409c75ae 100644 --- a/components/esm4/loadltex.cpp +++ b/components/esm4/loadltex.cpp @@ -33,8 +33,7 @@ void ESM4::LandTexture::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadltex.hpp b/components/esm4/loadltex.hpp index 5801dc6862..5fea61d0d0 100644 --- a/components/esm4/loadltex.hpp +++ b/components/esm4/loadltex.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct LandTexture { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -48,7 +49,7 @@ namespace ESM4 std::uint8_t mHavokRestitution; std::uint8_t mTextureSpecular; // default 30 - FormId mGrass; + ESM::FormId mGrass; // ------ TES4 only ----- @@ -57,8 +58,8 @@ namespace ESM4 // ------ TES5 only ----- - FormId mTexture; - FormId mMaterial; + ESM::FormId mTexture; + ESM::FormId mMaterial; // ---------------------- @@ -66,6 +67,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_LTEX4; }; } diff --git a/components/esm4/loadlvlc.cpp b/components/esm4/loadlvlc.cpp index b3c66e9345..b1a0a0f241 100644 --- a/components/esm4/loadlvlc.cpp +++ b/components/esm4/loadlvlc.cpp @@ -33,7 +33,7 @@ void ESM4::LevelledCreature::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadlvlc.hpp b/components/esm4/loadlvlc.hpp index 901cced32f..f72b183d63 100644 --- a/components/esm4/loadlvlc.hpp +++ b/components/esm4/loadlvlc.hpp @@ -31,9 +31,8 @@ #include #include -#include +#include -#include "formid.hpp" #include "inventory.hpp" namespace ESM4 @@ -43,13 +42,13 @@ namespace ESM4 struct LevelledCreature { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; - FormId mScriptId; - FormId mTemplate; + ESM::FormId mScriptId; + ESM::FormId mTemplate; std::int8_t mChanceNone; bool mHasLvlCreaFlags; diff --git a/components/esm4/loadlvli.cpp b/components/esm4/loadlvli.cpp index aa5f2c2e40..dcdd45341c 100644 --- a/components/esm4/loadlvli.cpp +++ b/components/esm4/loadlvli.cpp @@ -33,8 +33,7 @@ void ESM4::LevelledItem::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadlvli.hpp b/components/esm4/loadlvli.hpp index 3fed0378a3..e31d7ada85 100644 --- a/components/esm4/loadlvli.hpp +++ b/components/esm4/loadlvli.hpp @@ -31,7 +31,9 @@ #include #include -#include "formid.hpp" +#include +#include + #include "inventory.hpp" // LVLO namespace ESM4 @@ -41,7 +43,7 @@ namespace ESM4 struct LevelledItem { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -64,6 +66,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_LVLI4; }; } diff --git a/components/esm4/loadlvln.cpp b/components/esm4/loadlvln.cpp index 33833fade5..b1efddc255 100644 --- a/components/esm4/loadlvln.cpp +++ b/components/esm4/loadlvln.cpp @@ -33,7 +33,7 @@ void ESM4::LevelledNpc::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; // std::uint32_t esmVer = reader.esmVersion(); // currently unused diff --git a/components/esm4/loadlvln.hpp b/components/esm4/loadlvln.hpp index ac3942f494..8e5f7a7454 100644 --- a/components/esm4/loadlvln.hpp +++ b/components/esm4/loadlvln.hpp @@ -32,9 +32,8 @@ #include #include -#include +#include -#include "formid.hpp" #include "inventory.hpp" // LVLO namespace ESM4 @@ -44,7 +43,7 @@ namespace ESM4 struct LevelledNpc { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; diff --git a/components/esm4/loadmato.cpp b/components/esm4/loadmato.cpp index 5c3d74be3a..a3b55ce1f2 100644 --- a/components/esm4/loadmato.cpp +++ b/components/esm4/loadmato.cpp @@ -33,8 +33,7 @@ void ESM4::Material::load(ESM4::Reader& reader) { - // mFormId = reader.adjustFormId(reader.hdr().record.id); // FIXME: use master adjusted? - mFormId = reader.hdr().record.getFormId(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmato.hpp b/components/esm4/loadmato.hpp index 50fc7fcd59..9ff2422310 100644 --- a/components/esm4/loadmato.hpp +++ b/components/esm4/loadmato.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct Material { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -49,6 +50,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_MATO4; }; } diff --git a/components/esm4/loadmisc.cpp b/components/esm4/loadmisc.cpp index 45e87d5446..90ebe1566c 100644 --- a/components/esm4/loadmisc.cpp +++ b/components/esm4/loadmisc.cpp @@ -33,7 +33,7 @@ void ESM4::MiscItem::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmisc.hpp b/components/esm4/loadmisc.hpp index c0468f26bb..f41705a3d5 100644 --- a/components/esm4/loadmisc.hpp +++ b/components/esm4/loadmisc.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -50,7 +48,7 @@ namespace ESM4 }; #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -59,11 +57,11 @@ namespace ESM4 std::string mIcon; // inventory std::string mMiniIcon; // inventory - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; Data mData; diff --git a/components/esm4/loadmset.cpp b/components/esm4/loadmset.cpp index 9081968f73..e15c508bc1 100644 --- a/components/esm4/loadmset.cpp +++ b/components/esm4/loadmset.cpp @@ -33,8 +33,7 @@ void ESM4::MediaSet::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmset.hpp b/components/esm4/loadmset.hpp index 4f7b8dfa09..7352324c9c 100644 --- a/components/esm4/loadmset.hpp +++ b/components/esm4/loadmset.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct MediaSet { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -83,13 +84,14 @@ namespace ESM4 float mTime3; float mTime4; - FormId mSoundIntro; // HNAM - FormId mSoundOutro; // INAM + ESM::FormId mSoundIntro; // HNAM + ESM::FormId mSoundOutro; // INAM void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_MSET4; }; } diff --git a/components/esm4/loadmstt.cpp b/components/esm4/loadmstt.cpp index 88497a7d28..e216e5e003 100644 --- a/components/esm4/loadmstt.cpp +++ b/components/esm4/loadmstt.cpp @@ -33,8 +33,7 @@ void ESM4::MovableStatic::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmstt.hpp b/components/esm4/loadmstt.hpp index c7e5b34cd0..1e5b074b68 100644 --- a/components/esm4/loadmstt.hpp +++ b/components/esm4/loadmstt.hpp @@ -29,7 +29,8 @@ #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -38,19 +39,20 @@ namespace ESM4 struct MovableStatic { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mModel; std::int8_t mData; - FormId mLoopingSound; + ESM::FormId mLoopingSound; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_MSTT4; }; } diff --git a/components/esm4/loadmusc.cpp b/components/esm4/loadmusc.cpp index 5c790aaf23..47ed71b2cf 100644 --- a/components/esm4/loadmusc.cpp +++ b/components/esm4/loadmusc.cpp @@ -30,15 +30,12 @@ #include -//#include "formid.hpp" - #include "reader.hpp" //#include "writer.hpp" void ESM4::Music::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadmusc.hpp b/components/esm4/loadmusc.hpp index 56f5821bc0..964e33665c 100644 --- a/components/esm4/loadmusc.hpp +++ b/components/esm4/loadmusc.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,7 +42,7 @@ namespace ESM4 struct Music { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -51,6 +52,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_MUSC4; }; } diff --git a/components/esm4/loadnavi.cpp b/components/esm4/loadnavi.cpp index a1dd26207e..553e0f2c73 100644 --- a/components/esm4/loadnavi.cpp +++ b/components/esm4/loadnavi.cpp @@ -100,7 +100,7 @@ void ESM4::Navigation::NavMeshInfo::load(ESM4::Reader& reader) { // std::cout << "NVMI countMerged " << std::dec << count << std::endl; formIdMerged.resize(count); - for (FormId& value : formIdMerged) + for (ESM::FormId& value : formIdMerged) reader.getFormId(value); } @@ -109,7 +109,7 @@ void ESM4::Navigation::NavMeshInfo::load(ESM4::Reader& reader) { // std::cout << "NVMI countPrefMerged " << std::dec << count << std::endl; formIdPrefMerged.resize(count); - for (FormId& value : formIdPrefMerged) + for (ESM::FormId& value : formIdPrefMerged) reader.getFormId(value); } @@ -140,7 +140,8 @@ void ESM4::Navigation::NavMeshInfo::load(ESM4::Reader& reader) reader.getFormId(worldSpaceId); // FLG_Tamriel = 0x0000003c, // grid info follows, possibly Tamriel? // FLG_Morrowind = 0x01380000, // grid info follows, probably Skywind - if (worldSpaceId == FormId{ 0x3c, 0 } || worldSpaceId == FormId{ 0x380000, 1 }) + // FIXME: this check doesn't work because `getFormId` changes the index of content file. + if (worldSpaceId == ESM::FormId{ 0x3c, 0 } || worldSpaceId == ESM::FormId{ 0x380000, 1 }) { Grid grid; reader.get(grid.y); // NOTE: reverse order @@ -158,7 +159,7 @@ void ESM4::Navigation::NavMeshInfo::load(ESM4::Reader& reader) } else { - FormId cellId; + ESM::FormId cellId; reader.getFormId(cellId); cellGrid = cellId; @@ -266,7 +267,7 @@ void ESM4::Navigation::load(ESM4::Reader& reader) bool nodeFound = false; for (std::uint32_t i = 0; i < total; ++i) { - std::vector preferredPaths; + std::vector preferredPaths; reader.get(count); if (count == 1) { @@ -277,7 +278,7 @@ void ESM4::Navigation::load(ESM4::Reader& reader) if (count > 0) { preferredPaths.resize(count); - for (FormId& value : preferredPaths) + for (ESM::FormId& value : preferredPaths) reader.getFormId(value); } if (!nodeFound) @@ -294,7 +295,7 @@ void ESM4::Navigation::load(ESM4::Reader& reader) throw std::runtime_error("expected separator"); reader.get(node); // HACK - std::vector preferredPaths; + std::vector preferredPaths; mPreferredPaths.push_back(std::make_pair(node, preferredPaths)); // empty #if 0 std::cout << "node " << std::hex << node // FIXME: debugging only @@ -314,7 +315,7 @@ void ESM4::Navigation::load(ESM4::Reader& reader) std::cout << "node " << std::hex << node // FIXME: debugging only << ", index " << index << ", i " << std::dec << total+i << std::endl; #endif - FormId nodeFormId = FormId::fromUint32(node); // should we apply reader.adjustFormId? + ESM::FormId nodeFormId = ESM::FormId::fromUint32(node); // should we apply reader.adjustFormId? // std::pair::iterator, bool> res = mPathIndexMap.emplace(nodeFormId, index); // FIXME: this throws if more than one file is being loaded diff --git a/components/esm4/loadnavi.hpp b/components/esm4/loadnavi.hpp index 12022dd9ec..346e2fc936 100644 --- a/components/esm4/loadnavi.hpp +++ b/components/esm4/loadnavi.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "cellgrid.hpp" #include "vertex.hpp" @@ -45,7 +48,7 @@ namespace ESM4 struct DoorRef { std::uint32_t unknown; - FormId32 formId; + ESM::FormId32 formId; }; struct Triangle @@ -79,19 +82,19 @@ namespace ESM4 struct NavMeshInfo { - FormId formId; + ESM::FormId formId; std::uint32_t flags; // center point of the navmesh float x; float y; float z; std::uint32_t flagPrefMerges; - std::vector formIdMerged; - std::vector formIdPrefMerged; + std::vector formIdMerged; + std::vector formIdPrefMerged; std::vector linkedDoors; std::vector islandInfo; std::uint32_t locationMarker; - FormId worldSpaceId; + ESM::FormId worldSpaceId; CellGrid cellGrid; void load(ESM4::Reader& reader); @@ -101,14 +104,15 @@ namespace ESM4 std::vector mNavMeshInfo; - std::vector>> mPreferredPaths; + std::vector>> mPreferredPaths; - std::map mPathIndexMap; + std::map mPathIndexMap; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_NAVI4; }; } diff --git a/components/esm4/loadnavm.cpp b/components/esm4/loadnavm.cpp index 780d6deab7..0032d9b084 100644 --- a/components/esm4/loadnavm.cpp +++ b/components/esm4/loadnavm.cpp @@ -46,7 +46,8 @@ void ESM4::NavMesh::NVNMstruct::load(ESM4::Reader& reader) reader.getFormId(worldSpaceId); // FLG_Tamriel = 0x0000003c, // grid info follows, possibly Tamriel? // FLG_Morrowind = 0x01380000, // grid info follows, probably Skywind - if (worldSpaceId == FormId{ 0x3c, 0 } || worldSpaceId == FormId{ 380000, 1 }) + // FIXME: this check doesn't work because `getFormId` adjusts content file index + if (worldSpaceId == ESM::FormId{ 0x3c, 0 } || worldSpaceId == ESM::FormId{ 380000, 1 }) { // ^ // Y | X Y Index @@ -80,7 +81,7 @@ void ESM4::NavMesh::NVNMstruct::load(ESM4::Reader& reader) } else { - FormId cellId; + ESM::FormId cellId; reader.getFormId(cellId); cellGrid = cellId; @@ -190,7 +191,7 @@ void ESM4::NavMesh::NVNMstruct::load(ESM4::Reader& reader) void ESM4::NavMesh::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; // std::cout << "NavMesh 0x" << std::hex << this << std::endl; // FIXME diff --git a/components/esm4/loadnavm.hpp b/components/esm4/loadnavm.hpp index d134db006d..d8be6e02d8 100644 --- a/components/esm4/loadnavm.hpp +++ b/components/esm4/loadnavm.hpp @@ -30,6 +30,9 @@ #include #include +#include +#include + #include "cellgrid.hpp" #include "vertex.hpp" @@ -56,7 +59,7 @@ namespace ESM4 struct ExtConnection { std::uint32_t unknown; - FormId32 navMesh; + ESM::FormId32 navMesh; std::uint16_t triangleIndex; }; @@ -64,7 +67,7 @@ namespace ESM4 { std::uint16_t triangleIndex; std::uint32_t unknown; - FormId32 doorRef; + ESM::FormId32 doorRef; }; #pragma pack(pop) @@ -72,7 +75,7 @@ namespace ESM4 { std::uint32_t unknownNVER; std::uint32_t unknownLCTN; - FormId worldSpaceId; + ESM::FormId worldSpaceId; CellGrid cellGrid; std::vector verticies; std::vector triangles; @@ -96,13 +99,14 @@ namespace ESM4 std::vector mData; // Up to 4 skywind cells in one Morrowind cell - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_NAVM4; }; } diff --git a/components/esm4/loadnote.cpp b/components/esm4/loadnote.cpp index 1b671ed537..b51600d966 100644 --- a/components/esm4/loadnote.cpp +++ b/components/esm4/loadnote.cpp @@ -33,8 +33,7 @@ void ESM4::Note::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadnote.hpp b/components/esm4/loadnote.hpp index 5b7105348a..f9d94a6b69 100644 --- a/components/esm4/loadnote.hpp +++ b/components/esm4/loadnote.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct Note { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -51,6 +52,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_NOTE4; }; } diff --git a/components/esm4/loadnpc.cpp b/components/esm4/loadnpc.cpp index 42b3ef3cd8..bd8c15d5bb 100644 --- a/components/esm4/loadnpc.cpp +++ b/components/esm4/loadnpc.cpp @@ -30,13 +30,12 @@ #include #include // getline -#include "formid.hpp" #include "reader.hpp" //#include "writer.hpp" void ESM4::Npc::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); @@ -67,19 +66,11 @@ void ESM4::Npc::load(ESM4::Reader& reader) break; } case ESM4::SUB_SPLO: - { - FormId id; - reader.getFormId(id); - mSpell.push_back(id); + reader.getFormId(mSpell.emplace_back()); break; - } case ESM4::SUB_PKID: - { - FormId id; - reader.getFormId(id); - mAIPackages.push_back(id); + reader.getFormId(mAIPackages.emplace_back()); break; - } case ESM4::SUB_SNAM: { reader.get(mFaction); @@ -219,13 +210,8 @@ void ESM4::Npc::load(ESM4::Reader& reader) break; } case ESM4::SUB_PNAM: // FO3/FONV/TES5 - { - FormId headPart; - reader.getFormId(headPart); - mHeadParts.push_back(headPart); - + reader.getFormId(mHeadParts.emplace_back()); break; - } case ESM4::SUB_HCLF: // TES5 hair colour { reader.getFormId(mHairColourId); diff --git a/components/esm4/loadnpc.hpp b/components/esm4/loadnpc.hpp index 9080779c44..530b1fdfb7 100644 --- a/components/esm4/loadnpc.hpp +++ b/components/esm4/loadnpc.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include "actor.hpp" #include "inventory.hpp" @@ -167,7 +167,7 @@ namespace ESM4 #pragma pack(pop) - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details bool mIsTES4; @@ -177,29 +177,29 @@ namespace ESM4 std::string mFullName; std::string mModel; // skeleton model (can be a marker in FO3/FONV) - FormId mRace; - FormId mClass; - FormId mHair; // not for TES5, see mHeadParts - FormId mEyes; + ESM::FormId mRace; + ESM::FormId mClass; + ESM::FormId mHair; // not for TES5, see mHeadParts + ESM::FormId mEyes; - std::vector mHeadParts; // FO3/FONV/TES5 + std::vector mHeadParts; // FO3/FONV/TES5 float mHairLength; HairColour mHairColour; // TES4/FO3/FONV - FormId mHairColourId; // TES5 + ESM::FormId mHairColourId; // TES5 - FormId mDeathItem; - std::vector mSpell; - FormId mScriptId; + ESM::FormId mDeathItem; + std::vector mSpell; + ESM::FormId mScriptId; AIData mAIData; - std::vector mAIPackages; // seems to be in priority order, 0 = highest priority + std::vector mAIPackages; // seems to be in priority order, 0 = highest priority ActorBaseConfig mBaseConfig; // union ActorFaction mFaction; Data mData; - FormId mCombatStyle; - FormId mSoundBase; - FormId mSound; + ESM::FormId mCombatStyle; + ESM::FormId mSoundBase; + ESM::FormId mSound; std::uint8_t mSoundChance; float mFootWeight; @@ -208,12 +208,12 @@ namespace ESM4 std::vector mInventory; - FormId mBaseTemplate; // FO3/FONV/TES5 - FormId mWornArmor; // TES5 only? + ESM::FormId mBaseTemplate; // FO3/FONV/TES5 + ESM::FormId mWornArmor; // TES5 only? - FormId mDefaultOutfit; // TES5 OTFT - FormId mSleepOutfit; // TES5 OTFT - FormId mDefaultPkg; + ESM::FormId mDefaultOutfit; // TES5 OTFT + ESM::FormId mSleepOutfit; // TES5 OTFT + ESM::FormId mDefaultPkg; std::vector mSymShapeModeCoefficients; // size 0 or 50 std::vector mAsymShapeModeCoefficients; // size 0 or 30 diff --git a/components/esm4/loadotft.cpp b/components/esm4/loadotft.cpp index 4b3bdd0749..b980de4a8c 100644 --- a/components/esm4/loadotft.cpp +++ b/components/esm4/loadotft.cpp @@ -33,8 +33,7 @@ void ESM4::Outfit::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) @@ -47,13 +46,9 @@ void ESM4::Outfit::load(ESM4::Reader& reader) break; case ESM4::SUB_INAM: { - std::size_t numObj = subHdr.dataSize / sizeof(FormId32); - for (std::size_t i = 0; i < numObj; ++i) - { - FormId formId; + mInventory.resize(subHdr.dataSize / sizeof(ESM::FormId32)); + for (ESM::FormId& formId : mInventory) reader.getFormId(formId); - mInventory.push_back(formId); - } break; } default: diff --git a/components/esm4/loadotft.hpp b/components/esm4/loadotft.hpp index ccdd694951..04913bb208 100644 --- a/components/esm4/loadotft.hpp +++ b/components/esm4/loadotft.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -40,17 +41,18 @@ namespace ESM4 struct Outfit { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; - std::vector mInventory; + std::vector mInventory; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_OTFT4; }; } diff --git a/components/esm4/loadpack.cpp b/components/esm4/loadpack.cpp index feea7d78f7..ab75598121 100644 --- a/components/esm4/loadpack.cpp +++ b/components/esm4/loadpack.cpp @@ -34,8 +34,7 @@ void ESM4::AIPackage::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadpack.hpp b/components/esm4/loadpack.hpp index c0968aa207..68ffef519e 100644 --- a/components/esm4/loadpack.hpp +++ b/components/esm4/loadpack.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -60,14 +61,14 @@ namespace ESM4 { std::int32_t type = 0xff; // 0 = near ref, 1 = in cell, 2 = current loc, 3 = editor loc, 4 = obj id, 5 = obj // type, 0xff = no location data - FormId32 location; // uint32_t if type = 5 + ESM::FormId32 location; // uint32_t if type = 5 std::int32_t radius; }; struct PTDT // target { std::int32_t type = 0xff; // 0 = specific ref, 1 = obj id, 2 = obj type, 0xff = no target data - FormId32 target; // uint32_t if type = 2 + ESM::FormId32 target; // uint32_t if type = 2 std::int32_t distance; }; @@ -81,13 +82,13 @@ namespace ESM4 std::uint8_t unknown3; // probably padding float compValue; std::int32_t fnIndex; - FormId32 param1; - FormId32 param2; + ESM::FormId32 param1; + ESM::FormId32 param2; std::uint32_t unknown4; // probably padding }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -102,6 +103,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_PACK4; }; } diff --git a/components/esm4/loadpgrd.cpp b/components/esm4/loadpgrd.cpp index 4a0f8de42a..12cbf6f28b 100644 --- a/components/esm4/loadpgrd.cpp +++ b/components/esm4/loadpgrd.cpp @@ -28,17 +28,16 @@ #include -#include "formid.hpp" // FIXME: for mEditorId workaround #include "reader.hpp" +#include // FIXME: for mEditorId workaround //#include "writer.hpp" void ESM4::Pathgrid::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; - mEditorId = formIdToString(mFormId); // FIXME: quick workaround to use existing code + mEditorId = ESM::RefId(mId).serializeText(); // FIXME: quick workaround to use existing code while (reader.getSubRecordHeader()) { diff --git a/components/esm4/loadpgrd.hpp b/components/esm4/loadpgrd.hpp index 369ac08c77..0cf3763cb9 100644 --- a/components/esm4/loadpgrd.hpp +++ b/components/esm4/loadpgrd.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -68,11 +69,11 @@ namespace ESM4 struct PGRL { - FormId object; + ESM::FormId object; std::vector linkedNodes; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; // FIXME: no such record for PGRD, but keep here to avoid extra work for now @@ -87,6 +88,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_PGRD4; }; } diff --git a/components/esm4/loadpgre.cpp b/components/esm4/loadpgre.cpp index 9e06b51d44..8466122528 100644 --- a/components/esm4/loadpgre.cpp +++ b/components/esm4/loadpgre.cpp @@ -35,8 +35,7 @@ void ESM4::PlacedGrenade::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadpgre.hpp b/components/esm4/loadpgre.hpp index db0f8f8174..4ce9a0a968 100644 --- a/components/esm4/loadpgre.hpp +++ b/components/esm4/loadpgre.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,7 +42,7 @@ namespace ESM4 struct PlacedGrenade { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -50,6 +51,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_PGRE4; }; } diff --git a/components/esm4/loadpwat.cpp b/components/esm4/loadpwat.cpp index 575da861cb..339ae63daf 100644 --- a/components/esm4/loadpwat.cpp +++ b/components/esm4/loadpwat.cpp @@ -35,8 +35,7 @@ void ESM4::PlaceableWater::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadpwat.hpp b/components/esm4/loadpwat.hpp index 33d0421076..ef87080e29 100644 --- a/components/esm4/loadpwat.hpp +++ b/components/esm4/loadpwat.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,7 +42,7 @@ namespace ESM4 struct PlaceableWater { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -50,6 +51,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_PWAT4; }; } diff --git a/components/esm4/loadqust.cpp b/components/esm4/loadqust.cpp index 7928414ae2..305a510f61 100644 --- a/components/esm4/loadqust.cpp +++ b/components/esm4/loadqust.cpp @@ -34,8 +34,7 @@ void ESM4::Quest::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadqust.hpp b/components/esm4/loadqust.hpp index aacf3023cc..fa2f3e8f32 100644 --- a/components/esm4/loadqust.hpp +++ b/components/esm4/loadqust.hpp @@ -31,8 +31,9 @@ #include #include -#include "formid.hpp" #include "script.hpp" // TargetCondition, ScriptDefinition +#include +#include namespace ESM4 { @@ -59,13 +60,13 @@ namespace ESM4 Flag_AllowRepeatStages = 0x08 }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mQuestName; std::string mFileName; // texture file - FormId mQuestScript; + ESM::FormId mQuestScript; QuestData mData; @@ -77,6 +78,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_QUST4; }; } diff --git a/components/esm4/loadrace.cpp b/components/esm4/loadrace.cpp index 7c3bbb489b..ef8f423963 100644 --- a/components/esm4/loadrace.cpp +++ b/components/esm4/loadrace.cpp @@ -29,13 +29,12 @@ #include #include -#include "formid.hpp" #include "reader.hpp" //#include "writer.hpp" void ESM4::Race::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); @@ -89,15 +88,8 @@ void ESM4::Race::load(ESM4::Reader& reader) break; } case ESM4::SUB_SPLO: // bonus spell formid (TES5 may have SPCT and multiple SPLO) - { - FormId magic; - reader.getFormId(magic); - mBonusSpells.push_back(magic); - // std::cout << "RACE " << printName(subHdr.typeId) << " " << formIdToString(magic) << - // std::endl; - + reader.getFormId(mBonusSpells.emplace_back()); break; - } case ESM4::SUB_DATA: // ?? different length for TES5 { // DATA:size 128 @@ -415,7 +407,7 @@ void ESM4::Race::load(ESM4::Reader& reader) // case ESM4::SUB_HNAM: { - std::size_t numHairChoices = subHdr.dataSize / sizeof(FormId32); + std::size_t numHairChoices = subHdr.dataSize / sizeof(ESM::FormId32); mHairChoices.resize(numHairChoices); for (unsigned int i = 0; i < numHairChoices; ++i) reader.getFormId(mHairChoices.at(i)); @@ -424,7 +416,7 @@ void ESM4::Race::load(ESM4::Reader& reader) } case ESM4::SUB_ENAM: { - std::size_t numEyeChoices = subHdr.dataSize / sizeof(FormId32); + std::size_t numEyeChoices = subHdr.dataSize / sizeof(ESM::FormId32); mEyeChoices.resize(numEyeChoices); for (unsigned int i = 0; i < numEyeChoices; ++i) reader.getFormId(mEyeChoices.at(i)); @@ -490,7 +482,7 @@ void ESM4::Race::load(ESM4::Reader& reader) } case ESM4::SUB_XNAM: { - FormId race; + ESM::FormId race; std::int32_t adjustment; reader.getFormId(race); reader.get(adjustment); @@ -535,7 +527,7 @@ void ESM4::Race::load(ESM4::Reader& reader) break; case ESM4::SUB_KWDA: { - FormId formid; + ESM::FormId formid; for (unsigned int i = 0; i < mNumKeywords; ++i) reader.getFormId(formid); break; @@ -571,7 +563,7 @@ void ESM4::Race::load(ESM4::Reader& reader) } case ESM4::SUB_HEAD: // TES5 { - FormId formId; + ESM::FormId formId; reader.getFormId(formId); // FIXME: no order? head, mouth, eyes, brow, hair diff --git a/components/esm4/loadrace.hpp b/components/esm4/loadrace.hpp index 2010658589..9cd4d00891 100644 --- a/components/esm4/loadrace.hpp +++ b/components/esm4/loadrace.hpp @@ -32,11 +32,9 @@ #include #include -#include -#include - #include "actor.hpp" // AttributeValues, BodyTemplate -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -109,7 +107,7 @@ namespace ESM4 std::string texture; // can be empty e.g. eye left, eye right }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details bool mIsTES5; @@ -137,8 +135,8 @@ namespace ESM4 std::vector mBodyPartsMale; // see BodyPartIndex std::vector mBodyPartsFemale; // see BodyPartIndex - std::vector mEyeChoices; // texture only - std::vector mHairChoices; // not for TES5 + std::vector mEyeChoices; // texture only + std::vector mHairChoices; // not for TES5 float mFaceGenMainClamp; float mFaceGenFaceClamp; @@ -149,20 +147,20 @@ namespace ESM4 std::vector mSymTextureModeCoefficients; // should be 50 std::vector mSymTextureModeCoeffFemale; // should be 50 - std::map mDisposition; // race adjustments - std::vector mBonusSpells; // race ability/power - std::array mVNAM; // don't know what these are; 1 or 2 RACE FormIds - std::array mDefaultHair; // male/female (HAIR FormId for TES4) + std::map mDisposition; // race adjustments + std::vector mBonusSpells; // race ability/power + std::array mVNAM; // don't know what these are; 1 or 2 RACE FormIds + std::array mDefaultHair; // male/female (HAIR FormId for TES4) std::uint32_t mNumKeywords; - FormId mSkin; // TES5 + ESM::FormId mSkin; // TES5 BodyTemplate mBodyTemplate; // TES5 // FIXME: there's no fixed order? // head, mouth, eyes, brow, hair - std::vector mHeadPartIdsMale; // TES5 - std::vector mHeadPartIdsFemale; // TES5 + std::vector mHeadPartIdsMale; // TES5 + std::vector mHeadPartIdsFemale; // TES5 void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; diff --git a/components/esm4/loadrefr.cpp b/components/esm4/loadrefr.cpp index e91cabeedd..5c7ccc2235 100644 --- a/components/esm4/loadrefr.cpp +++ b/components/esm4/loadrefr.cpp @@ -36,13 +36,13 @@ void ESM4::Reference::load(ESM4::Reader& reader) mId = reader.hdr().record.getFormId(); reader.adjustFormId(mId); mFlags = reader.hdr().record.flags; - mParent = ESM::RefId::formIdRefId(reader.currCell()); + mParent = reader.currCell(); std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; - FormId mid; - FormId sid; + ESM::FormId mid; + ESM::FormId sid; while (reader.getSubRecordHeader()) { @@ -57,9 +57,9 @@ void ESM4::Reference::load(ESM4::Reader& reader) break; case ESM4::SUB_NAME: { - FormId BaseId; + ESM::FormId BaseId; reader.getFormId(BaseId); - mBaseObj = ESM::RefId::formIdRefId(BaseId); + mBaseObj = BaseId; break; } case ESM4::SUB_DATA: @@ -165,7 +165,7 @@ void ESM4::Reference::load(ESM4::Reader& reader) // MQ11BravilGate XRTM : 0018AE1B // e.g. some are XMarkerHeading // XRTM : 000A4DD7 in OblivionRDCavesMiddleA05 (maybe spawn points?) - FormId marker; + ESM::FormId marker; reader.getFormId(marker); // std::cout << "REFR " << mEditorId << " XRTM : " << formIdToString(marker) << std::endl;// FIXME break; @@ -224,9 +224,9 @@ void ESM4::Reference::load(ESM4::Reader& reader) reader.get(dummy); reader.get(dummy); reader.get(dummy); - FormId keyForm; + ESM::FormId keyForm; reader.getFormId(keyForm); - mKey = ESM::RefId::formIdRefId(keyForm); + mKey = keyForm; reader.get(dummy); // flag? reader.get(dummy); reader.get(dummy); diff --git a/components/esm4/loadrefr.hpp b/components/esm4/loadrefr.hpp index 9a17bf27a1..00ae175b9a 100644 --- a/components/esm4/loadrefr.hpp +++ b/components/esm4/loadrefr.hpp @@ -83,7 +83,7 @@ namespace ESM4 std::string mEditorId; std::string mFullName; - ESM::RefId mBaseObj; + ESM::FormId mBaseObj; ESM::Position mPos; float mScale = 1.0f; @@ -105,7 +105,7 @@ namespace ESM4 TeleportDest mDoor; bool mIsLocked; std::int8_t mLockLevel; - ESM::RefId mKey; + ESM::FormId mKey; ESM::FormId mTargetRef; diff --git a/components/esm4/loadregn.cpp b/components/esm4/loadregn.cpp index 7485a437af..4beb27afea 100644 --- a/components/esm4/loadregn.cpp +++ b/components/esm4/loadregn.cpp @@ -33,8 +33,7 @@ void ESM4::Region::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadregn.hpp b/components/esm4/loadregn.hpp index 521e1c8dba..c3daee4279 100644 --- a/components/esm4/loadregn.hpp +++ b/components/esm4/loadregn.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -63,18 +64,18 @@ namespace ESM4 struct RegionSound { - FormId32 sound; + ESM::FormId32 sound; std::uint32_t flags; // 0 pleasant, 1 cloudy, 2 rainy, 3 snowy std::uint32_t chance; }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::uint32_t mColour; // RGBA - FormId mWorldId; // worldspace formid + ESM::FormId mWorldId; // worldspace formid std::string mShader; //?? ICON std::string mMapName; @@ -89,6 +90,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_REGN4; }; } diff --git a/components/esm4/loadroad.cpp b/components/esm4/loadroad.cpp index c2a444fab5..8a33ab1c1d 100644 --- a/components/esm4/loadroad.cpp +++ b/components/esm4/loadroad.cpp @@ -28,18 +28,17 @@ #include -#include "formid.hpp" // FIXME: for workaround #include "reader.hpp" +#include // FIXME: for workaround //#include "writer.hpp" void ESM4::Road::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; mParent = reader.currWorld(); - mEditorId = formIdToString(mFormId); // FIXME: quick workaround to use existing code + mEditorId = ESM::RefId(mId).serializeText(); // FIXME: quick workaround to use existing code while (reader.getSubRecordHeader()) { diff --git a/components/esm4/loadroad.hpp b/components/esm4/loadroad.hpp index 60aa8d17da..b52b2392b5 100644 --- a/components/esm4/loadroad.hpp +++ b/components/esm4/loadroad.hpp @@ -31,7 +31,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -66,9 +67,9 @@ namespace ESM4 float z; }; #pragma pack(pop) - FormId mParent; // world FormId, from the loading sequence + ESM::FormId mParent; // world FormId, from the loading sequence - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -80,6 +81,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_ROAD4; }; } diff --git a/components/esm4/loadsbsp.cpp b/components/esm4/loadsbsp.cpp index 89c4f58754..a874331dab 100644 --- a/components/esm4/loadsbsp.cpp +++ b/components/esm4/loadsbsp.cpp @@ -33,8 +33,7 @@ void ESM4::SubSpace::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadsbsp.hpp b/components/esm4/loadsbsp.hpp index a5bbbde85a..e000ecfb69 100644 --- a/components/esm4/loadsbsp.hpp +++ b/components/esm4/loadsbsp.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -45,7 +46,7 @@ namespace ESM4 float z; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -55,6 +56,7 @@ namespace ESM4 // void save(Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SBSP4; }; } diff --git a/components/esm4/loadscol.cpp b/components/esm4/loadscol.cpp index fec34301d4..a795b63d10 100644 --- a/components/esm4/loadscol.cpp +++ b/components/esm4/loadscol.cpp @@ -35,8 +35,7 @@ void ESM4::StaticCollection::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadscol.hpp b/components/esm4/loadscol.hpp index d8a549e471..3be0f0d70f 100644 --- a/components/esm4/loadscol.hpp +++ b/components/esm4/loadscol.hpp @@ -32,7 +32,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -41,7 +42,7 @@ namespace ESM4 struct StaticCollection { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -50,6 +51,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SCOL4; }; } diff --git a/components/esm4/loadscpt.cpp b/components/esm4/loadscpt.cpp index 03a1274d57..b4071ed21d 100644 --- a/components/esm4/loadscpt.cpp +++ b/components/esm4/loadscpt.cpp @@ -33,8 +33,7 @@ void ESM4::Script::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; static ScriptLocalVariableData localVar; diff --git a/components/esm4/loadscpt.hpp b/components/esm4/loadscpt.hpp index 20ec25f861..20c895d241 100644 --- a/components/esm4/loadscpt.hpp +++ b/components/esm4/loadscpt.hpp @@ -30,8 +30,9 @@ #include #include -#include "formid.hpp" #include "script.hpp" +#include +#include namespace ESM4 { @@ -40,7 +41,7 @@ namespace ESM4 struct Script { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -51,6 +52,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SCPT4; }; } diff --git a/components/esm4/loadscrl.cpp b/components/esm4/loadscrl.cpp index 194edf0868..954ddf4e36 100644 --- a/components/esm4/loadscrl.cpp +++ b/components/esm4/loadscrl.cpp @@ -33,8 +33,7 @@ void ESM4::Scroll::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadscrl.hpp b/components/esm4/loadscrl.hpp index 21e5e8ccba..e25f8f7b54 100644 --- a/components/esm4/loadscrl.hpp +++ b/components/esm4/loadscrl.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -45,7 +46,7 @@ namespace ESM4 float weight; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -53,8 +54,8 @@ namespace ESM4 std::string mModel; std::string mText; - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; Data mData; @@ -62,6 +63,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SCRL4; }; } diff --git a/components/esm4/loadsgst.cpp b/components/esm4/loadsgst.cpp index 580e5ba59c..c4284eb9bc 100644 --- a/components/esm4/loadsgst.cpp +++ b/components/esm4/loadsgst.cpp @@ -34,8 +34,7 @@ void ESM4::SigilStone::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadsgst.hpp b/components/esm4/loadsgst.hpp index 1626b268f6..cb0db17c91 100644 --- a/components/esm4/loadsgst.hpp +++ b/components/esm4/loadsgst.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include "effect.hpp" namespace ESM4 @@ -47,7 +50,7 @@ namespace ESM4 float weight; }; - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -58,7 +61,7 @@ namespace ESM4 float mBoundRadius; std::vector mScriptEffect; // FIXME: prob. should be in a struct - FormId mScriptId; + ESM::FormId mScriptId; ScriptEffect mEffect; Data mData; @@ -67,6 +70,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SGST4; }; } diff --git a/components/esm4/loadslgm.cpp b/components/esm4/loadslgm.cpp index 1c27b0c486..635b73312e 100644 --- a/components/esm4/loadslgm.cpp +++ b/components/esm4/loadslgm.cpp @@ -33,8 +33,7 @@ void ESM4::SoulGem::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadslgm.hpp b/components/esm4/loadslgm.hpp index cc30e502e7..55fe3dea09 100644 --- a/components/esm4/loadslgm.hpp +++ b/components/esm4/loadslgm.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -47,7 +48,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -57,7 +58,7 @@ namespace ESM4 float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; std::uint8_t mSoul; // 0 = None, 1 = Petty, 2 = Lesser, 3 = Common, 4 = Greater, 5 = Grand std::uint8_t mSoulCapacity; // 0 = None, 1 = Petty, 2 = Lesser, 3 = Common, 4 = Greater, 5 = Grand @@ -67,6 +68,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SLGM4; }; } diff --git a/components/esm4/loadsndr.cpp b/components/esm4/loadsndr.cpp index 5ae181e625..ce1b9d6d52 100644 --- a/components/esm4/loadsndr.cpp +++ b/components/esm4/loadsndr.cpp @@ -33,8 +33,7 @@ void ESM4::SoundReference::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadsndr.hpp b/components/esm4/loadsndr.hpp index 6ecaa9735a..5e52499f12 100644 --- a/components/esm4/loadsndr.hpp +++ b/components/esm4/loadsndr.hpp @@ -30,8 +30,9 @@ #include #include -#include "formid.hpp" #include "script.hpp" // TargetCondition +#include +#include namespace ESM4 { @@ -58,14 +59,14 @@ namespace ESM4 struct SoundReference { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; - FormId mSoundCategory; // SNCT - FormId mSoundId; // another SNDR - FormId mOutputModel; // SOPM + ESM::FormId mSoundCategory; // SNCT + ESM::FormId mSoundId; // another SNDR + ESM::FormId mOutputModel; // SOPM std::string mSoundFile; LoopInfo mLoopInfo; @@ -77,6 +78,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SNDR4; }; } diff --git a/components/esm4/loadsoun.cpp b/components/esm4/loadsoun.cpp index 85edd50b09..440aaaf8d2 100644 --- a/components/esm4/loadsoun.cpp +++ b/components/esm4/loadsoun.cpp @@ -33,8 +33,7 @@ void ESM4::Sound::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadsoun.hpp b/components/esm4/loadsoun.hpp index d3164912c9..09f47e5dc2 100644 --- a/components/esm4/loadsoun.hpp +++ b/components/esm4/loadsoun.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -79,7 +80,7 @@ namespace ESM4 }; #pragma pack(pop) - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -92,6 +93,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_SOUN4; }; } diff --git a/components/esm4/loadstat.cpp b/components/esm4/loadstat.cpp index 1edb9471f3..770312c11b 100644 --- a/components/esm4/loadstat.cpp +++ b/components/esm4/loadstat.cpp @@ -33,7 +33,7 @@ void ESM4::Static::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadstat.hpp b/components/esm4/loadstat.hpp index dca07c24e8..266d07b78f 100644 --- a/components/esm4/loadstat.hpp +++ b/components/esm4/loadstat.hpp @@ -32,10 +32,8 @@ #include #include -#include "formid.hpp" - #include -#include +#include namespace ESM4 { @@ -44,8 +42,7 @@ namespace ESM4 struct Static { - FormId mFormId; // from the header - ESM::RefId mId; + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details diff --git a/components/esm4/loadtact.cpp b/components/esm4/loadtact.cpp index aeea62bf05..14d29d18b1 100644 --- a/components/esm4/loadtact.cpp +++ b/components/esm4/loadtact.cpp @@ -33,8 +33,7 @@ void ESM4::TalkingActivator::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadtact.hpp b/components/esm4/loadtact.hpp index 4720d15063..7500a5a223 100644 --- a/components/esm4/loadtact.hpp +++ b/components/esm4/loadtact.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -50,7 +51,7 @@ namespace ESM4 struct TalkingActivator { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see above for details std::string mEditorId; @@ -58,15 +59,16 @@ namespace ESM4 std::string mModel; - FormId mScriptId; - FormId mVoiceType; // VTYP - FormId mLoopSound; // SOUN - FormId mRadioTemplate; // SOUN + ESM::FormId mScriptId; + ESM::FormId mVoiceType; // VTYP + ESM::FormId mLoopSound; // SOUN + ESM::FormId mRadioTemplate; // SOUN void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_TACT4; }; } diff --git a/components/esm4/loadterm.cpp b/components/esm4/loadterm.cpp index b1fbdaedc2..af7d8dd62f 100644 --- a/components/esm4/loadterm.cpp +++ b/components/esm4/loadterm.cpp @@ -33,8 +33,7 @@ void ESM4::Terminal::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadterm.hpp b/components/esm4/loadterm.hpp index f1e8984f40..3d9ad4792e 100644 --- a/components/esm4/loadterm.hpp +++ b/components/esm4/loadterm.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct Terminal { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -49,14 +50,15 @@ namespace ESM4 std::string mModel; std::string mResultText; - FormId mScriptId; - FormId mPasswordNote; - FormId mSound; + ESM::FormId mScriptId; + ESM::FormId mPasswordNote; + ESM::FormId mSound; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_TERM4; }; } diff --git a/components/esm4/loadtes4.cpp b/components/esm4/loadtes4.cpp index 0ed2d16bd8..b1d2fa2957 100644 --- a/components/esm4/loadtes4.cpp +++ b/components/esm4/loadtes4.cpp @@ -29,7 +29,6 @@ #include #include "common.hpp" -#include "formid.hpp" #include "reader.hpp" //#include "writer.hpp" @@ -81,13 +80,13 @@ void ESM4::Header::load(ESM4::Reader& reader) } case ESM4::SUB_ONAM: { - mOverrides.resize(subHdr.dataSize / sizeof(FormId32)); - for (FormId& mOverride : mOverrides) + mOverrides.resize(subHdr.dataSize / sizeof(ESM::FormId32)); + for (ESM::FormId& mOverride : mOverrides) { uint32_t v; if (!reader.getExact(v)) throw std::runtime_error("TES4 ONAM data read error"); - mOverride = FormId::fromUint32(v); + mOverride = ESM::FormId::fromUint32(v); #if 0 std::string padding; padding.insert(0, reader.stackSize()*2, ' '); diff --git a/components/esm4/loadtes4.hpp b/components/esm4/loadtes4.hpp index d92fa5fa77..6c0faa3274 100644 --- a/components/esm4/loadtes4.hpp +++ b/components/esm4/loadtes4.hpp @@ -31,8 +31,8 @@ #include #include -#include "../esm/common.hpp" // ESMVersion, MasterData -#include "formid.hpp" +#include // ESMVersion, MasterData +#include namespace ESM4 { @@ -57,7 +57,7 @@ namespace ESM4 std::string mDesc; // File description std::vector mMaster; - std::vector mOverrides; // Skyrim only, cell children (ACHR, LAND, NAVM, PGRE, PHZD, REFR) + std::vector mOverrides; // Skyrim only, cell children (ACHR, LAND, NAVM, PGRE, PHZD, REFR) // position in the vector = mod index of master files above // value = adjusted mod index based on all the files loaded so far diff --git a/components/esm4/loadtree.cpp b/components/esm4/loadtree.cpp index 5369767c7e..42ae3ce543 100644 --- a/components/esm4/loadtree.cpp +++ b/components/esm4/loadtree.cpp @@ -33,7 +33,7 @@ void ESM4::Tree::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadtree.hpp b/components/esm4/loadtree.hpp index 22921096f3..2442063086 100644 --- a/components/esm4/loadtree.hpp +++ b/components/esm4/loadtree.hpp @@ -31,7 +31,7 @@ #include #include -#include +#include namespace ESM4 { @@ -40,7 +40,7 @@ namespace ESM4 struct Tree { - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; diff --git a/components/esm4/loadtxst.cpp b/components/esm4/loadtxst.cpp index 5cac7fd116..cd17820cc6 100644 --- a/components/esm4/loadtxst.cpp +++ b/components/esm4/loadtxst.cpp @@ -33,8 +33,7 @@ void ESM4::TextureSet::load(ESM4::Reader& reader) { - mFormId = reader.hdr().record.getFormId(); - reader.adjustFormId(mFormId); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; while (reader.getSubRecordHeader()) diff --git a/components/esm4/loadtxst.hpp b/components/esm4/loadtxst.hpp index 06502af582..eedfe433ef 100644 --- a/components/esm4/loadtxst.hpp +++ b/components/esm4/loadtxst.hpp @@ -30,7 +30,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -39,7 +40,7 @@ namespace ESM4 struct TextureSet { - FormId mFormId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -57,6 +58,7 @@ namespace ESM4 // void save(ESM4::Writer& writer) const; // void blank(); + static constexpr ESM::RecNameInts sRecordId = ESM::RecNameInts::REC_TXST4; }; } diff --git a/components/esm4/loadweap.cpp b/components/esm4/loadweap.cpp index 443e5dc51c..d6fa4cac06 100644 --- a/components/esm4/loadweap.cpp +++ b/components/esm4/loadweap.cpp @@ -33,7 +33,7 @@ void ESM4::Weapon::load(ESM4::Reader& reader) { - mId = reader.getRefIdFromHeader(); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; diff --git a/components/esm4/loadweap.hpp b/components/esm4/loadweap.hpp index 9cd0861181..bb943c0e86 100644 --- a/components/esm4/loadweap.hpp +++ b/components/esm4/loadweap.hpp @@ -31,9 +31,7 @@ #include #include -#include - -#include "formid.hpp" +#include namespace ESM4 { @@ -75,7 +73,7 @@ namespace ESM4 } }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; @@ -85,14 +83,14 @@ namespace ESM4 std::string mIcon; std::string mMiniIcon; - FormId mPickUpSound; - FormId mDropSound; + ESM::FormId mPickUpSound; + ESM::FormId mDropSound; float mBoundRadius; - FormId mScriptId; + ESM::FormId mScriptId; std::uint16_t mEnchantmentPoints; - FormId mEnchantment; + ESM::FormId mEnchantment; Data mData; diff --git a/components/esm4/loadwrld.cpp b/components/esm4/loadwrld.cpp index 0ab7faab9c..ec0ff908cd 100644 --- a/components/esm4/loadwrld.cpp +++ b/components/esm4/loadwrld.cpp @@ -33,8 +33,7 @@ void ESM4::World::load(ESM4::Reader& reader) { - FormId formid = reader.hdr().record.getFormId(); - reader.adjustFormId(formid); + mId = reader.getFormIdFromHeader(); mFlags = reader.hdr().record.flags; // It should be possible to save the current world formId automatically while reading in @@ -44,8 +43,7 @@ void ESM4::World::load(ESM4::Reader& reader) // Alternatively it may be possible to figure it out by examining the group headers, but // apparently the label field is not reliable so the parent world formid may have been // corrupted by the use of ignore flag (TODO: should check to verify). - reader.setCurrWorld(formid); // save for CELL later - mId = ESM::FormIdRefId(formid); + reader.setCurrWorld(mId); // save for CELL later std::uint32_t subSize = 0; // for XXXX sub record diff --git a/components/esm4/loadwrld.hpp b/components/esm4/loadwrld.hpp index 7dc42cd035..d8b0ba2177 100644 --- a/components/esm4/loadwrld.hpp +++ b/components/esm4/loadwrld.hpp @@ -31,11 +31,10 @@ #include #include -#include "formid.hpp" -#include "grid.hpp" - #include -#include +#include + +#include "grid.hpp" namespace ESM4 { @@ -58,7 +57,7 @@ namespace ESM4 struct REFRcoord { - FormId formId; + ESM::FormId formId; std::int16_t unknown1; std::int16_t unknown2; }; @@ -84,15 +83,15 @@ namespace ESM4 float initialPitch; }; - ESM::RefId mId; // from the header + ESM::FormId mId; // from the header std::uint32_t mFlags; // from the header, see enum type RecordFlag for details std::string mEditorId; std::string mFullName; - FormId mParent; // parent worldspace formid + ESM::FormId mParent; // parent worldspace formid std::uint8_t mWorldFlags; - FormId mClimate; - FormId mWater; + ESM::FormId mClimate; + ESM::FormId mWater; float mLandLevel; float mWaterLevel; @@ -114,7 +113,7 @@ namespace ESM4 RNAMstruct mData; // ---------------------- - FormId mMusic; + ESM::FormId mMusic; // 0x01 use Land data // 0x02 use LOD data @@ -127,8 +126,8 @@ namespace ESM4 std::uint16_t mParentUseFlags; // FO3/FONV // cache formId's of children (e.g. CELL, ROAD) - std::vector mCells; - std::vector mRoads; + std::vector mCells; + std::vector mRoads; void load(ESM4::Reader& reader); // void save(ESM4::Writer& writer) const; diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index 63884574e1..02bd78116f 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -36,18 +36,21 @@ #include #include +#include #include #include #include #include -#include "formid.hpp" #include "grouptype.hpp" namespace ESM4 { namespace { + using FormId = ESM::FormId; + using FormId32 = ESM::FormId32; + std::string getError(const std::string& header, const int errorCode, const char* msg) { return header + ": code " + std::to_string(errorCode) + ", " + std::string(msg != nullptr ? msg : "(null)"); @@ -461,8 +464,8 @@ namespace ESM4 { if (mIgnoreMissingLocalizedStrings) return; - throw std::runtime_error( - "ESM4::Reader::getLocalizedString localized string not found for " + formIdToString(stringId)); + throw std::runtime_error("ESM4::Reader::getLocalizedString localized string not found for " + + ESM::RefId(stringId).toDebugString()); } str = it->second; @@ -774,11 +777,11 @@ namespace ESM4 return true; } - ESM::FormIdRefId Reader::getRefIdFromHeader() const + ESM::FormId Reader::getFormIdFromHeader() const { FormId formId = hdr().record.getFormId(); adjustFormId(formId); - return ESM::FormIdRefId(formId); + return formId; } void Reader::adjustGRUPFormId() @@ -931,7 +934,7 @@ namespace ESM4 case ESM4::Grp_CellTemporaryChild: case ESM4::Grp_CellVisibleDistChild: { - ss << ": FormId 0x" << formIdToString(FormId::fromUint32(label.value)); + ss << ": " << ESM::RefId(FormId::fromUint32(label.value)); break; } default: diff --git a/components/esm4/reader.hpp b/components/esm4/reader.hpp index 17a11cb8c2..a095c23e85 100644 --- a/components/esm4/reader.hpp +++ b/components/esm4/reader.hpp @@ -34,7 +34,7 @@ #include "common.hpp" #include "loadtes4.hpp" -#include +#include #include #include @@ -71,12 +71,12 @@ namespace ESM4 std::uint32_t typeId; std::uint32_t dataSize; // does *not* include 24 bytes (20 for TES4) of header std::uint32_t flags; - FormId32 id; + ESM::FormId32 id; std::uint32_t revision; std::uint16_t version; // not in TES4 std::uint16_t unknown; // not in TES4 - FormId getFormId() const { return FormId::fromUint32(id); } + ESM::FormId getFormId() const { return ESM::FormId::fromUint32(id); } }; union RecordHeader @@ -123,8 +123,8 @@ namespace ESM4 SubRecordHeader subRecordHeader; // header of the current sub record being processed std::uint32_t recordRead; // bytes read from the sub records, incl. the current one - FormId currWorld; // formId of current world - for grouping CELL records - FormId currCell; // formId of current cell + ESM::FormId currWorld; // formId of current world - for grouping CELL records + ESM::FormId currCell; // formId of current cell // FIXME: try to get rid of these two members, seem like massive hacks CellGrid currCellGrid; // TODO: should keep a map of cell formids bool cellGridValid; @@ -157,7 +157,7 @@ namespace ESM4 Files::IStreamPtr mILStrings; Files::IStreamPtr mDLStrings; - std::unordered_map mLStringIndex; + std::unordered_map mLStringIndex; std::vector* mGlobalReaderList = nullptr; @@ -171,7 +171,7 @@ namespace ESM4 inline bool hasLocalizedStrings() const { return (mHeader.mFlags & Rec_Localized) != 0; } - void getLocalizedStringImpl(const FormId stringId, std::string& str); + void getLocalizedStringImpl(const ESM::FormId stringId, std::string& str); // Close the file, resets all information. // After calling close() the structure may be reused to load a new file. @@ -227,7 +227,7 @@ namespace ESM4 } // Use getFormId instead - void get(FormId& value) = delete; + void get(ESM::FormId& value) = delete; template bool getExact(T& t) @@ -284,14 +284,14 @@ namespace ESM4 inline void clearCellGrid() { mCtx.cellGridValid = false; } // Should be set at the beginning of a CELL load - inline void setCurrCell(FormId formId) { mCtx.currCell = formId; } + inline void setCurrCell(ESM::FormId formId) { mCtx.currCell = formId; } - inline FormId currCell() const { return mCtx.currCell; } + inline ESM::FormId currCell() const { return mCtx.currCell; } // Should be set at the beginning of a WRLD load - inline void setCurrWorld(FormId formId) { mCtx.currWorld = formId; } + inline void setCurrWorld(ESM::FormId formId) { mCtx.currWorld = formId; } - inline FormId currWorld() const { return mCtx.currWorld; } + inline ESM::FormId currWorld() const { return mCtx.currWorld; } // Get the data part of a record // Note: assumes the header was read correctly and nothing else was read @@ -337,13 +337,13 @@ namespace ESM4 } // ModIndex adjusted formId according to master file dependencies - void adjustFormId(FormId& id) const; + void adjustFormId(ESM::FormId& id) const; // Temporary. Doesn't support mod index > 255 - void adjustFormId(FormId32& id) const; + void adjustFormId(ESM::FormId32& id) const; - bool getFormId(FormId& id); - ESM::FormIdRefId getRefIdFromHeader() const; + bool getFormId(ESM::FormId& id); + ESM::FormId getFormIdFromHeader() const; void adjustGRUPFormId(); diff --git a/components/esm4/script.hpp b/components/esm4/script.hpp index cc9bf993b6..57dd85367b 100644 --- a/components/esm4/script.hpp +++ b/components/esm4/script.hpp @@ -33,7 +33,8 @@ #include #include -#include "formid.hpp" +#include +#include namespace ESM4 { @@ -326,7 +327,7 @@ namespace ESM4 std::uint32_t unknown1; std::uint32_t responseNo; // 1 byte + padding // below FO3/FONV - FormId32 sound; // when 20 bytes usually 0 but there are exceptions (FO3 INFO FormId = 0x0002241f) + ESM::FormId32 sound; // when 20 bytes usually 0 but there are exceptions (FO3 INFO FormId = 0x0002241f) std::uint32_t flags; // 1 byte + padding (0x01 = use emotion anim) }; @@ -339,7 +340,7 @@ namespace ESM4 std::uint32_t param2; std::uint32_t runOn; // 0 subject, 1 target, 2 reference, 3 combat target, 4 linked reference // below FO3/FONV/TES5 - FormId32 reference; + ESM::FormId32 reference; }; struct ScriptHeader @@ -380,7 +381,7 @@ namespace ESM4 std::string scriptSource; std::vector localVarData; std::vector localRefVarIndex; - FormId globReference; + ESM::FormId globReference; }; } diff --git a/components/esm4/typetraits.hpp b/components/esm4/typetraits.hpp index 2e04f2e70d..b29713dbba 100644 --- a/components/esm4/typetraits.hpp +++ b/components/esm4/typetraits.hpp @@ -5,32 +5,6 @@ namespace ESM4 { - template > - struct HasFormId : std::false_type - { - }; - - template - struct HasFormId> : std::true_type - { - }; - - template - inline constexpr bool hasFormId = HasFormId::value; - - template > - struct HasParentFormId : std::false_type - { - }; - - template - struct HasParentFormId> : std::true_type - { - }; - - template - inline constexpr bool hasParentFormId = HasParentFormId::value; - template > struct HasParent : std::false_type {