From 98c15d6b5f3f222bef6dc47c0a537c899d3630bb Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Tue, 20 Jan 2026 18:07:41 -0500 Subject: [PATCH] debug logging and stuff --- cmd/cli/guest/main.go | 42 ++++++++++++++++++++++++++++++++++++-- components/components.go | 10 ++++----- go.mod | 5 +---- go.sum | 2 -- systems.go | 29 -------------------------- systems/room.go | 44 ++++++++++++++++++++++++++++++---------- 6 files changed, 79 insertions(+), 53 deletions(-) delete mode 100644 systems.go diff --git a/cmd/cli/guest/main.go b/cmd/cli/guest/main.go index 0b925ec..36986d4 100644 --- a/cmd/cli/guest/main.go +++ b/cmd/cli/guest/main.go @@ -1,14 +1,52 @@ package main import ( - // "fmt" + "flag" + "log/slog" + "os" "github.com/EngoEngine/ecs" - // "code.ndumas.com/ndumas/muddy" + + "code.ndumas.com/ndumas/muddy/systems" ) func main() { + var ( + level string + ) + + flag.StringVar(&level, "level", "INFO", "Log level: INFO/info, DEBUG/debug, or ERROR/error") + + flag.Parse() + + var logLevel slog.Level + switch level { + case "INFO", "info": + logLevel = slog.LevelInfo + case "DEBUG", "debug": + logLevel = slog.LevelDebug + case "ERROR", "error": + logLevel = slog.LevelError + } + + l := slog.New(slog.NewJSONHandler( + os.Stderr, &slog.HandlerOptions{ + Level: logLevel, + }, + ), + ) + world := ecs.World{} + rs := &systems.RoomSystem{ + Rooms: make(map[uint64]*systems.Room, 0), + L: l.WithGroup("rooms"), + } + + world.AddSystem(rs) world.Update(1) + + l.With( + slog.Int("room count", len(rs.Rooms)), + ).Info("setup complete") } diff --git a/components/components.go b/components/components.go index 9c77b83..bd6838b 100644 --- a/components/components.go +++ b/components/components.go @@ -1,13 +1,13 @@ -package muddy +package components type ID struct { - ID int64 + ID uint64 } type Location struct { X, Y, Z int64 - World int64 - Exits []int64 + World uint64 + Exits []uint64 } type Observable struct { @@ -16,7 +16,7 @@ type Observable struct { } type Inventory struct { - Items []int64 + Items []uint64 } type HP struct { diff --git a/go.mod b/go.mod index 5cb0391..18e7715 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,6 @@ module code.ndumas.com/ndumas/muddy go 1.24.5 -require ( - github.com/EngoEngine/ecs v1.0.5 - github.com/mlange-42/ark v0.7.0 -) +require github.com/EngoEngine/ecs v1.0.5 require github.com/stretchr/testify v1.10.0 // indirect diff --git a/go.sum b/go.sum index 9608f85..c66d350 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/EngoEngine/ecs v1.0.5/go.mod h1:A8AYbzKIsl+t4qafmLL3t4H6cXdfGo4CIHl7E github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/mlange-42/ark v0.7.0 h1:cLEqhJhZaZayi35eY/cE7VQg7GonK+s1qbsSKdtcjrs= -github.com/mlange-42/ark v0.7.0/go.mod h1:gkS9cuklENPTmSjL2z4DcJgJsIVqF1yNwFlx48Hz/Sw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/systems.go b/systems.go deleted file mode 100644 index 383e975..0000000 --- a/systems.go +++ /dev/null @@ -1,29 +0,0 @@ -package systems - -import ( - // "fmt" - - "github.com/EngoEngine/ecs" - - "code.ndumas.com/ndumas/muddy/components" -) - -type Room struct { - components.ID - components.Location - components.Observable - components.Inventory -} - -type RoomRepository interface { - Get(int64) (Room, error) - GetAll() ([]Room, error) - Delete(int64) error -} - -type RoomSystem struct { - repository RoomRepository -} - -func (rs *RoomSystem) Update(dt float32) {} -func (rs *RoomSystem) Remove(e ecs.BasicEntity) {} diff --git a/systems/room.go b/systems/room.go index db6a60f..00dabe0 100644 --- a/systems/room.go +++ b/systems/room.go @@ -1,7 +1,7 @@ -package muddy +package systems import ( - "fmt" + "log/slog" "github.com/EngoEngine/ecs" @@ -9,22 +9,44 @@ import ( ) type Room struct { - components.ID - components.Location - components.Observable - components.Inventory + *components.ID + *components.Location + *components.Observable + *components.Inventory } type RoomSystem struct { - repository RoomRepository + L *slog.Logger + Rooms map[uint64]*Room } -func (s *RoomSystem) Initialize(w *ecs.World) { - fmt.Println("initializing room system") +func (rs *RoomSystem) New(w *ecs.World) { + rs.L.Debug("initializing room system") + z := 0 + for i := range 10 { + for j := range 10 { + rs.Rooms[uint64(z)] = &Room{ + ID: &components.ID{ + ID: uint64(z), + }, + Location: &components.Location{ + X: int64(i), + Y: int64(j), + }, + Observable: &components.Observable{}, + Inventory: &components.Inventory{}, + } + z++ + } + } // locationMapper := ecs.NewMap4[ID, Location, Observable, Inventory](w) } -func (s *RoomSystem) Update(w *ecs.World) {} +func (rs *RoomSystem) Update(dt float32) { + rs.L.Debug("room system tick") +} + +func (rs *RoomSystem) Remove(e ecs.BasicEntity) {} // Finalize the system. -func (s *RoomSystem) Finalize(w *ecs.World) {} +func (rs *RoomSystem) Finalize(w *ecs.World) {}