From: Holger Schemel Date: Mon, 3 Jul 2017 18:52:19 +0000 (+0200) Subject: added using global and personal game controller mapping files X-Git-Tag: 4.0.1.0~32 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=aa77ac7ad31e0a9ab20bb85b51e429cd45f12455;p=rocksndiamonds.git added using global and personal game controller mapping files --- diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index d6cf2b17..ee43dc05 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -2833,7 +2833,10 @@ void SDLInitJoysticks() static boolean sdl_joystick_subsystem_initialized = FALSE; boolean print_warning = !sdl_joystick_subsystem_initialized; #if defined(TARGET_SDL2) - char *mappings_file = "gamecontrollerdb.txt"; + char *mappings_file_base = getPath2(options.ro_base_directory, + GAMECONTROLLER_BASENAME); + char *mappings_file_user = getPath2(getUserGameDataDir(), + GAMECONTROLLER_BASENAME); int num_mappings; #endif int i; @@ -2855,15 +2858,25 @@ void SDLInitJoysticks() } #if defined(TARGET_SDL2) - num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file); + num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file_base); if (num_mappings != -1) - Error(ERR_INFO, "%d game controller mapping(s) added", num_mappings); + Error(ERR_INFO, "%d game controller base mapping(s) added", num_mappings); else - Error(ERR_WARN, "no game controller mappings found"); + Error(ERR_WARN, "no game controller base mappings found"); + + num_mappings = SDL_GameControllerAddMappingsFromFile(mappings_file_user); + + if (num_mappings != -1) + Error(ERR_INFO, "%d game controller user mapping(s) added", num_mappings); + else + Error(ERR_WARN, "no game controller user mappings found"); Error(ERR_INFO, "%d joystick(s) found:", SDL_NumJoysticks()); + checked_free(mappings_file_base); + checked_free(mappings_file_user); + for (i = 0; i < SDL_NumJoysticks(); i++) { const char *name, *type; diff --git a/src/libgame/system.h b/src/libgame/system.h index 3fc4eb6c..72a0754e 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -531,6 +531,8 @@ #define TAPEFILE_EXTENSION "tape" #define SCOREFILE_EXTENSION "score" +#define GAMECONTROLLER_BASENAME "gamecontrollerdb.txt" + #define LOG_OUT_BASENAME "stdout.txt" #define LOG_ERR_BASENAME "stderr.txt"