Skip to content

Commit

Permalink
input: fix saving custom controller layout
Browse files Browse the repository at this point in the history
Resolves #2422.
  • Loading branch information
rr- committed Feb 1, 2025
1 parent 1240537 commit 5139c16
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- fixed photo mode switching to the wrong flipmap rooms at times (#2362)
- fixed the teleporting command sometimes putting Lara in invalid flipmap rooms (#2370)
- fixed teleporting to an item on a ledge sometimes pushing Lara to the room below (#2372)
- fixed input controller remaps not being saved across game relaunches (#2422, regression from 4.6)
- fixed the upside-down camera fix to no longer limit Lara's vision (#2276, regression from 4.2)
- fixed being unable to load some old custom levels that contain certain (invalid) floor data (#2114, regression from 4.3)
- fixed a desync in the Lost Valley demo if responsive swim cancellation was enabled (#2113, regression from 4.6)
Expand Down
1 change: 1 addition & 0 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
- fixed demos playing too eagerly (#2068, regression from 0.3)
- fixed Lara sometimes being unable to use switches (#2184, regression from 0.6)
- fixed Lara interacting with airlock switches in unexpected ways (#2186, regression from 0.6)
- fixed input controller remaps not being saved across game relaunches (#2422, regression from 0.6)
- improved the animation of Lara's braid (#2094)

## [0.7.1](https://github.com/LostArtefacts/TRX/compare/tr2-0.7...tr2-0.7.1) - 2024-12-17
Expand Down
13 changes: 12 additions & 1 deletion src/libtrx/game/input/backends/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static SDL_GameController *M_FindController(void);

static void M_Init(void);
static void M_Shutdown(void);
static void M_Discover(void);
static bool M_CustomUpdate(INPUT_STATE *result, INPUT_LAYOUT layout);
static bool M_IsPressed(INPUT_LAYOUT layout, INPUT_ROLE role);
static bool M_IsRoleConflicted(INPUT_LAYOUT layout, INPUT_ROLE role);
Expand Down Expand Up @@ -415,7 +416,7 @@ static void M_Init(void)
if (result < 0) {
LOG_ERROR("Error while calling SDL_Init: 0x%lx", result);
} else {
m_Controller = M_FindController();
M_Discover();
}
}

Expand All @@ -427,6 +428,15 @@ static void M_Shutdown(void)
}
}

static void M_Discover(void)
{
if (m_Controller != nullptr) {
SDL_GameControllerClose(m_Controller);
m_Controller = nullptr;
}
m_Controller = M_FindController();
}

static bool M_CustomUpdate(INPUT_STATE *const result, const INPUT_LAYOUT layout)
{
if (m_Controller == nullptr) {
Expand Down Expand Up @@ -593,6 +603,7 @@ static bool M_ReadAndAssign(const INPUT_LAYOUT layout, const INPUT_ROLE role)
INPUT_BACKEND_IMPL g_Input_Controller = {
.init = M_Init,
.shutdown = M_Shutdown,
.discover = M_Discover,
.custom_update = M_CustomUpdate,
.is_pressed = M_IsPressed,
.is_role_conflicted = M_IsRoleConflicted,
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/game/input/backends/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ static bool M_ReadAndAssign(const INPUT_LAYOUT layout, const INPUT_ROLE role)
INPUT_BACKEND_IMPL g_Input_Keyboard = {
.init = M_Init,
.shutdown = nullptr,
.discover = nullptr,
.custom_update = M_CustomUpdate,
.is_pressed = M_IsPressed,
.is_role_conflicted = M_IsRoleConflicted,
Expand Down
14 changes: 5 additions & 9 deletions src/libtrx/game/input/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,13 @@ void Input_Shutdown(void)
}
}

void Input_InitController(void)
void Input_Discover(void)
{
if (g_Input_Controller.init != nullptr) {
g_Input_Controller.init();
if (g_Input_Keyboard.discover != nullptr) {
g_Input_Keyboard.discover();
}
}

void Input_ShutdownController(void)
{
if (g_Input_Controller.shutdown != nullptr) {
g_Input_Controller.shutdown();
if (g_Input_Controller.discover != nullptr) {
g_Input_Controller.discover();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/input/backends/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
typedef struct {
void (*init)(void);
void (*shutdown)(void);
void (*discover)(void);
bool (*custom_update)(INPUT_STATE *result, INPUT_LAYOUT layout);
bool (*is_pressed)(INPUT_LAYOUT layout, INPUT_ROLE role);
bool (*is_role_conflicted)(INPUT_LAYOUT layout, INPUT_ROLE role);
Expand Down
3 changes: 1 addition & 2 deletions src/libtrx/include/libtrx/game/input/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ extern INPUT_STATE g_OldInputDB;

void Input_Init(void);
void Input_Shutdown(void);
void Input_InitController(void);
void Input_ShutdownController(void);
void Input_Discover(void);
void Input_Update(void);

// Checks whether the given role can be assigned to by the player.
Expand Down
5 changes: 1 addition & 4 deletions src/tr1/specific/s_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,9 @@ void Shell_ProcessEvents(void)

case SDL_CONTROLLERDEVICEADDED:
case SDL_JOYDEVICEADDED:
Input_InitController();
break;

case SDL_CONTROLLERDEVICEREMOVED:
case SDL_JOYDEVICEREMOVED:
Input_ShutdownController();
Input_Discover();
break;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/tr2/game/shell/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,9 @@ void Shell_ProcessEvents(void)

case SDL_CONTROLLERDEVICEADDED:
case SDL_JOYDEVICEADDED:
Input_InitController();
break;

case SDL_CONTROLLERDEVICEREMOVED:
case SDL_JOYDEVICEREMOVED:
Input_ShutdownController();
Input_Discover();
break;

case SDL_WINDOWEVENT:
Expand Down

0 comments on commit 5139c16

Please sign in to comment.