From d6335f0431dd0b57207922bfaf26a65dcc84154b Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 31 Jul 2018 23:08:52 -0700 Subject: Read extral SDL2 mappings on startup from controller_types.cfg --- controller_info.c | 25 ++++++++++++++++++++++++- controller_info.h | 1 + render_sdl.c | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/controller_info.c b/controller_info.c index 630708f..12c90b3 100644 --- a/controller_info.c +++ b/controller_info.c @@ -45,12 +45,18 @@ static const char *variant_names[] = { "6b bumpers", "6b right" }; -controller_info get_controller_info(int joystick) + +static void load_ctype_config(void) { if (!loaded) { info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg"); loaded = 1; } +} + +controller_info get_controller_info(int joystick) +{ + load_ctype_config(); char guid_string[33]; SDL_Joystick *stick = render_get_joystick(joystick); SDL_GameController *control = render_get_controller(joystick); @@ -137,6 +143,23 @@ controller_info get_controller_info(int joystick) }; } +static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) +{ + if (valtype != TVAL_NODE) { + return; + } + char *mapping = tern_find_ptr(val.ptrval, "mapping"); + if (mapping) { + SDL_GameControllerAddMapping(mapping); + } +} + +void controller_add_mappings(void) +{ + load_ctype_config(); + tern_foreach(info_config, mappings_iter, NULL); +} + void save_controller_info(int joystick, controller_info *info) { char guid_string[33]; diff --git a/controller_info.h b/controller_info.h index 51f8891..4c29dec 100644 --- a/controller_info.h +++ b/controller_info.h @@ -45,5 +45,6 @@ const char *get_button_label(controller_info *info, int button); const char *get_axis_label(controller_info *info, int axis); void save_controller_info(int joystick, controller_info *info); void save_controller_mapping(int joystick, char *mapping_string); +void controller_add_mappings(void); #endif //CONTROLLER_INFO_H_ \ No newline at end of file diff --git a/render_sdl.c b/render_sdl.c index 532f11c..ca5cce5 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -16,6 +16,7 @@ #include "ppm.h" #include "png.h" #include "config.h" +#include "controller_info.h" #ifndef DISABLE_OPENGL #include @@ -1141,6 +1142,8 @@ void render_init(int width, int height, char * title, uint8_t fullscreen) printf("Added %d game controller mappings from gamecontrollerdb.txt\n", added); } + controller_add_mappings(); + SDL_JoystickEventState(SDL_ENABLE); render_set_video_standard(VID_NTSC); -- cgit v1.2.3