88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
package game
|
|
|
|
import (
|
|
"image/color"
|
|
"runtime"
|
|
|
|
"edgaru089.ink/go/gl01/internal/asset"
|
|
"edgaru089.ink/go/gl01/internal/igwrap"
|
|
"edgaru089.ink/go/gl01/internal/igwrap/backend"
|
|
"edgaru089.ink/go/gl01/internal/io"
|
|
"edgaru089.ink/go/gl01/internal/util"
|
|
"github.com/go-gl/glfw/v3.3/glfw"
|
|
"github.com/inkyblackness/imgui-go/v4"
|
|
)
|
|
|
|
type guiState struct {
|
|
showDemo bool
|
|
logFollow bool
|
|
|
|
lastframeCgoCalls int64
|
|
|
|
lastCountSec *util.Clock
|
|
|
|
loadChunkFile string
|
|
loadChunkID [2]int32
|
|
|
|
saveChunkFile string
|
|
saveChunkID [2]int32
|
|
}
|
|
|
|
func (g *Game) initImgui(win *glfw.Window) {
|
|
imgui.CreateContext(nil)
|
|
g.io = imgui.CurrentIO()
|
|
|
|
cfg := imgui.NewFontConfig()
|
|
cfg.SetOversampleH(1)
|
|
cfg.SetOversampleV(1)
|
|
cfg.SetPixelSnapH(true)
|
|
g.io.Fonts().AddFontFromMemoryTTFV(asset.Unifont, 16, cfg, g.io.Fonts().GlyphRangesChineseFull())
|
|
backend.Init(win)
|
|
|
|
g.gui = guiState{
|
|
showDemo: false,
|
|
logFollow: true,
|
|
loadChunkFile: "chunk.gob",
|
|
loadChunkID: [2]int32{0, 0},
|
|
saveChunkFile: "chunk.gob",
|
|
saveChunkID: [2]int32{0, 0},
|
|
}
|
|
}
|
|
|
|
func (g *Game) imgui() {
|
|
|
|
io.Diagnostics.CgoCalls = runtime.NumCgoCall() - g.gui.lastframeCgoCalls
|
|
g.gui.lastframeCgoCalls = runtime.NumCgoCall()
|
|
|
|
/*if g.gui.lastCountSec.Elapsed() >= time.Second {
|
|
g.gui.lastCountSec.Restart()
|
|
}*/
|
|
|
|
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", g.gui.lastframeCgoCalls, io.Diagnostics.CgoCalls, runtime.NumGoroutine())
|
|
igwrap.TextBlank()
|
|
|
|
if imgui.SelectableV("Show Demo", g.gui.showDemo, 0, imgui.Vec2{imgui.CalcTextSize("Show Demo", false, 0).X, 0}) {
|
|
g.gui.showDemo = !g.gui.showDemo
|
|
}
|
|
|
|
imgui.End()
|
|
}
|
|
}
|
|
|
|
if g.paused {
|
|
if g.gui.showDemo {
|
|
imgui.ShowDemoWindow(&g.gui.showDemo)
|
|
}
|
|
}
|
|
|
|
imgui.BackgroundDrawList().AddRectFilledV(imgui.Vec2{X: float32(io.DisplaySize[0]/2 - 12), Y: float32(io.DisplaySize[1]/2 - 1)}, imgui.Vec2{X: float32(io.DisplaySize[0]/2 + 12), Y: float32(io.DisplaySize[1]/2 + 1)}, imgui.Packed(color.White), 0, 0)
|
|
imgui.BackgroundDrawList().AddRectFilledV(imgui.Vec2{X: float32(io.DisplaySize[0]/2 - 1), Y: float32(io.DisplaySize[1]/2 - 12)}, imgui.Vec2{X: float32(io.DisplaySize[0]/2 + 1), Y: float32(io.DisplaySize[1]/2 + 12)}, imgui.Packed(color.White), 0, 0)
|
|
|
|
}
|