From db0e643419c32de12a80bfb9a03c0b17123e6348 Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Sat, 16 Apr 2022 01:37:15 -0400 Subject: [PATCH] Load gamecontrollerdb.txt for SDL2 joy mappings --- doc/040_cvarlist.md | 2 +- src/client/input/sdl.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 805ae677..c0cd7cd8 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -117,7 +117,7 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable` during gameplay and released otherwise (in menu, videos, console or if game is paused). - **in_sdlbackbutton**: Defines which button is used in the gamepad or +* **in_sdlbackbutton**: Defines which button is used in the gamepad or joystick as the `Esc` key, that is, to be able to access the menu and 'cancel'/'go back' on its options. When set to `0` (the default) the Back/Select/Minus button is used. Set this to `1` to use the diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index 1d8760a3..87da77b6 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -1201,7 +1201,9 @@ Haptic_Feedback(char *name, int effect_volume, int effect_duration, void IN_Init(void) { - static cvar_t *in_sdlbackbutton; + cvar_t *in_sdlbackbutton; + int nummappings; + char controllerdb[MAX_OSPATH] = {0}; Com_Printf("------- input initialization -------\n"); mouse_x = mouse_y = 0; @@ -1279,7 +1281,16 @@ IN_Init(void) { Com_Printf ("%i joysticks were found.\n", SDL_NumJoysticks()); - if (SDL_NumJoysticks() > 0) { + if (SDL_NumJoysticks() > 0) + { + for (const char* rawPath = FS_GetNextRawPath(NULL); rawPath != NULL; rawPath = FS_GetNextRawPath(rawPath)) + { + snprintf(controllerdb, MAX_OSPATH, "%s/%s", rawPath, "gamecontrollerdb.txt"); + nummappings = SDL_GameControllerAddMappingsFromFile(controllerdb); + if (nummappings > 0) + Com_Printf ("%d mappings loaded from gamecontrollerdb.txt\n", nummappings); + } + for (int i = 0; i < SDL_NumJoysticks(); i++) { joystick = SDL_JoystickOpen(i);