Move TimeStamp to ESM3 and remove sized reads

macos_ci_fix
Evil Eye 1 year ago
parent d2f16774d9
commit 79b3855c5b

@ -4,7 +4,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <components/esm/defs.hpp> #include <components/esm3/timestamp.hpp>
#include "duration.hpp" #include "duration.hpp"

@ -142,7 +142,7 @@ add_component_dir (esm3
inventorystate containerstate npcstate creaturestate dialoguestate statstate npcstats creaturestats inventorystate containerstate npcstate creaturestate dialoguestate statstate npcstats creaturestats
weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile weatherstate quickkeys fogstate spellstate activespells creaturelevliststate doorstate projectilestate debugprofile
aisequence magiceffects custommarkerstate stolenitems transport animationstate controlsstate mappings readerscache aisequence magiceffects custommarkerstate stolenitems transport animationstate controlsstate mappings readerscache
infoorder infoorder timestamp
) )
add_component_dir (esm3terrain add_component_dir (esm3terrain

@ -15,12 +15,6 @@
namespace ESM namespace ESM
{ {
struct TimeStamp
{
float mHour;
int mDay;
};
struct EpochTimeStamp struct EpochTimeStamp
{ {
float mGameHour; float mGameHour;

@ -68,7 +68,7 @@ namespace ESM
if (esm.isNextSub("WORS")) if (esm.isNextSub("WORS"))
{ {
esm.getHT(params.mWorsenings); esm.getHT(params.mWorsenings);
esm.getHNTSized<8>(params.mNextWorsening, "TIME"); params.mNextWorsening.load(esm);
} }
else else
params.mWorsenings = -1; params.mWorsenings = -1;

@ -4,6 +4,7 @@
#include "cellref.hpp" #include "cellref.hpp"
#include "components/esm/defs.hpp" #include "components/esm/defs.hpp"
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include "timestamp.hpp"
#include <string> #include <string>
#include <vector> #include <vector>
@ -27,15 +28,15 @@ namespace ESM
Flag_Ignore_SpellAbsorption = 1 << 4 Flag_Ignore_SpellAbsorption = 1 << 4
}; };
int mEffectId; int32_t mEffectId;
float mMagnitude; float mMagnitude;
float mMinMagnitude; float mMinMagnitude;
float mMaxMagnitude; float mMaxMagnitude;
int mArg; // skill or attribute int32_t mArg; // skill or attribute
float mDuration; float mDuration;
float mTimeLeft; float mTimeLeft;
int mEffectIndex; int32_t mEffectIndex;
int mFlags; int32_t mFlags;
}; };
// format 0, saved games only // format 0, saved games only
@ -55,10 +56,10 @@ namespace ESM
RefId mId; RefId mId;
std::vector<ActiveEffect> mEffects; std::vector<ActiveEffect> mEffects;
std::string mDisplayName; std::string mDisplayName;
int mCasterActorId; int32_t mCasterActorId;
RefNum mItem; RefNum mItem;
EffectType mType; EffectType mType;
int mWorsenings; int32_t mWorsenings;
TimeStamp mNextWorsening; TimeStamp mNextWorsening;
}; };

@ -16,7 +16,8 @@ namespace ESM
mLastRespawn.mDay = 0; mLastRespawn.mDay = 0;
mLastRespawn.mHour = 0; mLastRespawn.mHour = 0;
esm.getHNOTSized<8>(mLastRespawn, "RESP"); if (esm.peekNextSub("RESP"))
mLastRespawn.load(esm, "RESP");
} }
void CellState::save(ESMWriter& esm) const void CellState::save(ESMWriter& esm) const

@ -3,6 +3,7 @@
#include "components/esm/defs.hpp" #include "components/esm/defs.hpp"
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include "timestamp.hpp"
namespace ESM namespace ESM
{ {
@ -18,7 +19,7 @@ namespace ESM
bool mIsInterior; bool mIsInterior;
float mWaterLevel; float mWaterLevel;
int mHasFogOfWar; // Do we have fog of war state (0 or 1)? (see fogstate.hpp) int32_t mHasFogOfWar; // Do we have fog of war state (0 or 1)? (see fogstate.hpp)
TimeStamp mLastRespawn; TimeStamp mLastRespawn;

@ -21,9 +21,10 @@ namespace ESM
mTradeTime.mDay = 0; mTradeTime.mDay = 0;
mTradeTime.mHour = 0; mTradeTime.mHour = 0;
esm.getHNOTSized<8>(mTradeTime, "TIME"); if (esm.peekNextSub("TIME"))
mTradeTime.load(esm);
int flags = 0; int32_t flags = 0;
mDead = false; mDead = false;
mDeathAnimationFinished = false; mDeathAnimationFinished = false;
mDied = false; mDied = false;
@ -108,7 +109,8 @@ namespace ESM
mTimeOfDeath.mDay = 0; mTimeOfDeath.mDay = 0;
mTimeOfDeath.mHour = 0; mTimeOfDeath.mHour = 0;
esm.getHNOTSized<8>(mTimeOfDeath, "DTIM"); if (esm.peekNextSub("DTIM"))
mTimeOfDeath.load(esm, "DTIM");
mSpells.load(esm); mSpells.load(esm);
mActiveSpells.load(esm); mActiveSpells.load(esm);
@ -119,12 +121,12 @@ namespace ESM
{ {
while (esm.isNextSub("SUMM")) while (esm.isNextSub("SUMM"))
{ {
int magicEffect; int32_t magicEffect;
esm.getHT(magicEffect); esm.getHT(magicEffect);
ESM::RefId source = esm.getHNORefId("SOUR"); ESM::RefId source = esm.getHNORefId("SOUR");
int effectIndex = -1; int32_t effectIndex = -1;
esm.getHNOT(effectIndex, "EIND"); esm.getHNOT(effectIndex, "EIND");
int actorId; int32_t actorId;
esm.getHNT(actorId, "ACID"); esm.getHNT(actorId, "ACID");
mSummonedCreatureMap[SummonKey(magicEffect, source, effectIndex)] = actorId; mSummonedCreatureMap[SummonKey(magicEffect, source, effectIndex)] = actorId;
mSummonedCreatures.emplace(magicEffect, actorId); mSummonedCreatures.emplace(magicEffect, actorId);
@ -134,9 +136,9 @@ namespace ESM
{ {
while (esm.isNextSub("SUMM")) while (esm.isNextSub("SUMM"))
{ {
int magicEffect; int32_t magicEffect;
esm.getHT(magicEffect); esm.getHT(magicEffect);
int actorId; int32_t actorId;
esm.getHNT(actorId, "ACID"); esm.getHNT(actorId, "ACID");
mSummonedCreatures.emplace(magicEffect, actorId); mSummonedCreatures.emplace(magicEffect, actorId);
} }
@ -144,7 +146,7 @@ namespace ESM
while (esm.isNextSub("GRAV")) while (esm.isNextSub("GRAV"))
{ {
int actorId; int32_t actorId;
esm.getHT(actorId); esm.getHT(actorId);
mSummonGraveyard.push_back(actorId); mSummonGraveyard.push_back(actorId);
} }
@ -164,7 +166,7 @@ namespace ESM
CorprusStats stats; CorprusStats stats;
esm.getHNT(stats.mWorsenings, "WORS"); esm.getHNT(stats.mWorsenings, "WORS");
esm.getHNTSized<8>(stats.mNextWorsening, "TIME"); stats.mNextWorsening.load(esm);
mCorprusSpells[id] = stats; mCorprusSpells[id] = stats;
} }
@ -191,7 +193,7 @@ namespace ESM
if (mTradeTime.mDay != 0 || mTradeTime.mHour != 0) if (mTradeTime.mDay != 0 || mTradeTime.mHour != 0)
esm.writeHNT("TIME", mTradeTime); esm.writeHNT("TIME", mTradeTime);
int flags = 0; int32_t flags = 0;
if (mDead) if (mDead)
flags |= Dead; flags |= Dead;
if (mDeathAnimationFinished) if (mDeathAnimationFinished)
@ -260,7 +262,7 @@ namespace ESM
esm.writeHNT("ACID", actorId); esm.writeHNT("ACID", actorId);
} }
for (int key : mSummonGraveyard) for (int32_t key : mSummonGraveyard)
{ {
esm.writeHNT("GRAV", key); esm.writeHNT("GRAV", key);
} }

@ -16,6 +16,7 @@
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include "magiceffects.hpp" #include "magiceffects.hpp"
#include "spellstate.hpp" #include "spellstate.hpp"
#include "timestamp.hpp"
namespace ESM namespace ESM
{ {
@ -27,7 +28,7 @@ namespace ESM
{ {
struct CorprusStats struct CorprusStats
{ {
std::array<int, Attribute::Length> mWorsenings; std::array<int32_t, Attribute::Length> mWorsenings;
TimeStamp mNextWorsening; TimeStamp mNextWorsening;
}; };
@ -78,15 +79,15 @@ namespace ESM
bool mKnockdownOverOneFrame; bool mKnockdownOverOneFrame;
bool mHitRecovery; bool mHitRecovery;
bool mBlock; bool mBlock;
unsigned int mMovementFlags; uint32_t mMovementFlags;
float mFallHeight; float mFallHeight;
ESM::RefId mLastHitObject; ESM::RefId mLastHitObject;
ESM::RefId mLastHitAttemptObject; ESM::RefId mLastHitAttemptObject;
bool mRecalcDynamicStats; bool mRecalcDynamicStats;
int mDrawState; int32_t mDrawState;
signed char mDeathAnimation; int8_t mDeathAnimation;
TimeStamp mTimeOfDeath; TimeStamp mTimeOfDeath;
int mLevel; int32_t mLevel;
bool mMissingACDT; bool mMissingACDT;
std::map<ESM::RefId, CorprusStats> mCorprusSpells; std::map<ESM::RefId, CorprusStats> mCorprusSpells;

@ -128,6 +128,17 @@ namespace ESM
getHNTSized<sizeof(X)>(x, name); getHNTSized<sizeof(X)>(x, name);
} }
template <class... Args>
void getHNT(NAME name, Args&... args)
{
constexpr size_t size = (0 + ... + sizeof(Args));
getSubNameIs(name);
getSubHeader();
if (mCtx.leftSub != size)
reportSubSizeMismatch(size, mCtx.leftSub);
(getT(args), ...);
}
// Optional version of getHNT // Optional version of getHNT
template <typename X, typename = std::enable_if_t<IsReadable<X>>> template <typename X, typename = std::enable_if_t<IsReadable<X>>>
void getHNOT(X& x, NAME name) void getHNOT(X& x, NAME name)

@ -17,7 +17,7 @@ namespace ESM
SpellParams state; SpellParams state;
while (esm.isNextSub("INDX")) while (esm.isNextSub("INDX"))
{ {
int index; int32_t index;
esm.getHT(index); esm.getHT(index);
float magnitude; float magnitude;
@ -28,7 +28,7 @@ namespace ESM
while (esm.isNextSub("PURG")) while (esm.isNextSub("PURG"))
{ {
int index; int32_t index;
esm.getHT(index); esm.getHT(index);
state.mPurgedEffects.insert(index); state.mPurgedEffects.insert(index);
} }
@ -79,7 +79,7 @@ namespace ESM
CorprusStats stats; CorprusStats stats;
esm.getHNT(stats.mWorsenings, "WORS"); esm.getHNT(stats.mWorsenings, "WORS");
esm.getHNTSized<8>(stats.mNextWorsening, "TIME"); stats.mNextWorsening.load(esm);
mCorprusSpells[id] = stats; mCorprusSpells[id] = stats;
} }
@ -87,10 +87,7 @@ namespace ESM
while (esm.isNextSub("USED")) while (esm.isNextSub("USED"))
{ {
ESM::RefId id = esm.getRefId(); ESM::RefId id = esm.getRefId();
TimeStamp time; mUsedPowers[id].load(esm);
esm.getHNTSized<8>(time, "TIME");
mUsedPowers[id] = time;
} }
mSelectedSpell = esm.getHNORefId("SLCT"); mSelectedSpell = esm.getHNORefId("SLCT");

@ -8,6 +8,7 @@
#include "components/esm/defs.hpp" #include "components/esm/defs.hpp"
#include "components/esm/refid.hpp" #include "components/esm/refid.hpp"
#include "timestamp.hpp"
namespace ESM namespace ESM
{ {
@ -20,21 +21,21 @@ namespace ESM
{ {
struct CorprusStats struct CorprusStats
{ {
int mWorsenings; int32_t mWorsenings;
TimeStamp mNextWorsening; TimeStamp mNextWorsening;
}; };
struct PermanentSpellEffectInfo struct PermanentSpellEffectInfo
{ {
int mId; int32_t mId;
int mArg; int32_t mArg;
float mMagnitude; float mMagnitude;
}; };
struct SpellParams struct SpellParams
{ {
std::map<int, float> mEffectRands; // <effect index, normalised random magnitude> std::map<int32_t, float> mEffectRands; // <effect index, normalised random magnitude>
std::set<int> mPurgedEffects; // indices of purged effects std::set<int32_t> mPurgedEffects; // indices of purged effects
}; };
std::vector<ESM::RefId> mSpells; std::vector<ESM::RefId> mSpells;

@ -0,0 +1,11 @@
#include "timestamp.hpp"
#include "esmreader.hpp"
namespace ESM
{
void TimeStamp::load(ESMReader& esm, NAME name)
{
esm.getHNT(name, mHour, mDay);
}
}

@ -0,0 +1,21 @@
#ifndef OPENMW_COMPONENTS_ESM3_TIMESTAMP_H
#define OPENMW_COMPONENTS_ESM3_TIMESTAMP_H
#include <cstdint>
#include <components/esm/esmcommon.hpp>
namespace ESM
{
class ESMReader;
struct TimeStamp
{
float mHour;
int32_t mDay;
void load(ESMReader& esm, NAME name = "TIME");
};
}
#endif
Loading…
Cancel
Save