Description
Problem
@aevyrie has observed noticeable input lag in Bevy applications when vsync is enabled.
The most immediate source of this is quite obvious: we're only fetching the input state at the start of each frame, but are rendering is done at the end of the frame.
Input events appear to be moved into the Bevy app by the winit
runner:
bevy/crates/bevy_winit/src/lib.rs
Line 221 in de8edd3
At 60 fps, this means 16 ms of lag, which is noticeable for some applications: namely for precise cursor movement (FPS, GUI applications) and rhythm games.
Possible solutions
- Poll more regularly (somewhat limited by the OS I believe)
- I suspect this could be done at the end of each stage
- Perhaps a dedicated input-polling thread architecture would help?
- Poll closer to rendering time
Either solution will involve some trickiness, as we must pierce the Bevy schedule in some fashion in order to insert fresh input events into the World at the right time, rather than merely at the beginning of each pass over the schedule.