changeset 1604:68b05322d971

Don't redundantly store controller GUID when saving a mapping. Remove illegal chars from controller name
author Michael Pavone <pavone@retrodev.com>
date Tue, 31 Jul 2018 23:19:39 -0700
parents c0727712d529
children f7b1d983d5c0
files controller_info.c nuklear_ui/blastem_nuklear.c
diffstat 2 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/controller_info.c	Tue Jul 31 23:08:52 2018 -0700
+++ b/controller_info.c	Tue Jul 31 23:19:39 2018 -0700
@@ -2,6 +2,7 @@
 #include "render_sdl.h"
 #include "controller_info.h"
 #include "config.h"
+#include "util.h"
 
 typedef struct {
 	char const      *name;
@@ -150,14 +151,19 @@
 	}
 	char *mapping = tern_find_ptr(val.ptrval, "mapping");
 	if (mapping) {
-		SDL_GameControllerAddMapping(mapping);
+		const char *parts[] = {key, ",", mapping};
+		char * full = alloc_concat_m(3, parts);
+		SDL_GameControllerAddMapping(full);
+		free(full);
 	}
 }
 
 void controller_add_mappings(void)
 {
 	load_ctype_config();
-	tern_foreach(info_config, mappings_iter, NULL);
+	if (info_config) {
+		tern_foreach(info_config, mappings_iter, NULL);
+	}
 }
 
 void save_controller_info(int joystick, controller_info *info)
--- a/nuklear_ui/blastem_nuklear.c	Tue Jul 31 23:08:52 2018 -0700
+++ b/nuklear_ui/blastem_nuklear.c	Tue Jul 31 23:19:39 2018 -0700
@@ -839,10 +839,14 @@
 			const char *name = SDL_JoystickName(joy);
 			size_t namesz = strlen(name);
 			mapping_string = malloc(512 + namesz);
-			SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), mapping_string, 33);
-			mapping_string[32] = ',';
-			memcpy(mapping_string + 33, name, namesz);
-			mapping_pos = 33+namesz;
+			for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++)
+			{
+				char c = name[mapping_pos];
+				if (c == ',' || c == '\n' || c == '\r') {
+					c = ' ';
+				}
+				mapping_string[mapping_pos] = c;
+			}
 			
 			push_view(view_controller_mappings);
 		}