From 7ad0ec925fcb16b5900808073f23b770c65b2ca6 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 15 Jul 2022 12:22:02 +0100 Subject: [PATCH] Reduce sizes of Monster (goal)Vars sizeof(Monster): 168 -> 144 --- Source/loadsave.cpp | 16 +++++++------- Source/monster.cpp | 2 +- Source/monster.h | 52 ++++++++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index 175e1d944..c1fb3c91b 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -577,9 +577,9 @@ void LoadMonster(LoadHelper *file, Monster &monster) monster.mode = static_cast(file->NextLE()); monster.goal = static_cast(file->NextLE()); file->Skip(3); // Alignment - monster.goalVar1 = file->NextLE(); - monster.goalVar2 = file->NextLE(); - monster.goalVar3 = file->NextLE(); + monster.goalVar1 = file->NextLENarrow(); + monster.goalVar2 = file->NextLENarrow(); + monster.goalVar3 = file->NextLENarrow(); file->Skip(4); // Unused monster.pathCount = file->NextLE(); file->Skip(3); // Alignment @@ -608,11 +608,11 @@ void LoadMonster(LoadHelper *file, Monster &monster) monster.animInfo.currentFrame = file->NextLENarrow(-1); file->Skip(4); // Skip _meflag monster.isInvalid = file->NextBool32(); - monster.var1 = file->NextLE(); - monster.var2 = file->NextLE(); - monster.var3 = file->NextLE(); - monster.position.temp.x = file->NextLE(); - monster.position.temp.y = file->NextLE(); + monster.var1 = file->NextLENarrow(); + monster.var2 = file->NextLENarrow(); + monster.var3 = file->NextLENarrow(); + monster.position.temp.x = file->NextLENarrow(); + monster.position.temp.y = file->NextLENarrow(); monster.position.offset2.deltaX = file->NextLE(); monster.position.offset2.deltaY = file->NextLE(); file->Skip(4); // Skip actionFrame diff --git a/Source/monster.cpp b/Source/monster.cpp index 246650312..900d2eded 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1945,7 +1945,7 @@ Direction Turn(Direction direction, bool turnLeft) return turnLeft ? Left(direction) : Right(direction); } -bool RoundWalk(int monsterId, Direction direction, int *dir) +bool RoundWalk(int monsterId, Direction direction, int8_t *dir) { Monster &monster = Monsters[monsterId]; diff --git a/Source/monster.h b/Source/monster.h index 97f4d406e..3a0898add 100644 --- a/Source/monster.h +++ b/Source/monster.h @@ -150,11 +150,16 @@ struct AnimStruct { }; struct CMonster { + std::unique_ptr animData; + AnimStruct anims[6]; + std::unique_ptr sounds[4][2]; + const MonsterData *data; + _monster_id type; /** placeflag enum as a flags*/ uint8_t placeFlags; - std::unique_ptr animData; - AnimStruct anims[6]; + int8_t corpseId; + /** * @brief Returns AnimStruct for specified graphic */ @@ -162,9 +167,6 @@ struct CMonster { { return anims[static_cast(graphic)]; } - std::unique_ptr sounds[4][2]; - int8_t corpseId; - const MonsterData *data; }; extern CMonster LevelMonsterTypes[MaxLvlMTypes]; @@ -175,23 +177,6 @@ struct Monster { // note: missing field _mAFNum * @brief Contains information for current animation */ AnimationInfo animInfo; - /** Specifies current goal of the monster */ - MonsterGoal goal; - /** Specifies monster's behaviour regarding moving and changing goals. */ - int goalVar1; - /** - * @brief Specifies turning direction for @p RoundWalk in most cases. - * Used in custom way by @p FallenAi, @p SnakeAi, @p M_FallenFear and @p FallenAi. - */ - int goalVar2; - /** - * @brief Controls monster's behaviour regarding special actions. - * Used only by @p ScavengerAi and @p MegaAi. - */ - int goalVar3; - int var1; - int var2; - int var3; int maxHitPoints; int hitPoints; uint32_t flags; @@ -204,8 +189,31 @@ struct Monster { // note: missing field _mAFNum uint16_t toHitSpecial; uint16_t resistance; _speech_id talkMsg; + + /** @brief Specifies monster's behaviour regarding moving and changing goals. */ + int16_t goalVar1; + + /** + * @brief Specifies turning direction for @p RoundWalk in most cases. + * Used in custom way by @p FallenAi, @p SnakeAi, @p M_FallenFear and @p FallenAi. + */ + int8_t goalVar2; + + /** + * @brief Controls monster's behaviour regarding special actions. + * Used only by @p ScavengerAi and @p MegaAi. + */ + int8_t goalVar3; + + int16_t var1; + int16_t var2; + int8_t var3; + ActorPosition position; + /** Specifies current goal of the monster */ + MonsterGoal goal; + /** Usually corresponds to the enemy's future position */ WorldTilePosition enemyPosition; uint8_t levelType;