SDLControllerInterface: Pass player ID to hooks not joystick ID

Should fix controllers which show up as non-zero players.
This commit is contained in:
Connor McLaughlin 2020-04-05 01:28:06 +10:00
parent 3cfead36c4
commit cae2e09957

View file

@ -238,13 +238,13 @@ bool SDLControllerInterface::HandleControllerAxisEvent(const SDL_Event* ev)
const float value = static_cast<float>(ev->caxis.value) / (ev->caxis.value < 0 ? 32768.0f : 32767.0f);
Log_DebugPrintf("controller %d axis %d %d %f", ev->caxis.which, ev->caxis.axis, ev->caxis.value, value);
if (DoEventHook(Hook::Type::Axis, ev->caxis.which, ev->caxis.axis, value))
return true;
auto it = GetControllerDataForJoystickId(ev->caxis.which);
if (it == m_controllers.end())
return false;
if (DoEventHook(Hook::Type::Axis, it->player_id, ev->caxis.axis, value))
return true;
const AxisCallback& cb = it->axis_mapping[ev->caxis.axis];
if (cb)
{
@ -280,14 +280,14 @@ bool SDLControllerInterface::HandleControllerButtonEvent(const SDL_Event* ev)
Log_DebugPrintf("controller %d button %d %s", ev->cbutton.which, ev->cbutton.button,
ev->cbutton.state == SDL_PRESSED ? "pressed" : "released");
const bool pressed = (ev->cbutton.state == SDL_PRESSED);
if (DoEventHook(Hook::Type::Button, ev->cbutton.which, ev->cbutton.button, pressed ? 1.0f : 0.0f))
return true;
auto it = GetControllerDataForJoystickId(ev->caxis.which);
if (it == m_controllers.end())
return false;
const bool pressed = (ev->cbutton.state == SDL_PRESSED);
if (DoEventHook(Hook::Type::Button, it->player_id, ev->cbutton.button, pressed ? 1.0f : 0.0f))
return true;
const ButtonCallback& cb = it->button_mapping[ev->cbutton.button];
if (!cb)
return false;