Qt: Add savestate save undo
Jeffrey Pfau jeffrey@endrift.com
Tue, 14 Jul 2015 20:45:29 -0700
4 files changed,
32 insertions(+),
2 deletions(-)
M
CHANGES
→
CHANGES
@@ -24,7 +24,7 @@ - Ability to boot directly into the BIOS
- Preliminary support for yanking out the game pak while a game is running - Thumb-drive mode by putting a file called portable.ini in the same folder - Configurable display driver, between software and OpenGL - - Undo-able savestate loading + - Undo-able savestate loading and saving Bugfixes: - ARM7: Fix SWI and IRQ timings - GBA Audio: Force audio FIFOs to 32-bit
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -581,6 +581,12 @@ m_stateSlot = slot;
} GBARunOnThread(&m_threadContext, [](GBAThread* context) { GameController* controller = static_cast<GameController*>(context->userData); + VFile* vf = GBAGetState(context->gba, context->stateDir, controller->m_stateSlot, false); + if (vf) { + controller->m_backupSaveState.resize(vf->size(vf)); + vf->read(vf, controller->m_backupSaveState.data(), controller->m_backupSaveState.size()); + vf->close(vf); + } GBASaveState(context, context->stateDir, controller->m_stateSlot, true); }); }@@ -599,6 +605,23 @@ controller->stateLoaded(context);
} delete controller->m_backupLoadState; controller->m_backupLoadState = nullptr; + }); +} + +void GameController::saveBackupState() { + if (m_backupSaveState.isEmpty()) { + return; + } + + GBARunOnThread(&m_threadContext, [](GBAThread* context) { + GameController* controller = static_cast<GameController*>(context->userData); + VFile* vf = GBAGetState(context->gba, context->stateDir, controller->m_stateSlot, true); + if (vf) { + vf->write(vf, controller->m_backupSaveState.constData(), controller->m_backupSaveState.size()); + vf->close(vf); + GBALog(context->gba, GBA_LOG_STATUS, "Undid state save"); + } + controller->m_backupSaveState.clear(); }); }
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -121,6 +121,7 @@ void setFPSTarget(float fps);
void loadState(int slot = 0); void saveState(int slot = 0); void loadBackupState(); + void saveBackupState(); void setVideoSync(bool); void setAudioSync(bool); void setFrameskip(int);@@ -194,7 +195,7 @@ bool m_wasPaused;
int m_stateSlot; GBASerializedState* m_backupLoadState; - GBASerializedState* m_backupSaveState; // TODO: Use this + QByteArray m_backupSaveState; InputController* m_inputController; MultiplayerController* m_multiplayer;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -707,6 +707,12 @@ connect(undoLoadState, SIGNAL(triggered()), m_controller, SLOT(loadBackupState()));
m_gameActions.append(undoLoadState); addControlledAction(quickLoadMenu, undoLoadState, "undoLoadState"); + QAction* undoSaveState = new QAction(tr("Undo save state"), quickSaveMenu); + undoSaveState->setShortcut(tr("Shift+F11")); + connect(undoSaveState, SIGNAL(triggered()), m_controller, SLOT(saveBackupState())); + m_gameActions.append(undoSaveState); + addControlledAction(quickLoadMenu, undoSaveState, "undoSaveState"); + quickLoadMenu->addSeparator(); quickSaveMenu->addSeparator();