Skip to content

Commit

Permalink
Merge branch 'ducksinarow' into 'master'
Browse files Browse the repository at this point in the history
Improve memory alignment of CreatureStats to reduce memory usage

See merge request OpenMW/openmw!4433
  • Loading branch information
psi29a committed Nov 1, 2024
2 parents 362eec4 + ee16dbd commit 6c52d92
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 55 deletions.
25 changes: 0 additions & 25 deletions apps/openmw/mwmechanics/creaturestats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,6 @@ namespace MWMechanics
int CreatureStats::sActorId = 0;

CreatureStats::CreatureStats()
: mDrawState(DrawState::Nothing)
, mDead(false)
, mDeathAnimationFinished(false)
, mDied(false)
, mMurdered(false)
, mFriendlyHits(0)
, mTalkedTo(false)
, mAlarmed(false)
, mAttacked(false)
, mKnockdown(false)
, mKnockdownOneFrame(false)
, mKnockdownOverOneFrame(false)
, mHitRecovery(false)
, mBlock(false)
, mMovementFlags(0)
, mFallHeight(0)
, mLastRestock(0, 0)
, mGoldPool(0)
, mActorId(-1)
, mHitAttemptActorId(-1)
, mDeathAnimation(-1)
, mTimeOfDeath()
, mSideMovementAngle(0)
, mLevel(0)
, mAttackingOrSpell(false)
{
for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
{
Expand Down
62 changes: 32 additions & 30 deletions apps/openmw/mwmechanics/creaturestats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,30 @@ namespace MWMechanics
class CreatureStats
{
static int sActorId;
DrawState mDrawState;
std::map<ESM::RefId, AttributeValue> mAttributes;
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
DrawState mDrawState = DrawState::Nothing;
Spells mSpells;
ActiveSpells mActiveSpells;
MagicEffects mMagicEffects;
Stat<int> mAiSettings[4];
AiSequence mAiSequence;
bool mDead;
bool mDeathAnimationFinished;
bool mDied; // flag for OnDeath script function
bool mMurdered;
int mFriendlyHits;
bool mTalkedTo;
bool mAlarmed;
bool mAttacked;
bool mKnockdown;
bool mKnockdownOneFrame;
bool mKnockdownOverOneFrame;
bool mHitRecovery;
bool mBlock;
unsigned int mMovementFlags;

float mFallHeight;
bool mDead = false;
bool mDeathAnimationFinished = false;
bool mDied = false; // flag for OnDeath script function
bool mMurdered = false;
int mFriendlyHits = 0;
bool mTalkedTo = false;
bool mAlarmed = false;
bool mAttacked = false;
bool mKnockdown = false;
bool mKnockdownOneFrame = false;
bool mKnockdownOverOneFrame = false;
bool mHitRecovery = false;
bool mBlock = false;
unsigned int mMovementFlags = 0;

float mFallHeight = 0.f;

ESM::RefId mLastHitObject; // The last object to hit this actor
ESM::RefId mLastHitAttemptObject; // The last object to attempt to hit this actor
Expand All @@ -71,21 +71,17 @@ namespace MWMechanics
MWWorld::TimeStamp mLastRestock;

// The pool of merchant gold (not in inventory)
int mGoldPool;
int mGoldPool = 0;

int mActorId;
int mHitAttemptActorId; // Stores an actor that attacked this actor. Only one is stored at a time,
// and it is not changed if a different actor attacks. It is cleared when combat ends.

// The index of the death animation that was played, or -1 if none played
signed char mDeathAnimation;

MWWorld::TimeStamp mTimeOfDeath;
int mActorId = -1;
// Stores an actor that attacked this actor. Only one is stored at a time, and it is not changed if a different
// actor attacks. It is cleared when combat ends.
int mHitAttemptActorId = -1;

// The difference between view direction and lower body direction.
float mSideMovementAngle;
float mSideMovementAngle = 0;

bool mTeleported = false;
MWWorld::TimeStamp mTimeOfDeath;

private:
std::multimap<int, int> mSummonedCreatures; // <Effect, ActorId>
Expand All @@ -95,9 +91,15 @@ namespace MWMechanics
std::vector<int> mSummonGraveyard;

protected:
int mLevel;
bool mAttackingOrSpell;
std::string mAttackType;
int mLevel = 0;
bool mAttackingOrSpell = false;

private:
// The index of the death animation that was played, or -1 if none played
signed char mDeathAnimation = -1;

bool mTeleported = false;

public:
CreatureStats();
Expand Down

0 comments on commit 6c52d92

Please sign in to comment.