gabstv / ebiten-imgui

Dear ImGui renderer for Ebitengine
MIT License
122 stars 18 forks source link

Drawing when TPS and FPS are not in sync / have different rates #10

Closed eliasdaler closed 2 years ago

eliasdaler commented 2 years ago

Hello I think that some restructuring of the code/API is needed to make ebiten-imgui support different TPS/FPS rates.

In usual Dear ImGui setup, you call Begin/EndFrame and widget creation functions in "Update", not "Draw". Actual drawing should be just just done in "Draw" function.

So, I think it's the usage should be like this:

func (g *Game) Update() {
    g.mgr.BeginFrame()
    // put stuff like imgui.Button etc. here
    g.mgr.EndFrame() 
}

func (g *Game) Draw(screen *ebiten.Image) {
    g.mgr.Draw(screen) // new function - doesn't call "EndFrame" for us
}

This is much better and allows to have 60 TPS (update calls per second) and 60+ FPS (Draw calls per second) - we just need to render the old frame if Draw has been called more than once for 1 update call. Note that we can call imgui.Render once - it doesn't break anything.

Thoughts? If you agree with this, I can make a PR which implements the changes, though it'll break the API.

gabstv commented 2 years ago

Hello. I guess that this is indeed the correct approach. Feel free to submit a PR if you want to. Thanks!

gabstv commented 2 years ago

I fixed the implementation in #12

eliasdaler commented 2 years ago

Works wonderfully, thanks a lot!