@vgai/engine 0.5.21 → 0.5.23

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 (339) hide show
  1. package/README.md +6 -3
  2. package/dist/adapter/adapter-module.d.ts.map +1 -1
  3. package/dist/adapter/adapter-module.js +2 -4
  4. package/dist/adapter/adapter-surface.d.ts +1 -1
  5. package/dist/adapter/adapter-surface.js +1 -1
  6. package/dist/adapter/authoring.d.ts +19 -21
  7. package/dist/adapter/authoring.d.ts.map +1 -1
  8. package/dist/adapter/authoring.js +2 -2
  9. package/dist/adapter/binding.d.ts +341 -0
  10. package/dist/adapter/binding.d.ts.map +1 -0
  11. package/dist/adapter/binding.js +148 -0
  12. package/dist/adapter/colyseus-networking-adapter.d.ts.map +1 -1
  13. package/dist/adapter/colyseus-networking-adapter.js +23 -4
  14. package/dist/adapter/entrypoint-selection-readers.d.ts +24 -0
  15. package/dist/adapter/entrypoint-selection-readers.d.ts.map +1 -0
  16. package/dist/adapter/entrypoint-selection-readers.js +63 -0
  17. package/dist/adapter/entrypoint-selection-source.d.ts.map +1 -1
  18. package/dist/adapter/entrypoint-selection-source.js +1 -44
  19. package/dist/adapter/finders/scenes-from-entrypoint-selection.d.ts.map +1 -1
  20. package/dist/adapter/finders/scenes-from-entrypoint-selection.js +1 -52
  21. package/dist/adapter/host-context.d.ts +46 -15
  22. package/dist/adapter/host-context.d.ts.map +1 -1
  23. package/dist/adapter/host-context.js +2 -9
  24. package/dist/adapter/index.d.ts +11 -12
  25. package/dist/adapter/index.d.ts.map +1 -1
  26. package/dist/adapter/index.js +9 -10
  27. package/dist/adapter/ingest/game-contract.d.ts +0 -3
  28. package/dist/adapter/ingest/game-contract.d.ts.map +1 -1
  29. package/dist/adapter/ingest/game-contract.js +0 -3
  30. package/dist/adapter/ingest/scene-capture.d.ts +19 -23
  31. package/dist/adapter/ingest/scene-capture.d.ts.map +1 -1
  32. package/dist/adapter/ingest/scene-capture.js +143 -17
  33. package/dist/adapter/ingest/visible-capture-window.d.ts +34 -0
  34. package/dist/adapter/ingest/visible-capture-window.d.ts.map +1 -1
  35. package/dist/adapter/manifest-interpreter.d.ts +59 -0
  36. package/dist/adapter/manifest-interpreter.d.ts.map +1 -0
  37. package/dist/adapter/manifest-interpreter.js +50 -0
  38. package/dist/adapter/native-debug-module.d.ts +71 -3
  39. package/dist/adapter/native-debug-module.d.ts.map +1 -1
  40. package/dist/adapter/native-debug-module.js +146 -10
  41. package/dist/adapter/rapier-physics-adapter.d.ts +31 -1
  42. package/dist/adapter/rapier-physics-adapter.d.ts.map +1 -1
  43. package/dist/adapter/rapier-physics-adapter.js +50 -36
  44. package/dist/adapter/renderer-config.d.ts +3 -3
  45. package/dist/adapter/renderer-config.js +3 -3
  46. package/dist/adapter/root-adapter.d.ts +7 -7
  47. package/dist/adapter/root-adapter.js +4 -4
  48. package/dist/adapter/system-adapter.d.ts +45 -7
  49. package/dist/adapter/system-adapter.d.ts.map +1 -1
  50. package/dist/adapter/system-seam-contract.d.ts +3 -3
  51. package/dist/adapter/system-seam-contract.js +3 -3
  52. package/dist/adapter/system-slot.d.ts +168 -0
  53. package/dist/adapter/system-slot.d.ts.map +1 -0
  54. package/dist/adapter/system-slot.js +229 -0
  55. package/dist/adapter/transform.d.ts +11 -1
  56. package/dist/adapter/transform.d.ts.map +1 -1
  57. package/dist/ai/navigation.d.ts +17 -1
  58. package/dist/ai/navigation.d.ts.map +1 -1
  59. package/dist/ai/navigation.js +26 -5
  60. package/dist/animation/anim-graph-types.d.ts +11 -3
  61. package/dist/animation/anim-graph-types.d.ts.map +1 -1
  62. package/dist/animation/theatre-clock-binding.d.ts +4 -4
  63. package/dist/animation/theatre-clock-binding.js +4 -4
  64. package/dist/animation/xstate-animation-binding.d.ts.map +1 -1
  65. package/dist/animation/xstate-animation-binding.js +2 -2
  66. package/dist/animation/xstate-animation-meta.d.ts +13 -0
  67. package/dist/animation/xstate-animation-meta.d.ts.map +1 -1
  68. package/dist/animation/xstate-animation-meta.js +14 -0
  69. package/dist/asset-formats/index.d.ts +4 -7
  70. package/dist/asset-formats/index.d.ts.map +1 -1
  71. package/dist/asset-formats/index.js +4 -7
  72. package/dist/asset-formats/render-env.d.ts +5 -8
  73. package/dist/asset-formats/render-env.d.ts.map +1 -1
  74. package/dist/asset-formats/render-env.js +3 -6
  75. package/dist/asset-parse-error.d.ts +2 -5
  76. package/dist/asset-parse-error.d.ts.map +1 -1
  77. package/dist/asset-parse-error.js +2 -5
  78. package/dist/audio/bus-mixer.d.ts +101 -0
  79. package/dist/audio/bus-mixer.d.ts.map +1 -0
  80. package/dist/audio/bus-mixer.js +115 -0
  81. package/dist/canvas-react/index.d.ts +5 -12
  82. package/dist/canvas-react/index.d.ts.map +1 -1
  83. package/dist/canvas-react/index.js +5 -12
  84. package/dist/canvas-react/pixi-react-root-factory.d.ts +34 -21
  85. package/dist/canvas-react/pixi-react-root-factory.d.ts.map +1 -1
  86. package/dist/canvas-react/pixi-react-root-factory.js +274 -36
  87. package/dist/core/countdown-timer.d.ts +118 -0
  88. package/dist/core/countdown-timer.d.ts.map +1 -0
  89. package/dist/core/countdown-timer.js +137 -0
  90. package/dist/core/deferred-commands.d.ts +127 -0
  91. package/dist/core/deferred-commands.d.ts.map +1 -0
  92. package/dist/core/deferred-commands.js +132 -0
  93. package/dist/core/frame-pacing.d.ts +1 -1
  94. package/dist/core/frame-pacing.js +2 -2
  95. package/dist/core/game-loop.d.ts +1 -3
  96. package/dist/core/game-loop.d.ts.map +1 -1
  97. package/dist/core/game-loop.js +1 -3
  98. package/dist/core/seeded-random.d.ts +1 -1
  99. package/dist/core/sim-clock.d.ts +19 -8
  100. package/dist/core/sim-clock.d.ts.map +1 -1
  101. package/dist/core/sim-clock.js +18 -7
  102. package/dist/core/types.d.ts +1 -3
  103. package/dist/core/types.d.ts.map +1 -1
  104. package/dist/defaults.d.ts +6 -14
  105. package/dist/defaults.d.ts.map +1 -1
  106. package/dist/defaults.js +6 -14
  107. package/dist/dev/instruments.d.ts +38 -11
  108. package/dist/dev/instruments.d.ts.map +1 -1
  109. package/dist/dev/instruments.js +81 -11
  110. package/dist/dev/register-render-vitals.d.ts +1 -4
  111. package/dist/dev/register-render-vitals.d.ts.map +1 -1
  112. package/dist/dev/register-render-vitals.js +1 -4
  113. package/dist/dev/render-debug-adapter.d.ts +2 -3
  114. package/dist/dev/render-debug-adapter.d.ts.map +1 -1
  115. package/dist/dev/render-debug-adapter.js +2 -3
  116. package/dist/dev/render-vitals.d.ts +3 -3
  117. package/dist/dev/render-vitals.js +3 -3
  118. package/dist/dev/webgl-frame-capture.d.ts +1 -1
  119. package/dist/dev/webgl-frame-capture.js +1 -1
  120. package/dist/index.d.ts +2 -5
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +2 -4
  123. package/dist/input/host-pointer.d.ts +122 -0
  124. package/dist/input/host-pointer.d.ts.map +1 -0
  125. package/dist/input/host-pointer.js +160 -0
  126. package/dist/input/input-manager.d.ts +33 -5
  127. package/dist/input/input-manager.d.ts.map +1 -1
  128. package/dist/input/input-manager.js +48 -13
  129. package/dist/input/rebind-controller.d.ts.map +1 -1
  130. package/dist/input/rebind-controller.js +6 -8
  131. package/dist/input/schema.d.ts.map +1 -1
  132. package/dist/input/schema.js +56 -28
  133. package/dist/manifest/filename.d.ts.map +1 -1
  134. package/dist/manifest/filename.js +8 -12
  135. package/dist/manifest/load.d.ts +10 -10
  136. package/dist/manifest/load.d.ts.map +1 -1
  137. package/dist/manifest/load.js +9 -6
  138. package/dist/manifest/schema.d.ts +17 -21
  139. package/dist/manifest/schema.d.ts.map +1 -1
  140. package/dist/manifest/schema.js +45 -35
  141. package/dist/physics/collider-dimensions.d.ts +8 -12
  142. package/dist/physics/collider-dimensions.d.ts.map +1 -1
  143. package/dist/physics/collider-dimensions.js +8 -12
  144. package/dist/pixi/scene-capture.d.ts +11 -13
  145. package/dist/pixi/scene-capture.d.ts.map +1 -1
  146. package/dist/react/world-state.d.ts +1 -1
  147. package/dist/react/world-state.d.ts.map +1 -1
  148. package/dist/render/directional-shadow-fit.d.ts +88 -0
  149. package/dist/render/directional-shadow-fit.d.ts.map +1 -0
  150. package/dist/render/directional-shadow-fit.js +133 -0
  151. package/dist/render/environment-capture.d.ts +68 -0
  152. package/dist/render/environment-capture.d.ts.map +1 -0
  153. package/dist/render/environment-capture.js +90 -0
  154. package/dist/render/ibl-override-material.d.ts +97 -0
  155. package/dist/render/ibl-override-material.d.ts.map +1 -0
  156. package/dist/render/ibl-override-material.js +114 -0
  157. package/dist/render/light-camera-factory.d.ts +5 -7
  158. package/dist/render/light-camera-factory.d.ts.map +1 -1
  159. package/dist/render/light-camera-factory.js +8 -11
  160. package/dist/render/material-factory.js +1 -1
  161. package/dist/render/render-batch-system.d.ts.map +1 -1
  162. package/dist/render/render-features.d.ts +17 -6
  163. package/dist/render/render-features.d.ts.map +1 -1
  164. package/dist/render/render-features.js +0 -28
  165. package/dist/runtime/create-runtime.d.ts +34 -25
  166. package/dist/runtime/create-runtime.d.ts.map +1 -1
  167. package/dist/runtime/create-runtime.js +218 -93
  168. package/dist/runtime/debug-registry.d.ts +77 -8
  169. package/dist/runtime/debug-registry.d.ts.map +1 -1
  170. package/dist/runtime/debug-registry.js +3 -3
  171. package/dist/runtime/dev-build.d.ts +2 -2
  172. package/dist/runtime/dev-build.js +2 -2
  173. package/dist/runtime/game-input-seams.d.ts +51 -0
  174. package/dist/runtime/game-input-seams.d.ts.map +1 -0
  175. package/dist/runtime/game-input-seams.js +86 -0
  176. package/dist/runtime/game.d.ts +104 -40
  177. package/dist/runtime/game.d.ts.map +1 -1
  178. package/dist/runtime/game.js +119 -61
  179. package/dist/runtime/mount-game.d.ts +0 -16
  180. package/dist/runtime/mount-game.d.ts.map +1 -1
  181. package/dist/runtime/mount-game.js +26 -41
  182. package/dist/runtime/mount-manifest.d.ts +22 -14
  183. package/dist/runtime/mount-manifest.d.ts.map +1 -1
  184. package/dist/runtime/mount-manifest.js +22 -20
  185. package/dist/runtime/playtest.d.ts +22 -0
  186. package/dist/runtime/playtest.d.ts.map +1 -0
  187. package/dist/runtime/playtest.js +12 -0
  188. package/dist/runtime/state-bridge.d.ts +2 -3
  189. package/dist/runtime/state-bridge.d.ts.map +1 -1
  190. package/dist/runtime/state-bridge.js +1 -0
  191. package/dist/setup/setup-audio.d.ts +12 -0
  192. package/dist/setup/setup-audio.d.ts.map +1 -1
  193. package/dist/setup/setup-audio.js +9 -10
  194. package/dist/setup/setup-renderer.d.ts +2 -25
  195. package/dist/setup/setup-renderer.d.ts.map +1 -1
  196. package/dist/setup/setup-renderer.js +2 -31
  197. package/dist/world3d-react/index.d.ts +15 -25
  198. package/dist/world3d-react/index.d.ts.map +1 -1
  199. package/dist/world3d-react/index.js +15 -25
  200. package/dist/world3d-react/r3f-root-factory.d.ts +28 -34
  201. package/dist/world3d-react/r3f-root-factory.d.ts.map +1 -1
  202. package/dist/world3d-react/r3f-root-factory.js +403 -57
  203. package/dist/world3d-react/rapier-physics-bridge.d.ts +30 -17
  204. package/dist/world3d-react/rapier-physics-bridge.d.ts.map +1 -1
  205. package/dist/world3d-react/rapier-physics-bridge.js +143 -58
  206. package/package.json +1 -1
  207. package/schemas/engine-capabilities.json +16 -14
  208. package/schemas/vgai-project.schema.json +35 -26
  209. package/src/adapter/adapter-module.ts +2 -4
  210. package/src/adapter/adapter-surface.ts +1 -1
  211. package/src/adapter/authoring.ts +19 -21
  212. package/src/adapter/binding.ts +468 -0
  213. package/src/adapter/colyseus-networking-adapter.ts +20 -5
  214. package/src/adapter/entrypoint-selection-readers.ts +66 -0
  215. package/src/adapter/entrypoint-selection-source.ts +1 -40
  216. package/src/adapter/finders/scenes-from-entrypoint-selection.ts +1 -48
  217. package/src/adapter/host-context.ts +45 -15
  218. package/src/adapter/index.ts +23 -11
  219. package/src/adapter/ingest/game-contract.ts +0 -3
  220. package/src/adapter/ingest/scene-capture.ts +190 -39
  221. package/src/adapter/ingest/visible-capture-window.ts +35 -0
  222. package/src/adapter/manifest-interpreter.ts +64 -0
  223. package/src/adapter/native-debug-module.ts +248 -15
  224. package/src/adapter/rapier-physics-adapter.ts +76 -20
  225. package/src/adapter/renderer-config.ts +3 -3
  226. package/src/adapter/root-adapter.ts +7 -7
  227. package/src/adapter/system-adapter.ts +43 -8
  228. package/src/adapter/system-seam-contract.ts +3 -3
  229. package/src/adapter/system-slot.ts +291 -0
  230. package/src/adapter/transform.ts +18 -1
  231. package/src/ai/navigation.ts +30 -3
  232. package/src/animation/anim-graph-types.ts +11 -3
  233. package/src/animation/theatre-clock-binding.ts +4 -4
  234. package/src/animation/xstate-animation-binding.ts +2 -2
  235. package/src/animation/xstate-animation-meta.ts +16 -0
  236. package/src/asset-formats/index.ts +4 -7
  237. package/src/asset-formats/render-env.ts +3 -6
  238. package/src/asset-parse-error.ts +2 -5
  239. package/src/audio/bus-mixer.ts +161 -0
  240. package/src/canvas-react/index.ts +5 -21
  241. package/src/canvas-react/pixi-react-root-factory.tsx +301 -39
  242. package/src/core/countdown-timer.ts +188 -0
  243. package/src/core/deferred-commands.ts +174 -0
  244. package/src/core/frame-pacing.ts +2 -2
  245. package/src/core/game-loop.ts +1 -3
  246. package/src/core/seeded-random.ts +1 -1
  247. package/src/core/sim-clock.ts +19 -8
  248. package/src/core/types.ts +1 -3
  249. package/src/defaults.ts +6 -14
  250. package/src/dev/instruments.ts +108 -11
  251. package/src/dev/register-render-vitals.ts +1 -4
  252. package/src/dev/render-debug-adapter.ts +2 -3
  253. package/src/dev/render-vitals.ts +3 -3
  254. package/src/dev/webgl-frame-capture.ts +1 -1
  255. package/src/index.ts +2 -5
  256. package/src/input/host-pointer.ts +230 -0
  257. package/src/input/input-manager.ts +49 -13
  258. package/src/input/input-types.ts +1 -1
  259. package/src/input/rebind-controller.ts +6 -8
  260. package/src/input/schema.ts +216 -188
  261. package/src/manifest/filename.ts +8 -12
  262. package/src/manifest/load.ts +17 -13
  263. package/src/manifest/schema.ts +55 -47
  264. package/src/physics/collider-dimensions.ts +8 -12
  265. package/src/pixi/scene-capture.ts +12 -15
  266. package/src/react/world-state.tsx +1 -1
  267. package/src/render/directional-shadow-fit.ts +156 -0
  268. package/src/render/environment-capture.ts +102 -0
  269. package/src/render/ibl-override-material.ts +170 -0
  270. package/src/render/light-camera-factory.ts +8 -11
  271. package/src/render/material-factory.ts +1 -1
  272. package/src/render/render-batch-system.ts +14 -6
  273. package/src/render/render-features.ts +17 -35
  274. package/src/runtime/create-runtime.ts +270 -108
  275. package/src/runtime/debug-registry.ts +84 -8
  276. package/src/runtime/dev-build.ts +2 -2
  277. package/src/runtime/game-input-seams.ts +108 -0
  278. package/src/runtime/game.ts +231 -85
  279. package/src/runtime/mount-game.ts +31 -57
  280. package/src/runtime/mount-manifest.ts +47 -36
  281. package/src/runtime/playtest.ts +22 -0
  282. package/src/runtime/state-bridge.ts +3 -3
  283. package/src/setup/setup-audio.ts +21 -11
  284. package/src/setup/setup-renderer.ts +2 -61
  285. package/src/world3d-react/index.ts +15 -31
  286. package/src/world3d-react/r3f-root-factory.tsx +451 -60
  287. package/src/world3d-react/rapier-physics-bridge.tsx +154 -58
  288. package/dist/adapter/setup-three-root-adapter.d.ts +0 -86
  289. package/dist/adapter/setup-three-root-adapter.d.ts.map +0 -1
  290. package/dist/adapter/setup-three-root-adapter.js +0 -908
  291. package/dist/animation/clip-map.d.ts +0 -12
  292. package/dist/animation/clip-map.d.ts.map +0 -1
  293. package/dist/animation/clip-map.js +0 -31
  294. package/dist/asset-registry.d.ts +0 -38
  295. package/dist/asset-registry.d.ts.map +0 -1
  296. package/dist/asset-registry.js +0 -66
  297. package/dist/canvas-react/engine-bridge.d.ts +0 -45
  298. package/dist/canvas-react/engine-bridge.d.ts.map +0 -1
  299. package/dist/canvas-react/engine-bridge.js +0 -45
  300. package/dist/canvas-react/pixi-react-adapter.d.ts +0 -77
  301. package/dist/canvas-react/pixi-react-adapter.d.ts.map +0 -1
  302. package/dist/canvas-react/pixi-react-adapter.js +0 -294
  303. package/dist/canvas-react/world-context.d.ts +0 -98
  304. package/dist/canvas-react/world-context.d.ts.map +0 -1
  305. package/dist/canvas-react/world-context.js +0 -173
  306. package/dist/dev/debug-draw.d.ts +0 -24
  307. package/dist/dev/debug-draw.d.ts.map +0 -1
  308. package/dist/dev/debug-draw.js +0 -73
  309. package/dist/render/auto-batcher.d.ts +0 -34
  310. package/dist/render/auto-batcher.d.ts.map +0 -1
  311. package/dist/render/auto-batcher.js +0 -140
  312. package/dist/render/lod.d.ts +0 -13
  313. package/dist/render/lod.d.ts.map +0 -1
  314. package/dist/render/lod.js +0 -16
  315. package/dist/runtime/types.d.ts +0 -303
  316. package/dist/runtime/types.d.ts.map +0 -1
  317. package/dist/runtime/types.js +0 -1
  318. package/dist/world3d-react/engine-bridge.d.ts +0 -47
  319. package/dist/world3d-react/engine-bridge.d.ts.map +0 -1
  320. package/dist/world3d-react/engine-bridge.js +0 -73
  321. package/dist/world3d-react/r3f-adapter.d.ts +0 -58
  322. package/dist/world3d-react/r3f-adapter.d.ts.map +0 -1
  323. package/dist/world3d-react/r3f-adapter.js +0 -634
  324. package/dist/world3d-react/world-context.d.ts +0 -182
  325. package/dist/world3d-react/world-context.d.ts.map +0 -1
  326. package/dist/world3d-react/world-context.js +0 -235
  327. package/src/adapter/setup-three-root-adapter.ts +0 -1032
  328. package/src/animation/clip-map.ts +0 -34
  329. package/src/asset-registry.ts +0 -89
  330. package/src/canvas-react/engine-bridge.ts +0 -59
  331. package/src/canvas-react/pixi-react-adapter.tsx +0 -356
  332. package/src/canvas-react/world-context.ts +0 -253
  333. package/src/dev/debug-draw.ts +0 -80
  334. package/src/render/auto-batcher.ts +0 -168
  335. package/src/render/lod.ts +0 -17
  336. package/src/runtime/types.ts +0 -328
  337. package/src/world3d-react/engine-bridge.ts +0 -86
  338. package/src/world3d-react/r3f-adapter.tsx +0 -717
  339. package/src/world3d-react/world-context.ts +0 -358
@@ -1,328 +0,0 @@
1
- import type RAPIER from '@dimforge/rapier3d-compat';
2
- import type { EffectComposer } from 'postprocessing';
3
- import type * as THREE from 'three';
4
- import type { z } from 'zod';
5
- import type { SystemAdapters } from '../adapter/system-adapter';
6
- import type { AssetCache } from '../assets';
7
- import type { SeededRandom } from '../core/seeded-random';
8
- import type { SimClock } from '../core/sim-clock';
9
- import type { createSystemRunner } from '../core/system-runner';
10
- import type { createDebugDraw } from '../dev/debug-draw';
11
- import type { SceneIndex } from '../ecs/scene-index';
12
- import type { InputManager } from '../input/input-manager';
13
- import type { CollisionSystem } from '../physics/collision-system';
14
- import type { PhysicsRegistry } from '../physics/physics-registry';
15
- import type { AudioContext as GameAudio } from '../setup/setup-audio';
16
- import type { ParticlesContext } from '../setup/setup-particles';
17
- import type { Game, RootInstance } from './game';
18
-
19
- /**
20
- * The minimal structural shape `ctx.debug.attachRoom` needs from a joined
21
- * Colyseus room: just enough to send the reserved `__vgai:debugCommand`
22
- * message and listen for its `__vgai:debugCommandResult` reply. Structural,
23
- * not a Colyseus type import — the same seam-boundary style every other
24
- * `DebugCtxSurface` member uses (no wrapper around Colyseus itself, D2).
25
- * `onMessage`'s return type is `unknown` because Colyseus's own return shape
26
- * (void in some client versions, an unsubscribe function in others) isn't
27
- * load-bearing here: the registry calls it defensively (invokes it on detach
28
- * only if it's actually a function).
29
- */
30
- export interface DebugRoomHandle {
31
- send(type: string, message?: unknown): void;
32
- onMessage(type: string, cb: (message: unknown) => void): unknown;
33
- }
34
-
35
- /**
36
- * Infers a `registerCommand`/`registerReactCommand`/`useDebugCommand`
37
- * handler's parameter tuple from its declared Zod `args` tuple (dry-run
38
- * finding, ledger — "`registerCommand` fn typing forces `unknown[]` casts"):
39
- * a real `z.ZodTuple` infers its element types (`z.tuple([z.number(),
40
- * z.string()])` → `(n: number, s: string) => ...`), while omitting `args`
41
- * (the generic's `undefined` default) resolves to the original permissive
42
- * `(...args: unknown[]) => ...` shape every command had before this generic
43
- * existed. That permissive fallback is deliberate, not just a placeholder —
44
- * it keeps every existing no-schema registration (including ones whose
45
- * handler reads positional args the runtime never validates, since
46
- * `invoke()` only parses `args` against a schema when one is declared)
47
- * compiling byte-for-byte unchanged.
48
- */
49
- export type DebugCommandArgs<T extends z.ZodTuple | undefined = undefined> = T extends z.ZodTuple
50
- ? z.infer<T>
51
- : unknown[];
52
-
53
- /**
54
- * The authoring half of the debug/synthetic-player seam — the read/actuate half is
55
- * `SystemAdapters.DebugAdapter` (`adapter/system-adapter.ts`). Callable from any
56
- * `init` (one file per new provider/command), or from a react world's
57
- * `useDebugProvider`/`useDebugCommand`/`useDebugEmit` hooks. Every registration feeds the ONE
58
- * game-scoped registry (`runtime/debug-registry.ts`) — never a per-world accumulator.
59
- */
60
- export interface DebugCtxSurface {
61
- /** Register (or replace) a named, JSON-serializable state read. Duplicate
62
- * names from the SAME world replace + warn once; the SAME name from a
63
- * DIFFERENT world throws (`DebugError` code `DEBUG_NAME_COLLISION`). */
64
- registerStateProvider(
65
- name: string,
66
- fn: () => unknown,
67
- opts?: { tier?: 'observable' | 'assisted' },
68
- ): void;
69
- /** Register (or replace) an invokable command. `locus` is REQUIRED once the
70
- * project declares a Colyseus room (`DebugRegistry.setRoomDeclared`) — a
71
- * fixture must say whether it mutates authoritative (server) or predicted
72
- * (client) state.
73
- *
74
- * Generic over the declared `args` Zod tuple ({@link DebugCommandArgs}) so
75
- * `fn`'s parameters INFER from it: `registerCommand('setHp', { args:
76
- * z.tuple([z.number()]) }, (hp) => ...)` types `hp` as `number` with no
77
- * cast. Leaving `args` off keeps `fn` typed `(...args: unknown[]) => ...`,
78
- * same as before this generic existed. */
79
- registerCommand<T extends z.ZodTuple | undefined = undefined>(
80
- name: string,
81
- spec: { description?: string; args?: T; locus?: 'client' | 'server' },
82
- fn: (...args: DebugCommandArgs<T>) => unknown | Promise<unknown>,
83
- ): void;
84
- /** Push a tick-stamped event onto the debug event ring (spec §3.3) — the
85
- * engine stamps `tick`/`simT` at emission, not at read time. */
86
- emit(event: string, detail?: unknown): void;
87
- /**
88
- * Task 2.2 — server-locus command routing (client leg). Call once your
89
- * game code has joined its Colyseus room, so `locus: 'server'` commands
90
- * have somewhere to send `__vgai:debugCommand`. Returns a detach function
91
- * (call on room leave/dispose) — game-scoped, last-attached room wins.
92
- */
93
- attachRoom(room: DebugRoomHandle): () => void;
94
- }
95
-
96
- /**
97
- * All engine subsystems, passed to every game `setup(ctx)` and to each
98
- * game lifecycle callback.
99
- *
100
- * The surface is intentionally split in two:
101
- *
102
- * - **Raw libraries** — the actual Three.js / Rapier / postprocessing objects.
103
- * Call their documented APIs directly; do NOT build wrappers around them.
104
- * - **Engine handles** — thin VGAI-owned managers that bridge those libraries
105
- * into the phase-ordered game loop. Reach for these when you need behavior the
106
- * raw library doesn't provide (physics↔Object3D mapping, system phases, etc.).
107
- */
108
- /** Host-supplied identity for one private play run or coordinated team test.
109
- * Games may pass `roomKey` as a Colyseus filter/join option; the engine never
110
- * joins a room or couples this authoring identity to a networking library. */
111
- export interface PlaytestContext {
112
- readonly mode: 'private' | 'team';
113
- readonly id: string;
114
- readonly roomKey: string;
115
- readonly revision: number | null;
116
- readonly participantId: string | null;
117
- }
118
-
119
- export interface GameContext {
120
- // ─── Raw libraries (the real library objects — call them directly) ───
121
-
122
- /** Three.js scene graph root. Add/remove any `Object3D` (meshes, lights,
123
- * groups) here. This is THE scene — there is no separate engine scene. */
124
- scene: THREE.Scene;
125
- /** The single render camera. Move/aim it directly, or (preferred) drive it
126
- * from game code — see the camera-precedence note below. */
127
- camera: THREE.PerspectiveCamera;
128
- /** The Rapier physics `World`. Step/query it, create bodies & colliders via
129
- * `ctx.rapier`. One shared world for the whole scene. */
130
- rapierWorld: RAPIER.World;
131
- /** The Rapier module namespace itself (`RigidBodyDesc`, `ColliderDesc`,
132
- * `Vector3`, enums, …). Use to construct physics descriptors. */
133
- rapier: typeof RAPIER;
134
- /** The `postprocessing` EffectComposer driving the final render. Use to
135
- * add/remove passes (bloom, vignette, …) or reach the underlying
136
- * `WebGLRenderer` via `composer.getRenderer()`. */
137
- composer: EffectComposer;
138
-
139
- // ─── Engine handles (VGAI managers — use when the raw lib isn't enough) ───
140
-
141
- /** Keyboard/mouse/gamepad input. Polled once per frame in the `input` phase;
142
- * read action/axis state inside your `update`. */
143
- input: InputManager;
144
- /** Rapier collision-event dispatcher. Register handlers with
145
- * `collisions.onCollision(...)`; it is drained each `postPhysics`. Prefer a
146
- * own handler for per-entity sensor logic. */
147
- collisions: CollisionSystem;
148
- /** `Object3D ↔ Rapier body/collider` registry (+ collider→Object3D reverse
149
- * index). Use to find an entity's body/collider, or the entity behind a
150
- * raw collision. Inside a component, `this.rigidBody`/`this.collider` are
151
- * pre-resolved from here. */
152
- physics: PhysicsRegistry;
153
- /** Procedural audio: master gain, listener, and one-shot/impact helpers.
154
- * Use for SFX and music; the listener tracks the camera. */
155
- audio: GameAudio;
156
- /** three.quarks particle system: the batched renderer + spawn helpers. Use
157
- * to emit runtime particle effects; declarative scene particles register
158
- * here automatically. */
159
- particles: ParticlesContext;
160
- /** Immediate-mode debug drawing (`line`/`box`/`sphere`/`arrow`). Drawn
161
- * objects persist until you call `debugDraw.clear()` yourself (the
162
- * adapter also clears on scene dispose/hot-reload) — nothing clears it
163
- * automatically per frame. Dev-only visualization — not for shipped
164
- * visuals. */
165
- debugDraw: ReturnType<typeof createDebugDraw>;
166
- /** Shared GLTF/texture cache. Use `assets.loadGLTF(...)` etc. to load+cache
167
- * models at runtime so repeated loads reuse geometry/material. */
168
- assets: AssetCache;
169
- /** The phase-ordered system runner. `systems.add(phase, fn)` registers a
170
- * per-frame callback. Reserve this for non-gameplay infra (audio mixers,
171
- * network send); per-entity GAMEPLAY belongs in a `useFrame` hook. */
172
- systems: ReturnType<typeof createSystemRunner>;
173
- /**
174
- * P3 — the SIM-TIME scheduler (`core/sim-clock.ts`). `await ctx.clock.delay(n)`
175
- * waits `n` seconds of the fixed loop's own time, so it pauses when the game
176
- * pauses, steps when `Game.play.step()` steps, and reproduces exactly in an
177
- * offline export; `ctx.clock.after(n, fn)` is the frame-exact synchronous
178
- * form, and `ctx.clock.disposeAfter(obj, n)` is debris removal. Cancellation
179
- * is `AbortSignal`.
180
- *
181
- * REQUIRED, unlike `debug`/`random` above: every world has a sim clock. When
182
- * a Game hosts the mount it is the ONE game-scoped clock the fixed loop
183
- * flushes; a bare harness mount with no Game shell gets a private,
184
- * mount-local clock that nothing advances (so `now()` stays 0) rather than an
185
- * absent field.
186
- *
187
- * NOT `AnimationClock` (`animation/animation-clock.ts`) — that one is the
188
- * seekable cinematic playhead and runs backwards. This one is monotonic and
189
- * never rewinds, which is exactly why a Promise can be bound to it. See
190
- * `core/sim-clock.ts`'s header.
191
- */
192
- clock: SimClock;
193
- /** The live scene index for this root (P2 `observe`): tag/entity-id lookup
194
- * that never traverses, plus the change signals — `entityadded`,
195
- * `entityremoved`, `tagadded`, `tagremoved`, `attributechanged` — on a plain
196
- * `EventTarget`, unsubscribed with an `AbortSignal`. Maintained from three's
197
- * own `childadded`/`childremoved` parent events, so it costs nothing on a
198
- * frame where nothing changes. See `ecs/scene-index.ts`; the one-shot
199
- * `ecs/scene-query.ts` walks remain for a single ad-hoc question. */
200
- sceneIndex: SceneIndex;
201
- /** Register a game-owned `SystemAdapters` capability (networking,
202
- * navigation, …) on the mounted game's adapter surface, so the editor's
203
- * introspection panels (via `getActiveSystems()`) can see it. The engine
204
- * wires the first-party physics/input/assets/audio entries itself;
205
- * capabilities the GAME owns (a Colyseus connection, a NavMeshManager)
206
- * are registered here by the game's setup. Optional capability — absent
207
- * in contexts that expose no adapter surface (some test harnesses);
208
- * call as `ctx.registerSystemAdapter?.(…)`.
209
- *
210
- * Ordering contract: **game registrations always win** — the engine seeds
211
- * its first-party entries (physics/input/assets/audio) BEFORE setup()
212
- * runs, so a game that registers any of those same kinds during its own
213
- * setup overrides the engine's entry, not the other way around. This also
214
- * holds across a warm restart (`hotReload`): every kind the outgoing game
215
- * registered is stripped back to the engine's entry (or absent, for
216
- * game-only kinds like networking/navigation) before the incoming game's
217
- * setup runs, so a disposed game's adapter is never left stale on the
218
- * mounted surface. */
219
- registerSystemAdapter?<K extends keyof SystemAdapters>(kind: K, adapter: SystemAdapters[K]): void;
220
-
221
- /** The debug/synthetic-player authoring surface — see {@link DebugCtxSurface}.
222
- * Optional, same absence precedent as `registerSystemAdapter`: present on every
223
- * first-party mount, absent only in bare test harnesses that build a
224
- * hand-rolled `ctx`. */
225
- debug?: DebugCtxSurface;
226
-
227
- /**
228
- * D15 (T-D15.1) — the game-scoped, named-stream seeded PRNG. `ctx.random()`
229
- * draws from the `'gameplay'` stream; `ctx.random.stream('vfx')` (or any other
230
- * name) draws from an INDEPENDENT stream, so a cosmetic/VFX draw can never
231
- * shift the gameplay draw sequence. Use this instead of raw `Math.random()` for
232
- * anything a project wants to keep reproducible; `ctx.random` itself always
233
- * exists and is always internally consistent (same seed ⇒ same sequence)
234
- * whether or not the project's manifest declares `determinism.seededRandom` —
235
- * that flag only gates the BOOT-TIME seeding from
236
- * `manifest.determinism.defaultSeed`/`?vgai-seed=`, the burn-down lint scan,
237
- * and the dev-mode `Math.random` phase trap (three separate enforcers,
238
- * `test/gameplay-rng-ban.test.ts` + `runtime/gameplay-rng-trap.ts`), never
239
- * `ctx.random`'s mere presence. Same absence precedent as `debug` above:
240
- * present on every first-party mount, optional only for bare test harnesses
241
- * that build a hand-rolled `ctx`. `reseed(seed)` (future draws only) is
242
- * `play.seed.set`'s eventual target (T-D15.6, not yet wired).
243
- */
244
- random?: SeededRandom;
245
-
246
- // ─── Game root (T7.1 slice 1 — D6) ───
247
-
248
- /** The Game root — the loop, the world registry, and game-scoped handles.
249
- * Absent only in bare test harnesses that construct a partial context (the
250
- * host always sets it in `createGameRuntime`). Optional so every existing
251
- * harness that builds a hand-rolled `ctx` object keeps compiling
252
- * unmodified — the same precedent as `registerSystemAdapter`. */
253
- game?: Game | undefined;
254
- /** Alias for `game.roots` — the live, declaration-ordered world registry.
255
- * Same optionality/absence rule as `game` above. */
256
- roots?: ReadonlyArray<RootInstance> | undefined;
257
- /** The host's current private play or Team Test identity. Optional for
258
- * standalone/custom hosts; networking remains game-owned and direct. */
259
- playtest?: PlaytestContext | null | undefined;
260
- }
261
-
262
- /**
263
- * Services shared by component-authored roots, independent of their render
264
- * surface. This is deliberately an explicit pick from {@link GameContext}:
265
- * adding a subsystem to the imperative Three setup context never silently
266
- * exposes it to R3F or Canvas components.
267
- *
268
- * `input` is nullable because it belongs to the optional `Game` host. Normal
269
- * vgai project mounts always provide it; bare harnesses and foreign hosts do
270
- * not. Component code therefore sees the absence in its type instead of a
271
- * getter that first throws from inside a frame callback.
272
- *
273
- * `clock` is surface-specific and intentionally absent here. The imperative
274
- * and R3F clocks can dispose `THREE.Object3D` debris; a Canvas context narrows
275
- * that Three-only operation away.
276
- */
277
- export type ComponentContextBase = Pick<
278
- GameContext,
279
- 'systems' | 'debug' | 'random' | 'game' | 'roots' | 'playtest' | 'registerSystemAdapter'
280
- > & {
281
- readonly input: InputManager | null;
282
- };
283
-
284
- /** Return value from a game setup function. */
285
- export interface GameCleanup {
286
- dispose: () => void;
287
- }
288
-
289
- /** Context passed to setup() when launched from the editor's play mode. */
290
- export interface EditorPreview {
291
- /** Editor viewport camera transform — use this as the initial game camera viewpoint. */
292
- viewportCamera?: {
293
- position: [number, number, number];
294
- quaternion: [number, number, number, number];
295
- };
296
- /**
297
- * Which bundled example the static/browser build's project picker wants to
298
- * run (Adjudication H).
299
- *
300
- * Its one former reader — `browser-play-entry.ts`'s whole-bundle `setup()`,
301
- * which dispatched over the generated `SETUP_BY_EXAMPLE_ID` table — is
302
- * DELETED. Hosted dispatch is per-root (`ADAPTER_BY_EXAMPLE_ROOT` /
303
- * `REACT_BY_EXAMPLE_ROOT`, resolved in `adapter-resolver.ts`) and never
304
- * consults this field; `exampleDispatchFor` still sets it as the marker for
305
- * "play the project's own shipped game" rather than a `?scene=` override
306
- * (which sets `assetPrefix` instead — that one IS read, by
307
- * `SetupThreeRootAdapter`). Every `GameSetupFn` consumer ignores it.
308
- */
309
- exampleId?: string | undefined;
310
- /**
311
- * Asset prefix for the static/browser build's GENERIC scene-loader fallback,
312
- * set INSTEAD of `exampleId` when the editor has a non-default scene of a
313
- * bundled example open (hosted `?project=<id>&scene=<project-relative>` —
314
- * Track H): the open scene plays via `sceneData`, but its relative asset
315
- * refs still live under the example's staged `/examples/<id>/` public root.
316
- * Ignored whenever `exampleId` is set; undefined ⇒ root prefix `/`.
317
- */
318
- assetPrefix?: string | undefined;
319
- }
320
-
321
- /** A game setup function: receives engine context, returns cleanup.
322
- *
323
- * This is the MOUNT body of the FIRST-PARTY implementer. The host no longer
324
- * depends on it — the host depends on `RootAdapter` (`@engine/adapter`), and
325
- * `GameSetupFn` is wrapped into a `SetupThreeRootAdapter` via `fromSetup`.. (The
326
- * former `RootAdapter` `{ setup, components }` interface lived here; it is
327
- * superseded by the real adapter interfaces in `@engine/adapter`.) */
328
- export type GameSetupFn = (ctx: GameContext, editor?: EditorPreview) => Promise<GameCleanup>;
@@ -1,86 +0,0 @@
1
- /**
2
- * `@engine/world3d-react` — the React context that carries this R3F world's
3
- * engine runtime into its fiber tree: the world's `R3FGameContext`, read
4
- * with {@link useGameContext}.
5
- *
6
- * Upstreamed from `examples/r3f-first-party/src/engine-bridge.ts` (R4).
7
- * The bridge value
8
- * is built by `createR3FAdapter`'s `mount()` (./r3f-adapter.tsx): a real
9
- * `createSystemRunner` whose phases the adapter's `update(dt)` runs under the
10
- * HOST loop — so registered systems tick in engine phase order, pause included
11
- * (no update while the world is frozen).
12
- *
13
- * Behavior in an R3F world is components and hooks: `useGameContext` is how a
14
- * component reaches engine services.
15
- */
16
-
17
- import { createContext, useContext } from 'react';
18
- import { useOptionalGame } from '../react/world-state';
19
- import type { R3FGameContext } from './world-context';
20
-
21
- export interface EngineBridgeValue {
22
- /** This root's context — `input`, `debug`, `random`, `game`, `roots`, … .
23
- * Present so ordinary components can reach engine services with a HOOK
24
- * (see {@link useGameContext}). */
25
- readonly ctx?: R3FGameContext | undefined;
26
- }
27
-
28
- export const EngineBridge = createContext<EngineBridgeValue | null>(null);
29
-
30
- /**
31
- * This R3F root's context, for use inside any component in the tree — an
32
- * {@link R3FGameContext}, which is exactly the subsystems an R3F world builds.
33
- * The ones it does not build are absent from the type, so reaching for one is
34
- * a compile error at the call site; that type's doc comment says what to reach
35
- * for instead.
36
- *
37
- * An ordinary component does what a model would write:
38
- *
39
- * ```tsx
40
- * function Player({ speed = 4.5 }) {
41
- * const { input } = useGameContext();
42
- * const ref = useRef<THREE.Group>(null);
43
- * useFrame((_, dt) => { if (input?.isPressed('move_forward')) … });
44
- * return <group ref={ref}><PlayerCharacter /></group>;
45
- * }
46
- * ```
47
- *
48
- * Throws when called outside an R3F root mounted by `createR3FAdapter` —
49
- * absent context is a wiring bug, and a silent `null` would surface as a
50
- * mystery `undefined` deep in a frame callback.
51
- */
52
- export function useGameContext(): R3FGameContext {
53
- const bridge = useContext(EngineBridge);
54
- // Read unconditionally (rules of hooks) — used only to shape the throw below.
55
- const hostedByGame = useOptionalGame() !== null;
56
- if (!bridge?.ctx) {
57
- // NAME THE REAL CAUSE. This throw used to say "check that the component is
58
- // rendered inside your world entry" — advice a scaffolded game has already
59
- // followed, because the shape `vgai create` produces (`export default
60
- // function World()`) mounts as a COMPONENT ROOT and receives no vgai
61
- // runtime context at all: `r3f-root-factory.tsx` passes
62
- // `engineRuntime: false` deliberately, so this hook can never resolve
63
- // there however the component is nested. A world whose first render calls
64
- // it dies with "fiber crashed before its first commit" and a fix
65
- // instruction that cannot work. The `Game` in scope tells the two cases
66
- // apart: present means a vgai-mounted world, absent means no root at all.
67
- throw new Error(
68
- hostedByGame
69
- ? 'useGameContext(): this world mounts as a COMPONENT ROOT (the default-exported ' +
70
- 'shape `vgai create` scaffolds) and receives no vgai runtime context — by design, ' +
71
- 'so nesting cannot fix it. Game-scoped services are on the Game handle instead: ' +
72
- '`useGame().input` (from @vgai/engine/react/world-state) is the game-owned ' +
73
- "InputManager the host already loaded this project's input map into and the same " +
74
- 'one `game.input.hold/tap` drives; `useDebugProvider`/`useDebugCommand`/' +
75
- '`useWorldState` are the state/command doors. If this world genuinely needs the ' +
76
- 'imperative runtime (`ctx.systems`, adapter options like `inputMapPath`), export ' +
77
- '`adapter = createR3FAdapter({ id, content: <World/> })` from the entry instead of ' +
78
- 'default-exporting the component.'
79
- : 'useGameContext(): no engine root context and no Game in scope — this component is ' +
80
- 'rendering outside any mounted vgai root (a standalone <Canvas>, a story, or a ' +
81
- "bare test render). Mount it through your project's three root, or read services " +
82
- 'the component root way (native hooks and project-owned state).',
83
- );
84
- }
85
- return bridge.ctx;
86
- }