Qt: Ability to temporarily load a savegame
Jeffrey Pfau jeffrey@endrift.com
Mon, 22 Aug 2016 10:33:59 -0700
5 files changed,
23 insertions(+),
12 deletions(-)
M
src/gba/core.c
→
src/gba/core.c
@@ -209,7 +209,8 @@ return GBALoadSave(core->board, 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 }
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -138,6 +138,11 @@ };
m_threadContext.resetCallback = [](mCoreThread* context) { GameController* controller = static_cast<GameController*>(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() {
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -192,6 +192,7 @@ QThread* m_audioThread;
AudioProcessor* m_audioProcessor; QAtomicInt m_pauseAfterFrame; + QList<std::function<void ()>> m_resetActions; bool m_videoSync; bool m_audioSync;
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -850,7 +850,7 @@ m_shortcutController->addMenu(fileMenu);
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);