From 15f3f79732ad7cbebdebf57c634da3a30c725efb Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 2 Aug 2014 04:11:06 +0200 Subject: [PATCH] Refactor rarch_init_autosave/rarch_deinit_autosave --- general.h | 3 +-- retroarch.c | 19 +++++++++++++------ settings_data.c | 16 ++++++---------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/general.h b/general.h index 0ce17b1baf..48e500d594 100644 --- a/general.h +++ b/general.h @@ -101,6 +101,7 @@ enum basic_event RARCH_CMD_QUIT, RARCH_CMD_REINIT, RARCH_CMD_REWIND, + RARCH_CMD_AUTOSAVE, }; enum menu_enums @@ -786,8 +787,6 @@ void rarch_disk_control_set_eject(bool state, bool log); void rarch_disk_control_set_index(unsigned index); void rarch_disk_control_append_image(const char *path); bool rarch_set_rumble_state(unsigned port, enum retro_rumble_effect effect, bool enable); -void rarch_init_autosave(void); -void rarch_deinit_autosave(void); #ifdef HAVE_RECORD void rarch_init_recording(void); diff --git a/retroarch.c b/retroarch.c index 0a3fcaaf18..4a1b9bb3b1 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1699,7 +1699,7 @@ static void init_libretro_cbs(void) } #if defined(HAVE_THREADS) -void rarch_init_autosave(void) +static void init_autosave(void) { unsigned i; @@ -1729,7 +1729,7 @@ void rarch_init_autosave(void) } } -void rarch_deinit_autosave(void) +static void deinit_autosave(void) { unsigned i; for (i = 0; i < g_extern.num_autosave; i++) @@ -2483,7 +2483,7 @@ void rarch_disk_control_append_image(const char *path) msg_queue_push(g_extern.msg_queue, msg, 0, 180); #if defined(HAVE_THREADS) - rarch_deinit_autosave(); + deinit_autosave(); #endif // TODO: Need to figure out what to do with subsystems case. @@ -2498,7 +2498,7 @@ void rarch_disk_control_append_image(const char *path) } #if defined(HAVE_THREADS) - rarch_init_autosave(); + init_autosave(); #endif rarch_disk_control_set_eject(false, false); @@ -2922,7 +2922,7 @@ static void init_sram(void) #if defined(HAVE_THREADS) if (g_extern.use_sram) - rarch_init_autosave(); + init_autosave(); #endif } @@ -3151,6 +3151,13 @@ void rarch_main_command(unsigned action) else deinit_rewind(); break; + case RARCH_CMD_AUTOSAVE: +#ifdef HAVE_THREADS + deinit_autosave(); + if (g_settings.autosave_interval) + init_autosave(); +#endif + break; } } @@ -3284,7 +3291,7 @@ void rarch_main_deinit(void) #if defined(HAVE_THREADS) if (g_extern.use_sram) - rarch_deinit_autosave(); + deinit_autosave(); #endif #ifdef HAVE_RECORD diff --git a/settings_data.c b/settings_data.c index 6f258128ca..2bd6669b67 100644 --- a/settings_data.c +++ b/settings_data.c @@ -977,8 +977,9 @@ static void general_read_handler(const void *data) static void general_write_handler(const void *data) { - bool has_set_reinit = false; - bool has_set_rewind = false; + bool has_set_reinit = false; + bool has_set_rewind = false; + bool has_set_autosave = false; const rarch_setting_t *setting = (const rarch_setting_t*)data; if (!setting) @@ -1127,14 +1128,8 @@ static void general_write_handler(const void *data) g_settings.fastforward_ratio = *setting->value.fraction; else if (!strcmp(setting->name, "autosave_interval")) { -#ifdef HAVE_THREADS - rarch_deinit_autosave(); -#endif g_settings.autosave_interval = *setting->value.unsigned_integer; -#ifdef HAVE_THREADS - if (g_settings.autosave_interval) - rarch_init_autosave(); -#endif + has_set_autosave = true; } else if (!strcmp(setting->name, "video_font_enable")) g_settings.video.font_enable = *setting->value.boolean; @@ -1339,9 +1334,10 @@ static void general_write_handler(const void *data) if (has_set_reinit) rarch_main_command(RARCH_CMD_REINIT); - if (has_set_rewind) rarch_main_command(RARCH_CMD_REWIND); + if (has_set_autosave) + rarch_main_command(RARCH_CMD_AUTOSAVE); } #define NEXT (list[index++])