From e996e3df453b01f31359973332c26a8e605b8839 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 3 Oct 2014 11:59:24 +0200 Subject: [PATCH] Move more stuff to rarch_main_command --- general.h | 7 ++++ retroarch.c | 96 +++++++++++++++++++++++++---------------------------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/general.h b/general.h index 34b180a76c..1f0392e5c1 100644 --- a/general.h +++ b/general.h @@ -134,6 +134,13 @@ enum basic_event RARCH_CMD_SHADERS_APPLY_CHANGES, RARCH_CMD_SHADER_DIR_INIT, RARCH_CMD_SHADER_DIR_DEINIT, + RARCH_CMD_CONTROLLERS_INIT, + RARCH_CMD_SAVEFILES_INIT, + RARCH_CMD_SAVEFILES_DEINIT, + RARCH_CMD_MSG_QUEUE_INIT, + RARCH_CMD_MSG_QUEUE_DEINIT, + RARCH_CMD_CHEATS_INIT, + RARCH_CMD_CHEATS_DEINIT, }; enum action_state diff --git a/retroarch.c b/retroarch.c index 3da5728ac2..081bb6ff6e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1127,20 +1127,6 @@ static inline bool save_files(void) return true; } - -static void init_msg_queue(void) -{ - if (!g_extern.msg_queue) - rarch_assert(g_extern.msg_queue = msg_queue_new(8)); -} - -static void deinit_msg_queue(void) -{ - if (g_extern.msg_queue) - msg_queue_free(g_extern.msg_queue); - g_extern.msg_queue = NULL; -} - static void init_cheats(void) { bool allow_cheats = true; @@ -1156,13 +1142,6 @@ static void init_cheats(void) g_extern.cheat = cheat_manager_new(g_settings.cheat_database); } -static void deinit_cheats(void) -{ - if (g_extern.cheat) - cheat_manager_free(g_extern.cheat); - g_extern.cheat = NULL; -} - static void init_rewind(void) { void *state = NULL; @@ -2392,13 +2371,6 @@ static void deinit_subsystem_fullpaths(void) g_extern.subsystem_fullpaths = NULL; } -static void history_playlist_free(void) -{ - if (g_extern.history) - content_playlist_free(g_extern.history); - g_extern.history = NULL; -} - static void main_clear_state_extern(void) { /* XXX This memset is really dangerous. @@ -2413,7 +2385,7 @@ static void main_clear_state_extern(void) rarch_main_command(RARCH_CMD_RECORD_DEINIT); deinit_log_file(); - history_playlist_free(); + rarch_main_command(RARCH_CMD_HISTORY_DEINIT); memset(&g_extern, 0, sizeof(g_extern)); } @@ -2442,13 +2414,12 @@ static void main_clear_state(bool inited) void rarch_main_state_new(void) { main_clear_state(g_extern.main_is_init); - - init_msg_queue(); + rarch_main_command(RARCH_CMD_MSG_QUEUE_INIT); } void rarch_main_state_free(void) { - deinit_msg_queue(); + rarch_main_command(RARCH_CMD_MSG_QUEUE_DEINIT); deinit_log_file(); main_clear_state(false); @@ -2530,7 +2501,7 @@ static void validate_cpu_features(void) #endif } -static void init_sram(void) +static void init_savefiles(void) { g_extern.use_sram = g_extern.use_sram && !g_extern.sram_save_disable #ifdef HAVE_NETPLAY @@ -2630,13 +2601,10 @@ int rarch_main_init(int argc, char *argv[]) #endif rarch_main_command(RARCH_CMD_REWIND_INIT); - init_controllers(); - + rarch_main_command(RARCH_CMD_CONTROLLERS_INIT); rarch_main_command(RARCH_CMD_RECORD_INIT); - - init_sram(); - - init_cheats(); + rarch_main_command(RARCH_CMD_SAVEFILES_INIT); + rarch_main_command(RARCH_CMD_CHEATS_INIT); g_extern.error_in_init = false; g_extern.main_is_init = true; @@ -2859,9 +2827,6 @@ static void history_playlist_new(void) { bool init_history = true; - if (g_extern.history) - return; - if (!path_file_exists(g_settings.content_history_path)) init_history = write_empty_file( g_settings.content_history_path); @@ -2910,14 +2875,18 @@ void rarch_main_command(unsigned cmd) #endif main_state(cmd); break; + case RARCH_CMD_CONTROLLERS_INIT: + init_controllers(); + break; case RARCH_CMD_RESET: RARCH_LOG(RETRO_LOG_RESETTING_CONTENT); msg_queue_clear(g_extern.msg_queue); msg_queue_push(g_extern.msg_queue, "Reset.", 1, 120); pretro_reset(); + /* bSNES since v073r01 resets controllers to JOYPAD * after a reset, so just enforce it here. */ - init_controllers(); + rarch_main_command(RARCH_CMD_CONTROLLERS_INIT); break; case RARCH_CMD_SAVE_STATE: if (g_settings.savestate_auto_index) @@ -2952,6 +2921,15 @@ void rarch_main_command(unsigned cmd) /* Poll input to avoid possibly stale data to corrupt things. */ driver.input->poll(driver.input_data); break; + case RARCH_CMD_CHEATS_INIT: + rarch_main_command(RARCH_CMD_CHEATS_DEINIT); + init_cheats(); + break; + case RARCH_CMD_CHEATS_DEINIT: + if (g_extern.cheat) + cheat_manager_free(g_extern.cheat); + g_extern.cheat = NULL; + break; case RARCH_CMD_REWIND_DEINIT: deinit_rewind(); break; @@ -3053,11 +3031,14 @@ void rarch_main_command(unsigned cmd) rarch_main_command(RARCH_CMD_GPU_RECORD_DEINIT); break; - case RARCH_CMD_HISTORY_INIT: - history_playlist_new(); - break; case RARCH_CMD_HISTORY_DEINIT: - history_playlist_free(); + if (g_extern.history) + content_playlist_free(g_extern.history); + g_extern.history = NULL; + break; + case RARCH_CMD_HISTORY_INIT: + rarch_main_command(RARCH_CMD_HISTORY_DEINIT); + history_playlist_new(); break; case RARCH_CMD_CORE_INFO_INIT: if (g_extern.core_info) @@ -3178,6 +3159,22 @@ void rarch_main_command(unsigned cmd) g_extern.shader_dir.list = NULL; g_extern.shader_dir.ptr = 0; break; + case RARCH_CMD_SAVEFILES_INIT: + init_savefiles(); + break; + case RARCH_CMD_SAVEFILES_DEINIT: + save_files(); + break; + case RARCH_CMD_MSG_QUEUE_DEINIT: + if (g_extern.msg_queue) + msg_queue_free(g_extern.msg_queue); + g_extern.msg_queue = NULL; + break; + case RARCH_CMD_MSG_QUEUE_INIT: + rarch_main_command(RARCH_CMD_MSG_QUEUE_DEINIT); + if (!g_extern.msg_queue) + rarch_assert(g_extern.msg_queue = msg_queue_new(8)); + break; } } @@ -3342,11 +3339,10 @@ void rarch_main_deinit(void) #endif rarch_main_command(RARCH_CMD_RECORD_DEINIT); - - save_files(); + rarch_main_command(RARCH_CMD_SAVEFILES_DEINIT); rarch_main_command(RARCH_CMD_REWIND_DEINIT); - deinit_cheats(); + rarch_main_command(RARCH_CMD_CHEATS_DEINIT); deinit_movie();