-
-
Notifications
You must be signed in to change notification settings - Fork 61
Investigate smarter approaches to frame limiting #218
Copy link
Copy link
Open
Labels
Area: Game LoopIssues relating to the main game loop.Issues relating to the main game loop.Area: PlatformIssues relating to the platform layerIssues relating to the platform layerType: InvestigationOngoing investigations and unanswered questions.Ongoing investigations and unanswered questions.
Metadata
Metadata
Assignees
Labels
Area: Game LoopIssues relating to the main game loop.Issues relating to the main game loop.Area: PlatformIssues relating to the platform layerIssues relating to the platform layerType: InvestigationOngoing investigations and unanswered questions.Ongoing investigations and unanswered questions.
Summary:
In 0.5.6, we switched from doing
std::thread::yield_nowat the end of the game loop to doing a 1msstd::thread::sleep. This was to avoid issues some people were having with high CPU usage when the game is minimized or when vsync is turned off.This appears to be due to the fact that
std::thread::yield_nowdoesn't guarentee the thread will yield - it'll only yield if there's work to do elsewhere.std::thread::sleep, on the other hand, guarentees that we'll yield for some amount of time, putting an effective cap on the max FPS and preventing the game from maxing the CPU core. This is the approach used by Love2D's default game loop, and I've not noticed any ill effects from it there.That said, I would like to investigate whether there's a smarter approach to this, as sleeping for 1ms in all cases seems like a bit of a clunky solution (e.g. if the game is running slowly, you might want that extra headroom rather than a millisecond being wasted). I'm not entirely sure if it's necessary though.
Why is this needed?
Just for my own peace of mind, and to make sure that we're not leaving any performance on the table.