Skip to content

armgit / raea

Public Imported from GitHub
0

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.

TL13a: a sequence retimed live: the stage's props carry __raeaSequences (each named Sequence's from and length), which a Sequence takes over its own until the file it was written into opens again. domReads listens for raea-props in both runtimes (lite hands its bridge's addEventListener over as __raeaListen, since its entry gives domReads none). raea-feed b7e1514 sends them as an edit is let go and seeks a paused stage again so it draws them (set_props on a paused stage isn't drawn until something steps it, an engine gap); 16 edits on the stage in raea's window by 88 ms (median of sound upper bounds that each count a capture's ~78 ms read back), the playhead held through each reopening

shinyobjectzb95a9fab6350
diff --git a/sdk/raea/src/dom-reads.ts b/sdk/raea/src/dom-reads.ts
index eda0df70..58c4d618 100644
--- a/sdk/raea/src/dom-reads.ts
+++ b/sdk/raea/src/dom-reads.ts
@@ -12,6 +12,7 @@ import { domSvgText } from "./dom-svgtext";
import { domObservers } from "./dom-observers";
import { domTree } from "./dom-tree";
import { boxOf, type Box } from "./page-layout";
+import { retime } from "@raea/video/timeline";
/** The web's DOMRect, as getBoundingClientRect answers it. */
export class DOMRect {
@@ -63,7 +64,12 @@ const inline = (b: Box) => b.inline;
/** A ref's DOM, from the entry, given bevy-react's exports: LR3's geometry, LR4's tree and LR5's style on its BevyElement and
* BevyTextNode, and LR7's document and window (raea's patch; a bridge without it has none, and refs stay plain handles). */
-export function domReads(bevy: { BevyElement?: { prototype: object }; BevyTextNode?: { prototype: object }; containerNode?: unknown }): void {
+export function domReads(bevy: { BevyElement?: { prototype: object }; BevyTextNode?: { prototype: object }; containerNode?: unknown; addEventListener?: (name: string, cb: (v: unknown) => void) => unknown }): void {
+ // (the one call the entry makes with the bridge's exports, so here too:) the stage's props as they're set, their
+ // sequences retimed by name (`__raeaSequences`: a timeline's edit shown before its file is opened again, TL13a).
+ // Lite's entry hands the nodes instead: its runtime leaves the bridge's listener on globalThis (lite parts/root.ts)
+ const listen = bevy.addEventListener ?? (globalThis as { __raeaListen?: typeof bevy.addEventListener }).__raeaListen;
+ listen?.("raea-props", (v) => retime((v as { __raeaSequences?: unknown } | null)?.__raeaSequences));
geometry(bevy.BevyElement);
domTree(bevy.BevyElement, bevy.BevyTextNode);
domStyle(bevy.BevyElement);
diff --git a/sdk/react/js/lite/parts/root.ts b/sdk/react/js/lite/parts/root.ts
index ac219b08..65260e4b 100644
--- a/sdk/react/js/lite/parts/root.ts
+++ b/sdk/react/js/lite/parts/root.ts
@@ -1,7 +1,11 @@
// The root, and React's default export.
-import { flush, ROOT_ID } from "../../node_modules/bevy-react/src/bridge";
+import { addEventListener, flush, ROOT_ID } from "../../node_modules/bevy-react/src/bridge";
import { Children, Component, Fragment, Instance, Out, PRUNE_EVERY, ROOT_SLOT, S, children, cloneElement, createContext, createElement, effectsQueue, forwardRef, isValidElement, memo, prune, render, startTransition, sweep, unsee, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, useTransition, version } from "./all";
+// the bridge's events for the SDK's own listeners: React's entry hands the SDK bevy-react's exports (sdk/raea
+// dom-reads.ts domReads), lite's hands it the nodes, so the SDK finds them here (a timeline's retimed sequences, TL13a)
+(globalThis as { __raeaListen?: typeof addEventListener }).__raeaListen = addEventListener;
+
// ---- the root
const rootInstance: Instance = { fn: null, hooks: [], effects: [], cleanups: new Map(), kids: new Map(), seen: true, id: ROOT_SLOT, parent: null, el: null, inText: false, out: null, reads: null, codes: null, stale: false, misses: 0, cool: 0, sites: null, stamp: 0 };
diff --git a/sdk/video/src/timeline.tsx b/sdk/video/src/timeline.tsx
index da40ecfb..43a73cf2 100644
--- a/sdk/video/src/timeline.tsx
+++ b/sdk/video/src/timeline.tsx
@@ -122,9 +122,26 @@ function useStableTime(frame: number, origin: number, width: number, height: num
return (r.current = { frame, origin, width, height, duration });
}
+/** Sequences retimed as the piece plays, by their `name`: a timeline's edit on the stage before the file it wrote is
+ * opened again (docs/timeline.feature TL13a). Their `from` and `durationInFrames` here stand over the written ones. */
+const retimed = new Map<string, { from: number; durationInFrames: number }>();
+
+/** The sequences retimed now, by name (none: all as written). What the stage's props carry as `__raeaSequences`. */
+export function retime(by: unknown): void {
+ retimed.clear();
+ if (!by || typeof by !== "object") return;
+ for (const [name, t] of Object.entries(by as Record<string, { from?: unknown; durationInFrames?: unknown }>)) {
+ const from = Number(t?.from), durationInFrames = Number(t?.durationInFrames);
+ if (Number.isFinite(from) && Number.isInteger(durationInFrames) && durationInFrames >= 0) retimed.set(name, { from, durationInFrames });
+ }
+}
+
/** Shifts time by `from` and shows its children only for `durationInFrames` frames. */
export function Sequence(props: SequenceProps) {
- const { from = 0, durationInFrames = Infinity, name, layout = "absolute-fill", width, height, style, className } = props;
+ // (looked up only while something is retimed: a game renders hundreds of sound cues a frame)
+ const over = retimed.size && props.name !== undefined ? retimed.get(props.name) : undefined;
+ const { from = 0, durationInFrames = Infinity } = over ?? props;
+ const { name, layout = "absolute-fill", width, height, style, className } = props;
checkFinite("Sequence", "from", from);
checkDuration("Sequence", durationInFrames);
const parent = useLocalTime("Sequence");