Skip to content

Avoid busy-waiting when frame cap is in effect

Hanicef requested to merge Hanicef/SRB2:avoid-frame-cap-busywait into next

Discovered while testing !2047 (merged)

For some reason, the frame cap was busy-waiting while waiting for the next frame, which drained my laptop's battery pretty badly. According to a comment on the function...

This function makes a best effort not to oversleep, and will spinloop if sleeping would take too long.

...the busy-waiting is there to prevent inaccuracies in the framerate, and while it's true that sleep functions like Unix's nanosleep aren't accurate to the nanosecond, these "oversleeps" that the comment is talking about is in microseconds at worst. The advice is primarily towards hard real-time developers that develops for stuff like medical equipment and the like where a missed time-frame could kill a patient or have similar severe consequences. Games, however, don't need this sort of accuracy, not even remotely. Not only that, but busy-waiting defeats the purpose of frame capping, since the reason people normally enable it is to reduce battery usage while in this case, it has no effect (in fact, it's worse than running at refresh rate with V-Sync on, despite the lower framerate!).

Instead, this entire function is removed and replaced with I_Sleep. That's all that's needed. It's accurate and does what you'd expect, nothing more.

Merge request reports