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
@@ -7,14 +7,14 @@
7
7
  // so a half-deducted inventory or half-updated quest does not keep running, and a test does not mistake it for normal. A release build reports once and keeps running (so the player is not stuck for the whole session).
8
8
  // soft (core steps such as rendering and stream.update): report once per site and continue.
9
9
  // engine.error is machine-readable: { where, message, code, fix, docs } (code / fix / docs come from the error itself or from the hint table, errorHints.js).
10
- import { DEV } from './validate.js';
10
+ import { DEV, fmt } from './validate.js';
11
11
  import { errorInfo, hintText } from './errorHints.js';
12
12
 
13
13
  const STRINGS = { once: '[engine] {key} threw (later errors at the same place are not reported again)', disabled: '[engine] {type} module {name} threw and was disabled (the game continues) [module-disabled]', halted: '[engine] {key} threw and gameplay is frozen (in dev / tests a gameplay error fails hard; see engine.error for details) [gameplay-frozen]', listener: 'listener of event {name}',
14
14
  rejected: '[engine] a promise rejected and nothing caught it (e.g. audio.play() of a missing file, an async callback that threw); reported once, the game continues. Add .catch or await it in try. ' };
15
15
 
16
16
  /** picture / ui modules only show the game, so an error in one switches it off instead of freezing gameplay (the type is the one source; no extra flag) */
17
- export const failsSoft = m => m?.type === 'picture' || m?.type === 'ui';
17
+ const failsSoft = m => m?.type === 'picture' || m?.type === 'ui';
18
18
 
19
19
  /** Handle an error. key: where it happened (for display); module: the module definition that threw (none means a game callback / event listener, counted as gameplay); soft: report only once */
20
20
  export function reportError(engine, err, key, { module = null, soft = false } = {}) {
@@ -24,13 +24,13 @@ export function reportError(engine, err, key, { module = null, soft = false } =
24
24
  // code + fix + docs: what to do and which page to read; at: the line that threw (the message alone often does not say which callback line)
25
25
  engine.error = { where: key, message, ...errorInfo(err), at: firstFrame(err) };
26
26
  engine.freeze('error');
27
- console.error(STRINGS.halted.replace('{key}', key) + hintText(err?.code ? `[${err.code}]` : message), err);
27
+ console.error(fmt(STRINGS.halted, { key }) + hintText(err?.code ? `[${err.code}]` : message), err);
28
28
  engine.events.emit('engine:error', engine.error);
29
29
  return;
30
30
  }
31
31
  if (engine._hookErrors.has(key)) return;
32
32
  engine._hookErrors.add(key);
33
- console.error(STRINGS.once.replace('{key}', key), err);
33
+ console.error(fmt(STRINGS.once, { key }), err);
34
34
  }
35
35
 
36
36
  /** First stack frame of an error: V8 "at fn (file:line:col)", Firefox / Safari "fn@file:line:col"; null without a stack */
@@ -51,13 +51,13 @@ export function watchRejections(engine) {
51
51
  }
52
52
 
53
53
  /** An event listener threw (called by the event bus): counted as gameplay */
54
- export function reportListenerError(engine, name, err) { reportError(engine, err, STRINGS.listener.replace('{name}', name)); }
54
+ export function reportListenerError(engine, name, err) { reportError(engine, err, fmt(STRINGS.listener, { name })); }
55
55
 
56
56
  /** Disable a picture / ui module: remove its fixed / frame / afterRender hooks */
57
57
  function disableModule(engine, m, err) {
58
58
  if (engine.disabledModules.has(m.name)) return;
59
59
  engine.disabledModules.add(m.name);
60
60
  for (const k in engine._hooks) engine._hooks[k] = engine._hooks[k].filter(h => h.name !== m.name);
61
- console.error(STRINGS.disabled.replace('{type}', m.type).replace('{name}', m.name), err);
61
+ console.error(fmt(STRINGS.disabled, { type: m.type, name: m.name }), err);
62
62
  engine.events.emit('module:disabled', { name: m.name, message: String(err?.message ?? err) });
63
63
  }
@@ -27,6 +27,7 @@ export const ENGINE_EVENTS = [
27
27
  'character:launch',
28
28
  'character:fall',
29
29
  'character:model',
30
+ 'character:step',
30
31
  'character:land',
31
32
  'character:water',
32
33
  'dialogue:start',
@@ -5,8 +5,14 @@ import { codedError } from './errorHints.js';
5
5
  // API convention: a position is one argument. The old (x, z, ...) form arrives as a number; throw with the fix (otherwise it silently becomes the origin)
6
6
  const STRINGS = { position: 'A position must be passed as one argument: Vector3 / object / [x, y, z] / { x, z } (see the API conventions); got ' };
7
7
  const POS_ERR = STRINGS.position;
8
+ /**
9
+ * The one bad-position error. It carries the value: an op tells a bad argument (refused) from a bad value of its own making (a bug, reported) by it.
10
+ * @param {string} message @param {any} value @param {ErrorConstructor} [Type] @internal
11
+ */
12
+ export const badPosition = (message, value, Type) => Object.assign(codedError('bad-position', message, Type), { value });
8
13
  // A horizontal position missing x or z (a 2-element [x, z] array reads z as undefined; { x, y } has no z) would become 0 silently
9
14
  // (player.placeAt([10, 20]) at z = 0): say which part is missing and how to write it
15
+ const MAX_COORD = 1e9;
10
16
  const XZ_ERR = 'A horizontal position needs finite x and z: pass [x, y, z] (a 2-element [x, z] array does not work) or { x, z }; got ';
11
17
 
12
18
  /** Round to one decimal (describe, budget reports) @param {number} v @returns {number} */
@@ -20,10 +26,13 @@ export const r1 = v => Math.round(v * 10) / 10;
20
26
  */
21
27
  export const rv = v => (Number.isFinite(v) && v !== 0 ? Number(v.toPrecision(Math.max(4, Math.floor(Math.log10(Math.abs(v))) + 1))) : v);
22
28
 
29
+ /** An angle in radians as the same turn in -PI..PI; of a difference, the short way round @param {number} a @returns {number} */
30
+ export const wrapAngle = a => Math.atan2(Math.sin(a), Math.cos(a));
31
+
23
32
  /** Normalize a Vector3 / Object3D / [x, y, z] / { x, y, z } into a Vector3 */
24
33
  export function vec3(v, out = new THREE.Vector3()) {
25
- if (!v) return out;
26
- if (typeof v !== 'object') throw codedError('options-object', POS_ERR + JSON.stringify(v), TypeError);
34
+ if (!v && v !== 0) return out;
35
+ if (typeof v !== 'object') throw badPosition(POS_ERR + JSON.stringify(v), v, TypeError);
27
36
  if (v.isVector3) return out.copy(v);
28
37
  if (v.isObject3D) return out.copy(v.position);
29
38
  if (Array.isArray(v)) return out.set(v[0] ?? 0, v[1] ?? 0, v[2] ?? 0);
@@ -39,10 +48,12 @@ export function yOf(v) {
39
48
 
40
49
  /** Get the horizontal coordinates [x, z] from a Vector3 / Object3D / [x, y, z] / { x, z } */
41
50
  export function xzOf(v) {
42
- if (!v || typeof v !== 'object') throw codedError('options-object', POS_ERR + JSON.stringify(v), TypeError);
51
+ if (!v || typeof v !== 'object') throw badPosition(POS_ERR + JSON.stringify(v), v, TypeError);
43
52
  if (v.isObject3D) v = v.position;
44
53
  const x = Array.isArray(v) ? v[0] : v.x, z = Array.isArray(v) ? v[2] : v.z;
45
- if (!Number.isFinite(x) || !Number.isFinite(z)) throw codedError('options-object', XZ_ERR + JSON.stringify(v), TypeError);
54
+ if (!Number.isFinite(x) || !Number.isFinite(z)) throw badPosition(XZ_ERR + JSON.stringify(v), v, TypeError);
55
+ // Far past float precision (render coordinates are 32-bit): not a place. Worse, the chunk loops (`for (cx = floor(x / size); ...; cx++)`) never advance once x / size passes 2^53, a silent freeze (found by fuzz: pos z = -3.6e178)
56
+ if (Math.abs(x) > MAX_COORD || Math.abs(z) > MAX_COORD) throw badPosition(`A horizontal position must lie within ±${MAX_COORD} (far past that nothing renders or streams correctly, and chunk loops stop advancing); got ` + JSON.stringify(v), v, RangeError);
46
57
  return [x, z];
47
58
  }
48
59
 
@@ -6,6 +6,7 @@
6
6
  // several shapes: 'bool|object' (any of them; e.g. createEngine's batching: false or { ... }), checked like one type
7
7
  import { closest, fmt, DEV, warnOnce, unknownOptionText } from './validate.js';
8
8
  import { codedError, coded } from './errorHints.js';
9
+ import { isOptions, isObject } from './util.js';
9
10
 
10
11
  /** Types an op arg may use: plain data only. Two meanings of 'id' on purpose: as a module param it is any string; as an op arg it must also be a world record id (checked in dev by opsCheck) */
11
12
  export const OP_TYPES = ['string', 'number', 'int', 'bool', 'position', 'id', 'any'];
@@ -16,7 +17,7 @@ const isPos = v => Array.isArray(v) && (v.length === 2 || v.length === 3) && v.e
16
17
  /** type name -> value check (op args use the first seven: plain data only) */
17
18
  const CHECK = {
18
19
  string: v => typeof v === 'string', number: v => Number.isFinite(v), int: v => Number.isInteger(v), bool: v => typeof v === 'boolean',
19
- position: isPos, id: v => typeof v === 'string', any: () => true, object: v => !!v && typeof v === 'object' && !Array.isArray(v),
20
+ position: isPos, id: v => typeof v === 'string', any: () => true, object: isObject,
20
21
  array: Array.isArray, function: v => typeof v === 'function',
21
22
  color: v => (Number.isInteger(v) && v >= 0 && v <= 0xffffff) || (typeof v === 'string' && /^#[0-9a-f]{6}$/i.test(v)),
22
23
  };
@@ -33,8 +34,6 @@ const STRINGS = {
33
34
  // Why cache: public APIs (collision.addCircle, particles.emit ...) call readParams on every call; the same schema object is parsed once;
34
35
  // a literal schema written fresh each call is not cached (WeakMap keys by object, collected after use), it is just parsed once more
35
36
  const parsed = new WeakMap(), keyCache = new WeakMap();
36
- /** Is o an options object (not a number, string, array, Three.js object or vector)? Data checks use it where a field may also be a name or a list */
37
- export const isOptions = o => !!o && typeof o === 'object' && !Array.isArray(o) && !o.isObject3D && !o.isVector3 && !o.isColor;
38
37
  const parsedOf = (where, schema) => { let s = parsed.get(schema); if (!s) { s = parseSchema(where, schema); parsed.set(schema, s); } return s; };
39
38
 
40
39
  /** Parse one field spec ('int?' or { type, default, ... }) into { type, optional, default?, min?, max?, values?, desc? }; throws on a bad spec */
@@ -98,7 +97,7 @@ export function schemaInfo(shape) {
98
97
  }
99
98
 
100
99
  /**
101
- * Module options read through a params schema: unknown keys and wrong types throw (with the fix), defaults are filled in.
100
+ * Module options read through a params schema, defaults filled in. A wrong type, a value out of range or a missing required option throws (with the fix) in every build, a release one too; an unknown key throws in dev only and warns once in a release build.
102
101
  * Put the schema on the module definition too (`params`, `options`), so engine.catalog(name) shows every option, its default and the value in use.
103
102
  * @param {string} where who reads them, for the error text (the module name)
104
103
  * @param {Record<string, string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean }>} schema
@@ -0,0 +1,32 @@
1
+ // Small shared core helpers. One definition each, so "what counts as a plain object" and "how a dotted path is read" cannot drift apart.
2
+
3
+ /** A plain data object: { } or Object.create(null); not an array, class instance, three.js object or function */
4
+ export const isPlainObject = v => isObject(v) && [Object.prototype, null].includes(Object.getPrototypeOf(v));
5
+ /** Is v an object at all (class instances count; not null, not an array)? isPlainObject is the strict answer, for data that must stay plain */
6
+ export const isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v);
7
+ /** Is o an options object a game passed (not a number, string, array, Three.js object, vector or color)? Data checks use it where a field may also be a name or a list */
8
+ export const isOptions = o => isObject(o) && !o.isObject3D && !o.isVector3 && !o.isColor;
9
+
10
+ /**
11
+ * f() or null when it throws. For read-only reports (thing.explain and its module parts) that join several sources: one source that cannot
12
+ * answer (an unknown template, a disposed part) leaves its field null instead of failing the whole report. Never for gameplay paths.
13
+ */
14
+ export const orNull = f => { try { return f(); } catch { return null; } };
15
+
16
+ /** One value or a list, as a list @template T @param {T | T[]} v @returns {T[]} */
17
+ export const list = v => (Array.isArray(v) ? v : [v]);
18
+
19
+ /** A model name in model / lod position: 'pine' or ['flower', 0xff0000] (content data and vegetation.define take the same form) @param {any} m */
20
+ export const isModelName = m => typeof m === 'string' || Array.isArray(m) && typeof m[0] === 'string';
21
+
22
+ /** Is o root, or does it hang under root? @param {any} o @param {any} root */
23
+ export function isUnder(o, root) { for (let p = o; p; p = p.parent) if (p === root) return true; return false; }
24
+ /** Is o visible, itself and every parent (what traverseVisible checks)? @param {any} o */
25
+ export function isShown(o) { for (let p = o; p; p = p.parent) if (!p.visible) return false; return true; }
26
+
27
+ /** Read a dotted path ('a.b.c'); undefined as soon as a step is missing @param {any} obj @param {string} path */
28
+ export function getPath(obj, path) {
29
+ let v = obj;
30
+ for (const k of path.split('.')) v = v?.[k];
31
+ return v;
32
+ }
@@ -1,14 +1,15 @@
1
1
  // Runtime checks: when an option or name is misspelled, print the fix to the console ("did you mean `xxx`?").
2
2
  // Type checking (npm run types) catches mistakes while you write code; this catches the same kind at runtime, which also works for code without type checking.
3
3
  //
4
- // readParams('npcs.add()', NPC_PARAMS, opts) // options: an unknown key throws in dev (core/params.js)
4
+ // readParams('npcs.add()', NPC_PARAMS, opts) // options: an unknown key throws in dev (core/base/params.js)
5
5
  // checkOptions('inventory.define()', def, KEYS, { loose: true }) // extensible data: warns once on a near-miss key
6
6
  // warnMissing('action', 'jupm', ['jump', 'run']) // 'action "jupm" does not exist, did you mean `jump`? (available: jump, run)'
7
- // Properties the engine writes every frame (sky lights, camera ...) are core/owned.js defineOwned: the engine yields to a direct write and warns once
7
+ // Properties the engine writes every frame (sky lights, camera ...) are core/ops/owned.js defineOwned: the engine yields to a direct write and warns once
8
8
  //
9
9
  // On by default; createEngine({ validate: false }) turns it all off (for release builds). Each message warns only once.
10
10
 
11
11
  import { hintText, coded, codedError } from './errorHints.js';
12
+ import { isOptions } from './util.js';
12
13
 
13
14
  const STRINGS = {
14
15
  unknownKey: '{where}: unknown option "{key}", {hint}',
@@ -42,12 +43,34 @@ const enabled = () => live === 0 || quiet < live;
42
43
  // @ts-ignore Vite's import.meta.env (undefined outside Vite)
43
44
  const ENV = import.meta.env;
44
45
  export const DEV = !!(ENV?.DEV || ENV?.THREEDOG_TEST);
46
+ /** Whether a position can be written: [x, y, z], or { x, z } with y left out or a number. The one answer; thing.set asks it in can, world's putPos before it writes @param {any} p @returns {boolean} @internal */
47
+ export const goodPos = p => Array.isArray(p) ? p.length === 3 && p.every(Number.isFinite) : Number.isFinite(p?.x) && Number.isFinite(p?.z) && (p.y === undefined || Number.isFinite(p.y));
45
48
  /** The Vite dev server itself (npm run dev, not the test bundle): only it serves /__threedog endpoints and the dev bridge. The other spelling of "dev", named so nothing reads import.meta.env.DEV on its own. */
46
49
  export const DEV_SERVER = !!ENV?.DEV;
47
50
  /** Vite's base URL ('/' outside Vite) */
48
51
  export const BASE_URL = ENV?.BASE_URL ?? '/';
49
52
  const warned = new Set();
50
53
 
54
+ /**
55
+ * The one check behind every `.material = m` setter a module hands out.
56
+ * @param {string} code the module's error code
57
+ * @param {string} what what is being set, e.g. 'engine.water.material'
58
+ * @param {any} m the value
59
+ * @param {string} [next] what to write instead, appended to the message
60
+ * @internal
61
+ */
62
+ export function needMaterial(code, what, m, next = '') { if (!m?.isMaterial) throw codedError(code, `${what} takes a three.js Material, got ${m}${next}`); }
63
+ /**
64
+ * A shader part written for one renderer only, on the other one: the error that names the missing form.
65
+ * @param {string} code the module's error code
66
+ * @param {string} what the part, e.g. 'wind'
67
+ * @param {boolean} gpu true on WebGPURenderer (the glsl form cannot run), false on WebGLRenderer (the tsl form cannot run)
68
+ * @internal
69
+ */
70
+ export const oneForm = (code, what, gpu) => codedError(code, gpu
71
+ ? `${what} has only a glsl form, which WebGPURenderer cannot draw: give tsl too ({ glsl, tsl })`
72
+ : `${what} has only a tsl form, which WebGLRenderer cannot draw: give glsl too ({ glsl, tsl })`);
73
+
51
74
  /**
52
75
  * Count one engine's createEngine({ validate }) for the page-wide warnings; returns the release for dispose().
53
76
  * @param {boolean | undefined} on
@@ -120,7 +143,7 @@ export function missingText(kind, name, list) {
120
143
  /** A name does not exist: warn once */
121
144
  export function warnMissing(kind, name, list) {
122
145
  // may be called every frame: keyed by the name, so the list text is built only the first time
123
- if (!enabled || warned.has(kind + '\0' + name)) return;
146
+ if (!enabled() || warned.has(kind + '\0' + name)) return;
124
147
  warnOnce(coded('unknown-name', missingText(kind, name, list)), kind + '\0' + name);
125
148
  }
126
149
 
@@ -135,17 +158,15 @@ export function unknownOptionText(where, key, known, { soft = false } = {}) {
135
158
  if (!c && soft) return null;
136
159
  return fmt(STRINGS.unknownKey, { where, key, hint: c ? fmt(STRINGS.didYouMean, { name: c }) : fmt(STRINGS.available, { list: known.join(', ') }) });
137
160
  }
138
- /** Is options an object a game passed (not a Three.js object, array or missing)? */
139
- const isOptionsObject = o => !!o && typeof o === 'object' && !Array.isArray(o) && !o.isObject3D && !o.isVector3;
140
161
 
141
162
  /**
142
163
  * Unknown keys in extensible data (item definitions, template instance state, material specs: objects where games add their own fields): warn once.
143
- * Options bags of public calls do not come here: they go through readParams (core/params.js), where an unknown key throws in dev with the
164
+ * Options bags of public calls do not come here: they go through readParams (core/base/params.js), where an unknown key throws in dev with the
144
165
  * did-you-mean and warns once in a release build. Why two kinds: a misspelled option is always a bug and should stop on the spot; extra fields in extensible data may be the game's own, so only near-spellings are hinted (loose).
145
166
  * where is the origin (such as 'inventory.define()'), known are the keys the code reads. loose: report only near-misses.
146
167
  */
147
168
  export function checkOptions(where, opts, known, { loose = false } = {}) {
148
- if (!enabled() || !isOptionsObject(opts)) return;
169
+ if (!enabled() || !isOptions(opts)) return;
149
170
  for (const k of Object.keys(opts)) {
150
171
  const msg = unknownOptionText(where, k, known, { soft: loose });
151
172
  if (!msg) continue;
@@ -5,47 +5,48 @@
5
5
  import * as THREE from 'three';
6
6
  import { Page } from './page.js';
7
7
  import { createServices } from './services.js';
8
- import { Stacks } from './stacks.js';
9
- import { PostFX } from '../render/PostFX.js';
10
- import { Occlusion } from '../render/occlusion.js';
11
- import { createDefaultLights } from '../render/lights.js';
12
- import { registerEngine } from '../render/materials.js';
13
- import { createUniforms } from '../render/effects.js';
14
- import { bindUniforms } from '../render/engineUniforms.js';
15
- import { UIParts } from '../ui/Parts.js';
16
- import { defineCoreParts } from '../ui/defaults.js';
17
- import { applyUITheme } from '../ui/theme.js';
18
- import { trackValidate, warnOnce, DEV } from './validate.js';
19
- import { readParams } from './params.js';
8
+ import { Stacks } from '../ops/stacks.js';
9
+ import { PostFX } from '../../render/PostFX.js';
10
+ import { Occlusion } from '../../render/occlusion.js';
11
+ import { createDefaultLights } from '../../render/lights.js';
12
+ import { registerEngine } from '../../render/materials.js';
13
+ import { createUniforms } from '../../render/effects.js';
14
+ import { bindUniforms } from '../../render/engineUniforms.js';
15
+ import { UIParts } from '../../ui/Parts.js';
16
+ import { defineCoreParts } from '../../ui/defaults.js';
17
+ import { applyUITheme } from '../../ui/theme.js';
18
+ import { trackValidate, warnOnce, DEV } from '../base/validate.js';
19
+ import { readParams } from '../base/params.js';
20
20
  import { loopMethods } from './loop.js';
21
- import { holdMethods } from './holds.js';
21
+ import { holdMethods } from '../ops/holds.js';
22
22
  import { startupMethods } from './startup.js';
23
- import { groundMethods, flatGround } from './ground.js';
24
- import { actorMethods } from './actor.js';
25
- import { forcedTier, defaultPixelRatio } from './tier.js';
26
- import { tier as detectTier, tierBeforeRenderer, ownMsaa, timerContext, isWebGPU, webgpuPart, watchNodePrograms } from '../render/backend.js';
27
- import { dressNodeTwins } from '../render/patches.js';
23
+ import { groundMethods, flatGround } from '../scene/ground.js';
24
+ import { actorMethods } from '../ops/actor.js';
25
+ import { forcedTier, defaultPixelRatio } from '../scene/tier.js';
26
+ import { tier as detectTier, tierBeforeRenderer, ownMsaa, timerContext, isWebGPU, webgpuPart, watchNodePrograms } from '../../render/backend.js';
27
+ import { recordSweep } from '../../render/recordSweep.js';
28
+ import { dressNodeTwins } from '../../render/patches.js';
28
29
  import { lifecycleMethods, clearHooks, checkCanvasUsable } from './lifecycle.js';
29
- import { createAdaptive, GpuTimer } from './adaptive.js';
30
- import { watchRejections } from './errors.js';
31
- import { createMovement } from './movement.js';
30
+ import { createAdaptive, GpuTimer } from '../scene/adaptive.js';
31
+ import { watchRejections } from '../base/errors.js';
32
+ import { createMovement } from '../scene/movement.js';
32
33
  import { moduleMethods } from './modules.js';
33
- import { skipMethods } from './skip.js';
34
- import { checkMethods } from './checks.js';
35
- import { canvasBox, placeUI, resizeMethods } from './canvasBox.js';
36
- import { sceneMethods } from './sceneMethods.js';
37
- import { EngineCamera } from './engineCamera.js';
38
- import { recordRender } from './describeRender.js';
39
- import { installPictureWriters } from './pictureWriters.js';
34
+ import { skipMethods } from '../time/skip.js';
35
+ import { checkMethods } from '../inspect/checks.js';
36
+ import { canvasBox, placeUI, resizeMethods } from '../scene/canvasBox.js';
37
+ import { sceneMethods } from '../scene/sceneMethods.js';
38
+ import { EngineCamera } from '../scene/engineCamera.js';
39
+ import { recordRender } from '../inspect/describeRender.js';
40
+ import { installPictureWriters } from '../inspect/pictureWriters.js';
40
41
  import { ownHook } from './moduleTypes.js';
41
- import { defineShadows } from './shadows.js';
42
- import { defineTerms } from '../render/terms.js';
43
- import { defineView } from './view.js';
44
- import { nameShaderErrors } from '../render/shaderErrors.js';
45
- import { probeMethods } from '../render/probes.js';
46
- import { lightmapMethods } from '../render/lightmap.js';
42
+ import { defineShadows } from '../../render/shadows.js';
43
+ import { defineTerms } from '../../render/terms.js';
44
+ import { defineView } from '../scene/view.js';
45
+ import { nameShaderErrors } from '../../render/shaderErrors.js';
46
+ import { probeMethods } from '../../render/probes.js';
47
+ import { lightmapMethods } from '../../render/lightmap.js';
47
48
  import { headlessSettled } from './headlessLoad.js';
48
- import { codedError } from './errorHints.js';
49
+ import { coded, codedError } from '../base/errorHints.js';
49
50
  const FALLBACKS = ['webgl2', 'webgl', 'error'];
50
51
  // createEngine() options: the one table for the unknown-key and type check (dev throws with did-you-mean, release warns once), the plain
51
52
  // defaults and engine.catalog('core').params; R6 checks EngineOptions (types/core.d.ts) has exactly these keys. A key with several shapes
@@ -62,9 +63,13 @@ export const ENGINE_PARAMS = {
62
63
  pauseOnBlur: { type: 'bool', default: true }, batching: 'bool|object?', lights: { type: 'bool', default: true },
63
64
  };
64
65
 
65
- /** createEngine({ renderer: 'webgpu' }): three's WebGPURenderer from the classes threedog/tsl registered (render/backend.js) @param {any} canvas */
66
+ /**
67
+ * createEngine({ renderer: 'webgpu' }): three's WebGPURenderer from the classes threedog/tsl registered (render/backend.js). No powerPreference on
68
+ * Windows: Chrome ignores it there and warns on every page load (crbug.com/369219127) @param {any} canvas
69
+ */
66
70
  function newWebGPURenderer(canvas, antialias) {
67
- return new (needTsl("'webgpu'").WebGPURenderer)({ canvas, antialias, powerPreference: 'high-performance' });
71
+ const power = navigator.userAgent.includes('Windows') ? {} : { powerPreference: 'high-performance' };
72
+ return new (needTsl("'webgpu'").WebGPURenderer)({ canvas, antialias, ...power });
68
73
  }
69
74
 
70
75
  /**
@@ -80,7 +85,7 @@ function rendererWant(r, rendererIn, fallback) {
80
85
  if (typeof rendererIn === 'string' && rendererIn !== 'webgpu') throw codedError('engine-misuse', `createEngine({ renderer }): a name is 'webgl' (the default) or 'webgpu', or pass a three.js renderer object, got ${JSON.stringify(rendererIn)}`);
81
86
  const gpu = isWebGPU(r);
82
87
  if (gpu) needTsl('yourWebGPURenderer');
83
- if (fallback !== undefined && !gpu) throw codedError('engine-misuse', "createEngine({ fallback }) only applies with renderer: 'webgpu' or your own WebGPURenderer (WebGLRenderer has nothing to fall back from)");
88
+ if (DEV && fallback !== undefined && !gpu) warnOnce(coded('engine-misuse', `createEngine({ fallback: ${JSON.stringify(fallback)} }) does nothing here: it only applies with renderer: 'webgpu' or your own WebGPURenderer (WebGLRenderer has nothing to fall back from)`));
84
89
  return { requested: gpu ? 'webgpu' : 'webgl', fallback: fallback ?? 'webgl2' };
85
90
  }
86
91
 
@@ -101,31 +106,25 @@ export class Engine {
101
106
  /** This engine's dev checks (createEngine({ validate })); another engine on the page does not change it @type {boolean} */
102
107
  this.validate = opts.validate !== false;
103
108
  /** @internal */ this._untrackValidate = trackValidate(opts.validate);
104
- // createEngine({ post }) read as "turn bloom on" when nothing had added a bloom. Said here, because an unknown key would only be ignored
105
- if (opts.post !== undefined) throw codedError('post-effect', 'createEngine({ post }) is gone. The engine ships no effects: add one with engine.post.add(bloom()) ' +
106
- `(@threedog/post-effects), or as a file in the plugins folder; switch it with its handle: engine.post.get('bloom').enabled = false`);
107
- // said before the unknown-option check for the same reason: a picture given here has one place to go, and the generic message does not name it
108
- if (opts.style !== undefined) throw codedError('engine-misuse', "createEngine({ style }) is gone: there is no style table. Write the picture as plain three.js in the game's picture/ code " +
109
- "(scene.background, scene.fog, renderer.toneMapping, engine.<module>.material, engine.uniforms), and the screen UI's colors and CSS with createEngine({ ui }). recipes/62-picture-code.md");
110
109
  const o = readParams('createEngine()', ENGINE_PARAMS, opts);
111
110
  /** @internal createEngine options as read (engine.catalog('core').params shows them with the schema) */ this._createParams = o;
112
111
  const { canvas: canvasIn, renderer: rendererName, antialias, pixelRatio, adaptiveResolution, targetFps, ui = {}, audio = {},
113
112
  fov, near, locale, strings = {}, bindings = {}, saveKey, joystick,
114
113
  headless = new URLSearchParams(location.search).has('threedog-headless'), validate,
115
114
  decoders = null, budget = null, urlState = DEV, seed, movement, threads, pauseOnBlur, batching = {}, lights, fallback } = o;
116
- this.THREE = THREE;
117
115
  // 'webgl' names the default (a WebGLRenderer the engine builds), so it reads like leaving the option out
118
116
  const rendererIn = rendererName === 'webgl' ? undefined : rendererName;
119
- // 'webgpu' is the same road as a game's own WebGPURenderer: built here, then handed on like one (start() inits it, core/startup.js)
117
+ // 'webgpu' is the same road as a game's own WebGPURenderer: built here, then handed on like one (start() inits it, core/engine/startup.js)
120
118
  const gpuWanted = rendererIn === 'webgpu';
121
119
  const canvas = canvasIn ?? (gpuWanted ? undefined : rendererIn?.domElement);
122
120
  this.movement = createMovement(movement); // character radius / height / slope / step height: the single copy shared by collision, physics and nav
123
121
  if (opts.lights !== false) warnOnce(NO_PICTURE);
124
- // a game-supplied renderer is used as is: the engine configures (pixel ratio, size, tone mapping, shadows) only a renderer it created itself
122
+ // a game-supplied renderer keeps its settings: the engine configures pixel ratio, size, tone mapping and shadows only on a renderer it created itself.
123
+ // One write on every renderer: info.autoReset = false below, because the frame stats count a whole frame, not each render call
125
124
  const owned = !rendererIn || gpuWanted;
126
125
  this._ownsRenderer = owned; // dispose() releases the WebGL context only of a renderer the engine built
127
126
  if (owned) checkCanvasUsable(canvas);
128
- // 'low' | 'high': device tier, decides default quality. A headless tool page names its tier (?threedog-tier, core/tier.js): detection would call
127
+ // 'low' | 'high': device tier, decides default quality. A headless tool page names its tier (?threedog-tier, core/scene/tier.js): detection would call
129
128
  // every headless browser low tier and drop the game's costly post from shots. An engine-built renderer needs it before it exists: MSAA defaults
130
129
  // from the tier and is the canvas's own (antialias, fixed when the context is made), so an effect-free frame skips the post chain
131
130
  const tierFirst = (headless && forcedTier()) || (owned ? tierBeforeRenderer() : null);
@@ -134,6 +133,7 @@ export class Engine {
134
133
  /** @internal what the game asked for and what to do without WebGPU; start() fills describe().renderer from it */
135
134
  this._backendWant = rendererWant(r, rendererIn, fallback);
136
135
  watchNodePrograms(r); // WebGPU: generated code per material, for debug.view('shaderCost') (render/backend.js)
136
+ this._records = recordSweep(r); // WebGPU: meshes that left the scene free their records (render/recordSweep.js)
137
137
  if (isWebGPU(r)) dressNodeTwins(r); // WebGPU: classic materials get their patches as nodes (render/patches.js)
138
138
  nameShaderErrors(r); // compile errors name the patch and slot (render/shaderErrors.js); a game's own handler stays
139
139
  this.tier = tierFirst || detectTier(r);
@@ -145,18 +145,19 @@ export class Engine {
145
145
 
146
146
  this.scene = new THREE.Scene();
147
147
  /** @internal the neutral background a scene starts with: describe().render.defaults, and the reference a sky compares with @type {any} */ this.baseBackground = new THREE.Color(0x8c8c8c);
148
+ /** @internal */ this.baseBackgroundHex = this.baseBackground.getHex();
148
149
  this.scene.background = this.baseBackground;
149
150
  /** Placeholder lights { sun: DirectionalLight, hemi: HemisphereLight }: neutral and still; createEngine({ lights: false }) leaves them out of the scene @type {{ sun: any, hemi: any }} */
150
151
  this.lights = createDefaultLights(this, { add: lights !== false });
151
152
  // the engine's own renderer gets soft shadows by default; tone curve and environment stay three.js's defaults
152
153
  this.stacks = new Stacks(this); // shared points: the registry exists before the first engine.shadows / engine.post point
153
- defineShadows(this, { owned }); // engine.shadows: master switch, cascades, box, budget on the lights a game hands in (core/shadows.js)
154
- recordRender(this, { owned }); // baseline for describe().render (after the curve is written): which values the engine set
154
+ defineShadows(this, { owned }); // engine.shadows: master switch, cascades, box, budget on the lights a game hands in (render/shadows.js)
155
+ recordRender(this, { owned }); // baseline for describe().render (after the shadow defaults are written): which values the engine set
155
156
  // Dev server only. A bundled build (npm test, threedog shot, release) is one minified file, so a stack there names assets/index-x.js:1 for every value: a
156
157
  // wrong answer. Written as the literal, not DEV_SERVER: only the literal folds at build time, so the tracker leaves a release bundle altogether
157
158
  // @ts-ignore Vite's import.meta.env (undefined outside Vite)
158
159
  if (import.meta.env?.DEV) installPictureWriters(this);
159
- this.camera = new EngineCamera(fov, box.w / box.h, near, 1500); // a PerspectiveCamera that camera rigs can switch to orthographic (core/engineCamera.js)
160
+ this.camera = new EngineCamera(fov, box.w / box.h, near, 1500); // a PerspectiveCamera that camera rigs can switch to orthographic (core/scene/engineCamera.js)
160
161
  this.camera.position.set(0, 10, 20);
161
162
  this.focus = new THREE.Vector3(); // camera focus (updated by the camera module): the view loads around it; simulation follows world.anchor
162
163
  this.ground = flatGround;
@@ -168,9 +169,9 @@ export class Engine {
168
169
  this.actor = 'player';
169
170
  /**
170
171
  * Where the engine is in its life, the one state every "may this run yet" check reads: 'constructed' (createEngine done, start() not called)
171
- * -> 'loading' (start() running: modules init, assets, the world builds; frame hooks run, fixed steps do not, so no game time passes)
172
+ * -> 'starting' (start() running: modules init; frame hooks run, fixed steps do not, so no game time passes) -> 'loading' (the same, assets and the world build)
172
173
  * -> 'ready' (the world is built: fixed steps run, engine:ready fires, the new-game state is captured) -> 'running' (start() resolved)
173
- * -> 'disposed'. @type {'constructed' | 'loading' | 'ready' | 'running' | 'disposed'}
174
+ * -> 'disposed'. @type {'constructed' | 'starting' | 'loading' | 'ready' | 'running' | 'disposed'}
174
175
  */
175
176
  this.phase = 'constructed';
176
177
  /** @internal module name -> handles its install / init passed to ctx.track (removed with the module: modules.js) */ this._modTracked = new Map();
@@ -184,11 +185,14 @@ export class Engine {
184
185
  this.uiRoot.className = 'threedog-root';
185
186
  if (r.domElement.parentElement) r.domElement.after(this.uiRoot); else document.body.appendChild(this.uiRoot);
186
187
  this.headless = headless;
187
- this.paused = headless; // while paused the real-time loop does not advance; only step() does
188
+ this.halted = headless; // while halted the real-time loop does not advance; only step() does
188
189
  this.fps = 0;
189
- this.cpuMs = 0; // main-thread ms of the last real-time frame; cpuPhases splits it (loop.js)
190
- this.cpuPhases = { fixed: 0, frame: 0, render: 0, afterRender: 0 };
191
- this.openWindows = new Set(); // ids of open windows (for describe)
190
+ /** How far the drawn frame is from the last fixed step to the next, 0-1 (real loop); 1 after step(). Holds still while frozen. For drawing fixed-step state smoothly: prev + (now - prev) * stepBlend */
191
+ this.stepBlend = 1;
192
+ /** @internal the picture check is rendering (tools/picture/check.mjs): what it changes and puts back is not the game's */ this._probing = false;
193
+ /** @internal */ this._cpuMs = 0; // main-thread ms of the last real-time frame; _cpuPhases splits it (loop.js); read through engine.inspect.perf() and engine.budget
194
+ /** @internal */ this._cpuPhases = { fixed: 0, frame: 0, render: 0, afterRender: 0 };
195
+ this._openWindows = new Set(); // ids of open windows (for describe)
192
196
  this.modules = new Map();
193
197
  this._modState = new Map(); // module name -> registered | initializing | running | failed | disposed (modules.js)
194
198
  this.waterBodies = [];
@@ -197,16 +201,16 @@ export class Engine {
197
201
  this.error = null; // gameplay error in dev/test: { where, message, cause?, docs? }; gameplay is frozen (see errors.js)
198
202
  this.disabledModules = new Set(); // picture / ui modules disabled after they threw
199
203
  /**
200
- * This engine's shader uniforms (uTime, uWind, uCloud, season tints...); share these objects in your own ShaderMaterial or patch @type
201
- * {import('../types/core').EngineUniforms}
204
+ * This engine's shader uniforms (uTime, uWind, uWeatherCloud, season tints...); share these objects in your own ShaderMaterial or patch @type
205
+ * {import('../../types/core').EngineUniforms}
202
206
  */
203
207
  this.uniforms = createUniforms();
204
208
  bindUniforms(r, this.uniforms); // built-in shader effects read this engine's uniforms when compiled by this renderer
205
- defineView(this); // engine.view: manual() for camera.far / fov / pixel ratio / camera pose the engine changes on its own (core/view.js)
206
- defineTerms(this); // engine.terms: the game's own cloud shadow or season tint in place of the engine's (render/terms.js)
209
+ defineView(this); // engine.autoView: manual() for camera.far / fov / pixel ratio / camera pose the engine changes on its own (core/scene/view.js)
210
+ defineTerms(this); // engine.shaderTerms: the game's own cloud shadow or season tint in place of the engine's (render/terms.js)
207
211
  this._materials = registerEngine(this); // applyEffects without an engine option uses the first live engine
208
212
 
209
- createServices(this, { canvas, validate, locale, strings, saveKey, joystick, bindings, audio, decoders, budget, seed, headless, urlState, threads, batching });
213
+ createServices(this, { canvas: r.domElement, validate, locale, strings, saveKey, joystick, bindings, audio, decoders, budget, seed, headless, urlState, threads, batching });
210
214
  this.startup = null; // startup timing report (set once start() finishes)
211
215
  this._readyAt = null; // set at ready until the first frame is drawn (loop.js firstFrame)
212
216
  this._whileCompiling = []; // @internal one-time warm-ups a module queues during loading; start() runs them while the GPU compiles
@@ -238,31 +242,32 @@ export class Engine {
238
242
  get waterLevel() { return this.ground.waterLevel; }
239
243
  /** True once the world is built (phase 'ready' or 'running'): fixed steps, ops and rendering run from here on @type {boolean} */
240
244
  get ready() { return this.phase === 'ready' || this.phase === 'running'; }
245
+ /** @internal start() is on its way: no game time passes */
246
+ get _inStart() { return this.phase === 'starting' || this.phase === 'loading'; }
247
+ /** @internal the modules at start() have had their init, so one installed now runs its own at once */
248
+ get _initsDone() { return this.phase !== 'constructed' && this.phase !== 'starting'; }
241
249
  /** True after dispose() @type {boolean} */
242
250
  get disposed() { return this.phase === 'disposed'; }
243
251
 
244
252
  // ---------- common ----------
245
253
  /** Get a UI string (i18n) */
246
- t(key, params) { return this.i18n.t(key, params); }
247
- /**
248
- * Fixed steps run (= engine.time.tick, the one time counter, core/time.js). Read-only; starts again from 0 on session.newGame / load / quit.
249
- * Seconds are views of it: engine.time.now('real' | 'ambient' | 'calendar' | channel)
250
- */
251
- get tick() { return this.time.tick; }
254
+ t(key, params) { return this.i18n._t(key, params); }
252
255
  /** Ray cast: the nearest hit or null, see Rays.js */
253
- raycast(origin, dir, opts) { return this.rays.cast(origin, dir, opts); }
256
+ raycast(origin, dir, opts) { return this.rays._ray(origin, dir, opts); }
254
257
  /** Cast a ray from screen coordinates (-1..1) */
255
- pick(ndcX, ndcY, opts) { return this.rays.pick(ndcX, ndcY, opts); }
258
+ pick(ndcX, ndcY, opts) { return this.rays._rayAt(ndcX, ndcY, opts); }
256
259
  /** Set up a scenario: { time, weather, pos, at, save, wait, cutscene, state }, see UrlState.js */
257
260
  applyState(params) { return this._urlState.apply(params); }
258
261
  /**
259
262
  * Scenario ready: start() has finished, the URL parameters / latest applyState are applied, and (headless) a load begun after start has settled
260
- * (tests and screenshots wait for it; core/headlessLoad.js)
263
+ * (tests and screenshots wait for it; core/engine/headlessLoad.js)
261
264
  */
262
265
  get stateApplied() { return this.ready && this._urlState.applied && headlessSettled(this); }
266
+ /** What the URL parameters or the latest applyState could not do: [{ key, value, reason }], e.g. ?weather=typo. Read it after stateApplied @type {{ key: string, value: any, reason: string }[]} */
267
+ get stateRefused() { return this._urlState.refused; }
263
268
  /**
264
269
  * Name a set of scenario parameters, then use applyState({ state: name }) or the URL ?state=name. Returns a handle: remove() forgets the name
265
- * @param {string} name @param {import('../types/core').StateParams} params @param {{ owner?: string }} [opts]
270
+ * @param {string} name @param {import('../../types/core').StateParams} params @param {{ owner?: string }} [opts]
266
271
  * @returns {{ owner?: string, remove(): void }}
267
272
  */
268
273
  defineState(name, params, opts) { return this._urlState.define(name, params, opts); }
@@ -282,6 +287,9 @@ export class Engine {
282
287
  }
283
288
  /** Once per frame: animation, camera, UI. Returns a handle { remove() } */
284
289
  onFrame(fn) { const h = ownHook(this, fn); this._frame.push(h); return { remove: () => { this._frame = this._frame.filter(f => f !== h); } }; }
290
+ /** @internal An animator's per-frame update: runs after the whole onFrame list (loop.js), so what onFrame asked of it shows the same frame. Returns a handle { remove() } */
291
+ _onAnimate(fn) { const h = ownHook(this, fn); this._animate.push(h); return { remove: () => { this._animate = this._animate.filter(f => f !== h); } }; }
292
+
285
293
  /**
286
294
  * Around the main render, after the camera update and batching: fn({ renderer, scene, camera, dt }). when 'before' (default) runs just before the
287
295
  * engine's frame render: render to your own target there (mirror, minimap, portal, picking); the render target is reset afterwards. 'after' runs
@@ -314,8 +322,3 @@ export class Engine {
314
322
  // Mix in by property descriptor (Object.assign would evaluate getters on the spot and lose them)
315
323
  for (const part of [loopMethods, holdMethods, startupMethods, groundMethods, actorMethods, moduleMethods, lifecycleMethods, skipMethods, checkMethods, resizeMethods, sceneMethods, probeMethods, lightmapMethods])
316
324
  Object.defineProperties(Engine.prototype, Object.getOwnPropertyDescriptors(part));
317
- // engine.elapsed was a second counter beside engine.time (review 0.4, B): removed. In dev a read throws with the new form instead of giving
318
- // undefined (NaN in every Math.sin(engine.elapsed) animation, silently)
319
- if (DEV) Object.defineProperty(Engine.prototype, 'elapsed', { configurable: true, get() {
320
- throw codedError('renamed-field', "engine.elapsed was removed: read engine.time.now('real') (fixed seconds, no scale) or engine.time.now('ambient') (keeps moving while frozen)");
321
- } });
@@ -52,6 +52,8 @@ export class Loading {
52
52
  /** Start (or restart) a task; engine-internal callers keep the returned task and move its phase */
53
53
  _begin(name, kind, opts) { const t = new Task(name, kind, opts); this.tasks.set(kind + ':' + name, t); return t; } // keyed by kind too: a module and a model may share a name
54
54
  _done(t) { t.phase('done', 1); }
55
+ /** A load ended on purpose (assets.release, dispose): it neither finished nor failed, so the record goes; the next load of that name starts its own */
56
+ _drop(t) { if (this.tasks.get(t.kind + ':' + t.name) === t) this.tasks.delete(t.kind + ':' + t.name); }
55
57
  /** Record a failure: err may carry url / status (LoadError) */
56
58
  _fail(t, err, fallback = null) {
57
59
  t.phase('failed');
@@ -101,13 +103,13 @@ export class Loading {
101
103
  if (!e.stream.ready) out.push(Object.assign(new Task('stream', 'stream', { critical: true }), { state: 'build' }));
102
104
  return out;
103
105
  }
104
- /** The item to name when asked "what are we waiting for": a critical one first, the furthest along last */
106
+ /** The item to name when asked "what are we waiting for": a critical one first, else the oldest */
105
107
  _current(pending) { return pending.find(t => t.critical) ?? pending[0] ?? null; }
106
108
 
107
109
  /**
108
110
  * The summary describe().loading shows. done: nothing pending; ok: nothing failed and no missing references;
109
111
  * blocked: a critical item failed before start() finished; waiting: one English line naming the current item.
110
- * @returns {import('../types/core').LoadingView}
112
+ * @returns {import('../../types/core').LoadingView}
111
113
  */
112
114
  view() {
113
115
  const pending = this._pending(), all = [...this.tasks.values()];
@@ -1,12 +1,12 @@
1
- // Two copies of the engine on one page (e.g. a game imports `threedog` while a style or tool bundles its own copy, or a
1
+ // Two copies of the engine on one page (e.g. a game imports `threedog` while a pack or tool bundles its own copy, or a
2
2
  // workspace link plus an npm copy). Each copy installs the shadow accessors on THREE.Mesh.prototype (render/patches.js) and keeps
3
3
  // its own patch lists, so the second install makes the first copy's wind / CSM materials cast no matching shadow: nothing throws,
4
4
  // shadows just go wrong. So each copy writes itself under one global symbol at load and the second one says so, once, naming both.
5
5
  // console: [threedog] two copies of the engine on this page (0.2.1 at .../node_modules/threedog/, 0.2.1 at .../packages/engine/): load one, ...
6
6
  // A hot reload re-runs the same file (same path, a ?t= query): that is one copy, not two, so the path without the query decides.
7
- import { coded } from './errorHints.js';
7
+ import { coded } from '../base/errorHints.js';
8
8
 
9
- export const VERSION = '0.7.0'; // kept equal to package.json by the "[guard] engine copies" spec
9
+ export const VERSION = '0.8.0'; // kept equal to package.json by the "[guard] engine copies" spec
10
10
 
11
11
  const KEY = Symbol.for('threedog.engine.copies');
12
12
 
@@ -27,6 +27,6 @@ export function noteCopy(me, registry = globalThis) {
27
27
  if (!other) return '';
28
28
  return coded('engine-two-copies', `[threedog] two copies of the engine on this page (${other.version} at ${other.root}, ${me.version} at ${root}): ` +
29
29
  "load one, e.g. vite.config.js: resolve: { dedupe: ['threedog', 'three'] }. Each copy hooks THREE.Mesh.prototype for shadows, so " +
30
- 'wind / cascaded-shadow materials of one copy cast wrong shadows. `npm ls threedog` shows who pulls the second; a style or ' +
30
+ 'wind / cascaded-shadow materials of one copy cast wrong shadows. `npm ls threedog` shows who pulls the second; a pack or ' +
31
31
  'tool lists threedog under peerDependencies, not dependencies');
32
32
  }