From 2d158b809cc5ff0495a76044d36b44f2c4f27fe3 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 4 Mar 2016 19:29:22 +0100 Subject: [PATCH] Cleanups --- command_event.c | 4 ++-- content.c | 4 ++-- dynamic.c | 28 ++++++++++++++-------------- menu/menu_setting.c | 22 +++++++++++----------- retroarch.c | 4 ++-- runloop.c | 14 ++++++++------ system.h | 14 ++++++++++---- 7 files changed, 49 insertions(+), 41 deletions(-) diff --git a/command_event.c b/command_event.c index c6a6454bdb..a9c80012cd 100644 --- a/command_event.c +++ b/command_event.c @@ -340,9 +340,9 @@ static void event_init_controllers(void) const struct retro_controller_description *desc = NULL; unsigned device = settings->input.libretro_device[i]; - if (i < info->num_ports) + if (i < info->ports.size) desc = libretro_find_controller_description( - &info->ports[i], device); + &info->ports.data[i], device); if (desc) ident = desc->desc; diff --git a/content.c b/content.c index e4f13b41ea..3bb8ba8cc1 100644 --- a/content.c +++ b/content.c @@ -1444,8 +1444,8 @@ static const struct retro_subsystem_info *init_content_file_subsystem( { global_t *global = global_get_ptr(); const struct retro_subsystem_info *special = - libretro_find_subsystem_info(system->special, - system->num_special, global->subsystem); + libretro_find_subsystem_info(system->subsystem.data, + system->subsystem.size, global->subsystem); if (!special) { diff --git a/dynamic.c b/dynamic.c index 8272419a51..b03560ba87 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1133,16 +1133,16 @@ bool rarch_environment_cb(unsigned cmd, void *data) } } - free(system->special); - system->special = (struct retro_subsystem_info*) - calloc(i, sizeof(*system->special)); + free(system->subsystem.data); + system->subsystem.data = (struct retro_subsystem_info*) + calloc(i, sizeof(*system->subsystem.data)); - if (!system->special) + if (!system->subsystem.data) return false; - memcpy(system->special, info, - i * sizeof(*system->special)); - system->num_special = i; + memcpy(system->subsystem.data, info, + i * sizeof(*system->subsystem.data)); + system->subsystem.size = i; break; } @@ -1162,15 +1162,15 @@ bool rarch_environment_cb(unsigned cmd, void *data) info[i].types[j].id); } - free(system->ports); - system->ports = (struct retro_controller_info*) - calloc(i, sizeof(*system->ports)); - if (!system->ports) + free(system->ports.data); + system->ports.data = (struct retro_controller_info*) + calloc(i, sizeof(*system->ports.data)); + if (!system->ports.data) return false; - memcpy(system->ports, info, - i * sizeof(*system->ports)); - system->num_ports = i; + memcpy(system->ports.data, info, + i * sizeof(*system->ports.data)); + system->ports.size = i; break; } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index e8b3b17ad8..dbb3fdf9a8 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -1003,9 +1003,9 @@ static void setting_get_string_representation_uint_libretro_device(void *data, index_offset = menu_setting_get_index_offset(setting); - if (index_offset < system->num_ports) + if (index_offset < system->ports.size) desc = libretro_find_controller_description( - &system->ports[index_offset], + &system->ports.data[index_offset], settings->input.libretro_device [index_offset]); @@ -2235,11 +2235,11 @@ static int setting_action_start_libretro_device_type(void *data) /* Only push RETRO_DEVICE_ANALOG as default if we use an * older core which doesn't use SET_CONTROLLER_INFO. */ - if (!system->num_ports) + if (!system->ports.size) devices[types++] = RETRO_DEVICE_ANALOG; - desc = port < system->num_ports ? - &system->ports[port] : NULL; + desc = port < system->ports.size ? + &system->ports.data[port] : NULL; if (desc) { @@ -2385,11 +2385,11 @@ static int setting_action_left_libretro_device_type( /* Only push RETRO_DEVICE_ANALOG as default if we use an * older core which doesn't use SET_CONTROLLER_INFO. */ - if (!system->num_ports) + if (!system->ports.size) devices[types++] = RETRO_DEVICE_ANALOG; - if (port < system->num_ports) - desc = &system->ports[port]; + if (port < system->ports.size) + desc = &system->ports.data[port]; if (desc) { @@ -2450,11 +2450,11 @@ static int setting_action_right_libretro_device_type( /* Only push RETRO_DEVICE_ANALOG as default if we use an * older core which doesn't use SET_CONTROLLER_INFO. */ - if (!system->num_ports) + if (!system->ports.size) devices[types++] = RETRO_DEVICE_ANALOG; - if (port < system->num_ports) - desc = &system->ports[port]; + if (port < system->ports.size) + desc = &system->ports.data[port]; if (desc) { diff --git a/retroarch.c b/retroarch.c index e383479728..2a6b9747a2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1033,8 +1033,8 @@ static void rarch_init_savefile_paths(void) unsigned i, j; const struct retro_subsystem_info *info = libretro_find_subsystem_info( - system->special, - system->num_special, + system->subsystem.data, + system->subsystem.size, global->subsystem); /* We'll handle this error gracefully later. */ diff --git a/runloop.c b/runloop.c index 7602c96dcf..39a02cc0cc 100644 --- a/runloop.c +++ b/runloop.c @@ -499,12 +499,14 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) runloop_system.core_options = NULL; /* No longer valid. */ - if (runloop_system.special) - free(runloop_system.special); - runloop_system.special = NULL; - if (runloop_system.ports) - free(runloop_system.ports); - runloop_system.ports = NULL; + if (runloop_system.subsystem.data) + free(runloop_system.subsystem.data); + runloop_system.subsystem.data = NULL; + if (runloop_system.ports.data) + free(runloop_system.ports.data); + runloop_system.subsystem.size = 0; + runloop_system.ports.data = NULL; + runloop_system.ports.size = 0; runloop_key_event = NULL; runloop_frontend_key_event = NULL; diff --git a/system.h b/system.h index 72742b4247..18d90481c4 100644 --- a/system.h +++ b/system.h @@ -47,11 +47,17 @@ typedef struct rarch_system_info core_option_manager_t *core_options; - struct retro_subsystem_info *special; - unsigned num_special; + struct + { + struct retro_subsystem_info *data; + unsigned size; + } subsystem; - struct retro_controller_info *ports; - unsigned num_ports; + struct + { + struct retro_controller_info *data; + unsigned size; + } ports; } rarch_system_info_t; #ifdef __cplusplus