Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mact: Add single axis deadzone flag for analog stick distance calculation #848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions source/blood/src/_functio.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ static const int32_t joystickanalogdeaddefaults[MAXJOYAXES] =
};


static const int32_t joystickanalogaxissolodeadzone[MAXJOYAXES] =
{
1,
0,
0,
0,
};


static const int32_t joystickanalogsaturatedefaults[MAXJOYAXES] =
{
DEFAULTJOYSTICKANALOGUESATURATE*3,
Expand Down
16 changes: 16 additions & 0 deletions source/blood/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int32_t JoystickAnalogueScale[MAXJOYAXES];
int32_t JoystickAnalogueDead[MAXJOYAXES];
int32_t JoystickAnalogueSaturate[MAXJOYAXES];
int32_t JoystickAnalogueInvert[MAXJOYAXES];
int32_t JoystickAnalogueAxisSoloDeadZone[MAXJOYAXES];
uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2];
int32_t scripthandle;
int32_t setupread;
Expand Down Expand Up @@ -481,6 +482,9 @@ void CONFIG_SetDefaults(void)

JoystickAnalogueInvert[i] = 0;
CONTROL_SetAnalogAxisInvert(i, JoystickAnalogueInvert[i]);

JoystickAnalogueAxisSoloDeadZone[i] = 0;
JOYSTICK_SetAxisSoloDeadZone(i, JoystickAnalogueAxisSoloDeadZone[i]);
}
#else
for (int i=0; i<MAXJOYBUTTONSANDHATS; i++)
Expand Down Expand Up @@ -509,6 +513,9 @@ void CONFIG_SetDefaults(void)

JoystickAnalogueInvert[i] = 0;
CONTROL_SetAnalogAxisInvert(i, JoystickAnalogueInvert[i]);

JoystickAnalogueAxisSoloDeadZone[i] = joystickanalogaxissolodeadzone[i];
JOYSTICK_SetAxisSoloDeadZone(i, JoystickAnalogueAxisSoloDeadZone[i]);
}
#endif
}
Expand Down Expand Up @@ -670,6 +677,11 @@ void CONFIG_SetupJoystick(void)
scale = JoystickAnalogueInvert[i];
SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
JoystickAnalogueInvert[i] = scale;

Bsprintf(str,"JoystickAnalogAxisSoloDeadZone%d",i);
scale = JoystickAnalogueAxisSoloDeadZone[i];
SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
JoystickAnalogueAxisSoloDeadZone[i] = scale;
}

for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
Expand All @@ -685,6 +697,7 @@ void CONFIG_SetupJoystick(void)
CONTROL_SetAnalogAxisScale(i, JoystickAnalogueScale[i], controldevice_joystick);
JOYSTICK_SetDeadZone(i, JoystickAnalogueDead[i], JoystickAnalogueSaturate[i]);
CONTROL_SetAnalogAxisInvert(i, JoystickAnalogueInvert[i]);
JOYSTICK_SetAxisSoloDeadZone(i, JoystickAnalogueAxisSoloDeadZone[i]);
}
}

Expand Down Expand Up @@ -985,6 +998,9 @@ void CONFIG_WriteSetup(uint32_t flags)

Bsprintf(buf, "JoystickAnalogInvert%d", dummy);
SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogueInvert[dummy], FALSE, FALSE);

Bsprintf(buf, "JoystickAnalogAxisSoloDeadZone%d", dummy);
SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogueAxisSoloDeadZone[dummy], FALSE, FALSE);
}
}

Expand Down
1 change: 1 addition & 0 deletions source/blood/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern int32_t JoystickAnalogueScale[MAXJOYAXES];
extern int32_t JoystickAnalogueDead[MAXJOYAXES];
extern int32_t JoystickAnalogueSaturate[MAXJOYAXES];
extern int32_t JoystickAnalogueInvert[MAXJOYAXES];
extern int32_t JoystickAnalogueAxisSoloDeadZone[MAXJOYAXES];
extern uint8_t KeyboardKeys[NUMGAMEFUNCTIONS][2];
extern int32_t scripthandle;
extern int32_t setupread;
Expand Down
26 changes: 23 additions & 3 deletions source/blood/src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ void SetJoystickDigitalPos(CGameMenuItemZCycle* pItem);
void SetJoystickDigitalNeg(CGameMenuItemZCycle* pItem);
void SetJoystickDeadzone(CGameMenuItemSlider* pItem);
void SetJoystickSaturate(CGameMenuItemSlider* pItem);
void SetJoystickSoloDeadzone(CGameMenuItemZBool* pItem);

const char *pzTurnAccelerationStrings[] = {
"OFF",
Expand Down Expand Up @@ -838,6 +839,7 @@ CGameMenuItemZCycle *pItemOptionsControlJoystickAxisDigitalPos[MAXJOYAXES];
CGameMenuItemZCycle *pItemOptionsControlJoystickAxisDigitalNeg[MAXJOYAXES];
CGameMenuItemSlider *pItemOptionsControlJoystickAxisDeadzone[MAXJOYAXES];
CGameMenuItemSlider *pItemOptionsControlJoystickAxisSaturate[MAXJOYAXES];
CGameMenuItemZBool *pItemOptionsControlJoystickAxisSoloDeadzone[MAXJOYAXES];

void SetupLoadingScreen(void)
{
Expand Down Expand Up @@ -1561,11 +1563,11 @@ void SetupJoystickMenu(void)
pItemOptionsControlJoystickAxisName[nAxis] = new CGameMenuItemTitle(MenuJoyAxisNames[nAxis], 3, 160, y, -1); // get axis name
dassert(pItemOptionsControlJoystickAxisName[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisName[nAxis], false);
y += 12;
y += 10;
pItemOptionsControlJoystickAxisScale[nAxis] = new CGameMenuItemSlider("AXIS SCALE:", 1, 18, y, 280, &JoystickAnalogueScale[nAxis], fix16_from_int(0), fix16_from_float(2.f), fix16_from_float(0.025f), SetJoystickScale, -1, -1, kMenuSliderQ16); // get axis scale
dassert(pItemOptionsControlJoystickAxisScale[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisScale[nAxis], true);
y += 25;
y += 22;
pItemOptionsControlJoystickAxisAnalogue[nAxis] = new CGameMenuItemZCycle("ANALOG:", 1, 18, y, 280, 0, SetJoystickAnalogue, zJoystickAnalogue, ARRAY_SSIZE(zJoystickAnalogue), 0); // get analog function
dassert(pItemOptionsControlJoystickAxisAnalogue[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisAnalogue[nAxis], false);
Expand All @@ -1581,14 +1583,18 @@ void SetupJoystickMenu(void)
pItemOptionsControlJoystickAxisDigitalNeg[nAxis] = new CGameMenuItemZCycle("DIGITAL -:", 1, 18, y, 280, 0, SetJoystickDigitalNeg, pzGamefuncsStrings, NUMGAMEFUNCTIONS+1, 0, true); // get digital function
dassert(pItemOptionsControlJoystickAxisDigitalNeg[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisDigitalNeg[nAxis], false);
y += 25;
y += 22;
pItemOptionsControlJoystickAxisDeadzone[nAxis] = new CGameMenuItemSlider("DEAD ZONE:", 1, 18, y, 280, &JoystickAnalogueDead[nAxis], fix16_from_int(0), fix16_from_float(0.5f), fix16_from_float(0.025f), SetJoystickDeadzone, -1, -1, kMenuSliderPercent); // get dead size
dassert(pItemOptionsControlJoystickAxisDeadzone[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisDeadzone[nAxis], false);
y += 17;
pItemOptionsControlJoystickAxisSaturate[nAxis] = new CGameMenuItemSlider("SATURATE:", 1, 18, y, 280, &JoystickAnalogueSaturate[nAxis], fix16_from_int(0), fix16_from_float(0.5f), fix16_from_float(0.025f), SetJoystickSaturate, -1, -1, kMenuSliderPercent); // get saturate
dassert(pItemOptionsControlJoystickAxisSaturate[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisSaturate[nAxis], false);
y += 17;
pItemOptionsControlJoystickAxisSoloDeadzone[nAxis] = new CGameMenuItemZBool("SINGLE AXIS DEAD ZONE:", 1, 18, y, 280, false, SetJoystickSoloDeadzone, NULL, NULL); // get isolated dead
dassert(pItemOptionsControlJoystickAxisSoloDeadzone[nAxis] != NULL);
menuOptionsControlJoystickAxis[nAxis].Add(pItemOptionsControlJoystickAxisSoloDeadzone[nAxis], false);
menuOptionsControlJoystickAxis[nAxis].Add(&itemBloodQAV, false);
}
}
Expand Down Expand Up @@ -2400,6 +2406,7 @@ void SetupJoystickAxesMenu(CGameMenuItemChain *pItem)
}
pItemOptionsControlJoystickAxisDeadzone[nAxis]->nValue = JoystickAnalogueDead[nAxis];
pItemOptionsControlJoystickAxisSaturate[nAxis]->nValue = JoystickAnalogueSaturate[nAxis];
pItemOptionsControlJoystickAxisSoloDeadzone[nAxis]->at20 = JoystickAnalogueAxisSoloDeadZone[nAxis];
}
}

Expand Down Expand Up @@ -2526,6 +2533,19 @@ void SetJoystickSaturate(CGameMenuItemSlider* pItem)
}
}

void SetJoystickSoloDeadzone(CGameMenuItemZBool* pItem)
{
for (int nAxis = 0; nAxis < MAXJOYAXES; nAxis++)
{
if (pItem == pItemOptionsControlJoystickAxisSoloDeadzone[nAxis])
{
JoystickAnalogueAxisSoloDeadZone[nAxis] = pItem->at20;
JOYSTICK_SetAxisSoloDeadZone(nAxis, JoystickAnalogueAxisSoloDeadZone[nAxis]);
break;
}
}
}

void PreDrawControlMouse(CGameMenuItem *pItem)
{
if (pItem == &itemOptionsControlMouseVerticalAim)
Expand Down
1 change: 1 addition & 0 deletions source/mact/include/_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ typedef struct ControllerAxis
uint16_t deadzone;
uint16_t saturation;
bool invert;
bool solodeadzone;
} ControllerAxis_t;

typedef struct UserInputState
Expand Down
1 change: 1 addition & 0 deletions source/mact/include/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int32_t JOYSTICK_GetControllerButtons( void );
void JOYSTICK_ClearAllButtons( void );
int32_t JOYSTICK_GetHat( int32_t h );
void JOYSTICK_SetDeadZone(int32_t axis, uint16_t dead, uint16_t satur);
void JOYSTICK_SetAxisSoloDeadZone(int32_t axis, bool dead);

#ifdef __cplusplus
}
Expand Down
7 changes: 6 additions & 1 deletion source/mact/src/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ void JOYSTICK_SetDeadZone(int32_t axis, uint16_t dead, uint16_t satur)
joyAxes[axis].saturation = satur;
}

void JOYSTICK_SetAxisSoloDeadZone(int32_t axis, bool dead)
{
joyAxes[axis].solodeadzone = dead;
}

void CONTROL_SetAnalogAxisScale(int32_t whichaxis, int32_t axisscale, controldevice device)
{
float *set;
Expand Down Expand Up @@ -488,7 +493,7 @@ static void controlUpdateAxisState(int index, ControlInfo *const info)
else
{
// this assumes there are two sticks comprised of axes 0 and 1, and 2 and 3... because when isGameController is true, there are
if (index <= CONTROLLER_AXIS_LEFTY || (joystick.isGameController && (index <= CONTROLLER_AXIS_RIGHTY)))
if (!a.solodeadzone && (index <= CONTROLLER_AXIS_LEFTY || (joystick.isGameController && (index <= CONTROLLER_AXIS_RIGHTY))))
axisScaled10k = min(10000, joydist(joystick.pAxis[index & ~1], joystick.pAxis[index | 1]) * 10000 / 32767);

if (axisScaled10k < a.deadzone)
Expand Down