ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
235 lines
5.5 KiB
Go
235 lines
5.5 KiB
Go
package integration
|
|
|
|
import (
|
|
"math"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"aego/app/run"
|
|
"aego/core/log"
|
|
"aego/modules/render2d"
|
|
"aego/project"
|
|
"aego/scene"
|
|
"aego/scene/sceneio"
|
|
"aego/sdk"
|
|
)
|
|
|
|
const rotatorScene = `scene version=1 {
|
|
node "1a2b3c4d5e6f708192a3b4c5d6e7f809" name="Camera" enabled=true layers=1 {
|
|
transform { position=[0, 0] rotation=0 scale=[1, 1] }
|
|
component "engine.Camera" version=1 {
|
|
zoom=64
|
|
viewport=[0, 0, 1, 1]
|
|
mask=-1
|
|
order=0
|
|
clear=true
|
|
clearColor=#0a0d12ff
|
|
scale=free
|
|
virtual=[0, 0]
|
|
active=true
|
|
}
|
|
}
|
|
node "2b3c4d5e6f708192a3b4c5d6e7f8091a" name="Player" enabled=true layers=1 {
|
|
transform { position=[0, 0] rotation=0 scale=[1, 1] }
|
|
component "game.Rotator" version=1 {
|
|
speed=1.5
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
type Rotator struct {
|
|
Speed float32 `aego:"speed"`
|
|
}
|
|
|
|
type rotatorSystem struct{}
|
|
|
|
func (rotatorSystem) Run(ctx *sdk.Context) {
|
|
s := sdk.SceneOf(ctx)
|
|
if s == nil {
|
|
return
|
|
}
|
|
dt := float32(ctx.Dt)
|
|
sdk.Query1[Rotator](s).Each(func(n sdk.NodeHandle, r *Rotator) {
|
|
s.SetRotation(n, s.Local(n).Rotation+r.Speed*dt)
|
|
})
|
|
}
|
|
|
|
type rotatorModule struct{}
|
|
|
|
func (rotatorModule) Info() sdk.ModuleInfo {
|
|
return sdk.ModuleInfo{ID: "game.rotator", Version: "0.1.0"}
|
|
}
|
|
|
|
func (rotatorModule) Register(r *sdk.Registry) error {
|
|
if err := sdk.RegisterComponent[Rotator](r, sdk.Name("game.Rotator")); err != nil {
|
|
return err
|
|
}
|
|
return sdk.RegisterSystem(r, sdk.SystemDesc{
|
|
ID: "game.rotator.spin",
|
|
Phase: sdk.PhaseUpdate,
|
|
System: rotatorSystem{},
|
|
})
|
|
}
|
|
|
|
func newRotatorProject(t *testing.T) *project.Project {
|
|
t.Helper()
|
|
p, err := project.Create(t.TempDir(), "Rotator", false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
scenePath := filepath.Join(p.ScenesDir(), "main.aescene")
|
|
if err := os.WriteFile(scenePath, []byte(rotatorScene), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return p
|
|
}
|
|
|
|
func TestNativeComponentDrivesTheScene(t *testing.T) {
|
|
const frames = 120
|
|
const speed = 1.5 // the speed in rotatorScene
|
|
for _, tc := range []struct {
|
|
name string
|
|
frameTime float64
|
|
}{
|
|
{"120fps", 1.0 / 120},
|
|
{"60fps", 1.0 / 60},
|
|
{"30fps", 1.0 / 30},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
p := newRotatorProject(t)
|
|
app, err := run.Open(p, run.Config{
|
|
Headless: true,
|
|
FrameTime: tc.frameTime, // Use the headless simulated clock, not the host's wall clock.
|
|
Frames: frames,
|
|
Logger: log.Nop(),
|
|
ScenePath: filepath.Join(p.ScenesDir(), "main.aescene"),
|
|
}, rotatorModule{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer app.Close()
|
|
|
|
player := app.Scene.Find(app.Scene.Root(), "Player")
|
|
if player.IsZero() {
|
|
t.Fatal("player node missing")
|
|
}
|
|
rotator, ok := scene.Get[Rotator](app.Scene, player)
|
|
if !ok {
|
|
t.Fatal("rotator component was not loaded")
|
|
}
|
|
if rotator.Speed != speed {
|
|
t.Fatalf("rotator speed = %v, want %v", rotator.Speed, speed)
|
|
}
|
|
before := app.Scene.Local(player).Rotation
|
|
|
|
driver := app.Driver()
|
|
for i := 0; i < frames; i++ {
|
|
if !app.Engine.Step(driver) {
|
|
t.Fatalf("engine stopped at frame %d: %v", i, app.Engine.Err())
|
|
}
|
|
// The engine starts with a zero-delta frame; subsequent frames use
|
|
// the simulated clock even when no fixed update is due.
|
|
wantDelta := tc.frameTime
|
|
if i == 0 {
|
|
wantDelta = 0
|
|
}
|
|
if got := app.Engine.Stats().FrameTime; !(math.Abs(got-wantDelta) <= 1e-12) {
|
|
t.Fatalf("frame %d delta = %.12g, want %.12g", i, got, wantDelta)
|
|
}
|
|
want := float64(before) + float64(i)*speed*tc.frameTime
|
|
got := float64(app.Scene.Local(player).Rotation)
|
|
if !(math.Abs(got-want) <= 1e-5) {
|
|
t.Fatalf("frame %d rotation = %.9g, want %.9g", i, got, want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSceneLoadsWithoutTheNativeModule(t *testing.T) {
|
|
p := newRotatorProject(t)
|
|
app, err := run.Open(p, run.Config{
|
|
Headless: true,
|
|
Logger: log.Nop(),
|
|
ScenePath: filepath.Join(p.ScenesDir(), "main.aescene"),
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer app.Close()
|
|
|
|
player := app.Scene.Find(app.Scene.Root(), "Player")
|
|
if player.IsZero() {
|
|
t.Fatal("player node missing")
|
|
}
|
|
if _, ok := scene.Get[render2d.SpriteRenderer](app.Scene, player); ok {
|
|
t.Fatal("unexpected component")
|
|
}
|
|
|
|
out := sceneioSave(t, app)
|
|
if !containsString(out, "game.Rotator") || !containsString(out, "speed=1.5") {
|
|
t.Fatalf("unknown component data was lost:\n%s", out)
|
|
}
|
|
}
|
|
|
|
func TestCamerasProduceViews(t *testing.T) {
|
|
p := newRotatorProject(t)
|
|
app, err := run.Open(p, run.Config{
|
|
Headless: true,
|
|
Logger: log.Nop(),
|
|
ScenePath: filepath.Join(p.ScenesDir(), "main.aescene"),
|
|
}, rotatorModule{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer app.Close()
|
|
|
|
driver := app.Driver()
|
|
for i := 0; i < 5; i++ {
|
|
app.Engine.Step(driver)
|
|
}
|
|
if st := app.Runner.Stats(); st.Views != 1 {
|
|
t.Fatalf("views = %d", st.Views)
|
|
}
|
|
}
|
|
|
|
func TestNoAllocationsPerFrameWithScene(t *testing.T) {
|
|
p := newRotatorProject(t)
|
|
app, err := run.Open(p, run.Config{
|
|
Headless: true,
|
|
Logger: log.Nop(),
|
|
ScenePath: filepath.Join(p.ScenesDir(), "main.aescene"),
|
|
}, rotatorModule{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer app.Close()
|
|
|
|
driver := app.Driver()
|
|
for i := 0; i < 60; i++ {
|
|
app.Engine.Step(driver)
|
|
}
|
|
allocs := testing.AllocsPerRun(240, func() {
|
|
app.Engine.Step(driver)
|
|
})
|
|
if allocs != 0 {
|
|
t.Fatalf("frame allocates %.1f objects with a scene loaded", allocs)
|
|
}
|
|
}
|
|
|
|
func sceneioSave(t *testing.T, app *run.App) string {
|
|
t.Helper()
|
|
return string(sceneio.Save(app.Scene))
|
|
}
|
|
|
|
func containsString(s, sub string) bool {
|
|
for i := 0; i+len(sub) <= len(s); i++ {
|
|
if s[i:i+len(sub)] == sub {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|