From 1b8daa046531df238e7343c1cbb2d9cf5129e739 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Thu, 31 Oct 2024 20:33:57 +0100 Subject: [PATCH] fix up cheat toggle --- src/frontend/qt_sdl/EmuInstance.cpp | 2 +- src/frontend/qt_sdl/EmuThread.cpp | 10 ++++++++++ src/frontend/qt_sdl/EmuThread.h | 4 ++++ src/frontend/qt_sdl/Window.cpp | 7 ++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index e9550f8c..9114a141 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -1161,7 +1161,7 @@ std::optional EmuInstance::loadSDCard(const string& key) noexcept void EmuInstance::enableCheats(bool enable) { cheatsOn = enable; - if (cheatFile) + if (cheatsOn && cheatFile) nds->AREngine.Cheats = cheatFile->GetCodes(); else nds->AREngine.Cheats.clear(); diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index f4112cd3..f4ce8c94 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -648,6 +648,10 @@ void EmuThread::handleMessages() msgResult = 1; } break; + + case msg_EnableCheats: + emuInstance->enableCheats(msg.param.value()); + break; } msgSemaphore.release(); @@ -815,6 +819,12 @@ int EmuThread::importSavefile(const QString& filename) return msgResult; } +void EmuThread::enableCheats(bool enable) +{ + sendMessage({.type = msg_EnableCheats, .param = enable}); + waitMessage(); +} + void EmuThread::updateRenderer() { if (videoRenderer != lastVideoRenderer) diff --git a/src/frontend/qt_sdl/EmuThread.h b/src/frontend/qt_sdl/EmuThread.h index 19e1a3a6..18bff6dd 100644 --- a/src/frontend/qt_sdl/EmuThread.h +++ b/src/frontend/qt_sdl/EmuThread.h @@ -83,6 +83,8 @@ public: msg_UndoStateLoad, msg_ImportSavefile, + + msg_EnableCheats, }; struct Message @@ -124,6 +126,8 @@ public: int importSavefile(const QString& filename); + void enableCheats(bool enable); + bool emuIsRunning(); bool emuIsActive(); diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 430f0d6e..aed8076a 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -1655,7 +1655,12 @@ void MainWindow::onOpenPowerManagement() void MainWindow::onEnableCheats(bool checked) { localCfg.SetBool("EnableCheats", checked); - emuInstance->enableCheats(checked); + emuThread->enableCheats(checked); + + emuInstance->doOnAllWindows([=](MainWindow* win) + { + win->actEnableCheats->setChecked(checked); + }, windowID); } void MainWindow::onSetupCheats()