changeset 2314:59fd8aa352e2

Apply binding changes after a config change in UI
author Michael Pavone <pavone@retrodev.com>
date Thu, 30 Mar 2023 23:20:12 -0700
parents ef5dc4d02d27
children b67e4e930fa4
files bindings.c bindings.h blastem.c
diffstat 3 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bindings.c	Thu Mar 30 20:20:25 2023 -0700
+++ b/bindings.c	Thu Mar 30 23:20:12 2023 -0700
@@ -1177,8 +1177,10 @@
 		tern_foreach(mice, process_mouse, buttonmaps);
 	}
 	tern_node * speed_nodes = tern_find_path(config, "clocks\0speeds\0", TVAL_NODE).ptrval;
+	free(speeds);
 	speeds = malloc(sizeof(uint32_t));
 	speeds[0] = 100;
+	num_speeds = 1;
 	process_speeds(speed_nodes, NULL);
 	for (int i = 0; i < num_speeds; i++)
 	{
@@ -1189,6 +1191,17 @@
 	}
 }
 
+void update_pad_bindings(void)
+{
+	for (int i = 0; i < MAX_JOYSTICKS; i++)
+	{
+		if (joysticks[i].num_buttons || joysticks[i].num_axes || joysticks[i].num_dpads) {
+			reset_joystick_bindings(i);
+			handle_joy_added(i);
+		}
+	}
+}
+
 void bindings_set_mouse_mode(uint8_t mode)
 {
 	mouse_mode = mode;
--- a/bindings.h	Thu Mar 30 20:20:25 2023 -0700
+++ b/bindings.h	Thu Mar 30 23:20:12 2023 -0700
@@ -10,6 +10,7 @@
 } mouse_modes;
 
 void set_bindings(void);
+void update_pad_bindings(void);
 void bindings_set_mouse_mode(uint8_t mode);
 tern_node *get_binding_node_for_pad(int padnum);
 void handle_keydown(int keycode, uint8_t scancode);
--- a/blastem.c	Thu Mar 30 20:20:25 2023 -0700
+++ b/blastem.c	Thu Mar 30 23:20:12 2023 -0700
@@ -381,6 +381,8 @@
 void apply_updated_config(void)
 {
 	render_config_updated();
+	set_bindings();
+	update_pad_bindings();
 	if (current_system && current_system->config_updated) {
 		current_system->config_updated(current_system);
 	}