Skip to content

Commit

Permalink
libtrx/anims/enum: merge animation command enums
Browse files Browse the repository at this point in the history
This merges animation command enums and uses common utilities to
extract the required data in Item_Animate.
  • Loading branch information
lahm86 committed Jan 2, 2025
1 parent 2abf4f6 commit a83e2b3
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/libtrx/include/libtrx/game/anims.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#include "anims/enum.h"
#include "anims/types.h"
#include "anims/util.h"
19 changes: 19 additions & 0 deletions src/libtrx/include/libtrx/game/anims/enum.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/libtrx/include/libtrx/game/anims/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define CMD_ENVIRONMENT_BITS(C) ((C & 0xC000) >> 14)
#define CMD_PARAM_BITS(C) (C & 0x3FFF)
20 changes: 8 additions & 12 deletions src/tr1/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

#include <stddef.h>

#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) { \
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 0 additions & 10 deletions src/tr1/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/tr2/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/tr2/game/lara/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
16 changes: 0 additions & 16 deletions src/tr2/global/types_decomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a83e2b3

Please sign in to comment.