threedog 0.8.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 (372) hide show
  1. package/CHANGELOG.md +219 -4
  2. package/README.md +6 -6
  3. package/core/assets/Animator.js +2 -0
  4. package/core/assets/Assets.js +44 -13
  5. package/core/assets/assetEntry.js +87 -22
  6. package/core/assets/assetHot.js +2 -1
  7. package/core/assets/assetReport.js +1 -2
  8. package/core/audio/Audio.js +24 -5
  9. package/core/base/I18n.js +6 -3
  10. package/core/base/Random.js +3 -1
  11. package/core/base/Vars.js +14 -4
  12. package/core/base/errorCodes.js +54 -16
  13. package/core/base/errorHints.js +12 -1
  14. package/core/base/errors.js +6 -4
  15. package/core/base/events.generated.js +10 -0
  16. package/core/base/follows.js +26 -0
  17. package/core/base/math.js +15 -8
  18. package/core/base/params.js +2 -2
  19. package/core/{saves → base}/saveValues.js +24 -6
  20. package/core/base/sections.js +97 -0
  21. package/core/base/spelling.js +32 -0
  22. package/core/base/validate.js +8 -29
  23. package/core/engine/Engine.js +61 -18
  24. package/core/engine/Loading.js +30 -3
  25. package/core/engine/copies.js +1 -1
  26. package/core/engine/headlessLoad.js +30 -13
  27. package/core/engine/lifecycle.js +30 -25
  28. package/core/engine/loop.js +22 -4
  29. package/core/engine/moduleSlots.js +91 -15
  30. package/core/engine/moduleTypes.js +13 -0
  31. package/core/engine/modules.js +248 -62
  32. package/core/engine/page.js +25 -8
  33. package/core/engine/plugins.js +15 -3
  34. package/core/engine/services.js +3 -0
  35. package/core/engine/startup.js +46 -36
  36. package/core/input/Input.js +39 -19
  37. package/core/input/inputKeyboard.js +39 -0
  38. package/core/input/inputPad.js +23 -2
  39. package/core/input/inputPointer.js +3 -1
  40. package/core/input/inputSeat.js +66 -0
  41. package/core/input/inputTouch.js +23 -6
  42. package/core/inspect/DebugOverrides.js +13 -2
  43. package/core/inspect/Describe.js +10 -6
  44. package/core/inspect/Inspect.js +31 -4
  45. package/core/inspect/UrlState.js +14 -10
  46. package/core/inspect/catalog.js +12 -5
  47. package/core/inspect/describeRender.js +3 -2
  48. package/core/inspect/describeText.js +6 -2
  49. package/core/inspect/metadata.generated.js +4140 -0
  50. package/core/inspect/pictureWriters.js +117 -33
  51. package/core/inspect/toolDoor.js +21 -0
  52. package/core/inspect/valueHistory.js +35 -0
  53. package/core/ops/Ops.js +32 -7
  54. package/core/ops/control.js +48 -23
  55. package/core/ops/holds.js +4 -3
  56. package/core/ops/opsAtomic.js +18 -6
  57. package/core/ops/opsCheck.js +7 -5
  58. package/core/ops/opsFail.js +5 -7
  59. package/core/ops/opsRun.js +2 -2
  60. package/core/ops/owned.js +20 -3
  61. package/core/ops/sharedPoint.js +7 -10
  62. package/core/ops/stacks.js +22 -1
  63. package/core/saves/SaveStore.js +52 -26
  64. package/core/saves/Saves.js +122 -27
  65. package/core/saves/saveApply.js +159 -61
  66. package/core/saves/saveFiles.js +30 -25
  67. package/core/saves/saveVersions.js +20 -6
  68. package/core/saves/session.js +76 -33
  69. package/core/saves/stateReplace.js +184 -0
  70. package/core/scene/Rays.js +21 -5
  71. package/core/scene/Views.js +6 -6
  72. package/core/scene/adaptive.js +13 -10
  73. package/core/scene/canvasBox.js +2 -0
  74. package/core/scene/compositeGround.js +72 -0
  75. package/core/scene/floor.js +17 -0
  76. package/core/scene/grid.js +2 -0
  77. package/core/scene/ground.contract.js +14 -0
  78. package/core/scene/ground.js +52 -17
  79. package/core/scene/pixel.js +154 -0
  80. package/core/scene/pixelRatio.js +167 -0
  81. package/core/scene/sceneDelta.js +3 -3
  82. package/core/scene/sceneMethods.js +11 -6
  83. package/core/scene/stepPoses.js +6 -1
  84. package/core/scene/thingExplain.js +1 -1
  85. package/core/scene/thingOps.js +22 -14
  86. package/core/scene/things.js +1 -1
  87. package/core/scene/tier.js +10 -0
  88. package/core/scene/view.js +126 -9
  89. package/core/stream/Batching.js +0 -1
  90. package/core/stream/Stream.js +24 -12
  91. package/core/stream/batchGroups.js +1 -0
  92. package/core/stream/scatter.js +5 -2
  93. package/core/stream/streamSources.js +2 -1
  94. package/core/threads/Commits.js +12 -7
  95. package/core/threads/Jobs.js +15 -5
  96. package/core/threads/Threads.js +5 -2
  97. package/core/time/Clock.js +3 -1
  98. package/core/time/skip.js +10 -4
  99. package/core/time/time.js +16 -10
  100. package/docs/AI.md +89 -72
  101. package/docs/API.md +18 -14
  102. package/docs/CODEMAP.md +68 -40
  103. package/docs/COMMANDS.md +22 -23
  104. package/docs/CONVENTIONS.md +120 -17
  105. package/docs/MIGRATING-0.8.md +2 -0
  106. package/docs/MIGRATING-1.0.md +101 -0
  107. package/docs/THREE.md +65 -12
  108. package/docs/api/cameraRig.md +3 -0
  109. package/docs/api/characters.md +13 -7
  110. package/docs/api/collider3d.md +9 -0
  111. package/docs/api/content.md +16 -15
  112. package/docs/api/dialogue.md +2 -1
  113. package/docs/api/engine.md +18 -16
  114. package/docs/api/events.md +14 -4
  115. package/docs/api/ground.md +2 -2
  116. package/docs/api/i18n.md +1 -1
  117. package/docs/api/input.md +2 -1
  118. package/docs/api/interactions.md +1 -1
  119. package/docs/api/inventory.md +1 -1
  120. package/docs/api/level.md +3 -2
  121. package/docs/api/nav.md +4 -2
  122. package/docs/api/particles.md +8 -5
  123. package/docs/api/pickups.md +1 -1
  124. package/docs/api/post.md +3 -4
  125. package/docs/api/quests.md +4 -2
  126. package/docs/api/rays.md +2 -0
  127. package/docs/api/rigid.md +3 -2
  128. package/docs/api/saves.md +8 -7
  129. package/docs/api/stream.md +4 -5
  130. package/docs/api/terrain.md +3 -4
  131. package/docs/api/terrainDraw.md +1 -1
  132. package/docs/api/timeline.md +2 -2
  133. package/docs/api/tools.md +3 -1
  134. package/docs/api/triggers.md +2 -0
  135. package/docs/api/vegetationDraw.md +1 -1
  136. package/docs/api/water.md +6 -2
  137. package/docs/api/weather.md +19 -4
  138. package/docs/api/weatherDraw.md +1 -1
  139. package/docs/api/world.md +1 -1
  140. package/docs/recipes/01-new-game.md +3 -3
  141. package/docs/recipes/02-npc.md +3 -4
  142. package/docs/recipes/03-items-pickups.md +11 -11
  143. package/docs/recipes/04-quests.md +2 -0
  144. package/docs/recipes/05-props-bake.md +9 -9
  145. package/docs/recipes/06-clock-events.md +6 -6
  146. package/docs/recipes/07-flow-scenes-pause.md +18 -15
  147. package/docs/recipes/08-weather-sky.md +5 -5
  148. package/docs/recipes/09-materials-lights-models.md +3 -3
  149. package/docs/recipes/10-blender-level.md +16 -4
  150. package/docs/recipes/11-vehicles.md +18 -6
  151. package/docs/recipes/12-navmesh.md +52 -8
  152. package/docs/recipes/13-animation.md +34 -8
  153. package/docs/recipes/14-custom-module.md +20 -8
  154. package/docs/recipes/15-perf.md +4 -4
  155. package/docs/recipes/16-dev-bridge.md +9 -8
  156. package/docs/recipes/18-world.md +13 -5
  157. package/docs/recipes/19-shooting-picking.md +3 -2
  158. package/docs/recipes/20-content-actions-save.md +26 -6
  159. package/docs/recipes/21-camera.md +17 -23
  160. package/docs/recipes/22-shop-gold.md +21 -12
  161. package/docs/recipes/23-ops.md +19 -15
  162. package/docs/recipes/26-ui-parts.md +3 -2
  163. package/docs/recipes/27-net.md +3 -3
  164. package/docs/recipes/28-terrain.md +3 -3
  165. package/docs/recipes/29-grid.md +1 -1
  166. package/docs/recipes/30-templates.md +10 -13
  167. package/docs/recipes/31-audio.md +2 -2
  168. package/docs/recipes/32-action-game.md +6 -5
  169. package/docs/recipes/33-stream-sources.md +4 -1
  170. package/docs/recipes/34-environment-lighting.md +7 -8
  171. package/docs/recipes/35-picture-from-reference.md +13 -9
  172. package/docs/recipes/36-ground-plants.md +3 -2
  173. package/docs/recipes/40-scene.md +11 -10
  174. package/docs/recipes/43-shader-patches-surfaces.md +7 -7
  175. package/docs/recipes/44-water-weather-hooks.md +9 -8
  176. package/docs/recipes/45-cascaded-shadows.md +3 -4
  177. package/docs/recipes/46-blender-art-route.md +3 -3
  178. package/docs/recipes/49-game-module-contract.md +2 -1
  179. package/docs/recipes/50-own-renderer.md +1 -0
  180. package/docs/recipes/51-capability-catalog.md +14 -8
  181. package/docs/recipes/52-around-the-picture.md +4 -4
  182. package/docs/recipes/55-mods-time-wrap.md +5 -4
  183. package/docs/recipes/56-webgpu-tsl.md +12 -1
  184. package/docs/recipes/57-control.md +30 -10
  185. package/docs/recipes/58-input.md +13 -0
  186. package/docs/recipes/60-judge-the-picture.md +1 -1
  187. package/docs/recipes/62-picture-code.md +106 -48
  188. package/docs/recipes/63-third-person-start.md +2 -1
  189. package/docs/recipes/64-particles.md +53 -4
  190. package/docs/recipes/65-swarm.md +2 -2
  191. package/docs/recipes/66-common-tasks.md +313 -0
  192. package/examples/action/.threedog/content-index.json +1 -1
  193. package/examples/action/GAMEMAP.md +3 -3
  194. package/examples/perf-island/.threedog/content-index.json +1 -1
  195. package/examples/perf-island/GAMEMAP.md +3 -3
  196. package/examples/perf-island/main.js +2 -2
  197. package/examples/plain-picture/GAMEMAP.md +3 -1
  198. package/examples/rc2d/GAMEMAP.md +1 -1
  199. package/examples/rc2d/rc2d.js +1 -1
  200. package/examples/styletest/.threedog/content-index.json +1 -1
  201. package/examples/styletest/GAMEMAP.md +3 -3
  202. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  203. package/examples/world/.threedog/content-index.json +1 -1
  204. package/examples/world/GAMEMAP.md +5 -4
  205. package/examples/world/main.js +3 -3
  206. package/index.d.ts +8 -5
  207. package/index.js +22 -1
  208. package/llms.txt +2 -1
  209. package/modules/ambience/Ambience.js +5 -3
  210. package/modules/calendar/index.js +7 -5
  211. package/modules/camera/FirstPersonCamera.js +3 -3
  212. package/modules/camera/FixedCamera.js +34 -20
  213. package/modules/camera/FollowCamera.js +20 -11
  214. package/modules/camera/RtsCamera.js +1 -0
  215. package/modules/camera/common.js +33 -22
  216. package/modules/camera/pixelSnap.js +62 -0
  217. package/modules/characters/Character.js +136 -43
  218. package/modules/characters/NPC.js +60 -28
  219. package/modules/characters/assetModel.js +2 -2
  220. package/modules/characters/astar.js +47 -28
  221. package/modules/characters/character.contract.js +21 -0
  222. package/modules/characters/contract.js +17 -3
  223. package/modules/characters/index.js +94 -34
  224. package/modules/characters/moveHelpers.js +80 -15
  225. package/modules/characters/mover.contract.js +14 -0
  226. package/modules/characters/movers/common.js +6 -4
  227. package/modules/characters/movers/rapier.js +12 -5
  228. package/modules/characters/movers/simple.js +25 -12
  229. package/modules/characters/movers/support.js +18 -7
  230. package/modules/characters/npcAvoid.js +15 -12
  231. package/modules/characters/npcSim.js +75 -25
  232. package/modules/characters/npcView.js +13 -6
  233. package/modules/characters/pathAsync.js +74 -24
  234. package/modules/characters/pathJob.js +38 -21
  235. package/modules/characters/player.js +59 -47
  236. package/modules/characters/seat.js +56 -0
  237. package/modules/characters/vehicle.contract.js +8 -5
  238. package/modules/characters/walkTo.js +31 -18
  239. package/modules/collision/Collision.js +44 -26
  240. package/modules/collision/contract.js +2 -2
  241. package/modules/collision/grid.js +6 -1
  242. package/modules/content/explain.js +1 -1
  243. package/modules/content/fields.js +3 -3
  244. package/modules/content/ids.js +3 -1
  245. package/modules/content/index.js +83 -27
  246. package/modules/content/loader.js +110 -130
  247. package/modules/content/markers.js +1 -1
  248. package/modules/content/models.js +48 -14
  249. package/modules/content/packs.js +2 -1
  250. package/modules/content/places.js +5 -4
  251. package/modules/content/props.js +8 -6
  252. package/modules/content/rules.js +29 -47
  253. package/modules/content/templates.js +66 -35
  254. package/modules/content/words.js +19 -6
  255. package/modules/debug/DebugPanel.js +4 -2
  256. package/modules/flow/contract.js +1 -0
  257. package/modules/flow/index.js +24 -14
  258. package/modules/gameplay/Container.js +5 -2
  259. package/modules/gameplay/Containers.js +9 -1
  260. package/modules/gameplay/Dialogue.js +82 -25
  261. package/modules/gameplay/Interactions.js +61 -32
  262. package/modules/gameplay/Inventory.js +56 -13
  263. package/modules/gameplay/Quests.js +133 -24
  264. package/modules/gameplay/boxOps.js +7 -0
  265. package/modules/gameplay/dialogueBubbles.js +14 -9
  266. package/modules/gameplay/inventoryOps.js +11 -7
  267. package/modules/gameplay/pickups.js +43 -16
  268. package/modules/gameplay/questLog.js +4 -2
  269. package/modules/gameplay/questSave.js +6 -1
  270. package/modules/gameplay/quests.contract.js +1 -1
  271. package/modules/grid/Grid.js +1 -1
  272. package/modules/grid/Layer.js +8 -4
  273. package/modules/grid/index.js +21 -15
  274. package/modules/grid/ops.js +43 -46
  275. package/modules/grid/tiles.js +1 -1
  276. package/modules/hlod/index.js +6 -3
  277. package/modules/hud/index.js +6 -4
  278. package/modules/hud/parts.js +4 -4
  279. package/modules/level/contract.js +2 -2
  280. package/modules/level/heightfield.js +17 -21
  281. package/modules/level/index.js +83 -26
  282. package/modules/level/load.js +165 -48
  283. package/modules/level/nodes.js +34 -16
  284. package/modules/lights/index.js +6 -3
  285. package/modules/lights/sources.js +3 -1
  286. package/modules/music/Music.js +4 -2
  287. package/modules/nav/contract.js +7 -5
  288. package/modules/nav/index.js +174 -44
  289. package/modules/nav/navPath.js +45 -10
  290. package/modules/net/index.js +1 -1
  291. package/modules/particles/Particles.js +85 -22
  292. package/modules/particles/effect.js +80 -28
  293. package/modules/particles/shaders.js +17 -0
  294. package/modules/photo/Photo.js +12 -10
  295. package/modules/rigid/RigidBodies.js +200 -57
  296. package/modules/rigid/Vehicles.js +15 -5
  297. package/modules/rigid/collider3d.contract.js +26 -0
  298. package/modules/rigid/ragdoll.js +55 -44
  299. package/modules/rigid/ragdollBones.js +83 -33
  300. package/modules/rigid/refresh.js +10 -0
  301. package/modules/rigid/sync.js +46 -15
  302. package/modules/settings/Settings.js +84 -37
  303. package/modules/settings/apply.js +15 -8
  304. package/modules/settings/sections.js +7 -4
  305. package/modules/settings/strings.js +2 -2
  306. package/modules/sky/skyModule.js +3 -1
  307. package/modules/swarm/Swarm.js +16 -6
  308. package/modules/terrain/ChunkManager.js +10 -16
  309. package/modules/terrain/index.js +17 -11
  310. package/modules/terrain/terrainEdit.js +13 -2
  311. package/modules/terrain/terrainGen.js +5 -3
  312. package/modules/terrain/terrainShape.js +1 -1
  313. package/modules/timeline/Timeline.js +58 -26
  314. package/modules/timeline/Tween.js +19 -13
  315. package/modules/timeline/shots.js +19 -10
  316. package/modules/triggers/index.js +87 -20
  317. package/modules/vegetation/Vegetation.js +4 -3
  318. package/modules/vegetation/draw.js +16 -0
  319. package/modules/vegetation/groundChunks.js +10 -7
  320. package/modules/vegetation/index.js +30 -7
  321. package/modules/water/Water.js +6 -2
  322. package/modules/weather/Weather.js +16 -15
  323. package/modules/weather/weatherDraw.js +7 -6
  324. package/modules/world/World.js +20 -7
  325. package/modules/world/explain.js +1 -1
  326. package/modules/world/index.js +13 -6
  327. package/modules/world/persist.js +23 -8
  328. package/modules/world/pos.js +4 -4
  329. package/modules/world/records.js +13 -7
  330. package/modules/world/sim.js +74 -23
  331. package/modules/world/simFar.js +2 -2
  332. package/modules/world/state.js +31 -6
  333. package/modules/world/thingSource.js +16 -3
  334. package/modules/world/views.js +19 -8
  335. package/package.json +7 -1
  336. package/render/PostFX.js +47 -29
  337. package/render/backend.js +5 -1
  338. package/render/fx/particles.tsl.js +8 -6
  339. package/render/fx/postWebGPU.tsl.js +3 -3
  340. package/render/layers.js +1 -1
  341. package/render/lightmap.js +23 -3
  342. package/render/occlusion.js +43 -12
  343. package/render/patches.js +2 -2
  344. package/render/postWebGL.js +4 -3
  345. package/render/probes.js +25 -0
  346. package/render/shadows.js +2 -2
  347. package/types/core.d.ts +142 -55
  348. package/types/gameplay.d.ts +92 -40
  349. package/types/generated/core/base/I18n.d.ts +2 -2
  350. package/types/generated/core/input/Input.d.ts +16 -2
  351. package/types/generated/core/input/inputSeat.d.ts +26 -0
  352. package/types/generated/core/inspect/DebugOverrides.d.ts +15 -1
  353. package/types/generated/core/ops/Ops.d.ts +2 -1
  354. package/types/generated/core/ops/control.d.ts +12 -2
  355. package/types/generated/core/saves/Saves.d.ts +26 -6
  356. package/types/generated/core/saves/session.d.ts +1 -1
  357. package/types/generated/core/scene/Views.d.ts +1 -1
  358. package/types/generated/core/stream/Stream.d.ts +6 -4
  359. package/types/generated/modules/grid/Grid.d.ts +1 -0
  360. package/types/generated/modules/particles/Particles.d.ts +4 -3
  361. package/types/generated/modules/timeline/Timeline.d.ts +5 -4
  362. package/types/generated/modules/weather/Weather.d.ts +1 -7
  363. package/types/generated/modules/world/World.d.ts +6 -4
  364. package/types/generated/render/PostFX.d.ts +6 -14
  365. package/types/nav.d.ts +36 -4
  366. package/types/physics.d.ts +55 -7
  367. package/types/pixel.d.ts +75 -0
  368. package/types/world.d.ts +14 -8
  369. package/ui/Parts.js +9 -2
  370. package/ui/theme.js +2 -2
  371. package/core/scene/engineCamera.js +0 -32
  372. package/modules/camera/projection.js +0 -21
@@ -5,7 +5,7 @@
5
5
  // Clock-time / season timers (daily 18:00, time-window switches, season change) belong to the calendar module (modules/calendar, a gameplay
6
6
  // module, so core never names it): engine.calendar.at / between / daily / onSeason; the sky only draws that time.
7
7
  // engine.clock.after(120, 'bread:ready') // emit an event after 120 calendar seconds (saveable: still fires after a load)
8
- // engine.clock.after(5, () => door.close()) // a function works too, but functions cannot be saved
8
+ // engine.clock.after(5, () => door.close(), { channel: 'real' }) // a function works too, but functions cannot be saved
9
9
  // engine.clock.every(30, () => spawnBird()) // every 30 calendar seconds
10
10
  // engine.clock.after(1, 'poison:tick', { data: { id }, channel: 'enemies' }) // channel seconds instead: slows down with bullet time
11
11
  // engine.clock.after(3, () => respawn(), { channel: 'real' }) // real seconds: ignores bullet time and the calendar rate
@@ -59,3 +59,5 @@ export class Clock {
59
59
  /** Number of registered timers on every channel, used by engine.counts() */
60
60
  get size() { return this.engine.time.size; }
61
61
  }
62
+
63
+ export const handRolled = [{ kind: 'timers', seen: 'setInterval / setTimeout used for game timing', use: 'engine.clock.after(seconds, fn) / engine.clock.every(seconds, fn), or accumulate dt in engine.onFixed (they follow pause, step and saves); to await one: new Promise(r => engine.clock.after(s, r))', code: /\b(setInterval|setTimeout)\s*\(/, not: /setTimeout\s*\([^,]*,\s*0\s*\)/ }]; // debug: words for the tools, no timer runs here
package/core/time/skip.js CHANGED
@@ -86,17 +86,23 @@ export const skipMethods = {
86
86
  * @example await engine.skip({ to: '06:00' }); // sleep: until the calendar clock next reads 06:00
87
87
  * @example engine.skip({ seconds: 600 }); // wait 600 calendar seconds
88
88
  * @example await engine.skip({ to: '06:00', fade: 0.6, save: 'auto' }); // fade to black, jump, autosave, fade in
89
+ * Bad arguments throw at the call, before any fade (`[skip-amount]`, `[module-params]`); a skip already under way rejects.
89
90
  * @param {{ to?: string | number, seconds?: number, fade?: number, save?: string | boolean }} opts
90
- * Cancelled cleanly by session.newGame / load / quit (the skip resolves null and time stays where the new playthrough put it).
91
+ * Cancelled cleanly by session.newGame / load / quit and by saves.load (the skip resolves null and time stays where the new playthrough put it).
91
92
  * @returns {Promise<{ seconds: number, clock: string | null, day: number | null } | null>}
92
93
  */
93
- skip(opts = {}) {
94
+ skip(opts) {
95
+ opts ??= {}; // skip(null) reads as no amount, the coded error below, not a TypeError on .fade
94
96
  readParams('engine.skip()', keysSchema(['to', 'seconds', 'fade', 'save']), opts);
95
97
  const { fade = 0, save = null } = opts;
96
98
  amount(this, opts); // throw on bad arguments now, not after the fade
99
+ // one at a time: the end of a second one unfroze the game during the first one's fade
100
+ if (this._skipping) return Promise.reject(codedError('skip-busy', 'engine.skip(): a skip is already under way; await the first one, then skip again'));
101
+ this._skipping = true;
97
102
  let out = null, ended = false;
103
+ const generation = this.saves.generation;
98
104
  const go = () => {
99
- if (ended) return; // the playthrough ended during the fade out: nothing to skip in the new one
105
+ if (ended || this.saves.generation !== generation) return; // the playthrough ended, or a quick load replaced the state, during the fade out: nothing to skip in the new one
100
106
  const r = this.ops.run('time.skip', { seconds: amount(this, opts) }); // measured at jump time: a queued transition may have moved the clock
101
107
  if (!r.ok) throw codedError('skip-amount', `engine.skip(): the time.skip op was refused (${r.code}); read it with engine.ops.can('time.skip', { seconds })`);
102
108
  out = r.value;
@@ -104,7 +110,7 @@ export const skipMethods = {
104
110
  };
105
111
  const ctx = this.input.push('skip'); const fz = this.freeze('skip'); // opaque 'skip' context: gameplay input blocked until the skip ends
106
112
  const off = this.events.on('session:end', () => { ended = true; }); // newGame / load / quit cancel the skip cleanly (it resolves null)
107
- const end = () => { ctx.remove(); fz.remove(); off.remove(); };
113
+ const end = () => { this._skipping = false; ctx.remove(); fz.remove(); off.remove(); };
108
114
  if (!(fade > 0)) { try { go(); } finally { end(); } return Promise.resolve(out); }
109
115
  const run = this.flow ? this.flow.transition(go, { fade, autosave: false, music: false })
110
116
  : (async () => { try { await fadeScreen(this, 1, { seconds: fade }); go(); } finally { await fadeScreen(this, 0, { seconds: fade }); } })();
package/core/time/time.js CHANGED
@@ -18,7 +18,7 @@
18
18
  // Built in: world (the root), player (parent world), calendar (parent world, speed 'clock.rate'). Physics (rapier) steps with dt('world'): to slow enemies and leave bodies alone, slow a channel of their own, not world.
19
19
  import { codedError } from '../base/errorHints.js';
20
20
  import { reportError } from '../base/errors.js';
21
- import { saveValues } from '../saves/saveValues.js';
21
+ import { saveValues, SAVE_MAX_SECONDS } from '../base/saveValues.js';
22
22
 
23
23
  export const STEP = 1 / 60;
24
24
  const STRINGS = { where: 'clock timer', onMove: 'time.onMove listener' };
@@ -40,7 +40,7 @@ export class Time {
40
40
  this.channel('world', { parent: null });
41
41
  this.channel('player');
42
42
  this.channel('calendar', { stack: 'clock.rate' });
43
- engine.saves.register('time', {
43
+ engine.saves.register('time', { notAtomic: 'time goes on through a failed op: going back would run timers twice',
44
44
  version: 2,
45
45
  // v1 kept the calendar in its own 'clock' part ({ now, timers }); v2 has it as the 'calendar' channel of this part
46
46
  migrate: { 1: (d, save) => {
@@ -49,7 +49,8 @@ export class Time {
49
49
  timers: [...(d?.timers ?? []), ...(Array.isArray(c.timers) ? c.timers : []).map(t => ({ ...t, channel: 'calendar' }))] };
50
50
  } },
51
51
  // real: 'real' timers count on a clock no save restores (a new playthrough starts it from 0), so load shifts them by how far it moved
52
- save: () => ({ channels: Object.fromEntries([...this._ch.values()].map(c => [c.name, c.now])), real: this.now('real'),
52
+ // _pending: channels of the loaded save the game has not defined yet stay in the next save
53
+ save: () => ({ channels: { ...this._pending, ...Object.fromEntries([...this._ch.values()].map(c => [c.name, c.now])) }, real: this.now('real'),
53
54
  timers: this._timers.filter(t => t.event && !t.dead).map(({ ch, due, event, data, every }) => ({ channel: ch, due, event, data, ...(every ? { every } : null) })) }),
54
55
  load: d => this._load(d),
55
56
  });
@@ -58,7 +59,7 @@ export class Time {
58
59
  _load(d) {
59
60
  // saved seconds pass saveValues first: a negative / non-finite channel time ran its timers backwards (durability audit); clamped to >= 0, one warning
60
61
  const v = saveValues('time'), chans = {};
61
- for (const [name, now] of Object.entries(d?.channels ?? {})) chans[name] = v.num(now, `channels.${name}`, { min: 0, fallback: 0 });
62
+ for (const [name, now] of Object.entries(d?.channels ?? {})) chans[name] = v.num(now, `channels.${name}`, { min: 0, max: SAVE_MAX_SECONDS, fallback: 0 });
62
63
  const timers = (Array.isArray(d?.timers) ? d.timers : []).filter(t => {
63
64
  if (Number.isFinite(t?.due) && typeof t.event === 'string' && typeof t.channel === 'string') return true;
64
65
  v.drop('timers[]', t); return false;
@@ -141,7 +142,7 @@ export class Time {
141
142
  const t = typeof fnOrEvent === 'string' ? { ch, due: this.now(ch) + seconds, event: fnOrEvent, data, every, dead: false }
142
143
  : { ch, due: this.now(ch) + seconds, fn: fnOrEvent, every, dead: false };
143
144
  this._timers.push(t);
144
- return { remove: () => { t.dead = true; this._timers = this._timers.filter(x => x !== t); } };
145
+ return { _timer: t, remove: () => { t.dead = true; this._timers = this._timers.filter(x => x !== t); } }; // _timer: ctx.track files it with its module (Session._keepTimer)
145
146
  }
146
147
  /** Timers in the queue (engine.counts) */
147
148
  get size() { return this._timers.length; }
@@ -156,6 +157,7 @@ export class Time {
156
157
  if (!due.length) continue;
157
158
  this._timers = this._timers.filter(t => !(t.ch === ch && t.due <= at) || t.every);
158
159
  for (const t of due) {
160
+ if (this.engine.disposed) return; // a callback of this list disposed the engine: dispose cannot reach the ones already taken out of the queue
159
161
  if (t.every) { while (!t.dead && t.due <= at) { t.due += t.every; this._call(t); } continue; }
160
162
  if (!t.dead) { t.dead = true; this._call(t); }
161
163
  }
@@ -168,8 +170,11 @@ export class Time {
168
170
  }
169
171
  /** @internal engine.session: the function timers now, each with its time left (what a new playthrough starts with) @returns {{ t: any, rem: number }[]} */
170
172
  _snapshotFn() { return this._timers.filter(t => !t.event && !t.dead).map(t => ({ t, rem: t.due - this.now(t.ch) })); }
171
- /** @internal engine.session: keep the event timers (they came with the save), put back exactly the snapshotted function timers with their original delay */
172
- _restoreFn(list) { this._timers = this._timers.filter(t => t.event).concat(list.map(({ t, rem }) => Object.assign(t, { due: this.now(t.ch) + rem, dead: false }))); }
173
+ /** @internal engine.session: keep the event timers (they came with the save) and function timers set since `old` was taken, drop the rest, put back the snapshotted `list` with its original delay */
174
+ _restoreFn(list, old) {
175
+ const gone = new Set([...old, ...list].map(x => x.t));
176
+ this._timers = this._timers.filter(t => t.event || !gone.has(t)).concat(list.map(({ t, rem }) => Object.assign(t, { due: this.now(t.ch) + rem, dead: false })));
177
+ }
173
178
 
174
179
  // ---------- the three ways time moves ----------
175
180
  /** @internal loop.js, at the start of a fixed step: count it, so this step's commits, ops and input records carry the new tick */
@@ -210,7 +215,8 @@ export class Time {
210
215
  const scales = [...this._ch.values()].map(c => [c, this.scale(c.name)]);
211
216
  this._setAmbient(this._amb + fixed);
212
217
  for (const [c, s] of scales) c.now += c.name === 'calendar' && calendar != null ? calendar : fixed * s;
213
- for (const fn of [...this._onMove]) { try { fn(); } catch (err) { reportError(this.engine, err, STRINGS.onMove); } }
218
+ for (const fn of [...this._onMove]) { if (!this._onMove.includes(fn)) continue; /* removed earlier in this pass, or by a dispose */ try { fn(); } catch (err) { reportError(this.engine, err, STRINGS.onMove); } }
219
+ if (this.engine.disposed) return;
214
220
  this.engine.stacks._expire();
215
221
  this._runTimers();
216
222
  }
@@ -237,6 +243,6 @@ export class Time {
237
243
  }
238
244
  return out;
239
245
  }
240
- /** Clear all timers (engine.dispose) */
241
- dispose() { for (const t of this._timers) t.dead = true; this._timers = []; }
246
+ /** Clear all timers and move listeners (engine.dispose) */
247
+ dispose() { for (const t of this._timers) t.dead = true; this._timers = []; this._onMove = []; }
242
248
  }
package/docs/AI.md CHANGED
@@ -1,56 +1,82 @@
1
1
  # Using threedog.js (read first)
2
2
 
3
- threedog.js is a web 3D game engine on plain three.js 0.187: **core** -> **modules** (`engine.use`); all art is the game's own (its `picture/` folder and
4
- `assets.js`; without them: gray placeholders).
5
- Paths: `node_modules/threedog/docs/`. `threedog how "<2-4 English words>"` finds the section.
3
+ threedog.js: a web 3D game engine on plain three.js 0.187, **core** -> **modules** (`engine.use`); all art is the game's own (else gray placeholders).
4
+ Paths: `node_modules/threedog/docs/`. `threedog how "<2-4 English words>"`; no words: browse.
6
5
 
7
- ## Two routes
8
- **Picture** (materials, shaders, lights) is plain three.js on `engine.scene / camera / renderer` first (`THREE.md`). **Engineering** (saves, pause, menus, input, camera, time, checks) is the engine.
9
- New games start on WebGPU with TSL (recipe 56). With no WebGPU the same game runs on three's WebGL2 backend, slower; `describe().renderer` says why. TSL-only effects (`voxelGI`, `temporalAA`, `sunShafts`, `lightVolumes`): `@threedog/post-effects/tsl`. Imports: recipe 52.
6
+ ## Start by task
7
+ | The task | Where it goes |
8
+ |---|---|
9
+ | Lights, materials, models, shaders, fog, picture effects | Native three.js on `engine.scene / camera / renderer` (`THREE.md`), joined up with `onFrame`, `onRender`, `post.add` |
10
+ | Time, input, asset loading, saving, pausing, streaming | Check the engine first: rows below |
11
+ | Buying, picking up, attacking, opening doors: anything validated and recorded | `engine.ops` |
12
+ | Facts that persist, exist far away or keep changing | `engine.world`, `content` |
13
+ | Game-specific rules and looks | The game writes them; the engine coordinates (`engine.mod`) |
14
+ | Composing modules | `engine.use`, `requires` / `provides` when needed, `ctx.track`. A simple module may omit `type` |
15
+ | Troubleshooting | `describe`: state; `explain`: why; `catalog`: what exists; `inspect`: what can be done here; `thing`: one object |
10
16
 
11
- ## Most common mistakes
12
- - Hand-writing a system a row lists: find the row.
17
+ **The engine lacks it?** Plain JS and three.js, joined through modules, events, ops, assets and saves, is the expected path; a small feature needs no provider protocol.
18
+
19
+ ## Common mistakes
13
20
  - `Math.random()`, `setTimeout`, `performance.now()`, `addEventListener('keydown')` in game logic: `engine.random.next()`, `engine.clock.after`, fixed `dt`, `input.bind`.
14
21
  - Changing gameplay state from a frame hook or a raw callback: do it in `onFixed`, in an op, or via `engine.nextFixed(fn)`.
15
22
  - Saving positions or object references: save stable ids; `await` every `saves.*` call; a mesh a save must know about gets `engine.add(obj, { id })`.
23
+ - Awaiting `level.load` / `content.load` in a save part's `load(data, turn)`: pass `{ turn }`, or it waits for ever.
16
24
  - Editing generated docs (API.md, api/, CODEMAP, `types/generated/`): change the code, `npm run map`.
17
- - Guessing a name: look it up in `api/<module>.md`; errors carry `err.code` / `fix` / `docs`.
25
+ - Guessing a name: see `api/<module>.md`; errors carry `err.code` / `fix` / `docs`.
18
26
 
19
27
  ## What to read, in order
20
- The row -> its recipe (`recipes/NN-*.md`) -> `api/<module>.md`. Several entries for one task: `CONVENTIONS.md`. When needed: `THREE.md` · `COMMANDS.md` · `MIGRATING-0.8.md`.
28
+ Taking over a game: `STATUS.md` first. A new feature: a row or `threedog how` -> recipe -> `api/<module>.md`. Several entries: `CONVENTIONS.md`. Also: `THREE.md`, `COMMANDS.md`; upgrading: `MIGRATING-1.0.md`.
21
29
 
30
+ ## What exists: look here first
31
+ Recommendations. Your own code wires in time by `onFixed` and `engine.clock`, saving by `engine.saves.register`, cleanup by handles (`ctx.track`).
32
+ ### Picture and sound
33
+ | To do | Use | Recipe |
34
+ |---|---|---|
35
+ | The picture in three.js (`picture/`): lights, fog, exposure, parts | `lights: false`, `engine.uniforms` | 62-picture-code.md, 34-environment-lighting.md |
36
+ | Picture, writers; try a value | `describe().picture`, `explain({ value })`, `debug.watch`, `debug.override` | 52-around-the-picture.md, 62-picture-code.md |
37
+ | Materials, textures, a module's picture | `engine.water.material` | 09-materials-lights-models.md |
38
+ | Own material or shader (toon, cel shading) | TSL (WebGPU), `ShaderMaterial` (WebGL), `rampTexture`, `celLighting` | 43-shader-patches-surfaces.md, 56-webgpu-tsl.md |
39
+ | WebGPU (new games' default), TSL node materials, WebGL fallback | `renderer: 'webgpu'`, `import 'threedog/tsl'` | 56-webgpu-tsl.md |
40
+ | three.js idioms, own renderer | the idiom table in `THREE.md`, `createEngine({ renderer })` | 50-own-renderer.md |
41
+ | Dust, smoke | `engine.particles` | 64-particles.md |
42
+ | Sky, season tints, weather, wet roads | `engine.sky`, `engine.weather`, `engine.weatherDraw` | 08-weather-sky.md |
43
+ | Water, rain / snow, snow cover (own rain: `THREE.md`) | `engine.water`, `weather({ rain, snow })` | 44-water-weather-hooks.md |
44
+ | Shadows: blur, follow, cost | `engine.shadows` | 45-cascaded-shadows.md |
45
+ | Own far, fov; clouds | `engine.autoView`, `engine.shaderTerms` | 52-around-the-picture.md |
46
+ | Environment light, reflections, probes, lightmaps, GI, culling | `engine.sky.environment`, `engine.bakeProbes`, `engine.loadLightmap`, `engine.occlusion` | 34-environment-lighting.md |
47
+ | Post passes: color grading, bloom, outline, depth, AO | `engine.post.add(pass)`, `@threedog/post-effects` | 52-around-the-picture.md#post-effect-chain, 59-depth-post-effects.md |
48
+ | Many lights (torches); windows, signs at night | `engine.lightPool`, `uNight` | 09-materials-lights-models.md §1b |
49
+ | Picture from a reference; judge | `threedog picture palette`, `threedog examples list` | 35-picture-from-reference.md, 60-judge-the-picture.md |
50
+ | Reuse effects, models of old games | `threedog lib` | 05-props-bake.md |
51
+ | Sound, music, ambience | `engine.audio`, `engine.music`, `engine.ambience` | 31-audio.md |
22
52
 
23
- ## One thing, one entry point (don't build another)
24
- ### Project, world, content
53
+ ### Rules, state, time
25
54
  | To do | Use | Recipe |
26
55
  |---|---|---|
27
- | New game, project layout, preset start | `npx threedog init` (repo: `new-game`), `createEngine`, `openWorld()` | 01-new-game.md |
28
- | Put something in the scene | `scene.add(obj)`; saved: `engine.add(obj, { id })` | 40-scene.md |
29
- | Content data, packs, change an entry for good | `engine.content`, `threedog content set` | 20-content-actions-save.md |
30
- | Reusable objects (prefabs), groups of them | `templates`, flat `props` | 30-templates.md |
31
- | Props, many repeated objects, static batching | content `props`, `engine.batching` | 05-props-bake.md |
32
- | What is this thing, does it persist | `engine.pick(x, y)`, `engine.thing(id).explain()` | 30-templates.md §5, 40-scene.md |
33
- | Teleport the player, far-away and saved objects, streaming | `player.placeAt`, `engine.stream.teleport`, `engine.world` | 18-world.md, 33-stream-sources.md |
34
- | Blender level | `engine.level`; `engine.vegetation.define` | 10-blender-level.md, 05-props-bake.md §2e |
35
- | Terrain, height, edits | `engine.terrain`, `engine.ground` | 28-terrain.md |
36
- | Own ground or plant drawing, keep collision | `{ replaces: 'terrain-draw' }`, `engine.terrain.view`, `engine.terrainDraw`, `engine.vegetationDraw` | 28-terrain.md §6 |
37
- | Ground picture | `engine.terrain.material`, `.recolor`, `terrain({ detail, shading, shape })` | 36-ground-plants.md, 53-ground-up-close.md, 28-terrain.md §5 |
38
- | Grid placement, plots, build on cells; a grid from a PNG | `engine.grids`, `layer.material`, `sampleGrid`, `assets.gridFromImage` | 29-grid.md, 28-terrain.md §9 |
39
- | Asset packs, loading; code-made models; far detail | `engine.assets.manifest`, `.palette`, `.lod`, `engine.loading` | 05-props-bake.md, 15-perf.md |
40
- | Blender -> GLB art; fixed views before / after | `threedog assets check`, `engine.views` | 46-blender-art-route.md |
56
+ | Items, chests, shops, gold; things to pick up | `engine.inventory`, `engine.pickups` (`.material`) | 03-items-pickups.md, 22-shop-gold.md |
57
+ | Quests, objective markers | `engine.quests`, `engine.hud.marker()` | 04-quests.md |
58
+ | Player actions, UI buttons | `engine.ops.define` | 23-ops.md |
59
+ | What can the player do here, why not | `engine.inspect`, `engine.explain`, `engine.catalog` | 51-capability-catalog.md |
60
+ | Save game, load game, autosave, story flags, counters | `engine.saves.register` (`load(data, turn)`), `engine.vars` | 20-content-actions-save.md |
61
+ | New game / continue, scene flow, fades, pause for a menu, cutscenes | `engine.session`, `engine.flow`, `engine.freeze`, `engine.timeline` | 07-flow-scenes-pause.md |
62
+ | Timers, read / skip time | `engine.clock` (after, every), `engine.time.now(…)` | 06-clock-events.md |
63
+ | Slow or speed up time, bullet time | `engine.mod('clock.rate')` | 55-mods-time-wrap.md |
64
+ | Time of day, day / night, seasons | `engine.calendar` | 06-clock-events.md |
65
+ | Events, cause chain, randomness | `engine.events`, `engine.random.next()` | 06-clock-events.md |
66
+ | Multiplayer | `engine.net` | 27-net.md |
41
67
 
42
68
  ### Characters, input, UI
43
69
  | To do | Use | Recipe |
44
70
  |---|---|---|
45
71
  | Third-person start (walk, pause, menu) | `createPlayer` | 63-third-person-start.md |
46
72
  | Player, characters, who steers one | `engine.player`, `engine.characters` (`.material`), `engine.control` | 57-control.md, 13-animation.md |
47
- | Keys, gamepad: actions, contexts, rebinding | `engine.input` | 58-input.md |
48
- | Camera: follow / third person (followCamera), first person, fixedCamera, rts; switch live (setCamera) | `engine.cameraRig`, `engine.page` | 21-camera.md |
49
- | 2D, side-scroller, orthographic; 2D lights | `presets.player.sideScroller`; 2D lights: example `rc2d` | 21-camera.md §6, 09-materials-lights-models.md §1b |
50
- | Pixel art | plain three.js | 62-picture-code.md §4b |
73
+ | Keys, gamepad, rebinding, seats | `engine.input` | 58-input.md |
74
+ | Camera: followCamera (third person), first person, fixedCamera, rts; switch: setCamera | `engine.cameraRig`, `engine.page` | 21-camera.md |
75
+ | 2D, side-scroller, orthographic; 2D lights | `presets.player.sideScroller`; example `rc2d` | 21-camera.md §6 |
76
+ | Pixel art, pixel perfect camera | `pixelSize`, `pixelSnap` | 62-picture-code.md §4b |
51
77
  | Skeletal animation | `engine.assets.animate`, `engine.hlod` | 13-animation.md, 15-perf.md |
52
- | Pathfinding, navmesh, "can walk there" | `engine.characters.findPath`, `engine.nav` | 12-navmesh.md |
53
- | Physics (crates, joints, ragdoll), collision, vehicles | `engine.collision`, `engine.rigid` | 11-vehicles.md |
78
+ | Pathfinding, navmesh, NPC jumps and gaps | `engine.characters.findPath`, `engine.nav` | 12-navmesh.md |
79
+ | Physics, ragdoll, collision, vehicles | `engine.collision`, `engine.rigid`, `engine.collider3d` | 11-vehicles.md |
54
80
  | Ray / mouse picking, shooting, lock-on | `engine.rays` | 19-shooting-picking.md |
55
81
  | Prompts, trigger zones | `engine.interactions`, `engine.triggers` | 20-content-actions-save.md |
56
82
  | Press E on a mesh | `interactions.add(mesh, { once, counter })` | 03-items-pickups.md |
@@ -59,64 +85,55 @@ The row -> its recipe (`recipes/NN-*.md`) -> `api/<module>.md`. Several entries
59
85
  | NPCs and what they do, dialogue | `engine.npcs`, `engine.dialogue` | 02-npc.md |
60
86
  | Barks over an NPC | `dialogue.say(text, { channel: 'bubble' })` | 26-ui-parts.md "Two channels" |
61
87
  | UI, menus, HUD, popup message, languages, settings, photo mode | `engine.ui`, `makeWindow`, `toast(engine, text)`, `engine.hud`, `engine.i18n`, `engine.settings`, `engine.photo` | 26-ui-parts.md |
62
- | A settings row that turns off your own effect | `engine.settings.define(key, true, { limits: 'post.<name>.enabled' })` | 26-ui-parts.md §6 |
88
+ | Ambient occlusion, soft shadows | `engine.post.add(ao())`, `bakeVertexAO` | 52-around-the-picture.md |
89
+ | Settings turn off my effect | `settings.define(k, true, { limits: 'post.<name>.enabled' })` | 26-ui-parts.md |
63
90
  | Action game: hp, attacks, enemy AI, drops | your ops + `world.simulate` | 32-action-game.md |
64
- | Many bullets, debris with rules | `engine.swarm` | 65-swarm.md |
91
+ | Many bullets, debris | `engine.swarm` | 65-swarm.md |
65
92
  | Enemy crowds, hordes, flocks | `engine.swarm` | 65-swarm.md |
66
93
 
67
- ### Rules, state, time
94
+ ### Project, world, content
95
+ | To do | Use | Recipe |
96
+ |---|---|---|
97
+ | New game, project layout, preset start | `npx threedog init` (repo: `new-game`), `createEngine`, `openWorld()` | 01-new-game.md |
98
+ | Put something in the scene | `scene.add(obj)`; saved: `engine.add(obj, { id })` | 40-scene.md |
99
+ | Content data, packs, change an entry for good | `engine.content`, `threedog content set` | 20-content-actions-save.md |
100
+ | Reusable objects (prefabs), groups of them | `templates`, flat `props` | 30-templates.md |
101
+ | Props, many repeated objects, static batching | content `props`, `engine.batching` | 05-props-bake.md |
102
+ | What is this thing, does it persist | `engine.pick(x, y)`, `engine.explain({ thing: id })` | 30-templates.md §5, 40-scene.md |
103
+ | Teleport the player, far-away and saved objects, streaming | `player.placeAt`, `engine.stream.teleport`, `engine.world` | 18-world.md, 33-stream-sources.md |
104
+ | Blender level | `engine.level`; `engine.vegetation.define` | 10-blender-level.md |
105
+ | Terrain, height, edits | `engine.terrain`, `engine.ground` | 28-terrain.md |
106
+ | Ground picture | `engine.terrain.material`, `terrain({ detail, shape })` | 36-ground-plants.md, 53-ground-up-close.md |
107
+ | Grid placement, plots, build on cells; a grid from a PNG | `engine.grids`, `sampleGrid`, `assets.gridFromImage` | 29-grid.md, 28-terrain.md §9 |
108
+ | Assets, loading; code-made models; LOD | `engine.assets.manifest`, `.palette`, `.lod`, `engine.loading` | 05-props-bake.md, 15-perf.md |
109
+ | Blender -> GLB art; fixed views before / after | `threedog assets check`, `engine.views` | 46-blender-art-route.md |
110
+
111
+ ### Composing modules
68
112
  | To do | Use | Recipe |
69
113
  |---|---|---|
70
- | Items, chests, shops, gold; things to pick up | `engine.inventory`, `engine.pickups` (`.material`) | 03-items-pickups.md, 22-shop-gold.md |
71
- | Quests, objective markers | `engine.quests`, `engine.hud.marker()` | 04-quests.md |
72
- | Player actions, UI buttons | `engine.ops.define` | 23-ops.md |
73
- | What can the player do here, why not | `engine.catalog`, `engine.explain`, `engine.inspect`, `engine.describe` | 51-capability-catalog.md |
74
- | Save game, load game, autosave, story flags, counters | `engine.saves.register`, `engine.vars` | 20-content-actions-save.md |
75
- | New game / continue, scene flow, fades, pause for a menu, cutscenes | `engine.session`, `engine.flow`, `engine.freeze`, `engine.timeline` | 07-flow-scenes-pause.md |
76
- | Timers, read / skip time | `engine.clock` (after, every), `engine.time.now(…)` | 06-clock-events.md |
77
- | Slow or speed up time, bullet time | `engine.mod('clock.rate')`, `engine.mod('time.<channel>', …)` | 55-mods-time-wrap.md |
78
- | Time of day, day / night, seasons | `engine.calendar` | 06-clock-events.md |
79
114
  | A value several systems change; one-holder parts | `engine.mod`, `engine.stacks`, `provides`, `wrap` | 55-mods-time-wrap.md |
80
115
  | Replace a module (dialogue, camera) | `replaces`, `runContract` | 55-mods-time-wrap.md "Replacing a module" |
81
- | Events, cause chain, randomness | `engine.events`, `engine.random.next()` | 06-clock-events.md |
82
- | Multiplayer | `engine.net` | 27-net.md |
83
116
  | Your own module: `type`, `requires`, swap a part (`provides` + `{ replaces }`) | `engine.use`, `.unuse` | 14-custom-module.md, 49-game-module-contract.md |
117
+ | Drop-in file per piece, no main.js | `plugins/`, `engine.plugins`, `describe().slots` | 40-scene.md |
84
118
 
85
- ### Picture and sound
119
+ ### Advanced
86
120
  | To do | Use | Recipe |
87
121
  |---|---|---|
88
- | The picture in three.js (`picture/`): lights, fog, exposure, parts | `lights: false`, `engine.uniforms` | 62-picture-code.md, 34-environment-lighting.md |
89
- | Read the picture, its writers; try a value | `describe().picture`, `debug.override(owner, obj, key, value)` | 52-around-the-picture.md, 62-picture-code.md |
90
- | Materials, textures, a module's picture | `engine.water.material` | 09-materials-lights-models.md |
91
- | Own material or shader (toon, cel shading) | TSL (WebGPU), `ShaderMaterial` (WebGL), `rampTexture`, `celLighting` | 43-shader-patches-surfaces.md, 56-webgpu-tsl.md |
92
- | WebGPU renderer, TSL node materials, WebGL fallback | `renderer: 'webgpu'`, `import 'threedog/tsl'` | 56-webgpu-tsl.md |
93
- | Drop-in file per piece, no main.js | `plugins/`, `engine.plugins`, `describe().slots` | 40-scene.md |
94
- | three.js idioms, own renderer | the idiom table in `THREE.md`, `createEngine({ renderer })` | 50-own-renderer.md |
95
- | Dust, smoke | `particles({ effects })`, `engine.particles` | 64-particles.md |
96
- | Sky (`replace`, `clouds`, `layer`, `keyframes`), season tints, weather, wet roads | `engine.sky`, `engine.weather`, `engine.weatherDraw` | 08-weather-sky.md |
97
- | Water, rain / snow, snow cover | `engine.water`, `weather({ rain, snow })`, `weather.defineField` | 44-water-weather-hooks.md |
98
- | Shadows: blur, follow, cost | `engine.shadows.cascades(light)`, `.box(light)`, `.budget(light)`, `.cache(light, { static })`, `.mapSize(light, n)`, `.enabled` | 45-cascaded-shadows.md |
99
- | Own far, fov; clouds | `engine.autoView`, `engine.shaderTerms` | 52-around-the-picture.md |
100
- | Environment light, reflections, probes, lightmaps, GI, culling | `engine.sky.environment`, `engine.bakeProbes`, `engine.loadLightmap`, `engine.occlusion` | 34-environment-lighting.md |
101
- | Post passes: color grading, bloom, outline, depth | `post.add(pass)`: `lut`, `paletteLut`, `outline` of `@threedog/post-effects` | 52-around-the-picture.md#post-effect-chain, 59-depth-post-effects.md |
102
- | Ambient occlusion, soft shadows | `engine.post.add(ao())`, `bakeVertexAO` | 52-around-the-picture.md |
103
- | Many lights (torches); windows, signs at night | `engine.lightPool`, `uNight` | 09-materials-lights-models.md §1b |
104
- | Picture from a reference; judge | `threedog picture palette`, `threedog examples list` | 35-picture-from-reference.md, 60-judge-the-picture.md |
105
- | Reuse effects, models of old games | `threedog lib list` / `lib pull` | 05-props-bake.md |
106
- | Sound, music, ambience | `engine.audio`, `engine.music`, `engine.ambience` | 31-audio.md |
122
+ | Own ground or plant drawing, keep collision | `engine.terrain.view`, `engine.terrainDraw`, `engine.vegetationDraw` | 28-terrain.md §6 |
123
+ | Worker results, far records' models, raw navmesh or physics, content sections, own mover | `engine.commits`, `world.present`, `nav.query`, `rigid.world`, module `content`, `characters.kit` | 15-perf.md, 18-world.md, 12-navmesh.md, 11-vehicles.md, 14-custom-module.md, 57-control.md |
107
124
 
108
- ### Verify and speed
125
+ ### Troubleshooting and speed
109
126
  | To do | Use | Recipe |
110
127
  |---|---|---|
111
- | Something broke, looks wrong or is slow: which tool | `.threedog/errors.log`, `engine.describe`, `threedog how` | 16-dev-bridge.md §11 |
128
+ | Broke, looks wrong or slow: which tool | `.threedog/errors.log`, `engine.describe`, `engine.explain` | 16-dev-bridge.md §11 |
112
129
  | Drive and check the live game | the dev bridge (`verify <scenario>`) | 16-dev-bridge.md |
113
130
  | Slow, low fps, workers, budgets | `engine.jobs`, `engine.threads`, `engine.commits`, `engine.budget`, `engine.debug`, `threedog stress` | 15-perf.md |
114
131
  | Deploy | `npm run build` | 61-deploy.md |
115
132
 
116
133
  ## Conventions (`CONVENTIONS.md`)
117
- - **A position is one argument**; sizes and counts go in the options object after it. **Units** are meters, Y up, north -Z; characters face +Z.
118
- - **Registrations return a handle** (`h.remove()`). **Ready is `ready`**. **Events are `noun:action`**. **`owner`** is the name you pass; `describe()` names the `writer`.
119
- - **Fixed step vs frame**: `onFixed` runs game time (damage, AI, timers); `onFrame` is presentation (animation, HUD). Draw what `onFixed` moves with `engine.stepBlend`, or it stutters.
134
+ - **A position is one argument**, then an options object. **Units** are meters, Y up, north -Z; characters face +Z.
135
+ - **Registrations return a handle** (`h.remove()`, `ctx.track` takes it). **Ready is `ready`**. **Events are `noun:action`**. **`owner`** is the name you pass.
136
+ - **`onFixed`** is game time, **`onFrame`** presentation; draw what `onFixed` moves with `engine.stepBlend`, or it stutters.
120
137
 
121
138
  ## Stability
122
- `@experimental` on a name: it may change or go with no migration note (list: `CONVENTIONS.md`, "Stability").
139
+ `@experimental`: may change or go with no migration note.
package/docs/API.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Engine API index (generated, do not edit by hand; produced by npm run map)
2
2
 
3
- > **To do something, first look at the recipe in `recipes/` whose file name matches** (it has a ready-made pattern, faster than browsing the API): 01-new-game · 02-npc · 03-items-pickups · 04-quests · 05-props-bake · 06-clock-events · 07-flow-scenes-pause · 08-weather-sky · 09-materials-lights-models · 10-blender-level · 11-vehicles · 12-navmesh · 13-animation · 14-custom-module · 15-perf · 16-dev-bridge · 18-world · 19-shooting-picking · 20-content-actions-save · 21-camera · 22-shop-gold · 23-ops · 26-ui-parts · 27-net · 28-terrain · 29-grid · 30-templates · 31-audio · 32-action-game · 33-stream-sources · 34-environment-lighting · 35-picture-from-reference · 36-ground-plants · 40-scene · 43-shader-patches-surfaces · 44-water-weather-hooks · 45-cascaded-shadows · 46-blender-art-route · 49-game-module-contract · 50-own-renderer · 51-capability-catalog · 52-around-the-picture · 53-ground-up-close · 55-mods-time-wrap · 56-webgpu-tsl · 57-control · 58-input · 59-depth-post-effects · 60-judge-the-picture · 61-deploy · 62-picture-code · 63-third-person-start · 64-particles · 65-swarm
3
+ > A new feature starts at `AI.md` or `threedog how`; this page is for looking up a name.
4
4
  > The api pages are generated too, do not edit them by hand; `?` in a signature means optional, what follows `→` is the return value; the full types are in `types/*.d.ts`.
5
- > With no matching recipe: read this page first: the core everyday API + one line per core object / module (listing method names). For the one you need, **read only that page** `api/<name>.md` (methods, parameters, properties and data structures are all in it).
6
- > Paths are relative to the package (`node_modules/threedog/`). Entry: `import { createEngine, openWorld, … } from 'threedog'` (the engine package's own examples use relative paths); a module that is not installed is undefined, so use `engine.xxx?.method()`.
5
+ > One line per core object / module; for the one you need, **read only that page** `api/<name>.md`.
6
+ > Paths are relative to the package (`node_modules/threedog/`). Entry: `import { createEngine, openWorld, … } from 'threedog'` (the engine package's own examples use relative paths); a module the game needs is installed with `engine.use` before `await engine.start()`; `engine.xxx?.method()` is only for a feature the game works without, and a required module left out that way fails in silence.
7
+ > By task: ordinary picture is plain three.js (`THREE.md`); game rules are `onFixed`, `ops`, `world`; modules are `use` and `ctx.track`; drawing of your own is at the end of the module list; to troubleshoot, `describe` gives state and `explain` why.
7
8
 
8
9
  ## Core everyday API (all methods, properties, createEngine options and how to write a module are in [api/engine.md](api/engine.md))
9
10
  - `createEngine(opts: EngineOptions) → Engine` — creates the engine (core only); options: canvas ui loading saveKey headless budget …
@@ -27,11 +28,11 @@
27
28
  - `engine.ready` — phase is 'ready' or 'running': the world is built and the loading screen is gone…
28
29
  - `engine.player` — The player (exists only after characters.createPlayer())
29
30
  - `engine.scene` — three.js scene
30
- - `engine.camera` — three.js PerspectiveCamera (class EngineCamera, core/scene/engineCamera.js): a camera rig with proj…
31
+ - `engine.camera` — The camera the engine draws with, a plain THREE.PerspectiveCamera to begin with
31
32
 
32
33
  ## Core objects (engine.xxx, no install needed)
33
34
  - [`engine.events`](api/events.md) the event bus: traceFocus note trace recent on once emit; event table
34
- - [`engine.input`](api/input.md) Input: read by "action": action bind touchButton simulate rebind rebound keysOf isUnbound label down pressed released pressedRaw push …
35
+ - [`engine.input`](api/input.md) Input: read by "action": action bind touchButton simulate seat rebind rebound keysOf isUnbound label down pressed released pressedRaw …
35
36
  - [`engine.clock`](api/clock.md) calendar seconds and "after how long / every how long": after every
36
37
  - [`engine.vars`](api/vars.md) story flags and counters (autosaved): flag setFlag counter bump
37
38
  - [`engine.saves`](api/saves.md) engine.saves handles saving: register putAttachment removeAttachment attachments storageKey flush collect check apply save load list remove export …
@@ -40,27 +41,25 @@
40
41
  - [`engine.i18n`](api/i18n.md) string tables: add setLocale has
41
42
  - [`engine.rays`](api/rays.md) engine.rays is the ray registry…: addStatic forget addProvider
42
43
  - [`engine.jobs`](api/jobs.md) engine.jobs queues build work in a binary heap: add run
43
- - [`engine.stream`](api/stream.md) engine.stream builds on demand by space: only entries n…: add setRadius source teleport addReadyCheck sources
44
+ - [`engine.stream`](api/stream.md) engine.stream builds on demand by space: only entries n…: add source teleport addReadyCheck sources
44
45
  - [`engine.budget`](api/budget.md) performance budget (turned on by createEngine: enable disable metric limitOf report checkStartup values byTag
45
- - [`engine.post`](api/post.md) PostFX: object targets add get own setAntialias list render
46
+ - [`engine.post`](api/post.md) PostFX: object targets add get own list render
46
47
  - [`engine.occlusion`](api/occlusion.md) Occlusion
47
48
  - [`engine.ground`](api/ground.md) Ground: whoever provides the ground height is the "terr…: height slope type has voidY forEachCollider viewRange chunkCollision staticTrimeshes staticVersion
48
49
 
49
50
  ## Modules (installed with engine.use; the openWorld preset installs only world and environment, see [api/openWorld.md](api/openWorld.md))
50
- - [`engine.terrain`](api/terrain.md) terrain() Procedural terrain, data part: recolor setViewChunks setDensity view retry rebuild edit
51
- - [`engine.terrainDraw`](api/terrainDraw.md) terrainDraw: recolor
51
+ - [`engine.terrain`](api/terrain.md) terrain() Procedural terrain, data part: recolor view retry rebuild edit
52
52
  - [`engine.vegetation`](api/vegetation.md) vegetation() Vegetation: sway color view rebuild setShadowRing define get list isRemoved removeInstance restoreInstance instanceAt
53
- - [`engine.vegetationDraw`](api/vegetationDraw.md) vegetationDraw: mesh kind
54
53
  - [`engine.sky`](api/sky.md) sky() Sky dome and the sun / daylight / sky-color signals, from the calendar's time; it writes no light or fog: keyframes clouds layer replace environment
55
54
  - [`engine.calendar`](api/calendar.md) calendar() Time of day, day, seasons and clock-time timers: at between daily onSeason untilMark
56
- - [`engine.weather`](api/weather.md) Weather state: defineField setAuto set label
57
- - [`engine.weatherDraw`](api/weatherDraw.md) weatherDraw
55
+ - [`engine.weather`](api/weather.md) weather() Weather state: defineField set label
58
56
  - [`engine.water`](api/water.md) water() Water surface: shader normalMap
59
57
  - [`engine.world`](api/world.md) World data: add origin idOf get set move remove query forEachNear present view refresh …
60
58
  - [`engine.net`](api/net.md) net: reconnect
61
59
  - [`engine.grids`](api/grids.md) grids: add get list define preview
62
60
  - [`engine.collision`](api/collision.md) collision() Lightweight collision: addCircle addBox addSegment addBlocked blockedAt addObject forEachStatic mirror walkable walkableAt lineClear
63
61
  - [`engine.rigid`](api/rigid.md) rigid() Real physics, Rapier: addBox addBall addHull ragdoll impulse setPosition addWheeled
62
+ - [`engine.collider3d`](api/collider3d.md) collider3d: addSolid overlap sweep
64
63
  - [`engine.cameraRig`](api/cameraRig.md) followCamera() / firstPersonCamera() / fixedCamera() / rtsCamera() Current camera: follow forward right focusPoint screenToGround update onOverride onEnter onExit
65
64
  - [`engine.timeline`](api/timeline.md) timeline() Cutscenes, tweens: tween play skip
66
65
  - [`engine.level`](api/level.md) level() Hand-built level: marker markersWith unload load track
@@ -69,7 +68,7 @@
69
68
  - [`engine.swarm`](api/swarm.md) swarm
70
69
  - [`engine.settings`](api/settings.md) settings() Settings menu: get set preset define addSection open close toggle reset resetBindings rebind actionList …
71
70
  - [`engine.music`](api/music.md) music() Background music: define play stop stinger rules override pick
72
- - [`engine.characters`](api/characters.md) characters() Characters: findSpawn createPlayer moveInput support removePlayer findPath findPathAsync; Character, NPC; engine.npcs: list add remove behavior tiers get character avoid (behavior and avoid: see recipes/02-npc)
71
+ - [`engine.characters`](api/characters.md) characters() Characters: findSpawn createPlayer moveInput addVehicle support removePlayer findPath findPathAsync; Character, NPC; engine.npcs: list add remove behavior tiers get character avoid (behavior and avoid: see recipes/02-npc)
73
72
  - [`engine.interactions`](api/interactions.md) interactions() Interaction prompts: add get
74
73
  - [`engine.dialogue`](api/dialogue.md) dialogue() Dialogue: define start say bubbles end
75
74
  - [`engine.inventory`](api/inventory.md) inventory() Inventory: of define item count has list get add remove trade setData container …
@@ -84,5 +83,10 @@
84
83
  - [`engine.flow`](api/flow.md) flow() Game flow and scene transitions: define go transition
85
84
  - [`engine.hud`](api/hud.md) hud() Objective markers, counters, progress bars: marker counter bump value bar remove
86
85
 
86
+ ## Custom drawing (only to replace how a module draws: the facades above are the entry; `engine.use(mine, { replaces })`, recipe 28 §6)
87
+ - [`engine.terrainDraw`](api/terrainDraw.md) terrain() terrainDraw: recolor
88
+ - [`engine.vegetationDraw`](api/vegetationDraw.md) vegetation() vegetationDraw: mesh kind
89
+ - [`engine.weatherDraw`](api/weatherDraw.md) weather() weatherDraw
90
+
87
91
  ## Other
88
- - [Utility functions](api/tools.md): PICTURE_SLOTS weather presets world net fakeNetwork webSocket grids swarm screenToGround sampleGrid ease checkOptions contentParts readParams threePatches createTerrain terrainMaterial mergeColored applyEffects rampTexture bakeVertexAO materialPatches toast …
92
+ - [Utility functions](api/tools.md): PICTURE_SLOTS presets world net fakeNetwork webSocket grids swarm screenToGround sampleGrid ease checkOptions contentParts readParams threePatches createTerrain terrainMaterial mergeColored applyEffects rampTexture bakeVertexAO materialPatches toast makeWindow …