Files
aego/engine/world.go
T
sanspie 17cb5e4291 Stage 2-5: assets, scene/ECS, editor, 3D, and Aego Script
Stage 2: render pipeline and UI toolkit over gpu/platform.
Stage 3: schema registry, asset pipeline + runtime loader, scene graph and ECS.
Stage 4: editor — docking, inspector, scene/game views, play mode, asset browser, console, profiler; 4.5 adds the 3D foundation (mixed 2D/3D spaces, meshes, depth).
Stage 5: Aego Script — compiler (lexer/parser/types/resolver/checker/asm/compiler), bytecode with verifier and register VM, instance runtime, stdlib, native bindings, and editor/CLI integration (aego run/edit/check/test/dump).
2026-10-08 13:17:28 +03:00

69 lines
1.2 KiB
Go

package engine
import "aego/platform/input"
type World struct {
name string
services []serviceEntry
Input *input.State
}
func (c *Context) Input() *input.State {
if c.World != nil && c.World.Input != nil {
return c.World.Input
}
return c.Engine.Input()
}
func NewWorld(name string) *World {
return &World{name: name}
}
func (w *World) Name() string {
return w.name
}
func (w *World) SetService(id string, v any) {
for i := range w.services {
if w.services[i].id == id {
w.services[i].value = v
return
}
}
w.services = append(w.services, serviceEntry{id: id, value: v})
}
func (w *World) RemoveService(id string) {
for i := range w.services {
if w.services[i].id == id {
w.services = append(w.services[:i], w.services[i+1:]...)
return
}
}
}
func (w *World) ServiceAny(id string) (any, bool) {
for i := range w.services {
if w.services[i].id == id {
return w.services[i].value, true
}
}
return nil, false
}
func ServiceOf[T any](w *World, id string) (T, bool) {
var zero T
if w == nil {
return zero, false
}
v, ok := w.ServiceAny(id)
if !ok {
return zero, false
}
typed, ok := v.(T)
if !ok {
return zero, false
}
return typed, true
}