diff --git a/CHANGES b/CHANGES index 518621ede..af7f033bb 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Features: - GB: LR35902/GB-Z80 disassembler - Configuration of gamepad hats - Qt: Spanish translation (by Kevin López) + - Add option for whether rewinding restores save games Bugfixes: - LR35902: Fix core never exiting with certain event patterns - GB Timer: Improve DIV reset behavior diff --git a/include/mgba/core/config.h b/include/mgba/core/config.h index 2fac1ff37..aca655976 100644 --- a/include/mgba/core/config.h +++ b/include/mgba/core/config.h @@ -27,6 +27,7 @@ struct mCoreOptions { int frameskip; bool rewindEnable; int rewindBufferCapacity; + bool rewindSave; float fpsTarget; size_t audioBuffers; unsigned sampleRate; diff --git a/include/mgba/core/rewind.h b/include/mgba/core/rewind.h index a1a748d3d..8762ff76a 100644 --- a/include/mgba/core/rewind.h +++ b/include/mgba/core/rewind.h @@ -19,6 +19,7 @@ struct mCoreRewindContext { struct mCoreRewindPatches patchMemory; size_t current; size_t size; + int stateFlags; struct VFile* previousState; struct VFile* currentState; }; diff --git a/src/core/config.c b/src/core/config.c index 659efd3e8..ceca2bdfd 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -321,6 +321,7 @@ void mCoreConfigMap(const struct mCoreConfig* config, struct mCoreOptions* opts) _lookupIntValue(config, "frameskip", &opts->frameskip); _lookupIntValue(config, "volume", &opts->volume); _lookupIntValue(config, "rewindBufferCapacity", &opts->rewindBufferCapacity); + _lookupIntValue(config, "rewindSave", &opts->rewindSave); _lookupFloatValue(config, "fpsTarget", &opts->fpsTarget); unsigned audioBuffers; if (_lookupUIntValue(config, "audioBuffers", &audioBuffers)) { @@ -376,6 +377,7 @@ void mCoreConfigLoadDefaults(struct mCoreConfig* config, const struct mCoreOptio ConfigurationSetIntValue(&config->defaultsTable, 0, "frameskip", opts->frameskip); ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindEnable", opts->rewindEnable); ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindBufferCapacity", opts->rewindBufferCapacity); + ConfigurationSetIntValue(&config->defaultsTable, 0, "rewindSave", opts->rewindSave); ConfigurationSetFloatValue(&config->defaultsTable, 0, "fpsTarget", opts->fpsTarget); ConfigurationSetUIntValue(&config->defaultsTable, 0, "audioBuffers", opts->audioBuffers); ConfigurationSetUIntValue(&config->defaultsTable, 0, "sampleRate", opts->sampleRate); diff --git a/src/core/rewind.c b/src/core/rewind.c index 56a59e47d..9919acf2e 100644 --- a/src/core/rewind.c +++ b/src/core/rewind.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -20,6 +21,7 @@ void mCoreRewindContextInit(struct mCoreRewindContext* context, size_t entries) context->previousState = VFileMemChunk(0, 0); context->currentState = VFileMemChunk(0, 0); context->size = 0; + context->stateFlags = SAVESTATE_SAVEDATA; } void mCoreRewindContextDeinit(struct mCoreRewindContext* context) { @@ -41,7 +43,7 @@ void mCoreRewindAppend(struct mCoreRewindContext* context, struct mCore* core) { if (context->current >= mCoreRewindPatchesSize(&context->patchMemory)) { context->current = 0; } - mCoreSaveStateNamed(core, nextState, 0); + mCoreSaveStateNamed(core, nextState, context->stateFlags); struct PatchFast* patch = mCoreRewindPatchesGetPointer(&context->patchMemory, context->current); size_t size2 = nextState->size(nextState); size_t size = context->currentState->size(context->currentState); @@ -75,7 +77,7 @@ bool mCoreRewindRestore(struct mCoreRewindContext* context, struct mCore* core) patch->d.applyPatch(&patch->d, current, size, previous, size); context->currentState->unmap(context->currentState, current, size); context->previousState->unmap(context->previousState, previous, size); - mCoreLoadStateNamed(core, context->previousState, 0); + mCoreLoadStateNamed(core, context->previousState, context->stateFlags); struct VFile* nextState = context->previousState; context->previousState = context->currentState; context->currentState = nextState; diff --git a/src/core/thread.c b/src/core/thread.c index f3509071e..3ffa7c477 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -148,6 +149,7 @@ static THREAD_ENTRY _mCoreThreadRun(void* context) { if (core->opts.rewindEnable && core->opts.rewindBufferCapacity > 0) { mCoreRewindContextInit(&threadContext->rewind, core->opts.rewindBufferCapacity); + threadContext->rewind.stateFlags = core->opts.rewindSave ? SAVESTATE_SAVEDATA : 0; } _changeState(threadContext, THREAD_RUNNING, true); diff --git a/src/platform/qt/ConfigController.cpp b/src/platform/qt/ConfigController.cpp index 6f25326c5..520b6d9f2 100644 --- a/src/platform/qt/ConfigController.cpp +++ b/src/platform/qt/ConfigController.cpp @@ -110,6 +110,7 @@ ConfigController::ConfigController(QObject* parent) m_opts.logLevel = mLOG_WARN | mLOG_ERROR | mLOG_FATAL; m_opts.rewindEnable = false; m_opts.rewindBufferCapacity = 300; + m_opts.rewindSave = true; m_opts.useBios = true; m_opts.suspendScreensaver = true; m_opts.lockAspectRatio = true; diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index 84f089cfd..3889cb4c6 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -731,7 +731,7 @@ void GameController::frameAdvance() { } } -void GameController::setRewind(bool enable, int capacity) { +void GameController::setRewind(bool enable, int capacity, bool rewindSave) { if (m_gameOpen) { Interrupter interrupter(this); if (m_threadContext.core->opts.rewindEnable && m_threadContext.core->opts.rewindBufferCapacity > 0) { @@ -739,8 +739,10 @@ void GameController::setRewind(bool enable, int capacity) { } m_threadContext.core->opts.rewindEnable = enable; m_threadContext.core->opts.rewindBufferCapacity = capacity; + m_threadContext.core->opts.rewindSave = rewindSave; if (enable && capacity > 0) { mCoreRewindContextInit(&m_threadContext.rewind, capacity); + m_threadContext.rewind.stateFlags = rewindSave ? SAVESTATE_SAVEDATA : 0; } } } diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 7a3bfbecc..9ea53de7b 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -127,7 +127,7 @@ public slots: void setPaused(bool paused); void reset(); void frameAdvance(); - void setRewind(bool enable, int capacity); + void setRewind(bool enable, int capacity, bool rewindSave); void rewind(int states = 0); void startRewinding(); void stopRewinding(); diff --git a/src/platform/qt/SettingsView.cpp b/src/platform/qt/SettingsView.cpp index 57c27049d..da2d27be0 100644 --- a/src/platform/qt/SettingsView.cpp +++ b/src/platform/qt/SettingsView.cpp @@ -194,6 +194,7 @@ void SettingsView::updateConfig() { saveSetting("mute", m_ui.mute); saveSetting("rewindEnable", m_ui.rewind); saveSetting("rewindBufferCapacity", m_ui.rewindCapacity); + saveSetting("rewindSave", m_ui.rewindSave); saveSetting("resampleVideo", m_ui.resampleVideo); saveSetting("allowOpposingDirections", m_ui.allowOpposingDirections); saveSetting("suspendScreensaver", m_ui.suspendScreensaver); @@ -272,6 +273,7 @@ void SettingsView::reloadConfig() { loadSetting("mute", m_ui.mute); loadSetting("rewindEnable", m_ui.rewind); loadSetting("rewindBufferCapacity", m_ui.rewindCapacity); + loadSetting("rewindSave", m_ui.rewindSave); loadSetting("resampleVideo", m_ui.resampleVideo); loadSetting("allowOpposingDirections", m_ui.allowOpposingDirections); loadSetting("suspendScreensaver", m_ui.suspendScreensaver); diff --git a/src/platform/qt/SettingsView.ui b/src/platform/qt/SettingsView.ui index b7abd9c39..ad59bc5bd 100644 --- a/src/platform/qt/SettingsView.ui +++ b/src/platform/qt/SettingsView.ui @@ -77,7 +77,7 @@ - 1 + 0 @@ -535,21 +535,21 @@ - + Qt::Horizontal - + Idle loops: - + @@ -568,21 +568,21 @@ - + Qt::Horizontal - + Savestate extra data: - + Screenshot @@ -592,7 +592,7 @@ - + Save data @@ -602,7 +602,7 @@ - + Cheat codes @@ -612,14 +612,14 @@ - + Load extra data: - + Screenshot @@ -629,27 +629,37 @@ - + Save data - + Cheat codes - + Qt::Horizontal + + + + Rewind affects save data + + + true + + + diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index fa4a47ee0..256c1581d 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -1439,12 +1439,17 @@ void Window::setupMenu(QMenuBar* menubar) { ConfigOption* rewindEnable = m_config->addOption("rewindEnable"); rewindEnable->connect([this](const QVariant& value) { - m_controller->setRewind(value.toBool(), m_config->getOption("rewindBufferCapacity").toInt()); + m_controller->setRewind(value.toBool(), m_config->getOption("rewindBufferCapacity").toInt(), m_config->getOption("rewindSave").toInt()); }, this); ConfigOption* rewindBufferCapacity = m_config->addOption("rewindBufferCapacity"); rewindBufferCapacity->connect([this](const QVariant& value) { - m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), value.toInt()); + m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), value.toInt(), m_config->getOption("rewindSave").toInt()); + }, this); + + ConfigOption* rewindSave = m_config->addOption("rewindSave"); + rewindBufferCapacity->connect([this](const QVariant& value) { + m_controller->setRewind(m_config->getOption("rewindEnable").toInt(), m_config->getOption("rewindBufferCapacity").toInt(), value.toBool()); }, this); ConfigOption* allowOpposingDirections = m_config->addOption("allowOpposingDirections"); diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 9bbabedbc..a5d960b23 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -43,6 +43,7 @@ int main(int argc, char** argv) { .useBios = true, .rewindEnable = true, .rewindBufferCapacity = 600, + .rewindSave = true, .audioBuffers = 1024, .videoSync = false, .audioSync = true,