diff nuklear_ui/blastem_nuklear.c @ 1573:a051d8ee4528

Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
author Michael Pavone <pavone@retrodev.com>
date Fri, 27 Apr 2018 20:08:47 -0700
parents 5efeca06d942
children ccb3a8ae7ad0
line wrap: on
line diff
--- a/nuklear_ui/blastem_nuklear.c	Tue Apr 24 20:31:18 2018 -0700
+++ b/nuklear_ui/blastem_nuklear.c	Fri Apr 27 20:08:47 2018 -0700
@@ -23,6 +23,7 @@
 static uint32_t view_storage;
 static uint32_t num_prev;
 static struct nk_font *def_font;
+static uint8_t config_dirty;
 
 static void push_view(view_fun new_view)
 {
@@ -486,6 +487,7 @@
 				memcpy(path + prefix_len, name, suffix_len);
 				path[prefix_len + suffix_len] = 0;
 				
+				config_dirty = 1;
 				config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(set_binding)}, TVAL_PTR);
 				free(path);
 				free(name);
@@ -598,6 +600,7 @@
 	nk_label(context, label, NK_TEXT_LEFT);
 	uint8_t newval = nk_check_label(context, "", curval);
 	if (newval != curval) {
+		config_dirty = 1;
 		config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(newval ? "on" : "off")}, TVAL_PTR);
 	}
 }
@@ -616,6 +619,7 @@
 	nk_edit_string(context, NK_EDIT_SIMPLE, buffer, &len, sizeof(buffer)-1, nk_filter_decimal);
 	buffer[len] = 0;
 	if (strcmp(buffer, curstr)) {
+		config_dirty = 1;
 		config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR);
 	}
 }
@@ -630,6 +634,7 @@
 	if (val != curval) {
 		char buffer[12];
 		sprintf(buffer, "%d", val);
+		config_dirty = 1;
 		config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(buffer)}, TVAL_PTR);
 	}
 }
@@ -743,6 +748,7 @@
 	nk_label(context, label, NK_TEXT_LEFT);
 	int32_t next = nk_combo(context, opt_display, num_options, current, 30, nk_vec2(300, 300));
 	if (next != current) {
+		config_dirty = 1;
 		config = tern_insert_path(config, path, (tern_val){.ptrval = strdup(options[next])}, TVAL_PTR);
 	}
 	return next;
@@ -804,6 +810,7 @@
 		uint32_t next_selected = nk_combo(context, (const char **)prog_names, num_progs, selected_prog, 30, nk_vec2(300, 300));
 		if (next_selected != selected_prog) {
 			selected_prog = next_selected;
+			config_dirty = 1;
 			config = tern_insert_path(config, "video\0fragment_shader\0", (tern_val){.ptrval = strdup(progs[next_selected].fragment)}, TVAL_PTR);
 			config = tern_insert_path(config, "video\0vertex_shader\0", (tern_val){.ptrval = strdup(progs[next_selected].vertex)}, TVAL_PTR);
 		}
@@ -1024,6 +1031,11 @@
 		last = current;
 		render_update_display();
 	}
+	if (config_dirty) {
+		apply_updated_config();
+		persist_config(config);
+		config_dirty = 0;
+	}
 }
 static void handle_event(SDL_Event *event)
 {
@@ -1035,7 +1047,7 @@
 
 static void context_destroyed(void)
 {
-	nk_sdl_device_destroy();
+	nk_sdl_shutdown();
 }
 
 static uint32_t *controller_360_buf;
@@ -1067,7 +1079,7 @@
 
 static void context_created(void)
 {
-	nk_sdl_device_create();
+	context = nk_sdl_init(render_get_window());
 	texture_init();
 }