Skip to content

Commit

Permalink
tr1/passport: refactor input processing
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Feb 15, 2025
1 parent 4702d7e commit 35e4cee
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 84 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.8.1...develop) - ××××-××-××
- changed default FPS value to 60 (#2501)
- changed passport to be more responsive to player inputs (#1328)
- fixed story so far not skipping over levels (#2506, regression from 4.8)
- fixed resolving paths (especially to music files) on case-sensitive filesystems (#1934, #2504)
- improved memory usage by shedding ca. 100-110 MB on average
Expand Down
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.9...develop) - ××××-××-××
- changed passport to be more responsive to player inputs (#1328)
- fixed resolving paths (especially to music files) on case-sensitive filesystems (#1934, #2504)
- fixed loading a game crashing on Linux (#2508, regression from 0.9)
- improved memory usage by shedding ca. 100-110 MB on average
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/config/map_tr1.def
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CFG_BOOL(g_Config, gameplay.enable_cheats, false)
CFG_BOOL(g_Config, gameplay.enable_console, true)
CFG_BOOL(g_Config, input.enable_numeric_keys, true)
CFG_BOOL(g_Config, input.enable_tr3_sidesteps, true)
CFG_BOOL(g_Config, input.enable_responsive_passport, true)
CFG_BOOL(g_Config, visuals.enable_braid, true)
CFG_BOOL(g_Config, gameplay.enable_compass_stats, true)
CFG_BOOL(g_Config, gameplay.enable_total_stats, true)
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/config/map_tr2.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CFG_BOOL(g_Config, gameplay.enable_cheats, false)
CFG_BOOL(g_Config, gameplay.enable_console, true)
CFG_BOOL(g_Config, gameplay.enable_fmv, true)
CFG_BOOL(g_Config, input.enable_tr3_sidesteps, true)
CFG_BOOL(g_Config, input.enable_responsive_passport, true)
CFG_BOOL(g_Config, gameplay.enable_auto_item_selection, true)
CFG_INT32(g_Config, gameplay.turbo_speed, 0)
CFG_BOOL(g_Config, visuals.enable_3d_pickups, true)
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/config/types_tr1.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct {
int32_t controller_layout;
bool enable_numeric_keys;
bool enable_tr3_sidesteps;
bool enable_responsive_passport;
bool enable_buffering;
} input;

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/config/types_tr2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct {
int32_t keyboard_layout;
int32_t controller_layout;
bool enable_tr3_sidesteps;
bool enable_responsive_passport;
} input;

struct {
Expand Down
4 changes: 2 additions & 2 deletions src/tr1/game/inventory_ring/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ static GF_COMMAND M_Control(INV_RING *const ring)
}
}

if (!busy) {
Option_Control(inv_item);
Option_Control(inv_item, busy);

if (!busy) {
if (g_InputDB.menu_back) {
inv_item->sprite_list = nullptr;
InvRing_MotionSetup(ring, RNG_CLOSING_ITEM, RNG_DESELECT, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

#include <libtrx/game/inventory_ring/types.h>

void Option_Control(INVENTORY_ITEM *inv_item);
void Option_Control(INVENTORY_ITEM *inv_item, bool is_busy);
void Option_Draw(INVENTORY_ITEM *inv_item);
void Option_Shutdown(INVENTORY_ITEM *inv_item);
30 changes: 16 additions & 14 deletions src/tr1/game/option/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,37 @@ void Option_Shutdown(INVENTORY_ITEM *inv_item)
}
}

void Option_Control(INVENTORY_ITEM *inv_item)
void Option_Control(INVENTORY_ITEM *inv_item, const bool is_busy)
{
switch (inv_item->object_id) {
case O_PASSPORT_OPTION:
Option_Passport_Control(inv_item);
Option_Passport_Control(inv_item, is_busy);
break;

case O_COMPASS_OPTION:
Option_Compass_Control(inv_item);
Option_Compass_Control(inv_item, is_busy);
break;

case O_DETAIL_OPTION:
Option_Graphics_Control(inv_item);
Option_Graphics_Control(inv_item, is_busy);
break;

case O_SOUND_OPTION:
Option_Sound_Control(inv_item);
Option_Sound_Control(inv_item, is_busy);
break;

case O_CONTROL_OPTION:
switch (m_ControlMode) {
case CM_PICK:
m_ControlMode = Option_ControlsPick_Control();
m_ControlMode = Option_ControlsPick_Control(is_busy);
break;
case CM_KEYBOARD:
m_ControlMode =
Option_Controls_Control(inv_item, INPUT_BACKEND_KEYBOARD);
m_ControlMode = Option_Controls_Control(
inv_item, is_busy, INPUT_BACKEND_KEYBOARD);
break;
case CM_CONTROLLER:
m_ControlMode =
Option_Controls_Control(inv_item, INPUT_BACKEND_CONTROLLER);
m_ControlMode = Option_Controls_Control(
inv_item, is_busy, INPUT_BACKEND_CONTROLLER);
break;
}
break;
Expand All @@ -106,7 +106,9 @@ void Option_Control(INVENTORY_ITEM *inv_item)
case O_EXPLOSIVE_OPTION:
case O_MEDI_OPTION:
case O_BIGMEDI_OPTION:
g_InputDB.menu_confirm = 1;
if (!is_busy) {
g_InputDB.menu_confirm = 1;
}
break;

case O_PISTOL_AMMO_OPTION:
Expand All @@ -128,14 +130,14 @@ void Option_Control(INVENTORY_ITEM *inv_item)
case O_SCION_OPTION:
case O_LEADBAR_OPTION:
if (inv_item->action == ACTION_EXAMINE) {
Option_Examine_Control(inv_item->object_id);
} else {
Option_Examine_Control(inv_item->object_id, is_busy);
} else if (!is_busy) {
g_InputDB.menu_confirm = 1;
}
break;

default:
if (g_InputDB.menu_confirm || g_InputDB.menu_back) {
if (!is_busy && (g_InputDB.menu_confirm || g_InputDB.menu_back)) {
inv_item->goal_frame = 0;
inv_item->anim_direction = -1;
}
Expand Down
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_compass.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ static void M_Shutdown(void)
}
}

void Option_Compass_Control(INVENTORY_ITEM *const inv_item)
void Option_Compass_Control(INVENTORY_ITEM *const inv_item, const bool is_busy)
{
if (is_busy) {
return;
}

if (g_Config.gameplay.enable_compass_stats) {
char buf[100];
char time_buf[100];
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_compass.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <libtrx/game/inventory_ring/types.h>

void Option_Compass_Control(INVENTORY_ITEM *inv_item);
void Option_Compass_Control(INVENTORY_ITEM *inv_item, bool is_busy);
void Option_Compass_Draw(void);
void Option_Compass_Shutdown(void);

Expand Down
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,12 @@ static void M_CheckUnbindKey(INPUT_BACKEND backend, INPUT_LAYOUT layout)
}

CONTROL_MODE Option_Controls_Control(
INVENTORY_ITEM *inv_item, INPUT_BACKEND backend)
INVENTORY_ITEM *inv_item, const bool is_busy, INPUT_BACKEND backend)
{
if (is_busy) {
return CM_PICK;
}

INPUT_LAYOUT layout = INPUT_LAYOUT_DEFAULT;
if (backend == INPUT_BACKEND_KEYBOARD) {
layout = g_Config.input.keyboard_layout;
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ typedef enum {
} CONTROL_MODE;

CONTROL_MODE Option_Controls_Control(
INVENTORY_ITEM *inv_item, INPUT_BACKEND backend);
INVENTORY_ITEM *inv_item, bool is_busy, INPUT_BACKEND backend);
void Option_Controls_Draw(INVENTORY_ITEM *inv_item, INPUT_BACKEND backend);
void Option_Control_Shutdown(void);
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_controls_pick.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ static void M_ShutdownText(void)
}
}

CONTROL_MODE Option_ControlsPick_Control(void)
CONTROL_MODE Option_ControlsPick_Control(const bool is_busy)
{
if (is_busy) {
return CM_PICK;
}

if (!m_Text[TEXT_KEYBOARD]) {
M_InitText();
}
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_controls_pick.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include "game/option/option_controls.h"

CONTROL_MODE Option_ControlsPick_Control(void);
CONTROL_MODE Option_ControlsPick_Control(bool is_busy);
void Option_ControlsPick_Shutdown(void);
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_examine.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ bool Option_Examine_IsActive(void)
return m_PaginatorUI != nullptr;
}

void Option_Examine_Control(const GAME_OBJECT_ID obj_id)
void Option_Examine_Control(const GAME_OBJECT_ID obj_id, const bool is_busy)
{
if (is_busy) {
return;
}

if (m_PaginatorUI == nullptr) {
m_PaginatorUI = UI_Paginator_Create(
Object_GetName(obj_id), Object_GetDescription(obj_id), MAX_LINES);
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_examine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

bool Option_Examine_CanExamine(GAME_OBJECT_ID obj_id);
bool Option_Examine_IsActive(void);
void Option_Examine_Control(GAME_OBJECT_ID obj_id);
void Option_Examine_Control(GAME_OBJECT_ID obj_id, bool is_busy);
void Option_Examine_Draw(void);
void Option_Examine_Shutdown(void);
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,12 @@ static void M_ChangeTextOption(
}
}

void Option_Graphics_Control(INVENTORY_ITEM *inv_item)
void Option_Graphics_Control(INVENTORY_ITEM *inv_item, const bool is_busy)
{
if (is_busy) {
return;
}

if (!m_IsTextInit) {
M_InitText();
m_IsTextInit = true;
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include <libtrx/game/inventory_ring/types.h>

void Option_Graphics_Control(INVENTORY_ITEM *inv_item);
void Option_Graphics_Control(INVENTORY_ITEM *inv_item, bool is_busy);
void Option_Graphics_Shutdown(void);
44 changes: 29 additions & 15 deletions src/tr1/game/option/option_passport.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ static void M_NewGame(void);
static void M_Restart(INVENTORY_ITEM *inv_item);
static void M_FlipRight(INVENTORY_ITEM *inv_item);
static void M_FlipLeft(INVENTORY_ITEM *inv_item);
static void M_ShowPage(INVENTORY_ITEM *inv_item);
static void M_HandleFlipInputs(void);

void M_InitRequesters(void)
{
Expand Down Expand Up @@ -656,7 +658,26 @@ static void M_ShowPage(INVENTORY_ITEM *const inv_item)
}
}

void Option_Passport_Control(INVENTORY_ITEM *inv_item)
static void M_HandleFlipInputs(void)
{
if (g_InputDB.menu_left) {
for (int32_t page = m_State.active_page - 1; page >= 0; page--) {
if (m_State.pages[page].available) {
m_State.active_page = page;
break;
}
}
} else if (g_InputDB.menu_right) {
for (int32_t page = m_State.active_page + 1; page < 3; page++) {
if (m_State.pages[page].available) {
m_State.active_page = page;
break;
}
}
}
}

void Option_Passport_Control(INVENTORY_ITEM *inv_item, const bool is_busy)
{
if (m_State.active_page == -1) {
M_InitRequesters();
Expand All @@ -666,6 +687,13 @@ void Option_Passport_Control(INVENTORY_ITEM *inv_item)
M_DeterminePages();
}

if (!is_busy || g_Config.input.enable_responsive_passport) {
M_HandleFlipInputs();
}
if (is_busy) {
return;
}

const int32_t frame = inv_item->goal_frame - inv_item->open_frame;
const int32_t page = frame;
m_State.current_page = frame / 5;
Expand Down Expand Up @@ -708,20 +736,6 @@ void Option_Passport_Control(INVENTORY_ITEM *inv_item)
} else if (g_InputDB.menu_confirm) {
M_Close(inv_item);
m_State.active_page = -1;
} else if (g_InputDB.menu_left) {
for (int32_t page = m_State.active_page - 1; page >= 0; page--) {
if (m_State.pages[page].available) {
m_State.active_page = page;
break;
}
}
} else if (g_InputDB.menu_right) {
for (int32_t page = m_State.active_page + 1; page < 3; page++) {
if (m_State.pages[page].available) {
m_State.active_page = page;
break;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_passport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include <libtrx/game/inventory_ring/types.h>

void Option_Passport_Control(INVENTORY_ITEM *inv_item);
void Option_Passport_Control(INVENTORY_ITEM *inv_item, bool is_busy);
void Option_Passport_Shutdown(void);
6 changes: 5 additions & 1 deletion src/tr1/game/option/option_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ static void M_InitText(void)
}
}

void Option_Sound_Control(INVENTORY_ITEM *inv_item)
void Option_Sound_Control(INVENTORY_ITEM *inv_item, const bool is_busy)
{
if (is_busy) {
return;
}

char buf[20];

if (!m_Text[TEXT_MUSIC_VOLUME]) {
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/option/option_sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include <libtrx/game/inventory_ring/types.h>

void Option_Sound_Control(INVENTORY_ITEM *inv_item);
void Option_Sound_Control(INVENTORY_ITEM *inv_item, bool is_busy);
void Option_Sound_Shutdown(void);
4 changes: 2 additions & 2 deletions src/tr2/game/inventory_ring/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ static GF_COMMAND M_Control(INV_RING *const ring)
}
}

if (!busy) {
Option_Control(inv_item);
Option_Control(inv_item, busy);

if (!busy) {
if (g_InputDB.menu_back) {
inv_item->sprite_list = nullptr;
InvRing_MotionSetup(ring, RNG_CLOSING_ITEM, RNG_DESELECT, 0);
Expand Down
Loading

0 comments on commit 35e4cee

Please sign in to comment.