Remapped XInput to be the same as DirectInput buttons, so that
existing configs works as expected. Hard-coded 6 axis for xbox controller to allow for triggers to be reported as two different axis (instead of as one axis). Updated gamepad config to use proper names for triggers.
This commit is contained in:
parent
68d41a07ba
commit
891e439264
@ -197,6 +197,11 @@ struct SJoystickWin32Control
|
|||||||
activeJoystick.axisValid[i+caxis]=1;
|
activeJoystick.axisValid[i+caxis]=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On Xbox 360 devices left and right trigger are reported as two
|
||||||
|
// different axes (instead of 1 with DirectInput), so we need one
|
||||||
|
// additional axis:
|
||||||
|
if (activeJoystick.m_use_xinput && activeJoystick.devcaps.dwAxes == 5)
|
||||||
|
activeJoystick.devcaps.dwAxes = 6;
|
||||||
ActiveJoysticks.push_back(activeJoystick);
|
ActiveJoysticks.push_back(activeJoystick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,8 +360,37 @@ void pollJoysticks()
|
|||||||
XINPUT_STATE state;
|
XINPUT_STATE state;
|
||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
DWORD result = XInputGetState(ActiveJoysticks[joystick].Index, &state);
|
DWORD result = XInputGetState(ActiveJoysticks[joystick].Index, &state);
|
||||||
event.JoystickEvent.ButtonStates = state.Gamepad.wButtons;
|
// XInput reports the buttons in a different order. So to keep
|
||||||
// Map the axis as they were previously, so existing configs
|
// old configs to work as expected, remap the buttons.
|
||||||
|
int abxy = (state.Gamepad.wButtons & (XINPUT_GAMEPAD_A |
|
||||||
|
XINPUT_GAMEPAD_B |
|
||||||
|
XINPUT_GAMEPAD_X |
|
||||||
|
XINPUT_GAMEPAD_Y )
|
||||||
|
) >> 12;
|
||||||
|
int shoulder = (state.Gamepad.wButtons & (XINPUT_GAMEPAD_LEFT_SHOULDER|
|
||||||
|
XINPUT_GAMEPAD_RIGHT_SHOULDER)
|
||||||
|
) >> 4;
|
||||||
|
int start = (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) << 3;
|
||||||
|
int back = (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK ) << 1;
|
||||||
|
|
||||||
|
event.JoystickEvent.ButtonStates = abxy | shoulder | start | back;
|
||||||
|
int angle = 65535;
|
||||||
|
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
|
||||||
|
{
|
||||||
|
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) angle = 22500;
|
||||||
|
else if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) angle = 13500;
|
||||||
|
else angle = 18000;
|
||||||
|
}
|
||||||
|
else if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP)
|
||||||
|
{
|
||||||
|
if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) angle = 31500;
|
||||||
|
else if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) angle = 4500;
|
||||||
|
else angle = 0;
|
||||||
|
}
|
||||||
|
else if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) angle = 9000;
|
||||||
|
else if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) angle = 27000;
|
||||||
|
event.JoystickEvent.POV = angle;
|
||||||
|
// Map the axis as they were previously, so existing configs
|
||||||
// still work as expected. The Y axis needs to be reversed:
|
// still work as expected. The Y axis needs to be reversed:
|
||||||
// -32768 --> 32767, ..., 32767 --> -32768
|
// -32768 --> 32767, ..., 32767 --> -32768
|
||||||
// Inverting the bits with ~ does that (-sThumbLY would map -32768 to -32768!!)
|
// Inverting the bits with ~ does that (-sThumbLY would map -32768 to -32768!!)
|
||||||
|
@ -236,10 +236,7 @@ core::stringw GamepadConfig::getBindingAsString(const PlayerAction action) const
|
|||||||
// I18N: name of stick on gamepads
|
// I18N: name of stick on gamepads
|
||||||
: _("Left thumb up");
|
: _("Left thumb up");
|
||||||
// I18N: name of stick on gamepads
|
// I18N: name of stick on gamepads
|
||||||
case 2: return (ad==Input::AD_POSITIVE) ? _("Left trigger")
|
case 2: return _("Left trigger"); // I18N: name of trigger on gamepads
|
||||||
// I18N: name of stick on gamepads
|
|
||||||
: _("Right trigger");
|
|
||||||
// I18N: name of stick on gamepads
|
|
||||||
case 3: return (ad==Input::AD_POSITIVE) ? _("Right thumb down")
|
case 3: return (ad==Input::AD_POSITIVE) ? _("Right thumb down")
|
||||||
// I18N: name of stick on gamepads
|
// I18N: name of stick on gamepads
|
||||||
: _("Right thumb up");
|
: _("Right thumb up");
|
||||||
@ -248,7 +245,8 @@ core::stringw GamepadConfig::getBindingAsString(const PlayerAction action) const
|
|||||||
// I18N: name of stick on gamepads
|
// I18N: name of stick on gamepads
|
||||||
: _("Right thumb left");
|
: _("Right thumb left");
|
||||||
// I18N: name of buttons on gamepads
|
// I18N: name of buttons on gamepads
|
||||||
case Input::HAT_H_ID: return (ad == Input::AD_POSITIVE) ? _("DPad up")
|
case 5: return _("Right trigger"); // I18N: name of trigger on gamepads
|
||||||
|
case Input::HAT_H_ID: return (ad == Input::AD_POSITIVE) ? _("DPad up")
|
||||||
// I18N: name of buttons on gamepads
|
// I18N: name of buttons on gamepads
|
||||||
: _("DPad down");
|
: _("DPad down");
|
||||||
// I18N: name of buttons on gamepads
|
// I18N: name of buttons on gamepads
|
||||||
|
Loading…
Reference in New Issue
Block a user