Mercurial > repos > blastem
comparison controller_info.c @ 2317:e836cf11783b
Make deadzones configurable and bump up the default value
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 02 Apr 2023 23:21:39 -0700 |
parents | b67e4e930fa4 |
children | 9c6f53425140 |
comparison
equal
deleted
inserted
replaced
2316:523ab225815b | 2317:e836cf11783b |
---|---|
79 if (!loaded) { | 79 if (!loaded) { |
80 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg", NULL); | 80 info_config = load_overrideable_config("controller_types.cfg", "controller_types.cfg", NULL); |
81 loaded = 1; | 81 loaded = 1; |
82 } | 82 } |
83 } | 83 } |
84 | |
85 #define DEFAULT_DEADZONE 4000 | |
86 #define DEFAULT_DEADZONE_STR "4000" | |
84 | 87 |
85 controller_info get_controller_info(int joystick) | 88 controller_info get_controller_info(int joystick) |
86 { | 89 { |
87 #ifndef USE_FBDEV | 90 #ifndef USE_FBDEV |
88 load_ctype_config(); | 91 load_ctype_config(); |
139 break; | 142 break; |
140 } | 143 } |
141 } | 144 } |
142 } | 145 } |
143 res.name = control ? SDL_GameControllerName(control) : SDL_JoystickName(stick); | 146 res.name = control ? SDL_GameControllerName(control) : SDL_JoystickName(stick); |
147 res.stick_deadzone = atoi(tern_find_ptr_default(info, "stick_deadzone", DEFAULT_DEADZONE_STR)); | |
148 res.trigger_deadzone = atoi(tern_find_ptr_default(info, "trigger_deadzone", DEFAULT_DEADZONE_STR)); | |
144 if (control) { | 149 if (control) { |
145 SDL_GameControllerClose(control); | 150 SDL_GameControllerClose(control); |
146 } | 151 } |
147 return res; | 152 return res; |
148 } | 153 } |
149 if (!control) { | 154 if (!control) { |
150 return (controller_info) { | 155 return (controller_info) { |
151 .type = TYPE_UNKNOWN, | 156 .type = TYPE_UNKNOWN, |
152 .subtype = SUBTYPE_UNKNOWN, | 157 .subtype = SUBTYPE_UNKNOWN, |
153 .variant = VARIANT_NORMAL, | 158 .variant = VARIANT_NORMAL, |
154 .name = SDL_JoystickName(stick) | 159 .name = SDL_JoystickName(stick), |
160 .stick_deadzone = DEFAULT_DEADZONE, | |
161 .trigger_deadzone = DEFAULT_DEADZONE | |
155 }; | 162 }; |
156 } | 163 } |
157 const char *name = SDL_GameControllerName(control); | 164 const char *name = SDL_GameControllerName(control); |
158 SDL_GameControllerClose(control); | 165 SDL_GameControllerClose(control); |
159 for (uint32_t i = 0; i < num_heuristics; i++) | 166 for (uint32_t i = 0; i < num_heuristics; i++) |
160 { | 167 { |
161 if (strstr(name, heuristics[i].name)) { | 168 if (strstr(name, heuristics[i].name)) { |
162 controller_info res = heuristics[i].info; | 169 controller_info res = heuristics[i].info; |
163 res.name = name; | 170 res.name = name; |
171 res.stick_deadzone = DEFAULT_DEADZONE; | |
172 res.trigger_deadzone = DEFAULT_DEADZONE; | |
164 return res; | 173 return res; |
165 } | 174 } |
166 } | 175 } |
167 #else | 176 #else |
168 const char *name = "Unknown"; | 177 const char *name = "Unknown"; |
170 //default to a 360 | 179 //default to a 360 |
171 return (controller_info){ | 180 return (controller_info){ |
172 .type = TYPE_GENERIC_MAPPING, | 181 .type = TYPE_GENERIC_MAPPING, |
173 .subtype = SUBTYPE_UNKNOWN, | 182 .subtype = SUBTYPE_UNKNOWN, |
174 .variant = VARIANT_NORMAL, | 183 .variant = VARIANT_NORMAL, |
175 .name = name | 184 .name = name, |
185 .stick_deadzone = DEFAULT_DEADZONE, | |
186 .trigger_deadzone = DEFAULT_DEADZONE | |
176 }; | 187 }; |
177 } | 188 } |
178 | 189 |
179 static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) | 190 static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) |
180 { | 191 { |
206 char guid_string[33]; | 217 char guid_string[33]; |
207 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 218 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
208 tern_node *existing = tern_find_node(info_config, guid_string); | 219 tern_node *existing = tern_find_node(info_config, guid_string); |
209 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); | 220 existing = tern_insert_ptr(existing, "subtype", strdup(subtype_names[info->subtype])); |
210 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); | 221 existing = tern_insert_ptr(existing, "variant", strdup(variant_names[info->variant])); |
222 char buffer[32]; | |
223 snprintf(buffer, sizeof(buffer), "%d", info->stick_deadzone); | |
224 buffer[31] = 0; | |
225 existing = tern_insert_ptr(existing, "stick_deadzone", strdup(buffer)); | |
226 snprintf(buffer, sizeof(buffer), "%d", info->trigger_deadzone); | |
227 buffer[31] = 0; | |
228 existing = tern_insert_ptr(existing, "trigger_deadzone", strdup(buffer)); | |
211 info_config = tern_insert_node(info_config, guid_string, existing); | 229 info_config = tern_insert_node(info_config, guid_string, existing); |
212 persist_config_at(config, info_config, "controller_types.cfg"); | 230 persist_config_at(config, info_config, "controller_types.cfg"); |
213 handle_joy_added(joystick); | 231 handle_joy_added(joystick); |
214 #endif | 232 #endif |
215 } | 233 } |