From c62f6ed26d203ef00df40cbaec135c3e39e93ede Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 7 Dec 2015 14:59:09 +0100 Subject: [PATCH] Create RARCH_CTL_DEINIT and RARCH_CTL_INIT --- frontend/frontend.c | 2 +- retroarch.c | 66 ++++++++++++++++----------------------------- retroarch.h | 9 +++++-- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/frontend/frontend.c b/frontend/frontend.c index 6d96ea19b8..b59c5c9e9a 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -264,7 +264,7 @@ int rarch_main(int argc, char *argv[], void *data) rarch_main_alloc(); frontend_driver_init_first(args); - rarch_main_new(); + rarch_ctl(RARCH_CTL_INIT, NULL); #ifdef HAVE_THREADS async_jobs = async_job_new(); diff --git a/retroarch.c b/retroarch.c index d56fc88b75..cede2c8c27 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1067,32 +1067,6 @@ static bool init_state(void) return true; } -static void main_clear_state_drivers(void) -{ - global_t *global = global_get_ptr(); - bool inited = false; - if (!global) - return; - inited = global->inited.main; - if (!inited) - return; - - event_command(EVENT_CMD_DRIVERS_DEINIT); - event_command(EVENT_CMD_DRIVERS_INIT); -} - -static void main_init_state_config(void) -{ - unsigned i; - settings_t *settings = config_get_ptr(); - - if (!settings) - return; - - for (i = 0; i < MAX_USERS; i++) - settings->input.libretro_device[i] = RETRO_DEVICE_JOYPAD; -} - void rarch_main_alloc(void) { if (!config_realloc()) @@ -1103,23 +1077,6 @@ void rarch_main_alloc(void) runloop_ctl(RUNLOOP_CTL_CLEAR_STATE, NULL); } -/** - * rarch_main_new: - * - * Will teardown drivers and clears all - * internal state of the program. - * If @inited is true, will initialize all - * drivers again after teardown. - **/ -void rarch_main_new(void) -{ - main_clear_state_drivers(); - init_state(); - main_init_state_config(); - - runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_INIT, NULL); -} - void rarch_main_free(void) { runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_DEINIT, NULL); @@ -1345,6 +1302,29 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) switch(state) { + case RARCH_CTL_DEINIT: + { + bool inited = false; + if (!global) + return false; + inited = global->inited.main; + if (!inited) + return false; + + event_command(EVENT_CMD_DRIVERS_DEINIT); + event_command(EVENT_CMD_DRIVERS_INIT); + } + return true; + case RARCH_CTL_INIT: + rarch_ctl(RARCH_CTL_DEINIT, NULL); + init_state(); + { + unsigned i; + for (i = 0; i < MAX_USERS; i++) + settings->input.libretro_device[i] = RETRO_DEVICE_JOYPAD; + } + runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_INIT, NULL); + return true; case RARCH_CTL_SET_PATHS_REDIRECT: set_paths_redirect(global->name.base); break; diff --git a/retroarch.h b/retroarch.h index ab17295160..a51039eec7 100644 --- a/retroarch.h +++ b/retroarch.h @@ -54,6 +54,13 @@ enum rarch_ctl_state { RARCH_CTL_NONE = 0, + /* Will teardown drivers and clears all + * internal state of the program. */ + RARCH_CTL_DEINIT, + + /* Initialize all drivers. */ + RARCH_CTL_INIT, + RARCH_CTL_LOAD_CONTENT, #ifdef HAVE_FFMPEG @@ -143,8 +150,6 @@ struct rarch_main_wrap void rarch_main_alloc(void); -void rarch_main_new(void); - void rarch_main_free(void); bool rarch_ctl(enum rarch_ctl_state state, void *data);