Skip to content

Commit

Permalink
SDL: Fix a bunch of input timeout edge-cases (#1541)
Browse files Browse the repository at this point in the history
* SDL input: Properly round the timeout value.

We may have been passing a float to SDL, which would have had... unexpected results.

* SDL Input: round the timeout *up*, to avoid issues if the requested timeout is below our precision.

This prevents a bunch of useless roundtrips in some cases (e.g., autosuspend), because front has higher precision ;).
  • Loading branch information
NiLuJe committed Oct 24, 2022
1 parent 37f5b16 commit 8b1b0db
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ local is_in_touch = false

function S.waitForEvent(sec, usec)
local event = ffi.new("union SDL_Event")
-- TimeVal's :tomsecs if we were passed one to begin with, otherwise, -1 => block
local timeout = sec and math.floor(sec * 1000000 + usec + 0.5) / 1000 or -1
-- TimeVal to ms if we were passed one to begin with, otherwise, -1 => block.
-- NOTE: Since we have *less* precision than a timeval, we round *up*, to avoid passing zero for < 1ms timevals.
local timeout = sec and math.ceil((sec * 1000000 + usec) * (1/1000)) or -1

-- Reset the queue
inputQueue = {}
Expand Down

0 comments on commit 8b1b0db

Please sign in to comment.