From 02aaa3b2b90fd30ec9dfedc75d75d592dd3b13e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 16 Jun 2026 09:51:59 +0200 Subject: [PATCH] Don't have pauseTrigger as an output parameter from ControlMapper::Key() --- Core/ControlMapper.cpp | 6 +++--- Core/ControlMapper.h | 19 +++++++++++++------ UI/ControlMappingScreen.cpp | 3 +-- UI/EmuScreen.cpp | 16 ++++++++++------ UI/EmuScreen.h | 1 + UI/PauseScreen.cpp | 5 ++--- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index bc57961e6b..d939b3c64f 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -303,7 +303,7 @@ void ControlMapper::ReleaseAll() { Axis(axes.data(), axes.size());; for (const auto &key : keys) { - Key(key, nullptr); + Key(key); } } @@ -586,7 +586,7 @@ bool ControlMapper::UpdatePSPState(const InputMapping &changedMapping, double no return keyInputUsed; } -bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) { +bool ControlMapper::Key(const KeyInput &key) { double now = time_now_d(); InputMapping mapping(key.deviceId, key.keyCode); @@ -607,7 +607,7 @@ bool ControlMapper::Key(const KeyInput &key, bool *pauseTrigger) { bool mappingFound = KeyMap::InputMappingToPspButton(mapping, nullptr); DEBUG_LOG(Log::System, "Key: %d DeviceId: %d", key.keyCode, key.deviceId); if (!mappingFound || key.deviceId == DEVICE_ID_DEFAULT) { - *pauseTrigger = true; + pauseTrigger_ = true; return true; } } diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index 5ededf210c..70a65fae04 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -1,13 +1,14 @@ #pragma once +#include +#include +#include +#include +#include + #include "Common/Input/InputState.h" #include "Core/KeyMap.h" -#include -#include -#include -#include - struct DisplayLayoutConfig; // Pure interface. @@ -32,7 +33,7 @@ public: // Inputs to the table-based mapping // These functions are free-threaded. - bool Key(const KeyInput &key, bool *pauseTrigger); + bool Key(const KeyInput &key); void Axis(const AxisInput *axes, size_t count); // Required callbacks. @@ -60,6 +61,10 @@ public: void GetDebugString(StringWriter &w) const; + bool PollPauseTrigger() { + return pauseTrigger_.exchange(false); + } + struct InputSample { float value; double timestamp; @@ -107,6 +112,8 @@ private: bool autoRotatingAnalogCW_ = false; bool autoRotatingAnalogCCW_ = false; + std::atomic pauseTrigger_{}; + bool swapAxes_ = false; int iInternalScreenRotationCached_ = 0; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index c9d5516541..3e730cfa94 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -518,8 +518,7 @@ bool AnalogCalibrationScreen::key(const KeyInput &key) { bool retval = UIScreen::key(key); // Allow testing auto-rotation. If it collides with UI keys, too bad. - bool pauseTrigger = false; - g_controlMapper.Key(key, &pauseTrigger); + g_controlMapper.Key(key); if (UI::IsEscapeKey(key)) { TriggerFinish(DR_BACK); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f4a5f99711..9024a925f1 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1189,7 +1189,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { if (mappingFound) { for (auto b : pspButtons) { if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) { - return g_controlMapper.Key(key, &pauseTrigger_); + return g_controlMapper.Key(key); } } } @@ -1199,28 +1199,28 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { switch (key.deviceId) { case DEVICE_ID_KEYBOARD: if (!ImGui::GetIO().WantCaptureKeyboard) { - g_controlMapper.Key(key, &pauseTrigger_); + g_controlMapper.Key(key); } break; case DEVICE_ID_MOUSE: if (!ImGui::GetIO().WantCaptureMouse) { - g_controlMapper.Key(key, &pauseTrigger_); + g_controlMapper.Key(key); } break; default: - g_controlMapper.Key(key, &pauseTrigger_); + g_controlMapper.Key(key); break; } } else { // Let up-events through to the controlMapper_ so input doesn't get stuck. if (key.flags & KeyInputFlags::UP) { - g_controlMapper.Key(key, &pauseTrigger_); + g_controlMapper.Key(key); } } return UIScreen::UnsyncKey(key); } - return g_controlMapper.Key(key, &pauseTrigger_); + return g_controlMapper.Key(key); } void EmuScreen::UnsyncAxis(const AxisInput *axes, size_t count) { @@ -1525,6 +1525,10 @@ void EmuScreen::update() { return; } + if (g_controlMapper.PollPauseTrigger()) { + pauseTrigger_ = true; + } + if (pauseTrigger_) { pauseTrigger_ = false; screenManager()->push(new GamePauseScreen(gamePath_, bootPending_)); diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index 60459ca66f..37ea76325c 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -114,6 +114,7 @@ private: std::string errorMessage_; // If set, pauses at the end of the frame. + // We also poll the pause trigger from the ControlMapper. That needs refactoring. bool pauseTrigger_ = false; // The last read chat message count, and how many new ones there are. diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 19543e30ce..2d11eefe00 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -378,9 +378,8 @@ GamePauseScreen::~GamePauseScreen() { bool GamePauseScreen::UnsyncKey(const KeyInput &key) { bool retval = UIScreen::UnsyncKey(key); - bool pauseTrigger = false; - retval = g_controlMapper.Key(key, &pauseTrigger) || retval; - if (pauseTrigger) { + retval = g_controlMapper.Key(key) || retval; + if (g_controlMapper.PollPauseTrigger()) { TriggerFinish(DR_BACK); } return retval;