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.
156 lines
4.1 KiB
Go
156 lines
4.1 KiB
Go
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"aego/app/run"
|
|
"aego/core/log"
|
|
"aego/core/mathx"
|
|
"aego/project"
|
|
"aego/scene/sceneio"
|
|
"aego/sdk"
|
|
)
|
|
|
|
const roomScene = `scene version=1 space="3d" {
|
|
node "4a5b6c7d8e9f00112233445566778899" name="Camera" enabled=true layers=1 space="3d" {
|
|
transform3d { position=[0, 2, 6] rotation=[-0.1602, 0, 0, 0.9871] scale=[1, 1, 1] }
|
|
component "engine.Camera3D" version=1 {
|
|
fov=60
|
|
near=0.1
|
|
far=1000
|
|
viewport=[0, 0, 1, 1]
|
|
mask=-1
|
|
order=0
|
|
clear=true
|
|
clearColor=#0a0d12ff
|
|
active=true
|
|
}
|
|
}
|
|
node "5b6c7d8e9f0011223344556677889900" name="Floor" enabled=true layers=1 space="3d" {
|
|
transform3d { position=[0, 0, 0] rotation=[0, 0, 0, 1] scale=[1, 1, 1] }
|
|
component "engine.MeshRenderer" version=1 {
|
|
mesh=asset("ae900000000000000000000000000002")
|
|
color=#2e333dff
|
|
}
|
|
}
|
|
node "6c7d8e9f001122334455667788990011" name="Cube" enabled=true layers=1 space="3d" {
|
|
transform3d { position=[0, 0.5, 0] rotation=[0, 0, 0, 1] scale=[1, 1, 1] }
|
|
component "engine.MeshRenderer" version=1 {
|
|
mesh=asset("ae900000000000000000000000000001")
|
|
color=#e07b39ff
|
|
}
|
|
component "game.Rotator3D" version=1 {
|
|
axis=[0, 1, 0]
|
|
speed=1.2
|
|
}
|
|
}
|
|
node "7d8e9f00112233445566778899001122" name="Ball" enabled=true layers=1 space="3d" {
|
|
transform3d { position=[2, 0.5, 0] rotation=[0, 0, 0, 1] scale=[1, 1, 1] }
|
|
component "engine.MeshRenderer" version=1 {
|
|
mesh=asset("ae900000000000000000000000000003")
|
|
color=#52a7c9ff
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
type Rotator3D struct {
|
|
Axis mathx.Vec3 `aego:"axis"`
|
|
Speed float32 `aego:"speed"`
|
|
}
|
|
|
|
type rotator3DSystem struct{}
|
|
|
|
func (rotator3DSystem) Run(ctx *sdk.Context) {
|
|
s := sdk.SceneOf(ctx)
|
|
if s == nil {
|
|
return
|
|
}
|
|
dt := float32(ctx.Dt)
|
|
sdk.Query1[Rotator3D](s).Each(func(n sdk.NodeHandle, r *Rotator3D) {
|
|
q := mathx.QuatAxisAngle(r.Axis, r.Speed*dt).Mul(s.Local3D(n).Rotation)
|
|
s.SetRotation3D(n, q.Normalized())
|
|
})
|
|
}
|
|
|
|
type rotator3DModule struct{}
|
|
|
|
func (rotator3DModule) Info() sdk.ModuleInfo {
|
|
return sdk.ModuleInfo{ID: "game.rotator3d", Version: "0.1.0"}
|
|
}
|
|
|
|
func (rotator3DModule) Register(r *sdk.Registry) error {
|
|
if err := sdk.RegisterComponent[Rotator3D](r, sdk.Name("game.Rotator3D")); err != nil {
|
|
return err
|
|
}
|
|
return sdk.RegisterSystem(r, sdk.SystemDesc{
|
|
ID: "game.rotator3d.spin",
|
|
Phase: sdk.PhaseUpdate,
|
|
System: rotator3DSystem{},
|
|
})
|
|
}
|
|
|
|
func openRoom(t *testing.T) *run.App {
|
|
t.Helper()
|
|
p, err := project.Create(t.TempDir(), "Room", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(p.ScenesDir(), "room.aescene")
|
|
if err := os.WriteFile(path, []byte(roomScene), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
app, err := run.Open(p, run.Config{Headless: true, Logger: log.Nop(), ScenePath: path}, rotator3DModule{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(app.Close)
|
|
return app
|
|
}
|
|
|
|
func TestRoomRendersAndRotates(t *testing.T) {
|
|
app := openRoom(t)
|
|
cube := app.Scene.Find(app.Scene.Root(), "Cube")
|
|
if cube.IsZero() {
|
|
t.Fatal("cube missing")
|
|
}
|
|
driver := app.Driver()
|
|
for i := 0; i < 120; i++ {
|
|
if !app.Engine.Step(driver) {
|
|
t.Fatalf("engine stopped at frame %d: %v", i, app.Engine.Err())
|
|
}
|
|
}
|
|
q := app.Scene.Local3D(cube).Rotation
|
|
if q.Y <= 0 || mathx.Abs(q.X) > 1e-6 || mathx.Abs(q.Z) > 1e-6 {
|
|
t.Fatalf("cube must rotate about +Y: %v", q)
|
|
}
|
|
st := app.Runner.Stats()
|
|
if st.Views != 1 || st.Meshes != 3 {
|
|
t.Fatalf("views %d meshes %d", st.Views, st.Meshes)
|
|
}
|
|
}
|
|
|
|
func TestRoomRoundTrip(t *testing.T) {
|
|
app := openRoom(t)
|
|
out := string(sceneio.Save(app.Scene))
|
|
for _, want := range []string{`space="3d"`, "transform3d", "engine.Camera3D", "game.Rotator3D", "axis=[0, 1, 0]"} {
|
|
if !strings.Contains(out, want) {
|
|
t.Fatalf("saved scene lacks %q:\n%s", want, out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRoomFrameDoesNotAllocate(t *testing.T) {
|
|
app := openRoom(t)
|
|
driver := app.Driver()
|
|
for i := 0; i < 60; i++ {
|
|
app.Engine.Step(driver)
|
|
}
|
|
if allocs := testing.AllocsPerRun(240, func() { app.Engine.Step(driver) }); allocs != 0 {
|
|
t.Fatalf("3D frame allocates %.1f objects", allocs)
|
|
}
|
|
}
|