From ee1cc95f40c09d65082a6502f218e204e6b113e4 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 2 Nov 2024 18:16:50 +0100 Subject: [PATCH] input: fix potential freezes when remapping keys Resolves #1788. --- docs/tr1/CHANGELOG.md | 1 + src/libtrx/game/input/common.c | 15 ++++++++++++++- src/libtrx/include/libtrx/game/input/common.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/tr1/CHANGELOG.md b/docs/tr1/CHANGELOG.md index 235c545490..aa5c0c92ae 100644 --- a/docs/tr1/CHANGELOG.md +++ b/docs/tr1/CHANGELOG.md @@ -42,6 +42,7 @@ - fixed missing trapdoor triggers in City of Khamoon (#1744) - fixed being unable to rename the lead bar (#1774, regression from 4.5) - fixed the controls menu extending to the bottom of the screen with certain text scaling values (#1783, regression from 2.12) +- fixed game stuck at remapping controller key if no controllers connected (#1788) - improved enemy item drops by supporting the TR2+ approach of having drops defined in level data (#1713) - improved Italian localization for the Config Tool - removed health cheat (we now have the `/hp` command) diff --git a/src/libtrx/game/input/common.c b/src/libtrx/game/input/common.c index f54e137fce..0f02b6ed27 100644 --- a/src/libtrx/game/input/common.c +++ b/src/libtrx/game/input/common.c @@ -45,8 +45,9 @@ static INPUT_BACKEND_IMPL *M_GetBackend(const INPUT_BACKEND backend) return &g_Input_Keyboard; case INPUT_BACKEND_CONTROLLER: return &g_Input_Controller; + default: + return NULL; } - return NULL; } void Input_Init(void) @@ -106,6 +107,18 @@ bool Input_ReadAndAssignRole( const INPUT_BACKEND backend, const INPUT_LAYOUT layout, const INPUT_ROLE role) { + // Check for canceling from other devices + for (INPUT_BACKEND other_backend = 0; + other_backend < INPUT_BACKEND_NUMBER_OF; other_backend++) { + if (other_backend == backend) { + continue; + } + if (Input_IsPressed(other_backend, layout, INPUT_ROLE_MENU_BACK) + || Input_IsPressed(other_backend, layout, INPUT_ROLE_OPTION)) { + return true; + } + } + return M_GetBackend(backend)->read_and_assign(layout, role); } diff --git a/src/libtrx/include/libtrx/game/input/common.h b/src/libtrx/include/libtrx/game/input/common.h index efc4e37e6a..92ec3fc827 100644 --- a/src/libtrx/include/libtrx/game/input/common.h +++ b/src/libtrx/include/libtrx/game/input/common.h @@ -24,6 +24,7 @@ typedef union { typedef enum { INPUT_BACKEND_KEYBOARD, INPUT_BACKEND_CONTROLLER, + INPUT_BACKEND_NUMBER_OF, } INPUT_BACKEND; typedef enum {