Add gamepad axis inversion toggles

git-svn-id: https://svn.eduke32.com/eduke32@7986 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2019-08-14 03:03:57 +00:00 committed by Christoph Oelckers
parent 1bbd251bff
commit cb405ced52
6 changed files with 72 additions and 3 deletions

View file

@ -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<MAXJOYAXES; i++)
{
ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
ud.config.JoystickAnalogueInvert[i] = 0;
ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
CONTROL_SetAnalogAxisInvert(i, 0, controldevice_joystick);
ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
@ -551,6 +558,11 @@ void CONFIG_SetupJoystick(void)
SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
ud.config.JoystickAnalogueScale[i] = scale;
Bsprintf(str,"ControllerAnalogInvert%d",i);
scale = ud.config.JoystickAnalogueInvert[i];
SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
ud.config.JoystickAnalogueInvert[i] = scale;
Bsprintf(str,"ControllerAnalogDead%d",i);
scale = ud.config.JoystickAnalogueDead[i];
SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
@ -573,6 +585,7 @@ void CONFIG_SetupJoystick(void)
CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
CONTROL_SetAnalogAxisInvert(i, ud.config.JoystickAnalogueInvert[i], controldevice_joystick);
}
}
@ -753,6 +766,7 @@ void CONFIG_SetGameControllerDefaultsClear()
for (int i=0; i<MAXJOYAXES; i++)
{
CONFIG_SetJoystickAnalogAxisScale(i, DEFAULTJOYSTICKANALOGUESCALE);
CONFIG_SetJoystickAnalogAxisInvert(i, 0);
CONFIG_SetJoystickAnalogAxisDeadSaturate(i, DEFAULTJOYSTICKANALOGUEDEAD, DEFAULTJOYSTICKANALOGUESATURATE);
CONFIG_SetJoystickDigitalAxisFunction(i, 0, -1);
@ -1082,6 +1096,9 @@ void CONFIG_WriteSetup(uint32_t flags)
Bsprintf(buf, "ControllerAnalogScale%d", dummy);
SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
Bsprintf(buf, "ControllerAnalogInvert%d", dummy);
SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueInvert[dummy], FALSE, FALSE);
Bsprintf(buf, "ControllerAnalogDead%d", dummy);
SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);

View file

@ -246,6 +246,7 @@ typedef struct {
int32_t JoystickDigitalFunctions[MAXJOYAXES][2];
int32_t JoystickAnalogueAxes[MAXJOYAXES];
int32_t JoystickAnalogueScale[MAXJOYAXES];
int32_t JoystickAnalogueInvert[MAXJOYAXES];
int32_t JoystickAnalogueDead[MAXJOYAXES];
int32_t JoystickAnalogueSaturate[MAXJOYAXES];
uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2];

View file

@ -1023,6 +1023,8 @@ static MenuOption_t MEO_JOYSTICKAXIS_ANALOG = MAKE_MENUOPTION( &MF_Bluefont, &ME
static MenuEntry_t ME_JOYSTICKAXIS_ANALOG = MAKE_MENUENTRY( "Analog", &MF_Redfont, &MEF_BigSliders, &MEO_JOYSTICKAXIS_ANALOG, Option );
static MenuRangeInt32_t MEO_JOYSTICKAXIS_SCALE = MAKE_MENURANGE( NULL, &MF_Bluefont, -262144, 262144, 65536, 161, 3 );
static MenuEntry_t ME_JOYSTICKAXIS_SCALE = MAKE_MENUENTRY( "Scale", &MF_Redfont, &MEF_BigSliders, &MEO_JOYSTICKAXIS_SCALE, RangeInt32 );
static MenuOption_t MEO_JOYSTICKAXIS_INVERT = MAKE_MENUOPTION( &MF_Redfont, &MEOS_OffOn, NULL );
static MenuEntry_t ME_JOYSTICKAXIS_INVERT = MAKE_MENUENTRY( "Invert", &MF_Redfont, &MEF_BigSliders, &MEO_JOYSTICKAXIS_INVERT, Option );
static MenuRangeInt32_t MEO_JOYSTICKAXIS_DEAD = MAKE_MENURANGE( NULL, &MF_Bluefont, 0, 10000, 0, 101, 2 );
static MenuEntry_t ME_JOYSTICKAXIS_DEAD = MAKE_MENUENTRY( "Dead Zone", &MF_Redfont, &MEF_BigSliders, &MEO_JOYSTICKAXIS_DEAD, RangeInt32 );
static MenuRangeInt32_t MEO_JOYSTICKAXIS_SATU = MAKE_MENURANGE( NULL, &MF_Bluefont, 0, 10000, 0, 101, 2 );
@ -1036,6 +1038,7 @@ static MenuEntry_t ME_JOYSTICKAXIS_DIGITALPOSITIVE = MAKE_MENUENTRY( "Digital +"
static MenuEntry_t *MEL_JOYSTICKAXIS[] = {
&ME_JOYSTICKAXIS_ANALOG,
&ME_JOYSTICKAXIS_SCALE,
&ME_JOYSTICKAXIS_INVERT,
&ME_JOYSTICKAXIS_DEAD,
&ME_JOYSTICKAXIS_SATU,
&ME_Space8_Redfont,
@ -3223,6 +3226,7 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
M_JOYSTICKAXIS.title = joyGetName(0, M_JOYSTICKAXES.currentEntry);
MEO_JOYSTICKAXIS_ANALOG.data = &ud.config.JoystickAnalogueAxes[M_JOYSTICKAXES.currentEntry];
MEO_JOYSTICKAXIS_SCALE.variable = &ud.config.JoystickAnalogueScale[M_JOYSTICKAXES.currentEntry];
MEO_JOYSTICKAXIS_INVERT.data = &ud.config.JoystickAnalogueInvert[M_JOYSTICKAXES.currentEntry];
MEO_JOYSTICKAXIS_DEAD.variable = &ud.config.JoystickAnalogueDead[M_JOYSTICKAXES.currentEntry];
MEO_JOYSTICKAXIS_SATU.variable = &ud.config.JoystickAnalogueSaturate[M_JOYSTICKAXES.currentEntry];
MEO_JOYSTICKAXIS_DIGITALNEGATIVE.data = &ud.config.JoystickDigitalFunctions[M_JOYSTICKAXES.currentEntry][0];
@ -3387,6 +3391,8 @@ static int32_t Menu_EntryOptionModify(MenuEntry_t *entry, int32_t newOption)
}
else if (entry == &ME_JOYSTICKAXIS_ANALOG)
CONTROL_MapAnalogAxis(M_JOYSTICKAXES.currentEntry, newOption, controldevice_joystick);
else if (entry == &ME_JOYSTICKAXIS_INVERT)
CONTROL_SetAnalogAxisInvert(M_JOYSTICKAXES.currentEntry, newOption, controldevice_joystick);
else if (entry == &ME_NETOPTIONS_EPISODE)
{
if (newOption < g_volumeCnt)

View file

@ -171,8 +171,8 @@ typedef struct
typedef struct
{
int32_t analog;
int32_t digital;
int16_t digitalClearedN, digitalClearedP;
int8_t digital;
int8_t digitalClearedN, digitalClearedP;
} controlaxistype;

View file

@ -197,6 +197,7 @@ void CONTROL_Shutdown( void );
void CONTROL_MapAnalogAxis(int whichaxis, int whichanalog, controldevice device);
void CONTROL_MapDigitalAxis(int32_t whichaxis, int32_t whichfunction, int32_t direction, controldevice device);
void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device);
void CONTROL_SetAnalogAxisInvert(int32_t whichaxis, int32_t invert, controldevice device);
void CONTROL_ScanForControllers(void);

View file

@ -43,11 +43,13 @@ static controlaxismaptype CONTROL_MouseAxesMap[MAXMOUSEAXES]; // maps physical
static controlaxistype CONTROL_MouseAxes[MAXMOUSEAXES]; // physical axes
static controlaxistype CONTROL_LastMouseAxes[MAXMOUSEAXES];
static int32_t CONTROL_MouseAxesScale[MAXMOUSEAXES];
static int8_t CONTROL_MouseAxesInvert[MAXMOUSEAXES];
static controlaxismaptype CONTROL_JoyAxesMap[MAXJOYAXES];
static controlaxistype CONTROL_JoyAxes[MAXJOYAXES];
static controlaxistype CONTROL_LastJoyAxes[MAXJOYAXES];
static int32_t CONTROL_JoyAxesScale[MAXJOYAXES];
static int8_t CONTROL_JoyAxesInvert[MAXJOYAXES];
static controlbuttontype CONTROL_MouseButtonMapping[MAXMOUSEBUTTONS];
@ -367,6 +369,42 @@ void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldev
set[whichaxis] = axisscale;
}
void CONTROL_SetAnalogAxisInvert(int32_t whichaxis, int32_t invert, controldevice device)
{
int8_t * set;
switch (device)
{
case controldevice_mouse:
if ((unsigned) whichaxis >= (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)