Skip to content

Commit

Permalink
Bug 1606562 - Fixes XInput thumb value ranges. r=jmathies
Browse files Browse the repository at this point in the history
sThumbXXX in XInput is a short and its value range is between -32768 and 32767.

Differential Revision: https://phabricator.services.mozilla.com/D60876

--HG--
extra : moz-landing-system : lando
  • Loading branch information
daoshengmu committed Feb 12, 2020
1 parent e3c114a commit 568789d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions dom/gamepad/windows/WindowsGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,13 @@ void WindowsGamepadService::CheckXInputChanges(Gamepad& gamepad,

// Then triggers
if (state.Gamepad.bLeftTrigger != gamepad.state.Gamepad.bLeftTrigger) {
bool pressed =
const bool pressed =
state.Gamepad.bLeftTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
service->NewButtonEvent(gamepad.id, kButtonLeftTrigger, pressed,
state.Gamepad.bLeftTrigger / 255.0);
}
if (state.Gamepad.bRightTrigger != gamepad.state.Gamepad.bRightTrigger) {
bool pressed =
const bool pressed =
state.Gamepad.bRightTrigger >= XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
service->NewButtonEvent(gamepad.id, kButtonRightTrigger, pressed,
state.Gamepad.bRightTrigger / 255.0);
Expand All @@ -531,20 +531,24 @@ void WindowsGamepadService::CheckXInputChanges(Gamepad& gamepad,
// Finally deal with analog sticks
// TODO: bug 1001955 - Support deadzones.
if (state.Gamepad.sThumbLX != gamepad.state.Gamepad.sThumbLX) {
const float div = state.Gamepad.sThumbLX > 0 ? 32767.0 : 32768.0;
service->NewAxisMoveEvent(gamepad.id, kLeftStickXAxis,
state.Gamepad.sThumbLX / 32767.0);
state.Gamepad.sThumbLX / div);
}
if (state.Gamepad.sThumbLY != gamepad.state.Gamepad.sThumbLY) {
const float div = state.Gamepad.sThumbLY > 0 ? 32767.0 : 32768.0;
service->NewAxisMoveEvent(gamepad.id, kLeftStickYAxis,
-1.0 * state.Gamepad.sThumbLY / 32767.0);
-1.0 * state.Gamepad.sThumbLY / div);
}
if (state.Gamepad.sThumbRX != gamepad.state.Gamepad.sThumbRX) {
const float div = state.Gamepad.sThumbRX > 0 ? 32767.0 : 32768.0;
service->NewAxisMoveEvent(gamepad.id, kRightStickXAxis,
state.Gamepad.sThumbRX / 32767.0);
state.Gamepad.sThumbRX / div);
}
if (state.Gamepad.sThumbRY != gamepad.state.Gamepad.sThumbRY) {
const float div = state.Gamepad.sThumbRY > 0 ? 32767.0 : 32768.0;
service->NewAxisMoveEvent(gamepad.id, kRightStickYAxis,
-1.0 * state.Gamepad.sThumbRY / 32767.0);
-1.0 * state.Gamepad.sThumbRY / div);
}
gamepad.state = state;
}
Expand Down

0 comments on commit 568789d

Please sign in to comment.