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
@@ -10,9 +10,10 @@ const STRINGS = {
10
10
  actions: 'Can do (engine.ops): {list}',
11
11
  error: '[Error, gameplay frozen] {where}: {message}', errorAt: ' ({at})',
12
12
  errorHint: ' | Code: {code} | Fix: {fix} Read: {docs}', disabled: 'Disabled picture / ui modules (they threw): {list}',
13
- paused: ', paused', headless: ', headless', notReady: ', still loading',
13
+ halted: ', halted', headless: ', headless', notReady: ', still loading',
14
14
  waiting: 'Loading: {waiting} ({pending} pending, {done}/{total} done)', loadFailed: 'Load failed{blocked}: {list}', blocked: ' (start blocked)',
15
15
  loadWarn: 'Loaded with missing references: {list}',
16
+ audio: 'Audio: {list}',
16
17
  time: 'Time: {clock}, day {day}{season}, {dayNight}',
17
18
  day: 'daytime', night: 'night',
18
19
  weather: 'Weather: {name}{changing} (rain {rain}, snow {snow}, fog {fog}){shown}',
@@ -51,15 +52,15 @@ const STRINGS = {
51
52
  season: { spring: 'spring', summer: 'summer', autumn: 'autumn', winter: 'winter' },
52
53
  camType: { follow: 'follow camera', first: 'first person', fixed: 'fixed camera', rts: 'top-down strategy camera' },
53
54
  };
54
- import { fmt } from './validate.js';
55
- import { r1 } from './math.js';
56
- import { getPath } from './util.js';
55
+ import { fmt } from '../base/validate.js';
56
+ import { r1 } from '../base/math.js';
57
+ import { getPath } from '../base/util.js';
57
58
 
58
59
  const NEAR_SUMMARY = 5, LINE = 110;
59
60
  const tr = (table, k) => (k != null && STRINGS[table][k]) || (k ?? STRINGS.none);
60
61
  const n1 = v => (typeof v === 'number' ? r1(v) : v);
61
62
  // Standard fields get sentences above; data from other modules is squeezed into one JSON line
62
- const SHOWN = new Set(['nearbyRadius', 'ready', 'error', 'disabledModules', 'loading', 'time', 'player', 'camera', 'nearby', 'actions', 'ui', 'cutscene',
63
+ const SHOWN = new Set(['nearbyRadius', 'ready', 'error', 'disabledModules', 'loading', 'audio', 'time', 'player', 'camera', 'nearby', 'actions', 'ui', 'cutscene',
63
64
  'modules', 'perf', 'weather', 'render', 'threePatches']); // threePatches: page-wide, the same every call; describe() JSON carries it, the text stays short
64
65
  // engine bookkeeping in describe(): one count each in the summary, the content one describeText({ path }) away
65
66
  const TABLES = new Set(['holds', 'input', 'control', 'shared', 'wraps', 'slots', 'scene', 'owned', 'picture', 'renderer']);
@@ -90,7 +91,7 @@ function atPath(d, path) {
90
91
  export function describeText(d, { full = false, path, maxLines = 30, game = [] } = {}) {
91
92
  if (path) return atPath(d, path);
92
93
  const L = [], t = d.time;
93
- const flags = (t.paused ? STRINGS.paused : '') + (t.headless ? STRINGS.headless : '') + (d.loading.done ? '' : STRINGS.notReady);
94
+ const flags = (t.halted ? STRINGS.halted : '') + (t.headless ? STRINGS.headless : '') + (d.loading.done ? '' : STRINGS.notReady);
94
95
  if (d.error) L.push(fmt(STRINGS.error, d.error) + (d.error.at ? fmt(STRINGS.errorAt, d.error) : '')
95
96
  + (d.error.fix ? fmt(STRINGS.errorHint, { code: d.error.code, fix: d.error.fix, docs: d.error.docs.join(', ') }) : ''));
96
97
  L.push(fmt(STRINGS.head, { s: t.real, flags }));
@@ -100,6 +101,10 @@ export function describeText(d, { full = false, path, maxLines = 30, game = [] }
100
101
  { blocked: ld.blocked ? STRINGS.blocked : '',
101
102
  list: ld.failed.map(f => `${f.kind} "${f.name}" ${f.error.url ?? ''} ${f.error.message}${f.fallback ? ` -> ${f.fallback}` : ''}`).join('; ') }));
102
103
  if (ld.warnings.length) L.push(fmt(STRINGS.loadWarn, { list: ld.warnings.map(w => `"${w.name}" missing ${w.missing.join(', ')}`).join('; ') }));
104
+ if (d.audio) { // only present while a bus is ducked or a voice plays; ducks are the target level, so a fade in progress already shows its end
105
+ const low = Object.entries(d.audio.ducks).filter(([, v]) => v !== 1).map(([b, v]) => `${b} ducked to ${v}`), v = Object.entries(d.audio.voices).map(([k, n]) => `${k} x${n}`);
106
+ L.push(fmt(STRINGS.audio, { list: [...low, v.length ? 'playing ' + v.join(', ') : null].filter(Boolean).join('; ') }));
107
+ }
103
108
  if (d.disabledModules?.length) L.push(fmt(STRINGS.disabled, { list: d.disabledModules.join(', ') }));
104
109
  if (t.clock) L.push(fmt(STRINGS.time, { clock: t.clock, day: t.day, season: t.season ? ', ' + tr('season', t.season) : '', dayNight: t.isDay ? STRINGS.day
105
110
  : STRINGS.night }));
@@ -0,0 +1,38 @@
1
+ // Dev-only check (called from loop.js after each render once the engine is ready): warn when geometries keep piling up on the renderer that nothing in the scene uses.
2
+ // Why: scene.remove(mesh) without geometry.dispose() leaves the geometry counted by the renderer (and, on WebGLRenderer, its GPU buffers allocated) for good. The WebGPU record
3
+ // sweep (render/recordSweep.js) cannot close this: a geometry off the scene may be parked for reuse, and only the game knows it will not come back.
4
+ // What it compares: renderer.info.memory.geometries minus the distinct geometries reachable in engine.scene. Why not the mesh count: the renderer counts a geometry at its first
5
+ // draw, so a big static world counts up as the camera moves while its meshes stay flat, which is not a leak. Clamped at 0 for the same reason (meshes not drawn yet).
6
+ // False alarms are worse than none, so it speaks only after a sustained rise with no fall: a streaming game that disposes what it unloads stays flat, a load burst is one step.
7
+ // Silent on purpose: leaks slower than MIN_RISE per window. Not told apart: a game that keeps adding to a geometry cache off the scene, or streams through its own second Scene
8
+ // without engine.scene, looks like this too once it passes those limits.
9
+ // Cost: one scene walk every EVERY seconds, in dev only.
10
+ import { warnOnce } from '../base/validate.js';
11
+ import { coded } from '../base/errorHints.js';
12
+ import { memory } from '../../render/backend.js';
13
+
14
+ const EVERY = 10; // seconds between samples
15
+ const WINDOW = 12; // steps looked at together: two minutes
16
+ const RISES = 9; // of those steps, at least this many went up: a steady climb, not a few loads
17
+ const MIN_RISE = 100; // geometries gained over the window
18
+
19
+ /** @param {any} e the engine (dev and ready only: the caller checks) @param {number} dt seconds since the last call */
20
+ export function watchGeometries(e, dt) {
21
+ const w = e._geometryWatch ??= { wait: 0, unused: /** @type {number[]} */ ([]) };
22
+ if ((w.wait += dt) < EVERY) return;
23
+ w.wait = 0;
24
+ const used = new Set();
25
+ e.scene.traverse(/** @param {any} o */ o => { if (o.geometry) used.add(o.geometry); });
26
+ const n = Math.max(0, memory(e.renderer).geometries - used.size), h = w.unused;
27
+ if (h.length && n < h[h.length - 1]) h.length = 0; // the game is disposing: what came before is not this pattern
28
+ h.push(n);
29
+ if (h.length > WINDOW + 1) h.shift();
30
+ if (h.length <= WINDOW) return;
31
+ let rises = 0;
32
+ for (let i = 1; i < h.length; i++) if (h[i] > h[i - 1]) rises++;
33
+ const gained = h[h.length - 1] - h[0];
34
+ if (rises >= RISES && gained >= MIN_RISE) {
35
+ warnOnce(coded('geometry-undisposed', `${gained} geometries that nothing in the scene uses joined the renderer in the last ${WINDOW * EVERY} s (${n} in all). ` +
36
+ 'When a mesh is gone for good, call mesh.geometry.dispose() after removing it (engine.remove does it for you)'), 'geometry-undisposed');
37
+ }
38
+ }
@@ -3,11 +3,11 @@
3
3
  // removed or hidden mid-play compiles again and freezes that frame (a dungeon game froze ~450 ms when a torch turned its light on).
4
4
  // engine.start() already compiled everything for the startup lights; this names the cause when a game changes them afterwards.
5
5
  // Cost: one array-length compare per frame; the scene walk that counts lights runs only in a frame whose program count went up (rare).
6
- import { warnOnce } from './validate.js';
7
- import { coded } from './errorHints.js';
8
- import { programCount } from '../render/backend.js';
6
+ import { warnOnce, fmt } from '../base/validate.js';
7
+ import { coded } from '../base/errorHints.js';
8
+ import { programCount } from '../../render/backend.js';
9
9
 
10
- const MANY = 8; // above this many real-time lights every material's fragment shader loops over all of them: mobile GPUs slow down first
10
+ export const MANY = 8; // above this many real-time lights every material's fragment shader loops over all of them: mobile GPUs slow down first
11
11
 
12
12
  const STRINGS = {
13
13
  many: '{n} real-time lights are in the scene (more than {max}, not counting lightPool lights). Every lit material pays for every light in every pixel. ' +
@@ -42,19 +42,19 @@ export function watchLights(e) {
42
42
  const n = programCount(e.renderer);
43
43
  if (n == null) return;
44
44
  const first = !e._lightWatch;
45
- // changes and setup: the picture check reads them (packages/tools/picture/check.mjs 'light-layout')
46
- const w = e._lightWatch ??= { n, lights: lightSetup(e.scene), changes: [], setup: () => lightSetup(e.scene) };
45
+ // changes and setup: the picture check reads them (packages/tools/picture/hints-scene.mjs 'light-layout')
46
+ const w = /** @internal the picture check reads it */ e._lightWatch ??= { n, lights: lightSetup(e.scene), changes: [], setup: () => lightSetup(e.scene) };
47
47
  // the scene walk runs on the first observation and when programs grow (a light was added), never on a quiet frame
48
48
  if (!w.manyDone && (first || n > w.n)) {
49
49
  const c = countLoose(e.scene);
50
- if (c > MANY) { w.manyDone = true; warnOnce(coded('many-lights', STRINGS.many.replace('{n}', String(c)).replace('{max}', String(MANY)))); }
50
+ if (c > MANY) { w.manyDone = true; warnOnce(coded('many-lights', fmt(STRINGS.many, { n: String(c), max: String(MANY) }))); }
51
51
  }
52
52
  if (n <= w.n) { w.n = n; return; } // fewer programs (materials disposed) or none new: nothing to say
53
53
  const lights = lightSetup(e.scene);
54
54
  if (lights !== w.lights) {
55
55
  w.changes.push({ from: w.lights, to: lights, programs: n - w.n });
56
56
  // the layout is only reread when programs grow, so we say "since the last observation", never "in this frame"
57
- warnOnce(coded('light-recompile', STRINGS.changed.replace('{from}', String(w.n)).replace('{to}', String(n)).replace('{was}', w.lights).replace('{now}', lights)));
57
+ warnOnce(coded('light-recompile', fmt(STRINGS.changed, { from: String(w.n), to: String(n), was: w.lights, now: lights })));
58
58
  }
59
59
  w.n = n; w.lights = lights;
60
60
  }
@@ -15,21 +15,20 @@
15
15
  // function name, plus the part running it. shortcut: outside parts, two anonymous functions or two same-named methods in one file count as one place, so a fight between them goes unwarned;
16
16
  // upgrade by comparing function start lines if an agent reports one.
17
17
  //
18
- // Parts (modules, core/pictureSlots.js): a value in a slot a part holds has a declared owner, so a write from anyone else is reported at once, naming the holder and
18
+ // Parts (modules, core/scene/pictureSlots.js): a value in a slot a part holds has a declared owner, so a write from anyone else is reported at once, naming the holder and
19
19
  // both lines, not only when the two land in one frame (a held value written by a stray in another state would never be a fight). Who wrote it: the module running
20
- // now (install, its hooks: core/moduleTypes.js ownHook), else any frame in a file that part's code ran from (an event listener, a timer). A file two parts share
20
+ // now (install, its hooks: core/engine/moduleTypes.js ownHook), else any frame in a file that part's code ran from (an event listener, a timer). A file two parts share
21
21
  // cannot say which of them it was, so it counts as the holder: a warning that accuses the owner would teach agents to ignore this one.
22
22
  // What cannot be seen: a write made before the holder took the slot, and a part added under another object rather than the scene root (see added).
23
23
  //
24
24
  // Leftovers: three.js objects have no owner, so ctx.track only removes what it was handed. Each root a picture part adds and each post effect is remembered until it
25
25
  // leaves; what is still there after the part is gone, and a hook that outlived it, is reported by name. It observes, like the rest: nothing is cleaned up for the part.
26
- import { warnOnce, fmt } from './validate.js';
27
- import { coded } from './errorHints.js';
28
- import { notePatch } from './threePatches.js';
29
- import { sceneVisitor } from './sceneDelta.js';
30
- import { onSceneRoot } from './sceneDelta.js';
31
- import { stackFrames, frameText, callerAt, engineFile } from './stackFrames.js';
32
- import { slotOfValue, slotHolder } from './pictureSlots.js';
26
+ import { warnOnce, fmt } from '../base/validate.js';
27
+ import { coded } from '../base/errorHints.js';
28
+ import { notePatch } from '../scene/threePatches.js';
29
+ import { sceneVisitor, onSceneRoot } from '../scene/sceneDelta.js';
30
+ import { stackFrames, frameText, callerAt, engineFile } from '../ops/stackFrames.js';
31
+ import { slotOfValue, slotHolder } from '../scene/pictureSlots.js';
33
32
 
34
33
  const EVERY = 30; // frames between two looks at a value written every frame: a stale answer is at most half a second old
35
34
  const DEPTH = 10; // three's own frames above the writer: setter, Color.copy, lerpColors ... always fewer
@@ -42,8 +41,8 @@ const NOT = {
42
41
  };
43
42
  // three.js and pre-bundled libraries are never "the writer": the line that called them is
44
43
  const SKIP = /\/deps\/|\/node_modules\/|\/three(?:\.[a-z]+)*\.js$/;
45
- const SELF = /core\/pictureWriters\.js$/;
46
- const CORE = /\/(?:core|render)\/[^/]+$/; // with engineFile: core and render write for the engine; modules/ count as parts, they hold slots like any other
44
+ const SELF = /core\/inspect\/pictureWriters\.js$/;
45
+ const CORE = /\/(?:core|render)\/(?:[^/]+\/)?[^/]+$/; // with engineFile: core and render (and their folders: core/ops/x.js) write for the engine; modules/ count as parts, they hold slots like any other
47
46
  const MATERIALS_MAX = 40; // describe() stays small on a big scene; explain still answers any one of them
48
47
  const SHARED_FIX = "make it a shared value: the owner defines it with engine.stacks.define(name, { base: 1 }) and reads it where it writes three.js, the others change it with ctx.mod(name, { mul: 0.5 }); for an amount that moves, take it once, const h = ctx.mod(name, { mul: 1 }), and call h.change(x) each frame (recipes/62-picture-code.md)";
49
48
  const STRINGS = {
@@ -188,7 +187,7 @@ class Writers {
188
187
  const by = this.partsOf(w);
189
188
  this.claim(rec, w, by);
190
189
  const place = `${w.key}|${by[0] ?? ''}`; // the part too: two parts' anonymous hooks in one file are two places
191
- if (fr > 0 && rec.placeKey && rec.placeKey !== place && !rec.fought) this.fight(rec, rec.placeAt, rec.placeBy, w.at, by[0]);
190
+ if (!w.engine && fr > 0 && rec.placeKey && rec.placeKey !== place && !rec.fought) this.fight(rec, rec.placeAt, rec.placeBy, w.at, by[0]);
192
191
  rec.at = w.at; rec.why = null; rec.placeKey = place; rec.placeAt = w.at; rec.placeBy = by[0] ?? null;
193
192
  }
194
193
 
@@ -231,14 +230,14 @@ class Writers {
231
230
  const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error), lim = E.stackTraceLimit;
232
231
  E.stackTraceLimit = DEPTH;
233
232
  const stack = new Error().stack; E.stackTraceLimit = lim;
234
- const f = stackFrames(stack ?? '').find(x => !SELF.test(x.file) && !/core\/modules\.js$/.test(x.file));
233
+ const f = stackFrames(stack ?? '').find(x => !SELF.test(x.file) && !/core\/engine\/modules\.js$/.test(x.file));
235
234
  if (f && !engineFile(f.file)) this.noteFile(f.file, m.name, frameText(f));
236
235
  }
237
236
 
238
237
  /**
239
238
  * A scene root or a post effect just added: which picture part it belongs to, if any.
240
239
  * shortcut: only scene roots are seen. A light put under the camera or under another part's group is no root and goes unreported; upgrade through the visitor's
241
- * pending adds in core/sceneDelta.js if an agent reports one.
240
+ * pending adds in core/scene/sceneDelta.js if an agent reports one.
242
241
  */
243
242
  added(kind, thing, name) {
244
243
  if (page.off) return;
@@ -261,7 +260,7 @@ class Writers {
261
260
  const left = [];
262
261
  for (const [thing, r] of mine ?? []) if (!thing._removed) left.push(r); // _removed: a post handle; a scene root that left is already out of the map
263
262
  const e = this.e;
264
- for (const list of [e._onRender.before, e._onRender.after, e._frame, e._fixed, e._fixedLate]) for (const f of list) if (f.part === m.name) left.push({ kind: 'hook', name: 'frame callback', at: f.at });
263
+ for (const list of [e._onRender.before, e._onRender.after, e._frame, e._animate, e._fixed, e._fixedLate]) for (const f of list) if (f.part === m.name) left.push({ kind: 'hook', name: 'frame callback', at: f.at });
265
264
  if (!swapping) for (const [name, on] of [['scene.fog', e.scene], ['scene.environment', e.scene], ['scene.background', e.scene]]) {
266
265
  const r = this.top.get(name), key = name.slice(6);
267
266
  if (r?.last?.holder === m.name && r.last.writer === 'holder' && on[key] != null) left.push({ kind: 'value', name, at: r.at });
@@ -336,7 +335,7 @@ class Writers {
336
335
 
337
336
  /** @param {any} e */
338
337
  export function installPictureWriters(e) {
339
- notePatch('picture-writers', 'dev server only: intensity, color, position of lights, scene.fog and its values, renderer.toneMapping / toneMappingExposure, scene.environment / background and their intensities, material color / emissive / opacity: an own get / set on each, and on the r g b / x y z of the Color or Vector3 (core/pictureWriters.js)',
338
+ notePatch('picture-writers', 'dev server only: intensity, color, position of lights, scene.fog and its values, renderer.toneMapping / toneMappingExposure, scene.environment / background and their intensities, material color / emissive / opacity: an own get / set on each, and on the r g b / x y z of the Color or Vector3 (core/inspect/pictureWriters.js)',
340
339
  () => { page.off = true; }, // accessors already placed stay and only pass values through; new objects get none
341
340
  { scope: 'objects in the scene', lost: "describe('picture').writers stops answering, and two writers in one frame are no longer warned about" });
342
341
  e._picture = new Writers(e);
@@ -4,7 +4,7 @@
4
4
  // are not evaluated, so it over-counts) plus SAMPLER_WEIGHT per active sampler. A ranking aid, not a GPU timing: use it to find the heaviest
5
5
  // materials, then measure with the GPU tools (Spector.js through `threedog capture`).
6
6
  // Plain three.js equivalent: renderer.info.programs (the list) and gl.getShaderSource / gl.getActiveUniform on program.program.
7
- import { isWebGPU, nodeProgram, programList } from '../render/backend.js';
7
+ import { isWebGPU, nodeProgram, programList } from '../../render/backend.js';
8
8
 
9
9
  const SAMPLER_WEIGHT = 25;
10
10
  const SAMPLERS = new Set([0x8B5E, 0x8B60, 0x8B62, 0x8B5F, 0x8DC1, 0x8DD2, 0x8DCA, 0x8DCC, 0x8DCF, 0x8DD7, 0x8DC4]); // GL sampler uniform types
@@ -10,15 +10,15 @@
10
10
  // which lands "after step N" and replays the same. Args must be plain data and self-contained (aim direction goes in the args).
11
11
  // The guard (ops.guard) backs "don't go around it": in dev, saved gameplay state written outside loading, fixed steps and ops
12
12
  // is reported (see recipes/23-ops.md). Dev argument checks live in opsCheck.js.
13
- import { DEV, missingText, warnOnce } from './validate.js';
14
- import { checkTypeRule, asModule } from './moduleTypes.js';
15
- import { checkDef, checkArgs, devError, fmt, SOURCES } from './opsCheck.js';
16
- import { coded, codedError } from './errorHints.js';
13
+ import { DEV, fmt, missingText, warnOnce } from '../base/validate.js';
14
+ import { checkTypeRule, asModule } from '../engine/moduleTypes.js';
15
+ import { checkDef, checkArgs, devError, SOURCES } from './opsCheck.js';
16
+ import { coded, codedError } from '../base/errorHints.js';
17
17
  import { guardWrite } from './opsGuard.js';
18
18
  import { failure, isStructured, opsBlocked } from './opsFail.js';
19
19
  import { runOp } from './opsRun.js';
20
20
  import { newRing, logEntry, recentEntries } from './opsHistory.js';
21
- import { defaultsOf, withDefaults } from './params.js';
21
+ import { defaultsOf, withDefaults } from '../base/params.js';
22
22
 
23
23
  const STRINGS = {
24
24
  dup: "ops.define('{name}'): already defined. To replace it call remove() on the handle define returned first",
@@ -47,7 +47,7 @@ export class Ops {
47
47
  /** @internal ctx of the innermost running op (nested ops inherit source and actor) */ this._last = null;
48
48
  /** @internal set through route() (net clients): (def, args, opts) => result to return instead of running locally, or null to run here */ this._route = null;
49
49
  /** @internal true while route() is held: every write outside allow() is reported, even in fixed steps and ops (own movement, world.move, excepted) */ this._client = false;
50
- /** Counter bumped on each committed op (an op that failed or rolled back does not bump it); every run result carries it, so "did anything change since I looked" is one compare */
50
+ /** Counter that only goes up: each committed op, undo, load and rollback bumps it (a failed op that changed nothing does not); every run result carries it, so "did anything change since I looked" is one compare */
51
51
  this.revision = 0;
52
52
  /** @internal depth of atomic runs in progress, and after hooks waiting for the outermost one to commit */ this._txDepth = 0; this._txAfter = [];
53
53
  this.historySize = 256;
@@ -110,7 +110,7 @@ export class Ops {
110
110
 
111
111
  /**
112
112
  * Run an op now (synchronously): checks args (dev), calls can, then run, and logs it. Returns { ok: true, value, revision } or { ok: false, code, facts, nextActions, revision } (revision = ops.revision, counts committed ops); can may also return { code, facts?, nextActions? }.
113
- * Pass a fresh args object each call (it is kept in the history; in dev it is frozen). opts.source: 'player' | 'game' | 'bridge' | 'test' | 'replay' | 'net'
113
+ * Pass a fresh args object each call (it is kept in the history; in dev it is frozen). opts.source: 'player' | 'game' | 'bridge' | 'test' | 'replay' | 'net' | 'editor'
114
114
  * (default: 'game' inside a fixed step, 'player' between steps); opts.actor: who does it (world record id, default engine.actor, which is 'player' unless the game hands control elsewhere).
115
115
  * @param {string} name
116
116
  * @param {object} [args]
@@ -140,8 +140,12 @@ export class Ops {
140
140
  const d = this._def(name);
141
141
  if (!d) return this._res(failure({ code: 'unknownOp', facts: { op: name } }));
142
142
  if (typeof d.undo !== 'function') return this._res(failure({ code: 'noUndo', facts: { op: name }, nextActions: [] }));
143
+ const blocked = opsBlocked(this.engine); // as run: a load in progress or a gameplay error
144
+ if (blocked) return this._res(failure(blocked));
143
145
  this._allowDepth++;
144
- try { d.undo(this.engine, args, value, this._ctx(name, args, opts, null)); } finally { this._allowDepth--; }
146
+ // the op's code is the defining module's, not the caller's (run)
147
+ try { asModule(this.engine, null, () => d.undo(this.engine, args, value, this._ctx(name, args, opts, null))); } finally { this._allowDepth--; }
148
+ this.revision++; // the state changed: "did anything change since I looked" must see it
145
149
  return { ok: true };
146
150
  }
147
151
 
@@ -237,10 +241,11 @@ export class Ops {
237
241
  * @param {any} args
238
242
  * @param {{ reason: string, actor?: string, source?: string }} why source defaults to 'net'
239
243
  * @returns {void}
244
+ * @experimental
240
245
  */
241
- refused(name, args, { reason, actor = '', source = 'net' }) { this._log(name, args, { source, actor, tick: this.engine.tick }, false, reason, 0); }
246
+ refused(name, args, { reason, actor = '', source = 'net' }) { this._log(name, args, { source, actor, tick: this.engine.time.tick }, false, reason, 0); }
242
247
  /** @internal A separator in the history (save load): later entries belong to a different world state */
243
- _mark(label) { this._log(label, null, { tick: this.engine.tick, source: 'game', actor: '' }, true, null, 0); }
248
+ _mark(label) { this._log(label, null, { tick: this.engine.time.tick, source: 'game', actor: '' }, true, null, 0); }
244
249
  /**
245
250
  * Run fn with guarded writes allowed (loading a save, applying a scenario, net sync); works for an async fn too (allowed until its Promise settles). Returns what fn returns.
246
251
  * @experimental
@@ -274,7 +279,7 @@ export class Ops {
274
279
  if (!SOURCES.includes(source)) throw devError(fmt(STRINGS.badSource, { name, source }));
275
280
  if (args) checkArgs(e, this.defs.get(name), args);
276
281
  }
277
- return { source, actor: opts?.actor ?? parent?.actor ?? e.actor, tick: e.tick, frozen: e.frozen };
282
+ return { source, actor: opts?.actor ?? parent?.actor ?? e.actor, tick: e.time.tick, frozen: e.frozen };
278
283
  }
279
284
  /** @internal returns true or a reason string */
280
285
  _can(d, args, ctx) {
@@ -7,7 +7,8 @@
7
7
  // character in the same step; the last move() won and nobody could tell why the player slid. Now exactly one owner moves it per step.
8
8
  // Rules (one table, so a tool can predict them):
9
9
  // - layers, lowest first: base (the character's own driver: the player's keys, an NPC's behaviour) < script (walkTo, a quest escort, an AI
10
- // order) < cutscene (timeline) < net (a character another machine drives: held for good, nobody else may take it)
10
+ // order) < cutscene (timeline) < physics (a ragdoll: nothing can steer a limp body, a cutscene included) < net (a character another machine
11
+ // drives: held for good, nobody else may take it)
11
12
  // - the highest layer is in charge; the ones below are paused, not cancelled: when it ends they carry on (a walk resumes after a cutscene)
12
13
  // - one owner per layer: a second, different owner on the same layer throws control-conflict in dev naming both (release: the later wins, the
13
14
  // earlier is dropped, warned once). The same owner taking again replaces its own hold.
@@ -17,13 +18,13 @@
17
18
  // Kept by id, not by model: an NPC's model is torn down and rebuilt as it goes far and near; the hold stays with the NPC. The slot is dropped when
18
19
  // the world record goes (world:remove) or a record-less character is disposed. Not saved: holders are code (a running walk, a cutscene), retaken
19
20
  // by that code after a load.
20
- import { codedError, coded } from './errorHints.js';
21
- import { DEV, warnOnce } from './validate.js';
21
+ import { codedError, coded } from '../base/errorHints.js';
22
+ import { DEV, warnOnce } from '../base/validate.js';
22
23
  import { callerAt } from './stackFrames.js';
23
- import { STEP } from './time.js'; // the fixed step: handle.move()'s dt when none is given
24
+ import { STEP } from '../time/time.js'; // the fixed step: handle.move()'s dt when none is given
24
25
 
25
26
  /** Control layers, lowest first (see the header) */
26
- export const CONTROL_LAYERS = { base: 0, script: 1, cutscene: 2, net: 3 };
27
+ const CONTROL_LAYERS = { base: 0, script: 1, cutscene: 2, physics: 3, net: 4 };
27
28
  const LAYER_NAMES = Object.keys(CONTROL_LAYERS);
28
29
 
29
30
  const idOf = who => (typeof who === 'string' ? who : who?.id);
@@ -34,15 +35,15 @@ export class Control {
34
35
  /** @internal */ this.engine = engine;
35
36
  /** @type {Map<string, Map<string, any>>} id -> owner -> entry (take order) */ this._by = new Map();
36
37
  /** @internal the entry whose move is running now (handle.move / a behaviour run): the one caller character.move() lets through */ this._cur = null;
37
- /** @internal id -> Character; set by the characters module through resolveWith (core names no module) */ this._resolve = () => null;
38
- engine.events?.on('world:remove', ({ id }) => this.forget(id));
38
+ /** @internal id -> Character; set by the characters module through resolveWith (core names no module) */ this.characterOf = () => null;
39
+ engine.events.on('world:remove', ({ id }) => this.forget(id));
39
40
  }
40
41
  /**
41
42
  * Take a character's control. step (optional): (dt, character) => ({ x, z, run? }) | null | false, called each fixed step while this owner is in
42
43
  * charge (dt on the character's time channel): a direction moves it, null stands still (gravity and the idle pose go on), false skips the
43
44
  * move this step (you placed it yourself). Without step, move it with handle.move(x, z, run, dt), which does nothing while paused.
44
45
  * @param {any} who a Character, an NPC handle or a character id ('player', an NPC id)
45
- * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'net', step?: (dt: number, ch: any) => ({ x: number, z: number, run?: boolean } | null | false | void) }} o
46
+ * @param {{ owner: string, layer?: 'base' | 'script' | 'cutscene' | 'physics' | 'net', step?: (dt: number, ch: any) => ({ x: number, z: number, run?: boolean } | null | false | void) }} o
46
47
  * @returns {{ owner: string, layer: string, id: string, readonly active: boolean, move(x: number, z: number, run?: boolean, dt?: number): boolean, remove(): void }}
47
48
  * @example const h = engine.control.take(player, { owner: 'tutorial', layer: 'script', step: () => ({ x: 0, z: 1 }) }); ... h.remove();
48
49
  */
@@ -99,12 +100,12 @@ export class Control {
99
100
  return { owner: top.owner, layer: top.layer, ...(top.at && { at: top.at }), waiting };
100
101
  }
101
102
  /** @internal the characters module tells control how to find a live Character by id (the player, an NPC's model) @param {(id: string) => any} fn */
102
- resolveWith(fn) { this._resolve = fn; }
103
+ resolveWith(fn) { this.characterOf = fn; }
103
104
  /** True while owner holds the character (in charge or paused) @param {any} who @param {string} owner */
104
105
  has(who, owner) { return !!this._by.get(idOf(who))?.has(owner); }
105
106
  /** describe().control: every held character by id, as of() */
106
107
  describe() { const out = {}; for (const id of this._by.keys()) out[id] = this.of(id); return out; }
107
- /** Drop every hold on a character (its record left the world, or a record-less character was disposed) @param {string} id */
108
+ /** Drop every hold on a character (its record left the world, or a record-less character was disposed) @param {string} id @experimental */
108
109
  forget(id) { this._by.delete(id); }
109
110
  /** @internal the entry in charge: highest layer, latest taker inside it (only one per layer in dev) */
110
111
  _top(id) {
@@ -114,7 +115,7 @@ export class Control {
114
115
  return t;
115
116
  }
116
117
  /** @internal the Character an entry moves: the one passed in, if it is still the live one, else found by id (an NPC model rebuilt) */
117
- _char(ent) { const ch = ent.ch && !ent.ch._disposed ? ent.ch : this._resolve(ent.id); return ch ?? null; }
118
+ _char(ent) { const ch = ent.ch && !ent.ch._disposed ? ent.ch : this.characterOf(ent.id); return ch ?? null; }
118
119
  /** @internal run fn as the entry's own move (checkMove reads _cur) */
119
120
  _drive(ent, fn) { const prev = this._cur; this._cur = ent; try { return fn(); } finally { this._cur = prev; } }
120
121
  /** @internal for drivers that call character.move inside their own code (an NPC behaviour): run fn as owner's move when it is in charge; false when paused */
@@ -132,7 +133,7 @@ export class Control {
132
133
  if (!top?.step) continue;
133
134
  const ch = this._char(top);
134
135
  if (!ch) continue;
135
- const dt = T ? T.dt(ch.channel, ch.modId) : STEP;
136
+ const dt = T ? T.dt(ch.channel, ch.id) : STEP;
136
137
  const m = top.step(dt, ch);
137
138
  if (m === false || this._top(id) !== top) continue; // placed by hand this step, or the step handed control on (ended itself, something took it)
138
139
  this._drive(top, () => ch.move(m?.x ?? 0, m?.z ?? 0, !!m?.run, dt));
@@ -0,0 +1,139 @@
1
+ // Who holds the engine still: freeze and the loop halt (each ends with its handle's remove()), runState, and the camera takeover (takeCamera / cameraOverride).
2
+ // "Stopped" has one meaning for a game: frozen. engine.freeze is what menus, flow 'paused', the page hold and errors use. haltLoop is a tool's switch, not a game's: it
3
+ // stops the real-time loop and the picture with it, so tests and the dev bridge can drive the engine by step(). Its name says so because an AI asked to pause a game
4
+ // reached for engine.pause and got a dead screen. Time channels at 0 slow or stop one part of the world and are not a hold.
5
+ // Each is a named stack (core/ops/stacks.js: 'halt' and 'freeze' kind any, 'camera' kind top), so they follow the same owner rules as every shared quantity:
6
+ // engine.freeze('menu') is engine.mod('freeze', { owner: 'menu' }) with the loop's side effects added (ending the last halt restarts the loop).
7
+ // One entry per mechanism: the handle's remove() ends a halt / freeze (there is no engine.resume / engine.unfreeze).
8
+ import { warnOnce } from '../base/validate.js';
9
+ import { coded } from '../base/errorHints.js';
10
+ import { ownerArgs } from './sharedPoint.js';
11
+
12
+ // The halt / freeze handle is { owner, remove() } only: no chaining, so each is ended in exactly one way.
13
+ function handle(owner, remove) { return { owner, remove }; }
14
+
15
+ /**
16
+ * The three hold stacks: 'freeze' and 'halt' (kind any), 'camera' (kind top). services.js and the test engines call this, so both get the same stacks.
17
+ * The halt stack does the loop side effect itself (onChange), not engine.haltLoop(): engine.mod('halt', { owner }), engine.haltLoop(owner), the handle's
18
+ * remove() and _unhalt(owner) are then one behavior. Making mod('halt') throw instead would leave a quantity that engine.mod names in describe
19
+ * but refuses to change, a special case to remember; with onChange there is no path that holds the stack without stopping the loop.
20
+ * @param {any} engine
21
+ */
22
+ export function defineHoldStacks(engine) {
23
+ engine.stacks.define('freeze', { kind: 'any', save: false }); // who froze gameplay
24
+ engine.stacks.define('halt', { kind: 'any', save: false, onChange: () => { // who stopped the loop; it restarts only when empty
25
+ if (engine.stacks.get('halt').size()) engine.halted = true;
26
+ else if (!engine.disposed) { engine.halted = false; engine._loop(); }
27
+ engine.page._sync(); // a page hold is about the real-time loop: there is none while the loop is stopped (core/engine/page.js)
28
+ } });
29
+ engine.stacks.define('camera', { kind: 'top', save: false }); // who holds the camera; the latest is in charge (cameraOverride)
30
+ }
31
+
32
+ export const holdMethods = {
33
+ /**
34
+ * Stop the real-time loop for a test or a tool: nothing advances and nothing is drawn until step(), so this is not how a game pauses (engine.freeze, flow 'paused').
35
+ * owner names who stopped it (default 'game'; haltLoop({ owner }) works too): the loop stays stopped until every owner has let go.
36
+ * Returns a handle: remove() lets go for this owner.
37
+ * @param {string | { owner?: string }} [owner]
38
+ * @returns {{ owner: string, remove(): void }}
39
+ * @example const h = engine.haltLoop('perf-test'); engine.step(1); h.remove();
40
+ */
41
+ haltLoop(owner) {
42
+ const a = ownerArgs(owner);
43
+ const P = this.stacks.get('halt');
44
+ P.take({ owner: a.owner, value: true }); // the stack's onChange sets this.halted (defineHoldStacks), same as engine.mod('halt')
45
+ return handle(a.owner, () => { if (P.has(a.owner)) this._unhalt(a.owner); });
46
+ },
47
+ /**
48
+ * @internal The dev bridge and tests: end owner's halt (the handle's remove() calls this); with no halt held (a headless engine) it starts live running.
49
+ * A call by a non-owner while others hold a halt is ignored with a dev warning (a halt that silently stays stops even rendering).
50
+ * @param {string | { owner?: string }} [owner]
51
+ */
52
+ _unhalt(owner) {
53
+ const { owner: o } = ownerArgs(owner);
54
+ const P = this.stacks.get('halt');
55
+ if (P.size() && !P.has(o)) { warnOnce(coded('halt-owner', `ending the halt of '${o}': halted by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a halt with the handle haltLoop() returned (h.remove()), or the loop stays stopped`)); return this; }
56
+ // with holders the stack's onChange restarts the loop; with none (headless start) this call starts it
57
+ if (!P.release(o) && !P.size() && !this.disposed) { this.halted = false; this._loop(); }
58
+ return this;
59
+ },
60
+ // Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
61
+ // and rendering go on, so the picture and UI stay alive.
62
+ // Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
63
+ // Unlike haltLoop(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
64
+ // have unfrozen. step() obeys freezes as well. Same owner rules as every stack (core/ops/stacks.js).
65
+ /**
66
+ * Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
67
+ * Ambient motion (uniforms.uTime: wind, water, clouds), skeletal animation and particles keep moving behind the freeze, as behind a pause menu; ambient: true stops them too
68
+ * (a photo, a cutscene still; the page's own hold). UI and the camera stay live.
69
+ * Returns a handle whose remove() releases this owner's freeze. Same as engine.mod('freeze', { owner }) plus the kind.
70
+ * @param {string | { owner?: string, kind?: 'title', ambient?: boolean }} [owner] @param {{ kind?: 'title', ambient?: boolean }} [opts]
71
+ * @returns {{ owner: string, remove(): void }}
72
+ */
73
+ freeze(owner, opts) {
74
+ const a = ownerArgs(owner, opts);
75
+ const h = this.stacks.get('freeze').take({ owner: a.owner, value: { kind: a.opts.kind ?? null, ambient: !!a.opts.ambient } });
76
+ return handle(a.owner, h.remove);
77
+ },
78
+ /** True while someone has frozen gameplay */
79
+ get frozen() { return this.stacks.get('freeze').value(); },
80
+ /** True while a freeze asked for a full still (freeze(owner, { ambient: true })): code that moves things on frame dt reads this, as animation and particles do */
81
+ get still() { const F = this.stacks.get('freeze'); return F.size() > 0 && F.entries().some(h => h.value?.ambient); }, // read per character and animator: nothing built while no one froze
82
+ /**
83
+ * The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
84
+ * state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'halted' (the loop is stopped: a test, the bridge, a headless page)
85
+ * | 'frozen' (gameplay stopped by the owners in `owners`: a menu, the page, an error) | 'running';
86
+ * owners: every halt and freeze owner, so closing one part's menu can be told from a player's;
87
+ * blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
88
+ * 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
89
+ * @returns {{ state: 'loading' | 'title-frozen' | 'halted' | 'frozen' | 'running', owners: string[], blockedBy: string[] }}
90
+ */
91
+ get runState() {
92
+ const F = this.stacks.get('freeze'), owners = [...this.stacks.get('halt').names(), ...F.names()];
93
+ const lv = this.loading?.view();
94
+ const state = !this.ready || !lv?.done ? 'loading' : F.entries().some(d => d.value.kind === 'title') ? 'title-frozen'
95
+ : this.halted ? 'halted' : F.size() ? 'frozen' : 'running';
96
+ const blockedBy = this.input.holders.filter(h => !h.pass).map(h => h.context);
97
+ if (F.has('error')) blockedBy.push('error');
98
+ if (lv?.blocked) blockedBy.push('loading');
99
+ return { state, owners, blockedBy };
100
+ },
101
+
102
+ // ---------- camera takeover ----------
103
+ // While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). The 'camera' stack is kind top: the latest holder
104
+ // is in charge, and releasing it hands the camera back to the previous holder (or to the rig when none is left), never to nobody.
105
+ /**
106
+ * Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
107
+ * (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
108
+ * @param {string | { owner: string, focus?: import('three').Vector3 }} owner @param {{ focus?: import('three').Vector3, [k: string]: any }} [opts] extra fields stay readable on cameraOverride
109
+ * @returns {{ owner: string, remove(): void }}
110
+ * @example const cam = engine.takeCamera('photo-mode', { focus: engine.player.position }); ... cam.remove();
111
+ */
112
+ takeCamera(owner, opts) {
113
+ const a = ownerArgs(owner, opts);
114
+ const h = this.stacks.get('camera').take({ owner: a.owner, value: { ...a.opts, owner: a.owner } });
115
+ return { owner: a.owner, remove: h.remove };
116
+ },
117
+ /**
118
+ * The camera holder in charge ({ owner, focus? }), or null. Read-only: take the camera with engine.takeCamera(owner).
119
+ * @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
120
+ */
121
+ get cameraOverride() { return this.stacks.get('camera').value() ?? null; },
122
+ };
123
+
124
+ const HOLD_STACKS = { halt: 'halt', freeze: 'freeze', camera: 'camera', debugView: 'debug.view' };
125
+ /**
126
+ * Everyone who holds something, in one place (empty parts left out): halt / freeze / camera / debugView [{ owner, at }]; input [{ context, owner,
127
+ * pass }] (pushed input contexts); gates { action: [owners] } (input.gate). Every other shared value is in describe().shared (core/ops/stacks.js).
128
+ * Lives here, next to the hold stacks it reads, so describe() and the input-holds test use the same function (no second copy).
129
+ * "Why can't I move / why is time slow" is answered here without knowing which module did it.
130
+ */
131
+ export function describeHolds(e) {
132
+ const out = {};
133
+ for (const [k, n] of Object.entries(HOLD_STACKS)) { const h = e.stacks.has(n) ? e.stacks.get(n).holders() : []; if (h.length) out[k] = h; }
134
+ const inp = e.input.holders; if (inp.length) out.input = inp;
135
+ const g = e.stacks.has('input.gate') ? e.stacks.get('input.gate') : null, gates = {};
136
+ for (const id of g?.ids() ?? []) if (g.size(id)) gates[id] = g.names(id);
137
+ if (Object.keys(gates).length) out.gates = gates;
138
+ return out;
139
+ }
@@ -10,7 +10,8 @@
10
10
  /** Copy the atomic parts that exist now: [[provider, plain copy]] @internal */
11
11
  export function snapshot(e) {
12
12
  const out = [];
13
- for (const p of e.saves.providers.values()) if (p.atomic) out.push([p, JSON.parse(JSON.stringify(p.save() ?? null))]);
13
+ // a part with nothing to save is left out, as in a save: load() is never handed null
14
+ for (const p of e.saves.providers.values()) if (p.atomic) { const d = p.save(); if (d != null) out.push([p, JSON.parse(JSON.stringify(d))]); }
14
15
  return out;
15
16
  }
16
17
 
@@ -1,13 +1,12 @@
1
1
  // Dev checks for engine.ops (split out of Ops.js): op definition shape, argument plain-data and shape checks, and their error texts.
2
2
  // Each message says what is wrong and how to write it, because the reader is usually an AI that will fix the call from the text alone.
3
- import { closest, fmt } from './validate.js';
4
- import { codedError } from './errorHints.js';
5
- import { parseSchema, whyBad, checkOf, OP_TYPES as TYPES } from './params.js'; // one type check for op args and module params
3
+ import { closest, fmt } from '../base/validate.js';
4
+ import { codedError } from '../base/errorHints.js';
5
+ import { parseSchema, whyBad, checkOf, OP_TYPES as TYPES } from '../base/params.js'; // one type check for op args and module params
6
6
 
7
- export const SOURCES = ['player', 'game', 'bridge', 'test', 'replay', 'net'];
7
+ export const SOURCES = ['player', 'game', 'bridge', 'test', 'replay', 'net', 'editor'];
8
8
  const NAME = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
9
9
  const DEF_KEYS = ['desc', 'args', 'can', 'run', 'offers', 'reasons', 'undo', 'net', 'owner', 'targets', 'atomic', 'after'];
10
- export { fmt };
11
10
  const STRINGS = {
12
11
  badName: "ops.define('{name}'): name an op noun.verb, e.g. 'shop.buy' (lowercase start, camelCase)",
13
12
  noRun: "ops.define('{name}'): run(e, args, ctx) is required; it changes state. Put the \"may I\" checks in can(e, args, ctx)",
@@ -1,8 +1,8 @@
1
1
  // The dev guard of engine.ops (split out of Ops.js): reports saved gameplay state written outside a fixed step, an op or an allow() window.
2
2
  // Ops.guard(where) is the public entry; the work is here.
3
- import { coded } from './errorHints.js';
4
- import { devError, fmt } from './opsCheck.js';
5
- import { warnOnce } from './validate.js';
3
+ import { coded } from '../base/errorHints.js';
4
+ import { devError } from './opsCheck.js';
5
+ import { fmt, warnOnce } from '../base/validate.js';
6
6
 
7
7
  const STRINGS = {
8
8
  canWrote: "{name}'s can changed state ({where}). can is read-only; change state in run",
@@ -1,11 +1,11 @@
1
1
  // ops.run itself (split out of Ops.js). Order: can -> log -> [snapshot if atomic] -> run -> commit (revision + 1, after hook) or fail (rollback if atomic).
2
2
  // A run that returns or throws a structured failure { ok: false, code, facts?, nextActions? } counts as failed, like a can that said no (see opsFail.js).
3
- import { DEV } from './validate.js';
4
- import { devError, fmt, argRange } from './opsCheck.js';
5
- import { reportError } from './errors.js';
3
+ import { DEV, fmt } from '../base/validate.js';
4
+ import { devError, argRange } from './opsCheck.js';
5
+ import { reportError } from '../base/errors.js';
6
6
  import { failure, isRunFailure, opsBlocked } from './opsFail.js';
7
7
  import { snapshot, rollback, markRolledBack } from './opsAtomic.js';
8
- import { withDefaults } from './params.js';
8
+ import { withDefaults } from '../base/params.js';
9
9
 
10
10
  const MAX_DEPTH = 16;
11
11
  const RUN_STRINGS = {
@@ -66,6 +66,9 @@ export function runOp(ops, name, args, opts) {
66
66
  } catch (err) {
67
67
  if (snap) { undoWrites(ops, e, snap, where, seq, depth); ops._txAfter.length = mark; }
68
68
  if (err?.opsDevError) throw err;
69
+ // a bad value that came in as an argument is the caller's mistake, not a broken game: refused like a can that said no, so gameplay does not freeze on it.
70
+ // Only that one: a NaN the op worked out itself is a bug in the game, and goes on to stop it where it happened
71
+ if (err?.code === 'bad-position' && Object.values(args ?? {}).includes(err.value)) return failed(failure({ code: 'badPosition', facts: { message: err.message } }), h?.seq === seq ? h : null);
69
72
  if (h?.seq === seq) { h.ok = false; h.code = 'error'; } else ops._log(name, args, ctx, false, 'error', depth);
70
73
  reportError(e, err, where);
71
74
  if (e.error?.where === where && !e.error.ops) e.error.ops = ops.recent().slice(-5).map(r => `${r.name}${r.ok ? '' : ' x ' + r.code}`);