From 2cbfa8c608af2bd30048e29be94cdb63777732bf Mon Sep 17 00:00:00 2001 From: shane Date: Thu, 3 Dec 2026 12:23:00 -0800 Subject: [PATCH] A playable carries Bevy's world as wasm for a game whose rules are raea/ecs systems (#313) PA12: runtime/ecs builds as a cdylib for wasm32 (src/wasm.rs; sdk/playable/ecs/build.sh: 253 KB, 105 KB gzipped, no imports) into sdk/playable/src/host/ecs.wasm, with the hash of what it was built from beside it, which apps/playable's test checks. The lint's walk sees a World made; the export carries the module and its entry loads host/ecs.ts before the game, so raea/ecs's calls (native.ts ecsCall: the engine's bridge, else the page's) reach Bevy's tables in the page as they do in the engine. A page that can't make the module keeps raea/ecs's TypeScript tables. World.copy() is a game's next state (copied with its systems, stepped on its own), and a native store nothing holds frees its world, so a game's let-go states don't keep theirs. examples/playables/star-catch.tsx is a game whose rules are three systems on a World; conformance/ecs-wasm.test.ts runs one world's life on the wasm and on the TypeScript tables and finds them equal. The playable guide shows the pattern. Co-authored-by: shinyobjectz --- apps/playable/src/lib.rs | 75 +++++++++++--- apps/playable/src/lint.rs | 6 +- docs/playables.feature | 11 ++ examples/playables/star-catch.tsx | 143 ++++++++++++++++++++++++++ runtime/ecs/src/lib.rs | 3 + runtime/ecs/src/wasm.rs | 63 ++++++++++++ sdk/app/src/ecs.ts | 71 ++++++++----- sdk/app/src/native.ts | 18 +++- sdk/guides/craft/motion/playable.md | 19 ++++ sdk/playable/ecs/build.sh | 17 +++ sdk/playable/ecs/from.sh | 5 + sdk/playable/src/export/walk.ts | 4 +- sdk/playable/src/host/ecs.ts | 51 +++++++++ sdk/playable/src/host/ecs.wasm | Bin 0 -> 258660 bytes sdk/playable/src/host/ecs.wasm.from | 1 + sdk/playable/tools/check.ts | 4 +- sdk/raea/conformance/ecs-wasm.test.ts | 24 +++++ sdk/raea/conformance/ecs-wasm/run.ts | 44 ++++++++ 18 files changed, 512 insertions(+), 47 deletions(-) create mode 100644 examples/playables/star-catch.tsx create mode 100644 runtime/ecs/src/wasm.rs create mode 100644 sdk/playable/ecs/build.sh create mode 100644 sdk/playable/ecs/from.sh create mode 100644 sdk/playable/src/host/ecs.ts create mode 100644 sdk/playable/src/host/ecs.wasm create mode 100644 sdk/playable/src/host/ecs.wasm.from create mode 100644 sdk/raea/conformance/ecs-wasm.test.ts create mode 100644 sdk/raea/conformance/ecs-wasm/run.ts diff --git a/apps/playable/src/lib.rs b/apps/playable/src/lib.rs index 4dd33df2..7a228544 100644 --- a/apps/playable/src/lib.rs +++ b/apps/playable/src/lib.rs @@ -41,6 +41,14 @@ fn package_dir(game: &Path, home: &Path, name: &str, why: &str, add: &str) -> R< .ok_or_else(|| format!("a playable {why} with {name}, which this project doesn't have: `raea add {add}` in it")) } +/// runtime/ecs as wasm (sdk/playable/ecs/build.sh), base64 +fn ecs_wasm(home: &Path) -> R { + use base64::Engine; + let f = home.join("sdk/playable/src/host/ecs.wasm"); + let b = std::fs::read(&f).map_err(|e| format!("{}: raea/ecs's world as wasm isn't there ({e}): bash sdk/playable/ecs/build.sh", f.display()))?; + Ok(base64::engine::general_purpose::STANDARD.encode(b)) +} + /// What sound a game makes, as the lint found it: none, media only (