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).
82 lines
1.3 KiB
Go
82 lines
1.3 KiB
Go
package scene
|
|
|
|
import (
|
|
"aego/core/ids"
|
|
"aego/schema"
|
|
)
|
|
|
|
type EventKind uint8
|
|
|
|
const (
|
|
EvNodeCreated EventKind = iota
|
|
EvNodeDestroyed
|
|
EvNodeReparented
|
|
EvNodeRenamed
|
|
EvComponentAdded
|
|
EvComponentRemoved
|
|
EvPropertyChanged
|
|
EvHierarchyChanged
|
|
EvSpaceChanged
|
|
)
|
|
|
|
var eventNames = [...]string{
|
|
"NodeCreated", "NodeDestroyed", "NodeReparented", "NodeRenamed",
|
|
"ComponentAdded", "ComponentRemoved", "PropertyChanged", "HierarchyChanged",
|
|
"SpaceChanged",
|
|
}
|
|
|
|
func (k EventKind) String() string {
|
|
if int(k) < len(eventNames) {
|
|
return eventNames[k]
|
|
}
|
|
return "Unknown"
|
|
}
|
|
|
|
type Event struct {
|
|
Kind EventKind
|
|
Node NodeHandle
|
|
ID ids.NodeID
|
|
Type schema.TypeID
|
|
Field schema.FieldID
|
|
}
|
|
|
|
type subscriber struct {
|
|
id uint64
|
|
fn func(Event)
|
|
}
|
|
|
|
type Events struct {
|
|
subs []subscriber
|
|
nextID uint64
|
|
depth int
|
|
}
|
|
|
|
func (e *Events) Subscribe(fn func(Event)) func() {
|
|
e.nextID++
|
|
id := e.nextID
|
|
e.subs = append(e.subs, subscriber{id: id, fn: fn})
|
|
return func() {
|
|
for i := range e.subs {
|
|
if e.subs[i].id == id {
|
|
e.subs = append(e.subs[:i], e.subs[i+1:]...)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (e *Events) dispatch(ev Event) {
|
|
if len(e.subs) == 0 || e.depth > 4 {
|
|
return
|
|
}
|
|
e.depth++
|
|
for i := range e.subs {
|
|
e.subs[i].fn(ev)
|
|
}
|
|
e.depth--
|
|
}
|
|
|
|
func (e *Events) Len() int {
|
|
return len(e.subs)
|
|
}
|