refactor ImGUI code files

This commit is contained in:
2022-02-10 19:58:51 +08:00
parent bb33972616
commit 06cd549eb7
13 changed files with 172 additions and 50 deletions

View File

@@ -1,7 +1,6 @@
package game
import (
"fmt"
"log"
"math"
"os"
@@ -9,6 +8,8 @@ import (
"edgaru089.ml/go/gl01/internal/asset"
"edgaru089.ml/go/gl01/internal/igwrap"
"edgaru089.ml/go/gl01/internal/igwrap/backend"
"edgaru089.ml/go/gl01/internal/io"
"edgaru089.ml/go/gl01/internal/util/itype"
"edgaru089.ml/go/gl01/internal/world"
"github.com/go-gl/glfw/v3.3/glfw"
@@ -19,6 +20,8 @@ type guiState struct {
showLog, showDebugInfo bool
logFollow bool
lastframeCgoCalls int64
loadChunkFile string
loadChunkID [2]int32
@@ -35,7 +38,7 @@ func (g *Game) initImgui(win *glfw.Window) {
cfg.SetOversampleV(1)
cfg.SetPixelSnapH(true)
g.io.Fonts().AddFontFromMemoryTTFV(asset.Unifont, 16, cfg, g.io.Fonts().GlyphRangesChineseFull())
igwrap.Init(win)
backend.Init(win)
g.gui = guiState{
showLog: true,
@@ -49,6 +52,19 @@ func (g *Game) initImgui(win *glfw.Window) {
}
func (g *Game) imgui() {
if io.ShowDebugInfo {
imgui.SetNextWindowPosV(imgui.Vec2{}, imgui.ConditionAlways, imgui.Vec2{})
if igwrap.Begin("F3", nil, imgui.WindowFlagsAlwaysAutoResize|imgui.WindowFlagsNoBackground|imgui.WindowFlagsNoNavFocus|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoInputs|imgui.WindowFlagsNoSavedSettings|imgui.WindowFlagsNoFocusOnAppearing) {
igwrap.Text("Gl01(glfw%s, imgui%s) - compiled by %s[%s/%s]", glfw.GetVersionString(), imgui.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
igwrap.Text("CgoCalls:%d (%d lastframe), Goroutines:%d", runtime.NumCgoCall(), runtime.NumCgoCall()-g.gui.lastframeCgoCalls, runtime.NumGoroutine())
imgui.Text("")
pos := g.player.Position()
igwrap.Text("Player: (%.3f, %.5f, %.3f) - (Y%.2f, Z%.2f)", pos[0], pos[1], pos[2], g.rotY.Degrees(), g.rotZ)
imgui.End()
}
}
g.gui.lastframeCgoCalls = runtime.NumCgoCall()
if imgui.BeginV("Player", nil, imgui.WindowFlagsAlwaysAutoResize) {
pos := g.player.Position()
@@ -58,17 +74,6 @@ func (g *Game) imgui() {
}
imgui.End()
if imgui.BeginV("Go Runtime", nil, imgui.WindowFlagsAlwaysAutoResize) {
imgui.Text(fmt.Sprintf("%s/%s, compiler: %s", runtime.GOOS, runtime.GOARCH, runtime.Compiler))
imgui.Text(fmt.Sprintf("NumCPU=%d, NumGOMAXPROCS=%d", runtime.NumCPU(), runtime.GOMAXPROCS(0)))
imgui.Text(fmt.Sprintf("NumCgoCalls=%d, NumGoroutine=%d", runtime.NumCgoCall(), runtime.NumGoroutine()))
imgui.Spacing()
if imgui.ButtonV("!!! PANIC !!!", imgui.Vec2{X: -2, Y: 0}) {
panic("Manual Panic")
}
}
imgui.End()
if igwrap.Begin("Logs", &g.gui.showLog, imgui.WindowFlagsMenuBar) {
if imgui.BeginMenuBar() {
if imgui.Button("Clear") {