threedog 1.1.0 → 1.2.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 (363) hide show
  1. package/CHANGELOG.md +879 -798
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +178 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +16 -6
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +5 -5
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +46 -27
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +13 -7
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +44 -3
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +16 -11
  103. package/docs/COMMANDS.md +139 -142
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +28 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +23 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +6 -1
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +74 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +9 -8
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +70 -79
  180. package/docs/recipes/63-third-person-start.md +47 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/GAMEMAP.md +2 -3
  185. package/examples/action/main.js +3 -3
  186. package/examples/action/picture/lights.js +3 -1
  187. package/examples/perf-island/GAMEMAP.md +3 -3
  188. package/examples/perf-island/picture/lights.js +2 -1
  189. package/examples/plain-picture/GAMEMAP.md +1 -1
  190. package/examples/rc2d/GAMEMAP.md +1 -1
  191. package/examples/styletest/GAMEMAP.md +2 -2
  192. package/examples/styletest/main.js +1 -1
  193. package/examples/techniques/interior-light/README.md +3 -3
  194. package/examples/techniques/interior-light/interiorLight.js +2 -4
  195. package/examples/techniques/interior-light/picture/lights.js +2 -1
  196. package/examples/techniques/modular-building/picture/lights.js +3 -1
  197. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  198. package/examples/techniques/procedural-animation/README.md +1 -1
  199. package/examples/techniques/procedural-animation/main.js +1 -1
  200. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  201. package/examples/world/GAMEMAP.md +2 -3
  202. package/examples/world/art/humanoid.js +1 -1
  203. package/examples/world/main.js +6 -3
  204. package/index.d.ts +2 -2
  205. package/llms.txt +101 -0
  206. package/modules/ambience/Ambience.js +21 -5
  207. package/modules/calendar/index.js +9 -5
  208. package/modules/calendar/schedule.js +23 -8
  209. package/modules/camera/FirstPersonCamera.js +3 -1
  210. package/modules/camera/FollowCamera.js +10 -5
  211. package/modules/camera/RtsCamera.js +4 -3
  212. package/modules/camera/common.js +70 -8
  213. package/modules/camera/contract.js +1 -1
  214. package/modules/characters/Character.js +16 -10
  215. package/modules/characters/NPC.js +31 -19
  216. package/modules/characters/assetModel.js +14 -9
  217. package/modules/characters/astar.js +6 -1
  218. package/modules/characters/contract.js +2 -2
  219. package/modules/characters/index.js +34 -22
  220. package/modules/characters/movers/manual.js +1 -1
  221. package/modules/characters/movers/rapier.js +17 -2
  222. package/modules/characters/movers/simple.js +1 -1
  223. package/modules/characters/movers/support.js +16 -7
  224. package/modules/characters/npcAvoid.js +2 -2
  225. package/modules/characters/npcSim.js +3 -2
  226. package/modules/characters/pathAsync.js +24 -8
  227. package/modules/characters/pathJob.js +1 -1
  228. package/modules/characters/player.js +10 -9
  229. package/modules/characters/playerStrings.js +5 -5
  230. package/modules/characters/proceduralRig.js +5 -5
  231. package/modules/characters/useModel.js +6 -0
  232. package/modules/characters/walkTo.js +1 -1
  233. package/modules/collision/Collision.js +29 -18
  234. package/modules/collision/grid.js +22 -4
  235. package/modules/content/index.js +3 -1
  236. package/modules/content/loader.js +1 -1
  237. package/modules/content/models.js +82 -33
  238. package/modules/content/props.js +2 -1
  239. package/modules/content/rules.js +11 -5
  240. package/modules/content/templates.js +3 -3
  241. package/modules/content/words.js +2 -2
  242. package/modules/debug/DebugPanel.js +9 -9
  243. package/modules/flow/index.js +9 -6
  244. package/modules/gameplay/Dialogue.js +34 -20
  245. package/modules/gameplay/Interactions.js +19 -15
  246. package/modules/gameplay/Inventory.js +9 -4
  247. package/modules/gameplay/Quests.js +12 -10
  248. package/modules/gameplay/pickups.js +23 -11
  249. package/modules/grid/index.js +1 -1
  250. package/modules/grid/preview.js +2 -2
  251. package/modules/grid/tiles.js +1 -1
  252. package/modules/hlod/index.js +4 -1
  253. package/modules/hud/index.js +47 -10
  254. package/modules/hud/parts.js +28 -9
  255. package/modules/level/geometry.js +8 -3
  256. package/modules/level/index.js +10 -5
  257. package/modules/level/load.js +4 -2
  258. package/modules/lights/sources.js +1 -1
  259. package/modules/music/Music.js +22 -4
  260. package/modules/nav/index.js +20 -10
  261. package/modules/particles/Particles.js +31 -14
  262. package/modules/particles/effect.js +20 -5
  263. package/modules/particles/lit.js +72 -0
  264. package/modules/photo/Photo.js +72 -28
  265. package/modules/photo/pathTrace.js +106 -0
  266. package/modules/rigid/RigidBodies.js +23 -14
  267. package/modules/rigid/Vehicles.js +3 -13
  268. package/modules/rigid/sync.js +2 -1
  269. package/modules/settings/Settings.js +52 -20
  270. package/modules/settings/apply.js +23 -9
  271. package/modules/settings/sections.js +39 -6
  272. package/modules/settings/strings.js +2 -0
  273. package/modules/settings/view.js +19 -3
  274. package/modules/sky/dome.js +15 -3
  275. package/modules/sky/environment.js +28 -12
  276. package/modules/sky/fog.js +1 -1
  277. package/modules/sky/frame.js +6 -1
  278. package/modules/sky/shader.js +4 -3
  279. package/modules/sky/skyModule.js +8 -4
  280. package/modules/swarm/Swarm.js +1 -1
  281. package/modules/terrain/ChunkManager.js +61 -15
  282. package/modules/terrain/chunkJob.js +2 -2
  283. package/modules/terrain/index.js +20 -5
  284. package/modules/terrain/terrainEdit.js +8 -4
  285. package/modules/terrain/terrainTexture.js +4 -2
  286. package/modules/timeline/Timeline.js +4 -3
  287. package/modules/timeline/Tween.js +3 -0
  288. package/modules/timeline/letterbox.js +1 -0
  289. package/modules/triggers/index.js +36 -17
  290. package/modules/vegetation/Vegetation.js +81 -19
  291. package/modules/vegetation/densityMap.js +13 -8
  292. package/modules/vegetation/draw.js +147 -24
  293. package/modules/vegetation/groundChunks.js +20 -5
  294. package/modules/vegetation/index.js +3 -3
  295. package/modules/vegetation/modelGeometry.js +9 -4
  296. package/modules/water/Water.js +11 -8
  297. package/modules/weather/Weather.js +7 -2
  298. package/modules/weather/shaders.js +25 -5
  299. package/modules/weather/weatherDraw.js +20 -6
  300. package/modules/world/World.js +2 -1
  301. package/modules/world/index.js +2 -2
  302. package/modules/world/persist.js +6 -2
  303. package/modules/world/views.js +15 -2
  304. package/package.json +4 -1
  305. package/presets.js +5 -5
  306. package/render/PostFX.js +84 -41
  307. package/render/backend.js +137 -16
  308. package/render/cascades.js +3 -1
  309. package/render/cascades.tsl.js +2 -0
  310. package/render/daylight.js +7 -1
  311. package/render/detail.js +7 -4
  312. package/render/effects.js +27 -8
  313. package/render/fogLook.js +24 -0
  314. package/render/fuse.js +5 -2
  315. package/render/fx/detail.tsl.js +9 -7
  316. package/render/fx/index.js +7 -2
  317. package/render/fx/library.tsl.js +1 -0
  318. package/render/fx/lightShaft.tsl.js +114 -0
  319. package/render/fx/noise.tsl.js +25 -8
  320. package/render/fx/objectOrigin.tsl.js +39 -10
  321. package/render/fx/particles.tsl.js +23 -6
  322. package/render/fx/patchNodes.tsl.js +17 -12
  323. package/render/fx/pcss.tsl.js +51 -0
  324. package/render/fx/postWebGPU.tsl.js +89 -29
  325. package/render/fx/sky.tsl.js +3 -9
  326. package/render/fxNumbers.js +10 -4
  327. package/render/impostor.tsl.js +107 -0
  328. package/render/lighting.js +33 -1
  329. package/render/lightmap.js +42 -28
  330. package/render/lights.js +19 -3
  331. package/render/materials.js +6 -4
  332. package/render/mergeCommon.js +4 -1
  333. package/render/occlusion.js +14 -4
  334. package/render/patches.js +79 -41
  335. package/render/postRuns.js +32 -0
  336. package/render/postWebGL.js +97 -10
  337. package/render/probes.js +10 -14
  338. package/render/shaderErrors.js +2 -1
  339. package/render/shadowCache.tsl.js +33 -5
  340. package/render/shadows.js +42 -16
  341. package/render/slots.js +8 -5
  342. package/render/vertexInputs.js +52 -0
  343. package/types/core.d.ts +114 -46
  344. package/types/gameplay.d.ts +56 -23
  345. package/types/generated/core/audio/Audio.d.ts +27 -1
  346. package/types/generated/core/base/Random.d.ts +1 -1
  347. package/types/generated/core/input/Input.d.ts +6 -8
  348. package/types/generated/core/input/inputSeat.d.ts +1 -1
  349. package/types/generated/core/inspect/Budget.d.ts +26 -0
  350. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  351. package/types/generated/core/saves/Saves.d.ts +10 -7
  352. package/types/generated/core/saves/session.d.ts +8 -2
  353. package/types/generated/core/scene/Rays.d.ts +1 -3
  354. package/types/generated/modules/particles/Particles.d.ts +1 -1
  355. package/types/generated/modules/world/World.d.ts +2 -1
  356. package/types/generated/render/PostFX.d.ts +35 -9
  357. package/types/physics.d.ts +796 -764
  358. package/types/pixel.d.ts +1 -1
  359. package/types/tsl.d.ts +62 -1
  360. package/types/world.d.ts +12 -3
  361. package/ui/Focus.js +7 -5
  362. package/ui/Parts.js +1 -1
  363. package/ui/touchPart.js +6 -3
@@ -25,7 +25,7 @@ Not used yet (check these before writing the system yourself):
25
25
  - inventory: items, stacks, containers and pickups: `inventory()` + key map presets.bindings.inventory, content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
26
26
  - collision: walls and blocking for characters: `collision()` (in openWorld), template `collide` (node_modules/threedog/docs/recipes/18-world.md)
27
27
  - characters: player and NPC movement, spawn, schedules: `characters()` (in openWorld), content/npcs.js (node_modules/threedog/docs/recipes/02-npc.md)
28
- - saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
28
+ - saves: save your own state: `engine.saves.define(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
29
29
  - interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
30
30
  - quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
31
31
  - swarm: many same-kind moving things (shots, crowds, flocks, debris) in typed arrays, drawn as one mesh: `swarm()` (node_modules/threedog/docs/recipes/65-swarm.md)
@@ -30,7 +30,7 @@ Content: actions 4 · audio 3 · containers 1 · dialogues 1 · items 4 · npcs
30
30
 
31
31
  ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
32
32
 
33
- - world: `node_modules/threedog/docs/recipes/66-common-tasks.md` · `node_modules/threedog/docs/api/world.md`
33
+ - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
34
34
  - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
35
35
  - vegetation: `node_modules/threedog/docs/recipes/36-ground-plants.md` · `node_modules/threedog/docs/api/vegetation.md`
36
36
  - calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
@@ -73,7 +73,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
73
73
  | content/rules.js | 24 | |
74
74
  | content/templates.js | 6 | |
75
75
  | content/vegetation.js | 33 | |
76
- | main.js | 173 | Open-world example (slow photography life): riverside cabin + an old fisherman who walks by the clo… |
76
+ | main.js | 176 | Open-world example (slow photography life): riverside cabin + an old fisherman who walks by the clo… |
77
77
  | models.js | 39 | Models this game builds in code: the cabin (registered by name in main.js, placed by content/props.… |
78
78
  | picture/index.js | 21 | @ts-check The open world's picture: wiring only. Each part writes plain three.js; one onRender driv… |
79
79
  | picture/lights.js | 42 | @ts-check Sun or moon and the ambient, from the sky of this moment (sky.js) and the weather. One sh… |
@@ -149,7 +149,6 @@ Code that breaks saves or manages world models: none (rule R33).
149
149
  ## Objective markers and HUD (hud module)
150
150
 
151
151
  - Quest first-light step 1 is marked automatically
152
- - hud.counter('film') — main.js
153
152
 
154
153
  ## Key actions defined by the game (the engine's own are in node_modules/threedog/docs/CODEMAP.md)
155
154
 
@@ -1,5 +1,5 @@
1
1
  // The 'humanoid' body: the procedural character body, exported in the world example's asset pack (art/index.js `assets`), so a character picks it like any model:
2
- // createPlayer({ model: 'humanoid' }), npcs content { model: 'humanoid' }. It is an asset and not part of the picture because a body is content the
2
+ // addPlayer({ model: 'humanoid' }), npcs content { model: 'humanoid' }. It is an asset and not part of the picture because a body is content the
3
3
  // game chooses per character (a GLB hero next to procedural villagers), while the picture only decides how things look.
4
4
  // Each part uses a material by name from picture/materials.js (skin / cloth / trousers / hair), so one change there retints every humanoid.
5
5
  // Per-character colors ({ colors: { body, skin, legs, hair } }) recolor the parts marked userData.part.
@@ -52,11 +52,14 @@ engine.onFrame(() => {
52
52
  });
53
53
 
54
54
  // ---------- 3. Player + content (vegetation, items, pickups, NPCs, dialogues, quests, key actions, templates, props, physics props, custom conditions) ----------
55
- engine.characters.createPlayer({ ...presets.player.thirdPerson, model: 'humanoid', spawn: { x: home.x + 4, z: home.z + 7 } }); // body: the humanoid asset from art/
56
- engine.content.load(data, { places: { home, river, water: waterSpot } }); // content names models only; the asset packs above resolve them
55
+ engine.characters.addPlayer({ ...presets.player.thirdPerson, model: 'humanoid', spawn: { x: home.x + 4, z: home.z + 7 } }); // body: the humanoid asset from art/
56
+ // Impostor comparison (threedog perf --only=pages --renderer=webgpu --impostor): ?impostor draws the trees that have a low-poly as baked cards instead
57
+ const cards = new URLSearchParams(location.search).has('impostor');
58
+ const veg = cards ? Object.fromEntries(Object.entries(/** @type {Record<string, any>} */ (data.vegetation)).map(([n, { lod, ...v }]) => [n, lod ? { ...v, impostor: true } : data.vegetation[n]])) : data.vegetation;
59
+ engine.content.load({ ...data, vegetation: veg }, { places: { home, river, water: waterSpot } }); // content names models only; the asset packs above resolve them
57
60
 
58
61
  // Show the film count at the top left (hud counter)
59
- const showFilm = () => engine.hud.counter('film', { icon: '🎞', label: '胶卷', value: engine.inventory.count('film') });
62
+ const showFilm = () => engine.hud.addCounter('film', { icon: '🎞', label: '胶卷', value: engine.inventory.count('film') });
60
63
  for (const ev of ['item:add', 'item:remove', 'save:loaded']) engine.events.on(ev, showFilm);
61
64
  showFilm();
62
65
 
package/index.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  //
18
18
  // When the engine's public API changes (new export, changed parameter), update this file too; `npm run types` checks that every export of index.js is declared.
19
19
 
20
- import type { Engine, EngineOptions, ModuleDef, ModuleInput, PictureSlot, Ground } from './types/core';
20
+ import type { Engine, EngineOptions, ModuleDef, ModuleInput, PictureSlot, Ground, GroundProvider } from './types/core';
21
21
  import type { Ease, EaseName, BufferGeometry, ColorLike, Material, Vector3, PositionLike } from './types/common';
22
22
  import type {
23
23
  TerrainOptions, TerrainConfig, TerrainGen, Terrain, Vegetation, VegetationModuleOptions, Sky, SkyOptions, Calendar, CalendarOptions, Weather, WeatherOptions, WeatherPreset,
@@ -118,7 +118,7 @@ export function openWorld(opts: OpenWorldOptions): ModuleDef[];
118
118
  /** Procedural terrain -> engine.terrain, and engine.terrainDraw for its drawing */
119
119
  export function terrain(opts?: TerrainOptions): [ModuleDef<Terrain>, ModuleDef<TerrainDraw>];
120
120
  /** One ground slot over several providers: terrain({ part: true }) / level({ part: true }) answer inside their region, higher priority wins where regions overlap. region: (x, z) => boolean | { volume } (asked at y 0); omitted = everywhere */
121
- export function compositeGround(opts: { parts: Array<{ of?: 'terrain' | 'level'; ground?: Ground; region?: ((x: number, z: number) => boolean) | { volume: { contains(p: { x: number; y: number; z: number }): boolean } }; priority?: number }> }): ModuleDef<void>;
121
+ export function compositeGround(opts: { parts: Array<{ of?: 'terrain' | 'level'; ground?: Partial<GroundProvider>; region?: ((x: number, z: number) => boolean) | { volume: { contains(p: { x: number; y: number; z: number }): boolean } }; priority?: number }> }): ModuleDef<void>;
122
122
  /** Vegetation -> engine.vegetation: on terrain chunks when terrain() is installed first (no options), else on its own chunks over any ground (a level, setGround) */
123
123
  export function vegetation(opts?: VegetationModuleOptions): [ModuleDef<Vegetation>, ModuleDef<VegetationDraw>];
124
124
  // Migrated: sky() is generated from the JSDoc in modules/sky/skyModule.js
package/llms.txt CHANGED
@@ -9,6 +9,107 @@ Taking over a game: its status notes first. A new feature: docs/AI.md or threedo
9
9
  - [AI.md](docs/AI.md): entry table, commands, verification rules, conventions
10
10
  - [API.md](docs/API.md): API index; one page per module in docs/api/
11
11
 
12
+ ## Which one
13
+
14
+ - Say it happened, no answer; cause chain, randomness: docs/recipes/06-clock-events.md
15
+ - Player actions, UI buttons (can refuse): docs/recipes/23-ops.md §1
16
+ - A value several systems change; one-holder parts: docs/recipes/55-mods-time-wrap.md §"The rules in full"
17
+ - Content: items, NPCs, places, packs; change an entry for good: docs/recipes/20-content-actions-save.md §1b
18
+ - Save game, load game, autosave, story flags, counters: docs/recipes/20-content-actions-save.md §4
19
+ - Preferences outside the save; turn off my effect: docs/recipes/26-ui-parts.md §6
20
+ - Timers, skip time; game time: rules, AI: docs/recipes/06-clock-events.md §1
21
+ - What shows: animation, camera, HUD (engine.stepBlend): docs/recipes/06-clock-events.md §1
22
+ - Picture per frame: docs/recipes/62-picture-code.md §0
23
+
24
+ ## Picture and sound
25
+
26
+ - The picture in three.js (picture/): lights, fog, exposure, parts: docs/recipes/62-picture-code.md §0, 34-environment-lighting.md
27
+ - Picture, writers; try a value: docs/recipes/52-around-the-picture.md §"Who writes it", 62-picture-code.md §3c
28
+ - Materials, textures, a module's picture: docs/recipes/09-materials-lights-models.md §1
29
+ - Own material or shader (toon, cel shading): docs/recipes/43-shader-patches-surfaces.md §"Your own material", 56-webgpu-tsl.md §"A minimal TSL material"
30
+ - WebGPU (new games' default), TSL node materials, WebGL fallback: docs/recipes/56-webgpu-tsl.md §"WebGPU or WebGL"
31
+ - three.js idioms, own renderer: docs/recipes/50-own-renderer.md
32
+ - Dust, smoke (lit: true): docs/recipes/64-particles.md
33
+ - Sky, season tints, weather, wet roads: docs/recipes/08-weather-sky.md §1
34
+ - Water, rain, snow cover (own rain: THREE.md): docs/recipes/44-water-weather-hooks.md
35
+ - Shadows: blur, follow, cost: docs/recipes/45-cascaded-shadows.md
36
+ - Own far, fov; clouds: docs/recipes/52-around-the-picture.md §"Atmosphere"
37
+ - Environment light, reflections, probes, lightmaps, GI, culling, shafts: docs/recipes/34-environment-lighting.md §"Environment maps"
38
+ - Post passes: color grading, bloom, outline, depth, AO: docs/recipes/52-around-the-picture.md §"Post effect chain", 59-depth-post-effects.md
39
+ - Many lights (torches); windows, signs at night: docs/recipes/09-materials-lights-models.md §1b
40
+ - Picture from a reference; judge: docs/recipes/35-picture-from-reference.md §"The loop", 60-judge-the-picture.md
41
+ - Reuse effects, models of old games: docs/recipes/05-props-bake.md
42
+ - Sound, music, ambience: docs/recipes/31-audio.md
43
+
44
+ ## Rules, state, time
45
+
46
+ - Items, chests, shops, gold; things to pick up: docs/recipes/03-items-pickups.md §"Items and pickups", 22-shop-gold.md
47
+ - Quests, objective markers: docs/recipes/04-quests.md §1
48
+ - What can the player do here, why not: docs/recipes/51-capability-catalog.md §1
49
+ - New game / continue, scene flow, fades, pause for a menu, cutscenes: docs/recipes/07-flow-scenes-pause.md §4
50
+ - Slow or speed up time, bullet time: docs/recipes/55-mods-time-wrap.md §"Time channels"
51
+ - Time of day, day / night, seasons: docs/recipes/08-weather-sky.md §4, 06-clock-events.md
52
+ - Multiplayer: docs/recipes/27-net.md §1
53
+
54
+ ## Characters, input, UI
55
+
56
+ - Third-person start (player walks, walking player, pause): docs/recipes/63-third-person-start.md §1
57
+ - Player, characters: docs/recipes/57-control.md §"Who takes what", 13-animation.md
58
+ - Keys, gamepad, rebinding, seats: docs/recipes/58-input.md §1
59
+ - Camera: followCamera (third person), first person, fixedCamera, rts; setCamera: docs/recipes/21-camera.md §1
60
+ - 2D, side-scroller, orthographic; 2D lights: docs/recipes/21-camera.md §6
61
+ - Pixel art: docs/recipes/62-picture-code.md §4b
62
+ - Skeletal animation, IK: docs/recipes/13-animation.md §3, 15-perf.md
63
+ - Pathfinding, navmesh, NPC jumps and gaps, gates: docs/recipes/12-navmesh.md §2
64
+ - Physics, ragdoll, collision, vehicles: docs/recipes/11-vehicles.md §3
65
+ - Ray / mouse picking, shooting, lock-on: docs/recipes/19-shooting-picking.md §1
66
+ - Prompts, trigger zones: docs/recipes/20-content-actions-save.md §3
67
+ - Press E on a mesh: docs/recipes/03-items-pickups.md
68
+ - Reskin UI: docs/recipes/26-ui-parts.md §"Reskin"
69
+ - Start at a place: docs/recipes/07-flow-scenes-pause.md §2
70
+ - NPC conversation: talk to an NPC, what NPCs do: docs/recipes/02-npc.md §1
71
+ - Speech bubble over a head, barks: docs/recipes/26-ui-parts.md §4
72
+ - UI, menus, HUD, languages, settings, photo mode: docs/recipes/26-ui-parts.md §1, 26-ui-parts.md §6
73
+ - Action game: hp, attacks, enemy AI, drops: docs/recipes/32-action-game.md §1
74
+ - Ambient occlusion, soft shadows: docs/recipes/52-around-the-picture.md
75
+ - Many bullets, debris: docs/recipes/65-swarm.md §"Which tool for many things"
76
+ - Enemy crowds, flocks: docs/recipes/65-swarm.md §"Which tool for many things"
77
+
78
+ ## Project, world, content
79
+
80
+ - New game, project layout, preset start: docs/recipes/01-new-game.md §0
81
+ - Put something in the scene: docs/recipes/40-scene.md §1
82
+ - Reusable objects (prefabs), groups of them: docs/recipes/30-templates.md §1
83
+ - Props, many repeated objects, static batching: docs/recipes/05-props-bake.md §2b
84
+ - What is this thing, does it persist: docs/recipes/30-templates.md §5, 40-scene.md §9
85
+ - Teleport the player, far-away and saved objects, streaming: docs/recipes/18-world.md §6, 33-stream-sources.md
86
+ - Blender level: docs/recipes/10-blender-level.md §1
87
+ - Grass, trees: docs/recipes/05-props-bake.md §2e, 36-ground-plants.md
88
+ - Terrain, height: docs/recipes/28-terrain.md §2
89
+ - Ground picture: docs/recipes/36-ground-plants.md §"Ground color", 53-ground-up-close.md
90
+ - Grid placement, plots, build on cells; a grid from a PNG: docs/recipes/29-grid.md §1, 28-terrain.md §9
91
+ - Assets, loading; code-made models; LOD; setup per model: docs/recipes/05-props-bake.md §3, 15-perf.md
92
+ - Blender -> GLB art; fixed views before / after: docs/recipes/46-blender-art-route.md §1, 05-props-bake.md §2f
93
+
94
+ ## Composing modules
95
+
96
+ - Replace a module (dialogue, camera): docs/recipes/55-mods-time-wrap.md §"Replacing a module"
97
+ - Your own module: type, requires, swap a part (provides + { replaces }): docs/recipes/14-custom-module.md §1, 49-game-module-contract.md
98
+ - Drop-in file per piece, no main.js: docs/recipes/40-scene.md
99
+
100
+ ## Advanced
101
+
102
+ - Own ground or plant drawing, keep collision: docs/recipes/28-terrain.md §6
103
+ - Worker results, far records' models, raw navmesh or physics, content sections, own mover: docs/recipes/15-perf.md, 18-world.md, 12-navmesh.md, 11-vehicles.md, 14-custom-module.md, 57-control.md
104
+
105
+ ## Troubleshooting and speed
106
+
107
+ - Broke; describe, explain, shot: which tool: docs/recipes/16-dev-bridge.md §11
108
+ - Picture looks wrong: judge it: docs/recipes/60-judge-the-picture.md §"How to judge"
109
+ - Drive and check the live game: docs/recipes/16-dev-bridge.md §1
110
+ - Slow, low fps: docs/recipes/15-perf.md §1
111
+ - Deploy: docs/recipes/61-deploy.md
112
+
12
113
  ## Recipes
13
114
 
14
115
  - [01-new-game](docs/recipes/01-new-game.md): Starting a new game
@@ -3,12 +3,15 @@
3
3
  // createEngine({ audio: {
4
4
  // sounds: { wind: {}, cave: 'caveDrip', crows: ['crow1', 'crow2'] }, // play rules; the sounds are asset names (files or synths)
5
5
  // ambience: [
6
- // { sound: 'wind', volume: e => 0.1 + (e.weather?.current.wind ?? 0) * 0.1 }, // a loop; volume may be a function of the moment
6
+ // { sound: 'wind', volume: e => 0.1 + (e.audio.value('wind') ?? 0) * 0.1 }, // a loop; volume may be a function of the moment
7
7
  // { sound: 'cave', when: { zone: 'cave' }, volume: 0.6, fade: 2 }, // condition keys: zone (triggers), time (calendar), weather, state
8
8
  // { sound: 'crows', when: { time: 'day' }, every: [4, 12] }, // every: a one-shot at random gaps instead of a loop
9
9
  // ] } });
10
10
  // The same rules as data in a content pack (audio: { ambience }): measures instead of functions, e.g.
11
11
  // { sound: 'rain', volume: { add: { rain: 0.22 } } }, { sound: 'birds', when: { daylight: { gt: 0.15 } }, every: [2, 7] }
12
+ // A rule may set the reverb instead of playing a sound: { reverb: 0.6, when: { zone: 'cave' }, fade: 2 } sets engine.audio.reverb's wet while it
13
+ // holds (the highest of those that hold; none: the game's own wet comes back). The same when / volume forms, so places stay data. The game still
14
+ // sets the room (engine.audio.reverb({ sends, decay, size })): a rule says how much echo here, not what the room is.
12
15
  // This module adds the measures nearWater (share of water within 12 m of the listener, 0-1) and altitude (ground height under it, 0 below sea level).
13
16
  // engine.use(ambience()); // openWorld() installs it
14
17
  //
@@ -24,7 +27,7 @@ import { codedError, coded } from '../../core/base/errorHints.js';
24
27
  import { warnOnce } from '../../core/base/validate.js';
25
28
  /** @import { ModuleDef, AmbienceRule } from '../../types/core' */
26
29
  /** @import { AmbienceOptions } from '../../types/gameplay' */
27
- const RULE_KEYS = ['sound', 'when', 'volume', 'fade', 'every', 'bus'];
30
+ const RULE_KEYS = ['sound', 'when', 'volume', 'fade', 'every', 'bus', 'reverb'];
28
31
  const gap = r => r.every[0] + Math.random() * (r.every[1] - r.every[0]); // presentation
29
32
 
30
33
  /** engine.ambience: the rule table of background sounds */
@@ -56,10 +59,14 @@ export class Ambience {
56
59
  */
57
60
  add(rule) {
58
61
  readParams('ambience rule', keysSchema(RULE_KEYS), rule);
59
- if (typeof rule.sound !== 'string') throw codedError('ambience-rule', `ambience rule needs sound: a name from audio.sounds, got ${JSON.stringify(rule.sound)}. Example: { sound: 'wind', volume: 0.3 }`, TypeError);
62
+ if (rule.reverb != null) {
63
+ const extra = ['sound', 'volume', 'every', 'bus'].filter(k => k in rule);
64
+ if (extra.length) throw codedError('ambience-rule', `ambience rule: a reverb rule sets the reverb's wet and plays no sound, so ${extra.join(' / ')} has no meaning on it. Two rules: { sound: 'drips', when, volume } and { reverb: 0.6, when }`, TypeError);
65
+ if (!this.engine.audio.reverbOn) warnOnce(coded('ambience-rule', "ambience: a reverb rule changes the reverb's wet, but engine.audio.reverb() was never called, so no bus sends into it and nothing echoes. Call engine.audio.reverb({ sends: { sfx: 0.5 } }) first"), 'ambience-reverb-off');
66
+ } else if (typeof rule.sound !== 'string') throw codedError('ambience-rule', `ambience rule needs sound: a name from audio.sounds, got ${JSON.stringify(rule.sound)}. Example: { sound: 'wind', volume: 0.3 }`, TypeError);
60
67
  const slot = { rule, voice: null, level: 0, offT: 0, next: rule.every ? gap(rule) : 0 };
61
68
  this._rules.push(slot);
62
- return { remove: () => { slot.voice?.stop({ fade: rule.fade ?? 1 }); this._rules = this._rules.filter(s => s !== slot); } };
69
+ return { remove: () => { slot.voice?.stop({ fade: rule.fade ?? 1 }); this._rules = this._rules.filter(s => s !== slot); if (rule.reverb != null) this._place(rule.fade ?? 1); } };
63
70
  }
64
71
  /**
65
72
  * Replace the whole rule table (null or [] = silence)
@@ -70,6 +77,7 @@ export class Ambience {
70
77
  for (const s of this._rules) s.voice?.stop({ fade: s.rule.fade ?? 1 });
71
78
  this._rules = [];
72
79
  for (const r of list || []) this.add(r);
80
+ this._place(1);
73
81
  return this;
74
82
  }
75
83
  /**
@@ -91,7 +99,7 @@ export class Ambience {
91
99
  * @returns {{ sound: string, on: boolean, volume: number }[]}
92
100
  * @internal a debug readout the engine tests read; games react to their own rules instead
93
101
  */
94
- get info() { return this._rules.map(s => ({ sound: s.rule.sound, on: s.level > 0, volume: +s.level.toFixed(3) })); }
102
+ get info() { return this._rules.map(s => ({ sound: s.rule.sound ?? 'reverb', on: s.rule.reverb != null ? !!s.on : s.level > 0, volume: +s.level.toFixed(3) })); }
95
103
 
96
104
  /**
97
105
  * Per-frame update: checks the rules every `interval` seconds and fades sounds toward their targets
@@ -106,6 +114,13 @@ export class Ambience {
106
114
  dt = this._acc; this._acc = 0;
107
115
  this._listen();
108
116
  for (const s of this._rules) this._step(s, dt);
117
+ this._place();
118
+ }
119
+ /** @internal The reverb wet the places ask for: the highest reverb rule that holds now, else null (the game's own wet); fade from that rule */
120
+ _place(fade) {
121
+ let best = null;
122
+ for (const s of this._rules) if (s.rule.reverb != null && s.on && (!best || s.level > best.level)) best = s;
123
+ this.engine.audio.reverbPlace(best ? Math.min(1, best.level) : null, fade ?? best?.rule.fade ?? 1);
109
124
  }
110
125
  /** @internal Refresh this.position from the listener (player, else the camera focus). The measures call it too: music rules read them while ambience may have no rules (then update() returns early and never moves the position) */
111
126
  _listen() { const p = this.engine.actorPosition() ?? this.engine.focus; return this.position.set(p.x, p.y ?? 0, p.z); }
@@ -113,6 +128,7 @@ export class Ambience {
113
128
  _step(s, dt) {
114
129
  const r = s.rule, a = this.engine.audio, fade = r.fade ?? 1;
115
130
  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
131
+ if (r.reverb != null) { s.on = a.matches(r.when, this); s.level = s.on ? Math.max(0, a.volumeOf(r.reverb, this)) : 0; return; } // a place's echo: _place picks
116
132
  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
133
  const on = a.matches(r.when, this);
118
134
  s.level = on ? Math.max(0, a.volumeOf(r.volume, this)) : 0;
@@ -13,7 +13,7 @@ import { saveValues, SAVE_MAX_SECONDS } from '../../core/base/saveValues.js';
13
13
 
14
14
  const CALENDAR_OPTIONS = ['time', 'dayLength', 'day', 'daysPerSeason', 'seasons', 'hoursPerDay'];
15
15
  const STRINGS = {
16
- skyTime: "calendar() installed after sky({ time }): the sky now draws the calendar's time, so sky({ time }) would be unused; start the day with calendar({ time }) and drop sky({ time })",
16
+ skyTime: 'calendar owns the time of day while it is installed, so sky({ time }) is unused. Move the starting time to calendar({ time }) and remove sky({ time })',
17
17
  };
18
18
  const CALENDAR_PARAMS = keysSchema(CALENDAR_OPTIONS); // keys only: time takes 'HH:MM' or 0-1, seasons names or { name, days }; Calendar checks them
19
19
 
@@ -29,7 +29,7 @@ export function calendar(opts = {}) {
29
29
  name: 'calendar', skipKind: 'exact', type: 'world', provides: ['calendar'], label: 'Calendar', params: CALENDAR_PARAMS, options: opts, stage: 'environment', before: ['sky'],
30
30
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.calendar': '日历' }, en: { 'module.calendar': 'calendar' } });
31
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)
32
- if (e.modules.get('sky')?.options?.time != null) warnOnce(coded('calendar-option', STRINGS.skyTime), 'sky-time-calendar');
32
+ if (e.modules.get('sky')?.options?.time != null) warnOnce(coded('time-owner-conflict', STRINGS.skyTime), 'sky-time-calendar');
33
33
  c = new Calendar(e, opts);
34
34
  // audio rule condition { time: 'day' | 'night' | ['18:00', '06:00'] } and measure { daylight: { gt: 0.15 } } for music / ambience rule lists:
35
35
  // from the clock, so an indoor game without a sky still switches its night music
@@ -37,11 +37,14 @@ export function calendar(opts = {}) {
37
37
  ctx.track(e.audio.measure('daylight', () => c.daylight));
38
38
  ctx.track(e.audio.measure('timeOfDay', () => c.timeOfDay)); // render/daylight.js writes uTimeOfDay from it
39
39
  // between() ranges re-check whether they are inside after anything that moves the clock without stepping
40
- ctx.track(e.events.on('state:replaced', () => c._sched.syncRanges()));
40
+ c._sched.rebase(); // a calendar installed after start: its first step already counts the marks it crosses
41
+ // before the first step every write to the clock (setup, engine:ready, the first state door, applyState below) is a set, not elapsed time: re-base so only time that elapses fires alarms.
42
+ // After a load a cleared baseline is the restored time (a plain applyState later keeps it, so a forward jump still replays)
43
+ ctx.track(e.events.on('state:replaced', () => { c._sched.syncRanges(); if (!c._sched.ticks || c._sched.last == null) c._sched.rebase(); }));
41
44
  // 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)
42
45
  ctx.track(e.time.onMove(() => c.moved()));
43
46
  // at: the calendar channel second the time and day belong to, so the origin is right whichever part (calendar or time) loads first
44
- ctx.saves.register('calendar', { notAtomic: 'the clock moves it every step, and an op that sets the time means it to stay', save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
47
+ ctx.saves.define('calendar', { notAtomic: 'the clock moves it every step, and an op that sets the time means it to stay', save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
45
48
  // 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
49
  load: d => {
47
50
  if (d) {
@@ -53,7 +56,7 @@ export function calendar(opts = {}) {
53
56
  c._day0 = day; c._tod0 = tod; c._t0 = at; c._lastDay = c.day;
54
57
  c._season = c.season;
55
58
  }
56
- c._sched.rebase();
59
+ c._sched.last = null; // the baseline is set by state:replaced, once every part is restored
57
60
  } });
58
61
  return c;
59
62
  },
@@ -73,6 +76,7 @@ export function calendar(opts = {}) {
73
76
  "seasons are off by default: calendar({ seasons: ['spring', 'summer', 'autumn', 'winter'] })");
74
77
  c.day = (i ? c._ends[i - 1] : 0) + 1; c._season = c.season; // writing day fires no day:start
75
78
  }
79
+ if (!c._sched.ticks) c._sched.rebase(); // ?time=07:59&wait=5 before any step: the jump is a set, but the wait that follows is elapsed time and fires its alarms
76
80
  },
77
81
  describe(e, ctx) {
78
82
  Object.assign(ctx.out.time ??= {}, { clock: c.clock, day: c.day, season: c.season, isDay: c.isDay, timeOfDay: Math.round(c.timeOfDay * 1000) / 1000,
@@ -20,15 +20,21 @@ export class Schedule {
20
20
  this.points = []; // at / daily:{ clock, fn, days, catchUp }
21
21
  this.ranges = []; // between:{ from, to, on, off, inside }
22
22
  this.last = null; // last calendar.totalDays (null = reset baseline next step)
23
+ this.ticks = 0; // steps seen: before the first, every state write (setup, engine:ready, URL params) is a set, not elapsed time
24
+ this.seasons = new Set(); // onSeason handles on the global bus: this schedule made them, so dispose frees them
23
25
  }
24
26
  get size() { return this.points.length + this.ranges.length; }
25
- dispose() { this.points = []; this.ranges = []; }
27
+ dispose() {
28
+ for (const x of [...this.points, ...this.ranges]) x.dead = true;
29
+ this.points = []; this.ranges = [];
30
+ for (const h of [...this.seasons]) h.remove();
31
+ }
26
32
  at(clock, fn, opts) {
27
33
  const { days = null, catchUp = 'once' } = readParams('calendar.at()', keysSchema(AT_KEYS), opts);
28
34
  parseClock(clock); // a wrong clock time throws here, at the call, not later inside every step
29
35
  const p = { clock, fn, days, catchUp };
30
36
  this.points.push(p);
31
- return { remove: () => { this.points = this.points.filter(x => x !== p); } };
37
+ return { remove: () => { p.dead = true; this.points = this.points.filter(x => x !== p); } };
32
38
  }
33
39
  between(from, to, opts) {
34
40
  const { on, off } = readParams('calendar.between()', keysSchema(BETWEEN_KEYS), opts);
@@ -36,14 +42,20 @@ export class Schedule {
36
42
  const r = { from, to, on, off, inside: null };
37
43
  this.ranges.push(r);
38
44
  this.syncRanges();
39
- return { remove: () => { this.ranges = this.ranges.filter(x => x !== r); } };
45
+ return { remove: () => { r.dead = true; this.ranges = this.ranges.filter(x => x !== r); } };
40
46
  }
41
47
  /** A callback that throws is a gameplay error (errors.js), like clock timers; the other timers still run */
42
48
  _call(fn, arg) { try { fn(arg); } catch (err) { reportError(this.cal.engine, err, 'calendar timer'); } }
43
- onSeason(name, fn) { return this.cal.engine.events.on('season:change', s => { if (s === name) fn(s); }); }
49
+ onSeason(name, fn) {
50
+ const h = this.cal.engine.events.on('season:change', s => { if (s === name) fn(s); }), remove = h.remove.bind(h);
51
+ const mine = { ...h, remove: () => { this.seasons.delete(mine); remove(); } };
52
+ this.seasons.add(mine);
53
+ return mine;
54
+ }
44
55
  syncRanges() {
45
56
  const t = this.cal.timeOfDay, hpd = this.cal.hoursPerDay;
46
- for (const r of this.ranges) {
57
+ for (const r of [...this.ranges]) {
58
+ if (r.dead) continue; // an earlier callback of this pass removed it
47
59
  const inside = inFrac(t, frac(r, 'from', hpd), frac(r, 'to', hpd));
48
60
  if (inside === r.inside) continue;
49
61
  r.inside = inside;
@@ -61,22 +73,25 @@ export class Schedule {
61
73
  for (const r of this.ranges) { near(frac(r, 'from', hpd)); near(frac(r, 'to', hpd)); }
62
74
  return m;
63
75
  }
64
- /** After loading a save the next step only resets the baseline, no replay */
65
- rebase() { this.last = null; }
76
+ /** The baseline is now: a step from here on counts the marks it crosses. Called at install; after a load (which only clears it: the clock part may not be
77
+ * restored yet) state:replaced sets it, index.js */
78
+ rebase() { this.last = this.cal.totalDays; }
66
79
  /** Called right after the calendar channel moves (a step or a skip segment) */
67
80
  tick() {
68
81
  const cal = this.cal;
69
82
  if (this.ranges.length) this.syncRanges();
83
+ this.ticks++;
70
84
  const cur = cal.totalDays, last = this.last;
71
85
  this.last = cur;
72
86
  if (last == null || cur <= last) return; // just loaded or time rewound: only reset the baseline
73
87
  for (const p of [...this.points]) {
88
+ if (p.dead) continue; // removed by a callback earlier in this pass
74
89
  const f = frac(p, 'clock', cal.hoursPerDay);
75
90
  const first = Math.floor(last - f) + 1, end = Math.floor(cur - f); // triggers crossed: days first..end (0-based)
76
91
  if (end < first) continue;
77
92
  const n = end - first + 1;
78
93
  if (p.catchUp === 'skip' && n > 1) continue;
79
- for (let d = p.catchUp === 'all' ? first : end; d <= end; d++) {
94
+ for (let d = p.catchUp === 'all' ? first : end; d <= end && !p.dead; d++) {
80
95
  const day = d + 1;
81
96
  if (p.days && !(typeof p.days === 'function' ? p.days(day) : p.days.includes(day))) continue;
82
97
  this._call(p.fn, day);
@@ -10,7 +10,7 @@
10
10
  // engine.cameraRig.lookAt(position); // turn toward a point (Vector3 / object / [x, y, z])
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
- import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
13
+ import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock, inRange } from './common.js';
14
14
  import { vec3 } from '../../core/base/math.js';
15
15
  import { setFov } from '../../core/scene/view.js';
16
16
 
@@ -24,6 +24,7 @@ export class FirstPersonCamera {
24
24
  constructor(engine, { height = 1.6, sensitivity = 1, fov = null, headBob = 0.04, bobFrequency = 0.9, hideTarget = true, hideLayer = 30,
25
25
  pointerLock = true, yaw = 0, pitch = 0, minPitch = -1.45, maxPitch = 1.45, yawLimits = null, smoothing = 30, invertY = false, swallowLockClick = true } = {}) {
26
26
  Object.assign(this, { swallowLockClick, engine, height, sensitivity, headBob, bobFrequency, hideTarget, hideLayer, pointerLock, yaw, pitch, minPitch, maxPitch, yawLimits, smoothing, invertY });
27
+ inRange(this, 'firstPersonCamera', 'firstPersonCamera()', 'pitch', pitch, ['minPitch', 'maxPitch']); // update keeps pitch in range from the first frame
27
28
  this.target = null;
28
29
  this.eye = new THREE.Vector3();
29
30
  this._bob = 0; this._bobAmp = 0; this._last = null; this._hidden = [];
@@ -98,6 +99,7 @@ export class FirstPersonCamera {
98
99
  cam.position.copy(this.eye);
99
100
  cam.position.y += Math.sin(this._bob) * this._bobAmp;
100
101
  cam.rotation.set(this.pitch, this.yaw, Math.sin(this._bob * 0.5) * this._bobAmp * 0.15, 'YXZ');
102
+ this._carriedLights(); // a lamp the player carries is not shadowed by the hidden body (common.js HIDE_RIG)
101
103
  }
102
104
 
103
105
  /** Someone else's view shows while the camera is held: the mouse goes free and the body is back, since the eye it would block is no longer where the camera is */
@@ -10,7 +10,7 @@
10
10
  // Close-up: when the camera ends up nearer than hideTargetNear to the look point (wall, ground), the followed object is hidden from the camera (shadow stays).
11
11
  // Other cameras: firstPersonCamera, fixedCamera, rtsCamera (top-down strategy); all are engine.cameraRig; switch at runtime with engine.setCamera('firstPerson').
12
12
  import * as THREE from 'three';
13
- import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock } from './common.js';
13
+ import { rigModule, defineRig, YAW_RIG, HIDE_RIG, clickToLock, releaseLock, inRange } from './common.js';
14
14
  import { setProjection } from '../../core/scene/view.js';
15
15
  import { rigPixelSnap, checkPixelView } from './pixelSnap.js';
16
16
  import { codedError } from '../../core/base/errorHints.js';
@@ -20,6 +20,7 @@ const GROUND = ['raise', 'shorten', 'none'];
20
20
  // ground: 'shorten' sampling. 0.2 m: narrower than this the ground height rarely has a feature that blocks the view (posts and walls are colliders,
21
21
  // handled by the occlusion pull-in). 160 samples (one surface() each, every frame) keep full spacing up to a 32 m arm.
22
22
  const SHORTEN_STEP = 0.2, SHORTEN_MAX = 160;
23
+ const DISTANCE = ['minDistance', 'maxDistance'], PITCH = ['minPitch', 'maxPitch'];
23
24
 
24
25
  export class FollowCamera {
25
26
  /** yaw/pitch initial angles (yaw: see the top of this file); distance (min/max zoom range); height how high on the character to look; smoothing follow smoothness;
@@ -41,6 +42,8 @@ export class FollowCamera {
41
42
  this.size0 = size; this.distance0 = distance;
42
43
  Object.assign(this, { engine, yaw, pitch, distance, minDistance, maxDistance, height, smoothing, sensitivity, minPitch, maxPitch, zoomStep, groundClearance });
43
44
  Object.assign(this, { invertY, shoulder, pointerLock, swallowLockClick, ground, mouseLook, hideTargetNear, hideLayer });
45
+ // a start outside the range stays as given (the first wheel notch or drag pulls it in), and says so
46
+ inRange(this, 'followCamera', 'followCamera()', 'distance', distance, DISTANCE, true); inRange(this, 'followCamera', 'followCamera()', 'pitch', pitch, PITCH, true);
44
47
  this._hidden = [];
45
48
  /** Arm length used last frame (after walls and ground), meters */
46
49
  this.arm = distance;
@@ -53,7 +56,7 @@ export class FollowCamera {
53
56
  follow(obj, opts) {
54
57
  this._unhide();
55
58
  if (this._saved) { Object.assign(this, this._saved); this._saved = null; }
56
- if (opts) { this._saved = { distance: this.distance, height: this.height }; if (opts.distance != null) this.distance = opts.distance; if (opts.height != null) this.height = opts.height; }
59
+ if (opts) { this._saved = { distance: this.distance, height: this.height }; if (opts.distance != null) this.distance = inRange(this, 'followCamera', 'cameraRig.follow(obj, { distance })', 'distance', opts.distance, DISTANCE, true); if (opts.height != null) this.height = opts.height; }
57
60
  this.target = obj; if (obj) this.focus.copy(obj.position);
58
61
  }
59
62
 
@@ -64,14 +67,15 @@ export class FollowCamera {
64
67
  */
65
68
  frame(target, { strength = 6 } = {}) { this.framing = target ? { target, strength } : null; }
66
69
  /**
67
- * Set the view from game code (scripted look, your own input scheme): any of yaw / pitch (clamped to minPitch..maxPitch) / distance (clamped to the zoom range).
70
+ * Set the view from game code (scripted look, your own input scheme): any of yaw / pitch (clamped to minPitch..maxPitch) / distance (clamped to the zoom range;
71
+ * a value past the range warns once in dev, naming the option to widen).
68
72
  * Pair with mouseLook: false to own the view every frame. Returns the rig
69
73
  * @example engine.cameraRig.setView({ pitch: -0.6 }) // look up (negative pitch = camera below the look point)
70
74
  */
71
75
  setView({ yaw, pitch, distance } = {}) {
72
76
  if (yaw != null) this.yaw = yaw;
73
- if (pitch != null) this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, pitch));
74
- if (distance != null) this.distance = Math.min(this.maxDistance, Math.max(this.minDistance, distance));
77
+ if (pitch != null) this.pitch = inRange(this, 'followCamera', 'cameraRig.setView()', 'pitch', pitch, PITCH);
78
+ if (distance != null) this.distance = inRange(this, 'followCamera', 'cameraRig.setView()', 'distance', distance, DISTANCE);
75
79
  return this;
76
80
  }
77
81
  /** The current view: yaw, pitch, distance (wanted), arm (actual after walls / ground, m), lookPoint and look (unit 3D view direction of the camera) */
@@ -131,6 +135,7 @@ export class FollowCamera {
131
135
  }
132
136
  this.arm = cam.position.distanceTo(pivot);
133
137
  if (this.hideTargetNear > 0 && this.arm < this.hideTargetNear) this._hide(); else this._unhide();
138
+ this._carriedLights(); // close-up hides the body too: a torch in hand is then not shadowed by it (common.js HIDE_RIG)
134
139
  cam.lookAt(fx, fy, fz);
135
140
  }
136
141
 
@@ -11,7 +11,7 @@
11
11
  // const p = engine.cameraRig.screenToGround(engine.input.pointer.ndcX, engine.input.pointer.ndcY);
12
12
  // engine.cameraRig.moveTo(position); // move the view somewhere; { instant: true } skips smoothing
13
13
  import * as THREE from 'three';
14
- import { rigModule, defineRig, CAMERA_STRINGS, YAW_RIG, rigPlaced } from './common.js';
14
+ import { rigModule, defineRig, CAMERA_STRINGS, YAW_RIG, rigPlaced, inRange } from './common.js';
15
15
  import { xzOf } from '../../core/base/math.js';
16
16
  import { setFov } from '../../core/scene/view.js';
17
17
  import { surfaceOr } from '../../core/scene/ground.js';
@@ -28,6 +28,7 @@ export class RtsCamera {
28
28
  bounds = null, rotate = true, rotateSpeed = 1.8, zoomStep = 0.12, smoothing = 10, fov = null,
29
29
  followLock = false, start = null } = {}) {
30
30
  Object.assign(this, { engine, height, minHeight, maxHeight, pitch, yaw, panSpeed, dragPan, edgePan, edgeSize, bounds, rotateSpeed, zoomStep, smoothing, followLock });
31
+ inRange(this, 'rtsCamera', 'rtsCamera()', 'height', height, ['minHeight', 'maxHeight'], true); // a start outside the zoom range stays; the first wheel notch pulls it in
31
32
  this.target = null;
32
33
  this.following = false;
33
34
  const [sx, sz] = start ? xzOf(start) : [0, 0];
@@ -126,8 +127,8 @@ defineRig('rts', (e, opts, input) => {
126
127
  e.i18n.add(CAMERA_STRINGS);
127
128
  // declared through the camera module's ctx (gone with the module); optional: the camera pans and zooms without them
128
129
  if (opts.rotate !== false) {
129
- input.action('rotateLeft', { label: 'camera.rotateLeft', optional: true });
130
- input.action('rotateRight', { label: 'camera.rotateRight', optional: true });
130
+ input.define('rotateLeft', { label: 'camera.rotateLeft', optional: true });
131
+ input.define('rotateRight', { label: 'camera.rotateRight', optional: true });
131
132
  }
132
133
  return new RtsCamera(e, opts);
133
134
  }, ['height', 'minHeight', 'maxHeight', 'pitch', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotate',