mirror of https://github.com/mgba-emu/mgba.git
GUI: Make autosave configurable
This commit is contained in:
parent
45c2fdf7ed
commit
50cbf732b5
|
@ -47,6 +47,26 @@ void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t
|
||||||
},
|
},
|
||||||
.nStates = 2
|
.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) {
|
*GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) {
|
||||||
.title = "Use BIOS if found",
|
.title = "Use BIOS if found",
|
||||||
.data = "useBios",
|
.data = "useBios",
|
||||||
|
|
|
@ -135,6 +135,12 @@ static uint8_t _readLux(struct GBALuminanceSource* lux) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tryAutosave(struct mGUIRunner* runner) {
|
static void _tryAutosave(struct mGUIRunner* runner) {
|
||||||
|
int autosave = false;
|
||||||
|
mCoreConfigGetIntValue(&runner->config, "autosave", &autosave);
|
||||||
|
if (!autosave) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DISABLE_THREADING
|
#ifdef DISABLE_THREADING
|
||||||
mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA);
|
mCoreSaveState(runner->core, 0, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_METADATA);
|
||||||
#else
|
#else
|
||||||
|
@ -168,6 +174,12 @@ void mGUIInit(struct mGUIRunner* runner, const char* port) {
|
||||||
// TODO: Do we need to load more defaults?
|
// TODO: Do we need to load more defaults?
|
||||||
mCoreConfigSetDefaultIntValue(&runner->config, "volume", 0x100);
|
mCoreConfigSetDefaultIntValue(&runner->config, "volume", 0x100);
|
||||||
mCoreConfigSetDefaultValue(&runner->config, "idleOptimization", "detect");
|
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);
|
mCoreConfigLoad(&runner->config);
|
||||||
mCoreConfigGetIntValue(&runner->config, "logLevel", &logger.logLevel);
|
mCoreConfigGetIntValue(&runner->config, "logLevel", &logger.logLevel);
|
||||||
|
|
||||||
|
@ -352,10 +364,11 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
|
||||||
runner->core->reset(runner->core);
|
runner->core->reset(runner->core);
|
||||||
mLOG(GUI_RUNNER, DEBUG, "Reset!");
|
mLOG(GUI_RUNNER, DEBUG, "Reset!");
|
||||||
|
|
||||||
if (mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC)) {
|
|
||||||
struct VFile* autosave = mCoreGetState(runner->core, 0, true);
|
int autoload = false;
|
||||||
autosave->truncate(autosave, 0);
|
mCoreConfigGetIntValue(&runner->config, "autoload", &autoload);
|
||||||
autosave->close(autosave);
|
if (autoload) {
|
||||||
|
mCoreLoadState(runner->core, 0, SAVESTATE_SCREENSHOT | SAVESTATE_RTC);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
|
@ -516,6 +529,13 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
|
||||||
runner->autosave.core = NULL;
|
runner->autosave.core = NULL;
|
||||||
MutexUnlock(&runner->autosave.mutex);
|
MutexUnlock(&runner->autosave.mutex);
|
||||||
#endif
|
#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...");
|
mLOG(GUI_RUNNER, DEBUG, "Unloading game...");
|
||||||
runner->core->unloadROM(runner->core);
|
runner->core->unloadROM(runner->core);
|
||||||
drawState.screenshotId = 0;
|
drawState.screenshotId = 0;
|
||||||
|
@ -525,14 +545,6 @@ void mGUIRun(struct mGUIRunner* runner, const char* path) {
|
||||||
mappedMemoryFree(drawState.screenshot, w * h * 4);
|
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) {
|
if (runner->config.port) {
|
||||||
mLOG(GUI_RUNNER, DEBUG, "Saving key sources...");
|
mLOG(GUI_RUNNER, DEBUG, "Saving key sources...");
|
||||||
if (runner->keySources) {
|
if (runner->keySources) {
|
||||||
|
|
Loading…
Reference in New Issue