threedog 0.2.1 → 0.7.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 (725) hide show
  1. package/CHANGELOG.md +371 -1
  2. package/README.md +21 -12
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +92 -26
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +30 -15
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +40 -19
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +75 -25
  11. package/core/Describe.js +105 -45
  12. package/core/Engine.js +203 -75
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +175 -80
  16. package/core/Inspect.js +8 -5
  17. package/core/InspectMaterials.js +84 -0
  18. package/core/InspectPerf.js +68 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/MaterialInfo.js +7 -5
  22. package/core/Ops.js +50 -9
  23. package/core/Random.js +9 -2
  24. package/core/Rays.js +12 -7
  25. package/core/SaveStore.js +41 -9
  26. package/core/Saves.js +71 -15
  27. package/core/Stream.js +13 -10
  28. package/core/Threads.js +26 -7
  29. package/core/UrlState.js +69 -13
  30. package/core/Views.js +10 -6
  31. package/core/actor.js +1 -1
  32. package/core/adaptive.js +93 -0
  33. package/core/assetEntry.js +27 -7
  34. package/core/assetHot.js +176 -0
  35. package/core/assetLoad.js +44 -19
  36. package/core/assetManifest.js +53 -11
  37. package/core/assetReport.js +5 -5
  38. package/core/audioRules.js +13 -11
  39. package/core/audioVoice.js +69 -42
  40. package/core/batchGroups.js +9 -1
  41. package/core/canvasBox.js +1 -2
  42. package/core/catalog.js +21 -5
  43. package/core/cells.js +62 -0
  44. package/core/checks.js +10 -8
  45. package/core/chunkStream.js +87 -0
  46. package/core/control.js +149 -0
  47. package/core/copies.js +32 -0
  48. package/core/dayTime.js +12 -6
  49. package/core/debugView.js +85 -18
  50. package/core/describeRender.js +117 -21
  51. package/core/describeText.js +41 -21
  52. package/core/engineCamera.js +32 -0
  53. package/core/errorCodes.js +478 -32
  54. package/core/errorHints.js +41 -142
  55. package/core/errors.js +31 -8
  56. package/core/events.generated.js +13 -7
  57. package/core/gameLights.js +69 -0
  58. package/core/grayMap.js +20 -0
  59. package/core/grid.js +14 -13
  60. package/core/gridLoad.js +2 -1
  61. package/core/ground.js +6 -4
  62. package/core/headlessLoad.js +55 -0
  63. package/core/holds.js +78 -50
  64. package/core/inputContext.js +11 -7
  65. package/core/inputDefaults.js +24 -21
  66. package/core/inputPad.js +1 -1
  67. package/core/inputPointer.js +1 -1
  68. package/core/inputTouch.js +2 -2
  69. package/core/lifecycle.js +46 -12
  70. package/core/lightWatch.js +9 -5
  71. package/core/loop.js +109 -43
  72. package/core/math.js +18 -3
  73. package/core/moduleSlots.js +100 -0
  74. package/core/moduleTypes.js +86 -0
  75. package/core/modules.js +147 -29
  76. package/core/movement.js +2 -2
  77. package/core/namedModel.js +74 -0
  78. package/core/opsCheck.js +3 -3
  79. package/core/opsFail.js +15 -6
  80. package/core/opsGuard.js +4 -4
  81. package/core/opsRun.js +4 -3
  82. package/core/owned.js +171 -0
  83. package/core/page.js +44 -10
  84. package/core/params.js +30 -8
  85. package/core/pictureSlots.js +33 -0
  86. package/core/pictureWriters.js +343 -0
  87. package/core/plugins.js +245 -0
  88. package/core/saveApply.js +99 -17
  89. package/core/saveFiles.js +8 -6
  90. package/core/saveValues.js +46 -0
  91. package/core/saveVersions.js +20 -3
  92. package/core/scatter.js +48 -19
  93. package/core/sceneDelta.js +211 -0
  94. package/core/sceneMethods.js +31 -33
  95. package/core/screenToGround.js +1 -1
  96. package/core/services.js +27 -11
  97. package/core/session.js +28 -25
  98. package/core/shaderCost.js +78 -0
  99. package/core/shadowTypes.js +3 -2
  100. package/core/shadows.js +405 -0
  101. package/core/sharedPoint.js +303 -0
  102. package/core/skip.js +36 -28
  103. package/core/stackFrames.js +45 -0
  104. package/core/stacks.js +166 -0
  105. package/core/startup.js +153 -13
  106. package/core/streamSources.js +0 -11
  107. package/core/targeting.js +1 -1
  108. package/core/textureBytes.js +20 -0
  109. package/core/thingExplain.js +3 -3
  110. package/core/thingOps.js +29 -6
  111. package/core/things.js +22 -12
  112. package/core/threadPure.js +7 -3
  113. package/core/threePatches.js +47 -0
  114. package/core/tier.js +21 -10
  115. package/core/time.js +236 -0
  116. package/core/uiClock.js +25 -0
  117. package/core/util.js +8 -2
  118. package/core/validate.js +66 -87
  119. package/core/view.js +43 -0
  120. package/core/wrap.js +106 -0
  121. package/docs/AI.md +95 -104
  122. package/docs/API.md +35 -31
  123. package/docs/CODEMAP.md +231 -176
  124. package/docs/COMMANDS.md +63 -39
  125. package/docs/CONVENTIONS.md +99 -31
  126. package/docs/MIGRATING-0.3.md +248 -0
  127. package/docs/MIGRATING-0.4.md +320 -0
  128. package/docs/MIGRATING-0.5.md +68 -0
  129. package/docs/MIGRATING-0.6.md +126 -0
  130. package/docs/MIGRATING-0.7.md +39 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +82 -28
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +15 -11
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/budget.md +4 -0
  137. package/docs/api/calendar.md +41 -0
  138. package/docs/api/cameraRig.md +16 -5
  139. package/docs/api/characters.md +41 -24
  140. package/docs/api/clock.md +6 -5
  141. package/docs/api/collision.md +10 -7
  142. package/docs/api/content.md +6 -4
  143. package/docs/api/dialogue.md +9 -9
  144. package/docs/api/engine.md +95 -65
  145. package/docs/api/events.md +20 -14
  146. package/docs/api/grids.md +10 -3
  147. package/docs/api/ground.md +1 -1
  148. package/docs/api/hud.md +5 -2
  149. package/docs/api/i18n.md +1 -1
  150. package/docs/api/input.md +13 -7
  151. package/docs/api/interactions.md +10 -6
  152. package/docs/api/inventory.md +17 -17
  153. package/docs/api/level.md +0 -2
  154. package/docs/api/lightPool.md +3 -1
  155. package/docs/api/music.md +1 -1
  156. package/docs/api/nav.md +3 -0
  157. package/docs/api/occlusion.md +5 -0
  158. package/docs/api/openWorld.md +2 -1
  159. package/docs/api/particles.md +6 -3
  160. package/docs/api/photo.md +0 -2
  161. package/docs/api/pickups.md +21 -0
  162. package/docs/api/post.md +8 -5
  163. package/docs/api/quests.md +2 -3
  164. package/docs/api/rigid.md +16 -14
  165. package/docs/api/saves.md +6 -4
  166. package/docs/api/settings.md +2 -3
  167. package/docs/api/sky.md +18 -49
  168. package/docs/api/stream.md +1 -1
  169. package/docs/api/terrain.md +16 -7
  170. package/docs/api/terrainDraw.md +12 -0
  171. package/docs/api/timeline.md +3 -4
  172. package/docs/api/tools.md +32 -15
  173. package/docs/api/triggers.md +7 -10
  174. package/docs/api/vegetation.md +17 -9
  175. package/docs/api/vegetationDraw.md +10 -0
  176. package/docs/api/water.md +9 -21
  177. package/docs/api/weather.md +10 -15
  178. package/docs/api/weatherDraw.md +10 -0
  179. package/docs/api/world.md +3 -2
  180. package/docs/recipes/01-new-game.md +52 -42
  181. package/docs/recipes/02-npc.md +24 -7
  182. package/docs/recipes/03-items-pickups.md +57 -22
  183. package/docs/recipes/04-quests.md +12 -5
  184. package/docs/recipes/05-props-bake.md +174 -22
  185. package/docs/recipes/06-clock-events.md +100 -52
  186. package/docs/recipes/07-flow-scenes-pause.md +50 -10
  187. package/docs/recipes/08-weather-sky.md +134 -37
  188. package/docs/recipes/09-materials-lights-models.md +185 -0
  189. package/docs/recipes/10-blender-level.md +16 -4
  190. package/docs/recipes/11-vehicles.md +67 -10
  191. package/docs/recipes/13-animation.md +23 -9
  192. package/docs/recipes/14-custom-module.md +63 -29
  193. package/docs/recipes/15-perf.md +31 -10
  194. package/docs/recipes/16-dev-bridge.md +74 -40
  195. package/docs/recipes/18-world.md +26 -14
  196. package/docs/recipes/19-shooting-picking.md +12 -10
  197. package/docs/recipes/20-content-actions-save.md +60 -18
  198. package/docs/recipes/21-camera.md +55 -17
  199. package/docs/recipes/22-shop-gold.md +3 -3
  200. package/docs/recipes/23-ops.md +17 -11
  201. package/docs/recipes/26-ui-parts.md +86 -13
  202. package/docs/recipes/27-net.md +11 -5
  203. package/docs/recipes/28-terrain.md +36 -3
  204. package/docs/recipes/29-grid.md +46 -19
  205. package/docs/recipes/30-templates.md +72 -15
  206. package/docs/recipes/31-audio.md +20 -12
  207. package/docs/recipes/32-action-game.md +51 -4
  208. package/docs/recipes/34-environment-lighting.md +108 -21
  209. package/docs/recipes/35-picture-from-reference.md +147 -0
  210. package/docs/recipes/36-sky-ground-plants.md +158 -0
  211. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
  212. package/docs/recipes/38-environment-hooks.md +67 -0
  213. package/docs/recipes/40-scene.md +114 -32
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surfaces.md +206 -0
  216. package/docs/recipes/44-water-weather-hooks.md +191 -0
  217. package/docs/recipes/45-cascaded-shadows.md +130 -23
  218. package/docs/recipes/46-blender-art-route.md +17 -20
  219. package/docs/recipes/47-island-snow-backdrop.md +13 -15
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +4 -4
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-around-the-picture.md +181 -0
  224. package/docs/recipes/53-ground-up-close.md +12 -12
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +124 -0
  227. package/docs/recipes/56-webgpu-tsl.md +303 -0
  228. package/docs/recipes/57-control.md +104 -0
  229. package/docs/recipes/58-input.md +60 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +70 -0
  232. package/docs/recipes/61-deploy.md +27 -0
  233. package/docs/recipes/62-picture-code.md +244 -0
  234. package/docs/recipes/63-third-person-start.md +77 -0
  235. package/docs/recipes/64-particles.md +35 -0
  236. package/examples/action/.threedog/content-index.json +1 -0
  237. package/examples/action/GAMEMAP.md +20 -14
  238. package/examples/action/assets.js +8 -0
  239. package/examples/action/content/actions.js +1 -1
  240. package/examples/action/content/audio.js +5 -5
  241. package/examples/action/main.js +12 -15
  242. package/examples/action/models.js +23 -24
  243. package/examples/action/picture/index.js +13 -0
  244. package/examples/action/picture/lights.js +35 -0
  245. package/examples/action/picture/materials.js +8 -0
  246. package/examples/action/picture/palette.js +33 -0
  247. package/examples/plain-picture/.threedog/content-index.json +1 -0
  248. package/examples/plain-picture/FINDINGS.md +53 -0
  249. package/examples/plain-picture/GAMEMAP.md +90 -0
  250. package/examples/plain-picture/main.js +48 -0
  251. package/examples/plain-picture/picture/index.js +21 -0
  252. package/examples/plain-picture/picture/lights.js +54 -0
  253. package/examples/plain-picture/picture/materials.js +24 -0
  254. package/examples/plain-picture/picture/palette.js +16 -0
  255. package/examples/plain-picture/picture/sky.js +37 -0
  256. package/examples/pullable.json +133 -0
  257. package/examples/rc2d/.threedog/content-index.json +1 -0
  258. package/examples/rc2d/GAMEMAP.md +88 -0
  259. package/examples/rc2d/README.md +57 -0
  260. package/examples/rc2d/main.js +55 -0
  261. package/examples/rc2d/picture/index.js +18 -0
  262. package/examples/rc2d/picture/lights.js +11 -0
  263. package/examples/rc2d/picture/materials.js +18 -0
  264. package/examples/rc2d/picture/palette.js +15 -0
  265. package/examples/rc2d/picture/post.js +11 -0
  266. package/examples/rc2d/rc2d.js +187 -0
  267. package/examples/rc2d/shaders.js +144 -0
  268. package/examples/sheepisland/.threedog/content-index.json +1 -0
  269. package/examples/sheepisland/GAMEMAP.md +22 -17
  270. package/examples/sheepisland/assets.js +5 -0
  271. package/examples/sheepisland/content/templates.js +1 -1
  272. package/examples/sheepisland/content/vegetation.js +3 -1
  273. package/examples/sheepisland/main.js +29 -18
  274. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  275. package/examples/sheepisland/picture/index.js +20 -0
  276. package/examples/sheepisland/picture/lights.js +34 -0
  277. package/examples/sheepisland/picture/materials.js +61 -0
  278. package/examples/sheepisland/picture/palette.js +60 -0
  279. package/examples/sheepisland/picture/sky.js +20 -0
  280. package/examples/sheepisland/views.js +1 -1
  281. package/examples/styletest/.threedog/content-index.json +1 -0
  282. package/examples/styletest/GAMEMAP.md +25 -22
  283. package/examples/styletest/assets.js +6 -0
  284. package/examples/styletest/content/templates.js +1 -1
  285. package/examples/styletest/content/vegetation.js +1 -1
  286. package/examples/styletest/main.js +25 -34
  287. package/examples/styletest/models.js +30 -30
  288. package/examples/styletest/params.js +2 -5
  289. package/examples/styletest/picture/env.js +38 -0
  290. package/examples/styletest/picture/index.js +16 -0
  291. package/examples/styletest/picture/lights.js +9 -0
  292. package/examples/styletest/picture/materials.js +28 -0
  293. package/examples/styletest/picture/palette.js +22 -0
  294. package/examples/techniques/contact-shadows/README.md +91 -0
  295. package/examples/techniques/contact-shadows/contactShadows.js +67 -0
  296. package/examples/techniques/contact-shadows/main.js +55 -0
  297. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  298. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  299. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  300. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  301. package/examples/techniques/day-night-grade/README.md +83 -0
  302. package/examples/techniques/day-night-grade/main.js +41 -0
  303. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  304. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  305. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  306. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  307. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  308. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  309. package/examples/techniques/interior-light/README.md +106 -0
  310. package/examples/techniques/interior-light/interiorLight.js +47 -0
  311. package/examples/techniques/interior-light/main.js +87 -0
  312. package/examples/techniques/interior-light/picture/index.js +24 -0
  313. package/examples/techniques/interior-light/picture/lights.js +52 -0
  314. package/examples/techniques/interior-light/picture/materials.js +13 -0
  315. package/examples/techniques/interior-light/picture/palette.js +32 -0
  316. package/examples/techniques/interior-light/picture/sky.js +40 -0
  317. package/examples/techniques/modular-building/README.md +126 -0
  318. package/examples/techniques/modular-building/kit.js +426 -0
  319. package/examples/techniques/modular-building/main.js +39 -0
  320. package/examples/techniques/modular-building/picture/index.js +17 -0
  321. package/examples/techniques/modular-building/picture/lights.js +26 -0
  322. package/examples/techniques/modular-building/picture/materials.js +13 -0
  323. package/examples/techniques/modular-building/picture/palette.js +23 -0
  324. package/examples/techniques/night-lights/README.md +95 -0
  325. package/examples/techniques/night-lights/main.js +47 -0
  326. package/examples/techniques/night-lights/nightLights.js +95 -0
  327. package/examples/techniques/night-lights/picture/index.js +18 -0
  328. package/examples/techniques/night-lights/picture/lights.js +44 -0
  329. package/examples/techniques/night-lights/picture/materials.js +15 -0
  330. package/examples/techniques/night-lights/picture/palette.js +34 -0
  331. package/examples/techniques/night-lights/picture/post.js +9 -0
  332. package/examples/techniques/night-lights/picture/sky.js +36 -0
  333. package/examples/techniques/outlines-and-rim/README.md +59 -0
  334. package/examples/techniques/outlines-and-rim/main.js +61 -0
  335. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  336. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  337. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  338. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  339. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  340. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  341. package/examples/techniques/procedural-animation/README.md +79 -0
  342. package/examples/techniques/procedural-animation/creature.js +44 -0
  343. package/examples/techniques/procedural-animation/main.js +47 -0
  344. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  345. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  346. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  347. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  348. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  349. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  350. package/examples/techniques/procedural-surface/README.md +69 -0
  351. package/examples/techniques/procedural-surface/main.js +65 -0
  352. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  353. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  354. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  355. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  356. package/examples/techniques/procedural-surface/surface.js +120 -0
  357. package/examples/techniques/stylized-shading/README.md +74 -0
  358. package/examples/techniques/stylized-shading/main.js +62 -0
  359. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  360. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  361. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  362. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  363. package/examples/techniques/stylized-shading/shading.js +131 -0
  364. package/examples/techniques/sun-and-key-light/README.md +133 -0
  365. package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
  366. package/examples/techniques/sun-and-key-light/main.js +51 -0
  367. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  368. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  369. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  370. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  371. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  372. package/examples/techniques/three-looks/README.md +21 -0
  373. package/examples/techniques/three-looks/main.js +58 -0
  374. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  375. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  376. package/examples/techniques/three-looks/picture/comic.js +27 -0
  377. package/examples/techniques/three-looks/picture/index.js +14 -0
  378. package/examples/techniques/three-looks/picture/sun.js +23 -0
  379. package/examples/techniques/wet-road/README.md +102 -0
  380. package/examples/techniques/wet-road/main.js +48 -0
  381. package/examples/techniques/wet-road/picture/index.js +17 -0
  382. package/examples/techniques/wet-road/picture/lights.js +57 -0
  383. package/examples/techniques/wet-road/picture/materials.js +16 -0
  384. package/examples/techniques/wet-road/picture/palette.js +24 -0
  385. package/examples/techniques/wet-road/picture/sky.js +46 -0
  386. package/examples/techniques/wet-road/wetRoad.js +209 -0
  387. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  388. package/examples/webgpu-tsl/GAMEMAP.md +89 -0
  389. package/examples/webgpu-tsl/README.md +45 -0
  390. package/examples/webgpu-tsl/main.js +44 -0
  391. package/examples/webgpu-tsl/picture/index.js +18 -0
  392. package/examples/webgpu-tsl/picture/lights.js +25 -0
  393. package/examples/webgpu-tsl/picture/materials.js +36 -0
  394. package/examples/webgpu-tsl/picture/palette.js +23 -0
  395. package/examples/webgpu-tsl/picture/post.js +16 -0
  396. package/examples/webgpu-tsl/picture/sky.js +30 -0
  397. package/examples/world/.threedog/content-index.json +1 -0
  398. package/examples/world/GAMEMAP.md +31 -21
  399. package/examples/world/art/humanoid.js +38 -0
  400. package/examples/world/art/index.js +11 -0
  401. package/examples/world/art/models.js +57 -0
  402. package/examples/world/art/shapes.js +9 -0
  403. package/examples/world/assets.js +6 -0
  404. package/examples/world/content/audio.js +5 -5
  405. package/examples/world/content/items.js +1 -1
  406. package/examples/world/content/npcs.js +1 -1
  407. package/examples/world/content/props.js +1 -1
  408. package/examples/world/content/rules.js +1 -1
  409. package/examples/world/content/templates.js +1 -1
  410. package/examples/world/content/vegetation.js +1 -1
  411. package/examples/world/main.js +22 -18
  412. package/examples/world/models.js +17 -7
  413. package/examples/world/picture/index.js +20 -0
  414. package/examples/world/picture/lights.js +41 -0
  415. package/examples/world/picture/materials.js +34 -0
  416. package/examples/world/picture/palette.js +74 -0
  417. package/examples/world/picture/post.js +9 -0
  418. package/examples/world/picture/sky.js +39 -0
  419. package/index.d.ts +44 -54
  420. package/index.js +29 -25
  421. package/llms.txt +24 -15
  422. package/modules/ambience/Ambience.js +34 -23
  423. package/modules/calendar/Calendar.js +163 -0
  424. package/modules/calendar/contract.js +21 -0
  425. package/modules/calendar/index.js +82 -0
  426. package/modules/{sky → calendar}/schedule.js +17 -16
  427. package/modules/calendar/seasons.js +55 -0
  428. package/modules/camera/FirstPersonCamera.js +6 -15
  429. package/modules/camera/FixedCamera.js +33 -15
  430. package/modules/camera/FollowCamera.js +90 -16
  431. package/modules/camera/RtsCamera.js +18 -17
  432. package/modules/camera/common.js +73 -20
  433. package/modules/camera/contract.js +17 -0
  434. package/modules/camera/projection.js +11 -24
  435. package/modules/characters/Character.js +188 -48
  436. package/modules/characters/NPC.js +92 -41
  437. package/modules/characters/assetModel.js +8 -16
  438. package/modules/characters/behaviors.js +2 -1
  439. package/modules/characters/contract.js +13 -0
  440. package/modules/characters/footsteps.js +1 -1
  441. package/modules/characters/index.js +112 -49
  442. package/modules/characters/moveHelpers.js +4 -5
  443. package/modules/characters/movers/common.js +102 -19
  444. package/modules/characters/movers/manual.js +23 -0
  445. package/modules/characters/movers/rapier.js +19 -16
  446. package/modules/characters/movers/simple.js +14 -11
  447. package/modules/characters/movers/support.js +186 -0
  448. package/modules/characters/npcAvoid.js +47 -42
  449. package/modules/characters/npcSim.js +17 -9
  450. package/modules/characters/npcView.js +44 -16
  451. package/modules/characters/pathAsync.js +7 -3
  452. package/modules/characters/playerStrings.js +4 -3
  453. package/modules/characters/proceduralRig.js +19 -4
  454. package/modules/characters/useModel.js +2 -2
  455. package/modules/characters/vehicle.contract.js +21 -0
  456. package/modules/characters/walkTo.js +21 -7
  457. package/modules/collision/Collision.js +69 -27
  458. package/modules/collision/grid.js +8 -6
  459. package/modules/content/explain.js +2 -2
  460. package/modules/content/fields.js +102 -0
  461. package/modules/content/ids.js +8 -6
  462. package/modules/content/index.js +104 -27
  463. package/modules/content/loader.js +45 -33
  464. package/modules/content/models.js +58 -42
  465. package/modules/content/packs.js +6 -5
  466. package/modules/content/parts.js +41 -0
  467. package/modules/content/props.js +20 -11
  468. package/modules/content/rules.js +66 -0
  469. package/modules/content/stages.js +80 -0
  470. package/modules/content/templates.js +123 -30
  471. package/modules/debug/DebugPanel.js +24 -17
  472. package/modules/flow/contract.js +16 -0
  473. package/modules/flow/index.js +21 -15
  474. package/modules/gameplay/Container.js +41 -32
  475. package/modules/gameplay/Containers.js +30 -15
  476. package/modules/gameplay/Dialogue.js +113 -55
  477. package/modules/gameplay/Interactions.js +273 -72
  478. package/modules/gameplay/Inventory.js +72 -76
  479. package/modules/gameplay/Quests.js +75 -39
  480. package/modules/gameplay/boxOps.js +3 -3
  481. package/modules/gameplay/dialogue.contract.js +21 -0
  482. package/modules/gameplay/dialogueBox.js +4 -2
  483. package/modules/gameplay/dialogueBubbles.js +116 -0
  484. package/modules/gameplay/interactionPrompt.js +4 -1
  485. package/modules/gameplay/interactions.contract.js +16 -0
  486. package/modules/gameplay/inventory.contract.js +23 -0
  487. package/modules/gameplay/inventoryOps.js +19 -17
  488. package/modules/gameplay/pickups.js +306 -85
  489. package/modules/gameplay/questLog.js +6 -6
  490. package/modules/gameplay/quests.contract.js +17 -0
  491. package/modules/grid/Grid.js +92 -50
  492. package/modules/grid/Layer.js +27 -13
  493. package/modules/grid/index.js +96 -43
  494. package/modules/grid/ops.js +20 -18
  495. package/modules/grid/preview.js +37 -29
  496. package/modules/grid/strings.js +12 -0
  497. package/modules/grid/tiles.js +19 -22
  498. package/modules/hlod/index.js +52 -19
  499. package/modules/hud/index.js +48 -20
  500. package/modules/hud/parts.js +28 -13
  501. package/modules/level/heightfield.js +3 -1
  502. package/modules/level/index.js +49 -23
  503. package/modules/level/nodes.js +4 -3
  504. package/modules/lights/index.js +47 -19
  505. package/modules/music/Music.js +38 -21
  506. package/modules/music/rules.js +1 -1
  507. package/modules/nav/index.js +48 -42
  508. package/modules/net/Client.js +13 -6
  509. package/modules/net/Host.js +19 -5
  510. package/modules/net/Net.js +2 -1
  511. package/modules/net/index.js +13 -8
  512. package/modules/net/sync.js +9 -8
  513. package/modules/net/transports.js +77 -27
  514. package/modules/particles/Particles.js +58 -28
  515. package/modules/particles/contract.js +17 -0
  516. package/modules/particles/effect.js +54 -11
  517. package/modules/photo/Photo.js +56 -38
  518. package/modules/rigid/RigidBodies.js +194 -32
  519. package/modules/rigid/Vehicles.js +18 -15
  520. package/modules/rigid/sync.js +62 -17
  521. package/modules/settings/Settings.js +60 -55
  522. package/modules/settings/apply.js +38 -3
  523. package/modules/settings/sections.js +5 -3
  524. package/modules/settings/strings.js +3 -2
  525. package/modules/settings/view.js +5 -3
  526. package/modules/sky/Sky.js +132 -205
  527. package/modules/sky/clouds.js +37 -23
  528. package/modules/sky/dome.js +100 -0
  529. package/modules/sky/domeLayers.js +30 -15
  530. package/modules/sky/environment.js +45 -99
  531. package/modules/sky/fog.js +9 -139
  532. package/modules/sky/frame.js +60 -56
  533. package/modules/sky/season.js +21 -0
  534. package/modules/sky/shader.js +63 -35
  535. package/modules/sky/skyModule.js +52 -37
  536. package/modules/sky/tint.js +59 -0
  537. package/modules/terrain/ChunkManager.js +194 -110
  538. package/modules/terrain/chunkJob.js +1 -1
  539. package/modules/terrain/chunkQueries.js +6 -4
  540. package/modules/terrain/draw.js +154 -0
  541. package/modules/terrain/index.js +87 -54
  542. package/modules/terrain/terrainDefaults.js +2 -2
  543. package/modules/terrain/terrainEdit.js +18 -20
  544. package/modules/terrain/terrainGen.js +6 -4
  545. package/modules/terrain/terrainIsland.js +5 -4
  546. package/modules/terrain/terrainShape.js +12 -12
  547. package/modules/terrain/terrainShapeMain.js +8 -7
  548. package/modules/terrain/terrainTexture.js +21 -19
  549. package/modules/timeline/Timeline.js +95 -43
  550. package/modules/timeline/Tween.js +18 -10
  551. package/modules/timeline/letterbox.js +2 -2
  552. package/modules/timeline/shots.js +5 -1
  553. package/modules/triggers/index.js +111 -76
  554. package/modules/vegetation/Vegetation.js +229 -112
  555. package/modules/vegetation/densityMap.js +62 -0
  556. package/modules/vegetation/draw.js +191 -0
  557. package/modules/vegetation/groundChunks.js +52 -58
  558. package/modules/vegetation/index.js +32 -11
  559. package/modules/vegetation/modelGeometry.js +3 -2
  560. package/modules/vegetation/nearFade.js +8 -2
  561. package/modules/water/Water.js +157 -72
  562. package/modules/water/surface.js +86 -47
  563. package/modules/weather/Weather.js +96 -103
  564. package/modules/weather/particles.js +37 -14
  565. package/modules/weather/shaders.js +1 -1
  566. package/modules/weather/strings.js +2 -2
  567. package/modules/weather/weatherDraw.js +141 -0
  568. package/modules/world/World.js +26 -9
  569. package/modules/world/explain.js +1 -1
  570. package/modules/world/index.js +18 -4
  571. package/modules/world/persist.js +62 -2
  572. package/modules/world/pos.js +3 -2
  573. package/modules/world/records.js +8 -6
  574. package/modules/world/sim.js +60 -20
  575. package/modules/world/simFar.js +4 -3
  576. package/modules/world/state.js +3 -2
  577. package/modules/world/thingSource.js +1 -1
  578. package/modules/world/views.js +8 -6
  579. package/package.json +8 -3
  580. package/presets.js +43 -29
  581. package/render/PostFX.js +318 -135
  582. package/render/backend.js +486 -0
  583. package/render/cascades.js +195 -0
  584. package/render/cascades.tsl.js +96 -0
  585. package/render/daylight.js +39 -0
  586. package/render/detail.js +122 -41
  587. package/render/effects.js +155 -48
  588. package/render/engineUniforms.js +10 -1
  589. package/render/fuse.js +5 -4
  590. package/render/fx/cel.tsl.js +42 -0
  591. package/render/fx/cloudShadow.tsl.js +16 -0
  592. package/render/fx/detail.tsl.js +66 -0
  593. package/render/fx/index.js +28 -0
  594. package/render/fx/lighting.tsl.js +28 -0
  595. package/render/fx/nodeErrors.tsl.js +68 -0
  596. package/render/fx/noise.tsl.js +12 -0
  597. package/render/fx/objectOrigin.tsl.js +42 -0
  598. package/render/fx/particles.tsl.js +139 -0
  599. package/render/fx/patchNodes.tsl.js +403 -0
  600. package/render/fx/postWebGPU.tsl.js +181 -0
  601. package/render/fx/season.tsl.js +13 -0
  602. package/render/fx/sky.tsl.js +187 -0
  603. package/render/fx/uniforms.tsl.js +67 -0
  604. package/render/fx/water.tsl.js +53 -0
  605. package/render/fx/wind.tsl.js +22 -0
  606. package/render/fxNumbers.js +36 -0
  607. package/render/hotGlsl.js +24 -0
  608. package/render/layers.js +14 -0
  609. package/render/lighting.js +71 -18
  610. package/render/lightmap.js +142 -0
  611. package/render/lights.js +47 -6
  612. package/render/materials.js +55 -152
  613. package/render/modeling.js +73 -0
  614. package/render/neutral.js +23 -0
  615. package/render/occlusion.js +184 -0
  616. package/render/ownFrame.js +76 -0
  617. package/render/patches.js +317 -35
  618. package/render/postWebGL.js +205 -0
  619. package/render/probes.js +288 -0
  620. package/render/shaderErrors.js +154 -0
  621. package/render/slots.js +165 -0
  622. package/render/terms.js +163 -0
  623. package/render/uniformDecl.js +4 -3
  624. package/types/common.d.ts +2 -2
  625. package/types/core.d.ts +757 -346
  626. package/types/gameplay.d.ts +539 -330
  627. package/types/generated/core/Audio.d.ts +26 -42
  628. package/types/generated/core/Batching.d.ts +6 -2
  629. package/types/generated/core/Budget.d.ts +2 -8
  630. package/types/generated/core/DebugOverrides.d.ts +58 -9
  631. package/types/generated/core/I18n.d.ts +2 -2
  632. package/types/generated/core/Input.d.ts +110 -32
  633. package/types/generated/core/Ops.d.ts +31 -0
  634. package/types/generated/core/Random.d.ts +2 -2
  635. package/types/generated/core/Saves.d.ts +10 -2
  636. package/types/generated/core/Stream.d.ts +1 -1
  637. package/types/generated/core/Threads.d.ts +4 -1
  638. package/types/generated/core/Views.d.ts +0 -1
  639. package/types/generated/core/audioVoice.d.ts +17 -9
  640. package/types/generated/core/control.d.ts +55 -0
  641. package/types/generated/core/page.d.ts +9 -2
  642. package/types/generated/core/session.d.ts +2 -1
  643. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  644. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  645. package/types/generated/modules/calendar/index.d.ts +10 -0
  646. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  647. package/types/generated/modules/grid/Grid.d.ts +61 -25
  648. package/types/generated/modules/grid/Layer.d.ts +13 -5
  649. package/types/generated/modules/grid/index.d.ts +56 -20
  650. package/types/generated/modules/music/Music.d.ts +5 -3
  651. package/types/generated/modules/net/index.d.ts +3 -3
  652. package/types/generated/modules/net/transports.d.ts +12 -3
  653. package/types/generated/modules/particles/Particles.d.ts +13 -6
  654. package/types/generated/modules/sky/Sky.d.ts +85 -110
  655. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  656. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  657. package/types/generated/modules/water/Water.d.ts +50 -3
  658. package/types/generated/modules/weather/Weather.d.ts +44 -15
  659. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  660. package/types/generated/modules/world/World.d.ts +20 -5
  661. package/types/generated/render/PostFX.d.ts +109 -29
  662. package/types/generated/render/lighting.d.ts +29 -0
  663. package/types/generated/render/materials.d.ts +31 -50
  664. package/types/generated/render/modeling.d.ts +30 -0
  665. package/types/generated/render/occlusion.d.ts +13 -0
  666. package/types/generated/render/patches.d.ts +16 -2
  667. package/types/generated/ui/UI.d.ts +6 -3
  668. package/types/nav.d.ts +6 -0
  669. package/types/physics.d.ts +140 -45
  670. package/types/tsl.d.ts +94 -0
  671. package/types/world.d.ts +489 -122
  672. package/ui/Focus.js +35 -14
  673. package/ui/LoadingScreen.js +3 -3
  674. package/ui/Parts.js +35 -15
  675. package/ui/UI.js +27 -17
  676. package/ui/cursor.js +115 -0
  677. package/ui/defaults.js +15 -11
  678. package/ui/theme.js +36 -27
  679. package/ui/touchPart.js +2 -2
  680. package/core/claims.js +0 -51
  681. package/core/look/coreParts.js +0 -112
  682. package/core/look/layers.js +0 -136
  683. package/core/look/part.js +0 -173
  684. package/core/look/report.js +0 -79
  685. package/core/look/write.js +0 -86
  686. package/core/renamed.js +0 -22
  687. package/core/styleParts.js +0 -98
  688. package/docs/api/entities.md +0 -61
  689. package/docs/api/style.md +0 -134
  690. package/docs/recipes/09-style-pack.md +0 -169
  691. package/docs/recipes/35-style-from-reference.md +0 -84
  692. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  693. package/docs/recipes/38-environment-look-hooks.md +0 -88
  694. package/docs/recipes/41-thing-registry.md +0 -93
  695. package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
  696. package/docs/recipes/44-water-weather-look-hooks.md +0 -135
  697. package/docs/recipes/48-make-material.md +0 -70
  698. package/docs/recipes/52-look.md +0 -146
  699. package/examples/action/look.js +0 -5
  700. package/examples/sheepisland/style/index.js +0 -79
  701. package/examples/styletest/look.js +0 -11
  702. package/examples/styletest/overrides.js +0 -33
  703. package/examples/styletest/panel.js +0 -135
  704. package/modules/entities/Entities.js +0 -243
  705. package/modules/entities/build.js +0 -25
  706. package/modules/entities/index.js +0 -4
  707. package/modules/sky/calendar.js +0 -80
  708. package/modules/sky/cascades.js +0 -125
  709. package/modules/sky/layers.js +0 -69
  710. package/modules/sky/look.js +0 -51
  711. package/modules/sky/lookFog.js +0 -80
  712. package/modules/sky/lookShadow.js +0 -50
  713. package/modules/sky/lookSky.js +0 -108
  714. package/modules/sky/shadow.js +0 -74
  715. package/modules/terrain/chunkLevels.js +0 -40
  716. package/modules/terrain/lookGround.js +0 -61
  717. package/modules/terrain/mountTerrain.js +0 -32
  718. package/modules/vegetation/lookWind.js +0 -37
  719. package/modules/water/look.js +0 -80
  720. package/modules/weather/look.js +0 -75
  721. package/modules/world/cells.js +0 -42
  722. package/render/lookSurface.js +0 -161
  723. package/render/postLook.js +0 -86
  724. package/render/surface.js +0 -69
  725. package/types/style.d.ts +0 -643
@@ -0,0 +1,55 @@
1
+ // Headless loading after start: a headless engine (?threedog-headless, createEngine({ headless: true })) has no real-time loop, so after start()
2
+ // nothing runs frames unless someone calls step(). Anything that makes the world load again after start (a species added with
3
+ // vegetation.define, terrain.setDensity, a teleport, a level swap) queued its work and waited for frames that never came: the page sat on
4
+ // "waiting for module terrain" forever, while the same page in a live browser loaded within a second.
5
+ //
6
+ // Why a load pump and not "step more" in the tools: step() is synchronous, and chunk results come back from workers between tasks, so no
7
+ // number of steps inside one call can finish a load. Only frames spread over real time can, which is what a live loop gives. So while the
8
+ // world is not settled, the headless engine runs the same loading frame start() runs (frame hooks, stream, jobs; game time does not move:
9
+ // dt 0, jobs drain deterministically), on a timer. A settled world runs nothing, so step()-driven tests keep their exact frame count.
10
+ //
11
+ // stateApplied waits for it too (Engine.js): screenshots, npm test and the dev bridge wait on stateApplied, so a load that began after
12
+ // start is finished before they capture. A load that never settles stops holding stateApplied after engine.loading.timeoutMs (same limit
13
+ // as start()) with one warning naming who is still waiting, so a stuck module cannot hang a tool.
14
+ import { DEV, warnOnce } from './validate.js';
15
+ import { coded } from './errorHints.js';
16
+
17
+ const TICK_MS = 16; // one loading frame per ~60 Hz tick: the same pace a live loop gives the workers
18
+
19
+ /** Modules whose isReady(e) is false, plus the stream when its required nearby builds are not done ([] = settled) */
20
+ export function unsettled(e) {
21
+ const who = [];
22
+ for (const m of e.modules.values()) if (m.isReady && !m.isReady(e)) who.push(m.name);
23
+ if (!e.stream.ready) who.push('the stream (required nearby builds)');
24
+ return who;
25
+ }
26
+
27
+ /** @internal start(): begin pumping loading frames for a headless engine (no-op for a live one, its loop already runs frames) */
28
+ export function startHeadlessLoad(e) {
29
+ if (!e.headless || e._headlessLoad) return;
30
+ const s = e._headlessLoad = { since: -1, stalled: false, timer: 0 };
31
+ const tick = () => {
32
+ if (e.disposed) return;
33
+ if (!unsettled(e).length) { s.since = -1; s.stalled = false; }
34
+ else {
35
+ const now = performance.now(); // measure: wall clock, only to stop a stuck load from holding stateApplied forever
36
+ if (s.since < 0) s.since = now;
37
+ // the same loading frame start() runs while it waits (startup.js _waitReady): frame hooks, stream, jobs; game time stays put
38
+ // (no input.endFrame: a key a test pressed before its next step() must still read as just pressed there)
39
+ e._frameHooks(0, true);
40
+ if (!s.stalled && now - s.since > e.loading.timeoutMs) {
41
+ s.stalled = true;
42
+ const who = unsettled(e);
43
+ if (DEV && who.length) warnOnce(coded('module-not-ready', `headless load after start stalled: still waiting after ${Math.round(e.loading.timeoutMs / 1000)} s for: ${who.join(', ')}; stateApplied no longer waits for it. A module's isReady(e) keeps returning false; fix that module, or raise engine.loading.timeoutMs if the load is just slow`));
44
+ }
45
+ }
46
+ s.timer = setTimeout(tick, TICK_MS); // main-loop: a headless engine's stand-in for the live frame loop while something is loading
47
+ };
48
+ tick();
49
+ }
50
+
51
+ /** @internal stateApplied: true when the world is settled (or its post-start load gave up after timeoutMs); always true for a live engine */
52
+ export function headlessSettled(e) {
53
+ const s = e._headlessLoad;
54
+ return !s || s.stalled || !unsettled(e).length;
55
+ }
package/core/holds.js CHANGED
@@ -1,91 +1,102 @@
1
- // Who holds the engine still: pause / resume, freeze / unfreeze, runState, and the camera takeover (takeCamera / cameraOverride).
2
- // Split out of loop.js (which keeps the loop itself) so each owner-based hold uses the same claims() rules (core/claims.js) in one file.
1
+ // Who holds the engine still: pause, freeze (each ends with its handle's remove()), runState, and the camera takeover (takeCamera / cameraOverride).
2
+ // Each is a named stack (core/stacks.js: 'pause' and 'freeze' kind any, 'camera' kind top), so they follow the same owner rules as every shared quantity:
3
+ // engine.freeze('menu') is engine.mod('freeze', { owner: 'menu' }) with the loop's side effects added (ending the last pause restarts the loop).
4
+ // One entry per mechanism: the handle's remove() ends a pause / freeze (there is no engine.resume / engine.unfreeze).
3
5
  import { warnOnce } from './validate.js';
4
- import { coded, renamed } from './errorHints.js';
5
- import { ownerArgs } from './claims.js';
6
+ import { coded } from './errorHints.js';
7
+ import { ownerArgs } from './sharedPoint.js';
6
8
 
7
- // pause / freeze return a claim handle, but they used to return the engine for chaining (engine.pause('x').step(1)); the handle forwards those
8
- // calls so old code keeps working. release (optional) replaces the bare claim removal when releasing has side effects (resume restarts the loop).
9
- const CHAIN = ['pause', 'resume', 'freeze', 'unfreeze', 'step'];
10
- function chained(e, h, release) {
11
- const out = { owner: h.owner, remove: release ? () => { if (e._pausers.has(h.owner)) release(); } : h.remove };
12
- for (const k of CHAIN) out[k] = (...a) => e[k](...a);
13
- return out;
9
+ // The pause / freeze handle is { owner, remove() } only: no chaining, so a pause is ended in exactly one way.
10
+ function handle(owner, remove) { return { owner, remove }; }
11
+
12
+ /**
13
+ * The three hold stacks: 'freeze' and 'pause' (kind any), 'camera' (kind top). services.js and the test engines call this, so both get the same stacks.
14
+ * The pause stack does the loop side effect itself (onChange), not engine.pause(): engine.mod('pause', { owner }), engine.pause(owner), the handle's
15
+ * remove() and _resume(owner) are then one behavior. Making mod('pause') throw instead would leave a quantity that engine.mod names in describe
16
+ * but refuses to change, a special case to remember; with onChange there is no path that holds the stack without stopping the loop.
17
+ * @param {any} engine
18
+ */
19
+ export function defineHoldStacks(engine) {
20
+ engine.stacks.define('freeze', { kind: 'any', save: false }); // who froze gameplay
21
+ engine.stacks.define('pause', { kind: 'any', save: false, onChange: () => { // who paused the loop; it resumes only when empty
22
+ if (engine.stacks.get('pause').size()) engine.paused = true;
23
+ else if (!engine.disposed) { engine.paused = false; engine._loop(); }
24
+ } });
25
+ engine.stacks.define('camera', { kind: 'top', save: false }); // who holds the camera; the latest is in charge (cameraOverride)
14
26
  }
15
27
 
16
28
  export const holdMethods = {
17
29
  /**
18
30
  * Pause the real-time loop (the picture stops and the game stops advancing). owner names who paused (default 'game'; pause({ owner }) works too): the loop
19
- * stays paused until every owner has resumed, and resume(owner) by someone who did not pause does not undo another owner's pause.
31
+ * stays paused until every owner has resumed, and _resume(owner) by someone who did not pause does not undo another owner's pause.
20
32
  * kind tells engine.runState what the pause means: 'test' (a test or the dev bridge holds it: 'test-paused'); any other pause reads as 'paused'.
21
- * Returns a handle: remove() resumes this owner (same as resume(owner)); pause / resume / freeze / unfreeze / step on it still chain to the engine.
33
+ * Returns a handle: remove() resumes this owner.
22
34
  * @param {string | { owner?: string, kind?: 'test' }} [owner] @param {{ kind?: 'test' }} [opts]
23
- * @returns {{ owner: string, remove(): void, [k: string]: any }}
24
- * @example const p = engine.pause('perf-test'); ... p.remove(); // or engine.resume('perf-test')
35
+ * @returns {{ owner: string, remove(): void }}
36
+ * @example const p = engine.pause('perf-test'); ... p.remove();
25
37
  */
26
38
  pause(owner, opts) {
27
39
  const a = ownerArgs(owner, opts);
28
- const h = this._pausers.take(a.owner, { kind: a.opts.kind ?? null });
29
- this.paused = true;
30
- return chained(this, h, () => this.resume(a.owner));
40
+ const P = this.stacks.get('pause');
41
+ P.take({ owner: a.owner, value: { kind: a.opts.kind ?? null } }); // the stack's onChange sets this.paused (defineHoldStacks), same as engine.mod('pause')
42
+ return handle(a.owner, () => { if (P.has(a.owner)) this._resume(a.owner); });
31
43
  },
32
44
  /**
33
- * Resume the real-time loop (in headless mode this starts live running). With owners: removes this owner's pause and resumes only when none remain;
34
- * a resume by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering, so it warns;
35
- * an unfreeze by a non-owner is the same no-op but quiet, because UI parts release their freeze on every close whether or not they froze).
45
+ * @internal The dev bridge and tests: end owner's pause (the handle's remove() calls this); with no pause held (a headless engine) it starts live running.
46
+ * A call by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering).
36
47
  * @param {string | { owner?: string }} [owner]
37
48
  */
38
- resume(owner) {
49
+ _resume(owner) {
39
50
  const { owner: o } = ownerArgs(owner);
40
- if (this._pausers.size && !this._pausers.has(o)) { warnOnce(coded('pause-owner', `engine.resume('${o}'): paused by ${this._pausers.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. Pass the same owner to pause() and resume(), or the pause stays`)); return this; }
41
- this._pausers.release(o);
42
- if (!this._pausers.size && !this.disposed) { this.paused = false; this._loop(); }
51
+ const P = this.stacks.get('pause');
52
+ if (P.size() && !P.has(o)) { warnOnce(coded('pause-owner', `ending the pause of '${o}': paused by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a pause with the handle pause() returned (p.remove()), or the pause stays`)); return this; }
53
+ // with holders the stack's onChange restarts the loop; with none (headless start) resume itself starts it
54
+ if (!P.release(o) && !P.size() && !this.disposed) { this.paused = false; this._loop(); }
43
55
  return this;
44
56
  },
45
- // Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, game clock and engine.elapsed all stop) while frame hooks
57
+ // Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
46
58
  // and rendering go on, so the picture and UI stay alive.
47
59
  // Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
48
60
  // Unlike pause(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
49
- // have unfrozen. step() obeys freezes as well. Same claim rules as pause (core/claims.js).
61
+ // have unfrozen. step() obeys freezes as well. Same owner rules as every stack (core/stacks.js).
50
62
  /**
51
63
  * Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
52
- * Returns a handle whose remove() unfreezes this owner; chains to the engine like before.
53
- * @param {string | { owner?: string, kind?: 'title' }} [owner] @param {{ kind?: 'title' }} [opts]
54
- * @returns {{ owner: string, remove(): void, [k: string]: any }}
64
+ * Ambient animation (uniforms.uTime: wind, water, clouds) keeps moving behind the freeze; ambient: true stops it too (a photo / cutscene still).
65
+ * Returns a handle whose remove() releases this owner's freeze. Same as engine.mod('freeze', { owner }) plus the kind.
66
+ * @param {string | { owner?: string, kind?: 'title', ambient?: boolean }} [owner] @param {{ kind?: 'title', ambient?: boolean }} [opts]
67
+ * @returns {{ owner: string, remove(): void }}
55
68
  */
56
69
  freeze(owner, opts) {
57
70
  const a = ownerArgs(owner, opts);
58
- return chained(this, this._freezers.take(a.owner, { kind: a.opts.kind ?? null }));
71
+ const h = this.stacks.get('freeze').take({ owner: a.owner, value: { kind: a.opts.kind ?? null, ambient: !!a.opts.ambient } });
72
+ return handle(a.owner, h.remove);
59
73
  },
60
- /** Release owner's freeze (only that owner's) @param {string | { owner?: string }} [owner] */
61
- unfreeze(owner) { this._freezers.release(ownerArgs(owner).owner); return this; },
62
74
  /** True while someone has frozen gameplay */
63
- get frozen() { return this._freezers.size > 0; },
75
+ get frozen() { return this.stacks.get('freeze').value(); },
64
76
  /**
65
77
  * The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
66
78
  * state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'test-paused' (only pauses of kind 'test': the bridge or a test)
67
- * | 'paused' (paused or frozen by owners, listed in `by`) | 'running';
68
- * by: every pause and freeze owner, so closing one part's pause can be told from a player's;
79
+ * | 'paused' (paused or frozen by owners, listed in `owners`) | 'running';
80
+ * owners: every pause and freeze owner, so closing one part's pause can be told from a player's;
69
81
  * blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
70
82
  * 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
71
- * @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', by: string[], blockedBy: string[] }}
83
+ * @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', owners: string[], blockedBy: string[] }}
72
84
  */
73
85
  get runState() {
74
- const P = this._pausers, F = this._freezers, by = [...P.names(), ...F.names()];
86
+ const P = this.stacks.get('pause'), F = this.stacks.get('freeze'), owners = [...P.names(), ...F.names()];
75
87
  const lv = this.loading?.view();
76
- const onlyTest = by.length > 0 && !F.size && !P.some(d => d.kind !== 'test');
77
- const state = !this.ready || !lv?.done ? 'loading' : F.some(d => d.kind === 'title') ? 'title-frozen'
78
- : !by.length && !this.paused ? 'running' : !by.length || onlyTest ? 'test-paused' : 'paused';
79
- const blockedBy = (this.input?.contexts ?? []).filter((n, i) => !this.input._stack[i].pass);
88
+ const onlyTest = owners.length > 0 && !F.size() && !P.entries().some(d => d.value.kind !== 'test');
89
+ const state = !this.ready || !lv?.done ? 'loading' : F.entries().some(d => d.value.kind === 'title') ? 'title-frozen'
90
+ : !owners.length && !this.paused ? 'running' : !owners.length || onlyTest ? 'test-paused' : 'paused';
91
+ const blockedBy = (this.input?.holders ?? []).filter(h => !h.pass).map(h => h.context);
80
92
  if (F.has('error')) blockedBy.push('error');
81
93
  if (lv?.blocked) blockedBy.push('loading');
82
- return { state, by, blockedBy };
94
+ return { state, owners, blockedBy };
83
95
  },
84
96
 
85
97
  // ---------- camera takeover ----------
86
- // While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). Before this was a bare field: a named view
87
- // overwrote a running cutscene's takeover and release() then handed the camera to nobody. Now each holder has a claim; the latest holder is in charge,
88
- // and releasing it hands the camera back to the previous holder (or to the rig when none is left).
98
+ // While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). The 'camera' stack is kind top: the latest holder
99
+ // 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.
89
100
  /**
90
101
  * Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
91
102
  * (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
@@ -95,12 +106,29 @@ export const holdMethods = {
95
106
  */
96
107
  takeCamera(owner, opts) {
97
108
  const a = ownerArgs(owner, opts, undefined);
98
- return this._cameraClaims.take(a.owner, { ...a.opts, owner: a.owner });
109
+ const h = this.stacks.get('camera').take({ owner: a.owner, value: { ...a.opts, owner: a.owner } });
110
+ return { owner: a.owner, remove: h.remove };
99
111
  },
100
112
  /**
101
- * The camera holder in charge ({ owner, focus? }), or null. Read-only: assigning throws renamed-api and names engine.takeCamera(owner).
113
+ * The camera holder in charge ({ owner, focus? }), or null. Read-only: take the camera with engine.takeCamera(owner).
102
114
  * @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
103
115
  */
104
- get cameraOverride() { return this._cameraClaims?.top()?.data ?? null; },
105
- set cameraOverride(_v) { renamed('cameraOverride'); },
116
+ get cameraOverride() { return this.stacks?.get('camera').value() ?? null; },
106
117
  };
118
+
119
+ const HOLD_STACKS = { pause: 'pause', freeze: 'freeze', camera: 'camera', debugView: 'debug.view' };
120
+ /**
121
+ * Everyone who holds something, in one place (empty parts left out): pause / freeze / camera / debugView [{ owner, at }]; input [{ context, owner,
122
+ * pass }] (pushed input contexts); gates { action: [owners] } (input.gate). Every other shared value is in describe().shared (core/stacks.js).
123
+ * Lives here, next to the hold stacks it reads, so describe() and the input-holds test use the same function (no second copy).
124
+ * "Why can't I move / why is time slow" is answered here without knowing which module did it.
125
+ */
126
+ export function describeHolds(e) {
127
+ const out = {};
128
+ 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; }
129
+ const inp = e.input.holders; if (inp.length) out.input = inp;
130
+ const g = e.stacks.has('input.gate') ? e.stacks.get('input.gate') : null, gates = {};
131
+ for (const id of g?.ids() ?? []) if (g.size(id)) gates[id] = g.names(id);
132
+ if (Object.keys(gates).length) out.gates = gates;
133
+ return out;
134
+ }
@@ -1,9 +1,11 @@
1
- // Input contexts (like Unity's Action Maps): a stack of named groups of actions. The top context shadows lower ones that bind the same key;
1
+ import { codedError } from './errorHints.js';
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;
2
3
  // an opaque context (the default) blocks everything below it, a `pass` context lets unrelated actions through. Menus, dialogue, cutscenes and
3
4
  // full-screen UI push an opaque context instead of "locking input", so there is one mechanism, not two.
4
5
  // Changes take effect at the start of the next fixed step (before the input snapshot), so a key pressed in step N never acts in both the old and the new context.
5
6
 
6
- const BASE_CONTEXT = 'gameplay';
7
+ /** The base context: walking around (the common names: walk, vehicle, dialog, menu, cutscene; a game may add its own) */
8
+ export const BASE_CONTEXT = 'walk';
7
9
 
8
10
  /** @internal */
9
11
  export function initContexts(input) {
@@ -14,8 +16,10 @@ export function initContexts(input) {
14
16
  }
15
17
 
16
18
  /** @internal */
17
- export function pushContext(input, name, { pass = false } = {}) {
18
- const entry = { name, pass };
19
+ export function pushContext(input, name, { pass = false, owner = name } = {}) {
20
+ // owner: who pushed it (describe().holds.input, runState.blockedBy), so "why can't I move" names a system, not only a context
21
+ if (typeof owner !== 'string' || !owner) throw codedError('input-owner', `input.push('${name}', { owner }): owner must be a non-empty string, e.g. input.push('${name}', { owner: 'shop-menu' })`, TypeError);
22
+ const entry = { name, pass, owner };
19
23
  let gone = false;
20
24
  input._pendingCtx.push({ add: entry });
21
25
  return {
@@ -29,7 +33,7 @@ export function pushContext(input, name, { pass = false } = {}) {
29
33
  export function readableMap(input) {
30
34
  if (input._readable) return input._readable;
31
35
  const keysOf = new Map();
32
- for (const [, a] of input.actions) { const c = a.context || BASE_CONTEXT; let s = keysOf.get(c); if (!s) keysOf.set(c, s = new Set()); for (const k of a.keys) s.add(k); }
36
+ for (const [n, a] of input.actions) { const c = a.context || BASE_CONTEXT; let s = keysOf.get(c); if (!s) keysOf.set(c, s = new Set()); for (const k of input.keysOf(n)) s.add(k); }
33
37
  const m = new Map(), stack = input._stack;
34
38
  for (const [name, a] of input.actions) {
35
39
  const ctx = a.context || BASE_CONTEXT;
@@ -39,7 +43,7 @@ export function readableMap(input) {
39
43
  if (c.name === ctx) { ok = true; break; }
40
44
  if (!c.pass) break;
41
45
  const shadow = keysOf.get(c.name);
42
- if (shadow && a.keys.some(k => shadow.has(k))) break;
46
+ if (shadow && input.keysOf(name).some(k => shadow.has(k))) break;
43
47
  }
44
48
  m.set(name, ok);
45
49
  }
@@ -60,7 +64,7 @@ export function applyContexts(input) {
60
64
  const after = readableMap(input);
61
65
  for (const [name, was] of before) {
62
66
  if (!was || after.get(name)) continue;
63
- for (const k of input.actions.get(name)?.keys ?? []) {
67
+ for (const k of input.keysOf(name)) {
64
68
  if (!input.keys.has(k)) continue; // even if another action on this key becomes readable: it needs a fresh press (F that boards must not also exit)
65
69
  input.keys.delete(k); input._accP.delete(k); input._accR.delete(k); input._muted.add(k);
66
70
  }
@@ -1,22 +1,25 @@
1
- // Input defaults and strings (split out of Input.js): neutral actions, bound-action labels, gamepad menu keys, the redefine warning.
2
- // Only neutral input lives here: the direction axis (input.axis, the touch stick) and menu confirm / cancel. Nothing in it does anything until a game or module
3
- // reads it.
4
- // Gameplay keys (run, interact, jump...) are not core defaults: the game binds them (createEngine({ bindings }), input.define, a module's keys option or a
5
- // preset such as
6
- // presets.player.thirdPerson / presets.interactions.nearest), so no game inherits another game's Shift-to-run or E-to-use.
7
- export const DEFAULT_ACTIONS = {
8
- moveForward: [['KeyW', 'ArrowUp'], 'input.moveForward'],
9
- moveBack: [['KeyS', 'ArrowDown'], 'input.moveBack'],
10
- moveLeft: [['KeyA', 'ArrowLeft'], 'input.moveLeft'],
11
- moveRight: [['KeyD', 'ArrowRight'], 'input.moveRight'],
12
- confirm: [['Space', 'Enter'], 'input.confirm'],
13
- cancel: [['Escape'], 'input.cancel'],
14
- };
15
- // display names for actions a game creates through createEngine({ bindings }) before the module that reads them defines its label
1
+ // The one default key preset and its labels. Split out of Input.js.
2
+ // Only the basics live here: the direction axis (input.axis, the touch stick), menu confirm / cancel and the UI cursor. Every game needs them and
3
+ // nothing in them does anything until a game or module reads them, so they are the base value of their action (the game's bind hides it).
4
+ // Every other key is the game's choice: modules declare actions and their context, never keys (input.action), and the game binds them
5
+ // (createEngine({ bindings }), engine.input.bind, or a presets.bindings.* map). This file and presets.js are the only places in the engine that
6
+ // may name a key (the static check in tests/specs/input-owners.mjs).
7
+ export const BASIC_KEYS = Object.freeze({
8
+ moveForward: Object.freeze(['KeyW', 'ArrowUp']),
9
+ moveBack: Object.freeze(['KeyS', 'ArrowDown']),
10
+ moveLeft: Object.freeze(['KeyA', 'ArrowLeft']),
11
+ moveRight: Object.freeze(['KeyD', 'ArrowRight']),
12
+ confirm: Object.freeze(['Space', 'Enter', 'PadA']),
13
+ cancel: Object.freeze(['Escape', 'PadB']),
14
+ // The UI choice cursor (ui/Focus.js) moves between dialogue choices and window controls with these. Read with pressedRaw only while a window or
15
+ // dialogue is on top of the UI focus stack (which holds an opaque input context), so sharing WASD / arrows with walking never moves the player
16
+ // and the cursor at once.
17
+ uiUp: Object.freeze(['ArrowUp', 'KeyW', 'PadUp']),
18
+ uiDown: Object.freeze(['ArrowDown', 'KeyS', 'PadDown']),
19
+ uiLeft: Object.freeze(['ArrowLeft', 'KeyA', 'PadLeft']),
20
+ uiRight: Object.freeze(['ArrowRight', 'KeyD', 'PadRight']),
21
+ });
22
+ export const BASIC_LABELS = { moveForward: 'input.moveForward', moveBack: 'input.moveBack', moveLeft: 'input.moveLeft', moveRight: 'input.moveRight',
23
+ confirm: 'input.confirm', cancel: 'input.cancel', uiUp: 'input.uiUp', uiDown: 'input.uiDown', uiLeft: 'input.uiLeft', uiRight: 'input.uiRight' };
24
+ // display names for actions a game binds before the module that reads them declares its label
16
25
  export const BOUND_LABELS = { run: 'input.run', interact: 'input.interact', jump: 'input.jump' };
17
- // Default gamepad keys for the neutral menu actions only (confirm / cancel / menu): added when the action is registered (override in createEngine({ padBindings
18
- // })).
19
- // Gameplay actions (jump, run, interact, inventory...) get pad keys the same way as keyboard keys: from the game or a preset (presets.player.*, presets.keys.*)
20
- export const PAD_DEFAULTS = { confirm: 'PadA', cancel: 'PadB', menu: 'PadStart' };
21
- const STRINGS = { redefine: 'Input action "{action}" defined twice: it already had keys {from}, now {to}; the later definition overrides. Ignore this if the change is intended; to change only the label, pass the same keys' };
22
- export const fmtRedefine = (action, from, to) => STRINGS.redefine.replace('{action}', action).replace('{from}', from.join(', ')).replace('{to}', to.join(', '));
package/core/inputPad.js CHANGED
@@ -1,4 +1,4 @@
1
- // Gamepad (standard layout) button names; like keyboard key names they can go into action bindings
1
+ // Gamepad buttons. Standard layout names; like keyboard key names they can go into action bindings
2
2
  const PAD_BUTTONS = ['PadA', 'PadB', 'PadX', 'PadY', 'PadLB', 'PadRB', 'PadLT', 'PadRT', 'PadSelect', 'PadStart', 'PadL3', 'PadR3', 'PadUp', 'PadDown', 'PadLeft', 'PadRight'];
3
3
 
4
4
  /** Read the first connected gamepad into the input's keys, stick and look (every frame, allocates nothing) @internal */
@@ -43,6 +43,6 @@ export function bindPointer(input, canvas, signal) {
43
43
  };
44
44
  canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
45
45
  // if the right button is bound to an action, do not show the browser menu
46
- canvas.addEventListener('contextmenu', e => { if ([...input.actions.values()].some(a => a.keys.includes('Mouse2'))) e.preventDefault(); }, { signal });
46
+ canvas.addEventListener('contextmenu', e => { if ([...input.actions.keys()].some(n => input.keysOf(n).includes('Mouse2'))) e.preventDefault(); }, { signal });
47
47
  canvas.addEventListener('wheel', e => { e.preventDefault(); input.look.zoom += Math.sign(e.deltaY); }, { passive: false, signal });
48
48
  }
@@ -13,8 +13,8 @@
13
13
  */
14
14
  export function touchButton(inp, action, labelKey) {
15
15
  if (!inp.touch || inp._touch.some(b => b.action === action)) return;
16
- const code = 'Touch:' + action, a = inp.actions.get(action);
17
- if (a && !a.keys.includes(code)) a.keys.push(code);
16
+ inp._touchKeys.set(action, 'Touch:' + action); // kept beside the bound keys, so a rebind never drops the on-screen button
17
+ inp._readable = null;
18
18
  inp._touch.push({ action, labelKey });
19
19
  touchRefresh(inp);
20
20
  }
package/core/lifecycle.js CHANGED
@@ -1,17 +1,35 @@
1
- // Engine lifecycle (part of Engine, mixed into Engine.prototype): dispose() and counts() for leak hunting.
1
+ // Engine lifecycle: dispose() and counts() for leak hunting.
2
+ //
3
+ // Part of Engine (mixed into Engine.prototype).
2
4
  //
3
5
  // Who cleans up what:
4
6
  // - DOM listeners: attach to engine.signal (an AbortController); dispose aborts them all at once. Modules and games adding their own window / document listeners do the same:
5
7
  // addEventListener('resize', fn, { signal: engine.signal })
6
8
  // - UI elements: the engine and modules build UI under engine.uiRoot, removed as a whole on dispose; do not attach to document.body directly.
7
- // - Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations: core clears them all, modules need not.
9
+ // - Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations: core clears them all here. A module registers its own through
10
+ // ctx.track (modules.js), so they also leave when its install rolls back or its init fails, and go before its dispose hook runs.
8
11
  // - Things core does not know about (Worker, physics world, Audio nodes, real-time timers): clean up in the module's dispose(e) hook, called in reverse install order.
9
12
  // - GPU memory: every geometry, material and texture in the scene, the assets cache, the post composer, then renderer.dispose().
10
13
  // Level changes do not come through here: things inside a level register with level.track(handle), and the level removes them itself on change.
11
14
 
12
- import { coded } from './errorHints.js';
15
+ import { coded, codedError } from './errorHints.js';
16
+ import { dropOwned } from './owned.js';
17
+ import { reportError } from './errors.js';
18
+ import { releaseContext, memory } from '../render/backend.js';
19
+
20
+ /** The per-step / per-frame callback lists (onFixed, onFrame, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
21
+ export function clearHooks(e) {
22
+ e._fixed = []; e._fixedLate = []; e._frame = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
23
+ }
24
+
25
+ const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)',
26
+ released: 'createEngine(): this canvas lost its WebGL context in an earlier engine.dispose(), so a new engine cannot draw on it; use a new canvas, or dispose the old engine with dispose({ keepContext: true })',
27
+ opts: 'engine.dispose(opts): opts is { keepContext?: boolean }; got {v}' };
13
28
 
14
- const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)' };
29
+ // Canvases whose context dispose() released: a lost context cannot host a new renderer, so createEngine on one fails loudly instead of drawing black
30
+ const released = new WeakSet();
31
+ /** createEngine calls it before building its renderer on a canvas */
32
+ export function checkCanvasUsable(canvas) { if (canvas && released.has(canvas)) throw codedError('canvas-released', STRINGS.released); }
15
33
 
16
34
  /** Dispose the geometry, materials and material textures used by an object */
17
35
  function disposeObject(o) {
@@ -26,25 +44,41 @@ export const lifecycleMethods = {
26
44
  /**
27
45
  * Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then clean up core (listeners, timers, sound, UI, GPU memory).
28
46
  * No callbacks fire afterwards and engine.disposed becomes true. Safe to call repeatedly.
47
+ * The engine's own renderer also gives its WebGL context back (renderer.forceContextLoss): browsers keep only about 16 live contexts, so a page that
48
+ * creates and disposes engines (level editor, tests, restart) would otherwise lose the oldest one. That canvas cannot host a new engine afterwards;
49
+ * keepContext: true keeps the context for a new engine on the same canvas. A renderer the game passed in (createEngine({ renderer })) is never released.
50
+ * @param {{ keepContext?: boolean }} [opts]
29
51
  */
30
- dispose() {
52
+ dispose(opts = {}) {
53
+ if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', STRINGS.opts.replace('{v}', JSON.stringify(opts)));
31
54
  if (this.disposed) return;
32
- this.disposed = true; this.ready = false; this.paused = true;
55
+ this.phase = 'disposed'; this.paused = true;
33
56
  cancelAnimationFrame(this._raf);
57
+ dropOwned(this, [...(this._owned?.values() ?? [])]); // owned.js keeps a page-wide list for allowOwned
34
58
  for (const m of [...this.modules.values()].reverse()) {
35
59
  this._modState.set(m.name, 'disposed');
60
+ this._dropTracked(m.name); // its listeners / timers go first, so nothing calls into the module while its dispose tears it down
36
61
  if (!m.dispose) continue;
37
- try { m.dispose(this); } catch (err) { console.error(coded('module-dispose', STRINGS.failed.replace('{name}', m.name)), err); }
62
+ try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', STRINGS.failed.replace('{name}', m.name)), { soft: true }); }
38
63
  }
39
64
  this._abort.abort();
65
+ this._untrackValidate();
66
+ this._wraps?.dispose(); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
40
67
  this.debug.dispose(); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
41
- for (const part of [this.saves, this.audio, this.clock, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
42
- this._fixed = []; this._frame = []; this._hooks = { fixed: [], frame: [], afterRender: [], skip: [] }; this._afterTick = null;
68
+ for (const part of [this.saves, this.audio, this.time, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
69
+ clearHooks(this); this._afterTick = null;
43
70
  this.scene.traverse(disposeObject);
44
- for (const t of [this.scene.background, this.scene.environment]) if (t?.isTexture) t.dispose();
71
+ // scene.environment is never disposed here: the engine's own maps (sky PMREM targets, the baseline room map) were freed above by their
72
+ // owners, and anything else is the game's texture (a direct scene.environment write), which stays the game's to free
73
+ this.scene.environment = null;
74
+ if (this.scene.background?.isTexture) this.scene.background.dispose();
45
75
  this.assets.dispose();
76
+ this.occlusion.dispose();
46
77
  this.post.dispose();
78
+ this._webglOnlyView?.remove(); this._webglOnlyView = null;
79
+ this._gpu?.dispose();
47
80
  this.renderer.dispose();
81
+ if (this._ownsRenderer && !opts.keepContext) { releaseContext(this.renderer); released.add(this.renderer.domElement); }
48
82
  this.ui._dispose();
49
83
  this._materials.remove();
50
84
  this._uiStyle.remove();
@@ -57,9 +91,9 @@ export const lifecycleMethods = {
57
91
  * Each installed module with a counts(e) hook adds its own field under its name, e.g. world { records, views }, rigid (body count), particles { alive, emitters }, sky { timers }.
58
92
  */
59
93
  counts() {
60
- const mem = this.renderer.info.memory;
94
+ const mem = memory(this.renderer);
61
95
  const c = {
62
- listeners: this.events.size, fixed: this._fixed.length, frame: this._frame.length, timers: this.clock.size,
96
+ listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length, timers: this.time.size,
63
97
  statics: this.rays.statics.size, streamEntries: this.stream.entries.size, jobs: this.jobs.pending, commits: this.commits.pending,
64
98
  geometries: mem.geometries, textures: mem.textures,
65
99
  };
@@ -5,6 +5,7 @@
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
6
  import { warnOnce } from './validate.js';
7
7
  import { coded } from './errorHints.js';
8
+ import { programCount } from '../render/backend.js';
8
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
11
 
@@ -14,7 +15,7 @@ const STRINGS = {
14
15
  changed: 'Shader programs were compiled during play ({from} -> {to}) and, compared with the last observation, the light layout also changed ({was} -> {now}). ' +
15
16
  'three.js compiles every material again for a new light setup, so adding, removing or hiding a light mid-game freezes a frame. ' +
16
17
  'Use engine.use(lightPool({ point: 8 })) and engine.lightPool.add(torch, {...}) for many lights, or fade a fixed set with intensity ' +
17
- '(recipes/09-style-pack.md "Lights and stalls")',
18
+ '(recipes/09-materials-lights-models.md "Lights and stalls")',
18
19
  };
19
20
 
20
21
  /** Visible lights by the kinds three.js counts in its light setup (ambient and probes do not change programs), as one comparable string */
@@ -28,19 +29,21 @@ export function lightSetup(scene) {
28
29
  return `point ${point}, spot ${spot}, directional ${dir}, hemisphere ${hemi}, rect ${rect}`;
29
30
  }
30
31
 
31
- /** Lights that are not part of a lightPool (those are fixed and already the recommended fix) */
32
+ /** Lights not kept at a fixed count. A module that holds a fixed set of lights and moves them around (a light pool: the recommended fix) marks
33
+ * each with userData.fixedCount = true; core reads the mark, not a module's naming scheme, so any pool, built-in or the game's, counts the same */
32
34
  function countLoose(scene) {
33
35
  let c = 0;
34
- scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.name.startsWith('lightPool_')) c++; });
36
+ scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.isLightProbeGrid && !o.userData.fixedCount) c++; });
35
37
  return c;
36
38
  }
37
39
 
38
40
  /** @param {any} e the engine (dev and ready only: the caller checks) */
39
41
  export function watchLights(e) {
40
- const n = e.renderer.info?.programs?.length;
42
+ const n = programCount(e.renderer);
41
43
  if (n == null) return;
42
44
  const first = !e._lightWatch;
43
- const w = e._lightWatch ??= { n, lights: lightSetup(e.scene) };
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) };
44
47
  // the scene walk runs on the first observation and when programs grow (a light was added), never on a quiet frame
45
48
  if (!w.manyDone && (first || n > w.n)) {
46
49
  const c = countLoose(e.scene);
@@ -49,6 +52,7 @@ export function watchLights(e) {
49
52
  if (n <= w.n) { w.n = n; return; } // fewer programs (materials disposed) or none new: nothing to say
50
53
  const lights = lightSetup(e.scene);
51
54
  if (lights !== w.lights) {
55
+ w.changes.push({ from: w.lights, to: lights, programs: n - w.n });
52
56
  // the layout is only reread when programs grow, so we say "since the last observation", never "in this frame"
53
57
  warnOnce(coded('light-recompile', STRINGS.changed.replace('{from}', String(w.n)).replace('{to}', String(n)).replace('{was}', w.lights).replace('{now}', lights)));
54
58
  }