From 5477e348157ee3658e8560b0d5d5c59f6bc90fb7 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 29 Oct 2021 17:41:31 +0200 Subject: [PATCH] Move stray globals subsystem_data and subsystem_current_count to runloop_state --- dynamic.h | 9 ------ menu/cbs/menu_cbs_sublabel.c | 9 +++--- menu/menu_displaylist.c | 30 +++++++++++------- retroarch.c | 61 +++++++++++++++++++----------------- runloop.h | 9 ++++++ tasks/task_content.c | 29 +++++++++-------- 6 files changed, 80 insertions(+), 67 deletions(-) diff --git a/dynamic.h b/dynamic.h index 76169e327c..fdba9730b7 100644 --- a/dynamic.h +++ b/dynamic.h @@ -94,15 +94,6 @@ struct retro_core_t bool libretro_get_shared_context(void); -/* Arbitrary twenty subsystems limite */ -#define SUBSYSTEM_MAX_SUBSYSTEMS 20 -/* Arbitrary 10 roms for each subsystem limit */ -#define SUBSYSTEM_MAX_SUBSYSTEM_ROMS 10 - -/* TODO/FIXME - globals */ -extern struct retro_subsystem_info subsystem_data[SUBSYSTEM_MAX_SUBSYSTEMS]; -extern unsigned subsystem_current_count; - RETRO_END_DECLS #endif diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 2805f21d7e..111f533c1e 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -1094,17 +1094,18 @@ static int action_bind_sublabel_subsystem_add( const char *label, const char *path, char *s, size_t len) { - const struct retro_subsystem_info *subsystem; - rarch_system_info_t *system = &runloop_state_get_ptr()->system; + const struct retro_subsystem_info *subsystem = NULL; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) subsystem = system->subsystem.data + (type - MENU_SETTINGS_SUBSYSTEM_ADD); /* Core not loaded completely, use the data we peeked on load core */ else - subsystem = subsystem_data + (type - MENU_SETTINGS_SUBSYSTEM_ADD); + subsystem = runloop_st->subsystem_data + (type - MENU_SETTINGS_SUBSYSTEM_ADD); - if (subsystem && subsystem_current_count > 0) + if (subsystem && runloop_st->subsystem_current_count > 0) { if (content_get_subsystem_rom_id() < subsystem->num_roms) snprintf(s, len, " Current Content: %s", diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index a25061c123..6e33089330 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -192,15 +192,16 @@ static void filebrowser_parse( { if (filebrowser_type == FILEBROWSER_SELECT_FILE_SUBSYSTEM) { - rarch_system_info_t *system = &runloop_state_get_ptr()->system; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) subsystem = system->subsystem.data + content_get_subsystem(); /* Core not loaded completely, use the data we peeked on load core */ else - subsystem = subsystem_data + content_get_subsystem(); + subsystem = runloop_st->subsystem_data + content_get_subsystem(); - if (subsystem && subsystem_current_count > 0) + if (subsystem && runloop_st->subsystem_current_count > 0) ret = file_archive_get_file_list_noalloc(&str_list, path, subsystem->roms[ @@ -222,15 +223,16 @@ static void filebrowser_parse( if (filebrowser_type == FILEBROWSER_SELECT_FILE_SUBSYSTEM) { - rarch_system_info_t *system = &runloop_state_get_ptr()->system; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) subsystem = system->subsystem.data + content_get_subsystem(); /* Core not loaded completely, use the data we peeked on load core */ else - subsystem = subsystem_data + content_get_subsystem(); + subsystem = runloop_st->subsystem_data + content_get_subsystem(); - if (subsystem && subsystem_current_count > 0 && content_get_subsystem_rom_id() < subsystem->num_roms) + if (subsystem && runloop_st->subsystem_current_count > 0 && content_get_subsystem_rom_id() < subsystem->num_roms) ret = dir_list_initialize(&str_list, path, filter_ext ? subsystem->roms[content_get_subsystem_rom_id()].valid_extensions : NULL, @@ -5337,7 +5339,9 @@ static unsigned menu_displaylist_populate_subsystem( if (menu_displaylist_has_subsystems()) { - for (i = 0; i < subsystem_current_count; i++, subsystem++) + runloop_state_t *runloop_st = runloop_state_get_ptr(); + + for (i = 0; i < runloop_st->subsystem_current_count; i++, subsystem++) { char s[PATH_MAX_LENGTH]; if (content_get_subsystem() == i) @@ -5499,8 +5503,9 @@ unsigned menu_displaylist_build_list( { case DISPLAYLIST_SUBSYSTEM_SETTINGS_LIST: { - const struct retro_subsystem_info* subsystem = subsystem_data; - rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + const struct retro_subsystem_info* subsystem = runloop_st->subsystem_data; + rarch_system_info_t *sys_info = &runloop_st->system; /* Core not loaded completely, use the data we * peeked on load core */ @@ -9822,14 +9827,15 @@ static unsigned print_buf_lines(file_list_t *list, char *buf, bool menu_displaylist_has_subsystems(void) { - const struct retro_subsystem_info* subsystem = subsystem_data; - rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + const struct retro_subsystem_info* subsystem = runloop_st->subsystem_data; + rarch_system_info_t *sys_info = &runloop_st->system; /* Core not loaded completely, use the data we * peeked on load core */ /* Core fully loaded, use the subsystem data */ if (sys_info && sys_info->subsystem.data) subsystem = sys_info->subsystem.data; - return (subsystem && subsystem_current_count > 0); + return (subsystem && runloop_st->subsystem_current_count > 0); } bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, diff --git a/retroarch.c b/retroarch.c index 7392f419fe..5b0c709494 100644 --- a/retroarch.c +++ b/retroarch.c @@ -309,10 +309,8 @@ struct aspect_ratio_elem aspectratio_lut[ASPECT_RATIO_END] = { #ifdef HAVE_DISCORD bool discord_is_inited = false; #endif -unsigned subsystem_current_count = 0; struct retro_keybind input_config_binds[MAX_USERS][RARCH_BIND_LIST_END]; struct retro_keybind input_autoconf_binds[MAX_USERS][RARCH_BIND_LIST_END]; -struct retro_subsystem_info subsystem_data[SUBSYSTEM_MAX_SUBSYSTEMS]; static runloop_core_status_msg_t runloop_core_status_msg = { @@ -6434,8 +6432,8 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_LOAD_CORE: { - bool success = false; - subsystem_current_count = 0; + bool success = false; + runloop_st->subsystem_current_count = 0; content_clear_subsystem(); success = command_event(CMD_EVENT_LOAD_CORE_PERSIST, NULL); (void)success; @@ -6660,7 +6658,7 @@ bool command_event(enum event_command cmd, void *data) } if (is_inited) { - subsystem_current_count = 0; + runloop_st->subsystem_current_count = 0; content_clear_subsystem(); } } @@ -8625,7 +8623,7 @@ static bool runloop_environ_cb_get_system_info(unsigned cmd, void *data) settings_t *settings = config_get_ptr(); unsigned log_level = settings->uints.libretro_log_level; - subsystem_current_count = 0; + runloop_st->subsystem_current_count = 0; RARCH_LOG("[Environ]: SET_SUBSYSTEM_INFO.\n"); @@ -8661,47 +8659,52 @@ static bool runloop_environ_cb_get_system_info(unsigned cmd, void *data) { for (i = 0; i < size && i < SUBSYSTEM_MAX_SUBSYSTEMS; i++) { + struct retro_subsystem_info *subsys_info = &runloop_st->subsystem_data[i]; + struct retro_subsystem_rom_info *subsys_rom_info = runloop_st->subsystem_data_roms[i]; /* Nasty, but have to do it like this since * the pointers are const char * * (if we don't free them, we get a memory leak) */ - if (!string_is_empty(subsystem_data[i].desc)) - free((char *)subsystem_data[i].desc); - if (!string_is_empty(subsystem_data[i].ident)) - free((char *)subsystem_data[i].ident); - subsystem_data[i].desc = strdup(info[i].desc); - subsystem_data[i].ident = strdup(info[i].ident); - subsystem_data[i].id = info[i].id; - subsystem_data[i].num_roms = info[i].num_roms; + if (!string_is_empty(subsys_info->desc)) + free((char *)subsys_info->desc); + if (!string_is_empty(subsys_info->ident)) + free((char *)subsys_info->ident); + subsys_info->desc = strdup(info[i].desc); + subsys_info->ident = strdup(info[i].ident); + subsys_info->id = info[i].id; + subsys_info->num_roms = info[i].num_roms; if (log_level == RETRO_LOG_DEBUG) - if (subsystem_data[i].num_roms > SUBSYSTEM_MAX_SUBSYSTEM_ROMS) + if (subsys_info->num_roms > SUBSYSTEM_MAX_SUBSYSTEM_ROMS) RARCH_WARN("Subsystems exceed subsystem max roms, clamping to %d\n", SUBSYSTEM_MAX_SUBSYSTEM_ROMS); - for (j = 0; j < subsystem_data[i].num_roms && j < SUBSYSTEM_MAX_SUBSYSTEM_ROMS; j++) + for (j = 0; j < subsys_info->num_roms && j < SUBSYSTEM_MAX_SUBSYSTEM_ROMS; j++) { /* Nasty, but have to do it like this since * the pointers are const char * * (if we don't free them, we get a memory leak) */ - if (!string_is_empty( - runloop_st->subsystem_data_roms[i][j].desc)) + if (!string_is_empty(subsys_rom_info[j].desc)) free((char *) - runloop_st->subsystem_data_roms[i][j].desc); + subsys_rom_info[j].desc); if (!string_is_empty( - runloop_st->subsystem_data_roms[i][j].valid_extensions)) + subsys_rom_info[j].valid_extensions)) free((char *) - runloop_st->subsystem_data_roms[i][j].valid_extensions); - runloop_st->subsystem_data_roms[i][j].desc = strdup(info[i].roms[j].desc); - runloop_st->subsystem_data_roms[i][j].valid_extensions = strdup(info[i].roms[j].valid_extensions); - runloop_st->subsystem_data_roms[i][j].required = info[i].roms[j].required; - runloop_st->subsystem_data_roms[i][j].block_extract = info[i].roms[j].block_extract; - runloop_st->subsystem_data_roms[i][j].need_fullpath = info[i].roms[j].need_fullpath; + subsys_rom_info[j].valid_extensions); + subsys_rom_info[j].desc = + strdup(info[i].roms[j].desc); + subsys_rom_info[j].valid_extensions = + strdup(info[i].roms[j].valid_extensions); + subsys_rom_info[j].required = + info[i].roms[j].required; + subsys_rom_info[j].block_extract = + info[i].roms[j].block_extract; + subsys_rom_info[j].need_fullpath = + info[i].roms[j].need_fullpath; } - subsystem_data[i].roms = - runloop_st->subsystem_data_roms[i]; + subsys_info->roms = subsys_rom_info; } - subsystem_current_count = + runloop_st->subsystem_current_count = size <= SUBSYSTEM_MAX_SUBSYSTEMS ? size : SUBSYSTEM_MAX_SUBSYSTEMS; diff --git a/runloop.h b/runloop.h index 45de86d32c..0e783e285e 100644 --- a/runloop.h +++ b/runloop.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifdef HAVE_CONFIG_H @@ -38,6 +39,12 @@ #include "core_option_manager.h" #include "state_manager.h" +/* Arbitrary twenty subsystems limit */ +#define SUBSYSTEM_MAX_SUBSYSTEMS 20 + +/* Arbitrary 10 roms for each subsystem limit */ +#define SUBSYSTEM_MAX_SUBSYSTEM_ROMS 10 + enum runloop_state_enum { RUNLOOP_STATE_ITERATE = 0, @@ -143,6 +150,7 @@ struct runloop struct retro_perf_counter *perf_counters_libretro[MAX_COUNTERS]; bool *load_no_content_hook; struct string_list *subsystem_fullpaths; + struct retro_subsystem_info subsystem_data[SUBSYSTEM_MAX_SUBSYSTEMS]; struct retro_callbacks retro_ctx; /* ptr alignment */ msg_queue_t msg_queue; /* ptr alignment */ retro_input_state_t input_state_callback_original; /* ptr alignment */ @@ -189,6 +197,7 @@ struct runloop unsigned audio_latency; unsigned fastforward_after_frames; unsigned perf_ptr_libretro; + unsigned subsystem_current_count; fastmotion_overrides_t fastmotion_override; /* float alignment */ enum rarch_core_type current_core_type; diff --git a/tasks/task_content.c b/tasks/task_content.c index 9a941ad677..ed3d9c5fa9 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -2597,20 +2597,21 @@ void content_clear_subsystem(void) /* Set the current subsystem*/ void content_set_subsystem(unsigned idx) { - const struct retro_subsystem_info *subsystem; - rarch_system_info_t *system = &runloop_state_get_ptr()->system; + const struct retro_subsystem_info *subsystem = NULL; + runloop_state_t *runloop_st = runloop_state_get_ptr(); content_state_t *p_content = content_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) - subsystem = system->subsystem.data + idx; + subsystem = system->subsystem.data + idx; /* Core not loaded completely, use the data we peeked on load core */ else - subsystem = subsystem_data + idx; + subsystem = runloop_st->subsystem_data + idx; p_content->pending_subsystem_id = idx; - if (subsystem && subsystem_current_count > 0) + if (subsystem && runloop_st->subsystem_current_count > 0) { strlcpy(p_content->pending_subsystem_ident, subsystem->ident, sizeof(p_content->pending_subsystem_ident)); @@ -2627,17 +2628,18 @@ void content_set_subsystem(unsigned idx) /* Sets the subsystem by name */ bool content_set_subsystem_by_name(const char* subsystem_name) { - rarch_system_info_t *system = &runloop_state_get_ptr()->system; - unsigned i = 0; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; + unsigned i = 0; /* Core not loaded completely, use the data we peeked on load core */ const struct retro_subsystem_info - *subsystem = subsystem_data; + *subsystem = runloop_st->subsystem_data; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) - subsystem = system->subsystem.data; + subsystem = system->subsystem.data; - for (i = 0; i < subsystem_current_count; i++, subsystem++) + for (i = 0; i < runloop_st->subsystem_current_count; i++, subsystem++) { if (string_is_equal(subsystem_name, subsystem->ident)) { @@ -2651,16 +2653,17 @@ bool content_set_subsystem_by_name(const char* subsystem_name) void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsystem_friendly_name, size_t len) { - rarch_system_info_t *system = &runloop_state_get_ptr()->system; unsigned i = 0; + runloop_state_t *runloop_st = runloop_state_get_ptr(); + rarch_system_info_t *system = &runloop_st->system; /* Core not loaded completely, use the data we peeked on load core */ - const struct retro_subsystem_info *subsystem = subsystem_data; + const struct retro_subsystem_info *subsystem = runloop_st->subsystem_data; /* Core fully loaded, use the subsystem data */ if (system->subsystem.data) subsystem = system->subsystem.data; - for (i = 0; i < subsystem_current_count; i++, subsystem++) + for (i = 0; i < runloop_st->subsystem_current_count; i++, subsystem++) { if (string_is_equal(subsystem_name, subsystem->ident)) {