1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 01:45:38 +00:00

Replace fixed size writeHNT calls with decomposition

This commit is contained in:
Evil Eye 2024-02-27 20:47:46 +01:00
parent 828bf3d11a
commit cef59e8928
49 changed files with 339 additions and 144 deletions

View file

@ -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++;
}

View file

@ -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();

View file

@ -8,7 +8,7 @@
#include <osg/Vec4f>
#include <osg/ref_ptr>
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>
#include "tagbase.hpp"

View file

@ -8,7 +8,7 @@
#include <components/detournavigator/areatype.hpp>
#include <components/detournavigator/flags.hpp>
#include <components/detournavigator/status.hpp>
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm3/loadpgrd.hpp>
namespace MWWorld

View file

@ -1,7 +1,7 @@
#ifndef GAME_MWWORLD_REFDATA_H
#define GAME_MWWORLD_REFDATA_H
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/animationstate.hpp>

View file

@ -1,7 +1,7 @@
#ifndef OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTTRANSFORM_H
#define OPENMW_COMPONENTS_DETOURNAVIGATOR_OBJECTTRANSFORM_H
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <tuple>

View file

@ -4,12 +4,8 @@
#include <stdexcept>
#include <stdint.h>
#include <tuple>
#include <osg/Vec3f>
#include "components/esm/fourcc.hpp"
#include <components/esm/esmcommon.hpp>
#include <components/esm/fourcc.hpp>
#include <components/esm4/common.hpp>
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])

View file

@ -0,0 +1,47 @@
#ifndef OPENMW_ESM3_POSITION_H
#define OPENMW_ESM3_POSITION_H
#include <components/misc/concepts.hpp>
#include <osg/Vec3f>
#include <tuple>
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 <Misc::SameAsWithoutCvref<Position> T>
void decompose(T&& v, const auto& f)
{
f(v.pos, v.rot);
}
}
#endif

View file

@ -3,9 +3,15 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/algorithm.hpp>
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<CellId::CellIndex> 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

View file

@ -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()

View file

@ -4,8 +4,9 @@
#include <cstdint>
#include <string>
#include "components/esm/defs.hpp"
#include "components/esm/refid.hpp"
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>
namespace ESM
{

View file

@ -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), ...); });

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Potion::ALDTstruct> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Apparatus::AADTstruct> 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);
}

View file

@ -3,8 +3,15 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Armor::AODTstruct> 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);

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<BodyPart::BYDTstruct> 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()

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Book::BKDTstruct> 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);

View file

@ -5,6 +5,7 @@
#include <string>
#include <components/debug/debuglog.hpp>
#include <components/misc/concepts.hpp>
#include <components/misc/strings/algorithm.hpp>
#include "esmreader.hpp"
@ -41,6 +42,18 @@ namespace ESM
{
const StringRefId Cell::sDefaultWorldspaceId = StringRefId("sys::default");
template <Misc::SameAsWithoutCvref<Cell::DATAstruct> T>
void decompose(T&& v, const auto& f)
{
f(v.mFlags, v.mX, v.mY);
}
template <Misc::SameAsWithoutCvref<Cell::AMBIstruct> 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
{

View file

@ -2,7 +2,9 @@
#include <stdexcept>
#include "components/esm/defs.hpp"
#include <components/esm/defs.hpp>
#include <components/misc/concepts.hpp>
#include "esmreader.hpp"
#include "esmwriter.hpp"
@ -12,6 +14,12 @@ namespace ESM
= { "sSpecializationCombat", "sSpecializationMagic", "sSpecializationStealth" };
const std::array<std::string_view, 3> Class::specializationIndexToLuaId = { "combat", "magic", "stealth" };
template <Misc::SameAsWithoutCvref<Class::CLDTstruct> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Clothing::CTDTstruct> 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);

View file

@ -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);

View file

@ -1,12 +1,19 @@
#include "loadcrea.hpp"
#include <components/debug/debuglog.hpp>
#include <components/misc/concepts.hpp>
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
template <Misc::SameAsWithoutCvref<Creature::NPDTstruct> 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)
{

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Enchantment::ENDTstruct> 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);
}

View file

@ -3,8 +3,17 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<DialInfo::DATAstruct> 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);

View file

@ -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;

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Ingredient::IRDTstruct> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Light::LHDTstruct> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Lockpick::Data> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Miscellaneous::MCDTstruct> 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);
}

View file

@ -3,8 +3,23 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Pathgrid::DATAstruct> T>
void decompose(T&& v, const auto& f)
{
f(v.mX, v.mY, v.mGranularity, v.mPoints);
}
template <Misc::SameAsWithoutCvref<Pathgrid::Point> 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<int32_t>(rhs[0]);
@ -12,7 +27,6 @@ namespace ESM
mZ = static_cast<int32_t>(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<int32_t>(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");
}

View file

@ -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

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Probe::Data> 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);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Repair::Data> 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);
}

View file

@ -3,6 +3,7 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
#include <components/misc/strings/algorithm.hpp>
#include <cstdint>
@ -37,6 +38,12 @@ namespace ESM
const SkillId Skill::Speechcraft("Speechcraft");
const SkillId Skill::HandToHand("HandToHand");
template <Misc::SameAsWithoutCvref<Skill::SKDTstruct> 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);
}

View file

@ -57,7 +57,7 @@ namespace ESM
return;
}
esm.writeHNT("DATA", mType, 4);
esm.writeHNT("DATA", mType);
esm.writeHNOCRefId("CNAM", mCreature);
esm.writeHNOCRefId("SNAM", mSound);
}

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<SOUNstruct> 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()

View file

@ -3,8 +3,16 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<Spell::SPDTstruct> 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);
}

View file

@ -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<float, 6> 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)

View file

@ -4,8 +4,9 @@
#include <string>
#include <vector>
#include "components/esm/luascripts.hpp"
#include "components/esm3/formatversion.hpp"
#include <components/esm/luascripts.hpp>
#include <components/esm/position.hpp>
#include <components/esm3/formatversion.hpp>
#include "animationstate.hpp"
#include "cellref.hpp"

View file

@ -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);
}

View file

@ -3,11 +3,11 @@
#include <string>
#include "components/esm/defs.hpp"
#include "npcstate.hpp"
#include <components/esm/attr.hpp>
#include <components/esm/position.hpp>
#include "components/esm/attr.hpp"
#include "loadskil.hpp"
#include "npcstate.hpp"
namespace ESM
{

View file

@ -3,10 +3,17 @@
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "../misc/algorithm.hpp"
#include <components/misc/algorithm.hpp>
#include <components/misc/concepts.hpp>
namespace ESM
{
template <Misc::SameAsWithoutCvref<EpochTimeStamp> 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<std::string>::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());

View file

@ -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<Dest>::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);
}
}

View file

@ -4,7 +4,7 @@
#include <string>
#include <vector>
#include "components/esm/defs.hpp"
#include <components/esm/position.hpp>
namespace ESM
{

View file

@ -30,6 +30,7 @@
#include <cstdint>
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>
#include "reference.hpp" // Placement, EnableParent

View file

@ -32,6 +32,7 @@
#include "reference.hpp" // EnableParent
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>
namespace ESM4

View file

@ -30,8 +30,8 @@
#include <cstdint>
#include <string>
#include <components/esm/defs.hpp>
#include <components/esm/formid.hpp>
#include <components/esm/position.hpp>
namespace ESM4
{

View file

@ -1,7 +1,7 @@
#ifndef OPENMW_COMPONENTS_MISC_CONVERT_H
#define OPENMW_COMPONENTS_MISC_CONVERT_H
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/esm3/loadpgrd.hpp>
#include <LinearMath/btQuaternion.h>

View file

@ -1,7 +1,7 @@
#ifndef OPENMW_COMPONENTS_RESOURCE_FOREACHBULLETOBJECT_H
#define OPENMW_COMPONENTS_RESOURCE_FOREACHBULLETOBJECT_H
#include <components/esm/defs.hpp>
#include <components/esm/position.hpp>
#include <components/resource/bulletshape.hpp>
#include <osg/ref_ptr>