Create RARCH_CTL_DEINIT and RARCH_CTL_INIT

This commit is contained in:
twinaphex 2015-12-07 14:59:09 +01:00
parent 5278cf7e7e
commit c62f6ed26d
3 changed files with 31 additions and 46 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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);