added using global and personal game controller mapping files
authorHolger Schemel <info@artsoft.org>
Mon, 3 Jul 2017 18:52:19 +0000 (20:52 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 3 Jul 2017 18:52:19 +0000 (20:52 +0200)
src/libgame/sdl.c
src/libgame/system.h

index d6cf2b1779082a6a5b9d418273fe95c91add3ca7..ee43dc05b0c1b1795328b129d1ca0a563f0398e2 100644 (file)
@@ -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;
index 3fc4eb6cd0eb43cbf1b92f6a94713ab2d53bdb4a..72a0754e1b5b5e5ab54904abce54b023eb03d760 100644 (file)
 #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"