Skip to content

Commit

Permalink
input: fix potential freezes when remapping keys
Browse files Browse the repository at this point in the history
Resolves #1788.
  • Loading branch information
rr- committed Nov 2, 2024
1 parent cef24d9 commit 78e60c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion src/libtrx/game/input/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/input/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef union {
typedef enum {
INPUT_BACKEND_KEYBOARD,
INPUT_BACKEND_CONTROLLER,
INPUT_BACKEND_NUMBER_OF,
} INPUT_BACKEND;

typedef enum {
Expand Down
2 changes: 2 additions & 0 deletions src/tr2/game/option/option_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ static void M_HandleLayoutChange(const EVENT *event, void *user_data)
case INPUT_BACKEND_CONTROLLER:
g_Config.input.controller_layout = m_Controller.active_layout;
break;
default:
break;
}

Config_Write();
Expand Down

0 comments on commit 78e60c2

Please sign in to comment.