Improve mouse batching to only batch if the last event was less than 1 millisecond ago
This commit is contained in:
parent
9aa487418f
commit
9a71b4c237
2 changed files with 14 additions and 4 deletions
|
|
@ -23,7 +23,8 @@ const int SdlInputHandler::k_ButtonMap[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
SdlInputHandler::SdlInputHandler(bool multiController)
|
SdlInputHandler::SdlInputHandler(bool multiController)
|
||||||
: m_MultiController(multiController)
|
: m_LastMouseMotionTime(0),
|
||||||
|
m_MultiController(multiController)
|
||||||
{
|
{
|
||||||
// Allow gamepad input when the app doesn't have focus
|
// Allow gamepad input when the app doesn't have focus
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||||
|
|
@ -391,11 +392,19 @@ void SdlInputHandler::handleMouseMotionEvent(SDL_MouseMotionEvent* event)
|
||||||
short xdelta = (short)event->xrel;
|
short xdelta = (short)event->xrel;
|
||||||
short ydelta = (short)event->yrel;
|
short ydelta = (short)event->yrel;
|
||||||
|
|
||||||
// Delay for 1 ms to allow batching of mouse move
|
// If we're sending more than one motion event per millisecond,
|
||||||
// events from high DPI mice.
|
// delay for 1 ms to allow batching of mouse move events.
|
||||||
SDL_Delay(1);
|
Uint32 currentTime = SDL_GetTicks();
|
||||||
|
if (!SDL_TICKS_PASSED(currentTime, m_LastMouseMotionTime + 1)) {
|
||||||
|
SDL_Delay(1);
|
||||||
|
currentTime = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
m_LastMouseMotionTime = currentTime;
|
||||||
|
|
||||||
|
// Pump even if we didn't delay since we might get some extra events
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
|
|
||||||
|
// Batch all of the pending mouse motion events
|
||||||
SDL_Event nextEvent;
|
SDL_Event nextEvent;
|
||||||
while (SDL_PeepEvents(&nextEvent,
|
while (SDL_PeepEvents(&nextEvent,
|
||||||
1,
|
1,
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ private:
|
||||||
|
|
||||||
void sendGamepadState(GamepadState* state);
|
void sendGamepadState(GamepadState* state);
|
||||||
|
|
||||||
|
Uint32 m_LastMouseMotionTime;
|
||||||
bool m_MultiController;
|
bool m_MultiController;
|
||||||
int m_GamepadMask;
|
int m_GamepadMask;
|
||||||
GamepadState m_GamepadState[MAX_GAMEPADS];
|
GamepadState m_GamepadState[MAX_GAMEPADS];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue