From c207675dfb0ae3e39f9cb0745fe0cca79a697ae2 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 22 Aug 2016 10:33:59 -0700 Subject: [PATCH] Qt: Ability to temporarily load a savegame --- CHANGES | 1 + src/gba/core.c | 3 ++- src/platform/qt/GameController.cpp | 28 ++++++++++++++++++---------- src/platform/qt/GameController.h | 1 + src/platform/qt/Window.cpp | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGES b/CHANGES index 657ec089b..e5feb5d31 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Features: - GUI: Add fast-forward - Wii: 240p support - 3DS: Adjustable screen darkening + - Ability to temporarily load a savegame Bugfixes: - SDL: Fix axes being mapped wrong - GBA Memory: Fix mirror on non-overdumped Classic NES games diff --git a/src/gba/core.c b/src/gba/core.c index 732ae98e7..243becb2d 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -209,7 +209,8 @@ static bool _GBACoreLoadSave(struct mCore* core, struct VFile* vf) { } static bool _GBACoreLoadTemporarySave(struct mCore* core, struct VFile* vf) { - GBASavedataMask(core->board, vf); + struct GBA* gba = core->board; + GBASavedataMask(&gba->memory.savedata, vf); return true; // TODO: Return a real value } diff --git a/src/platform/qt/GameController.cpp b/src/platform/qt/GameController.cpp index f3704a0ad..58791bbec 100644 --- a/src/platform/qt/GameController.cpp +++ b/src/platform/qt/GameController.cpp @@ -138,6 +138,11 @@ GameController::GameController(QObject* parent) m_threadContext.resetCallback = [](mCoreThread* context) { GameController* controller = static_cast(context->userData); + for (auto action : controller->m_resetActions) { + action(); + } + controller->m_resetActions.clear(); + unsigned width, height; controller->m_threadContext.core->desiredVideoDimensions(controller->m_threadContext.core, &width, &height); memset(controller->m_frontBuffer, 0xF8, width * height * BYTES_PER_PIXEL); @@ -415,17 +420,20 @@ void GameController::loadSave(const QString& path, bool temporary) { if (!isLoaded()) { return; } - VFile* vf = VFileDevice::open(path, temporary ? O_RDONLY : O_RDWR); - if (!vf) { - LOG(QT, ERROR) << tr("Failed to open save file: %1").arg(path); - return; - } + m_resetActions.append([this, path, temporary]() { + VFile* vf = VFileDevice::open(path, temporary ? O_RDONLY : O_RDWR); + if (!vf) { + LOG(QT, ERROR) << tr("Failed to open save file: %1").arg(path); + return; + } - if (temporary) { - m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); - } else { - m_threadContext.core->loadSave(m_threadContext.core, vf); - } + if (temporary) { + m_threadContext.core->loadTemporarySave(m_threadContext.core, vf); + } else { + m_threadContext.core->loadSave(m_threadContext.core, vf); + } + }); + reset(); } void GameController::yankPak() { diff --git a/src/platform/qt/GameController.h b/src/platform/qt/GameController.h index 5ce3a8a3e..3906122eb 100644 --- a/src/platform/qt/GameController.h +++ b/src/platform/qt/GameController.h @@ -192,6 +192,7 @@ private: AudioProcessor* m_audioProcessor; QAtomicInt m_pauseAfterFrame; + QList> m_resetActions; bool m_videoSync; bool m_audioSync; diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index a6facdf20..71162fa0e 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -850,7 +850,7 @@ void Window::setupMenu(QMenuBar* menubar) { installEventFilter(m_shortcutController); addControlledAction(fileMenu, fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open), "loadROM"); - QAction* loadTemporarySave = new QAction(tr("Load temporary save"), fileMenu); + QAction* loadTemporarySave = new QAction(tr("Load temporary save..."), fileMenu); connect(loadTemporarySave, &QAction::triggered, [this]() { this->selectSave(true); }); m_gameActions.append(loadTemporarySave); m_gbaActions.append(loadTemporarySave);