threedog 0.7.0 → 1.0.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 (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  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} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  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} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /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,8 @@
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
+ import { CAP_CONTRACTS } from './core/engine/moduleSlots.js';
17
18
  import { terrain } from './modules/terrain/index.js';
18
19
  import { vegetation } from './modules/vegetation/index.js';
19
20
  import { sky } from './modules/sky/skyModule.js';
@@ -35,6 +36,7 @@ import { debug } from './modules/debug/DebugPanel.js';
35
36
  import { level } from './modules/level/index.js';
36
37
  import { triggers } from './modules/triggers/index.js';
37
38
  import { particles } from './modules/particles/Particles.js';
39
+ import { swarm } from './modules/swarm/Swarm.js';
38
40
  import { settings } from './modules/settings/index.js';
39
41
  import { music } from './modules/music/index.js';
40
42
  import { firstPersonCamera, fixedCamera, rtsCamera } from './modules/camera/index.js';
@@ -47,38 +49,66 @@ import { flow } from './modules/flow/index.js';
47
49
  import { hud } from './modules/hud/index.js';
48
50
  import { world } from './modules/world/index.js';
49
51
  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';
52
+ import calendarContract from './modules/calendar/contract.js';
53
+ import cameraContract from './modules/camera/contract.js';
54
+ import charactersContract from './modules/characters/contract.js';
55
+ import collisionContract from './modules/collision/contract.js';
56
+ import flowContract from './modules/flow/contract.js';
57
+ import dialogueContract from './modules/gameplay/dialogue.contract.js';
58
+ import interactionsContract from './modules/gameplay/interactions.contract.js';
59
+ import inventoryContract from './modules/gameplay/inventory.contract.js';
60
+ import questsContract from './modules/gameplay/quests.contract.js';
61
+ import levelContract from './modules/level/contract.js';
62
+ import navContract from './modules/nav/contract.js';
63
+ import particlesContract from './modules/particles/contract.js';
64
+ import collider3dContract from './modules/rigid/collider3d.contract.js';
65
+ import { checkOptions, DEV, fmt } from './core/base/validate.js';
66
+ import { readParams, keysSchema } from './core/base/params.js';
67
+ import { codedError } from './core/base/errorHints.js';
68
+
69
+ // The contract of each capability, so a provider is checked where it binds even when the engine's own module of that name was never installed. Here and not in core: core imports
70
+ // no module. Plain data, a few KB; a build cannot drop it behind DEV (only the literal import.meta.env test folds). tools/tests/contracts.mjs fails on a contract left out.
71
+ for (const c of [calendarContract, cameraContract, charactersContract, collisionContract, flowContract, dialogueContract, interactionsContract, inventoryContract, questsContract,
72
+ levelContract, navContract, particlesContract, collider3dContract]) CAP_CONTRACTS.set(c.name, c);
53
73
 
54
74
  // Engine and Animator are exported for types and instanceof; make them with createEngine / engine.assets.animate (AI.md entry-point table)
55
75
  export { THREE, Engine };
56
- export { Animator } from './core/Animator.js';
76
+ export { Animator } from './core/assets/Animator.js';
57
77
  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 };
78
+ level, triggers, particles, swarm, settings, music, firstPersonCamera, fixedCamera, rtsCamera, timeline, nav, hlod, lightPool, content, flow, hud, world, grids };
59
79
  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)
80
+ export { screenToGround } from './core/scene/screenToGround.js';
81
+ export { ease } from './core/base/easing.js';
82
+ 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
83
  export { checkOptions }; // only for extensible data (game-defined fields); an options bag goes through readParams
64
84
  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
85
+ export { threePatches } from './core/scene/threePatches.js'; // the engine's page-wide changes to three.js classes: list(), off(id) (THREE.md "Global changes")
86
+ export { readParams } from './core/base/params.js'; // params schema for game-made modules (recipes/14): validated, defaults filled, shown by engine.catalog()
87
+ export { compositeGround } from './core/scene/compositeGround.js'; // several ground providers (terrain({ part: true }), level({ part: true })) answering by region; holds the 'ground' slot
67
88
  export { createTerrain } from './modules/terrain/index.js';
68
89
  export { Character, NPC } from './modules/characters/index.js';
69
90
  export { presets } from './presets.js'; // opt-in gameplay presets (weather tables, calendars, player feel, camera): never applied by the engine itself
70
91
  export { terrainMaterial, mergeColored, applyEffects } from './render/materials.js';
71
92
  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)
93
+ export { bakeVertexAO } from './render/modeling.js'; // procedural-modeling gaps three.js lacks (THREE.md lists what three already has)
73
94
  export { materialPatches } from './render/patches.js';
74
95
  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';
96
+ export { parseClock, formatClock, inRange } from './core/time/dayTime.js';
97
+ export { pickTarget, switchTarget } from './core/scene/targeting.js';
98
+ export { PICTURE_SLOTS } from './core/scene/pictureSlots.js';
78
99
 
79
- /** Create an engine (core only). For the options see core/Engine.js */
100
+ /** Create an engine (core only). For the options see core/engine/Engine.js */
80
101
  export function createEngine(opts) { return new Engine(opts); }
81
102
 
103
+ const CAMERAS = { follow: followCamera, firstPerson: firstPersonCamera, rts: rtsCamera, fixed: fixedCamera };
104
+ const OPEN_WORLD_PARTS = { world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug };
105
+ const OPEN_WORLD_SHORT = ['seed', 'viewChunks', 'density', 'flatten', 'time', 'dayLength', 'autoWeather', 'camera'];
106
+ const OW_ERR = { camera: 'openWorld(): camera has no kind \'{k}\'; available: {list}, or pass a camera module (e.g. rtsCamera({ height: 60 })) or false',
107
+ 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)",
108
+ part: 'openWorld(): {k} must be false (leave it out), true or an options object, e.g. openWorld({ {k}: false }); got {got}',
109
+ noOpts: 'openWorld(): {k} takes no options, only true / false; got {got}. {hint}' };
110
+ // 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
111
+ 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
112
  /**
83
113
  * Open-world preset: covers only "world and environment" plus the basics every game needs:
84
114
  * world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, camera, characters, ambience, settings, debug (debug only in dev builds).
@@ -86,7 +116,7 @@ export function createEngine(opts) { return new Engine(opts); }
86
116
  * engine.use(openWorld({ seed: 7, camera: 'follow' }), interactions({ ...presets.interactions.nearest }), dialogue(), inventory(), quests()); // keys: createEngine({ bindings: { ...presets.bindings.interact, ...presets.bindings.inventory } })
87
117
  * 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
118
  * 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).
119
+ * 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
120
  * Shorthands still work and go to their module: seed / viewChunks / density / flatten → terrain, time / dayLength → calendar,
91
121
  * weather: 'rain' (starting weather) and autoWeather → weather. An object for the same module wins over the shorthand.
92
122
  * 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 +125,21 @@ export function createEngine(opts) { return new Engine(opts); }
95
125
  * Switch at runtime: engine.setCamera('firstPerson') (see recipes/21-camera.md).
96
126
  * @param {{ camera: 'follow' | 'firstPerson' | 'rts' | 'fixed' | false | import('./types/core').ModuleDef, [k: string]: any }} opts
97
127
  */
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
128
  export function openWorld(opts = {}) {
108
129
  readParams('openWorld()', keysSchema([...OPEN_WORLD_SHORT, ...Object.keys(OPEN_WORLD_PARTS)]), opts);
109
130
  const { seed, viewChunks, density, flatten = [], time, dayLength, autoWeather = false, camera } = opts;
110
131
  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(', ')));
132
+ if (typeof camera === 'string' && !CAMERAS[camera]) throw codedError('preset-option', fmt(OW_ERR.camera, { k: camera, list: Object.keys(CAMERAS).join(', ') }));
112
133
  const w = opts.weather;
113
- 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
134
+ // characters: a walking game's preset chooses to bring what falls back; the engine alone never does. openWorld({ characters: { fall: false } }) leaves it to the game
135
+ const short = { terrain: { seed, viewChunks, density, flatten, viewFog: true }, calendar: { time, dayLength }, weather: { start: typeof w === 'string' ? w : undefined, auto: autoWeather }, characters: { fall: 'rescue' } }; // no start: weather() picks one from the game's table
114
136
  const part = k => {
115
137
  const v = opts[k];
116
138
  if (v === false || (k === 'debug' && v === undefined && !DEV)) return null;
117
139
  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)));
140
+ throw codedError('preset-option', fmt(OW_ERR.part, { k, got: String(JSON.stringify(v)) }));
119
141
  }
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]));
142
+ 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
143
  return OPEN_WORLD_PARTS[k]({ ...short[k], ...(typeof v === 'object' ? v : null) });
123
144
  };
124
145
  const cam = camera === false ? null : typeof camera === 'string' ? CAMERAS[camera]() : camera;
package/llms.txt CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > A web 3D game engine on three.js 0.187 (plain three.js, no React): core and modules installed with engine.use. It ships no art: each game draws its own picture (plain three.js in its picture/ folder, and assets).
4
4
 
5
- Reading order: docs/AI.md (the index: one line per task) -> the recipe for the task -> docs/api/<module>.md for details -> the game's GAMEMAP.md.
5
+ Taking over a game: its status notes first. A new feature: docs/AI.md or threedog how, then the recipe, then docs/api/<module>.md.
6
6
 
7
7
  ## Start
8
8
 
@@ -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,5 @@ 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
68
+ - [66-common-tasks](docs/recipes/66-common-tasks.md): Common tasks, complete
@@ -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'];
@@ -82,7 +82,7 @@ export class Ambience {
82
82
  const e = this.engine, p = this.position; let n = 0;
83
83
  for (let ang = 0; ang < 6.28; ang += 1.05) {
84
84
  const x = p.x + Math.cos(ang) * radius, z = p.z + Math.sin(ang) * radius;
85
- if (e.surface(x, z) < e.waterAt(x, z)) n += 1 / 6;
85
+ if (e.surface(x, z, p.y) < e.waterAt(x, z, p.y)) n += 1 / 6;
86
86
  }
87
87
  return n;
88
88
  }
@@ -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
  }
@@ -177,7 +177,7 @@ const AMBIENCE_PARAMS = keysSchema(['rules', 'interval']);
177
177
  export function ambience(opts = {}) {
178
178
  readParams('ambience', AMBIENCE_PARAMS, opts);
179
179
  let a = null;
180
- return { name: 'ambience', type: 'picture', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late',
180
+ return { name: 'ambience', skipKind: 'none', type: 'picture', params: AMBIENCE_PARAMS, options: opts, label: 'Ambience', stage: 'late',
181
181
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.ambience': '环境音' }, en: { 'module.ambience': 'ambience' } });
182
182
  builtInSounds(e.assets, SYNTHS, { bus: 'ambience' }); // sound assets wind / rain / water / birds / crickets, silent until audio.sounds names them
183
183
  a = new Ambience(e, opts);
@@ -185,13 +185,18 @@ export function ambience(opts = {}) {
185
185
  // measures for data rules (content packs hold no functions). Each reads the listener position itself: music rules call them too,
186
186
  // and ambience refreshes this.position only while it has rules of its own
187
187
  ctx.track(e.audio.measure('nearWater', () => { a._listen(); return a.nearWater(12); }));
188
- ctx.track(e.audio.measure('altitude', () => { const p = a._listen(); return Math.max(0, e.surface(p.x, p.z)); }));
188
+ ctx.track(e.audio.measure('altitude', () => { const p = a._listen(); return Math.max(0, e.surface(p.x, p.z, p.y)); }));
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
  }
201
+
202
+ export const handRolled = 'none: sounds by place are data, and a hand-made version has no one shape in code';
@@ -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, SAVE_MAX_SECONDS } from '../../core/base/saveValues.js';
10
11
  /** @import { ModuleDef } from '../../types/core' */
11
12
  /** @import { CalendarOptions } from '../../types/world' */
12
13
 
@@ -25,10 +26,10 @@ export function calendar(opts = {}) {
25
26
  readParams('calendar', CALENDAR_PARAMS, opts);
26
27
  let c = null;
27
28
  return {
28
- name: 'calendar', type: 'world', provides: ['calendar'], label: 'Calendar', params: CALENDAR_PARAMS, options: opts, stage: 'environment', before: ['sky'],
29
+ name: 'calendar', skipKind: 'exact', 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
@@ -36,35 +37,34 @@ export function calendar(opts = {}) {
36
37
  ctx.track(e.audio.measure('daylight', () => c.daylight));
37
38
  ctx.track(e.audio.measure('timeOfDay', () => c.timeOfDay)); // render/daylight.js writes uTimeOfDay from it
38
39
  // between() ranges re-check whether they are inside after anything that moves the clock without stepping
39
- for (const name of ['engine:ready', 'save:loaded', 'state:applied']) ctx.track(e.events.on(name, () => c._sched.syncRanges()));
40
+ ctx.track(e.events.on('state:replaced', () => 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
- e.saves.register('calendar', { save: () => ({ time: c.timeOfDay, day: c.day, at: e.clock.now }),
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 }),
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, max: SAVE_MAX_SECONDS, 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) {
@@ -80,3 +80,5 @@ export function calendar(opts = {}) {
80
80
  },
81
81
  };
82
82
  }
83
+
84
+ export const handRolled = 'none: a day counter of its own is a plain number that looks like any other';
@@ -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
  };