Compare commits
62
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
477620470d | ||
|
|
50be5c04bc | ||
|
|
107b09e506 | ||
|
|
1f47880e8a | ||
|
|
4920c2a11c | ||
|
|
5dd9cc91bb | ||
|
|
a6822156cd | ||
|
|
5eb1832907 | ||
|
|
ad23798da5 | ||
|
|
132ddeff70 | ||
|
|
c8d45b6ff5 | ||
|
|
962c479933 | ||
|
|
72d9a21782 | ||
|
|
cc2a428a7d | ||
|
|
824aa2e9a0 | ||
|
|
c2736c158f | ||
|
|
d4b5b88be1 | ||
|
|
78e86970d7 | ||
|
|
a6ebf841d0 | ||
|
|
f5944907cc | ||
|
|
d436311f69 | ||
|
|
6d7adba259 | ||
|
|
1e28291320 | ||
|
|
49c9e97203 | ||
|
|
a1eb467600 | ||
|
|
a25db02077 | ||
|
|
239a449fe2 | ||
|
|
b6cc16531d | ||
|
|
70be14646a | ||
|
|
70534c271c | ||
|
|
a15d2a1fe3 | ||
|
|
6e8ebcd90f | ||
|
|
adcdd5fbad | ||
|
|
0ec28ad86b | ||
|
|
ba9d35443f | ||
|
|
0fa39a3e17 | ||
|
|
fa6f37b7f5 | ||
|
|
6151233e05 | ||
|
|
53ed8c6476 | ||
|
|
ff896506f5 | ||
|
|
8a842b19a6 | ||
|
|
f22242e5aa | ||
|
|
2e10968d48 | ||
|
|
2fcbaa6c12 | ||
|
|
67e2d77823 | ||
|
|
55871f666b | ||
|
|
ef59ae297f | ||
|
|
7b83e82c6e | ||
|
|
515f4ca1b3 | ||
|
|
3d8e3b2fd3 | ||
|
|
c6a24ba393 | ||
|
|
7dca06e4b1 | ||
|
|
6dfdb824e2 | ||
|
|
de49a53172 | ||
|
|
1030dc9a43 | ||
|
|
3d25734dfa | ||
|
|
12f628c469 | ||
|
|
1529213434 | ||
|
|
f8bb865920 | ||
|
|
f5fb32565e | ||
|
|
f1a8f538d3 | ||
|
|
963b01a011 |
@@ -0,0 +1,4 @@
|
|||||||
|
# Agents working on Aego
|
||||||
|
|
||||||
|
- Binaries go to `.cache/bin` only. Never run `go build` without `-o` in the repository root, and build test binaries only with `go test -c -o .cache/bin/<name>.test`. `make clean` empties `.cache/bin`; `make ci` fails when the root holds a binary or a `*.test` file (`tools/ci-clean-root.sh`).
|
||||||
|
- Run the full `make ci` before every push. Between pushes, run the checks that cover the change: the tests of the changed packages, `make lint`, `make depcheck`, the docs check and the golden tests when the UI changed.
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Claude configuration
|
||||||
|
|
||||||
|
This directory contains project-specific guidance and local configuration for Claude Code. The guidance records repository hygiene and verification expectations for agents working on Aego.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Golden files and project sources are byte-stable across platforms.
|
||||||
|
* text=auto eol=lf
|
||||||
|
|
||||||
|
# Preserve the upstream font license exactly as committed (it uses CRLF).
|
||||||
|
tools/gendocs/site/static/fonts/IBM-Plex-OFL.txt -text
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# CI workflows
|
||||||
|
|
||||||
|
Gitea is the source of truth. The Linux workflow runs there; optional Gitea
|
||||||
|
platform runners remain controlled by `PLATFORM_RUNNERS`.
|
||||||
|
|
||||||
|
`github-native.yml` is for the GitHub mirror. It builds and tests on native
|
||||||
|
Windows, macOS (arm64 and amd64), and Linux runners, and uploads unsigned CI
|
||||||
|
artifacts and diagnostic logs. The Windows installer smoke is restricted to an
|
||||||
|
ephemeral GitHub-hosted runner. macOS bundles are ad-hoc signed, not notarized.
|
||||||
|
These jobs are not evidence of platform support until they actually pass on
|
||||||
|
their respective runners.
|
||||||
|
|
||||||
|
On Gitea, the GitHub-only matrix routes to the Linux runner before being
|
||||||
|
skipped. This prevents Windows and macOS entries from waiting indefinitely for
|
||||||
|
runners that Gitea does not have. On GitHub, the actual native labels are used.
|
||||||
|
macOS and Windows build the pinned GLSL reference validator from verified
|
||||||
|
source, rather than depending on a changing package-manager version.
|
||||||
|
|
||||||
|
To show native GitHub results on the Gitea commit, create the GitHub Actions
|
||||||
|
secret `GITEA_STATUS_TOKEN` containing a Gitea API token with repository write
|
||||||
|
permission. Prefer a non-admin bot that has access only to `sanspie/aego`:
|
||||||
|
Gitea's repository-write token is broader than commit statuses. The reporter
|
||||||
|
publishes pending and final statuses with links to the real GitHub jobs only
|
||||||
|
for trusted `master` pushes or manual runs, never for pull requests. If the
|
||||||
|
secret is missing, CI still runs but no Gitea statuses are published.
|
||||||
|
|
||||||
|
Keep GitHub Actions disabled through the first mirror sync: historical tags
|
||||||
|
can contain older workflows. Before enabling Actions, verify mirrored refs and
|
||||||
|
restrict the allowed workflows so historical release jobs cannot run. Use a
|
||||||
|
separate repository-scoped credential for the mirror; do not put it in a URL.
|
||||||
|
Gitea's build-and-publish job remains paused. `github-release-mirror.yml`
|
||||||
|
copies already-published Gitea releases and assets to GitHub after the current
|
||||||
|
master passes Gitea Linux CI and all four real GitHub native jobs. It also
|
||||||
|
checks periodically and can be dispatched manually from master. Versioned
|
||||||
|
stable releases are published normally, with the highest stable version marked
|
||||||
|
Latest; nightly, beta versions, and the stable-channel pointer are prereleases.
|
||||||
|
The mirror verifies matching git refs and asset sizes/checksums, stages new
|
||||||
|
releases as drafts, and never moves tags or replaces existing assets. If a
|
||||||
|
mutable nightly or another mirrored snapshot changes, the mirror stops rather
|
||||||
|
than overwriting it; a separate reviewed update is needed in that case. Signed
|
||||||
|
update manifests are copied unchanged and retain their original download URLs.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -9,16 +9,19 @@ permissions:
|
|||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
GLSLANG_APT_VERSION: 15.1.0-2~ubuntu0.24.04.2
|
||||||
LINUX_PKGS: >-
|
LINUX_PKGS: >-
|
||||||
build-essential cmake ninja-build pkg-config
|
build-essential cmake ninja-build pkg-config openssl
|
||||||
libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev
|
libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev
|
||||||
libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev libxkbcommon-dev
|
libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev libxkbcommon-dev
|
||||||
libwayland-dev wayland-protocols libdecor-0-dev
|
libwayland-dev wayland-protocols libdecor-0-dev
|
||||||
libasound2-dev libpulse-dev libdrm-dev libgbm-dev libudev-dev libdbus-1-dev libibus-1.0-dev
|
libasound2-dev libpulse-dev libdrm-dev libgbm-dev libudev-dev libdbus-1-dev libibus-1.0-dev
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
# Native runs on Windows and macOS machines; the Windows build itself is cross-compiled on Linux in ci.yml (D301).
|
||||||
if: vars.PLATFORM_RUNNERS == 'true'
|
smoke:
|
||||||
|
name: ${{ matrix.goos }} ${{ matrix.goarch }} smoke
|
||||||
|
if: github.server_url != 'https://github.com' && vars.PLATFORM_RUNNERS == 'true'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -39,7 +42,7 @@ jobs:
|
|||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
- name: linux packages
|
- name: linux packages
|
||||||
if: runner.os == 'Linux'
|
if: runner.os == 'Linux'
|
||||||
run: sudo apt-get update && sudo apt-get install -y $LINUX_PKGS
|
run: sudo apt-get update && sudo apt-get install -y $LINUX_PKGS "glslang-tools=$GLSLANG_APT_VERSION" && bash tools/check-glslang.sh
|
||||||
- name: msys2
|
- name: msys2
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
id: msys2
|
id: msys2
|
||||||
|
|||||||
+228
-10
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
|||||||
|
name: github-release-mirror
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: [github-native]
|
||||||
|
types: [completed]
|
||||||
|
branches: [master]
|
||||||
|
schedule:
|
||||||
|
- cron: '17 */6 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: github-release-mirror
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
mirror:
|
||||||
|
if: github.server_url == 'https://github.com' && github.repository == 'Alexander-D-Karpov/aego' && github.ref == 'refs/heads/master'
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
timeout-minutes: 60
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
actions: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||||
|
with:
|
||||||
|
ref: refs/heads/master
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Test release mirror
|
||||||
|
run: python3 -m unittest discover -s tools/ci -p mirror_releases_test.py -v
|
||||||
|
- name: Mirror published Gitea releases
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: python3 tools/ci/mirror_releases.py --apply
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -17,4 +17,13 @@ tools/genicons/genicons
|
|||||||
|
|
||||||
/tests/golden/testdata/actual-*
|
/tests/golden/testdata/actual-*
|
||||||
tools/websmoke/node_modules/
|
tools/websmoke/node_modules/
|
||||||
|
/tools/websmoke/__pycache__/
|
||||||
tools/websmoke/golden/actual-*.png
|
tools/websmoke/golden/actual-*.png
|
||||||
|
|
||||||
|
# build output belongs in .cache/bin; these catch stray builds in the root
|
||||||
|
/aego-*
|
||||||
|
/i18n
|
||||||
|
*.prof
|
||||||
|
*.pprof
|
||||||
|
/data*.txt
|
||||||
|
*.key
|
||||||
|
|||||||
+278
-33
File diff suppressed because one or more lines are too long
@@ -0,0 +1,10 @@
|
|||||||
|
# Aego — A 2D game engine built in Go.
|
||||||
|
|
||||||
|
Build games visually, write gameplay logic in Aego Script, and extend the engine with native Go.
|
||||||
|
|
||||||
|
A complete development environment with a visual editor, hot reload, deterministic simulation, frame-by-frame rewind, and cross-platform export. From your first scene to a playable game on Windows, Linux, macOS, and the web.
|
||||||
|
|
||||||
|
- Documentation and the playground: <https://aego.akarpov.ru>
|
||||||
|
- Installing and building from source: [engine/res/docs/install.md](engine/res/docs/install.md)
|
||||||
|
- Contributing, check levels and rules for engine code: [docs/contributing.md](docs/contributing.md)
|
||||||
|
- Architecture and decisions: [ARCHITECTURE.md](ARCHITECTURE.md)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Animation
|
||||||
|
|
||||||
|
`anim` provides the shared animation kernel for clips, keyframe tracks, events, and controller graphs. It samples tracks, evaluates state transitions and blending, and encodes clips and controllers in text and binary forms for use by the engine and editor.
|
||||||
+238
File diff suppressed because it is too large
Load Diff
+234
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+109
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,98 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func clip(loop LoopMode, ts ...float32) *Clip {
|
||||||
|
c := &Clip{Length: 1, Loop: loop}
|
||||||
|
for _, t := range ts {
|
||||||
|
c.Events = append(c.Events, Event{T: t, Name: "e"})
|
||||||
|
}
|
||||||
|
c.Fix()
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func evs(cs []Crossing) []int32 {
|
||||||
|
out := make([]int32, len(cs))
|
||||||
|
for i, c := range cs {
|
||||||
|
out[i] = c.Event
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func cycles(cs []Crossing) []int64 {
|
||||||
|
out := make([]int64, len(cs))
|
||||||
|
for i, c := range cs {
|
||||||
|
out[i] = c.Cycle
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func expect[T comparable](t *testing.T, name string, got, want []T) {
|
||||||
|
t.Helper()
|
||||||
|
if !slices.Equal(got, want) {
|
||||||
|
t.Fatalf("%s: got %v, want %v", name, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOnce(t *testing.T) {
|
||||||
|
c := clip(LoopOnce, 0, 0.5, 1)
|
||||||
|
expect(t, "start", evs(Crossings(c, LoopOnce, 0, 0.6, true, nil)), []int32{0, 1})
|
||||||
|
expect(t, "end", evs(Crossings(c, LoopOnce, 0.6, 1.5, false, nil)), []int32{2})
|
||||||
|
expect(t, "after", evs(Crossings(c, LoopOnce, 1, 2, false, nil)), []int32{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestZeroKeyEveryCycle(t *testing.T) {
|
||||||
|
c := clip(LoopRepeat, 0)
|
||||||
|
expect(t, "start", cycles(Crossings(c, LoopRepeat, 0, 0.5, true, nil)), []int64{0})
|
||||||
|
expect(t, "next", cycles(Crossings(c, LoopRepeat, 0.5, 1.5, false, nil)), []int64{1})
|
||||||
|
expect(t, "two", cycles(Crossings(c, LoopRepeat, 1.5, 3.2, false, nil)), []int64{2, 3})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLengthKeyOncePerCycle(t *testing.T) {
|
||||||
|
c := clip(LoopRepeat, 1)
|
||||||
|
expect(t, "start", evs(Crossings(c, LoopRepeat, 0, 0.5, true, nil)), []int32{})
|
||||||
|
expect(t, "first", cycles(Crossings(c, LoopRepeat, 0.5, 1, false, nil)), []int64{0})
|
||||||
|
expect(t, "second", cycles(Crossings(c, LoopRepeat, 1, 2, false, nil)), []int64{1})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSameMoment(t *testing.T) {
|
||||||
|
c := clip(LoopOnce, 0.5, 0.5)
|
||||||
|
expect(t, "forward", evs(Crossings(c, LoopOnce, 0, 1, false, nil)), []int32{0, 1})
|
||||||
|
expect(t, "backward", evs(Crossings(c, LoopOnce, 1, 0, false, nil)), []int32{0, 1})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStillAndBackward(t *testing.T) {
|
||||||
|
c := clip(LoopRepeat, 0.2, 0.8)
|
||||||
|
expect(t, "speed 0", evs(Crossings(c, LoopRepeat, 0.3, 0.3, false, nil)), []int32{})
|
||||||
|
got := Crossings(c, LoopRepeat, 1.5, 0.1, false, nil)
|
||||||
|
expect(t, "backward events", evs(got), []int32{0, 1, 0})
|
||||||
|
expect(t, "backward cycles", cycles(got), []int64{1, 0, 0})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestManyCycles(t *testing.T) {
|
||||||
|
c := clip(LoopRepeat, 0.5)
|
||||||
|
expect(t, "three", cycles(Crossings(c, LoopRepeat, 0, 3, true, nil)), []int64{0, 1, 2})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPingPongTurns(t *testing.T) {
|
||||||
|
c := clip(LoopPingPong, 0, 1)
|
||||||
|
got := Crossings(c, LoopPingPong, 0, 4, true, nil)
|
||||||
|
expect(t, "events", evs(got), []int32{0, 1, 0, 1, 0})
|
||||||
|
expect(t, "cycles", cycles(got), []int64{0, 0, 2, 2, 4})
|
||||||
|
mid := clip(LoopPingPong, 0.25)
|
||||||
|
got = Crossings(mid, LoopPingPong, 0, 2, true, nil)
|
||||||
|
if len(got) != 2 || got[0].T != 0.25 || got[1].T != 1.75 {
|
||||||
|
t.Fatalf("mid %+v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCrossingsNoAllocs(t *testing.T) {
|
||||||
|
c := clip(LoopRepeat, 0, 0.25, 0.5, 0.75)
|
||||||
|
buf := make([]Crossing, 0, 64)
|
||||||
|
if n := testing.AllocsPerRun(100, func() { buf = Crossings(c, LoopRepeat, 0.1, 3.9, false, buf) }); n != 0 {
|
||||||
|
t.Fatalf("Crossings allocates %v", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
+332
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"aego/format/aetext"
|
||||||
|
)
|
||||||
|
|
||||||
|
const layoutSrc = `controller version=1 {
|
||||||
|
entry="Idle"
|
||||||
|
param "Speed" kind=float {}
|
||||||
|
state "Idle" {}
|
||||||
|
state "Run" {}
|
||||||
|
state "Jump" pos=[500, -40] {}
|
||||||
|
state "Lost" {}
|
||||||
|
transition "Idle" to="Run" duration=0.1 {
|
||||||
|
cond "Speed" op=gt value=0.1 {}
|
||||||
|
}
|
||||||
|
transition "Run" to="Idle" duration=0.1 {
|
||||||
|
cond "Speed" op=le value=0.1 {}
|
||||||
|
}
|
||||||
|
transition "any" to="Jump" {
|
||||||
|
cond "Speed" op=lt value=0 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
func layoutGraph(t *testing.T) *Graph {
|
||||||
|
t.Helper()
|
||||||
|
doc, err := aetext.Parse([]byte(layoutSrc), "l.aectrl")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
g, probs, err := DecodeGraph(doc)
|
||||||
|
if err != nil || len(probs) > 0 {
|
||||||
|
t.Fatalf("%v %+v", err, probs)
|
||||||
|
}
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLayoutPlacesEveryStateApart(t *testing.T) {
|
||||||
|
g := layoutGraph(t)
|
||||||
|
g.Layout()
|
||||||
|
seen := map[[2]float32]string{}
|
||||||
|
for _, s := range g.States {
|
||||||
|
if !s.HasPos {
|
||||||
|
t.Fatalf("%s has no position", s.Name)
|
||||||
|
}
|
||||||
|
if o, dup := seen[s.Pos]; dup {
|
||||||
|
t.Fatalf("%s and %s share %v", s.Name, o, s.Pos)
|
||||||
|
}
|
||||||
|
seen[s.Pos] = s.Name
|
||||||
|
}
|
||||||
|
idle, run, jump := g.States[0].Pos, g.States[1].Pos, g.States[2].Pos
|
||||||
|
if idle[0] != 0 || run[0] != LayoutColumn {
|
||||||
|
t.Fatalf("entry %v, next %v: the entry is the first column", idle, run)
|
||||||
|
}
|
||||||
|
if jump != [2]float32{500, -40} {
|
||||||
|
t.Fatalf("a written position moved to %v", jump)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPosRoundTrips(t *testing.T) {
|
||||||
|
g := layoutGraph(t)
|
||||||
|
g.Layout()
|
||||||
|
text := aetext.Write(EncodeGraph(g))
|
||||||
|
doc, err := aetext.Parse(text, "l.aectrl")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
back, _, err := DecodeGraph(doc)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
bin, err := UnmarshalGraph(MarshalGraph(back))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for i := range g.States {
|
||||||
|
if back.States[i].Pos != g.States[i].Pos || bin.States[i].Pos != g.States[i].Pos {
|
||||||
|
t.Fatalf("%s: text %v binary %v, want %v", g.States[i].Name, back.States[i].Pos, bin.States[i].Pos, g.States[i].Pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := UnmarshalGraph(MarshalGraph(back)[:len(MarshalGraph(back))-4]); err == nil {
|
||||||
|
t.Fatal("a truncated state was accepted")
|
||||||
|
}
|
||||||
|
}
|
||||||
+185
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
// RootDelta is the change of a root track between two clip times: a looping clip adds its end minus its start for every cycle crossed, a ping-pong clip only moves back and forth.
|
||||||
|
func RootDelta(c *Clip, s *Sampler, track int, loop LoopMode, t0, t1 float64) [2]float32 {
|
||||||
|
if !(c.Length > 0) || t0 == t1 || track < 0 || track >= len(c.Tracks) {
|
||||||
|
return [2]float32{}
|
||||||
|
}
|
||||||
|
u0, k0 := c.Local(loop, t0)
|
||||||
|
u1, k1 := c.Local(loop, t1)
|
||||||
|
a := s.Track(c, track, u0).L
|
||||||
|
b := s.Track(c, track, u1).L
|
||||||
|
d := [2]float32{b[0] - a[0], b[1] - a[1]}
|
||||||
|
if loop == LoopRepeat && k1 != k0 {
|
||||||
|
start := s.Track(c, track, 0).L
|
||||||
|
end := s.Track(c, track, c.Length).L
|
||||||
|
n := float32(k1 - k0)
|
||||||
|
d[0] += n * (end[0] - start[0])
|
||||||
|
d[1] += n * (end[1] - start[1])
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"aego/core/curve"
|
||||||
|
"aego/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
func walkClip(loop LoopMode) *Clip {
|
||||||
|
c := &Clip{Length: 1, Loop: loop, Tracks: []Track{{
|
||||||
|
Property: RootProp, Kind: schema.KindVec2, Root: true,
|
||||||
|
Keys: []Key{{T: 0, V: Lanes([4]float32{0, 0}), Interp: curve.InterpLinear}, {T: 1, V: Lanes([4]float32{1, 0.5})}},
|
||||||
|
}}}
|
||||||
|
c.Fix()
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRootDelta(t *testing.T) {
|
||||||
|
var s Sampler
|
||||||
|
loop := walkClip(LoopRepeat)
|
||||||
|
for _, tc := range []struct {
|
||||||
|
t0, t1 float64
|
||||||
|
want [2]float32
|
||||||
|
}{
|
||||||
|
{0.25, 0.75, [2]float32{0.5, 0.25}},
|
||||||
|
{0.5, 1.5, [2]float32{1, 0.5}},
|
||||||
|
{0.25, 2.25, [2]float32{2, 1}},
|
||||||
|
{1.25, 0.25, [2]float32{-1, -0.5}},
|
||||||
|
{0.75, 1, [2]float32{0.25, 0.125}},
|
||||||
|
} {
|
||||||
|
d := RootDelta(loop, &s, 0, LoopRepeat, tc.t0, tc.t1)
|
||||||
|
if !near(d[0], tc.want[0]) || !near(d[1], tc.want[1]) {
|
||||||
|
t.Fatalf("loop %v..%v: %v, want %v", tc.t0, tc.t1, d, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ping := walkClip(LoopPingPong)
|
||||||
|
if d := RootDelta(ping, &s, 0, LoopPingPong, 0.5, 1.5); !near(d[0], 0) || !near(d[1], 0) {
|
||||||
|
t.Fatalf("ping-pong turns back: %v", d)
|
||||||
|
}
|
||||||
|
once := walkClip(LoopOnce)
|
||||||
|
if d := RootDelta(once, &s, 0, LoopOnce, 0.75, 3); !near(d[0], 0.25) {
|
||||||
|
t.Fatalf("once stops at the end: %v", d)
|
||||||
|
}
|
||||||
|
if d := RootDelta(loop, &s, 0, LoopRepeat, 0.5, 0.5); d != ([2]float32{}) {
|
||||||
|
t.Fatalf("no time, no motion: %v", d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRootCheck(t *testing.T) {
|
||||||
|
c := walkClip(LoopRepeat)
|
||||||
|
if ps := c.Check(nil); len(ps) != 0 {
|
||||||
|
t.Fatalf("a good root track reports %+v", ps)
|
||||||
|
}
|
||||||
|
c.Tracks[0].Target = "Body"
|
||||||
|
if ps := c.Check(nil); len(ps) != 1 || ps[0].Kind != ProblemRoot {
|
||||||
|
t.Fatalf("a root track on a child: %+v", ps)
|
||||||
|
}
|
||||||
|
}
|
||||||
+146
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,73 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"aego/format/aetext"
|
||||||
|
)
|
||||||
|
|
||||||
|
// shape lists the attributes, fields and child blocks a block of a clip or controller may hold.
|
||||||
|
type shape struct {
|
||||||
|
attrs []string
|
||||||
|
fields []string
|
||||||
|
blocks []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
clipShape = shape{attrs: []string{"version", "length", "fps", "loop"}, blocks: []string{"track", "frames", "event"}}
|
||||||
|
trackShape = shape{attrs: []string{"prop", "kind", "numeric", "root", "authority", "onEnd"}, blocks: []string{"key"}}
|
||||||
|
keyShape = shape{attrs: []string{"t", "v", "interp", "tangent", "in", "out"}}
|
||||||
|
framesShape = shape{attrs: []string{"start", "fps", "prop", "flipProp", "authority"}, fields: []string{"sprites", "durations", "flipX"}}
|
||||||
|
eventShape = shape{attrs: []string{"t", "name", "payload", "mode"}}
|
||||||
|
ctrlShape = shape{attrs: []string{"version", "ease", "entryPos", "anyPos"}, fields: []string{"entry"}, blocks: []string{"param", "state", "transition"}}
|
||||||
|
paramShape = shape{attrs: []string{"kind", "default"}}
|
||||||
|
stateShape = shape{attrs: []string{"clip", "speed", "loop", "pos", "events"}}
|
||||||
|
transShape = shape{attrs: []string{"to", "duration", "exitTime", "interrupt"}, blocks: []string{"cond"}}
|
||||||
|
condShape = shape{attrs: []string{"op", "value"}}
|
||||||
|
)
|
||||||
|
|
||||||
|
// opening is how the block's first line reads with the attribute moved into it.
|
||||||
|
func opening(n *aetext.Node, f aetext.Field) string {
|
||||||
|
var b strings.Builder
|
||||||
|
b.WriteString(n.Head)
|
||||||
|
if n.Label != "" || n.Head == "frames" || n.Head == "track" {
|
||||||
|
b.WriteString(" " + strconv.Quote(n.Label))
|
||||||
|
}
|
||||||
|
b.WriteString(" " + f.Name + "=" + aetext.FormatValue(f.Value) + " {")
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// strict refuses names a block does not know, so a misspelt or misplaced setting is never dropped silently.
|
||||||
|
func strict(n *aetext.Node, s shape) error {
|
||||||
|
for _, f := range n.Attrs {
|
||||||
|
switch {
|
||||||
|
case slices.Contains(s.attrs, f.Name):
|
||||||
|
case slices.Contains(s.fields, f.Name):
|
||||||
|
return textErr(n, f.Name+" is a field of "+n.Head+": write "+f.Name+"="+aetext.FormatValue(f.Value)+" inside the block")
|
||||||
|
default:
|
||||||
|
return textErr(n, "unknown attribute "+f.Name+" of "+n.Head+"; it takes "+strings.Join(s.attrs, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range n.Fields {
|
||||||
|
switch {
|
||||||
|
case slices.Contains(s.fields, f.Name):
|
||||||
|
case slices.Contains(s.attrs, f.Name):
|
||||||
|
return textErr(n, f.Name+" is an attribute of "+n.Head+": write `"+opening(n, f)+"`")
|
||||||
|
case len(s.fields) == 0:
|
||||||
|
return textErr(n, "unknown field "+f.Name+": "+n.Head+" takes no fields")
|
||||||
|
default:
|
||||||
|
return textErr(n, "unknown field "+f.Name+" of "+n.Head+"; it takes "+strings.Join(s.fields, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, b := range n.Blocks {
|
||||||
|
if !slices.Contains(s.blocks, b.Head) {
|
||||||
|
if len(s.blocks) == 0 {
|
||||||
|
return textErr(b, n.Head+" holds no blocks, found "+b.Head)
|
||||||
|
}
|
||||||
|
return textErr(b, "unknown block "+b.Head+" in "+n.Head+"; it holds "+strings.Join(s.blocks, ", "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"aego/format/aetext"
|
||||||
|
)
|
||||||
|
|
||||||
|
func decodeText(t *testing.T, src string, ctrl bool) error {
|
||||||
|
t.Helper()
|
||||||
|
n, err := aetext.Parse([]byte(src), "t")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ctrl {
|
||||||
|
_, _, err = DecodeGraph(n)
|
||||||
|
} else {
|
||||||
|
_, err = Decode(n)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every block of a clip refuses names it does not know instead of dropping them.
|
||||||
|
func TestClipRefusesUnknownNames(t *testing.T) {
|
||||||
|
cases := []struct{ name, src, want string }{
|
||||||
|
{"root", `anim version=1 length=1 speed=2 {}`, "unknown attribute speed of anim"},
|
||||||
|
{"root block", "anim version=1 length=1 {\n curve \"\" {}\n}\n", "unknown block curve"},
|
||||||
|
{"track", "anim version=1 length=1 {\n track \"\" prop=\"SpriteRenderer.size\" kind=vec2 loop=true {}\n}\n", "unknown attribute loop of track"},
|
||||||
|
{"key", "anim version=1 length=1 {\n track \"\" prop=\"SpriteRenderer.size\" kind=vec2 {\n key t=0 v=[1, 1] ease=linear {}\n }\n}\n", "unknown attribute ease of key"},
|
||||||
|
{"frames", "anim version=1 length=1 {\n frames \"Slash\" {\n sprites=[asset(\"ae900000000000000000000000000b01\")]\n start=0.08\n }\n}\n", "start is an attribute of frames: write `frames \"Slash\" start=0.08 {`"},
|
||||||
|
{"frames field", "anim version=1 length=1 {\n frames \"\" {\n sprites=[asset(\"ae900000000000000000000000000b01\")]\n duration=[0.1]\n }\n}\n", "unknown field duration of frames"},
|
||||||
|
{"event", "anim version=1 length=1 {\n event t=0.1 name=\"Hit\" when=1 {}\n}\n", "unknown attribute when of event"},
|
||||||
|
{"event field", "anim version=1 length=1 {\n event t=0.1 name=\"Hit\" {\n payload=1\n }\n}\n", "payload is an attribute of event"},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
err := decodeText(t, c.src, false)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
||||||
|
t.Errorf("%s: got %v, want %q", c.name, err, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every block of a controller refuses names it does not know instead of dropping them.
|
||||||
|
func TestControllerRefusesUnknownNames(t *testing.T) {
|
||||||
|
cases := []struct{ name, src, want string }{
|
||||||
|
{"root", "controller version=1 start=\"Idle\" {\n state \"Idle\" {}\n}\n", "unknown attribute start of controller"},
|
||||||
|
{"root field", "controller version=1 {\n ease=linear\n state \"Idle\" {}\n}\n", "ease is an attribute of controller"},
|
||||||
|
{"param", "controller version=1 {\n param \"Speed\" kind=float min=0 {}\n}\n", "unknown attribute min of param"},
|
||||||
|
{"state", "controller version=1 {\n state \"Idle\" clipp=asset(\"a0a10000000000000000000000000005\") {}\n}\n", "unknown attribute clipp of state"},
|
||||||
|
{"transition", "controller version=1 {\n state \"A\" {}\n state \"B\" {}\n transition \"A\" to=\"B\" exit=1 {}\n}\n", "unknown attribute exit of transition"},
|
||||||
|
{"cond", "controller version=1 {\n param \"Speed\" kind=float {}\n state \"A\" {}\n state \"B\" {}\n transition \"A\" to=\"B\" {\n cond \"Speed\" op=gt val=1 {}\n }\n}\n", "unknown attribute val of cond"},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
err := decodeText(t, c.src, true)
|
||||||
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
||||||
|
t.Errorf("%s: got %v, want %q", c.name, err, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+521
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,87 @@
|
|||||||
|
package anim
|
||||||
|
|
||||||
|
import (
|
||||||
|
"aego/core/ids"
|
||||||
|
"aego/format/aetext"
|
||||||
|
"aego/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Value struct {
|
||||||
|
L [4]float32
|
||||||
|
I int64
|
||||||
|
A ids.AssetID
|
||||||
|
}
|
||||||
|
|
||||||
|
func Float(f float32) Value { return Value{L: [4]float32{f}} }
|
||||||
|
func Lanes(l [4]float32) Value { return Value{L: l} }
|
||||||
|
func Int(i int64) Value { return Value{I: i} }
|
||||||
|
func Asset(id ids.AssetID) Value { return Value{A: id} }
|
||||||
|
func (v Value) Truth() bool { return v.I != 0 }
|
||||||
|
|
||||||
|
func Bool(b bool) Value {
|
||||||
|
if b {
|
||||||
|
return Value{I: 1}
|
||||||
|
}
|
||||||
|
return Value{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type class uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
classNone class = iota
|
||||||
|
classLanes
|
||||||
|
classInt
|
||||||
|
classDiscrete
|
||||||
|
classQuat
|
||||||
|
classAsset
|
||||||
|
)
|
||||||
|
|
||||||
|
func classOf(k schema.Kind) class {
|
||||||
|
switch k {
|
||||||
|
case schema.KindFloat32, schema.KindFloat64, schema.KindVec2, schema.KindVec3, schema.KindVec4, schema.KindColor, schema.KindRect:
|
||||||
|
return classLanes
|
||||||
|
case schema.KindInt32, schema.KindInt64:
|
||||||
|
return classInt
|
||||||
|
case schema.KindBool, schema.KindEnum:
|
||||||
|
return classDiscrete
|
||||||
|
case schema.KindQuat:
|
||||||
|
return classQuat
|
||||||
|
case schema.KindAssetRef:
|
||||||
|
return classAsset
|
||||||
|
}
|
||||||
|
return classNone
|
||||||
|
}
|
||||||
|
|
||||||
|
func lanesOf(k schema.Kind) int {
|
||||||
|
switch k {
|
||||||
|
case schema.KindFloat32, schema.KindFloat64:
|
||||||
|
return 1
|
||||||
|
case schema.KindVec2:
|
||||||
|
return 2
|
||||||
|
case schema.KindVec3:
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
|
||||||
|
func Supported(k schema.Kind) bool {
|
||||||
|
return classOf(k) != classNone
|
||||||
|
}
|
||||||
|
|
||||||
|
func Interpolates(k schema.Kind) bool {
|
||||||
|
c := classOf(k)
|
||||||
|
return c == classLanes || c == classQuat
|
||||||
|
}
|
||||||
|
|
||||||
|
// LaneCount is the number of float lanes of a lane kind, 0 for discrete kinds.
|
||||||
|
func LaneCount(k schema.Kind) int {
|
||||||
|
if classOf(k) != classLanes && classOf(k) != classQuat {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return lanesOf(k)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValueText writes v the way a key stores it in .aeanim.
|
||||||
|
func ValueText(kind schema.Kind, v Value) aetext.Value {
|
||||||
|
return writeValue(kind, v)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# app
|
||||||
|
|
||||||
|
The `app` packages assemble the engine, modules, asset pipeline, and scripting workspace into development hosts. They coordinate workflows such as project creation, editing, running, and exporting outside the engine core.
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,97 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"aego/art"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ArtHost is supplied only by the running editor. Offline commands must not
|
||||||
|
// reopen files and silently replace the user's dirty graphical documents.
|
||||||
|
// Like Host.ApplyScene, these calls run on the editor mutation thread.
|
||||||
|
type ArtHost interface {
|
||||||
|
ReadArt(file, section string, offset, limit int) (*Output, error)
|
||||||
|
CaptureArt(file string, frame art.ID, channel art.Channel) (*Output, error)
|
||||||
|
PrepareArt(file string, revision uint64, label string, ops []art.Operation) (*Output, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArtProposal is an opaque, prepared transaction carried by the existing agent
|
||||||
|
// proposal queue. Commit is invoked only after its normal approval decision.
|
||||||
|
// Keeping the prepared transaction also preserves IDs returned by its preview.
|
||||||
|
type ArtProposal interface {
|
||||||
|
Commit() (*Output, error)
|
||||||
|
RetainedBytes() int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func artHost(s *Session) (ArtHost, error) {
|
||||||
|
if s != nil {
|
||||||
|
if h, ok := s.host.(ArtHost); ok {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("art: connect to the running Aego editor; offline writes to graphical documents are disabled")
|
||||||
|
}
|
||||||
|
func artCommands() []*Command {
|
||||||
|
fileArg := Arg{Name: "file", Type: "string", Doc: "Project-relative .aeart source, including unsaved editor content", Required: true, Pos: true}
|
||||||
|
return []*Command{
|
||||||
|
{Name: "art.read", Doc: "Read the current art document, not its last saved file. Lists are paginated; revision is a decimal string for art.apply.", Args: []Arg{
|
||||||
|
fileArg, {Name: "section", Type: "string", Doc: "summary, layers, frames, cels, palette, tags or slices"},
|
||||||
|
{Name: "offset", Type: "integer", Doc: "First item, default 0"}, {Name: "limit", Type: "integer", Doc: "1..1024 items; default 256"},
|
||||||
|
}, Run: func(s *Session, a Args) (*Output, error) {
|
||||||
|
h, err := artHost(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
offset, err := a.Int("offset", 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
limit, err := a.Int("limit", 256)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if offset < 0 || limit < 1 || limit > 1024 {
|
||||||
|
return nil, fmt.Errorf("art: invalid page")
|
||||||
|
}
|
||||||
|
return h.ReadArt(a.Str("file"), a.Str("section"), offset, limit)
|
||||||
|
}},
|
||||||
|
{Name: "art.capture", Doc: "Capture unsaved CPU pixels with document/frame/channel identity and revision. MCP returns a PNG image; the CLI writes it only with --out to a new file.", Args: []Arg{
|
||||||
|
fileArg, {Name: "frame", Type: "string", Doc: "Stable frame ID; defaults to current frame"},
|
||||||
|
{Name: "channel", Type: "string", Doc: "albedo, normal, height or emission; defaults to current channel"},
|
||||||
|
}, Run: func(s *Session, a Args) (*Output, error) {
|
||||||
|
h, err := artHost(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return h.CaptureArt(a.Str("file"), art.ID(a.Str("frame")), art.Channel(a.Str("channel")))
|
||||||
|
}},
|
||||||
|
{Name: "art.apply", Doc: "Propose one atomic graphics edit at the revision returned by art.read. Agent panel edits require approval; CLI and external agents follow the editor's confirmation setting. All use the document's common Undo. Name new entities with as and refer to them as $name later.", Write: true, Destroys: true, Args: []Arg{
|
||||||
|
fileArg, {Name: "revision", Type: "string", Doc: "Exact decimal revision returned by art.read", Required: true},
|
||||||
|
{Name: "label", Type: "string", Doc: "Human-readable operation label", Required: true},
|
||||||
|
{Name: "operations", Type: "array", Doc: "1..4096 typed art.Operation objects; no paths or shell commands", Required: true, Items: map[string]any{"type": "object"}},
|
||||||
|
}, Run: func(s *Session, a Args) (*Output, error) {
|
||||||
|
h, err := artHost(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !a.Bool("dry-run") {
|
||||||
|
return nil, fmt.Errorf("art: edits must pass through the editor proposal queue")
|
||||||
|
}
|
||||||
|
revision, err := strconv.ParseUint(a.Str("revision"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("art: revision must be an unsigned decimal integer")
|
||||||
|
}
|
||||||
|
label := strings.TrimSpace(a.Str("label"))
|
||||||
|
if label == "" || len(label) > 256 {
|
||||||
|
return nil, fmt.Errorf("art: label must have 1..256 bytes")
|
||||||
|
}
|
||||||
|
ops, err := art.DecodeOperations([]byte(a.Str("operations")))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return h.PrepareArt(a.Str("file"), revision, label, ops)
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,61 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func tree(depth, fan int) NodeView {
|
||||||
|
v := NodeView{Name: "n"}
|
||||||
|
if depth > 0 {
|
||||||
|
for i := 0; i < fan; i++ {
|
||||||
|
v.Children = append(v.Children, tree(depth-1, fan))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCapTreeKeepsTheFirstNodes(t *testing.T) {
|
||||||
|
v := tree(4, 4)
|
||||||
|
all := nodeCount(&v)
|
||||||
|
left := capTree(&v, 50, 0)
|
||||||
|
if kept := nodeCount(&v); kept != 50 || kept+left != all {
|
||||||
|
t.Fatalf("kept %d and left %d of %d", kept, left, all)
|
||||||
|
}
|
||||||
|
more := 0
|
||||||
|
var walk func(n *NodeView)
|
||||||
|
walk = func(n *NodeView) {
|
||||||
|
more += n.More
|
||||||
|
for i := range n.Children {
|
||||||
|
walk(&n.Children[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
walk(&v)
|
||||||
|
if more != left {
|
||||||
|
t.Fatalf("the more counts add up to %d, %d were left out", more, left)
|
||||||
|
}
|
||||||
|
v = tree(4, 2)
|
||||||
|
if left := capTree(&v, 0, 2); nodeCount(&v) != 7 || left != 31-7 {
|
||||||
|
t.Fatalf("depth 2 kept %d nodes", nodeCount(&v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestScriptWindow(t *testing.T) {
|
||||||
|
var b strings.Builder
|
||||||
|
for i := 1; i <= 1000; i++ {
|
||||||
|
b.WriteString("line " + strconv.Itoa(i) + "\n")
|
||||||
|
}
|
||||||
|
text := b.String()
|
||||||
|
if got, note := window(text, 0, 0, 2000); got != text || note != "" {
|
||||||
|
t.Fatal("a short script is not read whole")
|
||||||
|
}
|
||||||
|
got, note := window(text, 0, 0, 400)
|
||||||
|
if !strings.HasPrefix(got, "line 1\n") || !strings.HasSuffix(got, "line 400\n") || !strings.Contains(note, "1-400 of 1001") {
|
||||||
|
t.Fatalf("the first window is wrong: %q", note)
|
||||||
|
}
|
||||||
|
got, _ = window(text, 600, 620, 400)
|
||||||
|
if !strings.HasPrefix(got, "line 600\n") || !strings.HasSuffix(got, "line 620\n") {
|
||||||
|
t.Fatalf("the asked range is wrong: %q", got[:20])
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,10 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"aego/project"
|
"aego/project"
|
||||||
@@ -13,6 +15,7 @@ type cliFlags struct {
|
|||||||
json bool
|
json bool
|
||||||
quiet bool
|
quiet bool
|
||||||
strict bool
|
strict bool
|
||||||
|
artOut string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Usage(w io.Writer) {
|
func Usage(w io.Writer) {
|
||||||
@@ -47,6 +50,12 @@ func Main(p *project.Project, args []string, stdout, stderr io.Writer, opt Optio
|
|||||||
fmt.Fprintln(stderr, "usage: aego "+c.Usage())
|
fmt.Fprintln(stderr, "usage: aego "+c.Usage())
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
if addr, token, ok := EditorProxy(p.Root); ok {
|
||||||
|
out, err := proxyRun(addr, token, c, a)
|
||||||
|
if !errors.As(err, new(errProxyDown)) {
|
||||||
|
return report(stdout, stderr, f, out, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
s, err := Open(p, opt)
|
s, err := Open(p, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return report(stdout, stderr, f, nil, err)
|
return report(stdout, stderr, f, nil, err)
|
||||||
@@ -94,6 +103,22 @@ func parseArgs(c *Command, toks []string) (Args, cliFlags, error) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
case "out":
|
||||||
|
if c.Name != "art.capture" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
if i+1 >= len(toks) {
|
||||||
|
return nil, f, fmt.Errorf("--out needs a value")
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
val = toks[i]
|
||||||
|
}
|
||||||
|
if val == "" || f.artOut != "" {
|
||||||
|
return nil, f, fmt.Errorf("--out requires one non-empty path")
|
||||||
|
}
|
||||||
|
f.artOut = val
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
x, ok := byName[name]
|
x, ok := byName[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -122,6 +147,9 @@ func parseArgs(c *Command, toks []string) (Args, cliFlags, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func report(stdout, stderr io.Writer, f cliFlags, out *Output, err error) int {
|
func report(stdout, stderr io.Writer, f cliFlags, out *Output, err error) int {
|
||||||
|
if err == nil && f.artOut != "" {
|
||||||
|
err = writeArtCapture(f.artOut, out)
|
||||||
|
}
|
||||||
switch {
|
switch {
|
||||||
case f.json:
|
case f.json:
|
||||||
var v any = out
|
var v any = out
|
||||||
@@ -144,3 +172,31 @@ func report(stdout, stderr io.Writer, f cliFlags, out *Output, err error) int {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An explicit output path never overwrites a user's existing file.
|
||||||
|
func writeArtCapture(path string, out *Output) error {
|
||||||
|
if out == nil || len(out.Images) != 1 || out.Images[0].Mime != "image/png" {
|
||||||
|
return errors.New("art: editor did not return a PNG capture")
|
||||||
|
}
|
||||||
|
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("art: cannot create capture: %w", err)
|
||||||
|
}
|
||||||
|
return finishArtCapture(path, f, out.Images[0].Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// On failure leave the path alone: it may have been replaced while the opened
|
||||||
|
// file was being written. The caller is told that an incomplete file may remain.
|
||||||
|
func finishArtCapture(path string, f io.WriteCloser, data []byte) error {
|
||||||
|
n, err := f.Write(data)
|
||||||
|
if err == nil && n != len(data) {
|
||||||
|
err = io.ErrShortWrite
|
||||||
|
}
|
||||||
|
if closeErr := f.Close(); err == nil {
|
||||||
|
err = closeErr
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("art: cannot write capture: %w; incomplete output may remain at %q", err, path)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
+57
-5
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,59 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"aego/art"
|
||||||
|
"aego/asset"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Source-only scene validation must not treat a partial sprite sheet as a
|
||||||
|
// complete generic material texture when native runtime rejects that sampler.
|
||||||
|
func TestAgentSourceMaterialRejectsPartialArtSheet(t *testing.T) {
|
||||||
|
for _, multi := range []bool{false, true} {
|
||||||
|
t.Run(fmt.Sprintf("multi=%v", multi), func(t *testing.T) {
|
||||||
|
s := materialSession(t)
|
||||||
|
doc, err := art.New(4, 4, art.RGBA, art.DefaultLimits())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer doc.Close()
|
||||||
|
if multi {
|
||||||
|
edit, err := doc.Begin(doc.Revision(), "Add frame")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := edit.AddFrame(doc.Info().Frames[0].ID, 100); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
change, err := edit.Prepare()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := change.Apply(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data, err := doc.Encode()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
artID, err := s.create("assets/art.aeart", data)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
content := fmt.Sprintf("material version=1 shader=asset(%q) { params { Noise=asset(%q) } }", asset.BuiltinShaderDissolve.String(), artID.String())
|
||||||
|
materialID, err := s.create("assets/art.aemat", []byte(content))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if info, ok := (sources{s.Pipeline}).TextureMetadata(artID); !ok || info.Region != multi || info.Width != 4 || info.Height != 4 {
|
||||||
|
t.Fatalf("source-only metadata lost first-frame bounds: %+v/%v", info, ok)
|
||||||
|
}
|
||||||
|
if _, ok := (sources{s.Pipeline}).Material(materialID); ok == multi {
|
||||||
|
t.Fatalf("source-only material resolver result=%v for multi=%v", ok, multi)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
|||||||
|
package mcp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"aego/app/agent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Relay passes an outside agent's MCP session to the open editor, so its changes become the editor's Undo steps, named after the client.
|
||||||
|
func Relay(in io.Reader, out io.Writer, addr, token string) error {
|
||||||
|
client := "agent"
|
||||||
|
sc := bufio.NewScanner(in)
|
||||||
|
sc.Buffer(make([]byte, 0, 1<<20), maxBody)
|
||||||
|
for sc.Scan() {
|
||||||
|
line := sc.Bytes()
|
||||||
|
if len(line) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var msg map[string]any
|
||||||
|
if err := json.Unmarshal(line, &msg); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
params, _ := msg["params"].(map[string]any)
|
||||||
|
switch msg["method"] {
|
||||||
|
case "initialize":
|
||||||
|
if info, ok := params["clientInfo"].(map[string]any); ok {
|
||||||
|
if name, ok := info["name"].(string); ok && name != "" {
|
||||||
|
client = name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "tools/call":
|
||||||
|
if params != nil {
|
||||||
|
args, _ := params["arguments"].(map[string]any)
|
||||||
|
if args == nil {
|
||||||
|
args = map[string]any{}
|
||||||
|
}
|
||||||
|
args[agent.ViaArg] = "via agent: " + client
|
||||||
|
params["arguments"] = args
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body, _ := json.Marshal(msg)
|
||||||
|
rep, err := agent.ProxyPost(addr, token, body)
|
||||||
|
if err != nil {
|
||||||
|
id, ok := msg["id"]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rep, _ = json.Marshal(map[string]any{"jsonrpc": "2.0", "id": id, "error": map[string]any{"code": -32000, "message": "the editor closed; start the MCP server again: " + err.Error()}})
|
||||||
|
}
|
||||||
|
if len(rep) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := out.Write(append(rep, '\n')); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sc.Err()
|
||||||
|
}
|
||||||
+102
-36
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user