threedog 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
package/core/look/part.js CHANGED
@@ -1,157 +1,235 @@
1
- // engine.look.<part>: set / patch / replace and the layers.
2
- // Parts: tone, lights, cloudShadow (core), env (sky); fog / sky / water / post ... come from their modules.
3
- // set(params, { owner }) change parameters (shallow merge into that owner's layer; null drops a key so the layer below shows again)
4
- // patch(name, glsl, { owner }) swap one named GLSL hook the part registered (null gives the default back)
5
- // replace(impl, { owner }) take the whole part over (null gives it back to the engine / style)
1
+ // engine.look.<part>: what a game calls. Every part has the same small set (docs/plans/2026-11-03-look-api.md):
2
+ // set(params, { owner }) change values (shallow merge into that owner's layer; null drops a key so the layer below shows again)
3
+ // patch(hook, code, { owner }) swap one named hook the part declares (GLSL / TSL; null gives the default back). Only that meaning
4
+ // add(thing, ...) put one more named thing in next to the engine's (look.post.add, look.materials.add); remove() takes it out
5
+ // replace(thing, { owner }) swap the one three.js thing the part draws (a texture, a sky object, a Material, an effect list); null gives it
6
+ // back. A whole module (behaviour, saves) is engine.use(mine(), { replaces: '<slot>' }) instead
7
+ // manual(keys?) the engine stops writing values it writes on its own; the three.js object is yours
8
+ // value(key) the one read: the value in effect (who set it: describe().look); object: the three.js object(s) behind it
9
+ // A verb a part does not have throws with the part's pointer and the verbs it has. Everything else (raw writes, extending keys, drivers, the
10
+ // per-frame tick) is for module code and lives on part.author, so engine.look.fog. autocompletes to the game verbs only.
6
11
  // Why one helper and not per-part code: layering, owner records, validation, catalog and describe were written differently in every module
7
12
  // (sky.modify had owners, engine.look.tone.set had none, describeRender guessed the source by comparing against start values). A part author writes only
8
13
  // apply / applyHook / applyReplace; everything a reader (describe, catalog, debug.override) needs comes from the same records.
9
- // Layers per key, the upper one wins: engine default < style < game (each owner; the last one written wins) < debug (engine.debug.override).
14
+ // Every key is a shared point 'look.<part>.<key>' (points.js, core/sharedPoint.js): engine default < style < game < effect (weather, sunset:
15
+ // mul / add) < system < settings (restrict only, above system) < debug. Two owners setting one key on one layer is a dev error naming both, with the fix.
10
16
  // Hooks and the replace slot are keys too ('hook:<name>', '@replace'), so they get the same layering and records for free.
11
- // A part author never touches `_` fields: write / ownerValue / extend / retract / has / resolved are the public author methods (review r2 #2).
12
17
  import { closest } from '../validate.js';
13
18
  import { codedError } from '../errorHints.js';
14
- import { REPLACE, HOOK, addParams, topOf, allKeys, sourceOf, refresh, quietRefresh, commit, retractKeys, aliased } from './layers.js';
15
- import { setOn, setStyle, writeLayer, dropLayer, takeVerb, example } from './write.js';
19
+ import { REPLACE, HOOK, addParams, allKeys, sourceOf, flush, quietRefresh, retractKeys, batch, driveKeys, tick, pointOf, ownerValues, dropOwner } from './points.js';
20
+ import { LAYERS } from '../sharedPoint.js';
21
+ import { setOn, setStyle, writeLayer, takeVerb, example } from './write.js';
22
+ import { manualVerb, ownedOf } from '../owned.js';
23
+ import { defineState } from './state.js';
16
24
 
17
25
  export { REPLACE };
18
- export { disposeLooksOf } from './layers.js';
26
+
27
+ /** A patch(name, value) hook value as an object: a bare GLSL string becomes { glsl }, a { glsl, uniforms, ... } spec passes through */
28
+ export const hookSpec = v => (typeof v === 'string' ? { glsl: v } : v);
29
+ export { disposeLooksOf } from './points.js';
19
30
  const SPEC_FIELDS = ['id', 'group', 'module', 'object', 'params', 'style', 'read', 'apply', 'applyAtStart', 'hooks', 'applyHook', 'noPatch',
20
- 'replace', 'applyReplace', 'noReplace', 'docs', 'normalize', 'validate', 'verbs', 'appliesTo', 'extraSignatures'];
21
- const SIG = { set: 'set(params, { owner })', patch: 'patch(name, glsl, { owner })', replace: 'replace(impl, { owner })' };
31
+ 'replace', 'applyReplace', 'noReplace', 'noAdd', 'docs', 'normalize', 'validate', 'verbs', 'appliesTo', 'extraSignatures', 'info'];
32
+ const SIG = { set: "set(params, { owner, layer? })", patch: 'patch(hook, code, { owner })', replace: 'replace(thing, { owner })', manual: 'manual(keys?, on = true)' };
22
33
 
23
34
  class LookPart {
24
35
  /** @param {any} e @param {any} spec see defineLookPart */
25
36
  constructor(e, spec) {
26
- this._e = e; this._spec = spec; this._seq = 0;
37
+ this._e = e; this._spec = spec;
27
38
  this._params = {}; this._meta = {};
28
- addParams(this, spec.params);
39
+ /** key -> its shared point; _fns: function values on number keys (tick evaluates them); _dirty / _hold: batch(points.js) */
40
+ this._points = new Map(); this._fns = new Map(); this._dirty = new Set(); this._hold = 0;
29
41
  this._style = new Map();
30
- this._owners = { game: new Map(), debug: new Map() }; // owner -> { values: Map, seq, at }
31
42
  this._resolved = new Map();
43
+ addParams(this, spec.params);
44
+ this._rev = 0; // goes up whenever refresh changed a resolved key, so a per-frame reader rebuilds its view only after a change
32
45
  this._driven = new Map(); // key -> who writes it every frame from the style (sky keyframes drive the sun)
46
+ this._started = false; // true once defineLookPart wrote the style layer: apply runs only after that
47
+ /** module code's half (PartAuthor below); not enumerable, so a logged part shows the game's view */
48
+ this.author = /** @type {PartAuthor} */ (/** @type {unknown} */ (null));
49
+ Object.defineProperty(this, 'author', { value: new PartAuthor(this), enumerable: false });
33
50
  }
34
51
  /** Catalog / override id: 'look.<part>' */
35
52
  get id() { return `look.${this._spec.id}`; }
36
53
  /** The three.js object(s) behind this part (renderer, lights ...); changing them directly works but is tagged 'three' in describe().look */
37
54
  get object() { return this._spec.object?.(); }
38
- /** Each verb's call shape (spec.verbs overrides a default); the catalog lists it and verb errors quote it */
39
- get signatures() {
40
- const s = this._spec, out = { set: SIG.set };
41
- if (s.hooks) out.patch = s.verbs?.patch?.signature ?? SIG.patch;
42
- if (s.replace) out.replace = s.verbs?.replace?.signature ?? SIG.replace;
43
- return Object.assign(out, s.extraSignatures); // a part's own verb (look.post.add), listed so the catalog shows it
55
+
56
+ /**
57
+ * The error for a verb this part does not have. Every part says it the same way: why not, the part's own pointer (noPatch / noAdd / noReplace)
58
+ * or a set() example, then the verbs it does have with their call shapes (the same list as engine.catalog('look.<part>').signatures), so the
59
+ * next call is always on screen and no part's message can drift from what the part offers.
60
+ * @param {string} verb @param {string} why @param {string} [hint]
61
+ */
62
+ _lacks(verb, why, hint) {
63
+ const has = Object.values(this.author.signatures).map(sig => `${this.id}.${sig}`).join(', ');
64
+ const next = (hint ?? `Change it with ${this.id}.set(${example(this)})`).replace(/\.\s*$/, ''); // a hint may end in a period: not two
65
+ return codedError('look-verb', `${this.id}.${verb}(): ${why}. ${next}. Verbs it has: ${has}`);
44
66
  }
45
67
 
46
68
  /**
47
69
  * Change parameters for one owner. Nested objects flatten to the part's dotted keys ({ sun: { intensity: 3 } } -> 'sun.intensity').
48
70
  * @param {Record<string, any>} params null drops a key from this owner's layer
49
- * @param {{ owner?: string }} [o]
50
- * @returns {{ remove(): void }} removes this owner's whole layer on this part
71
+ * @param {{ owner?: string, layer?: 'style' | 'game' | 'effect' | 'system' | 'settings' | 'debug' }} [o] layer: game by default; an effect
72
+ * module writes 'effect', 'system' takes the key over above every effect (the settings layer only restricts: set false)
73
+ * @returns {{ remove(): void }} removes what this call wrote
51
74
  */
52
- set(params, { owner = 'game' } = {}) { return this._setOn('game', owner, params); }
75
+ set(params, { owner = 'game', layer = 'game' } = {}) {
76
+ // 'engine' is outside the JSDoc type, but an untyped caller can pass it
77
+ if (!(layer in LAYERS) || /** @type {string} */ (layer) === 'engine') throw codedError('shared-layer', `${this.id}.set(params, { layer }): layer is one of ${Object.keys(LAYERS).slice(1).join(' < ')}, got ${JSON.stringify(layer)}`);
78
+ return this._setOn(layer, owner, params);
79
+ }
53
80
  /**
54
- * Swap one named GLSL hook. Names and signatures: engine.catalog('look.<part>').hooks
55
- * @param {string} name @param {any} glsl a GLSL string (or the part's hook spec); null gives the default back
81
+ * Swap one named hook the part declares (only that: adding a thing is add()). Names and signatures: engine.catalog('look.<part>').hooks
82
+ * @param {string} name @param {any} code a GLSL string (or the part's hook spec { glsl, tsl, uniforms }); null gives the default back
56
83
  * @param {{ owner?: string }} [o]
57
84
  */
58
- patch(name, glsl, o) {
85
+ patch(name, code, o) {
59
86
  const hooks = this._spec.hooks;
60
- if (!hooks) throw codedError('look-verb', `${this.id}.patch(): this part has no GLSL hooks. ${this._spec.noPatch ?? `Change it with ${this.id}.set(${example(this)})`}`);
61
- if (this._spec.verbs?.patch?.take) return this._take('patch', [...arguments]);
62
- if (!(name in hooks) && !hooks['*']) { // hooks['*'] = any name the game picks (post: patch(name, fuse) makes an effect)
87
+ if (!hooks) throw this._lacks('patch', 'this part has no named hook to swap', this._spec.noPatch);
88
+ if (!(name in hooks)) {
63
89
  const c = closest(name, Object.keys(hooks)); throw codedError('look-verb', `${this.id}.patch('${name}'): unknown hook${c ? ` (did you mean '${c}'?)` : ''}; hooks: ${Object.keys(hooks).join(', ')}`);
64
90
  }
65
- return this.write(o?.owner ?? 'game', { [HOOK + name]: glsl });
91
+ return this._write('game', o?.owner ?? 'game', { [HOOK + name]: code });
66
92
  }
67
93
  /**
68
- * Take the whole part over (what it accepts and what is lost: engine.catalog('look.<part>').replace); null gives it back
69
- * @param {any} impl @param {{ owner?: string }} [o]
94
+ * Put one more named thing in next to the engine's (look.post.add: an effect; look.materials.add: a shader patch for some roles); the part's
95
+ * call shape: engine.catalog('look.<part>').signatures.add. A part with nothing to add throws with its pointer
96
+ * @param {...any} args @returns {{ remove(): void }}
97
+ */
98
+ add(...args) {
99
+ if (this._spec.verbs?.add?.take) return this._take('add', args);
100
+ throw this._lacks('add', 'this part has nothing to add', this._spec.noAdd);
101
+ }
102
+ /**
103
+ * Swap the one three.js thing this part draws (what it accepts and what is lost: engine.catalog('look.<part>').replace); null gives it back
104
+ * @param {any} impl @param {{ owner?: string, [option: string]: any }} [o] owner, plus the part's own options (catalog replace.options)
70
105
  */
71
106
  replace(impl, o) {
72
- if (!this._spec.replace) throw codedError('look-verb', `${this.id}.replace(): this part cannot be swapped whole. ${this._spec.noReplace ?? `Change it with ${this.id}.set(${example(this)})`}`);
107
+ if (!this._spec.replace) throw this._lacks('replace', 'this part has no thing to swap', this._spec.noReplace);
73
108
  if (this._spec.verbs?.replace?.take) return this._take('replace', [...arguments]);
74
- return this.write(o?.owner ?? 'game', { [REPLACE]: impl });
109
+ // options besides owner are the part's own (look.ground: { effects: false }); a key the part does not take throws instead of doing nothing
110
+ const extra = Object.keys(o ?? {}).filter(k => k !== 'owner'), takes = this._spec.replace.options ?? [];
111
+ const bad = extra.find(k => !takes.includes(k));
112
+ if (bad) throw codedError('look-param', `${this.id}.replace(impl, { ${bad} }): ${takes.length ? `options are owner, ${takes.join(', ')}` : 'the only option is owner'}`);
113
+ if (extra.length) this._spec.replace.withOptions(impl, o);
114
+ return this._write('game', o?.owner ?? 'game', { [REPLACE]: impl });
75
115
  }
76
- /** Remove every layer `owner` wrote on this part (game and debug); returns how many layers were removed (the same count shape as engine.debug.clear) */
77
- clear(owner) { let n = 0; for (const l of ['game', 'debug']) if (this._drop(l, owner)) n++; return n; }
78
- /** The value in effect for a key (after all layers) */
79
- value(key) { return this._resolved.get(key); }
80
- /** Only what the game or a debug override set for a key, else undefined (a driver writes its own value, then this one over it) */
81
- top(key) { const t = topOf(this, key); return t ? t.value : undefined; }
82
-
83
116
  /**
84
- * Declare keys a style-driven system writes every frame (the sky drives sun and hemisphere from style.sky.keyframes). Those keys then read
85
- * as by: 'style' in describe with the live value, and apply() gets undefined for them unless a game or debug layer set one (that system
86
- * should write top(key) over its own value). drive(keys, null) hands them back to the layers.
87
- * @param {string[]} keys @param {string | null} by the driver's name, e.g. 'sky' (a module name: disposing that module releases them)
117
+ * Take properties the engine writes on its own (every frame or on a timer) for the game, or hand them back. Taken, the engine stops writing them
118
+ * and the three.js object is yours (engine.lights.sun.intensity = 3 sticks); manual(keys, false) or the returned remove() gives them back.
119
+ * Keys match by dotted prefix ('sun' takes sun.intensity and sun.color); none = every one of this part. Which keys: describe().owned.
120
+ * A direct write without manual() does the same (the engine yields and warns once), manual() just says it on purpose.
121
+ * @example engine.look.lights.manual('sun'); engine.lights.sun.intensity = 3; engine.look.lights.manual('sun', false); engine.look.fog.manual();
122
+ * @param {string | string[]} [keys] @param {boolean} [on] @returns {{ remove(): void }}
88
123
  */
89
- drive(keys, by) {
90
- for (const k of keys) by ? this._driven.set(k, by) : this._driven.delete(k);
91
- this._refresh();
92
- }
93
- /** For a driver, after it wrote its keys this frame: re-apply the driven keys a game or debug layer set, so those layers win (cheap: a few keys) */
94
- applyTop() {
95
- let v = null, changed = null;
96
- for (const k of this._driven.keys()) { const t = topOf(this, k); if (t) { (v ??= {})[k] = t.value; (changed ??= new Set()).add(k); } }
97
- if (changed) this._spec.apply?.(v, changed);
98
- }
99
-
100
- // ---- for part authors (render/postLook.js, terrain, weather ...): public so no author reaches into `_` fields ------------------------------
101
-
102
- /** Write raw keys (params, 'hook:<name>', '@replace', a part's own slot keys) for an owner on the game layer, no normalize; null drops a key */
103
- write(owner, values, { layer = 'game' } = {}) { return this._write(layer, owner, values); }
104
- /** What one owner holds for a key (undefined when it holds nothing): look.weather.replace adds to the object its owner put in the replace slot */
105
- ownerValue(owner, key, { layer = 'game' } = {}) { return this._owners[layer].get(owner)?.values.get(key); }
106
- /** Add declared keys to a started part (same spec fields as params; a known key is left alone). Values recompute without calling apply */
107
- extend(params) { addParams(this, params, { skipKnown: true }); quietRefresh(this); }
108
- /** Remove every key starting with prefix (e.g. 'bloom.'), with the values any layer holds for them */
109
- retract(prefix) { retractKeys(this, prefix); }
110
- /** Replace the style layer (post: a replaced effect chain brings its own defaults) */
111
- restyle(values) { this._setStyle(values); }
112
- /** Is key a declared param of this part */
113
- has(key) { return key in this._params; }
114
- /** [key, value] pairs in effect whose key starts with prefix ('hook:' lists the patches set) */
115
- resolved(prefix = '') { return [...this._resolved].filter(([k]) => k.startsWith(prefix)); }
116
- /** Unregister the part (its module is disposed, or its install failed): engine.look.<id> goes away and nothing drives its keys any more */
117
- dispose() {
118
- const look = this._e.look;
119
- if (look?.[this._spec.id] === this) delete look[this._spec.id];
120
- this._driven.clear(); this._started = false;
121
- }
124
+ manual(keys, on) { return manualVerb(this._e, this._spec.id, keys, on); }
125
+ /** The value in effect for a key (after all layers): the one read. Who set it and how: engine.describe().look.<part> */
126
+ value(key) { return this._resolved.get(key); }
122
127
 
123
- // ---- internal (layering: layers.js) ------------------------------------------------------------------------------------------------------
128
+ // ---- internal (layering: points.js, write.js); module code goes through part.author ------------------------------------------------------
124
129
 
130
+ /** @internal drop every layer owner wrote (every layer above style), for tests and tools that did not keep the handle; returns how many */
131
+ _clear(owner) { let n = 0; for (const l of Object.keys(LAYERS)) if (l !== 'engine' && l !== 'style' && this._drop(l, owner)) n++; return n; }
125
132
  /** @internal set() and engine.debug.override share this (write.js: normalize, flatten, check, write) */
126
133
  _setOn(layer, owner, params) { return setOn(this, layer, owner, params); }
127
134
  /** @internal Replace the style layer (start, or a style swap); game and debug layers stay */
128
135
  _setStyle(values) { setStyle(this, values); }
129
136
  _write(layer, owner, values) { return writeLayer(this, layer, owner, values); }
130
- _drop(layer, owner) { return dropLayer(this, layer, owner); }
137
+ _drop(layer, owner) { return dropOwner(this, layer, owner); }
131
138
  /** @internal recompute (force: every key to apply again); _keys / _source: report.js */
132
- _refresh(force = false) { refresh(this, force); }
139
+ _refresh(force = false) { flush(this, force); }
133
140
  _keys() { return allKeys(this); }
134
141
  _source(key) { return sourceOf(this, key); }
135
142
  /** @internal Resolved params as a plain object */
136
- values() { const o = {}; for (const k in this._params) o[k] = this._resolved.get(k); return o; }
143
+ _values() { const o = {}; for (const k in this._params) o[k] = this._resolved.get(k); return o; }
137
144
  /** A verb with its own call shape (spec.verbs[verb].take) */
138
145
  _take(verb, args) { return takeVerb(this, verb, args); }
139
146
  }
140
147
 
141
148
  /**
142
- * Register a look part: engine.look.<id> gets set / patch / replace (the verbs the spec supports; the others throw and say which verb to use),
143
- * engine.catalog('look.<id>') lists its params, hooks, replace contract and verb signatures, describe().look shows every key's value and who
144
- * set it, and engine.debug.override(owner, 'look.<id>', values) writes its debug layer. Every param needs a default; a default that changes the
145
- * picture needs why (what it is for) and off (how to turn it off), or neutral: true (checked by `npm run check`, rule R35).
146
- * Its module's failed install drops it again (disposeLooksOf).
149
+ * part.author: what module code that defines or drives a part calls (render/postLook.js, terrain, weather, the sky's keyframes ...); a game never
150
+ * needs it. Kept off the part so a game's autocomplete shows only set / patch / add / replace / manual / value; public (not `_`) so no module
151
+ * reaches into a part's fields.
152
+ */
153
+ class PartAuthor {
154
+ /** @param {LookPart} p */
155
+ constructor(p) { this._p = p; }
156
+ /** Each verb's call shape (spec.verbs overrides a default); the catalog lists it and verb errors quote it */
157
+ get signatures() {
158
+ const p = this._p, s = p._spec, out = /** @type {Record<string, string>} */ ({ set: SIG.set });
159
+ if (s.hooks) out.patch = SIG.patch;
160
+ if (s.verbs?.add) out.add = s.verbs.add.signature;
161
+ if (s.replace) out.replace = s.verbs?.replace?.signature ?? SIG.replace;
162
+ if (ownedOf(p._e, s.id).length) out.manual = SIG.manual;
163
+ return Object.assign(out, s.extraSignatures); // a part's own verb (look.post.add, look.materials.glow), listed so the catalog shows it
164
+ }
165
+ /** Write raw keys (params, 'hook:<name>', '@replace', a part's own slot keys) for an owner on the game layer, no normalize; null drops a key */
166
+ write(owner, values, { layer = 'game' } = {}) { return this._p._write(layer, owner, values); }
167
+ /** What one owner holds for a key (undefined when it holds nothing): look.weather.replace adds to the object its owner put in the replace slot */
168
+ ownerValue(owner, key, { layer = 'game' } = {}) { return ownerValues(this._p, layer, owner)[key]; }
169
+ /** Add declared keys to a started part (same spec fields as params; a known key is left alone). Values recompute without calling apply */
170
+ extend(params) { addParams(this._p, params, { skipKnown: true }); quietRefresh(this._p); }
171
+ /** Remove every key starting with prefix (e.g. 'bloom.'), with the values any layer holds for them */
172
+ retract(prefix) { retractKeys(this._p, prefix); }
173
+ /** Replace the style layer (post: a replaced effect chain brings its own defaults) */
174
+ restyle(values) { this._p._setStyle(values); }
175
+ /** Is key a declared param of this part */
176
+ has(key) { return key in this._p._params; }
177
+ /** [key, value] pairs in effect whose key starts with prefix ('hook:' lists the patches set) */
178
+ resolved(prefix = '') { return [...this._p._resolved].filter(([k]) => k.startsWith(prefix)); }
179
+ /** Resolved params as a plain object */
180
+ values() { return this._p._values(); }
181
+ /** Only what the game (or a layer above it) set for a key, else undefined: render/lookSurface.js reads a game's material choice through it */
182
+ top(key) {
183
+ const p = this._p, s = p._points.get(key);
184
+ let best = null;
185
+ for (const en of s?._map(undefined)?.values() ?? []) if (en.op === 'set' && LAYERS[en.layer] >= LAYERS.game && (!best || LAYERS[en.layer] >= LAYERS[best.layer])) best = en;
186
+ return best ? p._fns.get(`${key}\0${best.owner}`)?.fn ?? best.value : undefined;
187
+ }
188
+ /** The shared point behind key (engine.stacks.get('look.<part>.<key>')): take() on it adds an effect entry */
189
+ point(key) { if (!(key in this._p._params)) throw this._p._lacks('point', `no key ${key}`); return pointOf(this._p, key); }
190
+ /**
191
+ * Declare keys a style-driven system writes every frame (the sky drives sun and hemisphere from style.sky.keyframes). While driven, the
192
+ * driver's value (feed) is the style layer of those keys; a game set, the weather's mul and the settings still apply on top, and the part's
193
+ * apply leaves the three.js object to the driver, which writes value(key). drive(keys, null) hands them back to the layers.
194
+ * @param {string[]} keys @param {string | null} by the driver's name, e.g. 'sky' (a module name: disposing that module releases them)
195
+ */
196
+ drive(keys, by) { driveKeys(this._p, keys, by); }
197
+ /** Who drives key every frame ('sky'), or null */
198
+ driven(key) { return this._p._driven.get(key) ?? null; }
199
+ /** The driver's value for a driven key this frame (the keyframes' sun intensity); the layers above still apply */
200
+ feed(key, value) { const p = this._p, by = p._driven.get(key); if (by) pointOf(p, key).take({ owner: by, layer: 'style', set: value }); }
201
+ /** Once per frame with the frame context: function values on number keys are evaluated (a function on a color key is the module's to read) */
202
+ tick(ctx) { tick(this._p, ctx); }
203
+ /** Run fn with the recompute held, so several writes apply once */
204
+ batch(fn) { return batch(this._p, fn); }
205
+ /** Unregister the part (its module is disposed, or its install failed): engine.look.<id> goes away and nothing drives its keys any more.
206
+ * remove(), not dispose(): the part owns no GPU resource (the cancel convention for everything that only unregisters) */
207
+ remove() {
208
+ const p = this._p, look = p._e.look;
209
+ if (look?.[p._spec.id] === p) delete look[p._spec.id];
210
+ // its points stay registered (a part registered again reuses them) but hold nothing: every entry, the weather's too, goes with the part
211
+ for (const s of p._points.values()) { s.onChange = null; s.clear(); }
212
+ p._driven.clear(); p._fns.clear(); p._started = false;
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Register a look part: engine.look.<id> gets set / patch / add / replace / manual / value (the verbs the spec supports; the others throw and
218
+ * say which verb to use; module code reaches the rest through part.author), engine.catalog('look.<id>') lists its params, hooks, replace
219
+ * contract and verb signatures, describe().look shows every key's value and who set it, and engine.debug.override(owner, 'look.<id>', values)
220
+ * writes its debug layer. Every param needs a default; a default that changes the picture needs why (what it is for) and off (how to turn it
221
+ * off), or neutral: true (checked by `npm run check`, rule R35). Its module's failed install drops it again (disposeLooksOf).
147
222
  * @param {any} engine @param {{ id: string, group?: string, module?: string, object?: () => any, params?: Record<string, any>, style?: () => object,
148
223
  * read?: () => object, apply?: (values: object, changed: Set<string>) => void, applyAtStart?: boolean,
149
224
  * hooks?: Record<string, { signature?: string, scope?: string[], example?: string }>, applyHook?: (name: string, glsl: any) => void, noPatch?: string,
150
- * replace?: { accepts: string, loses?: string[] }, applyReplace?: (impl: any) => void, noReplace?: string, docs?: string[],
151
- * validate?: (key: string, value: any) => string | null | undefined,
152
- * verbs?: Record<'patch' | 'replace', { signature: string, take: (bad: (msg: string) => never, ...args: any[]) => [Record<string, any>, string?] }>,
153
- * appliesTo?: string }} spec validate: why a value is wrong (checked before anything is written); verbs: a verb with its own call shape
154
- * (materials.replace(role, impl)); appliesTo: what a change reaches when not everything ('new materials')
225
+ * replace?: { accepts: string, loses?: string[], options?: string[], withOptions?: (impl: any, o: object) => void }, applyReplace?: (impl: any) => void, noReplace?: string, docs?: string[],
226
+ * normalize?: (params: Record<string, any>) => Record<string, any>, validate?: (key: string, value: any) => string | null | undefined, noAdd?: string,
227
+ * verbs?: Partial<Record<'add' | 'replace', { signature: string, take: (bad: (msg: string) => never, ...args: any[]) => [Record<string, any>, string?, string?] }>>,
228
+ * appliesTo?: string, info?: () => Record<string, object>, extraSignatures?: Record<string, string> }} spec validate: why a value is wrong (checked
229
+ * before anything is written); normalize: rewrites a set() / debug.override value before the key check (a part's shorthand, or a pointed error
230
+ * for a removed key); verbs: a verb with its own call shape (materials.add(name, patch, { roles }), materials.replace(role, impl));
231
+ * extraSignatures: the call shapes of the part's own verbs (look.post.add, look.materials.glow); appliesTo: what a change reaches when not
232
+ * everything ('new materials'); info: read-only rows describe().look adds beside the params (look.env's source: which map, does it follow the time)
155
233
  * @returns {LookPart}
156
234
  * @example
157
235
  * defineLookPart(engine, { id: 'glow', group: 'screen', module: 'myGlow', object: () => glowPass,
@@ -162,12 +240,14 @@ class LookPart {
162
240
  export function defineLookPart(engine, spec) {
163
241
  for (const k of Object.keys(spec ?? {})) if (!SPEC_FIELDS.includes(k)) { const c = closest(k, SPEC_FIELDS); throw codedError('look-param', `defineLookPart: unknown spec field ${k}${c ? ` (did you mean ${c}?)` : ''}; fields: ${SPEC_FIELDS.join(', ')}`); }
164
242
  if (!/^[a-z][\w]*$/i.test(spec?.id ?? '')) throw codedError('look-param', `defineLookPart: id is the part name, e.g. 'fog' (engine.look.fog, catalog id 'look.fog'); got ${JSON.stringify(spec?.id)}`);
165
- const look = aliased(engine.look ??= {});
243
+ const look = engine.look ??= {};
244
+ defineState(look, engine); // engine.look.state(patch): the game's half of the frame context function values read (state.js)
166
245
  if (look[spec.id] && look[spec.id]._spec.module !== spec.module) throw codedError('look-param', `defineLookPart('${spec.id}'): engine.look.${spec.id} is already registered (by ${look[spec.id]._spec.module ?? 'core'})`);
167
246
  const part = new LookPart(engine, spec);
168
247
  part._setStyle(spec.style?.());
169
248
  part._started = true;
170
- if (spec.applyAtStart !== false) part._refresh(true);
249
+ // applyAtStart false: the module writes the three.js object itself at start, but value(key) must already answer (fogFarOf reads it)
250
+ if (spec.applyAtStart !== false) part._refresh(true); else quietRefresh(part);
171
251
  look[spec.id] = part;
172
252
  return part;
173
253
  }
@@ -0,0 +1,255 @@
1
+ // A LookPart's keys on shared points: every look.<part>.<key> is one engine.stacks point (core/sharedPoint.js), so look values follow the
2
+ // same layers, owners, conflict errors and describe().shared rows as every other shared value. This file is the glue between a part and its points:
3
+ // which point a key is, writing a value for an owner on a layer, and the recompute that hands changed keys to the part's apply.
4
+ // Why points and not the part's own layer maps (the old layers.js): two layer systems decided differently (a game's look.lights.set covered the
5
+ // weather's multiplier, sky/frame.js), and a reader had to learn both. One table means "game sets 3, weather x0.6 on top" holds for every look value.
6
+ // Layers a part uses: the param default is the point's base (engine), a style pack writes owner 'style' on the style layer, a style-driven system
7
+ // (the sky's keyframes) writes on the style layer under its own name while it drives a key, games write the game layer (or one they name),
8
+ // effects (weather, sunset) write mul / add on effect, the settings menu restricts on settings, engine.debug.override writes debug.
9
+ import { markOwned, ownedOf } from '../owned.js';
10
+ import { parseSpec } from '../params.js';
11
+ import { coded, codedError } from '../errorHints.js';
12
+ import { DEV, warnOnce } from '../validate.js';
13
+ import { live } from './state.js';
14
+
15
+ // fn: the key also takes ({ time, weather, season, day, state, sky }) => value (number keys: evaluated each frame by tick(ctx), state.js)
16
+ // device: why the engine default differs on this device (a costly post effect off on a low-tier device or headless page); describe().look shows it
17
+ const LOOK_FIELDS = ['why', 'off', 'cost', 'neutral', 'check', 'fn', 'device'];
18
+ export const REPLACE = '@replace';
19
+ export const HOOK = 'hook:';
20
+
21
+ /** Parse param specs into part._params / part._meta and give each its point (constructor and extend share it) */
22
+ export function addParams(part, params, { skipKnown = false } = {}) {
23
+ for (const [k, raw] of Object.entries(params ?? {})) {
24
+ if (skipKnown && k in part._params) continue;
25
+ const meta = {}, rest = { ...raw };
26
+ for (const f of LOOK_FIELDS) if (f in rest) { meta[f] = rest[f]; delete rest[f]; }
27
+ if (!('default' in rest)) throw codedError('look-param', `defineLookPart('${part._spec.id}'): param ${k} has no default. Every look param declares the value the engine uses when nobody sets it (and why / off when that value changes the picture)`);
28
+ part._params[k] = parseSpec(part.id, k, rest, msg => codedError('look-param', msg));
29
+ part._meta[k] = meta;
30
+ pointOf(part, k);
31
+ }
32
+ }
33
+
34
+ /** The shared point behind key ('look.fog.far'), made on first use. number params: kind number (effects multiply them); anything else
35
+ * (colors, switches, hooks, the replace slot): kind value, set only. A part registered again reuses its points with the new default. */
36
+ export function pointOf(part, key) {
37
+ let s = part._points.get(key);
38
+ if (s) return s;
39
+ const S = part._e.stacks, id = part._spec.id, name = `look.${id}.${key}`, spec = part._params[key];
40
+ const num = spec?.type === 'number' && typeof spec.default === 'number';
41
+ if (S.has(name)) { s = S.get(name); s.clear(); s.base = spec ? spec.default : null; }
42
+ else s = S.define(name, { kind: num ? 'number' : 'value', base: spec ? spec.default : null, min: num ? spec.min ?? -Infinity : -Infinity, max: num ? spec.max ?? Infinity : Infinity, save: false });
43
+ // the conflict error's third fix: take it over on purpose. A key the engine writes on its own has manual(); any other is a set on system
44
+ Object.defineProperty(s, 'manual', { configurable: true, get: () => (ownedOf(part._e, id, key).length
45
+ ? `engine.look.${id}.manual('${key}')` : `engine.look.${id}.set({ '${key}': ... }, { owner, layer: 'system' })`) });
46
+ s.onChange = () => { part._dirty.add(key); if (!part._hold) flush(part); };
47
+ part._points.set(key, s);
48
+ return s;
49
+ }
50
+
51
+ /** One owner's entry on a point (or undefined): the old value a failed write puts back */
52
+ const entryOf = (s, owner) => s._map(undefined)?.get(owner);
53
+
54
+ /** Every key that has a point: params, plus hooks / replace / slot keys someone wrote */
55
+ export const allKeys = part => [...part._points.keys()];
56
+
57
+ /** The value in effect for key: the point's layered result; a hook or slot key nobody wrote is undefined (not the null base) */
58
+ function valueOf(part, k) {
59
+ const s = part._points.get(k);
60
+ if (!s) return undefined;
61
+ const v = s.value();
62
+ return k in part._params || (v != null && s.size()) ? v : undefined;
63
+ }
64
+
65
+ /** Hold the recompute until fn is done: a set of five keys, or the sky's frame, applies once (a point change only marks its key dirty) */
66
+ export function batch(part, fn) {
67
+ part._hold++;
68
+ try { return fn(); } finally { if (!--part._hold && part._dirty.size) flush(part); }
69
+ }
70
+
71
+ /**
72
+ * Recompute the dirty keys (force: every key) and hand the changed ones to the part's apply / applyHook / applyReplace.
73
+ */
74
+ export function flush(part, force = false) {
75
+ const keys = force ? allKeys(part) : [...part._dirty], changed = [];
76
+ part._dirty.clear();
77
+ for (const k of keys) {
78
+ const v = valueOf(part, k);
79
+ if (force || part._resolved.get(k) !== v || !part._resolved.has(k)) changed.push(k);
80
+ v === undefined ? part._resolved.delete(k) : part._resolved.set(k, v);
81
+ }
82
+ if (!changed.length) return;
83
+ part._rev++;
84
+ if (!part._started) return;
85
+ const s = part._spec, params = changed.filter(k => k in part._params);
86
+ if (changed.includes(REPLACE)) s.applyReplace?.(part._resolved.get(REPLACE) ?? null);
87
+ for (const k of changed) if (k.startsWith(HOOK)) s.applyHook?.(k.slice(HOOK.length), part._resolved.get(k) ?? null);
88
+ if (params.length) s.apply?.(part._values(), new Set(params));
89
+ // the engine wrote these on the game's request: re-read the owned properties so the next frame does not take it for an outside write (owned.js)
90
+ markOwned(part._e, s.id);
91
+ }
92
+
93
+ /**
94
+ * Evaluate a number key's function value: the number, or undefined when it threw or gave something that is not a finite number. Then the point
95
+ * keeps its last good value, the record counts the failure (describe().look shows fnErrors / fnError on the key) and dev warns once per key and
96
+ * owner. Why not silent: `({ state }) => state.boss.dist * 3` before the boss exists left the fog still with no word, and the AI blamed the layers.
97
+ */
98
+ function evalFn(part, rec, ctx) {
99
+ let n, bad;
100
+ try { n = live(rec.fn, ctx); if (!Number.isFinite(n)) bad = `returned ${typeof n === 'number' ? String(n) : n === undefined ? 'undefined' : JSON.stringify(n) ?? String(n)}`; }
101
+ catch (err) { bad = `threw "${err?.message ?? err}"`; }
102
+ if (bad === undefined) return n;
103
+ rec.errors = (rec.errors ?? 0) + 1; rec.lastError = bad;
104
+ if (DEV) warnOnce(coded('look-fn', `${part.id}.${rec.key}: the function value set by '${rec.owner}' (layer ${rec.layer}) ${bad}, not a finite number; ` +
105
+ 'the key keeps its last good value (describe().look counts it in fnErrors)'), `look-fn\0${part.id}\0${rec.key}\0${rec.owner}`);
106
+ return undefined;
107
+ }
108
+
109
+ /** Put one value for owner on layer. A function on a number key is kept and re-evaluated by tick(ctx); value keys keep the function itself
110
+ * (their module evaluates it while applying) */
111
+ function put(part, s, k, layer, owner, v) {
112
+ const fk = `${k}\0${owner}`;
113
+ if (typeof v === 'function' && s.kind === 'number') {
114
+ const rec = { key: k, owner, layer, fn: v };
115
+ part._fns.set(fk, rec);
116
+ // no frame context before the sky's first frame: the first tick evaluates it
117
+ const n = part._e._lookCtx ? evalFn(part, rec, part._e._lookCtx) : undefined;
118
+ if (n !== undefined) s.take({ owner, layer, set: n });
119
+ return;
120
+ }
121
+ part._fns.delete(fk);
122
+ s.take({ owner, layer, set: v });
123
+ }
124
+
125
+ /** Drop owner's value for key (and a kept function) */
126
+ function drop(part, k, owner) { part._fns.delete(`${k}\0${owner}`); part._points.get(k)?.release(owner); }
127
+
128
+ /**
129
+ * Write owner's keys on layer; null drops a key. All or nothing: if a conflict or the part's apply throws, every key goes back to the entry
130
+ * it had and the picture is re-applied (review H1). The handle drops only what this call wrote and still holds (a later write wins).
131
+ */
132
+ export function writeKeys(part, layer, owner, values) {
133
+ const undo = [];
134
+ try {
135
+ batch(part, () => {
136
+ for (const [k, v] of Object.entries(values)) {
137
+ const s = pointOf(part, k), old = entryOf(s, owner), oldFn = part._fns.get(`${k}\0${owner}`);
138
+ undo.push(() => { drop(part, k, owner); if (oldFn) part._fns.set(`${k}\0${owner}`, oldFn); if (old) s.take({ owner, layer: old.layer, set: old.value }); });
139
+ v === null ? drop(part, k, owner) : put(part, s, k, layer, owner, v);
140
+ }
141
+ });
142
+ } catch (err) {
143
+ part._hold++;
144
+ try { for (const u of undo.reverse()) u(); } finally { part._hold--; part._dirty.clear(); }
145
+ try { flush(part, true); } catch { /* the rethrow below is the error that broke it; this one is its echo on the old values */ }
146
+ throw err;
147
+ }
148
+ const wrote = Object.entries(values).filter(([, v]) => v !== null);
149
+ // remove() answers whether it dropped anything: false once the owner wrote the key again (a stale handle) or on a second call
150
+ return { remove: () => batch(part, () => {
151
+ let any = false;
152
+ for (const [k, v] of wrote) {
153
+ const fn = part._fns.get(`${k}\0${owner}`), e = entryOf(part._points.get(k) ?? { _map() {} }, owner);
154
+ if (fn ? fn.fn === v : e && e.value === v && e.layer === layer) { drop(part, k, owner); any = true; }
155
+ }
156
+ return any;
157
+ }) };
158
+ }
159
+
160
+ /** Every entry owner holds on layer, as { key: value } (DebugOverrides lists and clears the debug layer through it) */
161
+ export function ownerValues(part, layer, owner) {
162
+ const out = {};
163
+ for (const [k, s] of part._points) { const e = entryOf(s, owner); if (e?.layer === layer) out[k] = part._fns.get(`${k}\0${owner}`)?.fn ?? e.value; }
164
+ return out;
165
+ }
166
+
167
+ /** The owners with an entry on layer */
168
+ export function ownersOn(part, layer) {
169
+ const out = new Set();
170
+ for (const s of part._points.values()) for (const e of s._map(undefined)?.values() ?? []) if (e.layer === layer) out.add(e.owner);
171
+ return [...out];
172
+ }
173
+
174
+ /** Drop everything owner wrote on layer; true when it held something */
175
+ export function dropOwner(part, layer, owner) {
176
+ const keys = Object.keys(ownerValues(part, layer, owner));
177
+ if (keys.length) batch(part, () => { for (const k of keys) drop(part, k, owner); });
178
+ return keys.length > 0;
179
+ }
180
+
181
+ /** Replace the style layer (start, or a style swap): owner 'style' on the style layer; a key a driver drives keeps the driver's value */
182
+ export function writeStyle(part, given) {
183
+ batch(part, () => {
184
+ for (const k of part._style.keys()) if (!(k in given)) drop(part, k, 'style');
185
+ part._style = new Map(Object.entries(given));
186
+ for (const [k, v] of part._style) if (!part._driven.has(k)) put(part, pointOf(part, k), k, 'style', 'style', v);
187
+ });
188
+ }
189
+
190
+ /**
191
+ * Drive keys every frame from a style-driven system (the sky's keyframes): while driven, the driver's value sits on the style layer under its
192
+ * name and the style's own value steps aside; game / effect / settings / debug entries still apply on top. by null hands them back.
193
+ */
194
+ export function driveKeys(part, keys, by) {
195
+ batch(part, () => {
196
+ for (const k of keys) {
197
+ const was = part._driven.get(k);
198
+ if (by) { part._driven.set(k, by); drop(part, k, 'style'); continue; }
199
+ part._driven.delete(k);
200
+ if (was) drop(part, k, was);
201
+ if (part._style.has(k)) put(part, pointOf(part, k), k, 'style', 'style', part._style.get(k));
202
+ }
203
+ });
204
+ }
205
+
206
+ /** Re-evaluate every function value on a number key with this frame's context (the sky calls it once per frame) */
207
+ export function tick(part, ctx) {
208
+ if (!part._fns.size) return;
209
+ batch(part, () => {
210
+ for (const rec of part._fns.values()) {
211
+ const n = evalFn(part, rec, ctx);
212
+ if (n !== undefined) part._points.get(rec.key)?.take({ owner: rec.owner, layer: rec.layer, set: n });
213
+ }
214
+ });
215
+ }
216
+
217
+ /** Where a key's value comes from, from its point's describe row: { value, owner, layer, at, under } (report.js, look.lights env) */
218
+ export function sourceOf(part, key) {
219
+ const s = part._points.get(key);
220
+ if (!s) return null;
221
+ const r = s.row();
222
+ if (r.writer === 'default' && !(key in part._params)) return null;
223
+ const top = r.writer === 'default' ? { owner: 'engine', layer: 'engine', at: null } : { owner: r.writer, layer: r.layer ?? 'engine', at: r.at ?? null };
224
+ return { ...top, value: valueOf(part, key), driver: part._driven.get(key) ?? null, how: r.how,
225
+ under: r.also.filter(h => h.hidden).map(h => ({ owner: h.owner, layer: h.layer, at: h.at ?? null, value: h.value })) };
226
+ }
227
+
228
+ /** Remove every key starting with prefix, with every entry on it (LookPart.retract) */
229
+ export function retractKeys(part, prefix) {
230
+ part._hold++;
231
+ try {
232
+ for (const [k, s] of [...part._points]) if (k.startsWith(prefix)) {
233
+ s.onChange = null; s.clear();
234
+ for (const fk of [...part._fns.keys()]) if (fk.startsWith(k + '\0')) part._fns.delete(fk);
235
+ part._points.delete(k); part._style.delete(k); part._driven.delete(k); part._resolved.delete(k);
236
+ delete part._params[k]; delete part._meta[k];
237
+ }
238
+ } finally { part._hold--; part._dirty.clear(); }
239
+ }
240
+
241
+ /** A module went away (dispose, or engine.use rolled it back): drop the parts it registered and release the keys it drives (review M9) */
242
+ export function disposeLooksOf(e, name) {
243
+ if (!name) return;
244
+ for (const p of Object.values(e.look ?? {})) {
245
+ if (p._spec.module === name) { p.author.remove(); continue; }
246
+ const mine = [...p._driven].filter(([, by]) => by === name).map(([k]) => k);
247
+ if (mine.length) p.author.drive(mine, null);
248
+ }
249
+ }
250
+
251
+ /** Recompute without calling apply: a key added later describes the object its owner just made, its default must not be pushed onto it */
252
+ export function quietRefresh(part) {
253
+ const was = part._started; part._started = false;
254
+ try { flush(part, true); } finally { part._started = was; }
255
+ }