Work around SDL issues in Joystick:getGamepadMapping with XInput controllers (issue #1239).

This doesn’t fix the underlying issues in SDL so there may be other aspects of love.joystick which are still affected.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-12-10 16:14:14 -04:00
parent 8e2d9c5138
commit b620f32200
9 changed files with 134 additions and 190 deletions
+53
View File
@@ -248,6 +248,59 @@ bool Joystick::isGamepadDown(const std::vector<GamepadButton> &blist) const
return false;
}
Joystick::JoystickInput Joystick::getGamepadMapping(const GamepadInput &input) const
{
Joystick::JoystickInput jinput;
jinput.type = INPUT_TYPE_MAX_ENUM;
if (!isGamepad())
return jinput;
SDL_GameControllerButtonBind sdlbind = {};
sdlbind.bindType = SDL_CONTROLLER_BINDTYPE_NONE;
SDL_GameControllerButton sdlbutton;
SDL_GameControllerAxis sdlaxis;
switch (input.type)
{
case INPUT_TYPE_BUTTON:
if (getConstant(input.button, sdlbutton))
sdlbind = SDL_GameControllerGetBindForButton(controller, sdlbutton);
break;
case INPUT_TYPE_AXIS:
if (getConstant(input.axis, sdlaxis))
sdlbind = SDL_GameControllerGetBindForAxis(controller, sdlaxis);
break;
default:
break;
}
switch (sdlbind.bindType)
{
case SDL_CONTROLLER_BINDTYPE_BUTTON:
jinput.type = INPUT_TYPE_BUTTON;
jinput.button = sdlbind.value.button;
break;
case SDL_CONTROLLER_BINDTYPE_AXIS:
jinput.type = INPUT_TYPE_AXIS;
jinput.axis = sdlbind.value.axis;
break;
case SDL_CONTROLLER_BINDTYPE_HAT:
if (getConstant(sdlbind.value.hat.hat_mask, jinput.hat.value))
{
jinput.type = INPUT_TYPE_HAT;
jinput.hat.index = sdlbind.value.hat.hat;
}
break;
case SDL_CONTROLLER_BINDTYPE_NONE:
default:
break;
}
return jinput;
}
void *Joystick::getHandle() const
{
return joyhandle;