Files
aego/tools/artstudio/previewwasm/main.go
sanspie 50be5c04bc
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
Stage 12.5: Art Workspace and asset authoring
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.
2026-11-15 10:37:50 +03:00

145 lines
3.6 KiB
Go

//go:build js && wasm
// The lazy GPU presentation runtime consumes immutable snapshots. The main
// aegoArt runtime remains the only editable document and history owner.
package main
import (
"encoding/json"
"fmt"
"io"
"math"
"strings"
"syscall/js"
"aego/tools/artstudio/gpupreview"
)
var app *gpupreview.App
var callbacks []js.Func
func reply(err error) any {
v := map[string]any{}
if app != nil {
v["status"] = app.Status()
}
if err != nil {
v["error"] = err.Error()
}
b, _ := json.Marshal(v)
return string(b)
}
func integer(v js.Value) (uint64, error) {
if v.Type() != js.TypeNumber {
return 0, fmt.Errorf("preview expects a revision number")
}
n := v.Float()
if n <= 0 || n > 9007199254740991 || math.IsNaN(n) || math.Trunc(n) != n {
return 0, fmt.Errorf("invalid preview revision")
}
return uint64(n), nil
}
func start(_ js.Value, _ []js.Value) any {
if app != nil {
return reply(nil)
}
a, err := gpupreview.New(false)
if err != nil {
return reply(err)
}
app = a
go func() {
if err := a.Run(); err != nil {
js.Global().Get("console").Call("error", "Asset Studio GPU initialization failed: "+err.Error())
}
}()
return reply(nil)
}
func publish(_ js.Value, args []js.Value) any {
if app == nil {
return reply(fmt.Errorf("GPU preview is not started"))
}
if len(args) != 3 {
return reply(fmt.Errorf("preview requires sequence, revision and snapshot bytes"))
}
seq, err := integer(args[0])
if err != nil {
return reply(err)
}
rev, err := integer(args[1])
if err != nil {
return reply(err)
}
v := args[2]
if v.Type() != js.TypeObject || v.IsNull() || !v.InstanceOf(js.Global().Get("Uint8Array")) {
return reply(fmt.Errorf("preview requires a Uint8Array snapshot"))
}
n := v.Get("byteLength").Int()
if n == 0 || n > gpupreview.MaxSnapshotBytes {
return reply(fmt.Errorf("preview snapshot exceeds limit"))
}
b := make([]byte, n)
js.CopyBytesToGo(b, v)
return reply(app.Publish(seq, rev, b))
}
func configure(_ js.Value, args []js.Value) any {
if app == nil {
return reply(fmt.Errorf("GPU preview is not started"))
}
if len(args) != 1 || args[0].Type() != js.TypeString || len(args[0].String()) > 4096 {
return reply(fmt.Errorf("invalid preview configuration"))
}
o := gpupreview.DefaultOptions()
d := json.NewDecoder(strings.NewReader(args[0].String()))
d.DisallowUnknownFields()
if err := d.Decode(&o); err != nil {
return reply(err)
}
if err := d.Decode(new(any)); err != io.EOF {
return reply(fmt.Errorf("trailing preview configuration"))
}
return reply(app.Configure(o))
}
func main() {
api := js.Global().Get("Object").New()
for _, f := range []struct {
name string
run func(js.Value, []js.Value) any
}{
{"start", start}, {"publish", publish}, {"configure", configure},
{"restartParticles", func(js.Value, []js.Value) any {
if app == nil {
return reply(fmt.Errorf("GPU preview is not started"))
}
return reply(app.RestartParticles())
}},
{"status", func(js.Value, []js.Value) any { return reply(nil) }},
{"resources", func(js.Value, []js.Value) any {
if app == nil {
return "{}"
}
b, _ := json.Marshal(app.Resources())
return string(b)
}},
{"contextLoss", func(_ js.Value, args []js.Value) any {
if app == nil || len(args) != 1 || args[0].Type() != js.TypeBoolean {
return false
}
return app.ContextLoss(args[0].Bool())
}},
{"close", func(js.Value, []js.Value) any {
if app != nil {
app.Close()
app = nil
}
return reply(nil)
}},
} {
fn := js.FuncOf(f.run)
callbacks = append(callbacks, fn)
api.Set(f.name, fn)
}
js.Global().Set("aegoArtPreview", api)
select {}
}