Skip to content

Add screen redraw throttling in SDL2 backend

Jesse Pavel requested to merge jpavel1/grafX2:sdl2-redraw-throttle into master

I promise this will be my last SDL2 input.c merge request...

Background

Get_input() is called repeatedly in a tight loop by Main_handler() so long as events were pending. If events came in faster than the loop could process them, GFX2_UpdateScreen() was never called, and thus the "screen freezing" that I described earlier occurred.

If the mouse wasn't moved in Get_input(), it pushes a surface to a texture anyway on each call, using resources when idle.

Solution

This patch calls GFX2_UpdateScreen() at a reliable rate, whether or not events are in the queue. This takes care of screen freezes when input events arrive too quickly, and reduces CPU usage when idle. This rate is configurable via the Mouse_motion_debounce config setting, with special handling of these cases:

  • When Mouse_motion_debounce is disabled, all mouse motion events are processed, but the screen is only redrawn at 60 FPS, leading to a solid experience.
  • When Mouse_motion_debounce is set to a very high processing rate (> 120 Hz), the screen will be redrawn at a maximum of 120 FPS.
Edited by Jesse Pavel

Merge request reports