From a83e2b3597df72ddf1c5e27dff7d9012fc9d3662 Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:04:52 +0000 Subject: [PATCH] libtrx/anims/enum: merge animation command enums This merges animation command enums and uses common utilities to extract the required data in Item_Animate. --- src/libtrx/include/libtrx/game/anims.h | 2 ++ src/libtrx/include/libtrx/game/anims/enum.h | 19 +++++++++++++++++++ src/libtrx/include/libtrx/game/anims/util.h | 4 ++++ src/tr1/game/items.c | 20 ++++++++------------ src/tr1/game/items.h | 2 +- src/tr1/global/types.h | 10 ---------- src/tr2/game/items.c | 4 ++-- src/tr2/game/lara/control.c | 8 ++++---- src/tr2/global/types_decomp.h | 16 ---------------- 9 files changed, 40 insertions(+), 45 deletions(-) create mode 100644 src/libtrx/include/libtrx/game/anims/enum.h create mode 100644 src/libtrx/include/libtrx/game/anims/util.h diff --git a/src/libtrx/include/libtrx/game/anims.h b/src/libtrx/include/libtrx/game/anims.h index 02377fb58f..02578caa46 100644 --- a/src/libtrx/include/libtrx/game/anims.h +++ b/src/libtrx/include/libtrx/game/anims.h @@ -1,3 +1,5 @@ #pragma once +#include "anims/enum.h" #include "anims/types.h" +#include "anims/util.h" diff --git a/src/libtrx/include/libtrx/game/anims/enum.h b/src/libtrx/include/libtrx/game/anims/enum.h new file mode 100644 index 0000000000..1612b059a5 --- /dev/null +++ b/src/libtrx/include/libtrx/game/anims/enum.h @@ -0,0 +1,19 @@ +#pragma once + +// clang-format off +typedef enum { + AC_NULL = 0, + AC_MOVE_ORIGIN = 1, + AC_JUMP_VELOCITY = 2, + AC_ATTACK_READY = 3, + AC_DEACTIVATE = 4, + AC_SOUND_FX = 5, + AC_EFFECT = 6, +} ANIM_COMMAND; + +typedef enum { + ACE_ALL = 0, + ACE_LAND = 1, + ACE_WATER = 2, +} ANIM_COMMAND_ENVIRONMENT; +// clang-format on diff --git a/src/libtrx/include/libtrx/game/anims/util.h b/src/libtrx/include/libtrx/game/anims/util.h new file mode 100644 index 0000000000..09104143dd --- /dev/null +++ b/src/libtrx/include/libtrx/game/anims/util.h @@ -0,0 +1,4 @@ +#pragma once + +#define CMD_ENVIRONMENT_BITS(C) ((C & 0xC000) >> 14) +#define CMD_PARAM_BITS(C) (C & 0x3FFF) diff --git a/src/tr1/game/items.c b/src/tr1/game/items.c index b017c82cd8..94b3aa0f3c 100644 --- a/src/tr1/game/items.c +++ b/src/tr1/game/items.c @@ -20,11 +20,6 @@ #include -#define SFX_MODE_BITS(C) (C & 0xC000) -#define SFX_ID_BITS(C) (C & 0x3FFF) -#define SFX_LAND 0x4000 -#define SFX_WATER 0x8000 - #define ITEM_ADJUST_ROT(source, target, rot) \ do { \ if ((int16_t)(target - source) > rot) { \ @@ -711,22 +706,23 @@ bool Item_GetAnimChange(ITEM *item, ANIM *anim) return false; } -void Item_PlayAnimSFX(ITEM *item, int16_t *command, uint16_t flags) +void Item_PlayAnimSFX( + ITEM *const item, const int16_t *const command, const uint16_t flags) { if (item->frame_num != command[0]) { return; } - uint16_t mode = SFX_MODE_BITS(command[1]); - if (mode) { - int16_t height = Item_GetWaterHeight(item); - if ((mode == SFX_WATER && (height >= 0 || height == NO_HEIGHT)) - || (mode == SFX_LAND && height < 0 && height != NO_HEIGHT)) { + const ANIM_COMMAND_ENVIRONMENT mode = CMD_ENVIRONMENT_BITS(command[1]); + if (mode != ACE_ALL) { + const int16_t height = Item_GetWaterHeight(item); + if ((mode == ACE_WATER && (height >= 0 || height == NO_HEIGHT)) + || (mode == ACE_LAND && height < 0 && height != NO_HEIGHT)) { return; } } - Sound_Effect(SFX_ID_BITS(command[1]), &item->pos, flags); + Sound_Effect(CMD_PARAM_BITS(command[1]), &item->pos, flags); } bool Item_IsTriggerActive(ITEM *item) diff --git a/src/tr1/game/items.h b/src/tr1/game/items.h index 48b5b50125..98112b2881 100644 --- a/src/tr1/game/items.h +++ b/src/tr1/game/items.h @@ -43,7 +43,7 @@ void Item_SwitchToObjAnim( ITEM *item, int16_t anim_idx, int16_t frame, GAME_OBJECT_ID object_id); void Item_Animate(ITEM *item); bool Item_GetAnimChange(ITEM *item, ANIM *anim); -void Item_PlayAnimSFX(ITEM *item, int16_t *command, uint16_t flags); +void Item_PlayAnimSFX(ITEM *item, const int16_t *command, uint16_t flags); bool Item_IsTriggerActive(ITEM *item); diff --git a/src/tr1/global/types.h b/src/tr1/global/types.h index 7d4c92da0f..bbd08c5963 100644 --- a/src/tr1/global/types.h +++ b/src/tr1/global/types.h @@ -189,16 +189,6 @@ typedef enum { HT_BIG_SLOPE = 2, } HEIGHT_TYPE; -typedef enum { - AC_NULL = 0, - AC_MOVE_ORIGIN = 1, - AC_JUMP_VELOCITY = 2, - AC_ATTACK_READY = 3, - AC_DEACTIVATE = 4, - AC_SOUND_FX = 5, - AC_EFFECT = 6, -} ANIM_COMMAND; - typedef enum { BEB_POP = 1 << 0, BEB_PUSH = 1 << 1, diff --git a/src/tr2/game/items.c b/src/tr2/game/items.c index 7945c21d56..87437f5300 100644 --- a/src/tr2/game/items.c +++ b/src/tr2/game/items.c @@ -541,9 +541,9 @@ void Item_Animate(ITEM *const item) case AC_SOUND_FX: { const int32_t frame = cmd_ptr[0]; - const SOUND_EFFECT_ID sound_id = cmd_ptr[1] & 0x3FFF; + const SOUND_EFFECT_ID sound_id = CMD_PARAM_BITS(cmd_ptr[1]); const ANIM_COMMAND_ENVIRONMENT type = - (cmd_ptr[1] & 0xC000) >> 14; + CMD_ENVIRONMENT_BITS(cmd_ptr[1]); cmd_ptr += 2; if (item->frame_num != frame) { diff --git a/src/tr2/game/lara/control.c b/src/tr2/game/lara/control.c index a11c692aa9..151fdd50c2 100644 --- a/src/tr2/game/lara/control.c +++ b/src/tr2/game/lara/control.c @@ -751,9 +751,9 @@ void Lara_Animate(ITEM *const item) case AC_SOUND_FX: { const int32_t frame = cmd_ptr[0]; - const SOUND_EFFECT_ID sound_id = cmd_ptr[1] & 0x3FFF; + const SOUND_EFFECT_ID sound_id = CMD_PARAM_BITS(cmd_ptr[1]); const ANIM_COMMAND_ENVIRONMENT type = - (cmd_ptr[1] & 0xC000) >> 14; + CMD_ENVIRONMENT_BITS(cmd_ptr[1]); cmd_ptr += 2; if (item->frame_num != frame) { @@ -773,9 +773,9 @@ void Lara_Animate(ITEM *const item) case AC_EFFECT: const int32_t frame = cmd_ptr[0]; - const int32_t action_id = cmd_ptr[1] & 0x3FFF; + const int32_t action_id = CMD_PARAM_BITS(cmd_ptr[1]); const ANIM_COMMAND_ENVIRONMENT type = - (cmd_ptr[1] & 0xC000) >> 14; + CMD_ENVIRONMENT_BITS(cmd_ptr[1]); cmd_ptr += 2; if (item->frame_num != frame) { diff --git a/src/tr2/global/types_decomp.h b/src/tr2/global/types_decomp.h index e3207b7f73..c37dede26c 100644 --- a/src/tr2/global/types_decomp.h +++ b/src/tr2/global/types_decomp.h @@ -590,22 +590,6 @@ typedef enum { SF_UNFLIP = 0x80, } SOUND_FLAG; -typedef enum { - AC_NULL = 0, - AC_MOVE_ORIGIN = 1, - AC_JUMP_VELOCITY = 2, - AC_ATTACK_READY = 3, - AC_DEACTIVATE = 4, - AC_SOUND_FX = 5, - AC_EFFECT = 6, -} ANIM_COMMAND; - -typedef enum { - ACE_ALL = 0, - ACE_LAND = 1, - ACE_WATER = 2, -} ANIM_COMMAND_ENVIRONMENT; - typedef struct { int32_t boat_turn; int32_t left_fallspeed;