threedog 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (363) hide show
  1. package/CHANGELOG.md +879 -798
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +178 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +16 -6
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +5 -5
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +46 -27
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +13 -7
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +44 -3
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +16 -11
  103. package/docs/COMMANDS.md +139 -142
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +28 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +23 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +6 -1
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +74 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +9 -8
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +70 -79
  180. package/docs/recipes/63-third-person-start.md +47 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/GAMEMAP.md +2 -3
  185. package/examples/action/main.js +3 -3
  186. package/examples/action/picture/lights.js +3 -1
  187. package/examples/perf-island/GAMEMAP.md +3 -3
  188. package/examples/perf-island/picture/lights.js +2 -1
  189. package/examples/plain-picture/GAMEMAP.md +1 -1
  190. package/examples/rc2d/GAMEMAP.md +1 -1
  191. package/examples/styletest/GAMEMAP.md +2 -2
  192. package/examples/styletest/main.js +1 -1
  193. package/examples/techniques/interior-light/README.md +3 -3
  194. package/examples/techniques/interior-light/interiorLight.js +2 -4
  195. package/examples/techniques/interior-light/picture/lights.js +2 -1
  196. package/examples/techniques/modular-building/picture/lights.js +3 -1
  197. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  198. package/examples/techniques/procedural-animation/README.md +1 -1
  199. package/examples/techniques/procedural-animation/main.js +1 -1
  200. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  201. package/examples/world/GAMEMAP.md +2 -3
  202. package/examples/world/art/humanoid.js +1 -1
  203. package/examples/world/main.js +6 -3
  204. package/index.d.ts +2 -2
  205. package/llms.txt +101 -0
  206. package/modules/ambience/Ambience.js +21 -5
  207. package/modules/calendar/index.js +9 -5
  208. package/modules/calendar/schedule.js +23 -8
  209. package/modules/camera/FirstPersonCamera.js +3 -1
  210. package/modules/camera/FollowCamera.js +10 -5
  211. package/modules/camera/RtsCamera.js +4 -3
  212. package/modules/camera/common.js +70 -8
  213. package/modules/camera/contract.js +1 -1
  214. package/modules/characters/Character.js +16 -10
  215. package/modules/characters/NPC.js +31 -19
  216. package/modules/characters/assetModel.js +14 -9
  217. package/modules/characters/astar.js +6 -1
  218. package/modules/characters/contract.js +2 -2
  219. package/modules/characters/index.js +34 -22
  220. package/modules/characters/movers/manual.js +1 -1
  221. package/modules/characters/movers/rapier.js +17 -2
  222. package/modules/characters/movers/simple.js +1 -1
  223. package/modules/characters/movers/support.js +16 -7
  224. package/modules/characters/npcAvoid.js +2 -2
  225. package/modules/characters/npcSim.js +3 -2
  226. package/modules/characters/pathAsync.js +24 -8
  227. package/modules/characters/pathJob.js +1 -1
  228. package/modules/characters/player.js +10 -9
  229. package/modules/characters/playerStrings.js +5 -5
  230. package/modules/characters/proceduralRig.js +5 -5
  231. package/modules/characters/useModel.js +6 -0
  232. package/modules/characters/walkTo.js +1 -1
  233. package/modules/collision/Collision.js +29 -18
  234. package/modules/collision/grid.js +22 -4
  235. package/modules/content/index.js +3 -1
  236. package/modules/content/loader.js +1 -1
  237. package/modules/content/models.js +82 -33
  238. package/modules/content/props.js +2 -1
  239. package/modules/content/rules.js +11 -5
  240. package/modules/content/templates.js +3 -3
  241. package/modules/content/words.js +2 -2
  242. package/modules/debug/DebugPanel.js +9 -9
  243. package/modules/flow/index.js +9 -6
  244. package/modules/gameplay/Dialogue.js +34 -20
  245. package/modules/gameplay/Interactions.js +19 -15
  246. package/modules/gameplay/Inventory.js +9 -4
  247. package/modules/gameplay/Quests.js +12 -10
  248. package/modules/gameplay/pickups.js +23 -11
  249. package/modules/grid/index.js +1 -1
  250. package/modules/grid/preview.js +2 -2
  251. package/modules/grid/tiles.js +1 -1
  252. package/modules/hlod/index.js +4 -1
  253. package/modules/hud/index.js +47 -10
  254. package/modules/hud/parts.js +28 -9
  255. package/modules/level/geometry.js +8 -3
  256. package/modules/level/index.js +10 -5
  257. package/modules/level/load.js +4 -2
  258. package/modules/lights/sources.js +1 -1
  259. package/modules/music/Music.js +22 -4
  260. package/modules/nav/index.js +20 -10
  261. package/modules/particles/Particles.js +31 -14
  262. package/modules/particles/effect.js +20 -5
  263. package/modules/particles/lit.js +72 -0
  264. package/modules/photo/Photo.js +72 -28
  265. package/modules/photo/pathTrace.js +106 -0
  266. package/modules/rigid/RigidBodies.js +23 -14
  267. package/modules/rigid/Vehicles.js +3 -13
  268. package/modules/rigid/sync.js +2 -1
  269. package/modules/settings/Settings.js +52 -20
  270. package/modules/settings/apply.js +23 -9
  271. package/modules/settings/sections.js +39 -6
  272. package/modules/settings/strings.js +2 -0
  273. package/modules/settings/view.js +19 -3
  274. package/modules/sky/dome.js +15 -3
  275. package/modules/sky/environment.js +28 -12
  276. package/modules/sky/fog.js +1 -1
  277. package/modules/sky/frame.js +6 -1
  278. package/modules/sky/shader.js +4 -3
  279. package/modules/sky/skyModule.js +8 -4
  280. package/modules/swarm/Swarm.js +1 -1
  281. package/modules/terrain/ChunkManager.js +61 -15
  282. package/modules/terrain/chunkJob.js +2 -2
  283. package/modules/terrain/index.js +20 -5
  284. package/modules/terrain/terrainEdit.js +8 -4
  285. package/modules/terrain/terrainTexture.js +4 -2
  286. package/modules/timeline/Timeline.js +4 -3
  287. package/modules/timeline/Tween.js +3 -0
  288. package/modules/timeline/letterbox.js +1 -0
  289. package/modules/triggers/index.js +36 -17
  290. package/modules/vegetation/Vegetation.js +81 -19
  291. package/modules/vegetation/densityMap.js +13 -8
  292. package/modules/vegetation/draw.js +147 -24
  293. package/modules/vegetation/groundChunks.js +20 -5
  294. package/modules/vegetation/index.js +3 -3
  295. package/modules/vegetation/modelGeometry.js +9 -4
  296. package/modules/water/Water.js +11 -8
  297. package/modules/weather/Weather.js +7 -2
  298. package/modules/weather/shaders.js +25 -5
  299. package/modules/weather/weatherDraw.js +20 -6
  300. package/modules/world/World.js +2 -1
  301. package/modules/world/index.js +2 -2
  302. package/modules/world/persist.js +6 -2
  303. package/modules/world/views.js +15 -2
  304. package/package.json +4 -1
  305. package/presets.js +5 -5
  306. package/render/PostFX.js +84 -41
  307. package/render/backend.js +137 -16
  308. package/render/cascades.js +3 -1
  309. package/render/cascades.tsl.js +2 -0
  310. package/render/daylight.js +7 -1
  311. package/render/detail.js +7 -4
  312. package/render/effects.js +27 -8
  313. package/render/fogLook.js +24 -0
  314. package/render/fuse.js +5 -2
  315. package/render/fx/detail.tsl.js +9 -7
  316. package/render/fx/index.js +7 -2
  317. package/render/fx/library.tsl.js +1 -0
  318. package/render/fx/lightShaft.tsl.js +114 -0
  319. package/render/fx/noise.tsl.js +25 -8
  320. package/render/fx/objectOrigin.tsl.js +39 -10
  321. package/render/fx/particles.tsl.js +23 -6
  322. package/render/fx/patchNodes.tsl.js +17 -12
  323. package/render/fx/pcss.tsl.js +51 -0
  324. package/render/fx/postWebGPU.tsl.js +89 -29
  325. package/render/fx/sky.tsl.js +3 -9
  326. package/render/fxNumbers.js +10 -4
  327. package/render/impostor.tsl.js +107 -0
  328. package/render/lighting.js +33 -1
  329. package/render/lightmap.js +42 -28
  330. package/render/lights.js +19 -3
  331. package/render/materials.js +6 -4
  332. package/render/mergeCommon.js +4 -1
  333. package/render/occlusion.js +14 -4
  334. package/render/patches.js +79 -41
  335. package/render/postRuns.js +32 -0
  336. package/render/postWebGL.js +97 -10
  337. package/render/probes.js +10 -14
  338. package/render/shaderErrors.js +2 -1
  339. package/render/shadowCache.tsl.js +33 -5
  340. package/render/shadows.js +42 -16
  341. package/render/slots.js +8 -5
  342. package/render/vertexInputs.js +52 -0
  343. package/types/core.d.ts +114 -46
  344. package/types/gameplay.d.ts +56 -23
  345. package/types/generated/core/audio/Audio.d.ts +27 -1
  346. package/types/generated/core/base/Random.d.ts +1 -1
  347. package/types/generated/core/input/Input.d.ts +6 -8
  348. package/types/generated/core/input/inputSeat.d.ts +1 -1
  349. package/types/generated/core/inspect/Budget.d.ts +26 -0
  350. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  351. package/types/generated/core/saves/Saves.d.ts +10 -7
  352. package/types/generated/core/saves/session.d.ts +8 -2
  353. package/types/generated/core/scene/Rays.d.ts +1 -3
  354. package/types/generated/modules/particles/Particles.d.ts +1 -1
  355. package/types/generated/modules/world/World.d.ts +2 -1
  356. package/types/generated/render/PostFX.d.ts +35 -9
  357. package/types/physics.d.ts +796 -764
  358. package/types/pixel.d.ts +1 -1
  359. package/types/tsl.d.ts +62 -1
  360. package/types/world.d.ts +12 -3
  361. package/ui/Focus.js +7 -5
  362. package/ui/Parts.js +1 -1
  363. package/ui/touchPart.js +6 -3
@@ -1,5 +1,10 @@
1
1
  # Grid placement: towers, furniture, buildings, crops
2
2
 
3
+ > **Covers:** grid placement: cells, layers per cell, preview, baked vs changing state.
4
+ > **Use when:** towers, furniture, buildings or crops on cells.
5
+ > **Shortest:** `engine.grids.add('board', { cell: 1, size: [16, 12] })`.
6
+ > **Sections:** 1 Grids and items · 2 Place, pick up · 3 Layers per-cell state · 4 Preview · Materials · 5 Baked data vs · 6 Verify
7
+
3
8
  Requires module `grids()` and `world()` (`openWorld()` includes world; grids is opt-in and costs nothing when not installed). The API list is in
4
9
  `../api/grids.md`.
5
10
  A grid turns world positions into cells. Things placed on it are ordinary `engine.world` records; per-cell state that is not a thing (tilled soil, wet
@@ -11,15 +16,15 @@ Works on any ground: procedural terrain, a Blender level, an indoor floor. Heigh
11
16
  ```js
12
17
  import { grids, toast } from 'threedog';
13
18
  engine.use(grids());
14
- const board = engine.grids.add('board', { cell: 1, origin: [0, 0], size: [16, 12] }); // several grids may exist: a tower-defense board,
15
- const room = engine.grids.add('room', { cell: 0.5, origin: [-3, -3], size: [12, 12], zone: 'house' }); // a dungeon or house room,
16
- const plot = engine.grids.add('plot', { cell: 1, origin: [20, 0], size: [8, 8] }); // a garden plot
19
+ const board = engine.grids.add('board', { cell: 1, origin: [0, 0], size: [16, 12] }); // several grids may exist: a tower-defense board,
20
+ const room = engine.grids.add('room', { cell: 0.5, origin: [-3, -3], size: [12, 12], zone: 'house' }); // a dungeon or house room,
21
+ const plot = engine.grids.add('plot', { cell: 1, origin: [20, 0], size: [8, 8] }); // a garden plot
17
22
 
18
- engine.grids.define('tower', { size: [2, 2], kind: 'tower', fields: { level: 1 } }); // 2x2 cells on the board
19
- engine.grids.define('crop', { layer: { soil: 'tilled' }, fields: { plantedAt: 0 } }); // only on cells whose soil layer has tilled
23
+ engine.grids.define('tower', { size: [2, 2], kind: 'tower', fields: { level: 1 } }); // 2x2 cells on the board
24
+ engine.grids.define('crop', { layer: { soil: 'tilled' }, fields: { plantedAt: 0 } }); // only on cells whose soil layer has tilled
20
25
  engine.grids.define('bed', { size: [2, 1], kind: 'furniture', fields: { model: 'bed' } }); // 2x1 cells; world record kind 'furniture'
21
- engine.grids.define('shed', { size: [3, 2], ground: ['grass', 'dirt'], flat: 0.2 }); // engine.groundType must match; max 0.2 m height difference
22
- engine.grids.define('crate', { size: [1, 1], can: (e, { cell }) => (cell[1] > 2 ? true : 'tooCloseToRoad') }); // your own rule
26
+ engine.grids.define('shed', { size: [3, 2], ground: ['grass', 'dirt'], flat: 0.2 }); // engine.groundType must match; max 0.2 m height difference
27
+ engine.grids.define('crate', { size: [1, 1], can: (e, { cell }) => (cell[1] > 2 ? true : 'tooCloseToRoad') }); // your own rule
23
28
  ```
24
29
  Coordinates: `board.toCell(pos)` -> `[i, j]`, `board.toWorld(cell, size?, rotation?)` -> footprint center on the ground as a plain `{ x, y, z }` (not a Vector3:
25
30
  `obj.position.copy(board.toWorld(c))`), `board.snap(pos)`,
@@ -28,10 +33,10 @@ Cell `[0, 0]` starts at `origin`. A footprint is anchored at its min corner; `ro
28
33
 
29
34
  ## 2. Place, pick up, move: always ops
30
35
  ```js
31
- engine.ops.run('grid.place', { grid: 'room', item: 'bed', cell: [4, 4], rotation: 1 }); // { ok, value: record id } or { ok: false, code, facts, nextActions }
32
- engine.ops.run('grid.move', { id: 'furniture-3', cell: [6, 2], rotation: 0 }); // its own cells do not block it; grid: 'room' moves it to another grid
33
- engine.ops.run('grid.remove', { id: 'furniture-3' }); // value { item, kind }: put it back in the bag yourself
34
- board.can('tower', [3, 5]); // ask only: true or a failure code string
36
+ engine.ops.run('grid.place', { grid: 'room', item: 'bed', cell: [4, 4], rotation: 1 }); // { ok, value: record id } or { ok: false, code, facts, nextActions }
37
+ engine.ops.run('grid.move', { id: 'furniture-3', cell: [6, 2], rotation: 0 }); // its own cells do not block it; grid: 'room' moves it to another grid
38
+ engine.ops.run('grid.remove', { id: 'furniture-3' }); // value { item, kind }: put it back in the bag yourself
39
+ board.can('tower', [3, 5]); // ask only: true or a failure code string
35
40
  ```
36
41
  Failure codes: `outOfBounds` `occupied` `wrongGround` `notFlat` `not<Field>` (from a layer rule: `notTilled`) `noGrid` `idTaken` `unknown` `notPlaced`
37
42
  `badFields` (fields that set id / kind / grid / position / rot, which the placement owns), or your `can` code.
@@ -51,10 +56,10 @@ ops guard; a record added by hand that overlaps another is reported and the cell
51
56
  **Occupancy layers and levels.** An item takes cells in its own occupancy layer (`occupy`, default `'main'`), so things in different layers share
52
57
  a cell and two in one layer do not; `level` is a storey (integer, default 0) with its own cells.
53
58
  ```js
54
- engine.grids.define('tile', { occupy: 'floor' }); // floor tiles, rugs, paint marks
55
- engine.grids.define('lamp', { occupy: 'wall' }); // wall-hung things
56
- engine.grids.define('sofa', { size: [2, 1] }); // 'main': a sofa stands on a tile, a second sofa there is 'occupied'
57
- engine.ops.run('grid.place', { grid: 'room', item: 'sofa', cell: [2, 2], level: 1 }); // upstairs: y = (grid y or the ground) + 1 * levelHeight
59
+ engine.grids.define('tile', { occupy: 'floor' }); // floor tiles, rugs, paint marks
60
+ engine.grids.define('lamp', { occupy: 'wall' }); // wall-hung things
61
+ engine.grids.define('sofa', { size: [2, 1] }); // 'main': a sofa stands on a tile, a second sofa there is 'occupied'
62
+ engine.ops.run('grid.place', { grid: 'room', item: 'sofa', cell: [2, 2], level: 1 }); // upstairs: y = (grid y or the ground) + 1 * levelHeight
58
63
  room.at([2, 2], { occupy: 'floor', level: 0 }); room.stack([2, 2]); // one layer's record id; every layer's on that cell { floor, main }
59
64
  ```
60
65
  `grids.add(name, { y, levelHeight })`: `y` fixes level 0's height (default: the ground under each cell), `levelHeight` is meters per level (default 3);
@@ -64,15 +69,15 @@ used by `toCell`, `toWorld`, tiles and flatness (footprints stay rectangles of c
64
69
 
65
70
  ## 3. Layers: per-cell state (soil, creep, paint)
66
71
  ```js
67
- const soil = plot.layer('soil', { tiles: true }); // created on first use, options read then; saved with the game (only cells that differ from content)
72
+ const soil = plot.layer('soil', { tiles: true }); // created on first use, options read then; saved with the game (only cells that differ from content)
68
73
  engine.ops.define('plot.till', { args: { cell: 'any' },
69
74
  can: (e, { cell }) => (!plot.inside(cell) ? 'outOfBounds' : plot.at(cell) ? 'occupied' : true),
70
75
  run: (e, { cell }) => soil.set(cell, { tilled: true }) });
71
76
  engine.ops.define('plot.water', { args: { cell: 'any' },
72
77
  can: (e, { cell }) => (soil.get(cell)?.tilled ? true : 'notTilled'),
73
78
  run: (e, { cell }) => soil.set(cell, { watered: true }) });
74
- engine.ops.define('plot.dry', { run: () => soil.updateAll(d => { delete d.watered; }) }); // bulk change; return null from fn to clear a cell
75
- engine.calendar.at('06:00', () => engine.ops.run('plot.dry')); // daily reset is the game's job
79
+ engine.ops.define('plot.dry', { run: () => soil.updateAll(d => { delete d.watered; }) }); // bulk change; return null from fn to clear a cell
80
+ engine.calendar.at('06:00', () => engine.ops.run('plot.dry')); // daily reset is the game's job
76
81
  ```
77
82
  `get(cell)`, `set(cell, patch)` (merge; a field set to null is deleted), `clear(cell)`, `query(cell?, size?)` -> `[{ cell, data }]`, `updateAll(fn)`, `count`.
78
83
  Writes are saved gameplay state: do them inside an op or a fixed step (the guard reports anything else). Data must be plain values.
@@ -88,13 +93,13 @@ height (slopes, ramps, level meshes).
88
93
 
89
94
  ## 4. Preview
90
95
  ```js
91
- engine.input.action('place', { label: 'Place', keys: ['Mouse0'] }); // gameplay reads input actions, not pointer.clicked (recipe 26)
92
- engine.input.bind(presets.bindings.gridRotate); // R turns it (action 'rotate')
93
- const pv = engine.grids.preview({ grid: 'board', item: 'tower' }); // under the pointer; from: 'front' = the cell in front of the player
96
+ engine.input.define('place', { label: 'Place', keys: ['Mouse0'] }); // gameplay reads input actions, not pointer.clicked (recipe 26)
97
+ engine.input.bind(presets.bindings.gridRotate); // R turns it (action 'rotate')
98
+ const pv = engine.grids.preview({ grid: 'board', item: 'tower' }); // under the pointer; from: 'front' = the cell in front of the player
94
99
  engine.onFrame(() => {
95
- if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.code)); } // 'noTarget' or a grid.place code
100
+ if (engine.input.pressed('place')) { const r = pv.place(); if (!r.ok) toast(engine, engine.t('grid.' + r.code)); } // 'noTarget' or a grid.place code
96
101
  });
97
- pv.remove(); // leave build mode
102
+ pv.remove(); // leave build mode
98
103
  ```
99
104
  The engine binds no key: the preview declares the action `rotate` (gone with the preview); `presets.bindings.gridRotate` binds it to R, or bind it yourself with
100
105
  `engine.input.bind('rotate', ['KeyR'])`; pass `rotate: 'myAction'` to read another one, `false` for none. Without a binding the preview warns once and only `pv.rotate()` turns
@@ -118,14 +123,14 @@ tile (survival), a road or placed floor (city builder), a painted tile (puzzle),
118
123
  valleys, coast). Runtime state is a grid cell (`layer`), a `terrain.edit` (lower / raise / paint a ground type) or a world record (`grid.place`); all three are
119
124
  saved, while a baked version cannot be changed in game and is not saved. A save keeps only what differs from the generated base.
120
125
  ```js
121
- engine.use(terrain({ height: (x, z) => 3 + Math.sin(x * 0.05) * 2 }), world(), grids()); // generated: the landform only
126
+ engine.use(terrain({ height: (x, z) => 3 + Math.sin(x * 0.05) * 2 }), world(), grids()); // generated: the landform only
122
127
  engine.grids.add('plots', { cell: 4, origin: [8, 16], size: [4, 4] });
123
128
  engine.ops.define('plot.dig', { args: { cell: 'any' },
124
129
  can: (e, { cell }) => (e.grids.get('plots').inside(cell) ? true : 'outOfBounds'),
125
130
  run: (e, { cell }) => {
126
- const [x, z] = [8 + cell[0] * 4 + 2, 16 + cell[1] * 4 + 2]; // cell centre
127
- e.terrain.edit({ x, z }, { shape: 'square', radius: 2, lower: 0.5, paint: 'dug' }); // ground shape and type
128
- e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
131
+ const [x, z] = [8 + cell[0] * 4 + 2, 16 + cell[1] * 4 + 2]; // cell centre
132
+ e.terrain.edit({ x, z }, { shape: 'square', radius: 2, lower: 0.5, paint: 'dug' }); // ground shape and type
133
+ e.grids.get('plots').layer('state').set(cell, { dug: true }); // per-cell game state
129
134
  } });
130
135
  ```
131
136
  Undo with `paint: null` and `raise`.
@@ -1,28 +1,29 @@
1
1
  # Templates: reusable objects, definition vs instance state
2
2
 
3
- **In this recipe**: 1. Define a template · 2. Place instances · 3. What belongs to the definition, what to the instance ·
4
- 5. Point -> thing · 6. When to use a template · 7. A group of things
3
+ > **Covers:** templates: one kind of object defined once, placed many times, instance state.
4
+ > **Use when:** many objects of the same kind.
5
+ > **Shortest:** a template entry in content data, then instances (§1, §2).
6
+ > **Sections:** 1 Define a template · 2 Place instances · 3 What belongs to · 5 Point -> thing · 6 When to use · 7 A group of
5
7
 
6
8
  Requires `world()` (in `openWorld()`); a template with `interact` needs `interactions({ ...presets.interactions.nearest })`, with `container` needs
7
9
  `inventory()`.
8
10
 
9
- A **template** describes one kind of object once: its model, collision, interaction, container, sound, animation and the default values of its saved
10
- state. Every chest, campfire or bed you place is an **instance**: a world record that names the template (its `kind` is the template name) and holds
11
- only its own state. There is no inheritance and no variant layer; a different look or behaviour is another template, and a template is plain JS, so
12
- `{ ...chest, model: 'iron-chest' }` is that other template in one line.
11
+ A **template** describes one kind of object once: model, collision, interaction, container, sound, animation and the defaults of its saved state. Each
12
+ placed one is an **instance**: a world record whose `kind` is the template name, holding only its own state. No inheritance or variants: another look is
13
+ another template, `{ ...chest, model: 'iron-chest' }`.
13
14
 
14
15
  ## 1. Define a template
15
16
  `games/<game>/content/templates.js` (add it to `content/index.js`):
16
17
  ```js
17
18
  export default {
18
19
  chest: {
19
- model: 'chest', // an asset name (file or generator of an asset pack, the same name pickups and vegetation take); every chest clones one shared prototype
20
- collide: 'box', // 'box' = the model's bounds; 'circle' = a cylinder on its base; omitted = does not block
21
- state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
22
- interact: { label: rec => rec.opened ? '关上' : '打开', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
23
- container: { capacity: 6, items: { berry: 2 } }, // each chest gets a container whose id is the record id; items = starting goods (placed once)
24
- sound: { use: 'chest' }, // engine.audio.sfx after a successful use
25
- animate: (rec, obj, dt) => { obj.children[0].rotation.x = rec.opened ? -1.1 : 0; }, // per-frame look from the record, only while the model exists
20
+ model: 'chest', // an asset name (file or generator of an asset pack, the same name pickups and vegetation take); every chest clones one shared prototype
21
+ collide: 'box', // 'box' = the model's bounds; 'circle' = a cylinder on its base; omitted = does not block
22
+ state: { opened: false }, // instance fields and their defaults, copied onto each record and saved
23
+ interact: { label: rec => rec.opened ? 'Close' : 'Open', op: 'chest.toggle', radius: 2 }, // using it runs the op with { id }
24
+ container: { capacity: 6, items: { berry: 2 } }, // each chest gets a container whose id is the record id; items = starting goods (placed once)
25
+ sound: { use: 'chest' }, // engine.audio.sfx after a successful use
26
+ animate: (rec, obj, dt) => { obj.children[0].rotation.x = rec.opened ? -1.1 : 0; }, // per-frame look from the record, only while the model exists
26
27
  },
27
28
  };
28
29
  ```
@@ -72,7 +73,7 @@ spot near the river) stay in code and come in through `content.load(data, { plac
72
73
  has now (`-`/`+` lines, dry run); `--write` writes them into the content files. Writing today's id changes nothing for old saves. To give an entry a
73
74
  readable id later, change it and add the pair to `content/renames.js`: <!-- r18-ignore-line -->
74
75
  ```js
75
- export default { 'chest:3': 'chest-home', 'prop:rock:12': null }; // old id -> new id; null = deleted on purpose
76
+ export default { 'chest:3': 'chest-home', 'prop:rock:12': null }; // old id -> new id; null = deleted on purpose
76
77
  ```
77
78
  Loading a save then moves its changes, removal, owed time and container goods from `chest:3` to `chest-home` (save loaded before or after content),
78
79
  and drops `prop:rock:12`'s data quietly. `npm run check` errors on a target no entry defines and on a source content still defines; dev warns about an
@@ -112,13 +113,13 @@ export default {
112
113
  crop: {
113
114
  model: 'crop-seed', state: { watered: false },
114
115
  stages: [{ name: 'seed', duration: 600 }, { name: 'sprout', duration: 900, scale: 0.6 }, { name: 'ripe', model: 'crop-ripe' }],
115
- canGrow: rec => rec.watered, // asked every step, near and far; false holds the stage and blocked time does not count
116
- interact: { label: 'Water', op: 'crop.water' }, // an interaction is always an op, run with { id }
116
+ canGrow: rec => rec.watered, // asked every step, near and far; false holds the stage and blocked time does not count
117
+ interact: { label: 'Water', op: 'crop.water' }, // an interaction is always an op, run with { id }
117
118
  },
118
119
  turret: {
119
120
  model: 'turret', state: { heat: 0 },
120
121
  stages: [{ name: 'cold', duration: 5 }, { name: 'armed' }],
121
- update: (rec, dt, e) => { if (rec.stage === 1) rec.heat = Math.min(1, rec.heat + dt); }, // every fixed step while near
122
+ update: (rec, dt, e) => { if (rec.stage === 1) rec.heat = Math.min(1, rec.heat + dt); }, // every fixed step while near
122
123
  },
123
124
  };
124
125
  ```
@@ -156,9 +157,9 @@ plus the changing values on the record, and wrap the table with `Object.freeze`
156
157
  Runtime ops change only the current session and its saves. To change the level itself, edit the content files or the level model, then reload. To find
157
158
  the entry, ask the engine what a thing is:
158
159
  ```js
159
- const t = engine.pick(0, 0)?.thing; // what is in the middle of the screen
160
+ const t = engine.pick(0, 0)?.thing; // what is in the middle of the screen
160
161
  // { id: 'chest-home', kind: 'chest', template: 'chest', definedAt: 'content/props.js:14', templateAt: 'content/templates.js:3', fields: { opened: false }, edit: 'defined in content/props.js:14: …' }
161
- engine.world.origin('chest-home'); // the same source info for an id
162
+ engine.world.origin('chest-home'); // the same source info for an id
162
163
  ```
163
164
  `hit.thing` is on every `engine.pick` / `engine.raycast` hit (computed when read); a hit on a batched copy resolves to its original object.
164
165
  `engine.inspect(id).thing` and `engine.explain({ op, args: { id } })` say the same. A hit on a plain object added with `engine.add` gets its
@@ -201,7 +202,7 @@ save follows the new place too. Only places in `places.js` (or the `places` of `
201
202
 
202
203
  **`source`** (experimental, with `content stamp` and `content capture`) is a plain optional string on a model or template entry, naming what the entry was copied from. It has no effect at runtime; it is there to ask:
203
204
  ```js fragment
204
- engine.world.query({ where: r => r.source === 'stall' }); // every thing copied from that arrangement
205
+ engine.world.query({ where: r => r.source === 'stall' }); // every thing copied from that arrangement
205
206
  ```
206
207
  **Moving entries by hand.** On the dev server press F2 (or add `?edit=1` to the address), click an entry and drag its handle: letting go writes `x` and `z` into its content file, as an offset when it stands on a place. Comments and alignment stay. A value someone changed since the click is refused, and code-built entries and things added by code say why they cannot be saved.
207
208
 
@@ -1,5 +1,10 @@
1
1
  # Sound: buses, sounds by name, ambience rules, music, footsteps, ducking
2
2
 
3
+ > **Covers:** sound: buses, sounds by name, ambience rules, music, footsteps, ducking, settings, reverb.
4
+ > **Use when:** anything the player hears.
5
+ > **Shortest:** `createEngine({ audio: { levels: { music: 0.4 } } })`, then sounds by name.
6
+ > **Sections:** 1 Config in one · 2 Buses and sounds · 3 Ambience sounds by place · 4 Music rules, cross-fade · 5 Footsteps by surface · 6 Ducking · 7 Settings · 8 Sounds as content · 9 Reverb
7
+
3
8
  Everything you hear is the game's. The engine ships no sound files and plays nothing the game did not name; built-in synths (`footstep`, `shutter`,
4
9
  `thunder`, `wind`, `rain`, `water`, `birds`, `crickets`) stay silent until `audio.sounds` asks for them. Signatures: `api/audio.md`,
5
10
  `api/ambience.md`, `api/music.md`.
@@ -9,22 +14,22 @@ Two places, one job each: **the asset manifest says what a sound is** (a file, o
9
14
  model), **`audio.sounds` says how it plays** (which sound or variants, volume, bus, cooldown...).
10
15
  ```js
11
16
  const engine = createEngine({ canvas, audio: {
12
- levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
17
+ levels: { music: 0.4, voice: 1 }, // volume per bus; an extra key (voice) adds a bus
13
18
  sounds: {
14
- door: {}, // the asset of the same name, default rules
15
- hit: ['hit1', 'hit2'], // variants: random, never the same one twice in a row
19
+ door: {}, // the asset of the same name, default rules
20
+ hit: ['hit1', 'hit2'], // variants: random, never the same one twice in a row
16
21
  shot: { src: 'shot', jitter: { pitch: 0.08, volume: 0.1 }, cooldown: 0.05, voices: 4, distance: { ref: 3, max: 80 } },
17
- footstep: {}, // a built-in synth asset, named so it plays
18
- 'step.sand': { src: 'footstep', params: { surface: 'sand' } }, // a synth source with parameters
22
+ footstep: {}, // a built-in synth asset, named so it plays
23
+ 'step.sand': { src: 'footstep', params: { surface: 'sand' } }, // a synth source with parameters
19
24
  wind: {}, birds: {}, ding: { volume: 0.6 },
20
25
  },
21
26
  ambience: [ /* rule table, section 3 */ ],
22
27
  music: { tracks: { /* section 4 */ }, rules: [] },
23
- footsteps: { beach: 'step.sand', default: 'footstep' }, // section 5
28
+ footsteps: { beach: 'step.sand', default: 'footstep' }, // section 5
24
29
  } });
25
30
  engine.assets.manifest({ name: 'sfx', sounds: {
26
31
  door: '/sfx/door.ogg', hit1: '/sfx/hit1.ogg', hit2: '/sfx/hit2.ogg', shot: '/sfx/shot.ogg',
27
- ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
32
+ ding: (a, p, out) => { a.tone({ freq: 880 * p.pitch, dur: 0.2, out }); return 0.2; }, // a synth: connect to out, return seconds (or { stop(t) })
28
33
  } });
29
34
  ```
30
35
  Code may hold functions (a `volume: e => ...`); the same config as data goes in a content pack (section 8). A full working one:
@@ -36,10 +41,10 @@ Buses are real Web Audio `GainNode`s: `master`, `music`, `sfx`, `ambience`, `ui`
36
41
  unlocks on the player's first click or key: build your own nodes on the `audio:ready` event. A name that is no bus warns once and gives `master`, so the sound still plays.
37
42
 
38
43
  ```js fragment
39
- engine.audio.sfx('door'); // plays on its bus (default sfx)
40
- const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
44
+ engine.audio.sfx('door'); // plays on its bus (default sfx)
45
+ const h = engine.audio.sfx('shot', { at: enemy.root }); // 3D: a PannerNode that follows the Object3D every frame
41
46
  const hum = engine.audio.sfx('engine-hum', { loop: true, at: [4, 0, 2] });
42
- hum?.fade({ to: 0.2, seconds: 1.5 }); hum?.stop({ fade: 1 }); // the handle (null while silent, see below): fade({ to, seconds }), stop({ fade }), remove(), setPosition(at)
47
+ hum?.fade({ to: 0.2, seconds: 1.5 }); hum?.stop({ fade: 1 }); // the handle (null while silent, see below): fade({ to, seconds }), stop({ fade }), remove(), setPosition(at)
43
48
  engine.audio.sfx('click', { bus: 'ui' });
44
49
  ```
45
50
  `sfx` returns `null` when the sound is silent: neither a rule nor an asset of that name, a built-in synth no rule names, audio still locked (before
@@ -52,13 +57,13 @@ until the rules load again, instead of refetching.
52
57
 
53
58
  A synth with default params is `{ build: synthFn, params }` in the manifest.
54
59
 
55
- ## 3. Ambience: a rule table
56
- Each rule names a sound and says when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
60
+ ## 3. Ambience: sounds by place (a rule table)
61
+ Drips in a cave, a river near water, birds by day: one rule each, no per-frame code, naming a sound, when and how loud. A rule with `every` is a one-shot at random gaps; without, a loop that fades in and out (and stops
57
62
  when silent, so idle rules cost nothing).
58
63
  ```js
59
64
  ambience: [
60
- { sound: 'wind', volume: e => 0.05 + (e.weather?.current.wind ?? 0) * 0.08 }, // volume can follow the moment
61
- { sound: 'river', volume: (e, a) => a.nearWater(12) * 0.12 }, // a = engine.ambience (position, nearWater)
65
+ { sound: 'wind', volume: e => 0.05 + (e.weather?.current.wind ?? 0) * 0.08 }, // volume can follow the moment
66
+ { sound: 'river', volume: (e, a) => a.nearWater(12) * 0.12 }, // a = engine.ambience (position, nearWater)
62
67
  { sound: 'cave-drip', when: { zone: 'cave' }, volume: 0.6, fade: 2 },
63
68
  { sound: 'birds', when: { time: 'day', weather: ['clear', 'cloudy'] }, every: [2, 7] },
64
69
  { sound: 'war-drums', when: { state: 'combat' }, volume: 0.5 },
@@ -77,13 +82,13 @@ engine.use(music({ tracks: {
77
82
  combat: { url: '/music/combat.ogg', stems: [{ url: '/music/combat-drums.ogg', at: [0.3, 0.7] }] },
78
83
  }, rules: [
79
84
  { track: 'combat', when: { state: 'combat' }, priority: 10 },
80
- { track: 'explore' }, // no when: the fallback
85
+ { track: 'explore' }, // no when: the fallback
81
86
  ] }));
82
- engine.music.intensity = 0.8; // stems fade in as it rises through their at range
87
+ engine.music.intensity = 0.8; // stems fade in as it rises through their at range
83
88
  ```
84
89
  The same `when` keys as ambience. Tracks cross-fade (`fade`, default 2 s); a new rule result must hold `hold` seconds before switching.
85
90
  `engine.music.override('boss')` picks by hand; `override(null)` hands back to the rules. `engine.music.stinger('win')` plays a short piece over the music.
86
- Decoded music is large (about 21 MB a stereo minute), so it lives like any asset: `assets.release(name)` and `assets.trim()` (a level change calls it) free it, the longest-unused long sounds go by themselves over a memory budget, sounds still playing play on, and a freed sound loads again when played; effects under 10 s stay cached, and `preload: true` keeps a track.
91
+ Decoded music is large (about 21 MB a stereo minute): `assets.release(name)` and `assets.trim()` (a level change calls it) free it, the longest-unused long sounds go by themselves over a memory budget, playing sounds play on, a freed sound loads again when played; effects under 10 s stay cached, and `preload: true` keeps a track.
87
92
 
88
93
  ## 5. Footsteps by surface
89
94
  The player's footstep rhythm follows its speed (one step per foot landing). Each step plays the sound named by `footsteps[groundType]`, else
@@ -92,8 +97,8 @@ property); `water` while swimming.
92
97
 
93
98
  ## 6. Ducking
94
99
  ```js
95
- const d = engine.audio.duck({ music: 0.3, ambience: 0.5 }, { fade: 0.3 }); // lower these buses
96
- engine.events.once('dialogue:end', () => d.remove()); // restore
100
+ const d = engine.audio.duck({ music: 0.3, ambience: 0.5 }, { fade: 0.3 }); // lower these buses
101
+ engine.events.once('dialogue:end', () => d.remove()); // restore
97
102
  ```
98
103
  Ducks stack (levels multiply) and never touch the player's volume setting. `music({ duckDialogue: 0.35 })` ducks the music bus during dialogue for
99
104
  you; it is off by default (whether talking lowers the music is the game's choice).
@@ -107,9 +112,9 @@ A content pack carries the game's audio the way it carries items: data only, sou
107
112
  ```js
108
113
  // content/audio.js (export it from content/index.js like any content file)
109
114
  export default {
110
- sounds: { wind: {}, door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // asset pack sound names (files or synths)
115
+ sounds: { wind: {}, door: 'door', hit: ['hit1', 'hit2'], shot: { src: 'shot', cooldown: 0.05 } }, // asset pack sound names (files or synths)
111
116
  ambience: [
112
- { sound: 'wind', volume: { base: 0.05, add: { wind: 0.08, altitude: 0.00375 }, max: 0.5 } }, // base + measure x factor, clamped
117
+ { sound: 'wind', volume: { base: 0.05, add: { wind: 0.08, altitude: 0.00375 }, max: 0.5 } }, // base + measure x factor, clamped
113
118
  { sound: 'rain', volume: { add: { rain: 0.22 } } },
114
119
  { sound: 'birds', when: { daylight: { gt: 0.15 }, rain: { lt: 0.2 } }, every: [1.5, 6.5] },
115
120
  ],
@@ -119,7 +124,7 @@ export default {
119
124
  ```
120
125
  ```js fragment
121
126
  engine.assets.manifest({ name: 'sfx', base: '/sounds/', sounds: { door: 'door.ogg', hit1: 'hit1.ogg', hit2: 'hit2.ogg', shot: 'shot.ogg', 'music-day': 'day.ogg' } });
122
- engine.content.load([base, forest]); // each pack's audio merges in
127
+ engine.content.load([base, forest]); // each pack's audio merges in
123
128
  ```
124
129
  - **Names, never paths or code.** A sounds string is a sound name from an asset pack, a file or a synth (`engine.audio.load` and music resolve it
125
130
  through `engine.assets`, so a missing file falls back to silence as an `engine.loading` task). A file path warns in dev; a function anywhere in the
@@ -132,3 +137,15 @@ engine.content.load([base, forest]); // each pack's audio merges in
132
137
  `createEngine({ audio })` or `music({ tracks })` is an error (`[audio-name-clash]`). `ambience` and `music.rules` concatenate after the game's own.
133
138
  Loading a named pack again replaces its rules (hot reload).
134
139
  - `levels` (bus volumes) stay in `createEngine({ audio })`: they are settings, not content.
140
+
141
+ ## 9. Reverb (echo of a cave or a hall)
142
+ One reverb send/return on the buses, off until asked:
143
+ ```js
144
+ engine.audio.reverb({ sends: { sfx: 0.5, ambience: 0.8 }, decay: 3, size: 0.8, wet: 0.4 }); // which buses echo and how much; the room
145
+ engine.audio.reverb({ wet: 0.1, fade: 1 }); // later calls change only what they name; null turns it off
146
+ ```
147
+ `decay` is the seconds to fall 60 dB, `size` (0-1) the pre-gap and build-up, `wet` how much comes back (api/audio.md). Size or decay rebuilds the impulse; wet and sends only fade. Cost: one convolution for any number of sounds. A place can set wet with an ambience rule (same `when`; content packs too):
148
+ ```js fragment
149
+ { reverb: 0.7, when: { zone: 'cave' }, fade: 2 }, // in audio.ambience; the highest holding rule wins, none gives the game's wet back
150
+ ```
151
+ `engine.audio.info.reverb` shows the targets (`place` while a rule holds). A reverb rule plays no sound (no sound / volume / every / bus on it).
@@ -1,5 +1,10 @@
1
1
  # Action game wiring: hp, attacks, guns, enemy AI, drops, death, win and lose without engine combat rules
2
2
 
3
+ > **Covers:** an action game's own rules: health, attacks, guns, enemy AI, drops, win and lose.
4
+ > **Use when:** combat on top of the engine's systems.
5
+ > **Shortest:** the working example `examples/action/` (§1 says what goes where).
6
+ > **Sections:** 1 What goes where · 2 Rules that keep · 2b Guns hitscan shots · 3 Mouse attack and · 4 Movement jumps, speed
7
+
3
8
  The engine has no health, damage, hit detection or death. An action game writes those as its own rules on top of systems that already exist. The
4
9
  working example is `examples/action/` (page `/action.html`, the rules in `main.js`, the room in `content/`).
5
10
 
@@ -7,7 +12,7 @@ working example is `examples/action/` (page `/action.html`, the rules in `main.j
7
12
  | Piece | Built on | In the example |
8
13
  |---|---|---|
9
14
  | The room, the enemy and its stats (hp, damage, drop) | content `templates` + `props` with ids (recipe 30) | `content/templates.js` `slime: { model, static: false, state: { hp, maxHp, damage, cooldown, drop } }` |
10
- | Player hp, attack cooldown, game over | plain object + `engine.describe.add` + `engine.saves.register` | `const game = fresh()` |
15
+ | Player hp, attack cooldown, game over | plain object + `engine.describe.add` + `engine.saves.define` | `const game = fresh()` |
11
16
  | Attack, damage, enemy hit, death | ops with `can` / `run` (recipe 23), so keys, the dev bridge, MCP, tests and the AI run one rule | `player.attack`, `enemy.damage`, `enemy.attack`, `player.die` |
12
17
  | Enemy AI (chase, face, strike) | `engine.world.simulate(kind, { near, channel? })` (channel: bullet time reaches it, section 4), a fixed step per near record; it strikes with `ops.run(..., { actor: rec.id })` | `world.simulate('slime', ...)` |
13
18
  | Gameplay keys | content `actions` (`attack: { keys: ['Mouse0', 'KeyF'] }`), read with `input.pressed` in `onFixed` | `onFixed` runs `player.attack` |
@@ -24,7 +29,7 @@ working example is `examples/action/` (page `/action.html`, the rules in `main.j
24
29
  - `player.die` decides what death does. The example offers `respawn` (`player.placeAt(spawn)`, full hp), `restart` and `gameover` (both end in
25
30
  `engine.session.newGame()`, which is async flow and so runs from the frame hook, not inside the op).
26
31
  - What a fight sets up, falling undoes. `respawn` leaves the world as it was, so a closed arena gate, a blocked area, a locked camera or a boss phase is still there when the player returns, and a spawn point can end up inside ground that is no longer walkable. Keep one function that undoes the fight and call it from `player.die`; a win calls it too.
27
- - A blow that ends a contact ends it for both sides: a stomp, a dash through or a parry needs a short window in which that enemy cannot hurt the player, or its touch damage lands the step after. Each of these gets a scenario that loses as well as one that wins (recipe 16 section 2b).
32
+ - A blow that ends a contact ends it for both sides: a stomp, a dash through or a parry needs a short window in which that enemy cannot hurt the player, or its touch damage lands the step after. Each of these gets a scenario that loses and one that wins (recipe 16 section 2b).
28
33
  - Win and lose are the game's rule too: one state field, judged last in the fixed step so it sees this step's hits. The end screen is a `makeWindow`
29
34
  with `closable: false` (recipe 26).
30
35
 
@@ -45,15 +50,15 @@ looks, so a swing goes where you aim. The rules do not need the picture: `?pictu
45
50
 
46
51
  ## 4. Movement: jumps, speed effects, bullet time, platforms, falling
47
52
  ```js fragment
48
- engine.characters.createPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
49
- engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
50
- engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
51
- engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
52
- engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
53
- engine.world.simulate('slime', { near: chase, channel: 'enemies' }); // world records (the enemy AI above) get the slowed dt
54
- engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
55
- engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
56
- engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
53
+ engine.characters.addPlayer({ ...presets.player.thirdPerson, maxJumps: 2 }); // double jump: the same jump key twice
54
+ engine.player.launch(16, { owner: 'pad' }); // a jump pad / spring
55
+ engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 }); // haste for 5 s; no id = every character (mud, wind)
56
+ engine.time.channel('enemies'); // once, before anything uses it: a channel of your own
57
+ engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time: enemies on channel 'enemies' at 35%
58
+ engine.world.simulate('slime', { near: chase, channel: 'enemies' }); // world records (the enemy AI above) get the slowed dt
59
+ engine.onFixed(dt => moveShots(dt), { channel: 'enemies' }); // your own enemy logic on the same slowed dt
60
+ engine.characters.support(liftMesh); // a moving platform: move liftMesh any way, riders follow
61
+ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player.mover = 'simple'; // take over, give back
57
62
  ```
58
63
  - **Jumps** (all public, no private fields): `jump()` is buffered for `jumpBuffer` s (default 0.12) and uses coyote time (`coyoteTime`); in the air it is an
59
64
  air jump while `maxJumps` allows, at `airJumpSpeed` (default `jumpSpeed`). `jump({ air: false })` = ground only. `addJumps(n)` / `resetJumps()` for
@@ -79,11 +84,11 @@ engine.player.mover = 'manual'; /* a cutscene, your own physics */ engine.player
79
84
  ```js fragment
80
85
  const raft = new THREE.Group(), deck = new THREE.Mesh(new THREE.BoxGeometry(3, 0.2, 2), wood);
81
86
  raft.add(deck, mast); engine.scene.add(raft);
82
- engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
83
- engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
87
+ engine.characters.support(deck, { id: 'raft' }); // the deck, not the raft with its mast
88
+ engine.onFixed(dt => { raft.position.x += 1.5 * dt; }); // the player on it is carried
84
89
  ```
85
90
  A ride the player does not steer is `engine.control` instead (recipe 57, Moved by script).
86
- - **Falling out**: `createPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe }` once. Take hp in the listener. The rule `fall` decides what happens, and the engine alone decides nothing: `engine.mod('fall', { owner: 'game', set: 'rescue' })` (or `characters({ fall: 'rescue' })`; `openWorld` and the new-game templates choose it) puts the player back on `player.safeGround`, the last spot it stood still on safe, unmoving ground (saved); `set: false` handles it yourself, a function `(facts, engine) => 'rescue' | false` decides per fall (`facts.kind` is `'character'` or `'body'`), and without `id` it covers everything that falls, rigid bodies below y = -200 too.
91
+ - **Falling out**: `addPlayer({ ..., fall: { belowY: -20 } })` fires `character:fall { character, safe }` once. Take hp in the listener. The rule `fall` decides what happens: `engine.mod('fall', { owner: 'game', set: 'rescue' })` (or `characters({ fall: 'rescue' })`; `openWorld` and the new-game templates choose it) puts the player back on `player.safeGround`, the last spot it stood still on safe, unmoving ground (saved); `set: false` handles it yourself, a function `(facts, engine) => 'rescue' | false` decides per fall (`facts.kind` is `'character'` or `'body'`), and without `id` it covers everything that falls, rigid bodies below y = -200 too.
87
92
  - **Your own controller**: `mover: 'manual'` = you write the position; `move()` then only updates `grounded`, `support` (platforms still carry),
88
93
  `safeGround` and the fall check. Switch at any time (`player.mover = 'manual'` / `'simple'`): a cutscene, a grapple, a ladder.
89
94
  - **Knockback / dashes**: `player.push(vx, vz, seconds)`. Writing `player.velocity` or `player.vy` is an impulse: the mover keeps integrating from
@@ -1,9 +1,13 @@
1
1
  # Stream sources: what is loaded where (teleport, far camera)
2
2
 
3
- Part of the world data recipe (`18-world.md`): world records never unload, this page is about the models, terrain and colliders built around them.
3
+ > **Covers:** stream sources: what is loaded around which point (teleport, far camera).
4
+ > **Use when:** the camera or the player jumps far away.
5
+ > **Shortest:** `await engine.stream.teleport([x, y, z])`.
6
+
7
+ Part of `18-world.md`: world records never unload; this page is about the models, terrain and colliders built around them.
4
8
 
5
9
  Three things are kept apart: **what is shown** (terrain chunks, models, stream entries, hlod), **what has colliders** (rigid terrain colliders, chunk
6
- collision), and **world data** (records and their near / far simulation, which follows `world.anchor` and never unloads). Every loader reads the same
10
+ collision), and **world data** (records and their near / far simulation, which follows `world.anchor` and never unloads). Every loader reads one
7
11
  list, the sources of `engine.stream`:
8
12
 
9
13
  | Source | Shows | Colliders |
@@ -17,7 +21,7 @@ list, the sources of `engine.stream`:
17
21
  // a new game or load during the trip abandons it: it rejects with code stream-removed and the player stays
18
22
  await engine.stream.teleport([800, 0, 300]);
19
23
 
20
- // the same by hand (for a door animation or a fade while it loads)
24
+ // the same by hand (for a door animation or a fade)
21
25
  const dest = engine.stream.source([800, 0, 300], { radius: 64 });
22
26
  await dest.whenReady;
23
27
  engine.player.placeAt([800, 0, 300]);
@@ -30,11 +34,11 @@ engine.stream.source(photoCam, { physics: false, until: () => !photoMode.active
30
34
  const vista = engine.stream.source(towerTop, { detail: 'simple', radius: 600 });
31
35
  ```
32
36
  - `radius` caps every loader's own range around that source (terrain view distance, present radius, `stream.radius`); without it each loader uses its own.
33
- - `source.ready` is checked at the end of each frame; a new source counts after one full frame, so every loader has seen it. Fixed steps must run
34
- (collision takes effect on a tick), so do not wait while `engine.haltLoop()` is on without stepping.
35
- - `ready` means nothing is pending, not that everything built: a stream entry or world model whose build failed is reported and left out, and `teleport` still lands. Need a thing built?
36
- Check it yourself: `handle.built`, `engine.world.view(id)`. A failed terrain chunk (recipe 28) is different: no ground, never ready, `teleport` ends in `stream-timeout`.
37
- - Leaving a place and coming back is safe: models unload, but records (an opened chest, a dropped item, a removed rock) stay in `engine.world` and the
38
- models are rebuilt from them.
39
- - Module authors with their own distance-based loader: read `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and
40
- `s.reach(range)`, and register `engine.stream.addReadyCheck(name, s => ...)`. Do not read `engine.focus` or the player position for loading.
37
+ - `source.ready` is checked at the end of each frame, a new source after one full frame. Collision takes effect on a fixed tick: under `engine.haltLoop()`, step while waiting.
38
+ - `ready` means nothing is pending, not that everything built: a failed build is reported and left out, and `teleport` still lands. Need it built? Check
39
+ `handle.built`, `engine.world.view(id)`. A failed terrain chunk (recipe 28) is different: no ground, never ready, `teleport` ends in `stream-timeout`.
40
+ - Leaving and coming back is safe: models unload, records (an opened chest, a removed rock) stay in `engine.world` and the models are rebuilt from them.
41
+ - After start, a stream entry bringing an undrawn material attaches after its compile, a task later (not in the
42
+ same `engine.step`); `ready` waits. Unloading frees geometry and materials nothing else uses; textures are yours (`dispose`).
43
+ - A module's own distance-based loader reads `engine.stream.sources({ detail: 'full' })` / `sources({ physics: true })` and `s.reach(range)`, and
44
+ registers `engine.stream.addReadyCheck(name, s => ...)`, never `engine.focus` or the player position.