From fa0fb6eee6cc0d99602a070d3a3519047d5e13ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 30 Mar 2023 15:11:34 +0200 Subject: [PATCH] Rework and simplify VIRTKEY_SPEED_ANALOG --- Core/Config.cpp | 1 - Core/Config.h | 1 - Core/ConfigValues.h | 6 ----- Core/ControlMapper.cpp | 59 ------------------------------------------ Core/ControlMapper.h | 2 -- UI/EmuScreen.cpp | 26 +++++++++++++++++++ 6 files changed, 26 insertions(+), 69 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index b93e04886a..1debc46920 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -849,7 +849,6 @@ static const ConfigSetting graphicsSettings[] = { ConfigSetting("FrameRate", &g_Config.iFpsLimit1, 0, true, true), ConfigSetting("FrameRate2", &g_Config.iFpsLimit2, -1, true, true), ConfigSetting("AnalogFrameRate", &g_Config.iAnalogFpsLimit, 240, true, true), - ConfigSetting("AnalogFrameRateMode", &g_Config.iAnalogFpsMode, 0, true, true), ConfigSetting("UnthrottlingMode", &g_Config.iFastForwardMode, &DefaultFastForwardMode, &FastForwardModeToString, &FastForwardModeFromString, true, true), #if defined(USING_WIN_UI) ConfigSetting("RestartRequired", &g_Config.bRestartRequired, false, false), diff --git a/Core/Config.h b/Core/Config.h index a022e8105d..18d991a48a 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -220,7 +220,6 @@ public: int iFpsLimit1; int iFpsLimit2; int iAnalogFpsLimit; - int iAnalogFpsMode; // 0 = auto, 1 = single direction, 2 = mapped to opposite int iMaxRecent; int iCurrentStateSlot; int iRewindSnapshotInterval; diff --git a/Core/ConfigValues.h b/Core/ConfigValues.h index 6945dfacf0..96690ecc5d 100644 --- a/Core/ConfigValues.h +++ b/Core/ConfigValues.h @@ -132,12 +132,6 @@ enum class BackgroundAnimation { MOVING_BACKGROUND = 4, }; -enum class AnalogFpsMode { - AUTO = 0, - MAPPED_DIRECTION = 1, - MAPPED_DIR_TO_OPPOSITE_DIR = 2, -}; - // for Config.iShowStatusFlags enum class ShowStatusFlags { FPS_COUNTER = 1 << 1, diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index b1e4189b95..4f4a2064c9 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -365,62 +365,3 @@ void ControlMapper::onVKey(int vkey, bool down) { break; } } - -void ControlMapper::ProcessAnalogSpeed(const AxisInput &axis, bool opposite) { - static constexpr float DEADZONE_THRESHOLD = 0.15f; - static constexpr float DEADZONE_SCALE = 1.0f / (1.0f - DEADZONE_THRESHOLD); - - FPSLimit &limitMode = PSP_CoreParameter().fpsLimit; - // If we're using an alternate speed already, let that win. - if (limitMode != FPSLimit::NORMAL && limitMode != FPSLimit::ANALOG) - return; - // Don't even try if the limit is invalid. - if (g_Config.iAnalogFpsLimit <= 0) - return; - - AnalogFpsMode mode = (AnalogFpsMode)g_Config.iAnalogFpsMode; - float value = axis.value; - if (mode == AnalogFpsMode::AUTO) { - // TODO: Consider the pad name for better auto? KeyMap::PadName(axis.deviceId); - switch (axis.axisId) { - case JOYSTICK_AXIS_X: - case JOYSTICK_AXIS_Y: - case JOYSTICK_AXIS_Z: - case JOYSTICK_AXIS_RX: - case JOYSTICK_AXIS_RY: - case JOYSTICK_AXIS_RZ: - // These, at least on directinput, can be used for triggers that go from mapped to opposite. - mode = AnalogFpsMode::MAPPED_DIR_TO_OPPOSITE_DIR; - break; - - default: - // Other axises probably don't go from negative to positive. - mode = AnalogFpsMode::MAPPED_DIRECTION; - break; - } - } - - // Okay, now let's map it as appropriate. - if (mode == AnalogFpsMode::MAPPED_DIRECTION) { - value = fabsf(value); - // Clamp to 0 in this case if we're processing the opposite direction. - if (opposite) - value = 0.0f; - } else if (mode == AnalogFpsMode::MAPPED_DIR_TO_OPPOSITE_DIR) { - value = fabsf(value); - if (opposite) - value = -value; - value = 0.5f - value * 0.5f; - } - - // Apply a small deadzone (against the resting position.) - value = std::max(0.0f, (value - DEADZONE_THRESHOLD) * DEADZONE_SCALE); - - // If target is above 60, value is how much to speed up over 60. Otherwise, it's how much slower. - // So normalize the target. - int target = g_Config.iAnalogFpsLimit - 60; - PSP_CoreParameter().analogFpsLimit = 60 + (int)(target * value); - - // If we've reset back to normal, turn it off. - limitMode = PSP_CoreParameter().analogFpsLimit == 60 ? FPSLimit::NORMAL : FPSLimit::ANALOG; -} diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index 300f9bb81e..87decc1a27 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -36,8 +36,6 @@ private: void SetPSPAxis(int deviceId, int stick, char axis, float value); - void ProcessAnalogSpeed(const AxisInput &axis, bool opposite); - void onVKey(int vkey, bool down); void onVKeyAnalog(int deviceId, int vkey, float value); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 3781180c05..5868ae079a 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -764,7 +764,33 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) { } void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) { + if (virtualKeyCode != VIRTKEY_SPEED_ANALOG) { + return; + } + // We only handle VIRTKEY_SPEED_ANALOG here. + + static constexpr float DEADZONE_THRESHOLD = 0.15f; + static constexpr float DEADZONE_SCALE = 1.0f / (1.0f - DEADZONE_THRESHOLD); + + FPSLimit &limitMode = PSP_CoreParameter().fpsLimit; + // If we're using an alternate speed already, let that win. + if (limitMode != FPSLimit::NORMAL && limitMode != FPSLimit::ANALOG) + return; + // Don't even try if the limit is invalid. + if (g_Config.iAnalogFpsLimit <= 0) + return; + + // Apply a small deadzone (against the resting position.) + value = std::max(0.0f, (value - DEADZONE_THRESHOLD) * DEADZONE_SCALE); + + // If target is above 60, value is how much to speed up over 60. Otherwise, it's how much slower. + // So normalize the target. + int target = g_Config.iAnalogFpsLimit - 60; + PSP_CoreParameter().analogFpsLimit = 60 + (int)(target * value); + + // If we've reset back to normal, turn it off. + limitMode = PSP_CoreParameter().analogFpsLimit == 60 ? FPSLimit::NORMAL : FPSLimit::ANALOG; } bool EmuScreen::key(const KeyInput &key) {