Skip to content

Commit abedff5

Browse files
committed
Change joystick SOCD to match D-Pad
Up + Down = Up, Left + Right =Neutral. If the user sets the flag to disable the SOCD cleaner then both directions are neutral.
1 parent c12a974 commit abedff5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/XInput.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void XInputController::setJoystick(XInputControl joy, int32_t x, int32_t y) {
277277
setJoystickDirect(joy, x, y);
278278
}
279279

280-
void XInputController::setJoystick(XInputControl joy, boolean up, boolean down, boolean left, boolean right) {
280+
void XInputController::setJoystick(XInputControl joy, boolean up, boolean down, boolean left, boolean right, boolean useSOCD) {
281281
const XInputMap_Joystick * joyData = getJoyFromEnum(joy);
282282
if (joyData == nullptr) return; // Not a joystick
283283

@@ -287,7 +287,14 @@ void XInputController::setJoystick(XInputControl joy, boolean up, boolean down,
287287
int16_t y = 0;
288288

289289
// Simultaneous Opposite Cardinal Directions (SOCD) Cleaner
290-
// (Mutually exclusive. Avoids the '-1' result from adding the int16 extremes)
290+
if (useSOCD) {
291+
if (up && down) { down = false; } // Up + Down = Up
292+
if (left && right) { left = false; right = false; } // Left + Right = Neutral
293+
}
294+
295+
// Analog axis means directions are mutually exclusive. Only change the
296+
// output from '0' if the per-axis inputs are different, in order to
297+
// avoid the '-1' result from adding the int16 extremes
291298
if (left != right) {
292299
x = (right * range.max) - (left * range.min);
293300
}

src/XInput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class XInputController {
9191
void setTrigger(XInputControl trigger, int32_t val);
9292

9393
void setJoystick(XInputControl joy, int32_t x, int32_t y);
94-
void setJoystick(XInputControl joy, boolean up, boolean down, boolean left, boolean right);
94+
void setJoystick(XInputControl joy, boolean up, boolean down, boolean left, boolean right, boolean useSOCD = true);
9595

9696
void releaseAll();
9797

0 commit comments

Comments
 (0)