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

FPS Limit #9

Closed
EtienneBruines opened this issue Aug 13, 2015 · 3 comments
Closed

FPS Limit #9

EtienneBruines opened this issue Aug 13, 2015 · 3 comments

Comments

@EtienneBruines
Copy link
Member

When using the example given at the README, I'm getting a FPS of about 30-40k.

It would be nice if we could limit this, since this wastes quite some CPU resources. The programmer could pass/set options somewhere, to set the limit to 30/60/90/120/unlimited whenever he wants. Preferably at runtime (because it'll reside in the game Settings).

Looking at the code here, it's obvious why the FPS is getting this high.

What about something like this?

    Wo.New()
    ticker := time.NewTicker(time.Duration(int(time.Second) / fpsLimit))

Outer:
    for {
        select {
        case <-ticker.C:
            responder.Update(Time.Delta())
            window.SwapBuffers()
            glfw.PollEvents()
            keysUpdate()
            Time.Tick()
            if window.ShouldClose() {
                break Outer
            }
        }
    }
    ticker.Stop()

Not sure what the best practice would be if someone were to change the fpsLimit - we'd have to re-create the ticker.

@paked
Copy link
Member

paked commented Aug 13, 2015

Well looking at the exposed functions, we would have to recreate it. I personally am happy with this solution, it's not like people would recreate the ticker every frame.

@EtienneBruines
Copy link
Member Author

Would you prefer this to be handled as a static function, such as the SetBackground function? i.e.

func SetFPSLimit (fps int) {
    ....
}

Or tied to any running instance of some sort?

Then I could make a PR for that if you'd like.

@paked
Copy link
Member

paked commented Aug 14, 2015

Static seems to be the only possible way to do it right now, without a massive restructure. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants