Mercurial > repos > blastem
comparison controller_info.c @ 1861:fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 03 May 2019 18:56:12 -0700 |
parents | 52f136052ab0 |
children | 8a64d86cc362 |
comparison
equal
deleted
inserted
replaced
1860:bdca98187c9f | 1861:fc05f49075c2 |
---|---|
5 #endif | 5 #endif |
6 #include "controller_info.h" | 6 #include "controller_info.h" |
7 #include "config.h" | 7 #include "config.h" |
8 #include "util.h" | 8 #include "util.h" |
9 #include "blastem.h" | 9 #include "blastem.h" |
10 #include "bindings.h" | |
10 | 11 |
11 typedef struct { | 12 typedef struct { |
12 char const *name; | 13 char const *name; |
13 controller_info info; | 14 controller_info info; |
14 } heuristic; | 15 } heuristic; |
197 tern_node *existing = tern_find_node(info_config, guid_string); | 198 tern_node *existing = tern_find_node(info_config, guid_string); |
198 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); | 199 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); |
199 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); | 200 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); |
200 info_config = tern_insert_node(info_config, guid_string, existing); | 201 info_config = tern_insert_node(info_config, guid_string, existing); |
201 persist_config_at(config, info_config, "controller_types.cfg"); | 202 persist_config_at(config, info_config, "controller_types.cfg"); |
203 handle_joy_added(joystick); | |
202 #endif | 204 #endif |
203 } | 205 } |
204 | 206 |
205 void save_controller_mapping(int joystick, char *mapping_string) | 207 void save_controller_mapping(int joystick, char *mapping_string) |
206 { | 208 { |
209 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 211 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
210 tern_node *existing = tern_find_node(info_config, guid_string); | 212 tern_node *existing = tern_find_node(info_config, guid_string); |
211 existing = tern_insert_ptr(existing, "mapping", mapping_string); | 213 existing = tern_insert_ptr(existing, "mapping", mapping_string); |
212 info_config = tern_insert_node(info_config, guid_string, existing); | 214 info_config = tern_insert_node(info_config, guid_string, existing); |
213 persist_config_at(config, info_config, "controller_types.cfg"); | 215 persist_config_at(config, info_config, "controller_types.cfg"); |
216 const char *parts[] = {guid_string, ",", mapping_string}; | |
217 char * full = alloc_concat_m(3, parts); | |
218 SDL_GameControllerAddMapping(full); | |
219 free(full); | |
220 handle_joy_added(joystick); | |
214 #endif | 221 #endif |
215 } | 222 } |
216 | 223 |
217 char const *labels_xbox[] = { | 224 char const *labels_xbox[] = { |
218 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" | 225 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" |