From 7eaa6871409bd99f64361ef057a69548cc7b61fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 8 Jul 2021 23:49:14 +0200 Subject: [PATCH] Move the joystick deadzone processing until after all the mapping. --- UI/EmuScreen.cpp | 21 +++++++++++++++++---- UI/NativeApp.cpp | 45 +-------------------------------------------- 2 files changed, 18 insertions(+), 48 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index ca5466ff6e..9e24e53bd4 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -155,10 +155,23 @@ static void SetPSPAxis(char axis, float value, int stick) { default: break; } - if (axis == 'X') - __CtrlSetAnalogX(value, stick); - else if (axis == 'Y') - __CtrlSetAnalogY(value, stick); + + // TODO: Can we move the rest of this logic into ControlMapping too? + + static float history[2][2] = {}; + + int axisId = axis == 'X' ? 0 : 1; + + history[stick][axisId] = value; + + float x = history[stick][0]; + float y = history[stick][1]; + + // It's a bit non-ideal to run through this twice, once for each axis, but... + ConvertAnalogStick(x, y); + + __CtrlSetAnalogX(x, stick); + __CtrlSetAnalogY(y, stick); } EmuScreen::EmuScreen(const Path &filename) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index cf363b3a08..8e675dee95 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1327,38 +1327,6 @@ bool NativeKey(const KeyInput &key) { return retval; } -static bool AnalogStickAxis(const AxisInput &axis) { - static float history[JOYSTICK_AXIS_MAX+1] = { 0.0f }; - - history[axis.axisId] = axis.value; - AxisInput axisA = axis; - AxisInput axisB = axis; - - switch (axis.axisId) { - case JOYSTICK_AXIS_X: - case JOYSTICK_AXIS_Y: - axisA.axisId = JOYSTICK_AXIS_X; - axisB.axisId = JOYSTICK_AXIS_Y; - axisA.value = history[JOYSTICK_AXIS_X]; - axisB.value = history[JOYSTICK_AXIS_Y]; - break; - case JOYSTICK_AXIS_Z: - case JOYSTICK_AXIS_RZ: - axisA.axisId = JOYSTICK_AXIS_Z; - axisB.axisId = JOYSTICK_AXIS_RZ; - axisA.value = history[JOYSTICK_AXIS_Z]; - axisB.value = history[JOYSTICK_AXIS_RZ]; - break; - default: - break; - } - - ConvertAnalogStick(axisA.value, axisB.value); - bool retA = screenManager->axis(axisA); - bool retB = screenManager->axis(axisB); - return retA && retB; -} - bool NativeAxis(const AxisInput &axis) { if (!screenManager) { // Too early. @@ -1367,16 +1335,6 @@ bool NativeAxis(const AxisInput &axis) { using namespace TiltEventProcessor; - switch (axis.axisId) { - case JOYSTICK_AXIS_X: - case JOYSTICK_AXIS_Y: - case JOYSTICK_AXIS_Z: - case JOYSTICK_AXIS_RZ: - return AnalogStickAxis(axis); - default: - break; - } - // only handle tilt events if tilt is enabled. if (g_Config.iTiltInputType == TILT_NULL) { // if tilt events are disabled, then run it through the usual way. @@ -1388,8 +1346,7 @@ bool NativeAxis(const AxisInput &axis) { } // create the base coordinate tilt system from the calibration data. - // This is static for no particular reason, can be un-static'ed - static Tilt baseTilt; + Tilt baseTilt; baseTilt.x_ = g_Config.fTiltBaseX; baseTilt.y_ = g_Config.fTiltBaseY;