From 50cbf732b51ada4e6ce2a8f425540e701f7721dd Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 20 Jan 2018 15:48:57 -0800 Subject: [PATCH] GUI: Make autosave configurable --- src/feature/gui/gui-config.c | 20 ++++++++++++++++++++ src/feature/gui/gui-runner.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/feature/gui/gui-config.c b/src/feature/gui/gui-config.c index d6e377277..a0572903a 100644 --- a/src/feature/gui/gui-config.c +++ b/src/feature/gui/gui-config.c @@ -47,6 +47,26 @@ void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t }, .nStates = 2 }; + *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { + .title = "Autosave state", + .data = "autosave", + .submenu = 0, + .state = true, + .validStates = (const char*[]) { + "Off", "On" + }, + .nStates = 2 + }; + *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { + .title = "Autoload state", + .data = "autoload", + .submenu = 0, + .state = true, + .validStates = (const char*[]) { + "Off", "On" + }, + .nStates = 2 + }; *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { .title = "Use BIOS if found", .data = "useBios", diff --git a/src/feature/gui/gui-runner.c b/src/feature/gui/gui-runner.c index e4a589861..f92a33816 100644 --- a/src/feature/gui/gui-runner.c +++ b/src/feature/gui/gui-runner.c @@ -135,6 +135,12 @@ static uint8_t _readLux(struct GBALuminanceSource* lux) { } static void _tryAutosave(struct mGUIRunner* runner) { + int autosave = false; + mCoreConfigGetIntValue(&runner->config, "autosave", &autosave); + if (!autosave) { + return; + } + #ifdef DISABLE_THREADING mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); #else @@ -168,6 +174,12 @@ void mGUIInit(struct mGUIRunner* runner, const char* port) { // TODO: Do we need to load more defaults? mCoreConfigSetDefaultIntValue(&runner->config, "volume", 0x100); mCoreConfigSetDefaultValue(&runner->config, "idleOptimization", "detect"); + mCoreConfigSetDefaultIntValue(&runner->config, "autoload", true); +#ifdef DISABLE_THREADING + mCoreConfigSetDefaultIntValue(&runner->config, "autosave", false); +#else + mCoreConfigSetDefaultIntValue(&runner->config, "autosave", true); +#endif mCoreConfigLoad(&runner->config); mCoreConfigGetIntValue(&runner->config, "logLevel", &logger.logLevel); @@ -352,10 +364,11 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { runner->core->reset(runner->core); mLOG(GUI_RUNNER, DEBUG, "Reset!"); - if (mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC)) { - struct VFile* autosave = mCoreGetState(runner->core, 0, true); - autosave->truncate(autosave, 0); - autosave->close(autosave); + + int autoload = false; + mCoreConfigGetIntValue(&runner->config, "autoload", &autoload); + if (autoload) { + mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC); } bool running = true; @@ -516,6 +529,13 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { runner->autosave.core = NULL; MutexUnlock(&runner->autosave.mutex); #endif + + int autosave = false; + mCoreConfigGetIntValue(&runner->config, "autosave", &autosave); + if (autosave) { + mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA); + } + mLOG(GUI_RUNNER, DEBUG, "Unloading game..."); runner->core->unloadROM(runner->core); drawState.screenshotId = 0; @@ -525,14 +545,6 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) { mappedMemoryFree(drawState.screenshot, w * h * 4); } - struct VFile* autosave = mCoreGetState(runner->core, 0, false); - if (autosave) { - autosave->close(autosave); - autosave = mCoreGetState(runner->core, 0, true); - autosave->truncate(autosave, 0); - autosave->close(autosave); - } - if (runner->config.port) { mLOG(GUI_RUNNER, DEBUG, "Saving key sources..."); if (runner->keySources) {