From f95bf01c783f319ac90d986d0791e05d661bf03e Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 4 May 2020 16:15:43 +0200 Subject: [PATCH] Input: fix trigger scaling this is not a problem at the moment, but if you increase the trigger_max then the old code reports values bigger than 255 --- rpcs3/Emu/Io/PadHandler.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index f9620b1b45..3f9610e3e4 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -103,7 +103,7 @@ long PadHandlerBase::FindKeyCodeByString(const std::unordered_map(std::clamp(raw_value, minimum, maximum) - minimum) / (abs(maximum) + abs(minimum)); + const float val = static_cast(std::clamp(raw_value, minimum, maximum) - minimum) / (abs(maximum) + abs(minimum)); return 255.0f * val; } @@ -111,7 +111,7 @@ float PadHandlerBase::ScaledInput(s32 raw_value, int minimum, int maximum) float PadHandlerBase::ScaledInput2(s32 raw_value, int minimum, int maximum) { // value based on max range converted to [0, 1] - float val = static_cast(std::clamp(raw_value, minimum, maximum) - minimum) / (abs(maximum) + abs(minimum)); + const float val = static_cast(std::clamp(raw_value, minimum, maximum) - minimum) / (abs(maximum) + abs(minimum)); return (510.0f * val) - 255.0f; } @@ -124,11 +124,12 @@ u16 PadHandlerBase::NormalizeTriggerInput(u16 value, int threshold) } else if (threshold <= trigger_min) { - return value; + return static_cast(ScaledInput(value, trigger_min, trigger_max)); } else { - return static_cast(static_cast(trigger_max) * (value - threshold) / (trigger_max - threshold)); + const s32 val = static_cast(static_cast(trigger_max) * (value - threshold) / (trigger_max - threshold)); + return static_cast(ScaledInput(val, trigger_min, trigger_max)); } } @@ -141,7 +142,7 @@ u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 max return static_cast(0); } - float val = static_cast(std::clamp(raw_value, 0, maximum)) / maximum; // value based on max range converted to [0, 1] + const float val = static_cast(std::clamp(raw_value, 0, maximum)) / maximum; // value based on max range converted to [0, 1] if (threshold <= 0) { @@ -149,7 +150,7 @@ u16 PadHandlerBase::NormalizeDirectedInput(s32 raw_value, s32 threshold, s32 max } else { - float thresh = static_cast(threshold) / maximum; // threshold converted to [0, 1] + const float thresh = static_cast(threshold) / maximum; // threshold converted to [0, 1] return static_cast(255.0f * std::min(1.0f, (val - thresh) / (1.0f - thresh))); } }