comparison controller_info.c @ 1852:a4cae960fd08

Allow config file to be saved with executable for "portable" setups
author Michael Pavone <pavone@retrodev.com>
date Wed, 24 Apr 2019 19:08:49 -0700
parents 3a8c4ee68568
children 52f136052ab0
comparison
equal deleted inserted replaced
1851:419b458f93cd 1852:a4cae960fd08
4 #include "render_sdl.h" 4 #include "render_sdl.h"
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 10
10 typedef struct { 11 typedef struct {
11 char const *name; 12 char const *name;
12 controller_info info; 13 controller_info info;
13 } heuristic; 14 } heuristic;
64 }; 65 };
65 66
66 static void load_ctype_config(void) 67 static void load_ctype_config(void)
67 { 68 {
68 if (!loaded) { 69 if (!loaded) {
69 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg"); 70 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg", NULL);
70 loaded = 1; 71 loaded = 1;
71 } 72 }
72 } 73 }
73 74
74 controller_info get_controller_info(int joystick) 75 controller_info get_controller_info(int joystick)
195 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); 196 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
196 tern_node *existing = tern_find_node(info_config, guid_string); 197 tern_node *existing = tern_find_node(info_config, guid_string);
197 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); 198 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]);
198 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); 199 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]);
199 info_config = tern_insert_node(info_config, guid_string, existing); 200 info_config = tern_insert_node(info_config, guid_string, existing);
200 persist_config_at(info_config, "controller_types.cfg"); 201 persist_config_at(config, info_config, "controller_types.cfg");
201 #endif 202 #endif
202 } 203 }
203 204
204 void save_controller_mapping(int joystick, char *mapping_string) 205 void save_controller_mapping(int joystick, char *mapping_string)
205 { 206 {
207 char guid_string[33]; 208 char guid_string[33];
208 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); 209 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string));
209 tern_node *existing = tern_find_node(info_config, guid_string); 210 tern_node *existing = tern_find_node(info_config, guid_string);
210 existing = tern_insert_ptr(existing, "mapping", mapping_string); 211 existing = tern_insert_ptr(existing, "mapping", mapping_string);
211 info_config = tern_insert_node(info_config, guid_string, existing); 212 info_config = tern_insert_node(info_config, guid_string, existing);
212 persist_config_at(info_config, "controller_types.cfg"); 213 persist_config_at(config, info_config, "controller_types.cfg");
213 #endif 214 #endif
214 } 215 }
215 216
216 char const *labels_xbox[] = { 217 char const *labels_xbox[] = {
217 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" 218 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT"