XInput2: Only do a round trip when the mouse has moved

This should cut down on round trips and blocking calls dramatically
during gameplay.
This commit is contained in:
Jasper St. Pierre 2016-09-03 15:03:18 -07:00
parent 980ecfba7f
commit 2b640a4f7d
1 changed files with 7 additions and 3 deletions

View File

@ -216,12 +216,10 @@ void KeyboardMouse::UpdateInput()
{
XFlush(m_display);
// Get the absolute position of the mouse pointer
UpdateCursor();
// for the axis controls
float delta_x = 0.0f, delta_y = 0.0f;
double delta_delta;
bool mouse_moved = false;
// Iterate through the event queue - update the axis controls, mouse
// button controls, and keyboard controls.
@ -256,6 +254,8 @@ void KeyboardMouse::UpdateInput()
m_state.keyboard[dev_event->detail / 8] &= ~(1 << (dev_event->detail % 8));
break;
case XI_RawMotion:
mouse_moved = true;
// always safe because there is always at least one byte in
// raw_event->valuators.mask, and if a bit is set in the mask,
// then the value in raw_values is also available.
@ -286,6 +286,10 @@ void KeyboardMouse::UpdateInput()
m_state.axis.y *= MOUSE_AXIS_SMOOTHING;
m_state.axis.y += delta_y;
m_state.axis.y /= MOUSE_AXIS_SMOOTHING + 1.0f;
// Get the absolute position of the mouse pointer
if (mouse_moved)
UpdateCursor();
}
std::string KeyboardMouse::GetName() const