Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
H12: what reached an app screen in a play is logged and rendered again; exported games bundle app screens as apps
shinyobjectz3cd7f72b4bf4
diff --git a/apps/game/src/export.rs b/apps/game/src/export.rsindex 37ba8fd0..647266a8 100644--- a/apps/game/src/export.rs+++ b/apps/game/src/export.rs@@ -101,10 +101,7 @@ pub fn export(args: &[String]) -> R<String> {gather(&mut bundle, &dir, &game, &mut got)?;std::fs::write(&js, &bundle).map_err(|e| e.to_string())?;- // an app screen needs a player with the surface runtime (the `surfaces` feature), which the size-built one leaves out- if got.files.iter().any(|(rel, _)| rel.ends_with(raea_runtime_page::screen::BUNDLED)) && !player_has_surfaces(&player)? {- return Err(format!("this game has an app screen (<Screen app>), and the player {} can't run one: build it with them (cargo build --profile game -p raea-app-game --bin raea-game --features player,surfaces) and export again", player.display()));- }+ // an app screen (<Screen app>) draws on the player's own Blitz page (raea-runtime-appscreen): every player has one// 3. what play works out at open, worked out now from the package itself (so the package is known to load)let src = std::fs::read_to_string(&tsx).unwrap_or_default();@@ -255,12 +252,6 @@ pub(crate) fn imported(dir: &Path, file: &Path) -> bool {false}-/// Whether the player at `bin` was built with the surface runtime (app screens): its shim's text is in it.-pub(crate) fn player_has_surfaces(bin: &Path) -> R<bool> {- let bytes = std::fs::read(bin).map_err(|e| format!("{}: {e}", bin.display()))?;- Ok(bytes.windows(14).any(|w| w == b"__surfaceFrame"))-}-pub(crate) fn default_name(tsx: &Path) -> String {let stem = tsx.file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default();let base = if stem == "edit" { tsx.parent().and_then(|p| p.file_name()).map(|s| s.to_string_lossy().to_string()).unwrap_or(stem) } else { stem };diff --git a/apps/game/src/gather.rs b/apps/game/src/gather.rsindex a67533dc..510f4642 100644--- a/apps/game/src/gather.rs+++ b/apps/game/src/gather.rs@@ -105,13 +105,21 @@ pub(crate) fn gather(bundle: &mut String, dir: &Path, game: &Path, got: &mut Gatlet ext = file.extension().and_then(|x| x.to_str()).unwrap_or("").to_ascii_lowercase();if SOURCE_EXTS.contains(&ext.as_str()) || file.file_name().is_some_and(|n| n == MANIFEST) {// an app screen's module (`<Screen app="chat.tsx">`, a component on react-dom): bundled now with its npm- // packages beside where it was, as `chat.tsx.surface.js`, which the player opens (it bundles nothing)+ // packages beside where it was, as `chat.tsx.surface.js` and its CSS `chat.tsx.surface.css`, which the+ // player opens (it bundles nothing; raea-runtime-appscreen code_of)if matches!(ext.as_str(), "tsx" | "jsx") && std::fs::read_to_string(&file).is_ok_and(|t| t.contains("export default") && !t.contains("registerRoot(")) && !imported(dir, &file) {if let Some(rel) = inside(&file) {- let rel = format!("{rel}{}", raea_runtime_page::screen::BUNDLED);- if !got.has(&rel) {- raea_runtime_react::scene::bundle_surface(&file, &game.join(&rel))?;- got.files.push((rel, file.clone()));+ let (js_rel, css_rel) = (format!("{rel}{}", raea_runtime_page::screen::BUNDLED), format!("{rel}{}", raea_runtime_page::screen::BUNDLED_CSS));+ if !got.has(&js_rel) {+ let (js, css) = raea_runtime_page::screen::build_app(&file)?;+ for (r, text) in [(&js_rel, js), (&css_rel, css)] {+ let out = game.join(r);+ if let Some(d) = out.parent() {+ std::fs::create_dir_all(d).map_err(|e| format!("{}: {e}", d.display()))?;+ }+ std::fs::write(&out, text).map_err(|e| format!("{}: {e}", out.display()))?;+ got.files.push((r.clone(), file.clone()));+ }}}}diff --git a/apps/play/src/offscreen.rs b/apps/play/src/offscreen.rsindex f5062c93..d3163422 100644--- a/apps/play/src/offscreen.rs+++ b/apps/play/src/offscreen.rs@@ -237,6 +237,10 @@ pub(crate) fn offscreen(mut run: Run, json: Option<String>, flat_out: bool, snapif let Some((x, y, down)) = run.pointer {e["pointer"] = serde_json::json!({"x": x, "y": y, "down": down});}+ // what reached its app screens (the keys they took aren't the page's above), given them again in a render+ if let Some(apps) = live.app_input() {+ e["apps"] = apps;+ }// the session's seed and start with its first frame: a render of the log draws the same Math.random and Dateif logged.is_empty() {e["session"] = live.session();diff --git a/runtime/export/src/render.rs b/runtime/export/src/render.rsindex dfb65c64..05554466 100644--- a/runtime/export/src/render.rs+++ b/runtime/export/src/render.rs@@ -35,6 +35,10 @@ pub fn render(args: &[String]) -> R<String> {// the edit's words.json and perception.json beside it, as play loads them (a render without the flags lost the// captions its words drive; the corpus found 10 edits so); a flag still winslet mut o = comp_opts(args)?;+ // an input log's `apps`, what reached the app screens in the play it came from, given them again frame by frame+ // (docs/blitz-bevy.feature H12): the render draws what was played+ let apps: std::collections::BTreeMap<i64, serde_json::Value> = o.input.as_ref().and_then(|v| v.as_object()).into_iter().flatten().filter_map(|(f, v)| Some((f.parse().ok()?, v.get("apps")?.clone()))).collect();+ *raea_runtime_page::screen::APP_LOG.lock().unwrap() = (!apps.is_empty()).then_some(apps);for (slot, file) in [(&mut o.words, "words.json"), (&mut o.perception, "perception.json")] {if slot.is_none() && dir.join(file).exists() {let v = json_file(&dir.join(file).display().to_string())?;diff --git a/runtime/live/src/lib.rs b/runtime/live/src/lib.rsindex 93bfc77d..572e7f1f 100644--- a/runtime/live/src/lib.rs+++ b/runtime/live/src/lib.rs@@ -58,6 +58,9 @@ pub struct Live {frame: i64,/// the gamepads' marked keys the last frame was given beside its input ("Pad0:South"), for its input logpads: Vec<String>,+ /// the keys an app screen took from the last frame (the page didn't get them), left out of its input log, which+ /// keeps them under `apps` (`app_input`)+ taken: Vec<String>,/// the pointer on the page's elements, as the last frame left it (pointer.rs)pointer: pointer::PagePointer,/// generated sounds' files, by what they were made from (looked up once)@@ -202,6 +205,9 @@ impl Live {self.lag = (lag, std::time::Instant::now());self.frame = f;self.pads.clear();+ self.taken.clear();+ // the app screens step to this frame at the page's next sync (screen.rs step_all)+ self.page.set_app_frame(f, self.fps);let t0 = std::time::Instant::now();if self.baked.is_some() {// a baked timeline: its recorded commits, no JS; the clips it cuts to soon opened ahead; the page styled at@@ -224,6 +230,9 @@ impl Live {Some(e) => Some(raea_runtime_page::screen::route(&mut self.page, e, keys, pointer, (self.w, self.h))),None => None,};+ if let Some(r) = &routed {+ self.taken = keys.iter().filter(|k| !r.contains(k)).cloned().collect();+ }let keys = routed.as_deref().unwrap_or(keys);// the pointer on the page's elements: their on* handlers, before the frame's step (pointer.rs)if let Some(p) = pointer {@@ -389,7 +398,13 @@ impl Live {/// The keys the last frame stepped was given: `keys` and the gamepads marked beside them, as its input log records/// them, so a render of the log gives the game the same pads (bench/render-play's live-gamepad).pub fn played_keys(&self, keys: &[String]) -> Vec<String> {- keys.iter().chain(&self.pads).cloned().collect()+ keys.iter().chain(&self.pads).filter(|k| !self.taken.contains(k)).cloned().collect()+ }++ /// What reached the app screens in the last frame stepped, as its input log keeps it (`apps`): a render of the+ /// log gives them the same (runtime/page/src/screen.rs).+ pub fn app_input(&self) -> Option<serde_json::Value> {+ self.page.app_input()}}diff --git a/runtime/live/src/open.rs b/runtime/live/src/open.rsindex 318a278d..a1940840 100644--- a/runtime/live/src/open.rs+++ b/runtime/live/src/open.rs@@ -65,7 +65,7 @@ impl Live {let (w, h) = if responsive { (stage.0.max(1), stage.1.max(1)) } else { (cw, ch) };let page = raea_runtime_page::BevyPage::new(w, h, &dir)?;let brand = raea_runtime_react::scene::page_css(&dir, w, &js);- let mut live = Live { app, dir: dir.clone(), page, brand, dirty: true, mixer: None, mixer_failed: false, lag: (0.0, std::time::Instant::now()), w, h, fps, frames, responsive, js, master: None, master_wav: None, game_master: None, game_gain: None, scene_rx: None, scene: None, live3d: None, frame: 0, pads: Vec::new(), pointer: Default::default(), made: Default::default(), sound_buf: Vec::new(), holders: Vec::new(), baked: None, applied: -1, session: new_session() };+ let mut live = Live { app, dir: dir.clone(), page, brand, dirty: true, mixer: None, mixer_failed: false, lag: (0.0, std::time::Instant::now()), w, h, fps, frames, responsive, js, master: None, master_wav: None, game_master: None, game_gain: None, scene_rx: None, scene: None, live3d: None, frame: 0, pads: Vec::new(), taken: Vec::new(), pointer: Default::default(), made: Default::default(), sound_buf: Vec::new(), holders: Vec::new(), baked: None, applied: -1, session: new_session() };if responsive {live.send("raea-size", json!({"w": w, "h": h}));}@@ -117,7 +117,7 @@ impl Live {raea_runtime_react::scene::one_thread(&mut app);let page = raea_runtime_page::BevyPage::new(w, h, &dir)?;let brand = raea_runtime_react::scene::page_css(&dir, w, &js);- let mut live = Live { app, dir: dir.clone(), page, brand, dirty: true, mixer: None, mixer_failed: false, lag: (0.0, std::time::Instant::now()), w, h, fps, frames, responsive: false, js, master: None, master_wav: None, game_master: None, game_gain: None, scene_rx: None, scene: None, live3d: None, frame: 0, pads: Vec::new(), pointer: Default::default(), made: Default::default(), sound_buf: Vec::new(), holders: Vec::new(), baked: None, applied: -1, session: new_session() };+ let mut live = Live { app, dir: dir.clone(), page, brand, dirty: true, mixer: None, mixer_failed: false, lag: (0.0, std::time::Instant::now()), w, h, fps, frames, responsive: false, js, master: None, master_wav: None, game_master: None, game_gain: None, scene_rx: None, scene: None, live3d: None, frame: 0, pads: Vec::new(), taken: Vec::new(), pointer: Default::default(), made: Default::default(), sound_buf: Vec::new(), holders: Vec::new(), baked: None, applied: -1, session: new_session() };for b in &baked.init {live.app.world().resource::<raea_runtime_react::ReplayFeed>().feed(b.clone());}