Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce a global 'Maximimum Frame Rate' in the MainLoop #3815

Open
tig opened this issue Nov 12, 2024 · 0 comments
Open

Enforce a global 'Maximimum Frame Rate' in the MainLoop #3815

tig opened this issue Nov 12, 2024 · 0 comments
Milestone

Comments

@tig
Copy link
Collaborator

tig commented Nov 12, 2024

Via @tznind:

I think we should have a global 'frame rate' enforced for iteration. At the moment a lot of issues stem from iteration running too fast e.g. see #3812

To me a MainLoop should look something like (pseudocode)

do
{
     var dt = DateTime.Now();
    
    RunIteration();
    
    var took = DateTime.Now() - dt
    var sleepFor = TimeSpan.FromMilliseconds(200) - took;
    
    if(sleepFor > 0)
        Task.Delay(sleepFor).Wait();

}
while(true)

This solves several problems including the kinda sketchy way that 'has events' somehow has to take responsibility for blocking until there are events - except when there are timers (that being a problem in itself) etc.

The iteration, drawing, event queue inspection etc should all happen as fast as possible. Then we just sleep for however long we want to enforce our frame/loop rate.

Thoughts?

See for example this thread:

Did you realized that the EventsPending method is always running overkilling the CPU usage with 13%, approximately? That why the Threading scenario it's working on Linux and Windows. It's needed to wait until it's necessary.

#3791 (comment)

Originally posted by @tznind in #3813 (comment)

@tig tig added this to the V2 Beta milestone Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant