This commit is contained in:
2025-12-19 13:08:51 +08:00
parent fb0276bc4e
commit 56f2f02afe
24 changed files with 6 additions and 3179 deletions

View File

@@ -3,8 +3,6 @@ package game
import (
"image/color"
"log"
"math"
"os"
"runtime"
"edgaru089.ink/go/gl01/internal/asset"
@@ -12,8 +10,6 @@ import (
"edgaru089.ink/go/gl01/internal/igwrap/backend"
"edgaru089.ink/go/gl01/internal/io"
"edgaru089.ink/go/gl01/internal/util"
"edgaru089.ink/go/gl01/internal/util/itype"
"edgaru089.ink/go/gl01/internal/world"
"github.com/go-gl/glfw/v3.3/glfw"
"github.com/inkyblackness/imgui-go/v4"
)
@@ -73,13 +69,6 @@ func (g *Game) imgui() {
igwrap.TextBackground("CgoCalls:%d (%d lastframe), Goroutines:%d", g.gui.lastframeCgoCalls, io.Diagnostics.CgoCalls, runtime.NumGoroutine())
igwrap.TextBlank()
pos := g.player.Position()
igwrap.TextBackground("Player: (%.3f, %.5f, %.3f) (Y%.2f, Z%.2f)", pos[0], pos[1], pos[2], g.rotY.Degrees(), g.rotZ)
if ok, bc, face, _, _ := g.world.CastViewRay(io.ViewPos, io.ViewDir.Normalize(), 10); ok {
igwrap.TextBackground("Looking At: (%d %d %d) facing %s", bc[0], bc[1], bc[2], itype.DirectionName[face])
}
imgui.End()
}
}
@@ -87,14 +76,6 @@ func (g *Game) imgui() {
if g.paused {
imgui.ShowDemoWindow(nil)
if imgui.BeginV("Player", nil, imgui.WindowFlagsAlwaysAutoResize) {
pos := g.player.Position()
vel := g.player.Speed()
igwrap.Text("Pos: (%.5f, %.5f, %.5f), Vel: (%.5f, %.5f, %.5f)", pos[0], pos[1], pos[2], vel[0], vel[1], vel[2])
igwrap.Text("VelXZ=%.5f, VelXYZ=%.5f", math.Sqrt(vel[0]*vel[0]+vel[2]*vel[2]), vel.Length())
}
imgui.End()
if igwrap.Begin("Logs", &g.gui.showLog, imgui.WindowFlagsMenuBar) {
if imgui.BeginMenuBar() {
if imgui.Button("Clear") {
@@ -118,76 +99,9 @@ func (g *Game) imgui() {
imgui.End()
}
if imgui.Begin("Actions") {
imgui.Text("Chunks")
imgui.Separator()
imgui.InputText("Load Filename", &g.gui.loadChunkFile)
imgui.SliderInt2("Load ID", &g.gui.loadChunkID, -10, 10)
if imgui.ButtonV("Load", imgui.Vec2{X: -2, Y: 0}) {
c := &world.Chunk{}
f, err := os.Open(g.gui.loadChunkFile)
if err != nil {
log.Print("LoadChunk: ", err)
} else {
c.LoadFromGobIndexed(f, int(g.gui.loadChunkID[0]), int(g.gui.loadChunkID[1]))
g.world.SetChunk(int(g.gui.loadChunkID[0]), int(g.gui.loadChunkID[1]), c)
}
}
imgui.Separator()
imgui.InputText("Save Filename", &g.gui.saveChunkFile)
imgui.SliderInt2("Save ID", &g.gui.saveChunkID, -10, 10)
if imgui.ButtonV("Save", imgui.Vec2{X: -2, Y: 0}) {
c := g.world.Chunks[itype.Vec2i{int(g.gui.saveChunkID[0]), int(g.gui.saveChunkID[1])}]
f, _ := os.Create(g.gui.saveChunkFile)
c.WriteToGob(f)
f.Close()
}
imgui.Separator()
}
imgui.End()
}
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)
imgui.SetNextWindowPosV(imgui.Vec2{float32(io.DisplaySize[0] / 2), float32(io.DisplaySize[1]) + 1}, imgui.ConditionAlways, imgui.Vec2{0.5, 1})
if igwrap.Begin("InventoryBar", nil, imgui.WindowFlagsAlwaysAutoResize|imgui.WindowFlagsNoNavFocus|imgui.WindowFlagsNoNavInputs|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoBringToFrontOnFocus|imgui.WindowFlagsNoSavedSettings|imgui.WindowFlagsNoFocusOnAppearing) {
imgui.PushStyleColor(imgui.StyleColorBorder, imgui.Vec4{0.8, 0.8, 0.8, 1})
for i, id := range placeId {
if i != 0 {
imgui.SameLineV(0, 1)
}
if i == placei {
imgui.PushStyleVarFloat(imgui.StyleVarFrameBorderSize, 2)
}
app := world.GetBlockBehaviour(id).Appearance(itype.Vec3i{}, 0, nil, g.world)
var name string
switch app.RenderType {
case world.OneTexture:
name = app.Name + ".png"
case world.ThreeTexture:
name = app.Name + "_top.png"
case world.SixTexture:
name = app.Name + "_y+.png"
}
igwrap.ImageButtonV(
g.render.texture.Handle(),
itype.Vec2f{32, 32},
asset.WorldTextureAtlas.RectNormalized(name),
0, itype.Vec4f{}, itype.Vec4f{1, 1, 1, 1},
)
if i == placei {
imgui.PopStyleVar()
}
}
imgui.PopStyleColor()
imgui.End()
}
}