diff --git a/apps/esmtool/record.cpp b/apps/esmtool/record.cpp index d099bdfcfb..912ad0d683 100644 --- a/apps/esmtool/record.cpp +++ b/apps/esmtool/record.cpp @@ -839,8 +839,7 @@ namespace EsmTool std::cout << " Quest Status: " << questStatusLabel(mData.mQuestStatus) << " (" << mData.mQuestStatus << ")" << std::endl; - std::cout << " Unknown1: " << mData.mData.mUnknown1 << std::endl; - std::cout << " Unknown2: " << (int)mData.mData.mUnknown2 << std::endl; + std::cout << " Type: " << dialogTypeLabel(mData.mData.mType) << std::endl; for (const ESM::DialInfo::SelectStruct& rule : mData.mSelects) std::cout << " Select Rule: " << ruleString(rule) << std::endl; @@ -1137,7 +1136,6 @@ namespace EsmTool std::cout << " Coordinates: (" << point.mX << "," << point.mY << "," << point.mZ << ")" << std::endl; std::cout << " Auto-Generated: " << (int)point.mAutogenerated << std::endl; std::cout << " Connections: " << (int)point.mConnectionNum << std::endl; - std::cout << " Unknown: " << point.mUnknown << std::endl; i++; } diff --git a/apps/opencs/model/world/nestedcoladapterimp.cpp b/apps/opencs/model/world/nestedcoladapterimp.cpp index 8b8c7b17be..34205e9421 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.cpp +++ b/apps/opencs/model/world/nestedcoladapterimp.cpp @@ -38,7 +38,6 @@ namespace CSMWorld point.mZ = 0; point.mAutogenerated = 0; point.mConnectionNum = 0; - point.mUnknown = 0; points.insert(points.begin() + position, point); pathgrid.mData.mPoints = pathgrid.mPoints.size(); diff --git a/apps/opencs/view/render/object.hpp b/apps/opencs/view/render/object.hpp index 5c73b12211..31f0d93ac4 100644 --- a/apps/opencs/view/render/object.hpp +++ b/apps/opencs/view/render/object.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include "tagbase.hpp" diff --git a/apps/openmw/mwmechanics/pathfinding.hpp b/apps/openmw/mwmechanics/pathfinding.hpp index 44566d3b45..0f688686cd 100644 --- a/apps/openmw/mwmechanics/pathfinding.hpp +++ b/apps/openmw/mwmechanics/pathfinding.hpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include namespace MWWorld diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index ae80a0d64e..1b57971f11 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -1,7 +1,7 @@ #ifndef GAME_MWWORLD_REFDATA_H #define GAME_MWWORLD_REFDATA_H -#include +#include #include #include diff --git a/components/detournavigator/objecttransform.hpp b/components/detournavigator/objecttransform.hpp index e56f5dd392..1d52817f52 100644 --- a/components/detournavigator/objecttransform.hpp +++ b/components/detournavigator/objecttransform.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTTRANSFORM_H #define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTTRANSFORM_H -#include +#include #include diff --git a/components/esm/defs.hpp b/components/esm/defs.hpp index cbc70582c0..52b2afb8de 100644 --- a/components/esm/defs.hpp +++ b/components/esm/defs.hpp @@ -4,12 +4,8 @@ #include #include -#include - -#include - -#include "components/esm/fourcc.hpp" #include +#include #include namespace ESM @@ -33,37 +29,6 @@ namespace ESM RT_Target = 2 }; - // Position and rotation - struct Position - { - float pos[3]{}; - - // In radians - float rot[3]{}; - - osg::Vec3f asVec3() const { return osg::Vec3f(pos[0], pos[1], pos[2]); } - - osg::Vec3f asRotationVec3() const { return osg::Vec3f(rot[0], rot[1], rot[2]); } - - friend inline bool operator<(const Position& l, const Position& r) - { - const auto tuple = [](const Position& v) { return std::tuple(v.asVec3(), v.asRotationVec3()); }; - return tuple(l) < tuple(r); - } - }; - - bool inline operator==(const Position& left, const Position& right) noexcept - { - return left.pos[0] == right.pos[0] && left.pos[1] == right.pos[1] && left.pos[2] == right.pos[2] - && left.rot[0] == right.rot[0] && left.rot[1] == right.rot[1] && left.rot[2] == right.rot[2]; - } - - bool inline operator!=(const Position& left, const Position& right) noexcept - { - return left.pos[0] != right.pos[0] || left.pos[1] != right.pos[1] || left.pos[2] != right.pos[2] - || left.rot[0] != right.rot[0] || left.rot[1] != right.rot[1] || left.rot[2] != right.rot[2]; - } - constexpr unsigned int sEsm4RecnameFlag = 0x00800000; constexpr unsigned int esm3Recname(const char (&name)[5]) diff --git a/components/esm/position.hpp b/components/esm/position.hpp new file mode 100644 index 0000000000..d48997610e --- /dev/null +++ b/components/esm/position.hpp @@ -0,0 +1,47 @@ +#ifndef OPENMW_ESM3_POSITION_H +#define OPENMW_ESM3_POSITION_H + +#include +#include +#include + +namespace ESM +{ + // Position and rotation + struct Position + { + float pos[3]{}; + + // In radians + float rot[3]{}; + + osg::Vec3f asVec3() const { return osg::Vec3f(pos[0], pos[1], pos[2]); } + + osg::Vec3f asRotationVec3() const { return osg::Vec3f(rot[0], rot[1], rot[2]); } + + friend inline bool operator<(const Position& l, const Position& r) + { + const auto tuple = [](const Position& v) { return std::tuple(v.asVec3(), v.asRotationVec3()); }; + return tuple(l) < tuple(r); + } + }; + + bool inline operator==(const Position& left, const Position& right) noexcept + { + return left.pos[0] == right.pos[0] && left.pos[1] == right.pos[1] && left.pos[2] == right.pos[2] + && left.rot[0] == right.rot[0] && left.rot[1] == right.rot[1] && left.rot[2] == right.rot[2]; + } + + bool inline operator!=(const Position& left, const Position& right) noexcept + { + return left.pos[0] != right.pos[0] || left.pos[1] != right.pos[1] || left.pos[2] != right.pos[2] + || left.rot[0] != right.rot[0] || left.rot[1] != right.rot[1] || left.rot[2] != right.rot[2]; + } + + template T> + void decompose(T&& v, const auto& f) + { + f(v.pos, v.rot); + } +} +#endif \ No newline at end of file diff --git a/components/esm3/cellid.cpp b/components/esm3/cellid.cpp index 9a5be3aada..4d08691034 100644 --- a/components/esm3/cellid.cpp +++ b/components/esm3/cellid.cpp @@ -3,9 +3,15 @@ #include "esmreader.hpp" #include "esmwriter.hpp" #include +#include namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mX, v.mY); + } void CellId::load(ESMReader& esm) { @@ -13,7 +19,7 @@ namespace ESM mIndex.mX = 0; mIndex.mY = 0; - mPaged = esm.getHNOT("CIDX", mIndex.mX, mIndex.mY); + mPaged = esm.getOptionalComposite("CIDX", mIndex); } void CellId::save(ESMWriter& esm) const @@ -21,7 +27,7 @@ namespace ESM esm.writeHNString("SPAC", mWorldspace); if (mPaged) - esm.writeHNT("CIDX", mIndex, 8); + esm.writeNamedComposite("CIDX", mIndex); } struct VisitCellRefId diff --git a/components/esm3/cellref.cpp b/components/esm3/cellref.cpp index 93a2ece669..ecba6f7f5e 100644 --- a/components/esm3/cellref.cpp +++ b/components/esm3/cellref.cpp @@ -112,7 +112,7 @@ namespace ESM case fourCC("DODT"): if constexpr (load) { - esm.getHT(cellRef.mDoorDest.pos, cellRef.mDoorDest.rot); + esm.getSubComposite(cellRef.mDoorDest); cellRef.mTeleport = true; } else @@ -132,7 +132,7 @@ namespace ESM break; case fourCC("DATA"): if constexpr (load) - esm.getHT(cellRef.mPos.pos, cellRef.mPos.rot); + esm.getSubComposite(cellRef.mPos); else esm.skipHSub(); break; @@ -224,7 +224,7 @@ namespace ESM if (!inInventory && mTeleport) { - esm.writeHNT("DODT", mDoorDest); + esm.writeNamedComposite("DODT", mDoorDest); esm.writeHNOCString("DNAM", mDestCell); } @@ -243,7 +243,7 @@ namespace ESM esm.writeHNT("UNAM", mReferenceBlocked); if (!inInventory) - esm.writeHNT("DATA", mPos, 24); + esm.writeNamedComposite("DATA", mPos); } void CellRef::blank() diff --git a/components/esm3/cellref.hpp b/components/esm3/cellref.hpp index 84b6ae1d18..5079095889 100644 --- a/components/esm3/cellref.hpp +++ b/components/esm3/cellref.hpp @@ -4,8 +4,9 @@ #include #include -#include "components/esm/defs.hpp" -#include "components/esm/refid.hpp" +#include +#include +#include namespace ESM { diff --git a/components/esm3/esmreader.hpp b/components/esm3/esmreader.hpp index 4af2264828..7d0b9b980c 100644 --- a/components/esm3/esmreader.hpp +++ b/components/esm3/esmreader.hpp @@ -184,6 +184,16 @@ namespace ESM decompose(value, [&](auto&... args) { getHNT(name, args...); }); } + bool getOptionalComposite(NAME name, auto& value) + { + if (isNextSub(name)) + { + getSubComposite(value); + return true; + } + return false; + } + void getComposite(auto& value) { decompose(value, [&](auto&... args) { (getT(args), ...); }); diff --git a/components/esm3/loadalch.cpp b/components/esm3/loadalch.cpp index b85bbd558e..4e6c2ad1e2 100644 --- a/components/esm3/loadalch.cpp +++ b/components/esm3/loadalch.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mFlags); + } + void Potion::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -36,7 +44,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("ALDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mFlags); + esm.getSubComposite(mData); hasData = true; break; case fourCC("ENAM"): @@ -71,7 +79,7 @@ namespace ESM esm.writeHNOCString("TEXT", mIcon); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("ALDT", mData, 12); + esm.writeNamedComposite("ALDT", mData); mEffects.save(esm); } diff --git a/components/esm3/loadappa.cpp b/components/esm3/loadappa.cpp index ecc00222b8..40d9fc3f72 100644 --- a/components/esm3/loadappa.cpp +++ b/components/esm3/loadappa.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mQuality, v.mWeight, v.mValue); + } + void Apparatus::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("AADT"): - esm.getHT(mData.mType, mData.mQuality, mData.mWeight, mData.mValue); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -65,7 +73,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNCString("FNAM", mName); - esm.writeHNT("AADT", mData, 16); + esm.writeNamedComposite("AADT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNCString("ITEX", mIcon); } diff --git a/components/esm3/loadarmo.cpp b/components/esm3/loadarmo.cpp index 1832014173..37290ae39a 100644 --- a/components/esm3/loadarmo.cpp +++ b/components/esm3/loadarmo.cpp @@ -3,8 +3,15 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mWeight, v.mValue, v.mHealth, v.mEnchant, v.mArmor); + } void PartReferenceList::add(ESMReader& esm) { @@ -59,7 +66,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("AODT"): - esm.getHT(mData.mType, mData.mWeight, mData.mValue, mData.mHealth, mData.mEnchant, mData.mArmor); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -103,7 +110,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCRefId("SCRI", mScript); - esm.writeHNT("AODT", mData, 24); + esm.writeNamedComposite("AODT", mData); esm.writeHNOCString("ITEX", mIcon); mParts.save(esm); esm.writeHNOCRefId("ENAM", mEnchant); diff --git a/components/esm3/loadbody.cpp b/components/esm3/loadbody.cpp index 066e5ec949..8c944c6da0 100644 --- a/components/esm3/loadbody.cpp +++ b/components/esm3/loadbody.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mPart, v.mVampire, v.mFlags, v.mType); + } + void BodyPart::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mRace = esm.getRefId(); break; case fourCC("BYDT"): - esm.getHT(mData.mPart, mData.mVampire, mData.mFlags, mData.mType); + esm.getSubComposite(mData); hasData = true; break; case SREC_DELE: @@ -59,7 +67,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCRefId("FNAM", mRace); - esm.writeHNT("BYDT", mData, 4); + esm.writeNamedComposite("BYDT", mData); } void BodyPart::blank() diff --git a/components/esm3/loadbook.cpp b/components/esm3/loadbook.cpp index 8083c59828..bece59d31b 100644 --- a/components/esm3/loadbook.cpp +++ b/components/esm3/loadbook.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mIsScroll, v.mSkillId, v.mEnchant); + } + void Book::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("BKDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mIsScroll, mData.mSkillId, mData.mEnchant); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -70,7 +78,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("BKDT", mData, 20); + esm.writeNamedComposite("BKDT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); esm.writeHNOString("TEXT", mText); diff --git a/components/esm3/loadcell.cpp b/components/esm3/loadcell.cpp index 0c37e64f1e..3c651fac1a 100644 --- a/components/esm3/loadcell.cpp +++ b/components/esm3/loadcell.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include "esmreader.hpp" @@ -41,6 +42,18 @@ namespace ESM { const StringRefId Cell::sDefaultWorldspaceId = StringRefId("sys::default"); + template T> + void decompose(T&& v, const auto& f) + { + f(v.mFlags, v.mX, v.mY); + } + + template T> + void decompose(T&& v, const auto& f) + { + f(v.mAmbient, v.mSunlight, v.mFog, v.mFogDensity); + } + // Some overloaded compare operators. bool operator==(const MovedCellRef& ref, const RefNum& refNum) { @@ -93,7 +106,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("DATA"): - esm.getHT(mData.mFlags, mData.mX, mData.mY); + esm.getSubComposite(mData); hasData = true; break; case SREC_DELE: @@ -181,7 +194,7 @@ namespace ESM void Cell::save(ESMWriter& esm, bool isDeleted) const { esm.writeHNCString("NAME", mName); - esm.writeHNT("DATA", mData, 12); + esm.writeNamedComposite("DATA", mData); if (isDeleted) { @@ -199,7 +212,7 @@ namespace ESM if (mData.mFlags & QuasiEx) esm.writeHNOCRefId("RGNN", mRegion); else if (mHasAmbi) - esm.writeHNT("AMBI", mAmbi, 16); + esm.writeNamedComposite("AMBI", mAmbi); } else { diff --git a/components/esm3/loadclas.cpp b/components/esm3/loadclas.cpp index ec4ff680fa..1fd22e2a49 100644 --- a/components/esm3/loadclas.cpp +++ b/components/esm3/loadclas.cpp @@ -2,7 +2,9 @@ #include -#include "components/esm/defs.hpp" +#include +#include + #include "esmreader.hpp" #include "esmwriter.hpp" @@ -12,6 +14,12 @@ namespace ESM = { "sSpecializationCombat", "sSpecializationMagic", "sSpecializationStealth" }; const std::array Class::specializationIndexToLuaId = { "combat", "magic", "stealth" }; + template T> + void decompose(T&& v, const auto& f) + { + f(v.mAttribute, v.mSpecialization, v.mSkills, v.mIsPlayable, v.mServices); + } + int32_t& Class::CLDTstruct::getSkill(int index, bool major) { return mSkills.at(index)[major ? 1 : 0]; @@ -42,8 +50,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("CLDT"): - esm.getHT( - mData.mAttribute, mData.mSpecialization, mData.mSkills, mData.mIsPlayable, mData.mServices); + esm.getSubComposite(mData); if (mData.mIsPlayable > 1) esm.fail("Unknown bool value"); hasData = true; @@ -77,7 +84,7 @@ namespace ESM } esm.writeHNOCString("FNAM", mName); - esm.writeHNT("CLDT", mData, 60); + esm.writeNamedComposite("CLDT", mData); esm.writeHNOString("DESC", mDescription); } diff --git a/components/esm3/loadclot.cpp b/components/esm3/loadclot.cpp index 7d60c82197..8e778243fc 100644 --- a/components/esm3/loadclot.cpp +++ b/components/esm3/loadclot.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mWeight, v.mValue, v.mEnchant); + } + void Clothing::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -30,7 +38,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("CTDT"): - esm.getHT(mData.mType, mData.mWeight, mData.mValue, mData.mEnchant); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -73,7 +81,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("CTDT", mData, 12); + esm.writeNamedComposite("CTDT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); diff --git a/components/esm3/loadcont.cpp b/components/esm3/loadcont.cpp index d016654fea..9d90491448 100644 --- a/components/esm3/loadcont.cpp +++ b/components/esm3/loadcont.cpp @@ -100,8 +100,8 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("CNDT", mWeight, 4); - esm.writeHNT("FLAG", mFlags, 4); + esm.writeHNT("CNDT", mWeight); + esm.writeHNT("FLAG", mFlags); esm.writeHNOCRefId("SCRI", mScript); diff --git a/components/esm3/loadcrea.cpp b/components/esm3/loadcrea.cpp index 5a0d8048bc..83bdbd06ad 100644 --- a/components/esm3/loadcrea.cpp +++ b/components/esm3/loadcrea.cpp @@ -1,12 +1,19 @@ #include "loadcrea.hpp" #include +#include #include "esmreader.hpp" #include "esmwriter.hpp" namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mLevel, v.mAttributes, v.mHealth, v.mMana, v.mFatigue, v.mSoul, v.mCombat, v.mMagic, v.mStealth, + v.mAttack, v.mGold); + } void Creature::load(ESMReader& esm, bool& isDeleted) { @@ -48,8 +55,7 @@ namespace ESM mScript = esm.getRefId(); break; case fourCC("NPDT"): - esm.getHT(mData.mType, mData.mLevel, mData.mAttributes, mData.mHealth, mData.mMana, mData.mFatigue, - mData.mSoul, mData.mCombat, mData.mMagic, mData.mStealth, mData.mAttack, mData.mGold); + esm.getSubComposite(mData); hasNpdt = true; break; case fourCC("FLAG"): @@ -121,7 +127,7 @@ namespace ESM esm.writeHNOCRefId("CNAM", mOriginal); esm.writeHNOCString("FNAM", mName); esm.writeHNOCRefId("SCRI", mScript); - esm.writeHNT("NPDT", mData, 96); + esm.writeNamedComposite("NPDT", mData); esm.writeHNT("FLAG", ((mBloodType << 10) + mFlags)); if (mScale != 1.0) { diff --git a/components/esm3/loadench.cpp b/components/esm3/loadench.cpp index 1d19b690f0..9eb4fae301 100644 --- a/components/esm3/loadench.cpp +++ b/components/esm3/loadench.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mCost, v.mCharge, v.mFlags); + } + void Enchantment::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -23,7 +31,7 @@ namespace ESM hasName = true; break; case fourCC("ENDT"): - esm.getHT(mData.mType, mData.mCost, mData.mCharge, mData.mFlags); + esm.getSubComposite(mData); hasData = true; break; case fourCC("ENAM"): @@ -55,7 +63,7 @@ namespace ESM return; } - esm.writeHNT("ENDT", mData, 16); + esm.writeNamedComposite("ENDT", mData); mEffects.save(esm); } diff --git a/components/esm3/loadinfo.cpp b/components/esm3/loadinfo.cpp index 9cff21da3e..714d59fef4 100644 --- a/components/esm3/loadinfo.cpp +++ b/components/esm3/loadinfo.cpp @@ -3,8 +3,17 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + char padding = 0; + f(v.mType, v.mDisposition, v.mRank, v.mGender, v.mPCrank, padding); + } + void DialInfo::load(ESMReader& esm, bool& isDeleted) { mId = esm.getHNRefId("INAM"); @@ -23,8 +32,7 @@ namespace ESM switch (esm.retSubName().toInt()) { case fourCC("DATA"): - esm.getHT(mData.mUnknown1, mData.mDisposition, mData.mRank, mData.mGender, mData.mPCrank, - mData.mUnknown2); + esm.getSubComposite(mData); break; case fourCC("ONAM"): mActor = esm.getRefId(); @@ -102,7 +110,7 @@ namespace ESM return; } - esm.writeHNT("DATA", mData, 12); + esm.writeNamedComposite("DATA", mData); esm.writeHNOCRefId("ONAM", mActor); esm.writeHNOCRefId("RNAM", mRace); esm.writeHNOCRefId("CNAM", mClass); diff --git a/components/esm3/loadinfo.hpp b/components/esm3/loadinfo.hpp index 518e2eaa54..c2756e8d9c 100644 --- a/components/esm3/loadinfo.hpp +++ b/components/esm3/loadinfo.hpp @@ -35,7 +35,7 @@ namespace ESM struct DATAstruct { - int32_t mUnknown1 = 0; + int32_t mType = 0; // See Dialogue::Type union { int32_t mDisposition = 0; // Used for dialogue responses @@ -44,7 +44,6 @@ namespace ESM signed char mRank = -1; // Rank of NPC signed char mGender = Gender::NA; // See Gender enum signed char mPCrank = -1; // Player rank - signed char mUnknown2 = 0; }; // 12 bytes DATAstruct mData; diff --git a/components/esm3/loadingr.cpp b/components/esm3/loadingr.cpp index 4e409ab63d..6a4753d8e4 100644 --- a/components/esm3/loadingr.cpp +++ b/components/esm3/loadingr.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mEffectID, v.mSkills, v.mAttributes); + } + void Ingredient::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("IRDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mEffectID, mData.mSkills, mData.mAttributes); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -82,7 +90,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("IRDT", mData, 56); + esm.writeNamedComposite("IRDT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadligh.cpp b/components/esm3/loadligh.cpp index e22f6110c2..bb4f6bac7b 100644 --- a/components/esm3/loadligh.cpp +++ b/components/esm3/loadligh.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mTime, v.mRadius, v.mColor, v.mFlags); + } + void Light::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -31,7 +39,7 @@ namespace ESM mIcon = esm.getHString(); break; case fourCC("LHDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mTime, mData.mRadius, mData.mColor, mData.mFlags); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -68,7 +76,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); esm.writeHNOCString("ITEX", mIcon); - esm.writeHNT("LHDT", mData, 24); + esm.writeNamedComposite("LHDT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCRefId("SNAM", mSound); } diff --git a/components/esm3/loadlock.cpp b/components/esm3/loadlock.cpp index 578a8a36a7..019d6f9952 100644 --- a/components/esm3/loadlock.cpp +++ b/components/esm3/loadlock.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mQuality, v.mUses); + } + void Lockpick::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("LKDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mQuality, mData.mUses); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -66,7 +74,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("LKDT", mData, 16); + esm.writeNamedComposite("LKDT", mData); esm.writeHNORefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadmisc.cpp b/components/esm3/loadmisc.cpp index b38ce63294..63df1c6551 100644 --- a/components/esm3/loadmisc.cpp +++ b/components/esm3/loadmisc.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mFlags); + } + void Miscellaneous::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("MCDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mFlags); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -65,7 +73,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("MCDT", mData, 12); + esm.writeNamedComposite("MCDT", mData); esm.writeHNOCRefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadpgrd.cpp b/components/esm3/loadpgrd.cpp index 4f0a62a9d4..ebd51dcff0 100644 --- a/components/esm3/loadpgrd.cpp +++ b/components/esm3/loadpgrd.cpp @@ -3,8 +3,23 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mX, v.mY, v.mGranularity, v.mPoints); + } + + template T> + void decompose(T&& v, const auto& f) + { + char padding[2] = { 0, 0 }; + f(v.mX, v.mY, v.mZ, v.mAutogenerated, v.mConnectionNum, padding); + } + Pathgrid::Point& Pathgrid::Point::operator=(const float rhs[3]) { mX = static_cast(rhs[0]); @@ -12,7 +27,6 @@ namespace ESM mZ = static_cast(rhs[2]); mAutogenerated = 0; mConnectionNum = 0; - mUnknown = 0; return *this; } Pathgrid::Point::Point(const float rhs[3]) @@ -21,7 +35,6 @@ namespace ESM , mZ(static_cast(rhs[2])) , mAutogenerated(0) , mConnectionNum(0) - , mUnknown(0) { } Pathgrid::Point::Point() @@ -30,7 +43,6 @@ namespace ESM , mZ(0) , mAutogenerated(0) , mConnectionNum(0) - , mUnknown(0) { } @@ -54,15 +66,14 @@ namespace ESM mCell = esm.getRefId(); break; case fourCC("DATA"): - esm.getHT(mData.mX, mData.mY, mData.mGranularity, mData.mPoints); + esm.getSubComposite(mData); hasData = true; break; case fourCC("PGRP"): { esm.getSubHeader(); uint32_t size = esm.getSubSize(); - // Check that the sizes match up. Size = 16 * path points - if (size != sizeof(Point) * mData.mPoints) + if (size != 16u * mData.mPoints) esm.fail("Path point subrecord size mismatch"); else { @@ -70,12 +81,7 @@ namespace ESM for (uint16_t i = 0; i < mData.mPoints; ++i) { Point p; - esm.getT(p.mX); - esm.getT(p.mY); - esm.getT(p.mZ); - esm.getT(p.mAutogenerated); - esm.getT(p.mConnectionNum); - esm.getT(p.mUnknown); + esm.getComposite(p); mPoints.push_back(p); edgeCount += p.mConnectionNum; } @@ -160,7 +166,7 @@ namespace ESM // Save esm.writeHNCRefId("NAME", mCell); - esm.writeHNT("DATA", mData, 12); + esm.writeNamedComposite("DATA", mData); if (isDeleted) { @@ -173,7 +179,7 @@ namespace ESM esm.startSubRecord("PGRP"); for (const Point& point : correctedPoints) { - esm.writeT(point); + esm.writeComposite(point); } esm.endRecord("PGRP"); } diff --git a/components/esm3/loadpgrd.hpp b/components/esm3/loadpgrd.hpp index a343552efb..f2a33f9b9a 100644 --- a/components/esm3/loadpgrd.hpp +++ b/components/esm3/loadpgrd.hpp @@ -35,7 +35,6 @@ namespace ESM int32_t mX, mY, mZ; // Location of point unsigned char mAutogenerated; // autogenerated vs. user coloring flag? unsigned char mConnectionNum; // number of connections for this point - int16_t mUnknown; Point& operator=(const float[3]); Point(const float[3]); Point(); @@ -45,7 +44,6 @@ namespace ESM , mZ(z) , mAutogenerated(0) , mConnectionNum(0) - , mUnknown(0) { } }; // 16 bytes diff --git a/components/esm3/loadprob.cpp b/components/esm3/loadprob.cpp index 3f9ba95bf1..5e3086c7b9 100644 --- a/components/esm3/loadprob.cpp +++ b/components/esm3/loadprob.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mQuality, v.mUses); + } + void Probe::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("PBDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mQuality, mData.mUses); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -66,7 +74,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("PBDT", mData, 16); + esm.writeNamedComposite("PBDT", mData); esm.writeHNORefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadrepa.cpp b/components/esm3/loadrepa.cpp index c911cb1a23..886072ab56 100644 --- a/components/esm3/loadrepa.cpp +++ b/components/esm3/loadrepa.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mWeight, v.mValue, v.mUses, v.mQuality); + } + void Repair::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -28,7 +36,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("RIDT"): - esm.getHT(mData.mWeight, mData.mValue, mData.mUses, mData.mQuality); + esm.getSubComposite(mData); hasData = true; break; case fourCC("SCRI"): @@ -66,7 +74,7 @@ namespace ESM esm.writeHNCString("MODL", mModel); esm.writeHNOCString("FNAM", mName); - esm.writeHNT("RIDT", mData, 16); + esm.writeNamedComposite("RIDT", mData); esm.writeHNORefId("SCRI", mScript); esm.writeHNOCString("ITEX", mIcon); } diff --git a/components/esm3/loadskil.cpp b/components/esm3/loadskil.cpp index fd53726f90..28ea3eadba 100644 --- a/components/esm3/loadskil.cpp +++ b/components/esm3/loadskil.cpp @@ -3,6 +3,7 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include #include #include @@ -37,6 +38,12 @@ namespace ESM const SkillId Skill::Speechcraft("Speechcraft"); const SkillId Skill::HandToHand("HandToHand"); + template T> + void decompose(T&& v, const auto& f) + { + f(v.mAttribute, v.mSpecialization, v.mUseValue); + } + void Skill::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; // Skill record can't be deleted now (may be changed in the future) @@ -55,7 +62,7 @@ namespace ESM hasIndex = true; break; case fourCC("SKDT"): - esm.getHT(mData.mAttribute, mData.mSpecialization, mData.mUseValue); + esm.getSubComposite(mData); hasData = true; break; case fourCC("DESC"): @@ -78,7 +85,7 @@ namespace ESM void Skill::save(ESMWriter& esm, bool /*isDeleted*/) const { esm.writeHNT("INDX", refIdToIndex(mId)); - esm.writeHNT("SKDT", mData, 24); + esm.writeNamedComposite("SKDT", mData); esm.writeHNOString("DESC", mDescription); } diff --git a/components/esm3/loadsndg.cpp b/components/esm3/loadsndg.cpp index 4e2e2aa3f9..12a68b3afe 100644 --- a/components/esm3/loadsndg.cpp +++ b/components/esm3/loadsndg.cpp @@ -57,7 +57,7 @@ namespace ESM return; } - esm.writeHNT("DATA", mType, 4); + esm.writeHNT("DATA", mType); esm.writeHNOCRefId("CNAM", mCreature); esm.writeHNOCRefId("SNAM", mSound); } diff --git a/components/esm3/loadsoun.cpp b/components/esm3/loadsoun.cpp index fd403e3429..6f72a49a60 100644 --- a/components/esm3/loadsoun.cpp +++ b/components/esm3/loadsoun.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mVolume, v.mMinRange, v.mMaxRange); + } + void Sound::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -25,7 +33,7 @@ namespace ESM mSound = esm.getHString(); break; case fourCC("DATA"): - esm.getHT(mData.mVolume, mData.mMinRange, mData.mMaxRange); + esm.getSubComposite(mData); hasData = true; break; case SREC_DELE: @@ -55,7 +63,7 @@ namespace ESM } esm.writeHNOCString("FNAM", mSound); - esm.writeHNT("DATA", mData, 3); + esm.writeNamedComposite("DATA", mData); } void Sound::blank() diff --git a/components/esm3/loadspel.cpp b/components/esm3/loadspel.cpp index e4f63b8219..e40c03d007 100644 --- a/components/esm3/loadspel.cpp +++ b/components/esm3/loadspel.cpp @@ -3,8 +3,16 @@ #include "esmreader.hpp" #include "esmwriter.hpp" +#include + namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mType, v.mCost, v.mFlags); + } + void Spell::load(ESMReader& esm, bool& isDeleted) { isDeleted = false; @@ -27,7 +35,7 @@ namespace ESM mName = esm.getHString(); break; case fourCC("SPDT"): - esm.getHT(mData.mType, mData.mCost, mData.mFlags); + esm.getSubComposite(mData); hasData = true; break; case fourCC("ENAM"): @@ -60,7 +68,7 @@ namespace ESM } esm.writeHNOCString("FNAM", mName); - esm.writeHNT("SPDT", mData, 12); + esm.writeNamedComposite("SPDT", mData); mEffects.save(esm); } diff --git a/components/esm3/objectstate.cpp b/components/esm3/objectstate.cpp index f8905cfaea..f3017e2d0d 100644 --- a/components/esm3/objectstate.cpp +++ b/components/esm3/objectstate.cpp @@ -37,7 +37,7 @@ namespace ESM } mPosition = mRef.mPos; - esm.getHNOT("POS_", mPosition.pos, mPosition.rot); + esm.getOptionalComposite("POS_", mPosition); mFlags = 0; esm.getHNOT(mFlags, "FLAG"); @@ -66,10 +66,7 @@ namespace ESM if (!inInventory && mPosition != mRef.mPos) { - std::array pos; - memcpy(pos.data(), mPosition.pos, sizeof(float) * 3); - memcpy(pos.data() + 3, mPosition.rot, sizeof(float) * 3); - esm.writeHNT("POS_", pos, 24); + esm.writeNamedComposite("POS_", mPosition); } if (mFlags != 0) diff --git a/components/esm3/objectstate.hpp b/components/esm3/objectstate.hpp index b3f7bd3d45..c947adcd97 100644 --- a/components/esm3/objectstate.hpp +++ b/components/esm3/objectstate.hpp @@ -4,8 +4,9 @@ #include #include -#include "components/esm/luascripts.hpp" -#include "components/esm3/formatversion.hpp" +#include +#include +#include #include "animationstate.hpp" #include "cellref.hpp" diff --git a/components/esm3/player.cpp b/components/esm3/player.cpp index fd280bf12e..bf5864ce4c 100644 --- a/components/esm3/player.cpp +++ b/components/esm3/player.cpp @@ -15,7 +15,7 @@ namespace ESM esm.getHNT("LKEP", mLastKnownExteriorPosition); - mHasMark = esm.getHNOT("MARK", mMarkedPosition.pos, mMarkedPosition.rot); + mHasMark = esm.getOptionalComposite("MARK", mMarkedPosition); if (mHasMark) mMarkedCell = esm.getCellId(); @@ -90,7 +90,7 @@ namespace ESM if (mHasMark) { - esm.writeHNT("MARK", mMarkedPosition, 24); + esm.writeNamedComposite("MARK", mMarkedPosition); esm.writeCellId(mMarkedCell); } diff --git a/components/esm3/player.hpp b/components/esm3/player.hpp index 0f76a3b5eb..0cc0c22dc3 100644 --- a/components/esm3/player.hpp +++ b/components/esm3/player.hpp @@ -3,11 +3,11 @@ #include -#include "components/esm/defs.hpp" -#include "npcstate.hpp" +#include +#include -#include "components/esm/attr.hpp" #include "loadskil.hpp" +#include "npcstate.hpp" namespace ESM { diff --git a/components/esm3/savedgame.cpp b/components/esm3/savedgame.cpp index 0dc1fb0653..212925b61d 100644 --- a/components/esm3/savedgame.cpp +++ b/components/esm3/savedgame.cpp @@ -3,10 +3,17 @@ #include "esmreader.hpp" #include "esmwriter.hpp" -#include "../misc/algorithm.hpp" +#include +#include namespace ESM { + template T> + void decompose(T&& v, const auto& f) + { + f(v.mGameHour, v.mDay, v.mMonth, v.mYear); + } + void SavedGame::load(ESMReader& esm) { mPlayerName = esm.getHNString("PLNA"); @@ -19,7 +26,7 @@ namespace ESM mPlayerCellName = esm.getHNRefId("PLCE").toString(); else mPlayerCellName = esm.getHNString("PLCE"); - esm.getHNT("TSTM", mInGameTime.mGameHour, mInGameTime.mDay, mInGameTime.mMonth, mInGameTime.mYear); + esm.getNamedComposite("TSTM", mInGameTime); esm.getHNT(mTimePlayed, "TIME"); mDescription = esm.getHNString("DESC"); @@ -47,12 +54,12 @@ namespace ESM esm.writeHNString("PLCN", mPlayerClassName); esm.writeHNString("PLCE", mPlayerCellName); - esm.writeHNT("TSTM", mInGameTime, 16); + esm.writeNamedComposite("TSTM", mInGameTime); esm.writeHNT("TIME", mTimePlayed); esm.writeHNString("DESC", mDescription); - for (std::vector::const_iterator iter(mContentFiles.begin()); iter != mContentFiles.end(); ++iter) - esm.writeHNString("DEPE", *iter); + for (const std::string& dependency : mContentFiles) + esm.writeHNString("DEPE", dependency); esm.startSubRecord("SCRN"); esm.write(mScreenshot.data(), mScreenshot.size()); diff --git a/components/esm3/transport.cpp b/components/esm3/transport.cpp index 8b131b1b5f..a72cdbbaf8 100644 --- a/components/esm3/transport.cpp +++ b/components/esm3/transport.cpp @@ -13,7 +13,7 @@ namespace ESM if (esm.retSubName().toInt() == fourCC("DODT")) { Dest dodt; - esm.getHExact(&dodt.mPos, 24); + esm.getSubComposite(dodt.mPos); mList.push_back(dodt); } else if (esm.retSubName().toInt() == fourCC("DNAM")) @@ -28,11 +28,10 @@ namespace ESM void Transport::save(ESMWriter& esm) const { - typedef std::vector::const_iterator DestIter; - for (DestIter it = mList.begin(); it != mList.end(); ++it) + for (const Dest& dest : mList) { - esm.writeHNT("DODT", it->mPos, sizeof(it->mPos)); - esm.writeHNOCString("DNAM", it->mCellName); + esm.writeNamedComposite("DODT", dest.mPos); + esm.writeHNOCString("DNAM", dest.mCellName); } } diff --git a/components/esm3/transport.hpp b/components/esm3/transport.hpp index 555504c994..69bc1119c2 100644 --- a/components/esm3/transport.hpp +++ b/components/esm3/transport.hpp @@ -4,7 +4,7 @@ #include #include -#include "components/esm/defs.hpp" +#include namespace ESM { diff --git a/components/esm4/loadachr.hpp b/components/esm4/loadachr.hpp index 8abb47c8bc..526ab4c057 100644 --- a/components/esm4/loadachr.hpp +++ b/components/esm4/loadachr.hpp @@ -30,6 +30,7 @@ #include #include +#include #include #include "reference.hpp" // Placement, EnableParent diff --git a/components/esm4/loadrefr.hpp b/components/esm4/loadrefr.hpp index ec76928827..99826200c9 100644 --- a/components/esm4/loadrefr.hpp +++ b/components/esm4/loadrefr.hpp @@ -32,6 +32,7 @@ #include "reference.hpp" // EnableParent #include +#include #include namespace ESM4 diff --git a/components/esm4/reference.hpp b/components/esm4/reference.hpp index 9d6efdfd82..33e8fa82f3 100644 --- a/components/esm4/reference.hpp +++ b/components/esm4/reference.hpp @@ -30,8 +30,8 @@ #include #include -#include #include +#include namespace ESM4 { diff --git a/components/misc/convert.hpp b/components/misc/convert.hpp index a66fac9125..5d936b5d5f 100644 --- a/components/misc/convert.hpp +++ b/components/misc/convert.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_COMPONENTS_MISC_CONVERT_H #define OPENMW_COMPONENTS_MISC_CONVERT_H -#include +#include #include #include diff --git a/components/resource/foreachbulletobject.hpp b/components/resource/foreachbulletobject.hpp index fe39a8ed8c..d7e99cf0b5 100644 --- a/components/resource/foreachbulletobject.hpp +++ b/components/resource/foreachbulletobject.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_COMPONENTS_RESOURCE_FOREACHBULLETOBJECT_H #define OPENMW_COMPONENTS_RESOURCE_FOREACHBULLETOBJECT_H -#include +#include #include #include