From 734b2a55de07a9401277c94a551faa5746b04ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 12 Feb 2026 23:06:26 +0100 Subject: [PATCH] Move to a global controlmapper --- Core/ControlMapper.cpp | 1 + Core/ControlMapper.h | 2 ++ UI/ControlMappingScreen.cpp | 10 +++++----- UI/ControlMappingScreen.h | 2 -- UI/EmuScreen.cpp | 32 ++++++++++++++++---------------- UI/EmuScreen.h | 2 -- 6 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index 717e91a741..f487624e02 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -18,6 +18,7 @@ using KeyMap::MultiInputMapping; const float AXIS_BIND_THRESHOLD = 0.75f; const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f; +ControlMapper g_controlMapper; // We reduce the threshold of some axes when another axis on the same stick is active. // This makes it easier to hit diagonals if you bind an analog stick to four face buttons or D-Pad. diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index eed5fcf68f..8648662271 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -112,3 +112,5 @@ private: void ConvertAnalogStick(float x, float y, float *outX, float *outY); float GetDeviceAxisThreshold(int device, const InputMapping &mapping); + +extern ControlMapper g_controlMapper; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 8a36a3bd29..6a84af2da0 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -480,11 +480,11 @@ void KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) { } AnalogCalibrationScreen::AnalogCalibrationScreen(const Path &gamePath) : UITwoPaneBaseDialogScreen(gamePath, TwoPaneFlags::SettingsCanScroll) { - mapper_.AddListener(this); + g_controlMapper.AddListener(this); } AnalogCalibrationScreen::~AnalogCalibrationScreen() { - mapper_.RemoveListener(this); + g_controlMapper.RemoveListener(this); } void AnalogCalibrationScreen::SetPSPAnalog(int rotation, int stick, float x, float y) { @@ -498,7 +498,7 @@ void AnalogCalibrationScreen::SetRawAnalog(int stick, float x, float y) { } void AnalogCalibrationScreen::update() { - mapper_.Update(g_Config.GetDisplayLayoutConfig(GetDeviceOrientation()), time_now_d()); + g_controlMapper.Update(g_Config.GetDisplayLayoutConfig(GetDeviceOrientation()), time_now_d()); // We ignore the secondary stick for now and just use the two views // for raw and psp input. if (stickView_[0]) { @@ -515,7 +515,7 @@ bool AnalogCalibrationScreen::key(const KeyInput &key) { // Allow testing auto-rotation. If it collides with UI keys, too bad. bool pauseTrigger = false; - mapper_.Key(key, &pauseTrigger); + g_controlMapper.Key(key, &pauseTrigger); if (UI::IsEscapeKey(key)) { TriggerFinish(DR_BACK); @@ -529,7 +529,7 @@ void AnalogCalibrationScreen::axis(const AxisInput &axis) { // UIScreen::axis(axis); // Instead we just send the input directly to the mapper, that we'll visualize. - mapper_.Axis(&axis, 1); + g_controlMapper.Axis(&axis, 1); } std::string_view AnalogCalibrationScreen::GetTitle() const { diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index 366cae25ab..b1eb423afb 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -148,8 +148,6 @@ protected: private: void OnResetToDefaults(UI::EventParams &e); - ControlMapper mapper_; - float analogX_[2]{}; float analogY_[2]{}; float rawX_[2]{}; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 9cb32a4c7b..bd65269eb8 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -162,7 +162,7 @@ void EmuScreen::SetPSPAnalog(int iInternalScreenRotation, int stick, float x, fl EmuScreen::EmuScreen(const Path &filename) : gamePath_(filename) { saveStateSlot_ = SaveState::GetCurrentSlot(); - controlMapper_.AddListener(this); + g_controlMapper.AddListener(this); _dbg_assert_(coreState == CORE_POWERDOWN); @@ -446,7 +446,7 @@ void EmuScreen::bootComplete() { } EmuScreen::~EmuScreen() { - controlMapper_.RemoveListener(this); + g_controlMapper.RemoveListener(this); if (imguiInited_) { ImGui_ImplThin3d_Shutdown(); @@ -539,7 +539,7 @@ void EmuScreen::focusChanged(ScreenFocusChange focusChange) { switch (focusChange) { case ScreenFocusChange::FOCUS_LOST_TOP: g_Config.TimeTracker().Stop(gameID); - controlMapper_.ReleaseAll(); + g_controlMapper.ReleaseAll(); break; case ScreenFocusChange::FOCUS_BECAME_TOP: g_Config.TimeTracker().Start(gameID); @@ -831,7 +831,7 @@ void EmuScreen::OnVKey(VirtKey virtualKeyCode, bool down) { // Note: We don't check NetworkWarnUserIfOnlineAndCantSpeed, because we can keep // running in the background of the menu. pauseTrigger_ = true; - controlMapper_.ForceReleaseVKey(virtualKeyCode); + g_controlMapper.ForceReleaseVKey(virtualKeyCode); } break; @@ -917,12 +917,12 @@ void EmuScreen::ProcessVKey(VirtKey virtKey) { if (g_Config.bEnableNetworkChat && !g_Config.bShowImDebugger) { UI::EventParams e{}; OnChatMenu.Trigger(e); - controlMapper_.ForceReleaseVKey(VIRTKEY_OPENCHAT); + g_controlMapper.ForceReleaseVKey(VIRTKEY_OPENCHAT); } break; case VIRTKEY_AXIS_SWAP: - controlMapper_.ToggleSwapAxes(); + g_controlMapper.ToggleSwapAxes(); g_OSD.Show(OSDType::MESSAGE_INFO, mc->T("AxisSwap")); // best string we have. break; @@ -1142,7 +1142,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { if (mappingFound) { for (auto b : pspButtons) { if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) { - return controlMapper_.Key(key, &pauseTrigger_); + return g_controlMapper.Key(key, &pauseTrigger_); } } } @@ -1152,28 +1152,28 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { switch (key.deviceId) { case DEVICE_ID_KEYBOARD: if (!ImGui::GetIO().WantCaptureKeyboard) { - controlMapper_.Key(key, &pauseTrigger_); + g_controlMapper.Key(key, &pauseTrigger_); } break; case DEVICE_ID_MOUSE: if (!ImGui::GetIO().WantCaptureMouse) { - controlMapper_.Key(key, &pauseTrigger_); + g_controlMapper.Key(key, &pauseTrigger_); } break; default: - controlMapper_.Key(key, &pauseTrigger_); + g_controlMapper.Key(key, &pauseTrigger_); break; } } else { // Let up-events through to the controlMapper_ so input doesn't get stuck. if (key.flags & KeyInputFlags::UP) { - controlMapper_.Key(key, &pauseTrigger_); + g_controlMapper.Key(key, &pauseTrigger_); } } return UIScreen::UnsyncKey(key); } - return controlMapper_.Key(key, &pauseTrigger_); + return g_controlMapper.Key(key, &pauseTrigger_); } void EmuScreen::UnsyncAxis(const AxisInput *axes, size_t count) { @@ -1183,7 +1183,7 @@ void EmuScreen::UnsyncAxis(const AxisInput *axes, size_t count) { return UIScreen::UnsyncAxis(axes, count); } - return controlMapper_.Axis(axes, count); + return g_controlMapper.Axis(axes, count); } bool EmuScreen::key(const KeyInput &key) { @@ -1261,7 +1261,7 @@ void EmuScreen::CreateViews() { const Bounds &bounds = screenManager()->getUIContext()->GetLayoutBounds(); InitPadLayout(&touch, deviceOrientation, bounds.w, bounds.h); - root_ = CreatePadLayout(touch, bounds.w, bounds.h, &pauseTrigger_, &controlMapper_); + root_ = CreatePadLayout(touch, bounds.w, bounds.h, &pauseTrigger_, &g_controlMapper); if (g_Config.bShowDeveloperMenu) { root_->Add(new Button(dev->T("DevMenu")))->OnClick.Handle(this, &EmuScreen::OnDevTools); } @@ -1474,7 +1474,7 @@ void EmuScreen::update() { double now = time_now_d(); DisplayLayoutConfig &config = g_Config.GetDisplayLayoutConfig(GetDeviceOrientation()); - controlMapper_.Update(config, now); + g_controlMapper.Update(config, now); if (saveStatePreview_ && !bootPending_) { int currentSlot = SaveState::GetCurrentSlot(); @@ -1943,7 +1943,7 @@ void EmuScreen::renderUI() { if (PSP_IsInited()) { if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::CONTROL) { - DrawControlMapperOverlay(ctx, ctx->GetLayoutBounds(), controlMapper_); + DrawControlMapperOverlay(ctx, ctx->GetLayoutBounds(), g_controlMapper); } if (g_Config.iShowStatusFlags) { DrawFPS(ctx, ctx->GetLayoutBounds()); diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index e0a2c2db71..140057d712 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -141,8 +141,6 @@ private: std::string extraAssertInfoStr_; - ControlMapper controlMapper_; - std::unique_ptr imDebugger_ = nullptr; ImCommand imCmd_{}; // needed to buffer commands in case imgui wasn't created yet.