Files
aego/scene/sceneio/scripts_test.go
sanspie cf68c71f05 Stage 6: coroutines, signals, ScriptRef, workspace CLI, editor tooling
Language: yield/signal/coroutine become keywords, start is contextual.
Coroutine methods (func Name() coroutine) with start and
yield / wait / frames / fixed / await; signals with Emit/Connect and
Connection handles; ScriptRef<T> and node.GetScript<T>() for fields,
plain methods and signals of other scripts. Diagnostics AES2050-AES2059.

Bytecode v3: ScriptRefs, XFields, XMethods and Connects tables resolved by
name in vm.Link, per-script signals, coroutine flag on functions; new
opcodes START/YIELD/EMIT/CONNECT/DISCONNECT/CONNECTED/COSTOP/CORUN/
SELFREF/GETSCRIPT/GETXF/SETXF/CALLR, checked by verify.

Runtime: script/coroutine scheduler (frames/fixed counters, time heap,
await lists; only due coroutines are visited) and script/signal registry
(snapshot per Emit, deferred removal, no allocations in steady state).
Hot reload cancels coroutines of changed scripts, rebinds connections by
name and signature, then runs Reloaded.

Tooling: script/build removed, aego check/test/dump run on the workspace
(test builds include _test.aes); langsvc completion, hover, signatures and
semantic tokens for the new syntax; editor highlighting, snippets with
placeholders, coroutine/signal profiler graphs and stats.

Docs (script.md sections 16-19, editor.md, ARCHITECTURE), test fixtures and
golden files, platformer enemies wired to the player, scriptreload demo,
and run.Config.FrameTime for deterministic headless fixed steps.

Modules (6.5): engine/module registry and ComponentBuilder are the one
registration path for engine subsystems and native code; render2d,
render3d and script/engine are modules over scene/frame, the script
component moved to scene/scriptcomp, and scene/components and
scene/systems are gone. Editor inspector, templates, picking shapes and
extension hooks are driven by descriptors and editor/builtins; sdk gains
Component/EditorHook; depcheck checks the module graph and the
aego_runtime graph.

Also: stop tracking built tool binaries; gl33 activates the scratch unit
before binding for texture updates.

Verification: typed component method adapters (Method0..2, Proc0..2)
with direct field access and no allocations; app.Build as the single
construction path for run and the editor; modules attach per scene
document; depcheck aego_editor pass; diagnostic codes in one place and
every code covered by a test; indexed coroutine heaps with eager
cancel; dead component references and nil intrinsics fault with
AES6004, host faults keep their code; GC roots of struct fields checked
in verify and vm.Link; 255-field limit; AES4010 for script packages
shadowing host modules; architecture registry D111-D147.

Golden: the harness renders on the thread that owns the GL context,
ReadPixels returns rows in memory order (render targets are top-down per
D17), and the first rendering references are committed.
2026-10-12 14:22:08 +03:00

78 lines
2.2 KiB
Go

package sceneio_test
import (
"strings"
"testing"
"aego/scene"
"aego/scene/sceneio"
"aego/scene/scriptcomp"
"aego/schema"
)
const scriptScene = `scene version=1 {
node "0123456789abcdef0123456789abcdef" name="A" enabled=true layers=1 {
component "engine.Script" version=1 {
script "game.OldMover" enabled=false {
Velocity=321
Extra=5
}
script "other.Missing" enabled=true {
Kept=true
}
}
}
}
`
func TestScriptAttachmentRoundTrip(t *testing.T) {
types := scene.NewTypes(schema.NewRegistry())
if err := scriptcomp.Register(types); err != nil {
t.Fatal(err)
}
if err := sceneio.RegisterUnknown(types); err != nil {
t.Fatal(err)
}
if err := types.Schema().Freeze(); err != nil {
t.Fatal(err)
}
td, err := schema.NewScriptType("game.Mover", []string{"game.OldMover"}, []schema.FieldDescriptor{
{Name: "Speed", Kind: schema.KindFloat32, Former: []string{"Velocity"}, Flags: schema.FlagSerialize | schema.FlagEditor},
{Name: "Label", Kind: schema.KindString, Default: schema.String("hi"), HasDefault: true, Flags: schema.FlagSerialize | schema.FlagEditor},
})
if err != nil {
t.Fatal(err)
}
if err := types.Schema().SetDynamic([]*schema.TypeDescriptor{td}); err != nil {
t.Fatal(err)
}
s, rep, err := sceneio.Load([]byte(scriptScene), "t.aescene", types, nil, sceneio.LoadOptions{KeepIDs: true})
if err != nil {
t.Fatal(err)
}
if len(rep.Warnings) == 0 || len(rep.Unknown) == 0 {
t.Fatal("unknown property and unknown script type were not reported")
}
h := s.PreOrder()[1]
v, err := s.GetProperty(h, td.ID, td.Fields[0].ID)
if err != nil || v.F != 321 {
t.Fatalf("Speed through the overlay = %v, %v", v.F, err)
}
out := string(sceneio.Save(s))
for _, want := range []string{
`script "game.Mover" enabled=false`, `Speed=321`, `Label="hi"`, `Extra=5`,
`script "other.Missing" enabled=true`, `Kept=true`,
} {
if !strings.Contains(out, want) {
t.Fatalf("saved scene misses %q:\n%s", want, out)
}
}
again, _, err := sceneio.Load([]byte(out), "t2.aescene", types, nil, sceneio.LoadOptions{KeepIDs: true})
if err != nil {
t.Fatal(err)
}
if string(sceneio.Save(again)) != out {
t.Fatal("second save is not canonical")
}
}