Skip to content

Commit

Permalink
option: fix compass needle resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 1, 2024
1 parent fc1ad4a commit 2f90d4d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased](https://github.com/LostArtefacts/TR1X/compare/stable...develop) - ××××-××-××
- fixed reopening the compass not resetting its needle (#1472, regression from 4.0)
- fixed holstering pistols hiding the gun meshes 1 frame too early (#1449, regression from 0.6)
- fixed Lara's sliding animation sometimes being interrupted by a stumble (#1452, regression from 4.3)
- fixed cameras with glide values sometimes moving in the wrong direction (#1451, regression from 4.3)
Expand Down
17 changes: 17 additions & 0 deletions src/game/option/option_compass.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ typedef enum COMPASS_TEXT {
} COMPASS_TEXT;

static TEXTSTRING *m_Text[TEXT_NUMBER_OF] = { 0 };
static int16_t m_CompassNeedle = 0;
static int16_t m_CompassSpeed = 0;

static void Option_Compass_InitText(void);

Expand Down Expand Up @@ -149,3 +151,18 @@ void Option_Compass_Shutdown(void)
{
Option_Compass_ShutdownText();
}

void Option_Compass_UpdateNeedle(const INVENTORY_ITEM *const inv_item)
{
if (g_LaraItem == NULL) {
return;
}
int16_t delta = -inv_item->y_rot - g_LaraItem->rot.y - m_CompassNeedle;
m_CompassSpeed = m_CompassSpeed * 19 / 20 + delta / 50;
m_CompassNeedle += m_CompassSpeed;
}

int16_t Option_Compass_GetNeedleAngle(void)
{
return m_CompassNeedle;
}
3 changes: 3 additions & 0 deletions src/game/option/option_compass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

void Option_Compass(INVENTORY_ITEM *inv_item);
void Option_Compass_Shutdown(void);

void Option_Compass_UpdateNeedle(const INVENTORY_ITEM *inv_item);
int16_t Option_Compass_GetNeedleAngle(void);
23 changes: 13 additions & 10 deletions src/game/phase/phase_inventory.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "game/music.h"
#include "game/objects/common.h"
#include "game/option.h"
#include "game/option/option_compass.h"
#include "game/output.h"
#include "game/overlay.h"
#include "game/savegame.h"
Expand Down Expand Up @@ -48,8 +49,6 @@ static bool m_PassportModeReady;
static int32_t m_StartLevel;
static bool m_StartDemo;
static TEXTSTRING *m_VersionText = NULL;
static int16_t m_CompassNeedle = 0;
static int16_t m_CompassSpeed = 0;
static int32_t m_StatsCounter;
static CAMERA_INFO m_OldCamera;
static GAME_OBJECT_ID m_InvChosen;
Expand Down Expand Up @@ -357,16 +356,11 @@ static void Inv_SelectMeshes(INVENTORY_ITEM *inv_item)

static bool Inv_AnimateItem(INVENTORY_ITEM *inv_item)
{
if (inv_item->object_number == O_MAP_OPTION) {
int16_t delta = -inv_item->y_rot - g_LaraItem->rot.y - m_CompassNeedle;
m_CompassSpeed = m_CompassSpeed * 19 / 20 + delta / 50;
m_CompassNeedle += m_CompassSpeed;
}

if (inv_item->current_frame == inv_item->goal_frame) {
Inv_SelectMeshes(inv_item);
return false;
}

inv_item->current_frame += inv_item->anim_direction;
if (inv_item->current_frame >= inv_item->frames_total) {
inv_item->current_frame = 0;
Expand Down Expand Up @@ -533,7 +527,7 @@ static void Inv_DrawItem(INVENTORY_ITEM *const inv_item, const int32_t frames)
FRAME_INFO *frame2;
const int32_t frac = InvItem_GetFrames(inv_item, &frame1, &frame2, &rate);
if (inv_item->object_number == O_MAP_OPTION) {
const int16_t extra_rotation[1] = { m_CompassNeedle };
const int16_t extra_rotation[1] = { Option_Compass_GetNeedleAngle() };
int32_t *const bone = &g_AnimBones[obj->bone_index];
bone[0] |= BEB_ROT_Y;
Object_DrawInterpolatedObject(
Expand Down Expand Up @@ -707,6 +701,16 @@ static GAMEFLOW_COMMAND Phase_Inventory_ControlFrame(void)
g_InputDB = (INPUT_STATE) { 0, .menu_confirm = 1 };
}

if (!(g_InvMode == INV_TITLE_MODE || Output_FadeIsAnimating()
|| motion->status == RNG_OPENING)) {
for (int i = 0; i < ring->number_of_objects; i++) {
INVENTORY_ITEM *inv_item = ring->list[i];
if (inv_item->object_number == O_MAP_OPTION) {
Option_Compass_UpdateNeedle(inv_item);
}
}
}

switch (motion->status) {
case RNG_OPEN:
if (g_Input.menu_right && ring->number_of_objects > 1) {
Expand Down Expand Up @@ -1086,7 +1090,6 @@ static GAMEFLOW_COMMAND Phase_Inventory_Control(int32_t nframes)
if (g_Config.enable_timer_in_inventory) {
Stats_UpdateTimer();
}

for (int32_t i = 0; i < nframes; i++) {
GAMEFLOW_COMMAND result = Phase_Inventory_ControlFrame();
if (result.command != GF_PHASE_CONTINUE) {
Expand Down

0 comments on commit 2f90d4d

Please sign in to comment.