@volter/editor-game 0.5.65 → 0.5.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/contributions/audio-unlock.service.ts +2 -2
  2. package/contributions/autoplay.service.ts +1 -1
  3. package/contributions/bridge.command.ts +3 -3
  4. package/contributions/canvas/component-board.service.ts +16 -0
  5. package/contributions/canvas/design-time-mount.service.ts +45 -0
  6. package/contributions/canvas-story-capture.service.ts +12 -0
  7. package/contributions/edit-mode-audio.service.ts +2 -2
  8. package/contributions/edit-mode-networking.service.ts +1 -1
  9. package/contributions/gameplay.command.ts +4 -4
  10. package/contributions/generation.service.ts +3 -3
  11. package/contributions/generations.status.tsx +1 -1
  12. package/contributions/godot.palette.json +99 -0
  13. package/contributions/godot.style.ts +82 -0
  14. package/contributions/godot.view.ts +75 -0
  15. package/contributions/ingest.service.ts +4 -4
  16. package/contributions/instances.command.ts +1 -1
  17. package/contributions/navmesh.menu.ts +1 -1
  18. package/contributions/network-observer.service.ts +14 -0
  19. package/contributions/play.command.ts +11 -5
  20. package/contributions/react/component-board.service.ts +1 -1
  21. package/contributions/react/design-time-mount.service.ts +1 -1
  22. package/contributions/react/react-inspector.service.ts +2 -2
  23. package/contributions/scene-document.service.ts +5 -5
  24. package/contributions/state-watch.menu.ts +1 -1
  25. package/contributions/state-watch.utility.tsx +1 -1
  26. package/contributions/team-playtest.service.ts +4 -4
  27. package/contributions/three/component-board.service.ts +1 -1
  28. package/contributions/three/component-verbs.command.ts +8 -8
  29. package/contributions/three/three-authoring.service.ts +8 -5
  30. package/contributions/three-story-capture.service.ts +12 -0
  31. package/contributions/unity.palette.json +102 -0
  32. package/contributions/unity.style.ts +72 -0
  33. package/contributions/unity.view.ts +82 -0
  34. package/contributions/unreal.palette.json +105 -0
  35. package/contributions/unreal.style.ts +66 -0
  36. package/contributions/unreal.view.ts +93 -0
  37. package/dist-node/serving.mjs +16 -0
  38. package/package.json +33 -16
  39. package/serving/index.ts +27 -0
  40. package/src/asset-budget/AssetBudgetPanel.tsx +1 -1
  41. package/src/asset-budget/asset-budget-model.ts +4 -4
  42. package/src/asset-budget/optimize-apply.ts +7 -7
  43. package/src/audio/AudioDebuggerPanel.tsx +1 -1
  44. package/src/bridge/dispatch.ts +16 -16
  45. package/src/bridge/live-frames.ts +1 -1
  46. package/src/bridge/screenshot.ts +6 -6
  47. package/src/build/BuildProfilesPanel.tsx +3 -3
  48. package/src/canvas/canvas-board/CanvasBoardDocument.tsx +676 -0
  49. package/src/canvas/canvas-board/canvas-board-model.ts +407 -0
  50. package/src/canvas/canvas-board/canvas-component-board.ts +56 -0
  51. package/src/canvas/canvas-design-mount.ts +524 -0
  52. package/src/canvas/design-time-canvas-mount.ts +79 -0
  53. package/src/coverage/live-authoring-surface.ts +6 -6
  54. package/src/coverage/live-project-verbs.ts +2 -2
  55. package/src/coverage/native-system-coverage.ts +6 -6
  56. package/src/coverage/root-coverage.ts +1 -1
  57. package/src/coverage/session-coverage.ts +5 -5
  58. package/src/design-system-stories/ApplicationChrome.stories.tsx +5 -5
  59. package/src/design-system-stories/InspectorNarrowBodies.stories.tsx +13 -53
  60. package/src/edit-mode/edit-mode-audio.ts +4 -4
  61. package/src/edit-mode/edit-mode-networking.ts +2 -2
  62. package/src/game-document/GameCaptureFrameButton.tsx +2 -2
  63. package/src/game-document/GameDocument.tsx +2 -2
  64. package/src/game-document/GamePanel.tsx +8 -8
  65. package/src/game-document/InstanceInspectorPicker.tsx +2 -2
  66. package/src/game-document/crowd-debug.ts +1 -1
  67. package/src/game-document/device-preview.ts +10 -11
  68. package/src/game-document/physics-debug.ts +1 -1
  69. package/src/generation/GenerationActivity.tsx +6 -8
  70. package/src/generation/generation-documents.tsx +8 -8
  71. package/src/generation/generation-jobs.ts +2 -2
  72. package/src/generation/generation-presentation.ts +1 -1
  73. package/src/host/adapter-reach.ts +1 -1
  74. package/src/host/adapter-runtime-bindings.ts +97 -6
  75. package/src/host/api/configurations.ts +2 -2
  76. package/src/host/authoring/babylon-authoring-adapter.ts +8 -8
  77. package/src/host/authoring/contract-hierarchy-authoring.ts +1 -1
  78. package/src/host/authoring/contract-scenes-stories.ts +1 -1
  79. package/src/host/authoring/creation-site-related.ts +2 -2
  80. package/src/host/authoring/ephemeral-persistence.ts +1 -1
  81. package/src/host/authoring/gesture-persist.ts +2 -2
  82. package/src/host/authoring/ingest-data-writer.ts +1 -1
  83. package/src/host/authoring/ingest-source-persistence.ts +8 -8
  84. package/src/host/authoring/mount-isolated-pixi-screen.ts +1 -1
  85. package/src/host/authoring/mounted-authoring.ts +4 -4
  86. package/src/host/authoring/phaser-live-authoring-adapter.ts +4 -4
  87. package/src/host/authoring/pixi-authoring-adapter.ts +42 -17
  88. package/src/host/authoring/pixi-creation-site-write-target.ts +2 -2
  89. package/src/host/authoring/pixi-live-write-target.ts +7 -7
  90. package/src/host/authoring/pixi-source-identity.ts +3 -3
  91. package/src/host/authoring/pixi-source-write-target.ts +1614 -0
  92. package/src/host/authoring/pixi-still-presentation.ts +2 -2
  93. package/src/host/authoring/pixi-structure-history.ts +3 -3
  94. package/src/host/authoring/pixi-transform-channels.ts +16 -14
  95. package/src/host/authoring/source-persistence-backend.ts +6 -6
  96. package/src/host/authoring/struct-write-pipe.ts +3 -3
  97. package/src/host/binding-resolver.ts +8 -9
  98. package/src/host/browser-transpile.ts +2 -2
  99. package/src/host/canvas-entry-runtime.ts +59 -48
  100. package/src/host/canvas-preview-frames.ts +482 -0
  101. package/src/host/components/CameraAuthoringOverlay.tsx +1 -1
  102. package/src/host/components/HeaderTelemetry.tsx +9 -16
  103. package/src/host/components/PixiIsolationSceneContent.tsx +17 -16
  104. package/src/host/components/ThreeIsolationSceneContent.tsx +5 -5
  105. package/src/host/components/frame-debugger-model.ts +2 -2
  106. package/src/host/components/header-telemetry-model.ts +2 -2
  107. package/src/host/components/scene-document.tsx +29 -61
  108. package/src/host/components/utility-view-state.ts +1 -1
  109. package/src/host/components/world-root-stage-binding.tsx +17 -26
  110. package/src/host/components/world-root-stage.ts +130 -63
  111. package/src/host/coverage/capability-coverage.ts +13 -1
  112. package/src/host/coverage/game-contract-seam-evidence.ts +1 -1
  113. package/src/host/coverage/project-verb-coverage.ts +2 -17
  114. package/src/host/coverage/system-adapter-coverage.ts +4 -5
  115. package/src/host/design-system-stories/fixtures/editor-runtime.tsx +14 -8
  116. package/src/host/document-preview-three.ts +2 -2
  117. package/src/host/entry-adjudication.ts +6 -6
  118. package/src/host/game-css-scope-transform.ts +4 -0
  119. package/src/host/game-module-access.ts +1 -1
  120. package/src/host/game-realm-page.ts +16 -8
  121. package/src/host/game-realm-reclaim.ts +1 -1
  122. package/src/host/gameplay-export.ts +25 -14
  123. package/src/host/gameplay-recording.ts +5 -5
  124. package/src/host/gated-globals.ts +6 -6
  125. package/src/host/history/json-history-resource.ts +3 -3
  126. package/src/host/instance-extract-actions.ts +1 -1
  127. package/src/host/instance-fork-actions.ts +1 -1
  128. package/src/host/projection/dom.ts +2 -2
  129. package/src/host/projection/pixi.ts +25 -3
  130. package/src/host/r3f-entry-runtime.ts +65 -34
  131. package/src/host/react-mount-runtime.ts +8 -49
  132. package/src/host/realm-services.ts +2 -2
  133. package/src/host/roots/canvas-root.tsx +361 -0
  134. package/src/host/roots/module-root.ts +1 -1
  135. package/src/host/roots/r3f-root.tsx +473 -0
  136. package/src/host/roots/react-root.ts +9 -43
  137. package/src/host/scene-view-drawability.ts +2 -2
  138. package/src/host/served-bundle-runtime-modules.ts +1 -19
  139. package/src/host/server-log-bridge.ts +3 -3
  140. package/src/host/stories/mounted-story-viewport-source.ts +1 -1
  141. package/src/host/stories/pixi-story-model.ts +30 -0
  142. package/src/host/stories/story-media-captures.ts +46 -0
  143. package/src/host/stories/story-media-presence.ts +3 -3
  144. package/src/host/stories/story-pixi-preview.ts +408 -0
  145. package/src/host/stories/story-three-preview.ts +806 -0
  146. package/src/host/stories/three-story-captures.ts +35 -0
  147. package/src/host/story-three-preview-runtime.ts +56 -0
  148. package/src/host/three-ingest-runtime.ts +1 -1
  149. package/src/host/use-active-performance-source.ts +3 -3
  150. package/src/host/viewport-pose-memory.ts +1 -1
  151. package/src/host/viewport-root-presentation.ts +6 -5
  152. package/src/ingest/active-ingest.ts +2 -2
  153. package/src/ingest/authoring/ingest-dom-surface-authoring.ts +4 -4
  154. package/src/ingest/authoring/ingest-root-adapter.ts +13 -13
  155. package/src/ingest/capture-wait-report.ts +1 -1
  156. package/src/ingest/deferred-ingest-play.ts +11 -10
  157. package/src/ingest/discovery-public-ingest.ts +2 -2
  158. package/src/ingest/ingest-boot-viewport.ts +6 -8
  159. package/src/ingest/ingest-canvas-scene-document.tsx +17 -16
  160. package/src/ingest/ingest-canvas-scene.ts +5 -8
  161. package/src/ingest/ingest-evidence-hook.ts +1 -1
  162. package/src/ingest/ingest-frame-snapshot.ts +1 -1
  163. package/src/ingest/ingest-play-control.ts +4 -4
  164. package/src/ingest/ingest-render-debug.ts +11 -11
  165. package/src/ingest/ingest-siblings.ts +16 -28
  166. package/src/ingest/module-mode.ts +18 -19
  167. package/src/ingest/mount-canvas-ingest-root.ts +27 -27
  168. package/src/ingest/mount-coverage.ts +4 -4
  169. package/src/ingest/mount-dom-ingest-root.ts +16 -16
  170. package/src/ingest/mount-ingest-root.ts +14 -14
  171. package/src/ingest/mount-three-ingest-root.ts +12 -12
  172. package/src/ingest/resolve-canvas.ts +1 -1
  173. package/src/ingest/served-html-boot.ts +1 -1
  174. package/src/ingest/surface-canvas.ts +1 -1
  175. package/src/ingest/unmount-ingest-root.ts +7 -7
  176. package/src/navmesh/navmesh-handler.ts +24 -16
  177. package/src/network/NetworkInspectorPanel.tsx +449 -14
  178. package/src/network/network-inspector-model.ts +14 -2
  179. package/src/play/play-log-events.ts +1 -1
  180. package/src/play/play-mode.ts +99 -142
  181. package/src/play/play-recording.ts +2 -2
  182. package/src/play/react-play-live-authoring.ts +3 -3
  183. package/src/play/run-selection.ts +93 -0
  184. package/src/play-bar/PlayBar.tsx +20 -39
  185. package/src/profiler/FrameDebuggerPanel.tsx +1 -1
  186. package/src/profiler/PerformancePanel.tsx +4 -4
  187. package/src/react/design-time-react-mount.ts +37 -85
  188. package/src/react/dom-authoring-adapter.ts +11 -11
  189. package/src/react/react-inspector-section.tsx +13 -13
  190. package/src/react/react-world-authoring-adapter.ts +31 -143
  191. package/src/react/story-documents/story-documents.tsx +18 -22
  192. package/src/react/ui-board-document.tsx +10 -11
  193. package/src/react/ui-component-board.ts +5 -5
  194. package/src/runtime/adapter/audio-meter.ts +21 -0
  195. package/src/runtime/adapter/first-party-audio-system.ts +230 -0
  196. package/src/runtime/adapter/ingest/contract-debug-adapter.ts +114 -0
  197. package/src/runtime/adapter/ingest/contract-system-adapters.ts +256 -0
  198. package/src/runtime/adapter/ingest/merge-debug-adapters.ts +197 -0
  199. package/src/runtime/adapter/ingest/observation-debug-adapter.ts +162 -0
  200. package/src/runtime/adapter/ingest/upstream-pin.ts +51 -0
  201. package/src/runtime/adapter/native-debug-module.ts +498 -0
  202. package/src/runtime/audio/bus-mixer.ts +161 -0
  203. package/src/runtime/audio/pose-guard.ts +80 -0
  204. package/src/runtime/core/frame-pacing.ts +126 -0
  205. package/src/runtime/core/game-loop.ts +225 -0
  206. package/src/runtime/core/game-scoped-slot.ts +28 -0
  207. package/src/runtime/core/seeded-random.ts +162 -0
  208. package/src/runtime/core/sim-clock.ts +391 -0
  209. package/src/runtime/core/system-runner.ts +269 -0
  210. package/src/runtime/core/types.ts +104 -0
  211. package/src/runtime/create-runtime.ts +1128 -0
  212. package/src/runtime/debug-bridge.ts +570 -0
  213. package/src/runtime/debug-registry.ts +899 -0
  214. package/src/runtime/dev/chrome-trace.ts +153 -0
  215. package/src/runtime/dev/instruments.ts +403 -0
  216. package/src/runtime/dev/logger.ts +119 -0
  217. package/src/runtime/dev/performance-profiler.ts +367 -0
  218. package/src/runtime/dev/register-render-vitals.ts +276 -0
  219. package/src/runtime/dev/render-census.ts +354 -0
  220. package/src/runtime/dev/render-debug-adapter.ts +218 -0
  221. package/src/runtime/dev/render-memory.ts +226 -0
  222. package/src/runtime/dev/render-vitals.ts +338 -0
  223. package/src/runtime/dev/static-batch-advisor.ts +188 -0
  224. package/src/runtime/dev/webgl-frame-capture.ts +366 -0
  225. package/src/runtime/dev/webgl-gpu-timer.ts +53 -0
  226. package/src/runtime/dev-build.ts +47 -0
  227. package/src/runtime/game.ts +1636 -0
  228. package/src/runtime/gameplay-rng-trap.ts +135 -0
  229. package/src/runtime/host-context.ts +64 -0
  230. package/src/runtime/input-router.ts +169 -0
  231. package/src/runtime/mount-manifest.ts +480 -0
  232. package/src/runtime/pixi/authoring.ts +706 -0
  233. package/src/runtime/pixi/ingest.ts +116 -0
  234. package/src/runtime/pixi/physics-registry.ts +49 -0
  235. package/src/runtime/pixi/render-pass-bracket.ts +117 -0
  236. package/src/runtime/pixi/scene-capture.ts +179 -0
  237. package/src/runtime/pixi/system-adapters.ts +69 -0
  238. package/src/runtime/playtest.ts +22 -0
  239. package/src/runtime/presentation.ts +141 -0
  240. package/src/runtime/render-control.ts +642 -0
  241. package/src/runtime/render-seed.ts +77 -0
  242. package/src/runtime/run-ticks-settled.ts +73 -0
  243. package/src/runtime/setup/setup-audio.ts +72 -0
  244. package/src/services/audio-pose-guard.ts +2 -2
  245. package/src/services/game-audio.ts +152 -0
  246. package/src/services/game-network.ts +657 -0
  247. package/src/services/game-physics.ts +334 -0
  248. package/src/state-watch/StateWatchPanel.tsx +1 -1
  249. package/src/three/authoring/camera-runtime-inspector-section.tsx +4 -3
  250. package/src/three/authoring/constraint-inspector-section.tsx +8 -7
  251. package/src/three/authoring/model-asset-inspector-section.tsx +14 -17
  252. package/src/three/authoring/oid-source-persistence.ts +13 -13
  253. package/src/three/authoring/r3f-design-session.ts +79 -61
  254. package/src/three/authoring/r3f-source-authoring-adapter.ts +112 -108
  255. package/src/three/authoring/reflection-probe-inspector-section.tsx +5 -4
  256. package/src/three/authoring/spatial-joint-handles.ts +1 -1
  257. package/src/three/authoring/spatial-lod-handles.ts +1 -1
  258. package/src/three/authoring/spatial-particle-handles.ts +1 -1
  259. package/src/three/authoring/three-authoring-adapter.ts +33 -33
  260. package/src/three/component-verbs/extract-menu.ts +8 -7
  261. package/src/three/component-verbs/fork-menu.ts +8 -7
  262. package/src/three/component-verbs/internals-menu.ts +3 -3
  263. package/src/three/drei-asset-caches.ts +13 -0
  264. package/src/three/story-documents/three-story-documents.tsx +24 -34
  265. package/src/three/three-board/ThreeBoardDocument.tsx +25 -25
  266. package/src/three/three-board/board-scene.ts +7 -7
  267. package/src/three/three-board/three-component-board.ts +5 -5
  268. package/contributions/react/pasteboard.action.ts +0 -41
  269. package/contributions/xstate-behavior.action.ts +0 -42
  270. package/contributions/xstate-behavior.document.tsx +0 -73
  271. package/contributions/xstate-behavior.inspector.tsx +0 -28
  272. package/contributions/xstate-behavior.menu.ts +0 -23
  273. package/src/react/pasteboard-materialize.ts +0 -154
  274. package/src/services/game-audio-unlock.ts +0 -48
  275. package/src/xstate/XStateBehaviorSection.tsx +0 -130
  276. package/src/xstate/XStateMachineInspector.tsx +0 -566
  277. package/src/xstate/character-animation-machine.fixture.ts +0 -74
  278. package/src/xstate/live-behaviors.ts +0 -106
  279. package/src/xstate/use-live-actor-state.ts +0 -44
  280. package/src/xstate/xstate-graph.ts +0 -235
  281. package/src/xstate/xstate-layout.ts +0 -76
@@ -0,0 +1,642 @@
1
+ /**
2
+ * Render-control runtime seam (I2). This is the harness a deterministic-capture host
3
+ * (Playwright/CDP, I0/I3/I4) drives: exact-time seeks against the canonical
4
+ * `AnimationClock` (`animation/animation-clock.ts`), and single `preRender`+`render`
5
+ * phase passes across every world on a `Game` (`runtime/game.ts`) — WITHOUT ever
6
+ * advancing gameplay fixed-step substeps
7
+ * (`input`/`prePhysics`/`physics`/`postPhysics`/`gameLogic`/`animation` are never
8
+ * invoked by this seam; `--simulate` (I5) is a different, later, path that
9
+ * deliberately drives `game.runFrame(fixedDt)` instead).
10
+ *
11
+ * This module does NOT reuse `PlayState.step()` (`Game.play.step()`) — that
12
+ * surface only advances the currently-FROZEN (paused) set of roots and is a
13
+ * whole-call no-op while unpaused (see its doc comment in `runtime/game.ts`);
14
+ * the spec review explicitly flagged it as the wrong seam. `renderOnce`
15
+ * instead walks `game.roots` directly and calls each world's own
16
+ * `RootFrameHooks.runPhase` for exactly two phases.
17
+ *
18
+ * Also does NOT install anything by default — a caller must explicitly call
19
+ * {@link installRenderControlHarness}, and even then it only actually
20
+ * publishes `window.__vgaiRender` when the page's URL opts in via
21
+ * `?vgai-render=1` (AC 4: unavailable/protected in normal production
22
+ * gameplay unless explicitly enabled). See `render-seed.ts` for the
23
+ * matching `Math.random` determinism hardening, which must run BEFORE this
24
+ * module (or any other game module) is even imported.
25
+ *
26
+ * I5 (`--simulate` render, §15 I5) is implemented HERE, alongside `renderOnce`:
27
+ * {@link VgaiRenderHarness.simulateSubsteps} drives `game.runFrame(fixedDt)` a
28
+ * fixed integer number of times — the FULL fixed-step gameplay frame (every
29
+ * phase in `PHASE_ORDER`, including `physics`/`gameLogic`/`animation`), unlike
30
+ * `renderOnce`'s deliberately gameplay-free `preRender`+`render`-only pass.
31
+ * A caller that never invokes `simulateSubsteps` (the default, sequence-
32
+ * controlled render — I4) gets byte-identical behavior to before this method
33
+ * existed: `renderOnce`/`seek`/`seekFrame`/`advanceFrame` are untouched by
34
+ * this addition.
35
+ */
36
+
37
+ import { SystemPhase } from './core/types';
38
+ import type { Game, GameInternal, RootFrameHooks } from './game';
39
+ import { RENDER_MODE_QUERY_PARAM } from './render-seed';
40
+
41
+ /** Per-subsystem readiness verdict (I2 AC: "Runtime reports asset, shader,
42
+ * font, sequence, Tone, and scene readiness"). `not-applicable` is the
43
+ * correct answer for any subsystem genuinely absent from a given fixture
44
+ * (spec note: "If a subsystem isn't present in the fixture, report it as
45
+ * not-applicable rather than failing") — never coerced to `ready`. */
46
+ export type ReadinessStatus = 'ready' | 'not-applicable' | 'error';
47
+
48
+ export interface ReadinessEntry {
49
+ readonly status: ReadinessStatus;
50
+ readonly detail?: string;
51
+ }
52
+
53
+ /** The full readiness report `ready()` resolves. One entry per subsystem
54
+ * named in the I2 AC, always present (never a sparse/optional object) so a
55
+ * caller can read every key unconditionally. */
56
+ export interface ReadinessReport {
57
+ readonly assets: ReadinessEntry;
58
+ readonly shaders: ReadinessEntry;
59
+ readonly fonts: ReadinessEntry;
60
+ readonly sequences: ReadinessEntry;
61
+ readonly tone: ReadinessEntry;
62
+ readonly scene: ReadinessEntry;
63
+ }
64
+
65
+ /**
66
+ * Caller-supplied per-subsystem readiness checks. Each hook is optional:
67
+ * absence means that subsystem genuinely does not exist in this fixture/game
68
+ * (reported `not-applicable`), NOT that it's assumed ready. A hook that
69
+ * resolves is `ready`; one that throws/rejects is `error` with the message
70
+ * captured (never silently swallowed, never escalated to fail the whole
71
+ * `ready()` call — one subsystem's failure must not hide the others' status).
72
+ * `fonts` has no hook slot: it is always checked directly against
73
+ * `document.fonts.ready` (universally meaningful in a browser render page),
74
+ * matching the AC's explicit `document.fonts.ready` callout.
75
+ */
76
+ export interface RenderReadinessHooks {
77
+ assets?(): Promise<void> | void;
78
+ shaders?(): Promise<void> | void;
79
+ sequences?(): Promise<void> | void;
80
+ tone?(): Promise<void> | void;
81
+ scene?(): Promise<void> | void;
82
+ }
83
+
84
+ /** The minimal clock surface this seam drives — `AnimationClock`'s `seek`/
85
+ * `seekFrame` (`animation/animation-clock.ts`). Typed narrowly (not
86
+ * imported as a value) so this module never depends on the clock's full
87
+ * surface, just the two methods the render seam actually calls. */
88
+ export interface SeekableClock {
89
+ seek(t: number): unknown;
90
+ seekFrame(n: number, fps: number): unknown;
91
+ }
92
+
93
+ /**
94
+ * I8 render-integration seam: a per-frame, fixed-`dt` advance hook — exactly
95
+ * the engine's `SystemFn` shape (`core/types.ts`) — for a
96
+ * cinematic-participating system whose live-gameplay driver `renderOnce()`
97
+ * deliberately bypasses. The motivating case is `bindXStateAnimation`'s
98
+ * `tick` (`animation/xstate-animation-binding.ts`, E2): in live play it
99
+ * rides the fixed-step `'animation'` phase
100
+ * (`ctx.systems.add(SystemPhase.ANIMATION, binding.tick)`), but
101
+ * `renderOnce()` (I2) runs ONLY `preRender`+`render` — the `'animation'`
102
+ * phase, along with every other gameplay phase, is never touched by design
103
+ * (see this module's top doc comment). Without a distinct advance hook, an
104
+ * `AnimationMixer` driven this way would sit frozen for the entire render:
105
+ * nothing would ever call `mixer.update(dt)`. `advanceFrame` (below) is that
106
+ * hook — a small, explicit registry of `FrameAdvancer`s a render-mode page
107
+ * opts into via {@link RenderControlHarnessOptions.frameAdvancers}, invoked
108
+ * in registration order.
109
+ */
110
+ export type FrameAdvancer = (dt: number) => void;
111
+
112
+ /** The `window.__vgaiRender` surface (I2 AC, extended by I8's `advanceFrame`).
113
+ * Every method here is synchronous except the two that genuinely need to
114
+ * wait on the browser (composited render completion, async readiness
115
+ * probes). */
116
+ export interface VgaiRenderHarness {
117
+ /** Evaluate every registered sequence/cinematic-participating evaluator at
118
+ * exact time `t` (seconds) via `clock.seek(t)` — never advances gameplay
119
+ * substeps. Synchronous: the clock's subscribed evaluators run inline,
120
+ * before this call returns. */
121
+ seek(t: number): void;
122
+ /** Exact-frame variant — `clock.seekFrame(n, fps)`, i.e. `start + n/fps`,
123
+ * bit-exact and drift-free across repeated calls. Same no-substep
124
+ * semantics as {@link seek}. */
125
+ seekFrame(n: number, fps: number): void;
126
+ /**
127
+ * I8 render-integration seam: advance every registered
128
+ * {@link FrameAdvancer} (e.g. an XState/`AnimationMixer` binding's `tick`)
129
+ * by exactly `dt` seconds, in registration order. A render-mode capture
130
+ * loop calls this ONCE per OUTPUT frame, with `dt = 1 / fps`, BEFORE
131
+ * `seekFrame`/`renderOnce` for that frame — see
132
+ * `packages/vgai-sdk/src/render/render-cinematic.ts`'s `captureFrames`, which
133
+ * drives exactly this sequence. `advanceFrame` is a genuinely
134
+ * FORWARD-ONLY, INCREMENTAL tick (it has no notion of "time" to seek
135
+ * to — it only knows "advance by `dt` more") — unlike {@link seek}/
136
+ * {@link seekFrame}, which are absolute and idempotent, calling
137
+ * `advanceFrame` twice never undoes or re-derives a prior call, it always
138
+ * accumulates. This composes correctly with I4's default sequence-
139
+ * controlled render (and I8's reference cinematic) specifically BECAUSE
140
+ * that capture loop only ever walks output frames monotonically forward
141
+ * (`n = 0, 1, 2, ...`); it is NOT safe to call from a scrubber/editor
142
+ * preview that seeks backward or re-visits a frame — a caller that needs
143
+ * that (a future `--simulate`/preview seam) must not reuse this hook as-is.
144
+ * A no-op when no advancers are registered (the default), so this method
145
+ * is always present and always safe to call even for a fixture with
146
+ * nothing to advance (e.g. the I0 `render-cinematic` fixture).
147
+ */
148
+ advanceFrame(dt: number): void;
149
+ /** Runs exactly one `preRender`+`render` phase pass across every
150
+ * host-driven world on the `Game` (z-order is a DOM/canvas-stacking
151
+ * concern already handled by `create-runtime.ts`'s surface stack — this
152
+ * call does not need to reorder anything to composite correctly), then
153
+ * resolves after a double-`requestAnimationFrame` composition fence. */
154
+ renderOnce(): Promise<void>;
155
+ /** Resolves once every declared subsystem has reported in (see
156
+ * {@link ReadinessReport}). */
157
+ ready(): Promise<ReadinessReport>;
158
+ /**
159
+ * I5 `--simulate` seam: advance the FULL fixed-step gameplay frame
160
+ * (`game.runFrame(fixedDt)` — every phase in `PHASE_ORDER`: input,
161
+ * prePhysics, physics, postPhysics, gameLogic, animation, preRender,
162
+ * render) exactly `steps` times, synchronously, in a tight loop. This is
163
+ * what makes physics/gameplay/AI/particles/participating-audio evolve
164
+ * BETWEEN captured output frames under `--simulate` — every real gameplay
165
+ * phase runs, unlike {@link renderOnce} (which runs ONLY `preRender`+
166
+ * `render`, by design, for the I4 sequence-controlled default) or
167
+ * {@link advanceFrame} (which ticks only registered {@link FrameAdvancer}s,
168
+ * never a gameplay phase).
169
+ *
170
+ * `fixedDt` is fixed for the lifetime of this harness (see
171
+ * {@link RenderControlHarnessOptions.simulateFixedDt}, default `1/60` —
172
+ * the same fixed timestep every real host's `createGameLoop` config
173
+ * uses) — callers choose HOW MANY substeps to run per captured frame
174
+ * (`steps`), not the substep's own `dt`, matching the I5 AC's "a fixed
175
+ * integer number of times per output frame" wording exactly.
176
+ *
177
+ * A capture loop that wants BOTH a warmup period (I5 AC: "simulation
178
+ * state can warm up before the capture range") and per-frame substeps
179
+ * calls this twice: once with the warmup step count before frame 0, then
180
+ * once per captured frame with the per-frame step count — there is no
181
+ * separate "warmup" method, because warmup is just simulateSubsteps called
182
+ * before the capture loop starts (see `render-cinematic.ts`'s
183
+ * `captureFrames`, which drives exactly this sequence for `--simulate`
184
+ * requests).
185
+ */
186
+ simulateSubsteps(steps: number): void;
187
+ /**
188
+ * I5 AC 5 ("the render report names every subsystem excluded from
189
+ * deterministic participation"): every subsystem NOT participating in
190
+ * deterministic capture, computed fresh on every call from two sources —
191
+ * (1) `RenderControlHarnessOptions.excludedFromDeterminism`, a static,
192
+ * page-declared list (e.g. "live Colyseus networking", "non-seeded ambient
193
+ * audio") this fixture/game names about itself, and (2) any world this
194
+ * seam itself could not frame-gate (a `drivesOwnLoop` world, or a
195
+ * host-driven world with no `RootFrameHooks` — the SAME two conditions
196
+ * {@link renderOnce}'s `renderableRoots` skips, described here as policy
197
+ * rather than merely warned about once to the console). Declared entries
198
+ * come first, in declaration order; world-exclusion entries follow, in
199
+ * `game.roots` declaration order.
200
+ */
201
+ excludedFromDeterminism(): string[];
202
+ /**
203
+ * I7 fold-in (I5 nit): the ACTUAL fixed substep `dt` (seconds) this
204
+ * harness passes to every `game.runFrame(fixedDt)` call inside
205
+ * {@link simulateSubsteps} — i.e. `RenderControlHarnessOptions.simulateFixedDt`,
206
+ * resolved with its own `1/60` default already applied. Exists so the
207
+ * render pipeline (`render-cinematic.ts`'s `RenderManifestSimulate
208
+ * .fixedTimestep`) can report the REAL value a fixture is using instead of
209
+ * assuming every fixture matches the harness's own default — a fixture
210
+ * that configures a different `simulateFixedDt` (a different Rapier/
211
+ * physics substep) now shows up correctly in the render manifest rather
212
+ * than a silently wrong hardcoded `1/60`.
213
+ */
214
+ simulateFixedDt(): number;
215
+ /**
216
+ * W3d (F11 perf regression gates) — the `vgai perf` sampling seam. Runs
217
+ * exactly `steps` FULL fixed-step gameplay frames (the same
218
+ * `game.runFrame(fixedDt)` path {@link simulateSubsteps} drives — every
219
+ * phase in `PHASE_ORDER`, including `render`, so `renderer.info`-backed
220
+ * draw/triangle counters populate per frame) with the game's OWN
221
+ * `PerformanceProfiler` (`dev/performance-profiler.ts`) enabled, sampling
222
+ * it after every frame, then restores the profiler's prior enabled state.
223
+ * Returns per-frame CPU/phase timings + render counters, plus a
224
+ * structural node/entity count of every three/canvas world's live scene
225
+ * graph. NOT a parallel instrumentation layer: every number here comes
226
+ * from the existing profiler (timings, render counters) or the live world
227
+ * roots themselves (counts).
228
+ *
229
+ * Honesty notes, recorded here because this seam is what `vgai perf`
230
+ * reports: `gpuMs` is whatever the profiler's render reporter measured —
231
+ * `null` under headless SwiftShader (no usable GPU timer), never a
232
+ * fabricated 0; CPU timings include the profiler's own (small) phase
233
+ * bookkeeping, inherent to profiling; warmup belongs OUTSIDE this call
234
+ * (drive {@link simulateSubsteps} first — profiler disabled, zero
235
+ * overhead).
236
+ */
237
+ perfSample(steps: number): PerfSampleReport;
238
+ }
239
+
240
+ /** One measured fixed-step frame from {@link VgaiRenderHarness.perfSample}. */
241
+ export interface PerfFrameSample {
242
+ /** CPU time (ms) for the whole `runFrame` pass (profiler `cpuMs`). */
243
+ readonly cpuMs: number;
244
+ /** Per-phase CPU ms (profiler phase timings), keyed by phase name. */
245
+ readonly phases: Readonly<Record<string, number>>;
246
+ /** Renderer counters reported during this frame's `render` phase
247
+ * (`profiler.reportRender` — renderer.info). All zeros/null for a world
248
+ * whose adapter never reports render stats. */
249
+ readonly render: {
250
+ readonly gpuMs: number | null;
251
+ readonly drawCalls: number;
252
+ readonly triangles: number;
253
+ readonly geometries: number;
254
+ readonly textures: number;
255
+ };
256
+ }
257
+
258
+ /** Per-world structural counts from {@link VgaiRenderHarness.perfSample}. */
259
+ export interface PerfRootCount {
260
+ readonly id: string;
261
+ readonly kind: string;
262
+ /** Total scene-graph descendants of the world root (exclusive of the root
263
+ * itself). Exact and deterministic under a seed. */
264
+ readonly nodes: number;
265
+ /** Descendants carrying `userData.entityId` (the loader/editor entity
266
+ * tag). 0 for a hand-built world that tags nothing — an honest count of
267
+ * tagged nodes, not a guess at "entities". */
268
+ readonly entities: number;
269
+ }
270
+
271
+ export interface PerfSampleReport {
272
+ readonly frames: readonly PerfFrameSample[];
273
+ /** three/canvas worlds only — a react/DOM world has no scene-graph node
274
+ * count; it is omitted rather than fabricated. */
275
+ readonly worlds: readonly PerfRootCount[];
276
+ }
277
+
278
+ export interface RenderControlHarnessOptions {
279
+ /**
280
+ * `GameInternal` (not just the game-facing `Game`) — this harness is
281
+ * itself a host (the render/capture driver), and I5's
282
+ * {@link VgaiRenderHarness.simulateSubsteps} needs the host-only
283
+ * `runFrame` surface (`runtime/game.ts`'s `GameInternal.runFrame` doc
284
+ * comment: "the host loop ... and `GameSession.step()` are the only
285
+ * callers"). Every real call site already holds a `GameInternal` (the
286
+ * direct return of `createGame(...)`), so this is not a new construction
287
+ * requirement, just a narrower declared type than before I5.
288
+ */
289
+ readonly game: GameInternal;
290
+ readonly clock: SeekableClock;
291
+ readonly readiness?: RenderReadinessHooks;
292
+ /** Where to publish the harness. Defaults to the real `window` — override
293
+ * in a unit test to avoid touching the global object. */
294
+ readonly target?: Record<string, unknown>;
295
+ /** Where to read `?vgai-render=1` from. Defaults to `window.location`. */
296
+ readonly location?: { readonly search: string };
297
+ /** I8 render-integration seam — see {@link VgaiRenderHarness.advanceFrame}.
298
+ * Zero or more `FrameAdvancer`s invoked, in array order, on every
299
+ * `harness.advanceFrame(dt)` call. Default `[]` (no-op), which is exactly
300
+ * what a fixture with nothing gameplay-phase-driven (e.g. I0's fixture)
301
+ * needs — `advanceFrame` is still present on the harness, it just has
302
+ * nothing to do. */
303
+ readonly frameAdvancers?: readonly FrameAdvancer[];
304
+ /**
305
+ * I5 `--simulate` seam: the fixed substep `dt` (seconds)
306
+ * {@link VgaiRenderHarness.simulateSubsteps} passes to every
307
+ * `game.runFrame(fixedDt)` call. Default `1/60` — the same fixed timestep
308
+ * every real host's `createGameLoop` config uses (`create-runtime.ts`), so
309
+ * a `--simulate` fixture's Rapier world (whose own `integrationParameters.dt`
310
+ * defaults to `1/60`) stays in lockstep with the gameplay substep unless a
311
+ * fixture deliberately configures both to a different, still-matching,
312
+ * value.
313
+ */
314
+ readonly simulateFixedDt?: number;
315
+ /**
316
+ * I5 AC 5 — see {@link VgaiRenderHarness.excludedFromDeterminism}. A
317
+ * static, page-declared list of subsystems this fixture/game has that do
318
+ * NOT participate in deterministic capture (e.g. live networking,
319
+ * non-seeded ambient audio) — named here as an explicit, reviewable
320
+ * policy rather than silently dropped. Default `[]` (nothing to declare —
321
+ * correct for a fixture with no such subsystem).
322
+ */
323
+ readonly excludedFromDeterminism?: readonly string[];
324
+ }
325
+
326
+ /** Shared by {@link installRenderControlHarness} and any caller that wants
327
+ * to check the opt-in flag before doing render-mode-only setup work (e.g.
328
+ * `render-seed.ts`'s own gate uses the same query param name). */
329
+ export function isRenderModeRequested(location: { readonly search: string }): boolean {
330
+ return new URLSearchParams(location.search).get(RENDER_MODE_QUERY_PARAM) === '1';
331
+ }
332
+
333
+ const RENDER_ONLY_PHASES = [SystemPhase.PRE_RENDER, SystemPhase.RENDER] as const;
334
+
335
+ /**
336
+ * Run exactly one `preRender`+`render` phase pass across every host-driven
337
+ * (`!drivesOwnLoop`) world on `game`, then await the GPU/DOM composition
338
+ * fence. This is the ENTIRE frame this call drives — no `input`,
339
+ * `prePhysics`, `physics`, `postPhysics`, `gameLogic`, or `animation` phase
340
+ * is ever touched, which is what makes this safe to call from a paused-or-
341
+ * stopped clock without silently ticking gameplay. Phases are run as global
342
+ * barriers across roots (mirroring `GameInternal.runFrame`'s own phase-then-
343
+ * world nesting in `runtime/game.ts`): every world's `preRender` runs before
344
+ * any world's `render`, in `game.roots` declaration order.
345
+ *
346
+ * Ordering within a phase mirrors `GameInternal.runFrame` EXACTLY (see its
347
+ * doc comment in `runtime/game.ts`): the game-scoped `SystemRunner`
348
+ * (`game.systems`) runs FIRST, before any world's frame hooks. `game.systems`
349
+ * is empty for every game today (nothing registers against it yet), so this
350
+ * is a no-op in practice — but a later slice that registers a Game-scoped
351
+ * `preRender`/`render` system (e.g. a cinematic camera crossfade that must
352
+ * paint once per captured frame) would otherwise be silently MISSED by
353
+ * capture while running fine in live playback, since live playback goes
354
+ * through `runFrame`. Running it here keeps the seam a faithful subset of
355
+ * `runFrame`'s phase pass, not a divergent one.
356
+ *
357
+ * A `drivesOwnLoop` world (self-driven, raw-rAF) has no phase hooks this
358
+ * seam can drive — it is skipped with a loud, once-per-call warning rather
359
+ * than silently omitted, mirroring this file's "fail loudly, never a silent
360
+ * no-op" convention. A host-driven world with no `frame` (an opaque/foreign
361
+ * mount) is skipped the same way — there is no phase hook to call. Both
362
+ * checks happen ONCE, up front (see {@link renderableRoots}), not per
363
+ * phase — a world unrenderable in `preRender` is unrenderable in `render`
364
+ * too, so warning twice would just be noise.
365
+ */
366
+ async function renderOnce(game: Game): Promise<void> {
367
+ const roots = renderableRoots(game);
368
+ for (const phase of RENDER_ONLY_PHASES) {
369
+ // Game-scoped systems first, then per-world frame hooks — the SAME order
370
+ // GameInternal.runFrame uses (runtime/game.ts). See doc comment above.
371
+ game.systems.runPhase(phase, 0);
372
+ for (const world of roots) {
373
+ world.frame.runPhase(phase, 0);
374
+ }
375
+ }
376
+ await compositionFence();
377
+ }
378
+
379
+ interface RenderableRoot {
380
+ readonly id: string;
381
+ readonly frame: RootFrameHooks;
382
+ }
383
+
384
+ /** Filter `game.roots` down to the ones {@link renderOnce} can actually
385
+ * drive (host-driven, with real `RootFrameHooks`) — see that function's
386
+ * doc comment for why an excluded world is warned about loudly, not
387
+ * silently dropped. */
388
+ function renderableRoots(game: Game): RenderableRoot[] {
389
+ const result: RenderableRoot[] = [];
390
+ for (const world of game.roots) {
391
+ if (world.mounted.drivesOwnLoop) {
392
+ warnUnrenderable(world.id, 'drives its own loop — renderOnce() cannot frame-gate it');
393
+ continue;
394
+ }
395
+ if (!world.frame) {
396
+ warnUnrenderable(
397
+ world.id,
398
+ `(kind: ${world.kind}) has no phase hooks — renderOnce() cannot drive it (opaque/foreign ` +
399
+ 'mount with no frame-gated entry point)',
400
+ );
401
+ continue;
402
+ }
403
+ result.push({ id: world.id, frame: world.frame });
404
+ }
405
+ return result;
406
+ }
407
+
408
+ function warnUnrenderable(worldLabel: string, reason: string): void {
409
+ // biome-ignore lint/suspicious/noConsole: structured, greppable — mirrors runtime/game.ts's own direct console.warn idiom for "cannot gate this world" capability shortfalls.
410
+ console.warn(`[render-control] world "${worldLabel}" ${reason}.`);
411
+ }
412
+
413
+ /**
414
+ * I5 AC 5 policy text for the two conditions {@link renderableRoots} skips —
415
+ * shared so {@link VgaiRenderHarness.excludedFromDeterminism} names the SAME
416
+ * roots `renderOnce()` warns about, in the SAME words, rather than
417
+ * maintaining a second, driftable description of the same two checks.
418
+ */
419
+ function computeRootExclusionReasons(game: Game): string[] {
420
+ const reasons: string[] = [];
421
+ for (const world of game.roots) {
422
+ if (world.mounted.drivesOwnLoop) {
423
+ reasons.push(
424
+ `world "${world.id}" drives its own loop — cannot be frame-gated for deterministic ` +
425
+ 'capture (the policy is to FAIL LOUDLY, or be excluded only by an explicit declared ' +
426
+ 'policy).',
427
+ );
428
+ continue;
429
+ }
430
+ if (!world.frame) {
431
+ reasons.push(
432
+ `world "${world.id}" (kind: ${world.kind}) has no phase hooks — an opaque/foreign mount ` +
433
+ 'with no frame-gated entry point cannot participate in deterministic capture.',
434
+ );
435
+ }
436
+ }
437
+ return reasons;
438
+ }
439
+
440
+ /** Structural scene-graph walk shared by three (`Object3D`) and canvas
441
+ * (`Container`) roots — both expose a `children` array, and three nodes
442
+ * additionally carry `userData` (where the loader/editor entity tag lives).
443
+ * Deliberately duck-typed so this file keeps its type-only three/pixi rule. */
444
+ function countRootGraph(root: { readonly children?: readonly unknown[] }): {
445
+ nodes: number;
446
+ entities: number;
447
+ } {
448
+ let nodes = 0;
449
+ let entities = 0;
450
+ const stack: unknown[] = [...(root.children ?? [])];
451
+ while (stack.length > 0) {
452
+ const node = stack.pop() as {
453
+ readonly children?: readonly unknown[];
454
+ readonly userData?: Record<string, unknown>;
455
+ };
456
+ nodes++;
457
+ if (node.userData?.['entityId'] !== undefined) entities++;
458
+ if (node.children) stack.push(...node.children);
459
+ }
460
+ return { nodes, entities };
461
+ }
462
+
463
+ /** See {@link PerfSampleReport.worlds} — three/canvas worlds only; a
464
+ * react/DOM world has no scene-graph node count and is omitted, never
465
+ * fabricated. */
466
+ function countRoots(game: Game): PerfRootCount[] {
467
+ const counts: PerfRootCount[] = [];
468
+ for (const world of game.roots) {
469
+ if (world.kind === 'three') {
470
+ counts.push({ id: world.id, kind: world.kind, ...countRootGraph(world.threeScene()) });
471
+ } else if (world.kind === 'canvas') {
472
+ // Node counting is a substrate projection, not a surface fact. Pixi's
473
+ // native tree exposes `children`; other canvas substrates are omitted
474
+ // until their adapter declares an honest counter.
475
+ if (world.mounted.kind === 'canvas' && world.mounted.substrate.name === 'pixi') {
476
+ counts.push({ id: world.id, kind: world.kind, ...countRootGraph(world.canvasRoot()) });
477
+ }
478
+ }
479
+ }
480
+ return counts;
481
+ }
482
+
483
+ function nextAnimationFrame(): Promise<void> {
484
+ return new Promise((resolve) => {
485
+ requestAnimationFrame(() => resolve());
486
+ });
487
+ }
488
+
489
+ /**
490
+ * GPU/DOM composition fence (I2 AC: "waits for GPU/DOM composition
491
+ * (double-rAF fence ... ) rather than an arbitrary sleep"). Two nested
492
+ * `requestAnimationFrame` callbacks: the first fires once the browser has
493
+ * scheduled a new frame after our `render()` calls above; the second fires
494
+ * once THAT frame has itself been produced and composited — by the time the
495
+ * second callback runs, the compositor has committed the frame our render
496
+ * calls painted, so a screenshot taken immediately after this resolves
497
+ * reflects the seeked state, not a stale one. (The CDP screenshot
498
+ * compositor-commit wait itself is the capture host's job — I0/I3 — this
499
+ * fence is the runtime-side half.)
500
+ */
501
+ async function compositionFence(): Promise<void> {
502
+ await nextAnimationFrame();
503
+ await nextAnimationFrame();
504
+ }
505
+
506
+ async function resolveHook(
507
+ hook: (() => Promise<void> | void) | undefined,
508
+ ): Promise<ReadinessEntry> {
509
+ if (!hook) return { status: 'not-applicable' };
510
+ try {
511
+ await hook();
512
+ return { status: 'ready' };
513
+ } catch (err) {
514
+ return { status: 'error', detail: err instanceof Error ? err.message : String(err) };
515
+ }
516
+ }
517
+
518
+ async function checkFontsReady(): Promise<ReadinessEntry> {
519
+ if (typeof document === 'undefined' || !document.fonts) return { status: 'not-applicable' };
520
+ try {
521
+ await document.fonts.ready;
522
+ return { status: 'ready' };
523
+ } catch (err) {
524
+ return { status: 'error', detail: err instanceof Error ? err.message : String(err) };
525
+ }
526
+ }
527
+
528
+ async function buildReadinessReport(hooks: RenderReadinessHooks): Promise<ReadinessReport> {
529
+ const [assets, shaders, fonts, sequences, tone, scene] = await Promise.all([
530
+ resolveHook(hooks.assets),
531
+ resolveHook(hooks.shaders),
532
+ checkFontsReady(),
533
+ resolveHook(hooks.sequences),
534
+ resolveHook(hooks.tone),
535
+ resolveHook(hooks.scene),
536
+ ]);
537
+ return { assets, shaders, fonts, sequences, tone, scene };
538
+ }
539
+
540
+ /**
541
+ * Build (and, when render mode is actually requested, publish) the
542
+ * `window.__vgaiRender` harness. AC 4 — production protection — lives HERE,
543
+ * not just at the call site: even if a host application calls this
544
+ * unconditionally on every boot, the harness is only ever constructed *and*
545
+ * attached to `target` when `isRenderModeRequested(location)` is true;
546
+ * otherwise this is a no-op that returns `undefined`. A normal production
547
+ * gameplay page therefore never gets `window.__vgaiRender` no matter how
548
+ * this function is wired into its entry point.
549
+ */
550
+ export function installRenderControlHarness(
551
+ opts: RenderControlHarnessOptions,
552
+ ): VgaiRenderHarness | undefined {
553
+ const location = opts.location ?? window.location;
554
+ if (!isRenderModeRequested(location)) return undefined;
555
+
556
+ const { game, clock, readiness = {} } = opts;
557
+ const target = opts.target ?? (window as unknown as Record<string, unknown>);
558
+ const frameAdvancers = opts.frameAdvancers ?? [];
559
+ const simulateFixedDt = opts.simulateFixedDt ?? 1 / 60;
560
+ const declaredExclusions = opts.excludedFromDeterminism ?? [];
561
+
562
+ const harness: VgaiRenderHarness = {
563
+ seek(t: number): void {
564
+ clock.seek(t);
565
+ },
566
+ seekFrame(n: number, fps: number): void {
567
+ clock.seekFrame(n, fps);
568
+ },
569
+ advanceFrame(dt: number): void {
570
+ for (const advancer of frameAdvancers) advancer(dt);
571
+ },
572
+ renderOnce(): Promise<void> {
573
+ return renderOnce(game);
574
+ },
575
+ ready(): Promise<ReadinessReport> {
576
+ return buildReadinessReport(readiness);
577
+ },
578
+ simulateSubsteps(steps: number): void {
579
+ for (let i = 0; i < steps; i++) {
580
+ game.runFrame(simulateFixedDt);
581
+ }
582
+ },
583
+ excludedFromDeterminism(): string[] {
584
+ return [...declaredExclusions, ...computeRootExclusionReasons(game)];
585
+ },
586
+ simulateFixedDt(): number {
587
+ return simulateFixedDt;
588
+ },
589
+ perfSample(steps: number): PerfSampleReport {
590
+ const profiler = game.profiler;
591
+ const wasEnabled = profiler.enabled;
592
+ profiler.enabled = true;
593
+ profiler.clear();
594
+ const frames: PerfFrameSample[] = [];
595
+ try {
596
+ for (let i = 0; i < steps; i++) {
597
+ game.runFrame(simulateFixedDt);
598
+ const snapshot = profiler.getSnapshot();
599
+ const latest = snapshot.frames.at(-1);
600
+ frames.push({
601
+ cpuMs: latest?.cpuMs ?? 0,
602
+ phases: Object.fromEntries((latest?.phases ?? []).map((p) => [p.name, p.ms])),
603
+ render: { ...snapshot.render },
604
+ });
605
+ }
606
+ } finally {
607
+ profiler.enabled = wasEnabled;
608
+ }
609
+ return { frames, worlds: countRoots(game) };
610
+ },
611
+ };
612
+
613
+ target['__vgaiRender'] = harness;
614
+ return harness;
615
+ }
616
+
617
+ /**
618
+ * Defensive assertion for the I2 AC "Pixi roots are pinned to the WebGL
619
+ * renderer (not WebGPU) in render mode". In THIS engine that invariant
620
+ * already holds unconditionally — no in-repo mount constructs a Pixi
621
+ * `Application` with a WebGPU preference, and `setup/setup-renderer.ts` never
622
+ * constructs a `WebGPURenderer` for three roots either — so there is no
623
+ * live WebGPU code path for a first-party render-mode page to disable.
624
+ * This helper exists for a render-mode installer that mounts a CUSTOM/
625
+ * foreign pixi adapter (`create-runtime.ts`'s `{ module }` pixi path) this
626
+ * engine did not construct itself, to assert the invariant against the
627
+ * live mounted renderer rather than merely trusting it. Duck-typed against
628
+ * pixi.js v8's numeric `RendererType` (`WEBGL = 1`, `WEBGPU = 2`,
629
+ * `CANVAS = 4`) so this file never value-imports `pixi.js` (the same
630
+ * type-only-pixi rule `runtime/game.ts`/`create-runtime.ts` document for
631
+ * themselves).
632
+ */
633
+ export function assertPixiRootIsWebGL(rendererType: unknown, worldId: string): void {
634
+ const isWebGPU =
635
+ rendererType === 2 || (typeof rendererType === 'string' && /webgpu/i.test(rendererType));
636
+ if (isWebGPU) {
637
+ throw new Error(
638
+ `[render-control] world "${worldId}": Pixi renderer is WebGPU in render mode — ` +
639
+ 'render-control requires WebGL.',
640
+ );
641
+ }
642
+ }