diff --git a/Core/ControlMapper.cpp b/Core/ControlMapper.cpp index 354005a157d1..2847feb204c3 100644 --- a/Core/ControlMapper.cpp +++ b/Core/ControlMapper.cpp @@ -41,13 +41,15 @@ static float MapAxisValue(float v) { return sign * Clamp(invDeadzone + (abs(v) - deadzone) / (1.0f - deadzone) * (sensitivity - invDeadzone), 0.0f, 1.0f); } -void ConvertAnalogStick(float &x, float &y) { +void ConvertAnalogStick(float x, float y, float *outX, float *outY) { const bool isCircular = g_Config.bAnalogIsCircular; float norm = std::max(fabsf(x), fabsf(y)); - - if (norm == 0.0f) + if (norm == 0.0f) { + *outX = x; + *outY = y; return; + } if (isCircular) { float newNorm = sqrtf(x * x + y * y); @@ -58,8 +60,8 @@ void ConvertAnalogStick(float &x, float &y) { } float mappedNorm = MapAxisValue(norm); - x = Clamp(x / norm * mappedNorm, -1.0f, 1.0f); - y = Clamp(y / norm * mappedNorm, -1.0f, 1.0f); + *outX = Clamp(x / norm * mappedNorm, -1.0f, 1.0f); + *outY = Clamp(y / norm * mappedNorm, -1.0f, 1.0f); } void ControlMapper::SetCallbacks( @@ -102,7 +104,7 @@ void ControlMapper::SetPSPAxis(int device, int stick, char axis, float value) { bool ignore = false; if (inDeadZone && lastNonDeadzoneDeviceID_[stick] != device) { // Ignore this event! See issue #15465 - ignore = true; + ignore = true; } if (!inDeadZone) { @@ -114,9 +116,9 @@ void ControlMapper::SetPSPAxis(int device, int stick, char axis, float value) { float x = history_[stick][0]; float y = history_[stick][1]; - - ConvertAnalogStick(x, y); - setPSPAnalog_(stick, x, y); + float convertedX, convertedY; + ConvertAnalogStick(x, y, &convertedX, &convertedY); + setPSPAnalog_(stick, convertedX, convertedY); } } diff --git a/Core/ControlMapper.h b/Core/ControlMapper.h index cbcab1ce0bc2..17b6fb5bfa32 100644 --- a/Core/ControlMapper.h +++ b/Core/ControlMapper.h @@ -66,4 +66,4 @@ class ControlMapper { std::function setRawAnalog_; }; -void ConvertAnalogStick(float &x, float &y); +void ConvertAnalogStick(float x, float y, float *outX, float *outY); diff --git a/UI/JoystickHistoryView.cpp b/UI/JoystickHistoryView.cpp index 3fdd895ac504..3aa1828f9c6b 100644 --- a/UI/JoystickHistoryView.cpp +++ b/UI/JoystickHistoryView.cpp @@ -34,8 +34,8 @@ void JoystickHistoryView::Draw(UIContext &dc) { float by = (iy + 1) * dx; if (type_ == StickHistoryViewType::OUTPUT) { - ConvertAnalogStick(ax, ay); - ConvertAnalogStick(bx, by); + ConvertAnalogStick(ax, ay, &ax, &ay); + ConvertAnalogStick(bx, by, &bx, &by); } ax = ax * minRadius + bounds_.centerX(); @@ -58,8 +58,8 @@ void JoystickHistoryView::Draw(UIContext &dc) { float by = fy; if (type_ == StickHistoryViewType::OUTPUT) { - ConvertAnalogStick(ax, ay); - ConvertAnalogStick(bx, by); + ConvertAnalogStick(ax, ay, &ax, &ay); + ConvertAnalogStick(bx, by, &bx, &by); } ax = ax * minRadius + bounds_.centerX();