Skip to content

Investigate smarter approaches to frame limiting #218

@17cupsofcoffee

Description

@17cupsofcoffee

Summary:
In 0.5.6, we switched from doing std::thread::yield_now at the end of the game loop to doing a 1ms std::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_now doesn'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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Game LoopIssues relating to the main game loop.Area: PlatformIssues relating to the platform layerType: InvestigationOngoing investigations and unanswered questions.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions