From cb405ced526b3b0336ac47369790b783c7482040 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 14 Aug 2019 03:03:57 +0000 Subject: [PATCH] Add gamepad axis inversion toggles git-svn-id: https://svn.eduke32.com/eduke32@7986 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/config.cpp | 17 +++++++++++++ source/duke3d/src/game.h | 1 + source/duke3d/src/menus.cpp | 6 +++++ source/mact/include/_control.h | 4 +-- source/mact/include/control.h | 1 + source/mact/src/control.cpp | 46 +++++++++++++++++++++++++++++++++- 6 files changed, 72 insertions(+), 3 deletions(-) diff --git a/source/duke3d/src/config.cpp b/source/duke3d/src/config.cpp index 1ac425625..7591b9be1 100644 --- a/source/duke3d/src/config.cpp +++ b/source/duke3d/src/config.cpp @@ -106,6 +106,11 @@ static void CONFIG_SetJoystickAnalogAxisScale(int i, int scale) ud.config.JoystickAnalogueScale[i] = scale; CONTROL_SetAnalogAxisScale(i, scale, controldevice_joystick); } +static void CONFIG_SetJoystickAnalogAxisInvert(int i, int invert) +{ + ud.config.JoystickAnalogueInvert[i] = invert; + CONTROL_SetAnalogAxisInvert(i, invert, controldevice_joystick); +} static void CONFIG_SetJoystickAnalogAxisDeadSaturate(int i, int dead, int saturate) { ud.config.JoystickAnalogueDead[i] = dead; @@ -380,9 +385,11 @@ void CONFIG_SetDefaults(void) for (int i=0; i= (unsigned) MAXMOUSEAXES) + { + //Error("CONTROL_SetAnalogAxisInvert: axis %d out of valid range for %d mouse axes.", + // whichaxis, MAXMOUSEAXES); + return; + } + + set = CONTROL_MouseAxesInvert; + break; + + case controldevice_joystick: + if ((unsigned) whichaxis >= (unsigned) MAXJOYAXES) + { + //Error("CONTROL_SetAnalogAxisInvert: axis %d out of valid range for %d joystick axes.", + // whichaxis, MAXJOYAXES); + return; + } + + set = CONTROL_JoyAxesInvert; + break; + + default: + //Error("CONTROL_SetAnalogAxisInvert: invalid controller device type"); + return; + } + + set[whichaxis] = invert; +} + void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device) { controlaxismaptype *set; @@ -420,12 +458,14 @@ void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t di void CONTROL_ClearAssignments(void) { memset(CONTROL_JoyAxes, 0, sizeof(CONTROL_JoyAxes)); + memset(CONTROL_JoyAxesInvert, 0, sizeof(CONTROL_JoyAxesInvert)); memset(CONTROL_JoyAxesMap, AXISUNDEFINED, sizeof(CONTROL_JoyAxesMap)); memset(CONTROL_JoyButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_JoyButtonMapping)); // memset(CONTROL_KeyMapping, KEYUNDEFINED, sizeof(CONTROL_KeyMapping)); memset(CONTROL_LastJoyAxes, 0, sizeof(CONTROL_LastJoyAxes)); memset(CONTROL_LastMouseAxes, 0, sizeof(CONTROL_LastMouseAxes)); memset(CONTROL_MouseAxes, 0, sizeof(CONTROL_MouseAxes)); + memset(CONTROL_MouseAxesInvert, 0, sizeof(CONTROL_MouseAxesInvert)); memset(CONTROL_MouseAxesMap, AXISUNDEFINED, sizeof(CONTROL_MouseAxesMap)); memset(CONTROL_MouseButtonMapping, BUTTONUNDEFINED, sizeof(CONTROL_MouseButtonMapping)); @@ -570,23 +610,27 @@ static void CONTROL_ScaleAxis(int axis, controldevice device) { controlaxistype *set; int32_t *scale; + int8_t * invert; switch (device) { case controldevice_mouse: set = CONTROL_MouseAxes; scale = CONTROL_MouseAxesScale; + invert = CONTROL_MouseAxesInvert; break; case controldevice_joystick: set = CONTROL_JoyAxes; scale = CONTROL_JoyAxesScale; + invert = CONTROL_JoyAxesInvert; break; default: return; } - set[axis].analog = mulscale16(set[axis].analog, scale[axis]); + int const invertResult = !!invert[axis]; + set[axis].analog = (mulscale16(set[axis].analog, scale[axis]) ^ -invertResult) + invertResult; } static void CONTROL_ApplyAxis(int axis, ControlInfo *info, controldevice device)