refactor debug info, measure render times

This commit is contained in:
2022-02-21 12:24:05 +08:00
parent 057e8907a9
commit 4a9afb4246
6 changed files with 135 additions and 46 deletions

View File

@ -52,13 +52,17 @@ func (g *Game) initImgui(win *glfw.Window) {
}
func (g *Game) imgui() {
io.Diagnostics.CgoCalls = runtime.NumCgoCall() - g.gui.lastframeCgoCalls
g.gui.lastframeCgoCalls = runtime.NumCgoCall()
if io.ShowDebugInfo {
imgui.SetNextWindowPosV(imgui.Vec2{}, imgui.ConditionAlways, imgui.Vec2{})
imgui.SetNextWindowSize(imgui.Vec2{X: float32(io.DisplaySize[0]), Y: float32(io.DisplaySize[1])})
if igwrap.Begin("F3", nil, igwrap.WindowFlagsOverlay) {
igwrap.TextBackground("Gl01 compiled by %s/%s [%s/%s] (120AVG) %.1f FPS (%.3f frame)", runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH, imgui.CurrentIO().Framerate(), 1000/imgui.CurrentIO().Framerate())
igwrap.TextBackground("GLFW %s, Dear ImGUI %s", glfw.GetVersionString(), imgui.Version())
igwrap.TextBackground("CgoCalls:%d (%d lastframe), Goroutines:%d", runtime.NumCgoCall(), runtime.NumCgoCall()-g.gui.lastframeCgoCalls, runtime.NumGoroutine())
igwrap.TextBackground("CgoCalls:%d (%d lastframe), Goroutines:%d", g.gui.lastframeCgoCalls, io.Diagnostics.CgoCalls, runtime.NumGoroutine())
igwrap.TextBlank()
pos := g.player.Position()
@ -66,7 +70,6 @@ func (g *Game) imgui() {
imgui.End()
}
}
g.gui.lastframeCgoCalls = runtime.NumCgoCall()
if imgui.BeginV("Player", nil, imgui.WindowFlagsAlwaysAutoResize) {
pos := g.player.Position()

View File

@ -9,6 +9,7 @@ import (
"edgaru089.ml/go/gl01/internal/igwrap/backend"
"edgaru089.ml/go/gl01/internal/io"
"edgaru089.ml/go/gl01/internal/render"
"edgaru089.ml/go/gl01/internal/util"
"edgaru089.ml/go/gl01/internal/util/itype"
"edgaru089.ml/go/gl01/internal/world"
"edgaru089.ml/go/gl01/internal/world/worldgen"
@ -174,7 +175,8 @@ const airAccel = 0.1
// Update updates the game state, not necessarily in the main thread.
func (g *Game) Update(win *glfw.Window, delta time.Duration) {
backend.NewFrame()
imgui.ShowDemoWindow(nil)
clock := util.NewClock()
if !g.paused {
@ -242,7 +244,12 @@ func (g *Game) Update(win *glfw.Window, delta time.Duration) {
g.player.SetSpeed(itype.Vec3d{})
}
io.Diagnostics.Times.Logic = clock.Restart()
imgui.ShowDemoWindow(nil)
g.imgui()
io.Diagnostics.Times.GUI = clock.Restart()
}
// Render, called with a OpenGL context, renders the game.