Permalink
Browse files

Skip counting controllers that haven't received a single event yet. T…

…his closes #38
  • Loading branch information...
1 parent ff753ad commit 8c258c3eb5f862e91493f4b9adef08118c8f8d6f @cgutman cgutman committed Apr 16, 2016
Showing with 14 additions and 2 deletions.
  1. +14 −2 gamepad.cpp
View
@@ -20,6 +20,7 @@ static const unsigned int k_StandardGamepadTriggerButtonIndexes[] = {
void MoonlightInstance::PollGamepads() {
PP_GamepadsSampleData gamepadData;
+ short controllerIndex = 0;
m_GamepadApi->Sample(pp_instance(), &gamepadData);
@@ -31,8 +32,18 @@ void MoonlightInstance::PollGamepads() {
continue;
}
+ if (padData.timestamp == 0) {
+ // On some platforms, Chrome returns "connected" pads that
+ // really aren't, so timestamp stays at zero. To work around this,
+ // we'll only count gamepads that have a non-zero timestamp in our
+ // controller index.
+ continue;
+ }
+
if (padData.timestamp == m_LastPadTimestamps[p]) {
- // No change from last poll
+ // No change from last poll, but this controller is still valid
+ // so we skip this index.
+ controllerIndex++;
continue;
}
@@ -75,7 +86,8 @@ void MoonlightInstance::PollGamepads() {
rightStickY = -padData.axes[3] * 0x7FFF;
}
- LiSendMultiControllerEvent(p, buttonFlags, leftTrigger, rightTrigger,
+ LiSendMultiControllerEvent(controllerIndex, buttonFlags, leftTrigger, rightTrigger,
leftStickX, leftStickY, rightStickX, rightStickY);
+ controllerIndex++;
}
}

0 comments on commit 8c258c3

Please sign in to comment.