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
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Engine entry.
2
2
  //
3
3
  // Core (always present): rendering, main loop, events, input, assets, audio, saves, UI base, loading screen, ground API
4
- // Modules (opt-in): every lowercase function exported below is a module
4
+ // Modules (opt-in): installed with engine.use(...), like the list below
5
5
  //
6
6
  // import { createEngine, terrain, vegetation, sky, weather, water, collision, rigid,
7
7
  // followCamera, characters, interactions, dialogue, inventory, quests, photo, ambience, debug } from 'threedog';
@@ -13,7 +13,7 @@
13
13
  //
14
14
  // Or install the usual open-world set at once with a preset: engine.use(openWorld({ seed: 7, camera: 'follow', terrain: terrainPreset() }))
15
15
  import * as THREE from 'three';
16
- import { Engine } from './core/Engine.js';
16
+ import { Engine } from './core/engine/Engine.js';
17
17
  import { terrain } from './modules/terrain/index.js';
18
18
  import { vegetation } from './modules/vegetation/index.js';
19
19
  import { sky } from './modules/sky/skyModule.js';
@@ -35,6 +35,7 @@ import { debug } from './modules/debug/DebugPanel.js';
35
35
  import { level } from './modules/level/index.js';
36
36
  import { triggers } from './modules/triggers/index.js';
37
37
  import { particles } from './modules/particles/Particles.js';
38
+ import { swarm } from './modules/swarm/Swarm.js';
38
39
  import { settings } from './modules/settings/index.js';
39
40
  import { music } from './modules/music/index.js';
40
41
  import { firstPersonCamera, fixedCamera, rtsCamera } from './modules/camera/index.js';
@@ -47,38 +48,47 @@ import { flow } from './modules/flow/index.js';
47
48
  import { hud } from './modules/hud/index.js';
48
49
  import { world } from './modules/world/index.js';
49
50
  import { grids } from './modules/grid/index.js';
50
- import { checkOptions, DEV } from './core/validate.js';
51
- import { readParams, keysSchema } from './core/params.js';
52
- import { codedError } from './core/errorHints.js';
51
+ import { checkOptions, DEV, fmt } from './core/base/validate.js';
52
+ import { readParams, keysSchema } from './core/base/params.js';
53
+ import { codedError } from './core/base/errorHints.js';
53
54
 
54
55
  // Engine and Animator are exported for types and instanceof; make them with createEngine / engine.assets.animate (AI.md entry-point table)
55
56
  export { THREE, Engine };
56
- export { Animator } from './core/Animator.js';
57
+ export { Animator } from './core/assets/Animator.js';
57
58
  export { terrain, vegetation, calendar, sky, weather, water, collision, rigid, followCamera, characters, interactions, dialogue, inventory, pickups, quests, photo, ambience, debug,
58
- level, triggers, particles, settings, music, firstPersonCamera, fixedCamera, rtsCamera, timeline, nav, hlod, lightPool, content, flow, hud, world, grids };
59
+ level, triggers, particles, swarm, settings, music, firstPersonCamera, fixedCamera, rtsCamera, timeline, nav, hlod, lightPool, content, flow, hud, world, grids };
59
60
  export { net, fakeNetwork, webSocket } from './modules/net/index.js';
60
- export { screenToGround } from './core/screenToGround.js';
61
- export { EASINGS, ease } from './core/easing.js';
62
- export { sampleGrid } from './core/grid.js'; // a grid of numbers (height, moisture, density, walkable) as a function (x, z) -> value; assets.gridFromImage reads one from an image. 'threedog/grid' is the same file without three.js (workers, tests)
61
+ export { screenToGround } from './core/scene/screenToGround.js';
62
+ export { ease } from './core/base/easing.js';
63
+ export { sampleGrid } from './core/scene/grid.js'; // a grid of numbers (height, moisture, density, walkable) as a function (x, z) -> value; assets.gridFromImage reads one from an image. 'threedog/grid' is the same file without three.js (workers, tests)
63
64
  export { checkOptions }; // only for extensible data (game-defined fields); an options bag goes through readParams
64
65
  export { contentParts } from './modules/content/parts.js'; // one content kind split over files: content/props/*.js joined in file-name order (recipes/30)
65
- export { threePatches } from './core/threePatches.js'; // the engine's page-wide changes to three.js classes: list(), off(id) (THREE.md "Global changes")
66
- export { readParams } from './core/params.js'; // params schema for game-made modules: validated, defaults filled, shown by engine.catalog() // for game-made modules (recipes/14): the package exposes no core/* deep paths
66
+ export { threePatches } from './core/scene/threePatches.js'; // the engine's page-wide changes to three.js classes: list(), off(id) (THREE.md "Global changes")
67
+ export { readParams } from './core/base/params.js'; // params schema for game-made modules (recipes/14): validated, defaults filled, shown by engine.catalog()
67
68
  export { createTerrain } from './modules/terrain/index.js';
68
69
  export { Character, NPC } from './modules/characters/index.js';
69
70
  export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
70
71
  export { terrainMaterial, mergeColored, applyEffects } from './render/materials.js';
71
72
  export { rampTexture } from './render/lighting.js'; // a toon material's gradientMap from grays or colors (recipes/09)
72
- export { bakeVertexAO } from './render/modeling.js'; // procedural-modeling gaps three.js lacks (recipe 54 lists what three already has)
73
+ export { bakeVertexAO } from './render/modeling.js'; // procedural-modeling gaps three.js lacks (THREE.md lists what three already has)
73
74
  export { materialPatches } from './render/patches.js';
74
75
  export { toast, makeWindow, worldToScreen, fadeScreen, uiFocus, toggleOnKey } from './ui/UI.js';
75
- export { parseClock, formatClock, inRange } from './core/dayTime.js';
76
- export { pickTarget, switchTarget } from './core/targeting.js';
77
- export { PICTURE_SLOTS } from './core/pictureSlots.js';
76
+ export { parseClock, formatClock, inRange } from './core/time/dayTime.js';
77
+ export { pickTarget, switchTarget } from './core/scene/targeting.js';
78
+ export { PICTURE_SLOTS } from './core/scene/pictureSlots.js';
78
79
 
79
- /** Create an engine (core only). For the options see core/Engine.js */
80
+ /** Create an engine (core only). For the options see core/engine/Engine.js */
80
81
  export function createEngine(opts) { return new Engine(opts); }
81
82
 
83
+ const CAMERAS = { follow: followCamera, firstPerson: firstPersonCamera, rts: rtsCamera, fixed: fixedCamera };
84
+ const OPEN_WORLD_PARTS = { world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug };
85
+ const OPEN_WORLD_SHORT = ['seed', 'viewChunks', 'density', 'flatten', 'time', 'dayLength', 'autoWeather', 'camera'];
86
+ const OW_ERR = { camera: 'openWorld(): camera has no kind \'{k}\'; available: {list}, or pass a camera module (e.g. rtsCamera({ height: 60 })) or false',
87
+ noCamera: "openWorld(): no camera given; pick one: openWorld({ camera: 'follow' }) (or 'firstPerson' / 'rts' / 'fixed', a camera module such as followCamera(presets.camera.overShoulder), or false for none)",
88
+ part: 'openWorld(): {k} must be false (leave it out), true or an options object, e.g. openWorld({ {k}: false }); got {got}',
89
+ noOpts: 'openWorld(): {k} takes no options, only true / false; got {got}. {hint}' };
90
+ // vegetation takes options only on its own chunks: on terrain an options object would be dropped silently, so it throws and points to where the setting lives
91
+ const VEGETATION_HINT = 'How much vegetation grows is a terrain setting: openWorld({ density: 1.5 }) or terrain({ density }); the species are game content (content vegetation; a style only paints them). On ground without terrain (a level) it takes its own options: openWorld({ terrain: false, vegetation: { area, density } })';
82
92
  /**
83
93
  * Open-world preset: covers only "world and environment" plus the basics every game needs:
84
94
  * world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, camera, characters, ambience, settings, debug (debug only in dev builds).
@@ -86,7 +96,7 @@ export function createEngine(opts) { return new Engine(opts); }
86
96
  * engine.use(openWorld({ seed: 7, camera: 'follow' }), interactions({ ...presets.interactions.nearest }), dialogue(), inventory(), quests()); // keys: createEngine({ bindings: { ...presets.bindings.interact, ...presets.bindings.inventory } })
87
97
  * Every part takes false (leave it out) or an object (that module's own options), so the preset never has to be abandoned for one setting:
88
98
  * openWorld({ seed: 7, camera: 'follow', calendar: { seasons: ['wet', 'dry'], daysPerSeason: 28 }, characters: { npcs: false }, rigid: false, ambience: false })
89
- * The bundle hides the terrain's far edge in fog (terrain viewFog: true; openWorld({ terrain: { viewFog: false } }) leaves uViewDistance alone).
99
+ * The bundle turns on the signal uViewDistance (terrain viewFog: true) and writes no fog: the game's own fog reads it to hide the far edge; openWorld({ terrain: { viewFog: false } }) leaves it alone.
90
100
  * Shorthands still work and go to their module: seed / viewChunks / density / flatten → terrain, time / dayLength → calendar,
91
101
  * weather: 'rain' (starting weather) and autoWeather → weather. An object for the same module wins over the shorthand.
92
102
  * debug: installed only in dev builds by default (players of a release build get no F3 panel); true installs it in release builds too.
@@ -95,30 +105,20 @@ export function createEngine(opts) { return new Engine(opts); }
95
105
  * Switch at runtime: engine.setCamera('firstPerson') (see recipes/21-camera.md).
96
106
  * @param {{ camera: 'follow' | 'firstPerson' | 'rts' | 'fixed' | false | import('./types/core').ModuleDef, [k: string]: any }} opts
97
107
  */
98
- const CAMERAS = { follow: followCamera, firstPerson: firstPersonCamera, rts: rtsCamera, fixed: fixedCamera };
99
- const OPEN_WORLD_PARTS = { world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug };
100
- const OPEN_WORLD_SHORT = ['seed', 'viewChunks', 'density', 'flatten', 'time', 'dayLength', 'autoWeather', 'camera'];
101
- const OW_ERR = { camera: 'openWorld(): camera has no kind \'{k}\'; available: {list}, or pass a camera module (e.g. rtsCamera({ height: 60 })) or false',
102
- noCamera: "openWorld(): no camera given; pick one: openWorld({ camera: 'follow' }) (or 'firstPerson' / 'rts' / 'fixed', a camera module such as followCamera(presets.camera.overShoulder), or false for none)",
103
- part: 'openWorld(): {k} must be false (leave it out), true or an options object, e.g. openWorld({ {k}: false }); got {got}',
104
- noOpts: 'openWorld(): {k} takes no options, only true / false; got {got}. {hint}' };
105
- // parts whose module takes no options: an options object would be dropped silently, so it throws and points to where the setting lives
106
- const NO_OPTIONS = { vegetation: 'How much vegetation grows is a terrain setting: openWorld({ density: 1.5 }) or terrain({ density }); the species are game content (content vegetation; a style only paints them). On ground without terrain (a level) it takes its own options: openWorld({ terrain: false, vegetation: { area, density } })' };
107
108
  export function openWorld(opts = {}) {
108
109
  readParams('openWorld()', keysSchema([...OPEN_WORLD_SHORT, ...Object.keys(OPEN_WORLD_PARTS)]), opts);
109
110
  const { seed, viewChunks, density, flatten = [], time, dayLength, autoWeather = false, camera } = opts;
110
111
  if (camera === undefined) throw codedError('open-world-camera', OW_ERR.noCamera); // no default camera feel: the game names one (genericity rule)
111
- if (typeof camera === 'string' && !CAMERAS[camera]) throw codedError('preset-option', OW_ERR.camera.replace('{k}', camera).replace('{list}', Object.keys(CAMERAS).join(', ')));
112
+ if (typeof camera === 'string' && !CAMERAS[camera]) throw codedError('preset-option', fmt(OW_ERR.camera, { k: camera, list: Object.keys(CAMERAS).join(', ') }));
112
113
  const w = opts.weather;
113
114
  const short = { terrain: { seed, viewChunks, density, flatten, viewFog: true }, calendar: { time, dayLength }, weather: { start: typeof w === 'string' ? w : undefined, auto: autoWeather } }; // no start: weather() picks one from the game's table
114
115
  const part = k => {
115
116
  const v = opts[k];
116
117
  if (v === false || (k === 'debug' && v === undefined && !DEV)) return null;
117
118
  if (v !== undefined && v !== true && typeof v !== 'object' && !(k === 'weather' && typeof v === 'string')) {
118
- throw codedError('preset-option', OW_ERR.part.replaceAll('{k}', k).replace('{got}', JSON.stringify(v)));
119
+ throw codedError('preset-option', fmt(OW_ERR.part, { k, got: String(JSON.stringify(v)) }));
119
120
  }
120
- // vegetation takes options only when it grows on its own chunks (terrain: false); on terrain those settings belong to terrain
121
- if (NO_OPTIONS[k] && !(k === 'vegetation' && opts.terrain === false) && v && typeof v === 'object' && Object.keys(v).length) throw codedError('preset-option', OW_ERR.noOpts.replace('{k}', k).replace('{got}', JSON.stringify(v)).replace('{hint}', NO_OPTIONS[k]));
121
+ if (k === 'vegetation' && opts.terrain !== false && v && typeof v === 'object' && Object.keys(v).length) throw codedError('preset-option', fmt(OW_ERR.noOpts, { k, got: JSON.stringify(v), hint: VEGETATION_HINT }));
122
122
  return OPEN_WORLD_PARTS[k]({ ...short[k], ...(typeof v === 'object' ? v : null) });
123
123
  };
124
124
  const cam = camera === false ? null : typeof camera === 'string' ? CAMERAS[camera]() : camera;
package/llms.txt CHANGED
@@ -11,7 +11,7 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
11
11
 
12
12
  ## Recipes
13
13
 
14
- - [01-new-game](docs/recipes/01-new-game.md): Starting a new game (a workspace under games/)
14
+ - [01-new-game](docs/recipes/01-new-game.md): Starting a new game
15
15
  - [02-npc](docs/recipes/02-npc.md): Adding an NPC (schedule + dialogue)
16
16
  - [03-items-pickups](docs/recipes/03-items-pickups.md): Adding items and pickups
17
17
  - [04-quests](docs/recipes/04-quests.md): Adding quests (with HUD objective markers)
@@ -35,30 +35,25 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
35
35
  - [23-ops](docs/recipes/23-ops.md): Ops: one entry point for what players and NPCs do (engine.ops)
36
36
  - [26-ui-parts](docs/recipes/26-ui-parts.md): UI parts: replace or turn off any piece of the engine's screen UI
37
37
  - [27-net](docs/recipes/27-net.md): Co-op multiplayer: net() (host authority + state sync)
38
- - [28-terrain](docs/recipes/28-terrain.md): Terrain: your own generator, digging, raising and painting the ground
38
+ - [28-terrain](docs/recipes/28-terrain.md): Terrain: your own generator, digging, raising and painting the ground, islands
39
39
  - [29-grid](docs/recipes/29-grid.md): Grid placement: towers, furniture, buildings, crops
40
40
  - [30-templates](docs/recipes/30-templates.md): Templates: reusable objects, definition vs instance state
41
41
  - [31-audio](docs/recipes/31-audio.md): Sound: buses, sounds by name, ambience rules, music, footsteps, ducking
42
- - [32-action-game](docs/recipes/32-action-game.md): Action game wiring: hp, attacks, enemy AI, drops and death without engine combat rules
42
+ - [32-action-game](docs/recipes/32-action-game.md): Action game wiring: hp, attacks, guns, enemy AI, drops, death, win and lose without engine combat rules
43
43
  - [33-stream-sources](docs/recipes/33-stream-sources.md): Stream sources: what is loaded where (teleport, far camera)
44
- - [34-environment-lighting](docs/recipes/34-environment-lighting.md): Environment lighting
44
+ - [34-environment-lighting](docs/recipes/34-environment-lighting.md): Lights, fog, exposure and environment lighting
45
45
  - [35-picture-from-reference](docs/recipes/35-picture-from-reference.md): Making a new picture from a reference picture
46
- - [36-sky-ground-plants](docs/recipes/36-sky-ground-plants.md): Sky, ground and plants
47
- - [37-terrain-hooks](docs/recipes/37-terrain-hooks.md): Crisp ground color borders, terrain normals, height from a grid
48
- - [38-environment-hooks](docs/recipes/38-environment-hooks.md): Lights, fog and exposure
46
+ - [36-ground-plants](docs/recipes/36-ground-plants.md): Ground color and plants
49
47
  - [40-scene](docs/recipes/40-scene.md): Scene: what is in the world, where, who manages it, and what a save keeps (engine.thing)
50
- - [42-terrain-shape](docs/recipes/42-terrain-shape.md): Terrain outline: islands, floating rocks, a world that ends
51
48
  - [43-shader-patches-surfaces](docs/recipes/43-shader-patches-surfaces.md): Writing shader patches and surfaces
52
- - [44-water-weather-hooks](docs/recipes/44-water-weather-hooks.md): Water and rain/snow: depth color, foam, reflections, particles, lightning
53
- - [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md): Shadows: cascades, box, budget, the switch
49
+ - [44-water-weather-hooks](docs/recipes/44-water-weather-hooks.md): Water and rain/snow: depth color, foam, reflections, particles, snow cover, lightning
50
+ - [45-cascaded-shadows](docs/recipes/45-cascaded-shadows.md): Shadows: cascades, box, budget, cache, the switch
54
51
  - [46-blender-art-route](docs/recipes/46-blender-art-route.md): Blender to game (GLB) route
55
- - [47-island-snow-backdrop](docs/recipes/47-island-snow-backdrop.md): Snow cover, flat backdrop, rounded terrain rim
56
52
  - [49-game-module-contract](docs/recipes/49-game-module-contract.md): Writing a game system module (a smelter, a recharging turret, growing crops) that plugs into the engine's contracts
57
53
  - [50-own-renderer](docs/recipes/50-own-renderer.md): Bring your own renderer: `createEngine({ renderer })`
58
54
  - [51-capability-catalog](docs/recipes/51-capability-catalog.md): Capability catalog: ask what the game can do before reading docs
59
55
  - [52-around-the-picture](docs/recipes/52-around-the-picture.md): 52 Around the picture: reading it back, the post chain, who writes what
60
- - [53-ground-up-close](docs/recipes/53-ground-up-close.md): The ground up close: options and diagnosis
61
- - [54-three-idioms](docs/recipes/54-three-idioms.md): Plain three.js in this engine
56
+ - [53-ground-up-close](docs/recipes/53-ground-up-close.md): The ground up close: options, crisp color borders, normals, diagnosis
62
57
  - [55-mods-time-wrap](docs/recipes/55-mods-time-wrap.md): Shared values, exclusive slots, time channels and wrapping module methods
63
58
  - [56-webgpu-tsl](docs/recipes/56-webgpu-tsl.md): WebGPU and your own TSL materials
64
59
  - [57-control](docs/recipes/57-control.md): Who steers a character: engine.control
@@ -69,3 +64,4 @@ Reading order: docs/AI.md (the index: one line per task) -> the recipe for the t
69
64
  - [62-picture-code](docs/recipes/62-picture-code.md): The whole picture in plain three.js: signals in, picture out
70
65
  - [63-third-person-start](docs/recipes/63-third-person-start.md): Third-person start: walking, camera, save, pause, menu
71
66
  - [64-particles](docs/recipes/64-particles.md): Particles: dust, smoke, sparks, splashes
67
+ - [65-swarm](docs/recipes/65-swarm.md): Swarm: shots, crowds, pickups, debris by the thousand
@@ -18,10 +18,10 @@
18
18
 
19
19
  import * as THREE from 'three';
20
20
 
21
- import { builtInSounds } from '../../core/assetManifest.js';
22
- import { readParams, keysSchema } from '../../core/params.js';
23
- import { codedError, coded } from '../../core/errorHints.js';
24
- import { warnOnce } from '../../core/validate.js';
21
+ import { builtInSounds } from '../../core/assets/assetManifest.js';
22
+ import { readParams, keysSchema } from '../../core/base/params.js';
23
+ import { codedError, coded } from '../../core/base/errorHints.js';
24
+ import { warnOnce } from '../../core/base/validate.js';
25
25
  /** @import { ModuleDef, AmbienceRule } from '../../types/core' */
26
26
  /** @import { AmbienceOptions } from '../../types/gameplay' */
27
27
  const RULE_KEYS = ['sound', 'when', 'volume', 'fade', 'every', 'bus'];
@@ -113,7 +113,7 @@ export class Ambience {
113
113
  _step(s, dt) {
114
114
  const r = s.rule, a = this.engine.audio, fade = r.fade ?? 1;
115
115
  if (s.failed) return; // its file failed to load: retrying every check would refetch it ~4 times a second forever. Reloading the rules (rules(), a pack loaded again, a page reload) tries again
116
- if (s.voice?.failed) { s.failed = true; s.voice = null; warnOnce(coded('load-failed', `[threedog] ambience: sound '${r.sound}' failed to load, its rule stays silent until the rules are loaded again. Fix the file path / asset name in audio.sounds`)); return; }
116
+ if (s.voice?.failed) { s.failed = true; s.voice = null; warnOnce(coded('asset-load', `[threedog] ambience: sound '${r.sound}' failed to load, its rule stays silent until the rules are loaded again. Fix the file path / asset name in audio.sounds`)); return; }
117
117
  const on = a.matches(r.when, this);
118
118
  s.level = on ? Math.max(0, a.volumeOf(r.volume, this)) : 0;
119
119
  if (r.every) {
@@ -125,7 +125,7 @@ export class Ambience {
125
125
  if (s.level > 0.001) {
126
126
  s.offT = 0;
127
127
  if (!s.voice?.playing) s.voice = a.sfx(r.sound, { bus: r.bus ?? 'ambience', loop: true, volume: 0 });
128
- s.voice?._fade(s.level, fade); // every frame: the internal form skips the option parse
128
+ s.voice?._fade(s.level, fade); // every check: the internal form skips the option parse
129
129
  } else if (s.voice) {
130
130
  if (s.offT === 0) s.voice._fade(0, fade);
131
131
  if ((s.offT += dt) > fade) { s.voice._stop(0); s.voice = null; s.offT = 0; } // faded out: stop the loop so an idle rule costs nothing
@@ -142,7 +142,7 @@ function noiseLoop(audio, out, filters, wobble = 0) {
142
142
  const f = ctx.createBiquadFilter(), g = ctx.createGain(); f.type = type; f.frequency.value = freq; f.Q.value = q; g.gain.value = vol;
143
143
  src.connect(f).connect(g).connect(mix);
144
144
  }
145
- if (wobble) { // two slow oscillators on the level: the gusting of the old per-frame code, without per-frame work
145
+ if (wobble) { // two slow oscillators on the level: gusting without per-frame work
146
146
  for (const hz of [0.37, 0.13]) { const o = ctx.createOscillator(), d = ctx.createGain(); o.frequency.value = hz; d.gain.value = wobble / 2; o.connect(d).connect(mix.gain); o.start(); nodes.push(o); }
147
147
  mix.gain.value = 1 - wobble / 2;
148
148
  }
@@ -189,9 +189,12 @@ export function ambience(opts = {}) {
189
189
  return a;
190
190
  },
191
191
  frame(dt) { a.update(dt); },
192
+ dispose() { a.rules(null); }, // its loops would play on with nobody left to fade them
192
193
  // "is the rain sound on here" without listening: the rules whose condition holds now, with their target volume; failed = files that did not load
193
194
  describe() {
194
195
  const on = a.info.filter(r => r.on).map(r => ({ sound: r.sound, volume: r.volume })), failed = a._rules.filter(s => s.failed).map(s => s.rule.sound);
195
- return { rules: a._rules.length, on, ...(failed.length ? { failed } : {}) };
196
+ // audio starts only after a real click or key press (browser rule): until then `on` is empty everywhere, which is not "no rule matches here"
197
+ const locked = a._rules.length > 0 && !a.engine.audio.running;
198
+ return { rules: a._rules.length, on, ...(failed.length ? { failed } : {}), ...(locked ? { audioLocked: 'audio starts after a real click or key press; a bridge page has none, so `on` stays empty here whatever the position' } : {}) };
196
199
  } };
197
200
  }
@@ -13,16 +13,17 @@
13
13
  // A game's own calendar (a turn counter, a lunar calendar) replaces this module by meeting modules/calendar/contract.js.
14
14
  // Time of day and day are views of the engine's 'calendar' time channel (engine.time.now('calendar') = engine.clock.now), not a second counter:
15
15
  // the calendar keeps an origin (the day and time of day at channel second t0) and reads the rest from the channel. Why: one time source
16
- // (core/time.js); a calendar that added its own dt drifted from clock timers, and skip had to advance both. Writing timeOfDay or day moves the
16
+ // (core/time/time.js); a calendar that added its own dt drifted from clock timers, and skip had to advance both. Writing timeOfDay or day moves the
17
17
  // origin. day:start / season:change and the clock timers fire right after the channel moves (engine.time.onMove), on a step and on a skip alike.
18
18
  import { parseSeasons, seasonIndexOf, dayOfSeasonOf, seasonProgressOf } from './seasons.js';
19
- import { formatClock, parseClock } from '../../core/dayTime.js';
19
+ import { formatClock, parseClock, sunHeightAt } from '../../core/time/dayTime.js';
20
20
  import { Schedule } from './schedule.js';
21
- import { codedError } from '../../core/errorHints.js';
21
+ import { codedError } from '../../core/base/errorHints.js';
22
+ import { fmt } from '../../core/base/validate.js';
22
23
  /** @import { CalendarOptions, CalendarAtOptions, CalendarBetweenOptions } from '../../types/world' */
23
24
  /** @import { Handle } from '../../types/common' */
24
25
  const STRINGS = {
25
- badDayLength: 'calendar({ dayLength }): game seconds per day must be a number > 0 (Infinity = the time of day never moves); got {got}',
26
+ badDayLength: 'calendar({ dayLength }): calendar seconds per day must be a number > 0 (Infinity = the time of day never moves); got {got}',
26
27
  noSeason: "calendar.onSeason('{name}'): the calendar has no such season (seasons: {list}). " +
27
28
  "Seasons are off by default: calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'] })",
28
29
  };
@@ -35,18 +36,16 @@ export class Calendar {
35
36
  */
36
37
  constructor(engine, { time = 0.33, dayLength = Infinity, day = 1, daysPerSeason = 7, seasons = [], hoursPerDay = 24 } = {}) {
37
38
  /** @internal */ this.engine = engine;
38
- if (!(dayLength > 0)) throw codedError('calendar-option', STRINGS.badDayLength.replace('{got}', String(dayLength)));
39
+ if (!(dayLength > 0)) throw codedError('calendar-option', fmt(STRINGS.badDayLength, { got: String(dayLength) }));
39
40
  // the origin: day _day0 at time of day _tod0 when the calendar channel read _t0 (kept apart, so a time just set reads back exactly)
40
41
  /** @internal */ this._day0 = day;
41
42
  /** @internal */ this._tod0 = parseClock(time, hoursPerDay) % 1;
42
43
  /** @internal */ this._t0 = engine.clock.now;
43
44
  /** @internal */ this._dayLength = dayLength;
44
45
  /** @internal the day the last move saw (day:start fires when a move changes it) */ this._lastDay = day;
45
- /** Hours per day (clock notation 'HH:MM', schedules, at / between) @type {number} */
46
+ /** Hours per day (clock notation 'HH:MM', schedules, at / between) @type {number} @experimental */
46
47
  this.hoursPerDay = hoursPerDay;
47
- /** Days per season for seasons given by name only @type {number} */
48
- this.daysPerSeason = daysPerSeason;
49
- /** Season names, [] when the game has no seasons (the default) @type {string[]} */
48
+ /** Season names, [] when the game has no seasons (the default) @type {string[]} @experimental */
50
49
  this.seasons = [];
51
50
  // kept as names plus the day each season ends (cumulative), so seasons of different lengths cost one short loop in the getters
52
51
  /** @internal */ this._ends = [];
@@ -61,7 +60,7 @@ export class Calendar {
61
60
  /** @internal move the origin to `day` at `tod` now */
62
61
  _origin(day, tod) { this._day0 = day; this._tod0 = tod; this._t0 = this.engine.clock.now; }
63
62
  /**
64
- * Time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength game seconds (the unit of engine.clock.now). Writing it later
63
+ * Time of day: 0-1 (0 midnight, 0.25 6am, 0.5 noon, 0.75 6pm); one day = dayLength calendar seconds (the unit of engine.clock.now). Writing it later
65
64
  * in the day counts as time passing (at timers crossed fire); writing it earlier only resets the timers' baseline @type {number}
66
65
  */
67
66
  get timeOfDay() { const x = this._x(); return x - Math.floor(x); }
@@ -70,29 +69,29 @@ export class Calendar {
70
69
  get day() { return this._day0 + Math.floor(this._x()); }
71
70
  set day(v) { this._origin(v, this.timeOfDay); this._lastDay = v; }
72
71
  /**
73
- * Game seconds per day (1 hour = dayLength / hoursPerDay game seconds; at clock.rate 1 calendar seconds equal real seconds); Infinity = the time of
72
+ * Calendar seconds per day (1 hour = dayLength / hoursPerDay calendar seconds; at clock.rate 1 calendar seconds equal real seconds); Infinity = the time of
74
73
  * day never moves. Changing it keeps the current time of day @type {number}
75
74
  */
76
75
  get dayLength() { return this._dayLength; }
77
76
  set dayLength(v) {
78
- if (!(v > 0)) throw codedError('calendar-option', STRINGS.badDayLength.replace('{got}', String(v)));
77
+ if (!(v > 0)) throw codedError('calendar-option', fmt(STRINGS.badDayLength, { got: String(v) }));
79
78
  this._origin(this.day, this.timeOfDay); this._dayLength = v;
80
79
  }
81
80
  /** Clock text, e.g. "18:00" */
82
81
  get clock() { return formatClock(this.timeOfDay, this.hoursPerDay); }
83
82
  /** Daylight from the clock 0-1 (0 from 18:00 to 06:00, 1 at noon; a sine over the day). Audio rules { daylight }, ambience and the sky's default sun read it */
84
- get daylight() { return Math.max(0, Math.sin((this.timeOfDay - 0.25) * Math.PI * 2)); }
83
+ get daylight() { return Math.max(0, sunHeightAt(this.timeOfDay)); }
85
84
  /** Whether it is daytime by the clock (06:00-18:00 of the day's hours) */
86
85
  get isDay() { return this.daylight > 0; }
87
- /** Current season index, -1 without seasons */
86
+ /** Current season index, -1 without seasons @experimental */
88
87
  get seasonIndex() { return seasonIndexOf(this); }
89
88
  /** Current season name, e.g. 'spring'; null without seasons @type {string | null} */
90
89
  get season() { return this.seasons[this.seasonIndex] ?? null; }
91
- /** Day within the season (1-based); 0 without seasons */
90
+ /** Day within the season (1-based); 0 without seasons @experimental */
92
91
  get dayOfSeason() { return dayOfSeasonOf(this); }
93
- /** Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons */
92
+ /** Fraction of the season elapsed, 0-1 (includes time of day); 0 without seasons @experimental */
94
93
  get seasonProgress() { return seasonProgressOf(this); }
95
- /** Total game time in days (fractional), for growth, cooldowns and the like */
94
+ /** Total game time in days (fractional), for growth, cooldowns and the like @experimental */
96
95
  get totalDays() { return this._day0 - 1 + this._x(); }
97
96
 
98
97
  /**
@@ -150,12 +149,13 @@ export class Calendar {
150
149
  onSeason(name, fn) {
151
150
  // a season the calendar does not have would never fire: say so now instead of waiting forever
152
151
  if (!this.seasons.includes(name))
153
- throw codedError('calendar-option', STRINGS.noSeason.replace('{name}', name).replace('{list}', this.seasons.length ? this.seasons.join(', ') : 'none'));
152
+ throw codedError('calendar-option', fmt(STRINGS.noSeason, { name: String(name), list: this.seasons.length ? this.seasons.join(', ') : 'none' }));
154
153
  return this._sched.onSeason(name, fn);
155
154
  }
156
155
  /**
157
- * Game seconds until the next clock mark (midnight, at times, between edges); engine.skip ends a segment there; Infinity when the time of day never moves
156
+ * Calendar seconds until the next clock mark (midnight, at times, between edges); engine.skip ends a segment there; Infinity when the time of day never moves
158
157
  * @returns {number}
158
+ * @experimental
159
159
  */
160
160
  untilMark() { return Number.isFinite(this.dayLength) ? this._sched.untilNext() * this.dayLength : Infinity; }
161
161
  /** Number of registered clock-time / season timers, for engine.counts() @internal */
@@ -1,12 +1,13 @@
1
1
  // calendar() hooks, saves, scenario time.
2
- // The calendar() module definition: install, per-step time, engine.skip, saves, scenario time / season, describe. engine.calendar API: Calendar.js.
2
+ // The calendar() module definition: install, the clock channel's moves, engine.skip, saves, scenario time / season, describe. engine.calendar API: Calendar.js.
3
3
  // Stage 'environment' before sky: the sky reads the calendar each frame to draw, so the time it draws is this step's.
4
4
  import { Calendar } from './Calendar.js';
5
5
  import { timeCondition } from './seasons.js';
6
- import { readParams, keysSchema } from '../../core/params.js';
7
- import { parseClock } from '../../core/dayTime.js';
8
- import { codedError } from '../../core/errorHints.js';
9
- import { saveValues } from '../../core/saveValues.js';
6
+ import { readParams, keysSchema } from '../../core/base/params.js';
7
+ import { parseClock } from '../../core/time/dayTime.js';
8
+ import { codedError, coded } from '../../core/base/errorHints.js';
9
+ import { warnOnce } from '../../core/base/validate.js';
10
+ import { saveValues } from '../../core/saves/saveValues.js';
10
11
  /** @import { ModuleDef } from '../../types/core' */
11
12
  /** @import { CalendarOptions } from '../../types/world' */
12
13
 
@@ -28,7 +29,7 @@ export function calendar(opts = {}) {
28
29
  name: 'calendar', type: 'world', provides: ['calendar'], label: 'Calendar', params: CALENDAR_PARAMS, options: opts, stage: 'environment', before: ['sky'],
29
30
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.calendar': '日历' }, en: { 'module.calendar': 'calendar' } });
30
31
  // sky({ time }) is the fixed time drawn without a calendar: installed before this one it would now sit unused, so say so (sky checks the other order)
31
- if (e.modules.get('sky')?.options?.time != null) throw codedError('calendar-option', STRINGS.skyTime);
32
+ if (e.modules.get('sky')?.options?.time != null) warnOnce(coded('calendar-option', STRINGS.skyTime), 'sky-time-calendar');
32
33
  c = new Calendar(e, opts);
33
34
  // audio rule condition { time: 'day' | 'night' | ['18:00', '06:00'] } and measure { daylight: { gt: 0.15 } } for music / ambience rule lists:
34
35
  // from the clock, so an indoor game without a sky still switches its night music
@@ -39,32 +40,31 @@ export function calendar(opts = {}) {
39
40
  for (const name of ['engine:ready', 'save:loaded', 'state:applied']) ctx.track(e.events.on(name, () => c._sched.syncRanges()));
40
41
  // the day and time of day are views of the 'calendar' channel: its events and clock timers run right after the channel moves (a step or a skip segment)
41
42
  ctx.track(e.time.onMove(() => c.moved()));
42
- // movedFrom.sky: saves from before the calendar was its own module kept the time under the 'sky' part ({ time, day }); they load here
43
43
  // at: the calendar channel second the time and day belong to, so the origin is right whichever part (calendar or time) loads first
44
44
  e.saves.register('calendar', { save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
45
45
  // saved numbers pass saveValues as clock / random / time do: a time 'abc' showed clock 'NaN:NaN' and a day -5 broke seasons (one warning per part)
46
46
  load: d => {
47
47
  if (d) {
48
48
  const v = saveValues('calendar');
49
- const tod = v.num(d.time ?? c.timeOfDay, 'time', { min: 0, max: 1, fallback: c.timeOfDay }) % 1; // 1 is the next midnight, as calendar({ time })
50
- const day = v.num(d.day ?? 1, 'day', { min: 1, int: true, fallback: c.day });
51
- const at = v.num(d.at ?? e.clock.now, 'at', { fallback: e.clock.now }); // a save without at (older): its time belongs to now
49
+ const tod = v.num(d.time, 'time', { min: 0, max: 1, fallback: c.timeOfDay }) % 1; // 1 is the next midnight, as calendar({ time })
50
+ const day = v.num(d.day, 'day', { min: 1, int: true, fallback: c.day });
51
+ const at = v.num(d.at, 'at', { fallback: e.clock.now });
52
52
  v.done();
53
53
  c._day0 = day; c._tod0 = tod; c._t0 = at; c._lastDay = c.day;
54
54
  c._season = c.season;
55
55
  }
56
56
  c._sched.rebase();
57
- },
58
- movedFrom: { sky: d => ({ time: d?.time, day: d?.day }) } });
57
+ } });
59
58
  return c;
60
59
  },
61
60
  counts() { return { timers: c.scheduled }; }, // engine.counts().calendar
62
- // engine.skip: segments end at clock marks (core/skip.js reads untilMark), so each move crosses at most one mark and one midnight; a skip right after
61
+ // engine.skip: segments end at clock marks (core/time/skip.js reads untilMark), so each move crosses at most one mark and one midnight; a skip right after
63
62
  // loading counts from now (a step would only reset the baseline). The move itself is the time source's (onMove above)
64
63
  skip() { c._sched.last ??= c.totalDays; },
65
64
  dispose() { c._sched.dispose(); },
66
65
  // scenario param time: 'HH:MM' or 0-1 (text in the URL)
67
66
  // scenario param season: the first day of that season (outside the last-20% blend into the next one), time of day kept
67
+ stateKeys: ['time', 'season'],
68
68
  applyState(e, { time, season }) {
69
69
  if (time != null) c.timeOfDay = parseClock(time, c.hoursPerDay) % 1;
70
70
  if (season != null) {
@@ -1,9 +1,12 @@
1
1
  // Calendar clock-time / season timers (implementation of engine.calendar.at / between / daily / onSeason; Calendar owns one Schedule).
2
- // They read the calendar's time of day calendar.timeOfDay, not game seconds; for "after N seconds / every N seconds" use engine.clock.after / every.
2
+ // They read the calendar's time of day calendar.timeOfDay, not calendar seconds; for "after N seconds / every N seconds" use engine.clock.after / every.
3
3
  // at is a "cross a clock time" event: when time moves forward (natural flow, fast-forward, raising calendar.timeOfDay) across several triggers, catchUp decides replay: 'once' fires once (default), 'all' fires all, 'skip' fires none;
4
4
  // rewinding time (applyState to an earlier time, lowering calendar.timeOfDay) and loading a save only reset the baseline, no replay. To hold a state during a time range use between.
5
- import { parseClock, inFrac } from '../../core/dayTime.js';
6
- import { reportError } from '../../core/errors.js';
5
+ import { parseClock, inFrac } from '../../core/time/dayTime.js';
6
+ import { reportError } from '../../core/base/errors.js';
7
+ import { readParams, keysSchema } from '../../core/base/params.js';
8
+
9
+ const AT_KEYS = ['days', 'catchUp'], BETWEEN_KEYS = ['on', 'off'];
7
10
 
8
11
  // clock-time conversions needed every step are cached on the registered entry (recomputed only when the clock time or hours per day change)
9
12
  function frac(o, key, hoursPerDay) {
@@ -20,13 +23,15 @@ export class Schedule {
20
23
  }
21
24
  get size() { return this.points.length + this.ranges.length; }
22
25
  dispose() { this.points = []; this.ranges = []; }
23
- at(clock, fn, { days = null, catchUp = 'once' } = {}) {
26
+ at(clock, fn, opts) {
27
+ const { days = null, catchUp = 'once' } = readParams('calendar.at()', keysSchema(AT_KEYS), opts);
24
28
  parseClock(clock); // a wrong clock time throws here, at the call, not later inside every step
25
29
  const p = { clock, fn, days, catchUp };
26
30
  this.points.push(p);
27
31
  return { remove: () => { this.points = this.points.filter(x => x !== p); } };
28
32
  }
29
- between(from, to, { on, off } = {}) {
33
+ between(from, to, opts) {
34
+ const { on, off } = readParams('calendar.between()', keysSchema(BETWEEN_KEYS), opts);
30
35
  parseClock(from); parseClock(to); // as at(): a wrong clock time throws at the call
31
36
  const r = { from, to, on, off, inside: null };
32
37
  this.ranges.push(r);
@@ -58,7 +63,7 @@ export class Schedule {
58
63
  }
59
64
  /** After loading a save the next step only resets the baseline, no replay */
60
65
  rebase() { this.last = null; }
61
- /** Called every fixed step after the calendar advances time */
66
+ /** Called right after the calendar channel moves (a step or a skip segment) */
62
67
  tick() {
63
68
  const cal = this.cal;
64
69
  if (this.ranges.length) this.syncRanges();
@@ -1,9 +1,9 @@
1
- // Calendar arithmetic (helpers of Calendar.js): seasons, day of season, one fixed step of the calendar, and the audio rule condition `time`.
1
+ // Calendar arithmetic (helpers of Calendar.js): seasons, day of season, and the audio rule condition `time`.
2
2
  // Why here and not in the sky: day, season and clock time are gameplay (an indoor shop sim or a dungeon has no sky but has opening hours and
3
3
  // a day counter); the sky only reads them to draw (modules/sky/season.js tints by season, frame.js places the sun by the time of day).
4
- import { warnOnce } from '../../core/validate.js';
5
- import { inRange } from '../../core/dayTime.js';
6
- import { codedError } from '../../core/errorHints.js';
4
+ import { warnOnce, fmt } from '../../core/base/validate.js';
5
+ import { inRange } from '../../core/time/dayTime.js';
6
+ import { codedError } from '../../core/base/errorHints.js';
7
7
 
8
8
  const STRINGS = {
9
9
  badTime: "audio rule condition time: {got} never matches; use 'day', 'night' or a clock range ['18:00', '06:00'] (or 0-1 times [0.75, 0.25])",
@@ -11,12 +11,12 @@ const STRINGS = {
11
11
  };
12
12
  /** Season names and the cumulative day each one ends on, from calendar({ seasons }): names (daysPerSeason long each) or { name, days } with days >= 1 */
13
13
  export function parseSeasons(seasons, daysPerSeason) {
14
- if (!Array.isArray(seasons)) throw codedError('calendar-option', STRINGS.badSeasons.replace('{got}', JSON.stringify(seasons)));
14
+ if (!Array.isArray(seasons)) throw codedError('calendar-option', fmt(STRINGS.badSeasons, { got: String(JSON.stringify(seasons)) }));
15
15
  const names = [], ends = [];
16
16
  let end = 0;
17
17
  for (const x of seasons) {
18
18
  const name = typeof x === 'string' ? x : x?.name, days = typeof x === 'string' ? daysPerSeason : x?.days;
19
- if (typeof name !== 'string' || !(days >= 1)) throw codedError('calendar-option', STRINGS.badSeasons.replace('{got}', JSON.stringify(x)));
19
+ if (typeof name !== 'string' || !(days >= 1)) throw codedError('calendar-option', fmt(STRINGS.badSeasons, { got: String(JSON.stringify(x)) }));
20
20
  names.push(name); ends.push(end += days);
21
21
  }
22
22
  return { names, ends };
@@ -28,7 +28,7 @@ export function timeCondition(s) {
28
28
  if (v === 'day') return s.isDay;
29
29
  if (v === 'night') return !s.isDay;
30
30
  // anything else must be a [from, to] range; 'evening' or a lone '18:00' would silently never match, so say which forms work
31
- if (!Array.isArray(v) || v.length !== 2) { warnOnce(STRINGS.badTime.replace('{got}', JSON.stringify(v))); return false; }
31
+ if (!Array.isArray(v) || v.length !== 2) { warnOnce(fmt(STRINGS.badTime, { got: String(JSON.stringify(v)) })); return false; }
32
32
  // a rule is read every frame: a wrong clock time ('dusk') warns once like the shapes above instead of throwing each frame
33
33
  try { return inRange(s.timeOfDay, v[0], v[1], s.hoursPerDay); } catch (err) { warnOnce(err.message); return false; }
34
34
  };
@@ -11,8 +11,8 @@
11
11
  // engine.setCamera('follow'); // switch back to third person at runtime (mouse lock releases, body shows again); see recipes/21-camera.md
12
12
  import * as THREE from 'three';
13
13
  import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
14
- import { vec3 } from '../../core/math.js';
15
- import { setFov } from '../../core/view.js';
14
+ import { vec3 } from '../../core/base/math.js';
15
+ import { setFov } from '../../core/scene/view.js';
16
16
 
17
17
  export class FirstPersonCamera {
18
18
  /**
@@ -17,13 +17,13 @@
17
17
  import * as THREE from 'three';
18
18
  import { rigModule, defineRig, viewForward, rightOf, rigPlaced } from './common.js';
19
19
  import { setProjection } from './projection.js';
20
- import { setFov } from '../../core/view.js';
21
- import { vec3 } from '../../core/math.js';
22
- import { ease as easing } from '../../core/easing.js';
23
- import { warnMissing } from '../../core/validate.js';
24
- import { readParams, keysSchema } from '../../core/params.js';
20
+ import { setFov } from '../../core/scene/view.js';
21
+ import { vec3 } from '../../core/base/math.js';
22
+ import { ease as easing } from '../../core/base/easing.js';
23
+ import { warnMissing } from '../../core/base/validate.js';
24
+ import { readParams, keysSchema } from '../../core/base/params.js';
25
25
  const BLEND_KEYS = ['seconds', 'ease'];
26
- import { codedError } from '../../core/errorHints.js';
26
+ import { codedError } from '../../core/base/errorHints.js';
27
27
 
28
28
  const SHOT_KEYS = ['position', 'lookAt', 'track', 'fov', 'at', 'trackHeight', 'projection', 'size'];
29
29
 
@@ -64,7 +64,7 @@ export class FixedCamera {
64
64
  });
65
65
  }
66
66
  /** @internal switched away (or replaced on a new playthrough): a rig that is not the camera never moves it (review 0.4 modules-a B1) */
67
- onExit() { this._onZone?.remove(); this._onZone = null; }
67
+ onExit() { this._onZone?.remove(); this._onZone = null; this._blend?.res(); this._blend = null; } // await blend() never hangs: no update runs here any more
68
68
 
69
69
  /** Add or replace a shot */
70
70
  add(name, s) {
@@ -109,8 +109,7 @@ export class FixedCamera {
109
109
  focusPoint() { return this.target ? this.target.position : this._look; }
110
110
 
111
111
  update(dt, input) {
112
- const s = this.shots[this.current];
113
- if (!s) return;
112
+ if (!this.shots[this.current]) return;
114
113
  if (this.auto === 'nearest' && this.target && (this._autoT -= dt) <= 0) {
115
114
  this._autoT = this.autoInterval;
116
115
  const n = this.nearest(this.target.position);
@@ -119,21 +118,21 @@ export class FixedCamera {
119
118
  if (d(n) + this.hysteresis < d(this.current)) this.triggerBlend > 0 ? this.blend(n, { seconds: this.triggerBlend }) : this.cut(n);
120
119
  }
121
120
  }
122
- const want = this._lookTarget(this.shots[this.current], this._want ??= new THREE.Vector3()); // scratch vectors: no per-frame allocation
123
- const fov = this.shots[this.current].fov ?? this._baseFov;
121
+ const sh = this.shots[this.current]; // after the auto switch: the shot this frame shows
122
+ const want = this._lookTarget(sh, this._want ??= new THREE.Vector3()); // scratch vectors: no per-frame allocation
123
+ const fov = sh.fov ?? this._baseFov;
124
124
  if (this._blend) {
125
125
  const b = this._blend; b.t += dt;
126
126
  const k = easing(b.ease)(Math.min(1, b.t / b.dur));
127
- const sh = this.shots[this.current];
128
127
  const pos = (this._bp ??= new THREE.Vector3()).copy(b.from).lerp(sh.position, k), look = (this._bl ??= new THREE.Vector3()).copy(b.fromLook).lerp(want, k);
129
128
  this._look.copy(look);
130
129
  // size blends only between two orthographic shots; a perspective/orthographic mix switches to the target's mode at once
131
130
  this._place(pos, look, b.fromFov + (fov - b.fromFov) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
132
131
  if (b.t >= b.dur) { this._blend = null; b.res(); }
133
132
  } else {
134
- if (this.shots[this.current].track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
133
+ if (sh.track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
135
134
  else this._look.copy(want);
136
- this._place(this.shots[this.current].position, this._look, fov, s.size);
135
+ this._place(sh.position, this._look, fov, sh.size);
137
136
  }
138
137
  // Direction: release the hold once no direction key is pressed
139
138
  const a = input.axis;
@@ -158,7 +157,7 @@ export class FixedCamera {
158
157
  const cam = this.engine.camera;
159
158
  cam.position.copy(pos); cam.lookAt(look);
160
159
  setProjection(cam, size ? 'orthographic' : 'perspective', size);
161
- if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (engine.view 'fov')
160
+ if (Math.abs(cam.fov - fov) > 1e-3) setFov(this.engine, fov); // yields to a fov the game set itself (engine.autoView 'fov')
162
161
  rigPlaced(this.engine); // a cut between frames is the engine's own write (common.js)
163
162
  }
164
163
  _latchDirection() {