Skip to content

Commit

Permalink
Fix mouse buttons stick on low FPS
Browse files Browse the repository at this point in the history
Thanks @Giperion

Also remove code dublication when checking mouse hold
  • Loading branch information
Xottab-DUTY committed Jan 10, 2018
1 parent 7a1bb10 commit 943d499
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/xrEngine/Xr_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,42 @@ void CInput::MouseUpdate()
}
}

if (mouseState[0] && mouse_prev[0])
// Giperion: double check mouse buttons state
DIMOUSESTATE2 MouseState;
hr = pMouse->GetDeviceState(sizeof(MouseState), &MouseState);

auto RecheckMouseButtonFunc = [&](int i)
{
cbStack.back()->IR_OnMouseHold(0);
}
if (MouseState.rgbButtons[i] & 0x80 && mouseState[i] == FALSE)
{
mouseState[i] = TRUE;
cbStack.back()->IR_OnMousePress(i);
}
else if (!(MouseState.rgbButtons[i] & 0x80) && mouseState[i] == TRUE)
{
mouseState[i] = FALSE;
cbStack.back()->IR_OnMouseRelease(i);
}
};

if (mouseState[1] && mouse_prev[1])
if (hr == S_OK)
{
cbStack.back()->IR_OnMouseHold(1);
RecheckMouseButtonFunc(0);
RecheckMouseButtonFunc(1);
RecheckMouseButtonFunc(2);
}
//-Giperion

if (mouseState[2] && mouse_prev[2])
auto isButtonOnHold = [&](int i)
{
cbStack.back()->IR_OnMouseHold(2);
}
if (mouseState[i] && mouse_prev[i])
cbStack.back()->IR_OnMouseHold(i);
};

isButtonOnHold(0);
isButtonOnHold(1);
isButtonOnHold(2);

if (dwElements)
{
if (offs[0] || offs[1])
Expand Down

0 comments on commit 943d499

Please sign in to comment.