mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Skip counting controllers that haven't received a single event yet. This closes #38
This commit is contained in:
parent
ff753adcfe
commit
8c258c3eb5
16
gamepad.cpp
16
gamepad.cpp
@ -20,6 +20,7 @@ static const unsigned int k_StandardGamepadTriggerButtonIndexes[] = {
|
|||||||
|
|
||||||
void MoonlightInstance::PollGamepads() {
|
void MoonlightInstance::PollGamepads() {
|
||||||
PP_GamepadsSampleData gamepadData;
|
PP_GamepadsSampleData gamepadData;
|
||||||
|
short controllerIndex = 0;
|
||||||
|
|
||||||
m_GamepadApi->Sample(pp_instance(), &gamepadData);
|
m_GamepadApi->Sample(pp_instance(), &gamepadData);
|
||||||
|
|
||||||
@ -31,8 +32,18 @@ void MoonlightInstance::PollGamepads() {
|
|||||||
continue;
|
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]) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +86,8 @@ void MoonlightInstance::PollGamepads() {
|
|||||||
rightStickY = -padData.axes[3] * 0x7FFF;
|
rightStickY = -padData.axes[3] * 0x7FFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
LiSendMultiControllerEvent(p, buttonFlags, leftTrigger, rightTrigger,
|
LiSendMultiControllerEvent(controllerIndex, buttonFlags, leftTrigger, rightTrigger,
|
||||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
|
controllerIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user