Browse Source

Reduce sizes of Monster (goal)Vars

sizeof(Monster): 168 -> 144
pull/5008/head
Gleb Mazovetskiy 4 years ago
parent
commit
7ad0ec925f
  1. 16
      Source/loadsave.cpp
  2. 2
      Source/monster.cpp
  3. 52
      Source/monster.h

16
Source/loadsave.cpp

@ -577,9 +577,9 @@ void LoadMonster(LoadHelper *file, Monster &monster)
monster.mode = static_cast<MonsterMode>(file->NextLE<int32_t>());
monster.goal = static_cast<MonsterGoal>(file->NextLE<uint8_t>());
file->Skip(3); // Alignment
monster.goalVar1 = file->NextLE<int32_t>();
monster.goalVar2 = file->NextLE<int32_t>();
monster.goalVar3 = file->NextLE<int32_t>();
monster.goalVar1 = file->NextLENarrow<int32_t, int16_t>();
monster.goalVar2 = file->NextLENarrow<int32_t, int8_t>();
monster.goalVar3 = file->NextLENarrow<int32_t, int8_t>();
file->Skip(4); // Unused
monster.pathCount = file->NextLE<uint8_t>();
file->Skip(3); // Alignment
@ -608,11 +608,11 @@ void LoadMonster(LoadHelper *file, Monster &monster)
monster.animInfo.currentFrame = file->NextLENarrow<int32_t, int8_t>(-1);
file->Skip(4); // Skip _meflag
monster.isInvalid = file->NextBool32();
monster.var1 = file->NextLE<int32_t>();
monster.var2 = file->NextLE<int32_t>();
monster.var3 = file->NextLE<int32_t>();
monster.position.temp.x = file->NextLE<int32_t>();
monster.position.temp.y = file->NextLE<int32_t>();
monster.var1 = file->NextLENarrow<int32_t, int16_t>();
monster.var2 = file->NextLENarrow<int32_t, int16_t>();
monster.var3 = file->NextLENarrow<int32_t, int8_t>();
monster.position.temp.x = file->NextLENarrow<int32_t, WorldTileCoord>();
monster.position.temp.y = file->NextLENarrow<int32_t, WorldTileCoord>();
monster.position.offset2.deltaX = file->NextLE<int32_t>();
monster.position.offset2.deltaY = file->NextLE<int32_t>();
file->Skip(4); // Skip actionFrame

2
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];

52
Source/monster.h

@ -150,11 +150,16 @@ struct AnimStruct {
};
struct CMonster {
std::unique_ptr<byte[]> animData;
AnimStruct anims[6];
std::unique_ptr<TSnd> sounds[4][2];
const MonsterData *data;
_monster_id type;
/** placeflag enum as a flags*/
uint8_t placeFlags;
std::unique_ptr<byte[]> animData;
AnimStruct anims[6];
int8_t corpseId;
/**
* @brief Returns AnimStruct for specified graphic
*/
@ -162,9 +167,6 @@ struct CMonster {
{
return anims[static_cast<int>(graphic)];
}
std::unique_ptr<TSnd> 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;

Loading…
Cancel
Save