threedog 0.7.0 → 0.8.0

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 (544) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +6 -9
  3. package/core/{Animator.js → assets/Animator.js} +28 -18
  4. package/core/{Assets.js → assets/Assets.js} +98 -54
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +237 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +7 -6
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +6 -12
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +26 -23
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +10 -10
  18. package/core/{Random.js → base/Random.js} +5 -4
  19. package/core/{easing.js → base/easing.js} +1 -1
  20. package/core/{errorCodes.js → base/errorCodes.js} +98 -110
  21. package/core/{errorHints.js → base/errorHints.js} +5 -9
  22. package/core/{errors.js → base/errors.js} +6 -6
  23. package/core/{events.generated.js → base/events.generated.js} +1 -0
  24. package/core/{math.js → base/math.js} +15 -4
  25. package/core/{params.js → base/params.js} +3 -4
  26. package/core/base/util.js +32 -0
  27. package/core/{validate.js → base/validate.js} +28 -7
  28. package/core/{Engine.js → engine/Engine.js} +80 -77
  29. package/core/{Loading.js → engine/Loading.js} +4 -2
  30. package/core/{copies.js → engine/copies.js} +4 -4
  31. package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
  32. package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
  33. package/core/{loop.js → engine/loop.js} +68 -47
  34. package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
  35. package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
  36. package/core/{modules.js → engine/modules.js} +14 -11
  37. package/core/{page.js → engine/page.js} +36 -23
  38. package/core/{plugins.js → engine/plugins.js} +6 -9
  39. package/core/{services.js → engine/services.js} +47 -40
  40. package/core/{startup.js → engine/startup.js} +26 -24
  41. package/core/{Input.js → input/Input.js} +30 -22
  42. package/core/{inputContext.js → input/inputContext.js} +14 -5
  43. package/core/{inputPad.js → input/inputPad.js} +1 -1
  44. package/core/{inputPointer.js → input/inputPointer.js} +8 -2
  45. package/core/{inputTouch.js → input/inputTouch.js} +1 -1
  46. package/core/{Budget.js → inspect/Budget.js} +21 -20
  47. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
  48. package/core/{Describe.js → inspect/Describe.js} +26 -22
  49. package/core/{Inspect.js → inspect/Inspect.js} +9 -7
  50. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  51. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  52. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  53. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  54. package/core/{UrlState.js → inspect/UrlState.js} +52 -20
  55. package/core/{catalog.js → inspect/catalog.js} +3 -3
  56. package/core/{checks.js → inspect/checks.js} +7 -5
  57. package/core/{debugView.js → inspect/debugView.js} +4 -4
  58. package/core/{describeRender.js → inspect/describeRender.js} +21 -20
  59. package/core/{describeText.js → inspect/describeText.js} +11 -6
  60. package/core/inspect/geometryWatch.js +38 -0
  61. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  62. package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
  63. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  64. package/core/{Ops.js → ops/Ops.js} +16 -11
  65. package/core/{control.js → ops/control.js} +13 -12
  66. package/core/ops/holds.js +139 -0
  67. package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
  68. package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
  69. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  70. package/core/{opsRun.js → ops/opsRun.js} +7 -4
  71. package/core/{owned.js → ops/owned.js} +14 -17
  72. package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
  73. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  74. package/core/{stacks.js → ops/stacks.js} +12 -14
  75. package/core/{wrap.js → ops/wrap.js} +8 -6
  76. package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
  77. package/core/{Saves.js → saves/Saves.js} +58 -36
  78. package/core/{saveApply.js → saves/saveApply.js} +13 -9
  79. package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
  80. package/core/{saveValues.js → saves/saveValues.js} +20 -3
  81. package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
  82. package/core/{session.js → saves/session.js} +31 -17
  83. package/core/{Rays.js → scene/Rays.js} +23 -25
  84. package/core/{Views.js → scene/Views.js} +14 -6
  85. package/core/{adaptive.js → scene/adaptive.js} +15 -8
  86. package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
  87. package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
  88. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  89. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  90. package/core/{grid.js → scene/grid.js} +4 -4
  91. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  92. package/core/{ground.js → scene/ground.js} +9 -9
  93. package/core/{movement.js → scene/movement.js} +3 -3
  94. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  95. package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
  96. package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
  97. package/core/scene/stepPoses.js +55 -0
  98. package/core/{targeting.js → scene/targeting.js} +4 -5
  99. package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
  100. package/core/{thingOps.js → scene/thingOps.js} +4 -3
  101. package/core/{things.js → scene/things.js} +18 -5
  102. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  103. package/core/{view.js → scene/view.js} +17 -16
  104. package/core/{Batching.js → stream/Batching.js} +85 -27
  105. package/core/{Stream.js → stream/Stream.js} +60 -30
  106. package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
  107. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  108. package/core/{scatter.js → stream/scatter.js} +2 -2
  109. package/core/{streamSources.js → stream/streamSources.js} +12 -7
  110. package/core/{Commits.js → threads/Commits.js} +6 -5
  111. package/core/{Jobs.js → threads/Jobs.js} +12 -10
  112. package/core/{Threads.js → threads/Threads.js} +16 -16
  113. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  114. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  115. package/core/{Clock.js → time/Clock.js} +17 -10
  116. package/core/{dayTime.js → time/dayTime.js} +5 -1
  117. package/core/{skip.js → time/skip.js} +18 -17
  118. package/core/{time.js → time/time.js} +18 -12
  119. package/core/{uiClock.js → time/uiClock.js} +4 -4
  120. package/docs/AI.md +22 -19
  121. package/docs/API.md +24 -23
  122. package/docs/CODEMAP.md +76 -183
  123. package/docs/COMMANDS.md +66 -58
  124. package/docs/CONVENTIONS.md +54 -14
  125. package/docs/MIGRATING-0.8.md +169 -0
  126. package/docs/THREE.md +78 -29
  127. package/docs/api/assets.md +12 -13
  128. package/docs/api/audio.md +6 -5
  129. package/docs/api/budget.md +4 -4
  130. package/docs/api/calendar.md +10 -11
  131. package/docs/api/cameraRig.md +29 -29
  132. package/docs/api/characters.md +23 -18
  133. package/docs/api/clock.md +1 -1
  134. package/docs/api/collision.md +12 -9
  135. package/docs/api/content.md +6 -6
  136. package/docs/api/dialogue.md +3 -3
  137. package/docs/api/engine.md +45 -43
  138. package/docs/api/events.md +3 -2
  139. package/docs/api/flow.md +1 -1
  140. package/docs/api/grids.md +1 -1
  141. package/docs/api/ground.md +4 -5
  142. package/docs/api/hud.md +2 -2
  143. package/docs/api/i18n.md +6 -6
  144. package/docs/api/input.md +7 -7
  145. package/docs/api/interactions.md +4 -4
  146. package/docs/api/inventory.md +9 -9
  147. package/docs/api/jobs.md +5 -5
  148. package/docs/api/level.md +7 -7
  149. package/docs/api/lightPool.md +1 -6
  150. package/docs/api/music.md +3 -3
  151. package/docs/api/nav.md +10 -10
  152. package/docs/api/openWorld.md +1 -1
  153. package/docs/api/particles.md +2 -2
  154. package/docs/api/photo.md +4 -2
  155. package/docs/api/pickups.md +2 -2
  156. package/docs/api/post.md +20 -3
  157. package/docs/api/quests.md +3 -3
  158. package/docs/api/rays.md +5 -7
  159. package/docs/api/rigid.md +27 -18
  160. package/docs/api/saves.md +8 -7
  161. package/docs/api/settings.md +9 -8
  162. package/docs/api/sky.md +8 -7
  163. package/docs/api/stream.md +7 -7
  164. package/docs/api/swarm.md +34 -0
  165. package/docs/api/terrain.md +7 -8
  166. package/docs/api/terrainDraw.md +1 -1
  167. package/docs/api/timeline.md +2 -2
  168. package/docs/api/tools.md +25 -22
  169. package/docs/api/vars.md +1 -1
  170. package/docs/api/vegetation.md +4 -3
  171. package/docs/api/vegetationDraw.md +1 -1
  172. package/docs/api/water.md +1 -1
  173. package/docs/api/weather.md +9 -9
  174. package/docs/api/weatherDraw.md +3 -3
  175. package/docs/api/world.md +5 -5
  176. package/docs/recipes/01-new-game.md +25 -40
  177. package/docs/recipes/02-npc.md +19 -20
  178. package/docs/recipes/03-items-pickups.md +27 -43
  179. package/docs/recipes/04-quests.md +3 -4
  180. package/docs/recipes/05-props-bake.md +29 -39
  181. package/docs/recipes/06-clock-events.md +27 -18
  182. package/docs/recipes/07-flow-scenes-pause.md +12 -17
  183. package/docs/recipes/08-weather-sky.md +88 -34
  184. package/docs/recipes/09-materials-lights-models.md +22 -36
  185. package/docs/recipes/10-blender-level.md +6 -7
  186. package/docs/recipes/11-vehicles.md +30 -22
  187. package/docs/recipes/12-navmesh.md +9 -8
  188. package/docs/recipes/13-animation.md +39 -17
  189. package/docs/recipes/14-custom-module.md +14 -13
  190. package/docs/recipes/15-perf.md +49 -26
  191. package/docs/recipes/16-dev-bridge.md +32 -52
  192. package/docs/recipes/18-world.md +36 -23
  193. package/docs/recipes/19-shooting-picking.md +4 -2
  194. package/docs/recipes/20-content-actions-save.md +30 -35
  195. package/docs/recipes/21-camera.md +33 -5
  196. package/docs/recipes/22-shop-gold.md +0 -4
  197. package/docs/recipes/23-ops.md +10 -10
  198. package/docs/recipes/26-ui-parts.md +22 -12
  199. package/docs/recipes/27-net.md +0 -2
  200. package/docs/recipes/28-terrain.md +117 -21
  201. package/docs/recipes/29-grid.md +2 -2
  202. package/docs/recipes/30-templates.md +55 -19
  203. package/docs/recipes/31-audio.md +5 -5
  204. package/docs/recipes/32-action-game.md +15 -6
  205. package/docs/recipes/33-stream-sources.md +2 -2
  206. package/docs/recipes/34-environment-lighting.md +67 -19
  207. package/docs/recipes/35-picture-from-reference.md +10 -17
  208. package/docs/recipes/36-ground-plants.md +105 -0
  209. package/docs/recipes/40-scene.md +7 -11
  210. package/docs/recipes/43-shader-patches-surfaces.md +20 -41
  211. package/docs/recipes/44-water-weather-hooks.md +48 -43
  212. package/docs/recipes/45-cascaded-shadows.md +39 -17
  213. package/docs/recipes/46-blender-art-route.md +7 -8
  214. package/docs/recipes/49-game-module-contract.md +5 -5
  215. package/docs/recipes/50-own-renderer.md +2 -2
  216. package/docs/recipes/52-around-the-picture.md +54 -98
  217. package/docs/recipes/53-ground-up-close.md +61 -24
  218. package/docs/recipes/55-mods-time-wrap.md +12 -16
  219. package/docs/recipes/56-webgpu-tsl.md +16 -14
  220. package/docs/recipes/57-control.md +9 -2
  221. package/docs/recipes/58-input.md +2 -2
  222. package/docs/recipes/59-depth-post-effects.md +1 -1
  223. package/docs/recipes/60-judge-the-picture.md +29 -24
  224. package/docs/recipes/62-picture-code.md +49 -17
  225. package/docs/recipes/63-third-person-start.md +17 -4
  226. package/docs/recipes/64-particles.md +1 -1
  227. package/docs/recipes/65-swarm.md +140 -0
  228. package/examples/action/.threedog/content-index.json +1 -1
  229. package/examples/action/GAMEMAP.md +2 -2
  230. package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
  231. package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
  232. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  233. package/examples/{sheepisland → perf-island}/main.js +8 -8
  234. package/examples/{sheepisland → perf-island}/models.js +1 -1
  235. package/examples/{sheepisland → perf-island}/params.js +1 -1
  236. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  237. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  238. package/examples/{sheepisland → perf-island}/views.js +1 -1
  239. package/examples/plain-picture/GAMEMAP.md +1 -0
  240. package/examples/rc2d/GAMEMAP.md +3 -2
  241. package/examples/rc2d/main.js +1 -3
  242. package/examples/styletest/.threedog/content-index.json +1 -1
  243. package/examples/styletest/GAMEMAP.md +3 -2
  244. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  245. package/examples/techniques/contact-shadows/main.js +1 -1
  246. package/examples/techniques/interior-light/main.js +1 -1
  247. package/examples/techniques/modular-building/README.md +7 -6
  248. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  249. package/examples/techniques/procedural-animation/README.md +1 -1
  250. package/examples/webgpu-tsl/GAMEMAP.md +1 -0
  251. package/examples/world/.threedog/content-index.json +1 -1
  252. package/examples/world/GAMEMAP.md +4 -3
  253. package/examples/world/picture/sky.js +1 -1
  254. package/index.d.ts +8 -7
  255. package/index.js +31 -31
  256. package/llms.txt +9 -13
  257. package/modules/ambience/Ambience.js +11 -8
  258. package/modules/calendar/Calendar.js +19 -19
  259. package/modules/calendar/index.js +13 -13
  260. package/modules/calendar/schedule.js +11 -6
  261. package/modules/calendar/seasons.js +7 -7
  262. package/modules/camera/FirstPersonCamera.js +2 -2
  263. package/modules/camera/FixedCamera.js +14 -15
  264. package/modules/camera/FollowCamera.js +4 -4
  265. package/modules/camera/RtsCamera.js +11 -11
  266. package/modules/camera/common.js +48 -24
  267. package/modules/camera/contract.js +1 -0
  268. package/modules/camera/projection.js +2 -2
  269. package/modules/characters/Character.js +33 -30
  270. package/modules/characters/NPC.js +27 -19
  271. package/modules/characters/assetModel.js +14 -10
  272. package/modules/characters/astar.js +7 -5
  273. package/modules/characters/behaviors.js +4 -5
  274. package/modules/characters/contract.js +2 -2
  275. package/modules/characters/index.js +168 -214
  276. package/modules/characters/moveHelpers.js +14 -3
  277. package/modules/characters/movers/common.js +16 -14
  278. package/modules/characters/movers/manual.js +1 -1
  279. package/modules/characters/movers/rapier.js +7 -6
  280. package/modules/characters/movers/simple.js +3 -3
  281. package/modules/characters/movers/support.js +8 -8
  282. package/modules/characters/npcAvoid.js +4 -4
  283. package/modules/characters/npcSim.js +23 -17
  284. package/modules/characters/npcView.js +6 -5
  285. package/modules/characters/pathAsync.js +12 -10
  286. package/modules/characters/pathWorker.js +1 -1
  287. package/modules/characters/player.js +108 -0
  288. package/modules/characters/playerStrings.js +2 -2
  289. package/modules/characters/proceduralRig.js +2 -2
  290. package/modules/characters/useModel.js +3 -3
  291. package/modules/characters/walkTo.js +11 -17
  292. package/modules/collision/Collision.js +26 -20
  293. package/modules/collision/contract.js +15 -0
  294. package/modules/content/explain.js +1 -2
  295. package/modules/content/fields.js +24 -3
  296. package/modules/content/ids.js +2 -2
  297. package/modules/content/index.js +61 -99
  298. package/modules/content/loader.js +14 -17
  299. package/modules/content/markers.js +25 -0
  300. package/modules/content/models.js +10 -7
  301. package/modules/content/packs.js +3 -3
  302. package/modules/content/parts.js +2 -2
  303. package/modules/content/places.js +35 -0
  304. package/modules/content/props.js +17 -14
  305. package/modules/content/rules.js +25 -21
  306. package/modules/content/stages.js +7 -7
  307. package/modules/content/templates.js +20 -20
  308. package/modules/content/words.js +34 -0
  309. package/modules/debug/DebugPanel.js +10 -43
  310. package/modules/flow/contract.js +1 -1
  311. package/modules/flow/index.js +11 -7
  312. package/modules/gameplay/Container.js +12 -11
  313. package/modules/gameplay/Containers.js +14 -5
  314. package/modules/gameplay/Dialogue.js +13 -11
  315. package/modules/gameplay/Interactions.js +37 -24
  316. package/modules/gameplay/Inventory.js +8 -9
  317. package/modules/gameplay/Quests.js +16 -9
  318. package/modules/gameplay/boxOps.js +1 -1
  319. package/modules/gameplay/dialogueBubbles.js +3 -4
  320. package/modules/gameplay/inventoryOps.js +0 -1
  321. package/modules/gameplay/pickups.js +22 -23
  322. package/modules/gameplay/questSave.js +3 -3
  323. package/modules/grid/Grid.js +1 -1
  324. package/modules/grid/Layer.js +4 -4
  325. package/modules/grid/index.js +7 -8
  326. package/modules/grid/preview.js +7 -7
  327. package/modules/grid/tiles.js +6 -6
  328. package/modules/hlod/index.js +37 -55
  329. package/modules/hud/index.js +17 -11
  330. package/modules/hud/parts.js +4 -4
  331. package/modules/level/contract.js +16 -0
  332. package/modules/level/heightfield.js +12 -10
  333. package/modules/level/index.js +47 -152
  334. package/modules/level/load.js +79 -0
  335. package/modules/level/meshes.js +65 -0
  336. package/modules/level/nodes.js +6 -7
  337. package/modules/lights/index.js +28 -181
  338. package/modules/lights/slots.js +93 -0
  339. package/modules/lights/sources.js +88 -0
  340. package/modules/music/Music.js +30 -26
  341. package/modules/music/rules.js +1 -1
  342. package/modules/nav/contract.js +14 -0
  343. package/modules/nav/index.js +11 -10
  344. package/modules/net/Client.js +7 -7
  345. package/modules/net/Host.js +7 -7
  346. package/modules/net/Net.js +1 -1
  347. package/modules/net/index.js +5 -4
  348. package/modules/net/sync.js +2 -2
  349. package/modules/net/transports.js +2 -2
  350. package/modules/particles/Particles.js +11 -8
  351. package/modules/particles/effect.js +7 -5
  352. package/modules/particles/shaders.js +2 -1
  353. package/modules/photo/Photo.js +15 -17
  354. package/modules/rigid/RigidBodies.js +66 -43
  355. package/modules/rigid/Vehicles.js +2 -3
  356. package/modules/rigid/ragdoll.js +287 -0
  357. package/modules/rigid/ragdollBones.js +159 -0
  358. package/modules/rigid/sync.js +6 -6
  359. package/modules/settings/Settings.js +108 -39
  360. package/modules/settings/apply.js +6 -6
  361. package/modules/settings/sections.js +16 -14
  362. package/modules/settings/view.js +3 -3
  363. package/modules/sky/Sky.js +29 -22
  364. package/modules/sky/clouds.js +7 -7
  365. package/modules/sky/dome.js +33 -20
  366. package/modules/sky/domeLayers.js +9 -9
  367. package/modules/sky/environment.js +6 -6
  368. package/modules/sky/frame.js +19 -10
  369. package/modules/sky/season.js +7 -1
  370. package/modules/sky/shader.js +24 -25
  371. package/modules/sky/skyModule.js +14 -27
  372. package/modules/sky/tint.js +1 -1
  373. package/modules/swarm/Swarm.js +346 -0
  374. package/modules/swarm/draw.js +68 -0
  375. package/modules/swarm/grid.js +63 -0
  376. package/modules/terrain/ChunkManager.js +70 -52
  377. package/modules/terrain/chunkQueries.js +7 -24
  378. package/modules/terrain/chunkWorker.js +1 -1
  379. package/modules/terrain/draw.js +14 -11
  380. package/modules/terrain/index.js +28 -34
  381. package/modules/terrain/terrainColorMap.js +6 -3
  382. package/modules/terrain/terrainDefaults.js +2 -1
  383. package/modules/terrain/terrainEdit.js +32 -27
  384. package/modules/terrain/terrainGen.js +17 -12
  385. package/modules/terrain/terrainIsland.js +2 -2
  386. package/modules/terrain/terrainMesh.js +7 -6
  387. package/modules/terrain/terrainShape.js +8 -10
  388. package/modules/terrain/terrainShapeMain.js +3 -3
  389. package/modules/timeline/Timeline.js +27 -19
  390. package/modules/timeline/Tween.js +6 -6
  391. package/modules/timeline/shots.js +5 -7
  392. package/modules/triggers/index.js +9 -9
  393. package/modules/vegetation/Vegetation.js +30 -23
  394. package/modules/vegetation/densityMap.js +4 -7
  395. package/modules/vegetation/draw.js +23 -18
  396. package/modules/vegetation/groundChunks.js +11 -31
  397. package/modules/vegetation/index.js +8 -6
  398. package/modules/vegetation/modelGeometry.js +3 -6
  399. package/modules/vegetation/nearFade.js +1 -1
  400. package/modules/water/Water.js +16 -16
  401. package/modules/water/surface.js +3 -3
  402. package/modules/weather/Weather.js +41 -30
  403. package/modules/weather/particles.js +8 -8
  404. package/modules/weather/weatherDraw.js +22 -18
  405. package/modules/world/World.js +8 -8
  406. package/modules/world/explain.js +1 -1
  407. package/modules/world/index.js +18 -12
  408. package/modules/world/persist.js +73 -25
  409. package/modules/world/pos.js +4 -4
  410. package/modules/world/records.js +28 -8
  411. package/modules/world/sim.js +4 -4
  412. package/modules/world/state.js +12 -5
  413. package/modules/world/thingSource.js +4 -2
  414. package/modules/world/views.js +11 -9
  415. package/package.json +42 -7
  416. package/presets.js +1 -3
  417. package/render/PostFX.js +39 -27
  418. package/render/backend.js +26 -32
  419. package/render/cascades.js +17 -12
  420. package/render/cascades.tsl.js +5 -8
  421. package/render/daylight.js +20 -3
  422. package/render/detail.js +8 -7
  423. package/render/effects.js +28 -25
  424. package/render/fuse.js +3 -3
  425. package/render/fx/cloudShadow.tsl.js +3 -3
  426. package/render/fx/detail.tsl.js +1 -1
  427. package/render/fx/index.js +5 -10
  428. package/render/fx/library.tsl.js +11 -0
  429. package/render/fx/lighting.tsl.js +2 -1
  430. package/render/fx/nodeErrors.tsl.js +2 -2
  431. package/render/fx/objectOrigin.tsl.js +1 -2
  432. package/render/fx/patchNodes.tsl.js +5 -15
  433. package/render/fx/postWebGPU.tsl.js +27 -23
  434. package/render/fx/sky.tsl.js +15 -17
  435. package/render/fx/uniforms.tsl.js +4 -4
  436. package/render/fx/wind.tsl.js +1 -1
  437. package/render/fxNumbers.js +3 -0
  438. package/render/layers.js +1 -1
  439. package/render/lighting.js +5 -3
  440. package/render/lightmap.js +20 -20
  441. package/render/lights.js +6 -6
  442. package/render/lit.js +24 -0
  443. package/render/materials.js +8 -7
  444. package/render/mergeCommon.js +22 -0
  445. package/render/modeling.js +2 -2
  446. package/render/occlusion.js +20 -4
  447. package/render/ownFrame.js +4 -4
  448. package/render/patches.js +13 -13
  449. package/render/postWebGL.js +12 -10
  450. package/render/probes.js +16 -19
  451. package/render/recordSweep.js +117 -0
  452. package/render/shaderErrors.js +10 -9
  453. package/render/shadowCache.tsl.js +107 -0
  454. package/render/shadowTypes.js +9 -0
  455. package/{core → render}/shadows.js +57 -11
  456. package/render/slots.js +7 -7
  457. package/render/terms.js +22 -24
  458. package/render/uniformDecl.js +1 -1
  459. package/types/core.d.ts +200 -153
  460. package/types/gameplay.d.ts +163 -91
  461. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  462. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  463. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  464. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +7 -15
  465. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  466. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  467. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +12 -8
  468. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  469. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
  470. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
  471. package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
  472. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
  473. package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
  474. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  475. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
  476. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  477. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
  478. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  479. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  480. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  481. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  482. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  483. package/types/generated/modules/grid/Layer.d.ts +1 -1
  484. package/types/generated/modules/grid/index.d.ts +3 -3
  485. package/types/generated/modules/music/Music.d.ts +7 -5
  486. package/types/generated/modules/particles/Particles.d.ts +1 -1
  487. package/types/generated/modules/sky/Sky.d.ts +21 -10
  488. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  489. package/types/generated/modules/timeline/Timeline.d.ts +2 -1
  490. package/types/generated/modules/water/Water.d.ts +1 -0
  491. package/types/generated/modules/weather/Weather.d.ts +16 -12
  492. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  493. package/types/generated/modules/world/World.d.ts +5 -3
  494. package/types/generated/render/PostFX.d.ts +17 -11
  495. package/types/generated/render/materials.d.ts +1 -0
  496. package/types/generated/render/occlusion.d.ts +9 -0
  497. package/types/generated/render/patches.d.ts +1 -0
  498. package/types/generated/ui/Focus.d.ts +1 -0
  499. package/types/generated/ui/UI.d.ts +1 -0
  500. package/types/nav.d.ts +11 -11
  501. package/types/physics.d.ts +99 -70
  502. package/types/tsl.d.ts +37 -4
  503. package/types/world.d.ts +38 -71
  504. package/ui/Focus.js +10 -9
  505. package/ui/Parts.js +4 -3
  506. package/ui/UI.js +7 -7
  507. package/ui/defaults.js +3 -2
  508. package/ui/theme.js +5 -3
  509. package/core/assetEntry.js +0 -109
  510. package/core/holds.js +0 -134
  511. package/core/shadowTypes.js +0 -16
  512. package/core/util.js +0 -17
  513. package/docs/MIGRATING-0.3.md +0 -248
  514. package/docs/MIGRATING-0.4.md +0 -320
  515. package/docs/MIGRATING-0.5.md +0 -68
  516. package/docs/MIGRATING-0.6.md +0 -126
  517. package/docs/PERF.md +0 -245
  518. package/docs/recipes/36-sky-ground-plants.md +0 -158
  519. package/docs/recipes/37-terrain-hooks.md +0 -115
  520. package/docs/recipes/38-environment-hooks.md +0 -67
  521. package/docs/recipes/42-terrain-shape.md +0 -64
  522. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  523. package/docs/recipes/54-three-idioms.md +0 -88
  524. package/examples/plain-picture/FINDINGS.md +0 -53
  525. /package/core/{Vars.js → base/Vars.js} +0 -0
  526. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  527. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  528. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  529. /package/core/{actor.js → ops/actor.js} +0 -0
  530. /package/core/{opsFail.js → ops/opsFail.js} +0 -0
  531. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  532. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  533. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  534. /package/core/{tier.js → scene/tier.js} +0 -0
  535. /package/core/{cells.js → stream/cells.js} +0 -0
  536. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  537. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  538. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  539. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  540. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  541. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  542. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  543. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  544. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -6,7 +6,7 @@
6
6
  // - the GAME BINDS keys: createEngine({ bindings: { jump: ['Space'] } }), engine.input.bind('jump', ['Space']) or a whole preset map
7
7
  // engine.input.bind(presets.bindings.dialogNumbers). The basics (WASD / arrows move, confirm, cancel, UI cursor) are the one default preset.
8
8
  // - the PLAYER REBINDS: engine.input.rebind('jump', ['KeyJ']) (the settings menu calls it and saves it).
9
- // Keys are the shared point 'input.keys' (core/sharedPoint.js), one record per action: the default preset is its base, the game binds on the game
9
+ // Keys are the shared point 'input.keys' (core/ops/sharedPoint.js), one record per action: the default preset is its base, the game binds on the game
10
10
  // layer, the player's rebind on the settings layer (it replaces). describe().shared['input.keys[jump]'] says who bound what.
11
11
  // Two different owners binding one action is input-bound-twice in dev (with the fix); a module's bindings and declarations go with the module.
12
12
  // Reading an action nobody bound reports input-unbound once in dev (naming the one-line bind), unless its declaration said optional: true.
@@ -15,7 +15,7 @@
15
15
  // Gameplay (onFixed, module fixed) reads a snapshot taken at the start of each fixed step: reads within one step agree, and "just pressed" counts exactly once,
16
16
  // never lost, whatever the frame rate. UI keys and camera (onFrame, module frame) read this frame's latest state.
17
17
  // Contexts (inputContext.js): a stack, the top one wins. Base 'walk'; 'vehicle' passes unrelated actions through; 'dialog', 'menu', 'cutscene' are opaque.
18
- // Window blur / tab hide (page:blur from core/page.js) releases every held key.
18
+ // Window blur / tab hide (page:blur from core/engine/page.js) releases every held key.
19
19
  // engine.input.label('interact') -> "E" (UI hints); engine.input.axis -> { x, y } movement direction (moveLeft/Right/Forward/Back + sticks)
20
20
  //
21
21
  // Mouse buttons are keys too: 'Mouse0' left / 'Mouse1' middle / 'Mouse2' right (real mouse only; touch taps do not count); gamepad buttons are 'PadA' etc.
@@ -24,15 +24,15 @@
24
24
  // (click-to-move via screenToGround); clicked is true only on this frame and a drag does not count,
25
25
  // gameplay (fire, attack) must not read it; bind a Mouse0 action instead
26
26
 
27
- /** @import { Pointer, Autopilot } from '../types/core' */
28
- import { coded, codedError } from './errorHints.js';
29
- import { checkTypeRule } from './moduleTypes.js';
30
- import { warnMissing, warnOnce, missingText, DEV } from './validate.js';
27
+ /** @import { Pointer, Autopilot } from '../../types/core' */
28
+ import { coded, codedError } from '../base/errorHints.js';
29
+ import { checkTypeRule } from '../engine/moduleTypes.js';
30
+ import { warnMissing, warnOnce, missingText, DEV } from '../base/validate.js';
31
31
  import { touchButton } from './inputTouch.js';
32
32
  import { bindPointer } from './inputPointer.js';
33
33
  import { pollPad, keyLabel } from './inputPad.js';
34
34
  import { BASIC_KEYS, BASIC_LABELS, BOUND_LABELS } from './inputDefaults.js';
35
- import { initContexts, pushContext, readableMap, applyContexts, BASE_CONTEXT } from './inputContext.js';
35
+ import { initContexts, pushContext, readableMap, applyContexts, settledStack, BASE_CONTEXT } from './inputContext.js';
36
36
 
37
37
  const NONE = Object.freeze([]);
38
38
  const ACTION_OPTS = ['context', 'label', 'optional', 'keys', 'owner'];
@@ -52,13 +52,14 @@ export class Input {
52
52
  /** @internal */ this._fx = { keys: new Set(), pressed: new Set(), released: new Set(), x: 0, y: 0 }; // this fixed step's snapshot
53
53
  /** @internal */ this._live = { keys: this.keys, pressed: this.justPressed, released: this.justReleased };
54
54
  /** @internal */ this._inFixed = false;
55
+ /** @internal frames ended so far. A press lives until endFrame, so this is what "the same press" means to ui/Focus.js, from any fixed step or frame hook */ this.frameCount = 0;
55
56
  /** This frame's look-drag amount (pixels) and wheel notches */
56
57
  this.look = { dx: 0, dy: 0, zoom: 0 };
57
58
  /** Mouse/touch pointer @type {Pointer} */
58
59
  this.pointer = { x: 0, y: 0, ndcX: 0, ndcY: 0, down: false, clicked: false, button: 0 };
59
60
  /** Set by a camera that locks the mouse on click: true while the next mouse press would only lock it, so that press is not delivered as Mouse0 / a click @internal */
60
61
  this.swallowLockClick = /** @type {null | (() => boolean)} */ (null);
61
- /** On-screen stick (touch) */
62
+ /** On-screen stick (touch) @experimental */
62
63
  this.stick = { x: 0, y: 0 };
63
64
  /** Auto movement (stress tests, test scripts) @type {Autopilot | null} */
64
65
  this.autopilot = null;
@@ -72,9 +73,9 @@ export class Input {
72
73
  /** @internal */ this.padDeadzone = padDeadzone;
73
74
  /** @internal */ this.padLookSpeed = padLookSpeed;
74
75
  /** @internal */ this.padStick = { x: 0, y: 0 };
75
- /** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} */
76
+ /** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} @experimental */
76
77
  this.lastDevice = 'keyboard';
77
- /** Is this a touch device? */
78
+ /** Is this a touch device? @experimental */
78
79
  this.touch = matchMedia('(pointer: coarse)').matches;
79
80
  /** @internal touch buttons the game asked for [{ action, labelKey }]; drawn by the UI part 'touch' (inputTouch.js) */ this._touch = [];
80
81
  for (const a of Object.keys(BASIC_KEYS)) this.actions.set(a, { labelKey: BASIC_LABELS[a], context: BASE_CONTEXT, optional: false, by: 'engine' });
@@ -87,8 +88,8 @@ export class Input {
87
88
  if (e.code === 'Space' || e.code === 'Tab' || e.code.startsWith('Arrow')) e.preventDefault();
88
89
  }, { signal });
89
90
  addEventListener('keyup', e => this._keyUp(e.code), { signal });
90
- // Losing focus swallows the keyup events, so release everything when the page goes away (window blur or tab hidden; core/page.js owns those listeners)
91
- engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); });
91
+ // Losing focus swallows the keyup events, so release everything when the page goes away (window blur or tab hidden; core/engine/page.js owns those listeners)
92
+ engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); this._muted.clear(); }); // a muted key's keyup is lost the same way
92
93
 
93
94
  bindPointer(this, canvas, signal);
94
95
 
@@ -118,15 +119,19 @@ export class Input {
118
119
  + `Rule: an action belongs to one context. Fix: give one of them another name (e.g. '${owner}.${name}'), or declare it in the same context`);
119
120
  }
120
121
  // a second owner declaring the same action in the same context shares the first declaration (two modules may read one 'interact')
121
- const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner };
122
+ const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner, users: 0 };
122
123
  if (entry !== cur) this.actions.set(name, entry);
124
+ entry.users++;
123
125
  this._readable = null;
124
126
  const bound = keys !== undefined ? this.bind(name, keys, { owner }) : null;
125
127
  let gone = false;
126
128
  return { name, remove: () => {
127
129
  if (gone) return; gone = true;
128
130
  bound?.remove();
129
- if (this.actions.get(name) === entry && entry.by === owner) { this.actions.delete(name); this._readable = null; }
131
+ if (--entry.users !== 0 || this.actions.get(name) !== entry) return; // a sharing owner keeps it
132
+ // keys someone else bound stay readable: back to an action only bound, as bind() makes it
133
+ if (this._keys.size(name)) this.actions.set(name, { labelKey: entry.labelKey, context: BASE_CONTEXT, optional: false, by: null }); else this.actions.delete(name);
134
+ this._readable = null;
130
135
  } };
131
136
  }
132
137
  /**
@@ -147,15 +152,14 @@ export class Input {
147
152
  return { owner, remove: () => { for (const h of hs) h.remove(); } };
148
153
  }
149
154
  keys = [].concat(keys ?? NONE);
150
- if (keys.some(k => typeof k !== 'string' || !k)) throw codedError('bad-arg', `input.bind('${name}', ${JSON.stringify(keys)}): keys are key names like 'KeyE', 'Space', 'PadA', 'Mouse0'`, TypeError);
155
+ if (keys.some(k => typeof k !== 'string' || !k)) throw codedError('input-keys', `input.bind('${name}', ${JSON.stringify(keys)}): keys are key names like 'KeyE', 'Space', 'PadA', 'Mouse0'`, TypeError);
151
156
  if (!this.actions.has(name)) this.actions.set(name, { labelKey: BOUND_LABELS[name] || name, context: BASE_CONTEXT, optional: false, by: null });
152
157
  // checked here, before the shared point's own conflict rule, so the message talks about keys (mul / add make no sense for a key list)
153
158
  const other = this._keys.holders(name).find(h => h.layer === 'game' && h.owner !== owner);
154
159
  if (other && DEV) {
155
160
  throw codedError('input-bound-twice', `input.bind('${name}'): '${other.owner}' already binds it (${other.value.join(', ') || 'no key'}${other.at ? `, ${other.at}` : ''}), now '${owner}' binds ${keys.join(', ') || 'no key'}. `
156
- + `Rule: one owner binds an action. Fix: keep one of the two (drop the module's keys option, or the createEngine({ bindings }) entry), or bind another action name`);
161
+ + `Rule: one owner binds an action. Fix: keep one of the two binds, or bind another action name`);
157
162
  }
158
- this._readable = null;
159
163
  return this._keys.take({ owner, id: name, set: Object.freeze([...keys]), layer: 'game' });
160
164
  }
161
165
  /**
@@ -205,6 +209,7 @@ export class Input {
205
209
  /**
206
210
  * All keys bound to an action: the player's rebinding, else the game's bind, else the default preset (basics only); plus its touch button
207
211
  * @param {string} action @returns {readonly string[]}
212
+ * @experimental
208
213
  */
209
214
  keysOf(action) {
210
215
  const k = this._keys.value(action, BASIC_KEYS[action] ?? null) ?? NONE, t = this._touchKeys.get(action);
@@ -243,6 +248,7 @@ export class Input {
243
248
  /**
244
249
  * Just released (which copy is read is the same as pressed; for things like release-to-fire after charging) @param {string} action @returns {boolean}
245
250
  * @example if (engine.input.released('fire')) shoot(charge);
251
+ * @experimental
246
252
  */
247
253
  released(action) { return this._has(action, 'released'); }
248
254
  /**
@@ -272,13 +278,15 @@ export class Input {
272
278
  const unbound = [...this.actions.keys()].filter(n => this.isUnbound(n));
273
279
  return { stack: this._stack.map(c => (c.owner && c.owner !== c.name ? `${c.name}(owner: ${c.owner})` : c.name)), unbound, rebound: this.rebound() };
274
280
  }
275
- /** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} */
281
+ /** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} @experimental */
276
282
  get contexts() { return this._stack.map(c => c.name); }
277
283
  /**
278
- * Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read)
284
+ * Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read).
285
+ * Pushes and removes count at once, before the next fixed step applies them: on a halted page a closed window is not a holder any more
279
286
  * @returns {{ context: string, owner: string, pass: boolean }[]}
287
+ * @experimental
280
288
  */
281
- get holders() { return this._stack.slice(1).map(c => ({ context: c.name, owner: c.owner, pass: c.pass })); }
289
+ get holders() { return settledStack(this).slice(1).map(c => ({ context: c.name, owner: c.owner, pass: c.pass })); }
282
290
  /**
283
291
  * Close one action while anyone holds its gate (stun: no jump; a tutorial: no attack yet), without a whole input context. Same rules as every
284
292
  * engine.mod stack (it is the shared point 'input.gate', one entry per owner and action): only the owner opens it, { for } ends it by itself.
@@ -293,7 +301,7 @@ export class Input {
293
301
  return this.engine.mod('input.gate', { ...o, id: action });
294
302
  }
295
303
  /** @internal true while someone holds this action's gate */
296
- _gated(action) { const g = this._gateStack ??= this.engine.stacks?.has('input.gate') ? this.engine.stacks.get('input.gate') : null; return !!g && g.size(action) > 0; }
304
+ _gated(action) { return (this._gateStack ??= this.engine.stacks.get('input.gate')).size(action) > 0; }
297
305
  /**
298
306
  * False while an opaque context (menu, dialogue, cutscene...) covers gameplay: no game action can be read, and cameras ignore picture/zoom @returns {boolean}
299
307
  */
@@ -336,5 +344,5 @@ export class Input {
336
344
 
337
345
 
338
346
  /** @internal */
339
- endFrame() { this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
347
+ endFrame() { this.frameCount++; this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
340
348
  }
@@ -1,4 +1,4 @@
1
- import { codedError } from './errorHints.js';
1
+ import { codedError } from '../base/errorHints.js';
2
2
  // Input contexts. Like Unity Action Maps: a stack of named groups of actions. The top context shadows lower ones that bind the same key;
3
3
  // an opaque context (the default) blocks everything below it, a `pass` context lets unrelated actions through. Menus, dialogue, cutscenes and
4
4
  // full-screen UI push an opaque context instead of "locking input", so there is one mechanism, not two.
@@ -50,15 +50,24 @@ export function readableMap(input) {
50
50
  return input._readable = m;
51
51
  }
52
52
 
53
+ /** Queued pushes and removes played onto a stack @internal */
54
+ function playQueue(q, stack) {
55
+ for (const op of q) {
56
+ if (op.add) stack.push(op.add);
57
+ else { const i = stack.indexOf(op.del); if (i > 0) stack.splice(i, 1); }
58
+ }
59
+ return stack;
60
+ }
61
+
62
+ /** The stack as the next fixed step will leave it: what reports read, because a halted page may wait long for that step @internal */
63
+ export function settledStack(input) { return playQueue(input._pendingCtx, input._stack.slice()); }
64
+
53
65
  /** Apply queued push/remove at the start of a fixed step; held keys of newly blocked actions are cleared (a key stays dead until released) @internal */
54
66
  export function applyContexts(input) {
55
67
  const q = input._pendingCtx;
56
68
  if (!q.length) return;
57
69
  const before = readableMap(input);
58
- for (const op of q) {
59
- if (op.add) input._stack.push(op.add);
60
- else { const i = input._stack.indexOf(op.del); if (i > 0) input._stack.splice(i, 1); }
61
- }
70
+ playQueue(q, input._stack);
62
71
  q.length = 0;
63
72
  input._readable = null;
64
73
  const after = readableMap(input);
@@ -30,6 +30,6 @@ export function keyLabel(input, action) {
30
30
  const pad = keys.filter(k => k.startsWith('Pad')), kb = keys.filter(k => !k.startsWith('Pad'));
31
31
  const use = input.lastDevice === 'pad' && pad.length ? pad : kb.length ? kb : pad;
32
32
  // Key names go through the string table too (key.Space -> its localized name); fall back to the generic form if missing
33
- const name = k => input.engine.i18n?.has('key.' + k) ? input.engine.t('key.' + k) : keyName(k);
33
+ const name = k => input.engine.i18n.has('key.' + k) ? input.engine.t('key.' + k) : keyName(k);
34
34
  return use.map(name).filter((v, i, arr) => arr.indexOf(v) === i).join('/');
35
35
  }
@@ -1,9 +1,15 @@
1
1
  // The mouse / touch pointer part of input: drag to look, wheel to zoom, pointer state; mouse buttons act as keys (Mouse0 left / Mouse1 middle / Mouse2 right) passed to Input's _keyDown / _keyUp,
2
2
  // the same path as the keyboard, so they can be defined as actions and enter the fixed-step snapshot. Touch taps are not mouse buttons (pointerType only accepts 'mouse').
3
3
 
4
+ /** e.button -> its bit in e.buttons (middle and right are the other way round) */
5
+ const BUTTON_BITS = [1, 4, 2, 8, 16];
6
+
4
7
  /** Wire pointer events on the canvas to input (called once when Input is constructed). signal: engine.dispose() cancels all listeners at once */
5
8
  export function bindPointer(input, canvas, signal) {
6
9
  let drag = null;
10
+ // A second button pressed or released while another is held fires no pointerdown / pointerup, only a pointermove with e.button set (chorded
11
+ // buttons), and pointerup comes for the last button alone: e.buttons is the one true list. A shooter's aim + fire needs it, and a Mouse0 stuck down is the other half
12
+ const chord = e => { if (e.pointerType === 'mouse') BUTTON_BITS.forEach((bit, b) => { if (e.buttons & bit) input._keyDown('Mouse' + b, 'keyboard'); else input._keyUp('Mouse' + b); }); };
7
13
  // pointer x / y are pixels from the canvas content box's top-left, ndc is -1..1 across that box: a canvas in a page section or editor
8
14
  // panel picks the thing under the mouse, not the thing under the same window position. Read on every event (the canvas may have moved)
9
15
  const place = e => {
@@ -24,8 +30,8 @@ export function bindPointer(input, canvas, signal) {
24
30
  if (document.pointerLockElement !== canvas) canvas.setPointerCapture(e.pointerId);
25
31
  }, { signal });
26
32
  canvas.addEventListener('pointermove', e => {
27
- const p = input.pointer;
28
33
  place(e);
34
+ if (e.button >= 0 && drag && !drag.swallowed) chord(e); // -1 on a plain move
29
35
  if (!drag || drag.id !== e.pointerId) return;
30
36
  const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
31
37
  if (document.pointerLockElement === canvas) return;
@@ -39,7 +45,7 @@ export function bindPointer(input, canvas, signal) {
39
45
  drag = null;
40
46
  if (swallowed) return;
41
47
  input.pointer.down = false;
42
- if (e.pointerType === 'mouse') input._keyUp('Mouse' + e.button);
48
+ chord(e);
43
49
  };
44
50
  canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
45
51
  // if the right button is bound to an action, do not show the browser menu
@@ -2,7 +2,7 @@
2
2
  // Drawing is the UI part 'touch' (default ui/touchPart.js); a game replaces it or turns it off with createEngine({ ui: { touch: ... } }).
3
3
  // press / release go to Input's _keyDown / _keyUp as the key 'Touch:<action>', the same path as real keys (snapshot and just-pressed behave identically).
4
4
  /** @import { Input } from './Input.js' */
5
- /** @import { TouchView } from '../types/core' */
5
+ /** @import { TouchView } from '../../types/core' */
6
6
 
7
7
  /**
8
8
  * Touch button: registers the key 'Touch:<action>' on the action and asks the touch part to draw a button (touch devices only)
@@ -5,14 +5,14 @@
5
5
  // Categories: drawCalls, triangles, textures, cpuMs, fps, low1 (fps and low1 are lower bounds) + registered metrics (lights, shadowLights, shadowMaps, shadowMapSize, chunkApplyMs, rigidBodies...)
6
6
  // + the apply-cost stages (applyTransitMs, applyBuildMs, applyColliderMs, applyUploadMs, applyStreamMs: ms per frame, see ApplyCost).
7
7
  // "Who uses the most": draw calls are estimated by the userData.budgetTag of an object (or its parent); untagged counts as 'other'.
8
- /** @import { Handle } from '../types/common' */
9
- /** @import { BudgetLimits, BudgetReport, BudgetTagStat } from '../types/world' */
10
- import { coded } from './errorHints.js';
11
- import { fmt, warnOnce } from './validate.js';
12
- import { r1 } from './math.js';
13
- import { SHADOW_TYPES } from './shadowTypes.js';
8
+ /** @import { Handle } from '../../types/common' */
9
+ /** @import { BudgetLimits, BudgetReport, BudgetTagStat } from '../../types/world' */
10
+ import { coded } from '../base/errorHints.js';
11
+ import { fmt, warnOnce } from '../base/validate.js';
12
+ import { r1 } from '../base/math.js';
13
+ import { SHADOW_TYPES } from '../../render/shadowTypes.js';
14
14
  import * as THREE from 'three';
15
- import { stats, shadowMaps } from '../render/backend.js';
15
+ import { stats, shadowMaps } from '../../render/backend.js';
16
16
 
17
17
  const STRINGS = {
18
18
  startup: 'Startup took {value} ms, over budget startupMs {limit} ms; slowest module: {top}',
@@ -28,14 +28,6 @@ const STAGES = ['transit', 'build', 'collider', 'upload', 'stream'];
28
28
  const EMA = 0.1; // per-frame smoothing, the same factor chunkApplyMs always used
29
29
  const COMPILES_KEPT = 20; // compile-stall frames remembered by ApplyCost.compiles
30
30
 
31
- /**
32
- * engine.budget.cost: where the main thread pays for background results (terrain chunks, vegetation, colliders, stream builds), split in stages.
33
- * Always on (a few performance.now() calls per applied result). Stages: transit = worker round trip minus the worker's own compute (queueing,
34
- * structured clone, waiting for a busy main thread: an async wait, not main-thread blocking, so it is an approximation); build = creating the
35
- * three.js objects (geometry, meshes, instanced meshes); collider = physics colliders; upload = GPU upload and shader compile, approximated as the
36
- * extra render time of frames that first draw new objects over the average render time of other frames; stream = the synchronous part of a stream
37
- * build() callback.
38
- */
39
31
  /** Bytes of the typed arrays in a plain result object, `depth` levels down @param {any} v @param {number} depth @returns {number} */
40
32
  function arrayBytes(v, depth) {
41
33
  if (ArrayBuffer.isView(v)) return v.byteLength;
@@ -45,7 +37,15 @@ function arrayBytes(v, depth) {
45
37
  return n;
46
38
  }
47
39
 
48
- export class ApplyCost {
40
+ /**
41
+ * engine.budget.cost: where the main thread pays for background results (terrain chunks, vegetation, colliders, stream builds), split in stages.
42
+ * Always on (a few performance.now() calls per applied result). Stages: transit = worker round trip minus the worker's own compute (queueing,
43
+ * structured clone, waiting for a busy main thread: an async wait, not main-thread blocking, so it is an approximation); build = creating the
44
+ * three.js objects (geometry, meshes, instanced meshes); collider = physics colliders; upload = GPU upload and shader compile, approximated as the
45
+ * extra render time of frames that first draw new objects over the average render time of other frames; stream = the synchronous part of a stream
46
+ * build() callback.
47
+ */
48
+ class ApplyCost {
49
49
  /** @internal */
50
50
  constructor() {
51
51
  /** @internal */ this.t = {};
@@ -110,7 +110,7 @@ export class Budget {
110
110
  /** @internal */ this.engine = engine;
111
111
  /** Is it on? */
112
112
  this.enabled = false;
113
- /** Current limits @type {BudgetLimits} */
113
+ /** Current limits @type {BudgetLimits} @experimental */
114
114
  this.limits = {};
115
115
  /** @internal Module-defined categories: name -> { read, limit } @type {Map<string, { read: () => number, limit?: number }>} */
116
116
  this.metrics = new Map();
@@ -131,7 +131,7 @@ export class Budget {
131
131
  * @example engine.budget.enable({ drawCalls: 250, fps: 55 });
132
132
  */
133
133
  enable(limits = {}) { this.enabled = true; this.limits = { ...limits }; this._dts = []; this._cpu = []; this._last = null; return this; }
134
- /** Turn off */
134
+ /** Turn off @experimental */
135
135
  disable() { this.enabled = false; this._last = null; }
136
136
  /**
137
137
  * Module-defined category: read() returns the current value, opts.limit is the limit (the game's enable() takes precedence). Returns a handle { remove() }
@@ -145,13 +145,13 @@ export class Budget {
145
145
  this.metrics.set(name, m);
146
146
  return { remove: () => { if (this.metrics.get(name) === m) this.metrics.delete(name); } };
147
147
  }
148
- /** Limit of a category; undefined if none was given (not checked) @param {string} name @returns {number | undefined} */
148
+ /** Limit of a category; undefined if none was given (not checked) @param {string} name @returns {number | undefined} @experimental */
149
149
  limitOf(name) { return this.limits[name] ?? this.metrics.get(name)?.limit; }
150
150
 
151
151
  /** @internal Called by the engine after each rendered frame: records frame time, checks once a second, and warns once per category over its limit */
152
152
  sample(dt) {
153
153
  if (!this.enabled) return;
154
- this._dts.push(dt); this._cpu.push(this.engine.cpuMs ?? 0);
154
+ this._dts.push(dt); this._cpu.push(this.engine._cpuMs ?? 0);
155
155
  if (this._dts.length > WINDOW) { this._dts.shift(); this._cpu.shift(); }
156
156
  if ((this._t += dt) < 1) return;
157
157
  this._t = 0;
@@ -170,6 +170,7 @@ export class Budget {
170
170
  * Called by the engine when startup finishes: warns if startupMs / moduleMs is exceeded and returns the offenders (empty array if none)
171
171
  * @param {{ totalMs: number, modules: Record<string, { init?: number, ready?: number }> }} s
172
172
  * @returns {{ category: 'startupMs' | 'moduleMs', value: number, limit: number, top: { tag: string, ms: number }[] }[]}
173
+ * @experimental
173
174
  */
174
175
  checkStartup(s) {
175
176
  if (!this.enabled) return [];
@@ -6,11 +6,16 @@
6
6
  // One chain: every material / visibility change, from override() and from a view, is an entry in this._l. Removing any entry undoes the whole chain
7
7
  // in reverse and re-applies the rest in order, so a view and an override on the same mesh can never restore each other's stale material, and nothing
8
8
  // here disposes a material it did not create (stand-ins are cached on the original, so the original is never touched).
9
- import { codedError } from './errorHints.js';
9
+ import { MeshBasicMaterial } from 'three';
10
+ import { allowOwned } from '../ops/owned.js';
11
+ import { reportError } from '../base/errors.js';
12
+ import { codedError } from '../base/errorHints.js';
10
13
  import { DebugView } from './debugView.js';
11
- import { isWebGPU, webgpuPart } from '../render/backend.js';
12
- import { reloadGlsl } from '../render/hotGlsl.js';
13
- import { reloadAssets } from './assetHot.js';
14
+ import { isWebGPU, webgpuPart } from '../../render/backend.js';
15
+ import { reloadGlsl } from '../../render/hotGlsl.js';
16
+ import { reloadAssets } from '../assets/assetHot.js';
17
+ import { hex } from './MaterialInfo.js';
18
+ import { isUnder } from '../base/util.js';
14
19
 
15
20
  const KEYS = ['visible', 'material', 'apply'];
16
21
  const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is internal: it needs patch.colorOf
@@ -19,13 +24,14 @@ const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is interna
19
24
  function meshes(obj) { const out = []; obj.traverse(o => { if (o.isMesh || o.isPoints || o.isLine) out.push(o); }); return out; }
20
25
  const patchInfo = p => ({ ...p, ...(p.apply && { apply: 'function' }) });
21
26
  /** A value in describe(): plain data as is, a three.js object by its type (describe() stays JSON) */
22
- const plain = v => (v === null || typeof v !== 'object' ? v : v.isColor ? `#${v.getHexString()}` : `<${v.type ?? 'object'}>`);
27
+ const plain = v => (v === null || typeof v !== 'object' ? v : v.isColor ? hex(v) : `<${v.type ?? 'object'}>`);
23
28
 
24
29
  export class DebugOverrides {
25
30
  /** @internal */
26
31
  constructor(e) {
27
32
  /** @internal */ this.e = e;
28
33
  /** @internal the override chain, in apply order */ this._l = [];
34
+ /** @internal material -> { kind: stand-in } */ this._stands = new WeakMap();
29
35
  /** @internal */ this._view = new DebugView(e, this);
30
36
  /** The F3 debug panel (the debug() module), or null when it is not installed @type {any} */
31
37
  this.panel = null;
@@ -63,7 +69,7 @@ export class DebugOverrides {
63
69
  * Asset hot swap: register the asset packs again (the new module of an edited assets.js) and build what changed (a new generator function,
64
70
  * url or params schema); every live copy swaps geometry and material in place, the page, player, clock and world state stay. The vite preset
65
71
  * calls it when an art module imported by the game's assets.js is saved; returns what was swapped (also in describe().assetSwaps).
66
- * @example import packs from './assets.js'; if (import.meta.hot) import.meta.hot.accept('./assets.js', m => engine.debug.reloadAssets(m.default));
72
+ * @example import packs from '../assets.js'; if (import.meta.hot) import.meta.hot.accept('./assets.js', m => engine.debug.reloadAssets(m.default));
67
73
  * @param {any} packs @returns {Promise<{ why: string, names: string[], copies: Record<string, number>, ms: number, partsChanged?: string[] }>}
68
74
  */
69
75
  reloadAssets(packs) { return reloadAssets(this.e, packs); }
@@ -87,7 +93,8 @@ export class DebugOverrides {
87
93
  override(owner, target, patch, value) {
88
94
  if (!owner || typeof owner !== 'string') throw codedError('debug-override', "engine.debug.override(owner, target, patch): owner is a non-empty string naming who sets it, e.g. 'ai-session', so engine.debug.clear(owner) can remove it");
89
95
  if (typeof patch === 'string') return this._value(owner, target, patch, value);
90
- for (const k of Object.keys(patch ?? {})) if (!KEYS.includes(k)) throw codedError('debug-override', `engine.debug.override: unknown field '${k}'. Fields: ${KEYS.join(', ')}, e.g. { visible: false } or { material: 'flat' }`);
96
+ if (!patch || typeof patch !== 'object') throw codedError('debug-override', `engine.debug.override(owner, target, patch): patch is a field name with a value, or { ${KEYS.join(', ')} }; got ${patch}`);
97
+ for (const k of Object.keys(patch)) if (!KEYS.includes(k)) throw codedError('debug-override', `engine.debug.override: unknown field '${k}'. Fields: ${KEYS.join(', ')}, e.g. { visible: false } or { material: 'flat' }`);
91
98
  if (patch.material !== undefined && !MATERIALS.includes(patch.material)) throw codedError('debug-override', `engine.debug.override: material must be ${MATERIALS.map(m => `'${m}'`).join(' or ')} (unlit base colour / wireframe), got ${JSON.stringify(patch.material)}`);
92
99
  const byId = typeof target === 'string';
93
100
  const obj = /** @type {any} */ (target)?.isObject3D ? target : this.e.thing(target).object;
@@ -107,7 +114,7 @@ export class DebugOverrides {
107
114
  /** Active overrides as plain data (describe().scene.overrides) */
108
115
  overrides() {
109
116
  this._prune();
110
- return [...this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) }))];
117
+ return this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) }));
111
118
  }
112
119
  /** @internal One three.js value on the chain: written now and again before each draw, so picture code that writes it per frame does not end the diagnosis */
113
120
  _value(owner, obj, key, value) {
@@ -119,10 +126,13 @@ export class DebugOverrides {
119
126
  if (now != null && value != null && typeof now !== typeof value) throw say(`'${key}' holds a ${typeof now}, got ${typeof value}${now.isColor ? ': pass a THREE.Color' : ''}`);
120
127
  if (value === undefined) throw say(`give the value for '${key}' (null to clear it)`);
121
128
  const apply = o => {
129
+ // allowed: a diagnostic is no game write, so the engine keeps driving an owned value (camera.far, tone) once the override ends
130
+ // put is the exemption's owner: one per override, so two overrides of one key on two objects do not end each other's
122
131
  const was = o[key], put = () => { o[key] = value; };
132
+ allowOwned(put, [o]);
123
133
  put();
124
134
  const h = this.e.onRender(put);
125
- return () => { h.remove(); o[key] = was; };
135
+ return () => { h.remove(); o[key] = was; allowOwned(put, false); };
126
136
  };
127
137
  return this._add({ owner, id: `${label}.${key}`, byId: false, obj, patch: { key, value: plain(value), apply }, undo: null });
128
138
  }
@@ -141,7 +151,7 @@ export class DebugOverrides {
141
151
  _drop(o) { if (this._l.includes(o)) this._rebuild(() => { this._l = this._l.filter(x => x !== o); }); }
142
152
  /** @internal Undo the whole chain newest first, change the list, re-apply in order: no entry ever restores a value another entry set after it */
143
153
  _rebuild(change) {
144
- for (const x of [...this._l].reverse()) { x.undo?.(); x.undo = null; }
154
+ for (const x of [...this._l].reverse()) { try { x.undo?.(); } catch (err) { reportError(this.e, err, `undo of debug override ${x.id ?? x.owner}`, { soft: true }); } x.undo = null; }
145
155
  change();
146
156
  const keep = [];
147
157
  for (const x of this._l) { try { this._apply(x); keep.push(x); } catch { /* an apply that throws now (its object was disposed) is dropped */ } }
@@ -158,30 +168,34 @@ export class DebugOverrides {
158
168
  const { patch, obj } = o, undos = [];
159
169
  const undo = () => { for (const u of undos.reverse()) u(); };
160
170
  try {
161
- if (patch.visible !== undefined) { const was = obj.visible; obj.visible = patch.visible; undos.push(() => { obj.visible = was; }); }
171
+ // each undo puts back only what is still ours: a swap the game made meanwhile (a hit flash, a model change) stays
172
+ if (patch.visible !== undefined) { const was = obj.visible; obj.visible = patch.visible; undos.push(() => { if (obj.visible === patch.visible) obj.visible = was; }); }
162
173
  if (patch.material) {
163
174
  for (const m of meshes(obj)) {
164
175
  const was = m.material;
165
176
  if (!was) continue;
166
177
  m.material = Array.isArray(was) ? was.map(x => this._stand(x, patch.material, patch.colorOf)) : this._stand(was, patch.material, patch.colorOf);
167
- undos.push(() => { m.material = was; });
178
+ const put = m.material;
179
+ undos.push(() => { if (m.material === put) m.material = was; });
168
180
  }
169
181
  }
170
182
  if (patch.apply) { const u = patch.apply(obj); if (typeof u === 'function') undos.push(u); }
171
183
  } catch (err) { undo(); throw err; }
172
184
  o.undo = undo;
173
185
  }
174
- /** @internal One cached unlit stand-in per material and kind, kept on the original's userData (we created it; the original is never disposed here) */
186
+ /** @internal One cached unlit stand-in per material and kind. Beside the material, not on its userData: the stand-in points back (_dbgOf), and three's material.clone()
187
+ * writes userData through JSON, which threw on the circle for the rest of the session */
175
188
  _stand(m, kind, colorOf) {
176
189
  if (m.userData._dbgOf) m = m.userData._dbgOf; // already a stand-in (a view under an override): derive from the original, never stack copies
177
- const cache = m.userData._dbg ??= {};
190
+ let cache = this._stands.get(m);
191
+ if (!cache) this._stands.set(m, cache = {});
178
192
  if (cache[kind]) { if (colorOf) cache[kind].color.setHex(colorOf(m)); return cache[kind]; }
179
193
  // a plain material on purpose: a diagnostic stand-in must not depend on the style it is diagnosing (rule 1 allows dev-only debug overlays)
180
194
  // on WebGPURenderer a MeshBasicNodeMaterial carrying the material's shape nodes (a NodeMaterial's own, or a patched material's tsl chain): a
181
195
  // plain stand-in would drop positionNode / vertexNode, so swaying trees froze and TSL-displaced meshes changed shape in the very view meant to
182
196
  // show them; colorNode is its base color (not for cost)
183
197
  const Node = isWebGPU(this.e.renderer) ? webgpuPart('classes', 'debug.view').MeshBasicNodeMaterial : null;
184
- const s = new (Node ?? this.e.THREE.MeshBasicMaterial)({ color: colorOf ? colorOf(m) : m.color ?? 0xffffff, map: colorOf ? null : m.map ?? null, alphaMap: m.alphaMap ?? null, vertexColors: !!m.vertexColors,
198
+ const s = new (Node ?? MeshBasicMaterial)({ color: colorOf ? colorOf(m) : m.color ?? 0xffffff, map: colorOf ? null : m.map ?? null, alphaMap: m.alphaMap ?? null, vertexColors: !!m.vertexColors,
185
199
  transparent: !!m.transparent, opacity: m.opacity ?? 1, side: m.side, alphaTest: m.alphaTest ?? 0, wireframe: kind === 'wire', fog: false });
186
200
  if (Node) { s.positionNode = m.positionNode ?? null; s.vertexNode = m.vertexNode ?? null; if (!colorOf) s.colorNode = m.colorNode ?? null; }
187
201
  s.name = `debug:${kind}:${m.name || ''}`; s.userData._dbgOf = m;
@@ -190,4 +204,4 @@ export class DebugOverrides {
190
204
  }
191
205
 
192
206
  /** True while obj hangs under the scene (a removed thing is detached) */
193
- function inScene(obj, scene) { for (let o = obj; o; o = o.parent) if (o === scene) return true; return !scene; }
207
+ function inScene(obj, scene) { return !scene || isUnder(obj, scene); }
@@ -14,30 +14,32 @@
14
14
  // ctx.near(at, info, weak): reports for the same `at` (same object) are merged; with weak = true only missing fields are filled (used by the interaction module).
15
15
  // Display names (ground type, weather name) are not hard-coded here: they come from the string table, ground.<type> and weather.<name> (registered by the terrain and weather modules), and go into groundName / label.
16
16
  // describeText, which turns this into text, lives in describeText.js.
17
+ import { Vector3 } from 'three';
17
18
  import { describeText } from './describeText.js';
18
- import { moduleRow } from './moduleTypes.js';
19
+ import { moduleRow } from '../engine/moduleTypes.js';
19
20
  import { inspect, explain } from './Inspect.js';
20
21
  import { inspectScene } from './InspectScene.js';
21
22
  import { inspectMaterials } from './InspectMaterials.js';
22
23
  import { inspectPerf } from './InspectPerf.js';
23
- import { codedError, coded } from './errorHints.js';
24
- import { r1 } from './math.js';
24
+ import { codedError, coded } from '../base/errorHints.js';
25
+ import { r1 } from '../base/math.js';
25
26
  import { describeRender, describePicture, describeBackend } from './describeRender.js';
26
- import { describeOwned, checkWrittenOnce } from './owned.js';
27
- import { describeScene } from './thingOps.js';
28
- import { describeHolds } from './holds.js';
29
- import { warnOnce } from './validate.js';
30
- import { stats } from '../render/backend.js';
31
- import { threePatches } from './threePatches.js';
32
- import { describeSlots } from './plugins.js';
27
+ import { describeOwned, checkWrittenOnce } from '../ops/owned.js';
28
+ import { describeScene } from '../scene/thingOps.js';
29
+ import { describeHolds } from '../ops/holds.js';
30
+ import { warnOnce } from '../base/validate.js';
31
+ import { stats } from '../../render/backend.js';
32
+ import { threePatches } from '../scene/threePatches.js';
33
+ import { describeSlots } from '../engine/plugins.js';
33
34
  /** describe().perf's draw counters (render/backend.js reads them per renderer) @param {any} r */
34
35
  const drawStats = r => { const s = stats(r); return { drawCalls: s.drawCalls, triangles: s.triangles }; };
35
36
 
36
37
  const NEAR_RADIUS = 30, NEAR_MAX = 15;
37
38
  const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; // north = -Z, east = +X
38
39
  const RELATIVE = ['front', 'front-right', 'right', 'back-right', 'back', 'back-left', 'left', 'front-left']; // relative to the camera heading
39
- const STANDARD = new Set(['ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'control']);
40
- const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters // the core's own fields
40
+ // the core's own fields
41
+ const STANDARD = new Set(['unhandled', 'holds', 'input', 'wraps', 'slots', 'threePatches', 'renderer', 'vars', 'ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'audio', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'control']);
42
+ const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters
41
43
  const sector = a => Math.round(((a % (Math.PI * 2)) + Math.PI * 2) / (Math.PI / 4)) % 8;
42
44
 
43
45
  /** Display name from the string table (prefix + key); null if missing (the text then uses the raw name) */
@@ -97,7 +99,7 @@ function pendingModules(e) {
97
99
 
98
100
  // Engine tables no module hook writes into (hooks add to time / player / camera / ui / perf / cutscene / nearby): a describe({ only }) that asks
99
101
  // for nothing else skips the hooks, describe.add and the action list
100
- const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer']);
102
+ const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'audio', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer']);
101
103
  const NONE = Symbol('none'); // a conditional section that is absent this time
102
104
 
103
105
  /**
@@ -116,13 +118,15 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
116
118
  disabledModules: () => [...e.disabledModules], // picture / ui modules disabled after an error
117
119
  moduleStates: () => pendingModules(e) ?? NONE, // while a module is initializing or failed
118
120
  loading: () => e.loading.view(), // what is pending / failed and whether it blocks the start (Loading.js)
119
- time: () => ({ tick: e.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now), paused: e.paused, frozen: e.frozen, ...(e.frozen ? { frozenBy: e.stacks.get('freeze').names() } : {}), headless: e.headless, run: e.runState,
121
+ time: () => ({ tick: e.time.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now), halted: e.halted, frozen: e.frozen, ...(e.frozen ? { frozenBy: e.stacks.get('freeze').names() } : {}), headless: e.headless, run: e.runState,
120
122
  channels: e.time.describe(), rate: e.clock.rate }),
121
- holds: () => describeHolds(e), // who holds pause / freeze / camera / input (holds.js)
123
+ audio: () => { const i = e.audio?.info; return i && (Object.values(i.ducks).some(v => v !== 1) || Object.keys(i.voices).length) ? { ducks: i.ducks, voices: i.voices, state: i.state } : NONE; }, // only while a duck or a voice is active; ducks = target level per bus (Audio.info)
124
+ holds: () => describeHolds(e), // who holds halt / freeze / camera / input (holds.js)
122
125
  input: () => e.input.describe(), // context stack, declared actions nobody bound, the player's rebindings (Input.js)
123
126
  control: () => e.control.describe(), // who decides where each held character goes: { id: { owner, layer, waiting } } (control.js)
124
127
  shared: () => e.stacks.describe(), // every shared value / slot with entries: value, writer, how it combined, who else wants it (stacks.js)
125
128
  wraps: () => { const w = e._wraps?.describe(); return w && Object.keys(w).length ? w : NONE; }, // engine.wrap: { 'inventory.add': [owners, outermost first] }
129
+ vars: () => ({ flags: { ...e.vars.flags }, counters: { ...e.vars.counters } }), // story state: without it a snapshot said "same" after a flag was set
126
130
  player: () => p ? {
127
131
  x: r1(p.x), y: r1(p.y), z: r1(p.z),
128
132
  ground: e.groundType(p.x, p.z),
@@ -130,24 +134,24 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
130
134
  inWater: e.waterAt(p.x, p.z) > p.y,
131
135
  state: e.player.state ?? null, // the character module's own state name ('walk', 'jump'...): core passes it on and never interprets it
132
136
  } : null,
133
- // projection: engine.camera is an EngineCamera (core/engineCamera.js) that a rig may switch to orthographic; said here so the switch is never hidden
137
+ // projection: engine.camera is an EngineCamera (core/scene/engineCamera.js) that a rig may switch to orthographic; said here so the switch is never hidden
134
138
  camera: () => ({ type: null, projection: cam.orthoSize ? 'orthographic' : 'perspective', ...(cam.orthoSize ? { orthoSize: r1(cam.orthoSize) } : {}), x: r1(cam.position.x), y: r1(cam.position.y), z: r1(cam.position.z),
135
139
  focus: { x: r1(e.focus.x), z: r1(e.focus.z) }, override: e.cameraOverride?.owner ?? null }),
136
140
  nearbyRadius: () => radius,
137
141
  nearby: () => [],
138
- ui: () => ({ windows: [...e.openWindows], inputLocked: !e.input.enabled, dialogue: null, parts: e.ui.describe() }), // windows include full-screen UI parts (title); parts: default / custom / off
142
+ ui: () => ({ windows: [...e._openWindows], inputLocked: !e.input.enabled, dialogue: null, parts: e.ui.describe() }), // windows include full-screen UI parts (title); parts: default / custom / off
139
143
  cutscene: () => null,
140
144
  modules: () => [...e.modules.values()].map(moduleRow), // { name, type, provides?, requires? } in install order (moduleTypes.js)
141
145
  slots: () => describeSlots(e), // what is plugged in where, from which file, what it affects (plugins.js)
142
146
  scene: () => describeScene(e), // engine.add / world things: counts by save tier and what will not survive a load (thingOps.js)
143
- threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/threePatches.js)
147
+ threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/scene/threePatches.js)
144
148
  owned: () => describeOwned(e), // every property the engine writes on its own and who writes it now (owned.js)
145
149
  render: () => describeRender(e), // renderer / post / lights and who set each (describeRender.js)
146
150
  picture: () => describePicture(e), // tone, fog, environment, background, lights, shadows as three.js holds them now (describeRender.js)
147
151
  renderer: () => describeBackend(e), // asked for, drawing, why not WebGPU and what that backend can run (describeRender.js)
148
152
  perf: () => ({
149
- fps: e.paused ? null : Math.round(e.fps), cpuMs: e.paused ? null : r1(e.cpuMs),
150
- cpu: e.paused ? null : Object.fromEntries(Object.entries(e.cpuPhases).map(([k, v]) => [k, r1(v)])),
153
+ fps: e.halted ? null : Math.round(e.fps), cpuMs: e.halted ? null : r1(e._cpuMs),
154
+ cpu: e.halted ? null : Object.fromEntries(Object.entries(e._cpuPhases).map(([k, v]) => [k, r1(v)])),
151
155
  apply: e.budget.cost.report(),
152
156
  ...drawStats(e.renderer), pixelRatio: e.renderer.getPixelRatio(),
153
157
  budget: e.budget.report(), startup: e.startup, stream: e.stream.stats, batching: e.batching.stats, jobs: e.jobs.pending, commits: { pending: e.commits.pending, ...e.commits.stats },
@@ -169,9 +173,9 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
169
173
 
170
174
  /** Module describe hooks and describe.add, then the nearby list and the player's actions, into out */
171
175
  function hooks(e, out, radius, center, extras) {
172
- const dir = e.camera.getWorldDirection(new e.THREE.Vector3()), camYaw = Math.atan2(dir.x, -dir.z);
176
+ const dir = e.camera.getWorldDirection(new Vector3()), camYaw = Math.atan2(dir.x, -dir.z);
173
177
  // Nearby things: collect first, then sort and truncate once at the end
174
- const found = new Map(), v = new e.THREE.Vector3();
178
+ const found = new Map(), v = new Vector3();
175
179
  const ctx = {
176
180
  out, radius, center,
177
181
  near(at, info, weak = false) {