Skip to content

Commit

Permalink
tr2: migrate to Item_TestFrameEqual
Browse files Browse the repository at this point in the history
This updates frame index tests for items to use Item_TestFrameEqual and
Item_TestFrameRange.
  • Loading branch information
lahm86 committed Jan 5, 2025
1 parent ec70b65 commit 3379fec
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/tr2/decomp/flares.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ void Flare_Undraw(void)
if (Item_TestAnimEqual(g_LaraItem, LA_FLARE_THROW)) {
g_Lara.flare_control_left = 0;

if (frame_num_2
>= g_Anims[LA_FLARE_THROW].frame_base + LF_FL_THROW_FT - 1) {
if (Item_TestFrameRange(
g_LaraItem, LF_FL_THROW_FT - 1, LF_FL_THROW_END)) {
g_Lara.gun_type = g_Lara.last_gun_type;
g_Lara.request_gun_type = g_Lara.last_gun_type;
g_Lara.gun_status = LGS_ARMLESS;
Expand Down
1 change: 1 addition & 0 deletions src/tr2/decomp/flares.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
typedef enum {
LF_FL_HOLD_FT = 1,
LF_FL_THROW_FT = 32,
LF_FL_THROW_END = 35,
LF_FL_DRAW_FT = 39,
LF_FL_IGNITE_FT = 23,
LF_FL_2_HOLD_FT = 15,
Expand Down
12 changes: 8 additions & 4 deletions src/tr2/game/gun/gun_rifle.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include <libtrx/config.h>
#include <libtrx/utils.h>

#define GUN_RIFLE_EQUIP_FRAME 1
#define GUN_RIFLE_DRAW_FRAME 10
#define GUN_RIFLE_UNDRAW_FRAME 21

static bool m_M16Firing = false;
static bool m_HarpoonFired = false;

Expand Down Expand Up @@ -256,7 +260,7 @@ void Gun_Rifle_Draw(const LARA_GUN_TYPE weapon_type)
if (item->current_anim_state == LA_G_AIM
|| item->current_anim_state == LA_G_UAIM) {
Gun_Rifle_Ready(weapon_type);
} else if (item->frame_num - g_Anims[item->anim_num].frame_base == 10) {
} else if (Item_TestFrameEqual(item, GUN_RIFLE_DRAW_FRAME)) {
Gun_Rifle_DrawMeshes(weapon_type);
} else if (g_Lara.water_status == LWS_UNDERWATER) {
item->goal_anim_state = LA_G_UAIM;
Expand Down Expand Up @@ -293,7 +297,7 @@ void Gun_Rifle_Undraw(const LARA_GUN_TYPE weapon_type)
g_Lara.right_arm.lock = 0;
} else if (
item->current_anim_state == LA_G_UNDRAW
&& item->frame_num - g_Anims[item->anim_num].frame_base == 21) {
&& Item_TestFrameEqual(item, GUN_RIFLE_UNDRAW_FRAME)) {
Gun_Rifle_UndrawMeshes(weapon_type);
}

Expand Down Expand Up @@ -344,7 +348,7 @@ void Gun_Rifle_Animate(const LARA_GUN_TYPE weapon_type)
break;

case LA_G_RECOIL:
if (item->frame_num - g_Anims[item->anim_num].frame_base == 0) {
if (Item_TestFrameEqual(item, 0)) {
item->goal_anim_state = LA_G_UNAIM;
if (g_Lara.water_status != LWS_UNDERWATER && !running
&& !m_HarpoonFired) {
Expand Down Expand Up @@ -396,7 +400,7 @@ void Gun_Rifle_Animate(const LARA_GUN_TYPE weapon_type)
break;

case LA_G_URECOIL:
if (item->frame_num - g_Anims[item->anim_num].frame_base == 0) {
if (Item_TestFrameEqual(item, 0)) {
item->goal_anim_state = LA_G_UUNAIM;
if ((g_Lara.water_status == LWS_UNDERWATER || running)
&& !m_HarpoonFired) {
Expand Down
87 changes: 64 additions & 23 deletions src/tr2/game/lara/col.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,39 @@
#include <libtrx/config.h>
#include <libtrx/utils.h>

#define LF_WALK_STEP_L_START 29
#define LF_WALK_STEP_L_MID 44
#define LF_WALK_STEP_L_NEAR_END 45
#define LF_WALK_STEP_L_END 47
#define LF_WALK_STEP_R_START 22
#define LF_WALK_STEP_R_NEAR_END 27
#define LF_WALK_STEP_R_END 28
#define LF_WALK_STEP_R_2_START 48
#define LF_WALK_STEP_R_2_END 57

#define LF_RUN_L_START 0
#define LF_RUN_L_HEEL_GROUND 3
#define LF_RUN_L_END 9
#define LF_RUN_R_START 10
#define LF_RUN_R_FOOT_GROUND 14
#define LF_RUN_R_END 21

#define LF_BACK_R_START 26
#define LF_BACK_R_END 55

#define LF_WADE_L_START 0
#define LF_WADE_L_END 9
#define LF_WADE_R_START 10
#define LF_WADE_R_END 21

#define LF_WADE_STEP_L_START 3
#define LF_WADE_STEP_L_END 14

#define LF_HANG 21
#define LF_CLIMB_L_SHIFT_START 28
#define LF_CLIMB_L_SHIFT_END 29
#define LF_CLIMB_R_SHIFT 57

void Lara_CollideStop(ITEM *const item, const COLL_INFO *const coll)
{
switch (coll->old_anim_state) {
Expand Down Expand Up @@ -223,11 +256,13 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll)
}

if (Lara_DeflectEdge(item, coll)) {
if (item->frame_num >= 29 && item->frame_num <= 47) {
if (Item_TestFrameRange(
item, LF_WALK_STEP_L_START, LF_WALK_STEP_L_END)) {
Item_SwitchToAnim(item, LA_WALK_STOP_LEFT, 0);
} else if (
(item->frame_num >= 22 && item->frame_num <= 28)
|| (item->frame_num >= 48 && item->frame_num <= 57)) {
Item_TestFrameRange(item, LF_WALK_STEP_R_START, LF_WALK_STEP_R_END)
|| Item_TestFrameRange(
item, LF_WALK_STEP_R_2_START, LF_WALK_STEP_R_2_END)) {
Item_SwitchToAnim(item, LA_WALK_STOP_RIGHT, 0);
} else {
Lara_CollideStop(item, coll);
Expand All @@ -239,7 +274,8 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll)
}

if (coll->side_mid.floor > STEP_L / 2) {
if (item->frame_num >= 28 && item->frame_num <= 45) {
if (Item_TestFrameRange(
item, LF_WALK_STEP_R_END, LF_WALK_STEP_L_NEAR_END)) {
Item_SwitchToAnim(item, LA_WALK_DOWN_LEFT, 0);
} else {
Item_SwitchToAnim(item, LA_WALK_DOWN_RIGHT, 0);
Expand All @@ -248,7 +284,8 @@ void Lara_Col_Walk(ITEM *item, COLL_INFO *coll)

if (coll->side_mid.floor >= -STEPUP_HEIGHT
&& coll->side_mid.floor < -STEP_L / 2) {
if (item->frame_num >= 27 && item->frame_num <= 44) {
if (Item_TestFrameRange(
item, LF_WALK_STEP_R_NEAR_END, LF_WALK_STEP_L_MID)) {
Item_SwitchToAnim(item, LA_WALK_UP_STEP_LEFT, 0);
} else {
Item_SwitchToAnim(item, LA_WALK_UP_STEP_RIGHT, 0);
Expand Down Expand Up @@ -285,11 +322,11 @@ void Lara_Col_Run(ITEM *item, COLL_INFO *coll)
if (!Item_TestAnimEqual(item, LA_RUN_START)
&& Lara_TestWall(item, STEP_L, 0, -STEP_L * 5 / 2)) {
item->current_anim_state = LS_SPLAT;
if (item->frame_num >= 0 && item->frame_num <= 9) {
if (Item_TestFrameRange(item, LF_RUN_L_START, LF_RUN_L_END)) {
Item_SwitchToAnim(item, LA_WALL_SMASH_LEFT, 0);
return;
}
if (item->frame_num >= 10 && item->frame_num <= 21) {
if (Item_TestFrameRange(item, LF_RUN_R_START, LF_RUN_R_END)) {
Item_SwitchToAnim(item, LA_WALL_SMASH_RIGHT, 0);
return;
}
Expand All @@ -308,7 +345,8 @@ void Lara_Col_Run(ITEM *item, COLL_INFO *coll)
|| coll->side_front.floor >= -STEP_L / 2)) {
coll->side_mid.floor = 0;
} else {
if (item->frame_num >= 3 && item->frame_num <= 14) {
if (Item_TestFrameRange(
item, LF_RUN_L_HEEL_GROUND, LF_RUN_R_FOOT_GROUND)) {
Item_SwitchToAnim(item, LA_RUN_UP_STEP_LEFT, 0);
} else {
Item_SwitchToAnim(item, LA_RUN_UP_STEP_RIGHT, 0);
Expand Down Expand Up @@ -501,7 +539,7 @@ void Lara_Col_Hang(ITEM *item, COLL_INFO *coll)
|| coll->hit_static) {
if (g_Lara.climb_status
&& Item_TestAnimEqual(item, LA_REACH_TO_HANG)
&& item->frame_num == g_Anims[item->anim_num].frame_base + 21
&& Item_TestFrameEqual(item, LF_HANG)
&& coll->side_mid.ceiling <= -256) {
item->goal_anim_state = LS_HANG;
item->current_anim_state = LS_HANG;
Expand All @@ -515,7 +553,7 @@ void Lara_Col_Hang(ITEM *item, COLL_INFO *coll)
} else if (
g_Input.back && g_Lara.climb_status
&& Item_TestAnimEqual(item, LA_REACH_TO_HANG)
&& item->frame_num == g_Anims[item->anim_num].frame_base + 21) {
&& Item_TestFrameEqual(item, LF_HANG)) {
item->goal_anim_state = LS_HANG;
item->current_anim_state = LS_HANG;
Item_SwitchToAnim(item, LA_LADDER_DOWN_HANGING, 0);
Expand Down Expand Up @@ -629,7 +667,7 @@ void Lara_Col_Back(ITEM *item, COLL_INFO *coll)

if (coll->side_mid.floor > STEP_L / 2
&& coll->side_mid.floor < STEPUP_HEIGHT) {
if (item->frame_num >= 964 && item->frame_num <= 993) {
if (Item_TestFrameRange(item, LF_BACK_R_START, LF_BACK_R_END)) {
Item_SwitchToAnim(item, LA_WALK_DOWN_BACK_RIGHT, 0);
} else {
Item_SwitchToAnim(item, LA_WALK_DOWN_BACK_LEFT, 0);
Expand Down Expand Up @@ -903,13 +941,15 @@ void Lara_Col_Wade(ITEM *item, COLL_INFO *coll)
if (Lara_DeflectEdge(item, coll)) {
item->rot.z = 0;
if (coll->side_front.type != COLL_NONE
&& coll->side_front.floor < -STEP_L * 5 / 2) {
&& coll->side_front.floor < -STEP_L * 5 / 2
&& coll->old_anim_state == LS_WADE
&& Item_TestAnimEqual(item, LA_WADE)) {
item->current_anim_state = LS_SPLAT;
if (item->frame_num >= 0 && item->frame_num <= 9) {
if (Item_TestFrameRange(item, LF_WADE_L_START, LF_WADE_L_END)) {
Item_SwitchToAnim(item, LA_WALL_SMASH_LEFT, 0);
return;
}
if (item->frame_num >= 10 && item->frame_num <= 21) {
if (Item_TestFrameRange(item, LF_WADE_R_START, LF_WADE_R_END)) {
Item_SwitchToAnim(item, LA_WALL_SMASH_RIGHT, 0);
return;
}
Expand All @@ -923,7 +963,8 @@ void Lara_Col_Wade(ITEM *item, COLL_INFO *coll)

if (coll->side_mid.floor >= -STEPUP_HEIGHT
&& coll->side_mid.floor < -STEP_L / 2) {
if (item->frame_num >= 3 && item->frame_num <= 14) {
if (Item_TestFrameRange(
item, LF_WADE_STEP_L_START, LF_WADE_STEP_L_END)) {
Item_SwitchToAnim(item, LA_RUN_UP_STEP_LEFT, 0);
} else {
Item_SwitchToAnim(item, LA_RUN_UP_STEP_RIGHT, 0);
Expand Down Expand Up @@ -1108,12 +1149,12 @@ void Lara_Col_Climbing(ITEM *item, COLL_INFO *coll)
}

int32_t yshift;
int32_t frame_rel = item->frame_num - g_Anims[item->anim_num].frame_base;
if (frame_rel == 0) {
if (Item_TestFrameEqual(item, 0)) {
yshift = 0;
} else if (frame_rel == 28 || frame_rel == 29) {
} else if (Item_TestFrameRange(
item, LF_CLIMB_L_SHIFT_START, LF_CLIMB_L_SHIFT_END)) {
yshift = -STEP_L;
} else if (frame_rel == 57) {
} else if (Item_TestFrameEqual(item, LF_CLIMB_R_SHIFT)) {
yshift = -STEP_L * 2;
} else {
return;
Expand Down Expand Up @@ -1165,12 +1206,12 @@ void Lara_Col_ClimbDown(ITEM *item, COLL_INFO *coll)
}

int32_t yshift;
int32_t frame_rel = item->frame_num - g_Anims[item->anim_num].frame_base;
if (frame_rel == 0) {
if (Item_TestFrameEqual(item, 0)) {
yshift = 0;
} else if (frame_rel >= 28 && frame_rel <= 29) {
} else if (Item_TestFrameRange(
item, LF_CLIMB_L_SHIFT_START, LF_CLIMB_L_SHIFT_END)) {
yshift = STEP_L;
} else if (frame_rel == 57) {
} else if (Item_TestFrameEqual(item, LF_CLIMB_R_SHIFT)) {
yshift = STEP_L * 2;
} else {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/lara/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void Lara_HangTest(ITEM *item, COLL_INFO *coll)
}

if (Item_TestAnimEqual(item, LA_REACH_TO_HANG)
&& item->frame_num == g_Anims[item->anim_num].frame_base + 21
&& Item_TestFrameEqual(item, LF_HANG)
&& Lara_TestClimbStance(item, coll)) {
item->goal_anim_state = LS_CLIMB_STANCE;
}
Expand Down
Loading

0 comments on commit 3379fec

Please sign in to comment.