Skip to content

Commit 6c52d92

Browse files
committed
Merge branch 'ducksinarow' into 'master'
Improve memory alignment of CreatureStats to reduce memory usage See merge request OpenMW/openmw!4433
2 parents 362eec4 + ee16dbd commit 6c52d92

File tree

2 files changed

+32
-55
lines changed

2 files changed

+32
-55
lines changed

apps/openmw/mwmechanics/creaturestats.cpp

-25
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@ namespace MWMechanics
2020
int CreatureStats::sActorId = 0;
2121

2222
CreatureStats::CreatureStats()
23-
: mDrawState(DrawState::Nothing)
24-
, mDead(false)
25-
, mDeathAnimationFinished(false)
26-
, mDied(false)
27-
, mMurdered(false)
28-
, mFriendlyHits(0)
29-
, mTalkedTo(false)
30-
, mAlarmed(false)
31-
, mAttacked(false)
32-
, mKnockdown(false)
33-
, mKnockdownOneFrame(false)
34-
, mKnockdownOverOneFrame(false)
35-
, mHitRecovery(false)
36-
, mBlock(false)
37-
, mMovementFlags(0)
38-
, mFallHeight(0)
39-
, mLastRestock(0, 0)
40-
, mGoldPool(0)
41-
, mActorId(-1)
42-
, mHitAttemptActorId(-1)
43-
, mDeathAnimation(-1)
44-
, mTimeOfDeath()
45-
, mSideMovementAngle(0)
46-
, mLevel(0)
47-
, mAttackingOrSpell(false)
4823
{
4924
for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
5025
{

apps/openmw/mwmechanics/creaturestats.hpp

+32-30
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,30 @@ namespace MWMechanics
3939
class CreatureStats
4040
{
4141
static int sActorId;
42-
DrawState mDrawState;
4342
std::map<ESM::RefId, AttributeValue> mAttributes;
4443
DynamicStat<float> mDynamic[3]; // health, magicka, fatigue
44+
DrawState mDrawState = DrawState::Nothing;
4545
Spells mSpells;
4646
ActiveSpells mActiveSpells;
4747
MagicEffects mMagicEffects;
4848
Stat<int> mAiSettings[4];
4949
AiSequence mAiSequence;
50-
bool mDead;
51-
bool mDeathAnimationFinished;
52-
bool mDied; // flag for OnDeath script function
53-
bool mMurdered;
54-
int mFriendlyHits;
55-
bool mTalkedTo;
56-
bool mAlarmed;
57-
bool mAttacked;
58-
bool mKnockdown;
59-
bool mKnockdownOneFrame;
60-
bool mKnockdownOverOneFrame;
61-
bool mHitRecovery;
62-
bool mBlock;
63-
unsigned int mMovementFlags;
64-
65-
float mFallHeight;
50+
bool mDead = false;
51+
bool mDeathAnimationFinished = false;
52+
bool mDied = false; // flag for OnDeath script function
53+
bool mMurdered = false;
54+
int mFriendlyHits = 0;
55+
bool mTalkedTo = false;
56+
bool mAlarmed = false;
57+
bool mAttacked = false;
58+
bool mKnockdown = false;
59+
bool mKnockdownOneFrame = false;
60+
bool mKnockdownOverOneFrame = false;
61+
bool mHitRecovery = false;
62+
bool mBlock = false;
63+
unsigned int mMovementFlags = 0;
64+
65+
float mFallHeight = 0.f;
6666

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

7373
// The pool of merchant gold (not in inventory)
74-
int mGoldPool;
74+
int mGoldPool = 0;
7575

76-
int mActorId;
77-
int mHitAttemptActorId; // Stores an actor that attacked this actor. Only one is stored at a time,
78-
// and it is not changed if a different actor attacks. It is cleared when combat ends.
79-
80-
// The index of the death animation that was played, or -1 if none played
81-
signed char mDeathAnimation;
82-
83-
MWWorld::TimeStamp mTimeOfDeath;
76+
int mActorId = -1;
77+
// Stores an actor that attacked this actor. Only one is stored at a time, and it is not changed if a different
78+
// actor attacks. It is cleared when combat ends.
79+
int mHitAttemptActorId = -1;
8480

8581
// The difference between view direction and lower body direction.
86-
float mSideMovementAngle;
82+
float mSideMovementAngle = 0;
8783

88-
bool mTeleported = false;
84+
MWWorld::TimeStamp mTimeOfDeath;
8985

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

9793
protected:
98-
int mLevel;
99-
bool mAttackingOrSpell;
10094
std::string mAttackType;
95+
int mLevel = 0;
96+
bool mAttackingOrSpell = false;
97+
98+
private:
99+
// The index of the death animation that was played, or -1 if none played
100+
signed char mDeathAnimation = -1;
101+
102+
bool mTeleported = false;
101103

102104
public:
103105
CreatureStats();

0 commit comments

Comments
 (0)