From 71db1904e4cf1d33e2858d7814084672192f16fb Mon Sep 17 00:00:00 2001 From: fgsfds Date: Wed, 3 Jun 2020 00:10:42 +0300 Subject: [PATCH] load external gamecontrollerdb file if it's present --- src/pc/controller/controller_sdl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 1f56236c..331eefc5 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -13,6 +13,7 @@ #include "controller_api.h" #include "controller_sdl.h" #include "../configfile.h" +#include "../platform.h" #include "game/level_update.h" @@ -89,6 +90,17 @@ static void controller_sdl_init(void) { return; } + // try loading an external gamecontroller mapping file + char gcpath[SYS_MAX_PATH]; + snprintf(gcpath, sizeof(gcpath), "%s/gamecontrollerdb.txt", sys_save_path()); + int nummaps = SDL_GameControllerAddMappingsFromFile(gcpath); + if (nummaps < 0) { + snprintf(gcpath, sizeof(gcpath), "%s/gamecontrollerdb.txt", sys_data_path()); + nummaps = SDL_GameControllerAddMappingsFromFile(gcpath); + } + if (nummaps >= 0) + printf("loaded %d controller mappings from '%s'\n", nummaps, gcpath); + #ifdef BETTERCAMERA if (newcam_mouse == 1) SDL_SetRelativeMouseMode(SDL_TRUE);