threedog 1.1.0 → 1.3.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 (370) hide show
  1. package/CHANGELOG.md +893 -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 +187 -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 +17 -7
  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 +8 -7
  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 +50 -28
  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 +36 -15
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +47 -4
  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 +17 -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 +30 -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 +24 -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 +7 -2
  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 +75 -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 +10 -9
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +72 -79
  180. package/docs/recipes/63-third-person-start.md +48 -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/.threedog/content-index.json +1 -1
  185. package/examples/action/GAMEMAP.md +2 -3
  186. package/examples/action/main.js +3 -3
  187. package/examples/action/picture/lights.js +3 -1
  188. package/examples/perf-island/.threedog/content-index.json +1 -1
  189. package/examples/perf-island/GAMEMAP.md +3 -3
  190. package/examples/perf-island/picture/lights.js +2 -1
  191. package/examples/plain-picture/GAMEMAP.md +1 -1
  192. package/examples/rc2d/GAMEMAP.md +1 -1
  193. package/examples/styletest/.threedog/content-index.json +1 -1
  194. package/examples/styletest/GAMEMAP.md +2 -2
  195. package/examples/styletest/main.js +1 -1
  196. package/examples/techniques/interior-light/README.md +3 -3
  197. package/examples/techniques/interior-light/interiorLight.js +2 -4
  198. package/examples/techniques/interior-light/picture/lights.js +2 -1
  199. package/examples/techniques/modular-building/picture/lights.js +3 -1
  200. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  201. package/examples/techniques/procedural-animation/README.md +1 -1
  202. package/examples/techniques/procedural-animation/main.js +1 -1
  203. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  204. package/examples/world/.threedog/content-index.json +1 -1
  205. package/examples/world/GAMEMAP.md +2 -3
  206. package/examples/world/art/humanoid.js +1 -1
  207. package/examples/world/main.js +6 -3
  208. package/index.d.ts +2 -2
  209. package/llms.txt +101 -0
  210. package/modules/ambience/Ambience.js +21 -5
  211. package/modules/calendar/index.js +9 -5
  212. package/modules/calendar/schedule.js +23 -8
  213. package/modules/camera/FirstPersonCamera.js +3 -1
  214. package/modules/camera/FollowCamera.js +10 -5
  215. package/modules/camera/RtsCamera.js +4 -3
  216. package/modules/camera/common.js +70 -8
  217. package/modules/camera/contract.js +1 -1
  218. package/modules/characters/Character.js +16 -10
  219. package/modules/characters/NPC.js +31 -19
  220. package/modules/characters/assetModel.js +14 -9
  221. package/modules/characters/astar.js +6 -1
  222. package/modules/characters/contract.js +2 -2
  223. package/modules/characters/index.js +34 -22
  224. package/modules/characters/movers/manual.js +1 -1
  225. package/modules/characters/movers/rapier.js +17 -2
  226. package/modules/characters/movers/simple.js +1 -1
  227. package/modules/characters/movers/support.js +16 -7
  228. package/modules/characters/npcAvoid.js +2 -2
  229. package/modules/characters/npcSim.js +3 -2
  230. package/modules/characters/pathAsync.js +24 -8
  231. package/modules/characters/pathJob.js +1 -1
  232. package/modules/characters/player.js +10 -9
  233. package/modules/characters/playerStrings.js +5 -5
  234. package/modules/characters/proceduralRig.js +5 -5
  235. package/modules/characters/useModel.js +6 -0
  236. package/modules/characters/walkTo.js +1 -1
  237. package/modules/collision/Collision.js +29 -18
  238. package/modules/collision/grid.js +22 -4
  239. package/modules/content/index.js +3 -1
  240. package/modules/content/loader.js +1 -1
  241. package/modules/content/models.js +82 -33
  242. package/modules/content/props.js +2 -1
  243. package/modules/content/rules.js +11 -5
  244. package/modules/content/templates.js +3 -3
  245. package/modules/content/words.js +2 -2
  246. package/modules/debug/DebugPanel.js +9 -9
  247. package/modules/flow/index.js +9 -6
  248. package/modules/gameplay/Dialogue.js +34 -20
  249. package/modules/gameplay/Interactions.js +19 -15
  250. package/modules/gameplay/Inventory.js +9 -4
  251. package/modules/gameplay/Quests.js +12 -10
  252. package/modules/gameplay/pickups.js +23 -11
  253. package/modules/grid/index.js +1 -1
  254. package/modules/grid/preview.js +2 -2
  255. package/modules/grid/tiles.js +1 -1
  256. package/modules/hlod/index.js +4 -1
  257. package/modules/hud/index.js +47 -10
  258. package/modules/hud/parts.js +28 -9
  259. package/modules/level/geometry.js +8 -3
  260. package/modules/level/index.js +10 -5
  261. package/modules/level/load.js +4 -2
  262. package/modules/lights/sources.js +1 -1
  263. package/modules/music/Music.js +22 -4
  264. package/modules/nav/index.js +20 -10
  265. package/modules/particles/Particles.js +31 -14
  266. package/modules/particles/effect.js +20 -5
  267. package/modules/particles/lit.js +72 -0
  268. package/modules/photo/Photo.js +72 -28
  269. package/modules/photo/pathTrace.js +106 -0
  270. package/modules/rigid/RigidBodies.js +23 -14
  271. package/modules/rigid/Vehicles.js +3 -13
  272. package/modules/rigid/sync.js +2 -1
  273. package/modules/settings/Settings.js +52 -20
  274. package/modules/settings/apply.js +23 -9
  275. package/modules/settings/sections.js +39 -6
  276. package/modules/settings/strings.js +2 -0
  277. package/modules/settings/view.js +19 -3
  278. package/modules/sky/dome.js +15 -3
  279. package/modules/sky/environment.js +28 -12
  280. package/modules/sky/fog.js +1 -1
  281. package/modules/sky/frame.js +6 -1
  282. package/modules/sky/shader.js +4 -3
  283. package/modules/sky/skyModule.js +8 -4
  284. package/modules/swarm/Swarm.js +1 -1
  285. package/modules/terrain/ChunkManager.js +61 -15
  286. package/modules/terrain/chunkJob.js +2 -2
  287. package/modules/terrain/index.js +20 -5
  288. package/modules/terrain/terrainEdit.js +8 -4
  289. package/modules/terrain/terrainTexture.js +4 -2
  290. package/modules/timeline/Timeline.js +4 -3
  291. package/modules/timeline/Tween.js +3 -0
  292. package/modules/timeline/letterbox.js +1 -0
  293. package/modules/triggers/index.js +36 -17
  294. package/modules/vegetation/Vegetation.js +81 -19
  295. package/modules/vegetation/densityMap.js +13 -8
  296. package/modules/vegetation/draw.js +147 -24
  297. package/modules/vegetation/groundChunks.js +20 -5
  298. package/modules/vegetation/index.js +3 -3
  299. package/modules/vegetation/modelGeometry.js +9 -4
  300. package/modules/water/Water.js +11 -8
  301. package/modules/weather/Weather.js +7 -2
  302. package/modules/weather/shaders.js +25 -5
  303. package/modules/weather/weatherDraw.js +20 -6
  304. package/modules/world/World.js +2 -1
  305. package/modules/world/index.js +2 -2
  306. package/modules/world/persist.js +6 -2
  307. package/modules/world/views.js +15 -2
  308. package/package.json +5 -1
  309. package/presets.js +5 -5
  310. package/render/PostFX.js +102 -42
  311. package/render/backend.js +142 -16
  312. package/render/bindingLimits.js +59 -0
  313. package/render/cascades.js +3 -1
  314. package/render/cascades.tsl.js +2 -0
  315. package/render/daylight.js +7 -1
  316. package/render/detail.js +7 -4
  317. package/render/effects.js +27 -8
  318. package/render/fogLook.js +24 -0
  319. package/render/fuse.js +5 -2
  320. package/render/fx/compareLevel.tsl.js +23 -0
  321. package/render/fx/detail.tsl.js +9 -7
  322. package/render/fx/index.js +9 -2
  323. package/render/fx/library.tsl.js +1 -0
  324. package/render/fx/lightShaft.tsl.js +114 -0
  325. package/render/fx/noise.tsl.js +25 -8
  326. package/render/fx/objectOrigin.tsl.js +39 -10
  327. package/render/fx/particles.tsl.js +23 -6
  328. package/render/fx/patchNodes.tsl.js +17 -12
  329. package/render/fx/pcss.tsl.js +51 -0
  330. package/render/fx/postWebGPU.tsl.js +104 -29
  331. package/render/fx/sky.tsl.js +3 -9
  332. package/render/fxNumbers.js +10 -4
  333. package/render/impostor.tsl.js +107 -0
  334. package/render/lighting.js +33 -1
  335. package/render/lightmap.js +42 -28
  336. package/render/lights.js +19 -3
  337. package/render/materials.js +6 -4
  338. package/render/mergeCommon.js +4 -1
  339. package/render/occlusion.js +14 -4
  340. package/render/patches.js +79 -41
  341. package/render/postRuns.js +32 -0
  342. package/render/postWebGL.js +97 -10
  343. package/render/probes.js +10 -14
  344. package/render/shaderErrors.js +44 -7
  345. package/render/shadowCache.tsl.js +33 -5
  346. package/render/shadows.js +42 -16
  347. package/render/slots.js +8 -5
  348. package/render/vertexInputs.js +52 -0
  349. package/types/core.d.ts +115 -47
  350. package/types/gameplay.d.ts +56 -23
  351. package/types/generated/core/audio/Audio.d.ts +27 -1
  352. package/types/generated/core/base/Random.d.ts +1 -1
  353. package/types/generated/core/input/Input.d.ts +6 -8
  354. package/types/generated/core/input/inputSeat.d.ts +1 -1
  355. package/types/generated/core/inspect/Budget.d.ts +26 -0
  356. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  357. package/types/generated/core/saves/Saves.d.ts +10 -7
  358. package/types/generated/core/saves/session.d.ts +8 -2
  359. package/types/generated/core/scene/Rays.d.ts +1 -3
  360. package/types/generated/core/scene/Views.d.ts +17 -3
  361. package/types/generated/modules/particles/Particles.d.ts +1 -1
  362. package/types/generated/modules/world/World.d.ts +2 -1
  363. package/types/generated/render/PostFX.d.ts +35 -9
  364. package/types/physics.d.ts +796 -764
  365. package/types/pixel.d.ts +1 -1
  366. package/types/tsl.d.ts +62 -1
  367. package/types/world.d.ts +12 -3
  368. package/ui/Focus.js +7 -5
  369. package/ui/Parts.js +1 -1
  370. package/ui/touchPart.js +6 -3
@@ -13,9 +13,13 @@
13
13
  // An entry { id: 'graphics', omit: ['pixelRatio', 'antialias'] } in that list leaves rows out of the graphics tab.
14
14
  // The whole menu is replaceable: skip this module and build your own (register it as the Esc root with uiFocus(engine).setRoot(() => myMenu.open())).
15
15
  //
16
- // A game's own settings page (e.g. "Gameplay"):
16
+ // A game's own settings (each one a menu row the engine draws, in the 'options' tab unless menu names another; label is an i18n key or text, else the key):
17
17
  // engine.settings.define('subtitles', true, on => game.subtitles = on); // custom setting: default value + apply function, autosaved
18
- // engine.settings.define('volfog', true, { limits: 'post.volfog.enabled' }); // off holds the game's own effect off, like the shadows row
18
+ // engine.settings.define('volfog', true, { limits: 'post.volfog.enabled', menu: 'graphics' }); // off holds the game's own effect off, like the shadows row
19
+ // engine.settings.define('difficulty', 'normal', { options: ['easy', 'normal', 'hard'], label: 'my.difficulty', apply }); // number rows: { min, max, step? }
20
+ // The bloom and ao rows follow post effects by the role they declare (about.acts "glow" / "ao"), whatever the effect is named; every effect with the role follows its row, and the shadows row shows only while a light casts.
21
+ // A tab that draws its rows itself (menu: false on those rows, or the engine draws them a second time):
22
+ // engine.settings.define('subtitles', true, { menu: false, apply: on => game.subtitles = on });
19
23
  // engine.settings.addSection('gameplay', {
20
24
  // title: e => e.t('my.gameplay'),
21
25
  // render: (tools, e, s) => tools.row(tools.t('my.subtitles'), tools.toggle('subtitles', s.get('subtitles'))),
@@ -30,10 +34,10 @@
30
34
  // controls just carry the attributes data-tab / data-set+data-value / data-range / data-rebind / data-reset / data-locale / data-save-export / data-save-import
31
35
  // (see sections.js)
32
36
  import { makeWindow, injectUICSS, uiFocus } from '../../ui/UI.js';
33
- import { BUILTIN_SECTIONS } from './sections.js';
37
+ import { BUILTIN_SECTIONS, rowKindProblem } from './sections.js';
34
38
  import { STRINGS, CSS } from './strings.js';
35
39
  import { SettingsView } from './view.js';
36
- import { applySetting, allowed, checkLimits, releaseLimits, releaseRow } from './apply.js';
40
+ import { applySetting, allowed, checkLimits, releaseLimits, releaseRow, ROLE_ROWS, roleEffects } from './apply.js';
37
41
  import { readParams, keysSchema } from '../../core/base/params.js';
38
42
  import { codedError, coded } from '../../core/base/errorHints.js';
39
43
  import { warnOnce } from '../../core/base/validate.js';
@@ -52,7 +56,9 @@ const PRESETS = {
52
56
  // Preset rows that are shares, and how each share lands on its whole
53
57
  const SHARES = { pixelRatio: n => +n.toFixed(2), viewChunks: n => Math.max(1, Math.round(n)), density: n => +n.toFixed(2) };
54
58
  // Settings keys that switch a post effect of the same name; a key whose effect the game did not add is hidden and ignored
55
- const POST_KEYS = ['bloom', 'ao'];
59
+ const POST_KEYS = Object.keys(ROLE_ROWS);
60
+ // settings.define's options: a typo (lable, men) throws in dev instead of silently drawing the key as the label
61
+ const DEFINE_KEYS = keysSchema(['apply', 'limits', 'menu', 'label', 'options', 'min', 'max', 'step']);
56
62
 
57
63
  /**
58
64
  * The graphics rows a game left out: the { id: 'graphics', omit } entry of sections. An omitted row is the game's value: no control, and no preset or stored value moves it.
@@ -103,23 +109,26 @@ export class Settings extends SettingsView {
103
109
  engine.i18n.add(STRINGS);
104
110
  // the default opener is the basic cancel key (the UI focus stack hands it to the menu when nothing else is open); another action is the
105
111
  // game's, declared here and bound by the game (settings({ action: 'menu' }) + engine.input.bind('menu', ['Tab']))
106
- if (action !== 'cancel') track(engine.input.action(action, { label: 'settings.action', owner: 'settings' }));
112
+ if (action !== 'cancel') track(engine.input.define(action, { label: 'settings.action', owner: 'settings' }));
107
113
  injectUICSS(CSS);
108
114
 
109
115
  const stored = this._read();
110
116
  // the player's saved keys: through input.rebind, the one way to rebind (the settings layer of 'input.keys'). It works before the module that
111
117
  // declares an action is installed, so nothing waits for "every action registered"
112
- for (const [a, k] of Object.entries(stored.bindings || {})) if (Array.isArray(k) && k.length) engine.input.rebind(a, k);
118
+ for (const [a, k] of Object.entries(stored.bindings || {})) if (Array.isArray(k)) engine.input.rebind(a, k); // [] is a saved choice (no key), only a missing entry means never saved
113
119
  this._defaults = this._currentValues(); // the engine's own values before the player's saved ones: what reset() goes back to
114
120
  // Only what the player changed is stored and applied, like input.rebound() for keys. The rest stays with whoever owns it (the tier, adaptive
115
121
  // resolution, the game), so one volume change no longer pins every graphics value for all later launches
116
122
  /** @internal key -> value; 'quality' names a chosen preset, the rows after it override it */ this._changed = playerValues(stored, this._defaults);
123
+ /** @internal row key -> the shared points it holds off now (apply.js limitRow): what it gives back, never a fresh query */ this._held = new Map();
117
124
  this._values = { ...this._defaults, ...this._picked() };
118
125
  this._values.quality = this._matchPreset();
119
126
  for (const [k, v] of Object.entries(this._picked())) this._apply(k, v);
120
127
  // Tabs: true = the default set; a list picks built-in and optional tabs by name (optional ones register their own settings in setup)
121
128
  if (sections === true) for (const [id, s] of Object.entries(BUILTIN_SECTIONS)) this.sections.set(id, s);
122
129
  else if (sections) for (const s of sections) this._builtin(s.id ?? s);
130
+ // whatever tabs the game picked: a defined row must have a place to show (the tab hides while it has none)
131
+ if (sections) this._builtin('options');
123
132
  if (stored.locale && engine.i18n.languages.includes(stored.locale) && stored.locale !== engine.i18n.locale) engine.i18n.setLocale(stored.locale);
124
133
 
125
134
  this.win = makeWindow(engine, {
@@ -140,6 +149,8 @@ export class Settings extends SettingsView {
140
149
  track(engine.events.on('ui:open', id => { if (id === 'settings') this._pause(true); }));
141
150
  track(engine.events.on('ui:close', id => { if (id === 'settings') this._pause(false); }));
142
151
  track(engine.events.on('i18n:change', () => { if (this._ready) this.save(); }));
152
+ // an effect added after the player's choice was applied (the game adds its effects after settings installs) still gets it: a row follows an effect by role, so there is no point to wait on by name
153
+ track(engine.events.on('post:add', name => { for (const k of POST_KEYS) if (this._values[k] === false && roleEffects(engine, k).some(h => h.name === name)) this._apply(k, false); }));
143
154
  }
144
155
 
145
156
  // ---------- reading and writing settings ----------
@@ -157,14 +168,14 @@ export class Settings extends SettingsView {
157
168
  * Change a setting: applies at once and saves. Changing a graphics setting turns the preset into "custom". A key no row owns throws: storing it would read back a value nothing
158
169
  * applied. Before start() a module's row may still come, so an unknown key waits and init() reports it.
159
170
  */
160
- set(key, value, { save = true } = {}) {
171
+ set(key, value, { save = true, apply = true } = {}) {
161
172
  if (key === 'quality') return this.preset(value);
162
173
  if (!this._hasRow(key)) {
163
174
  if (this._ready) throw codedError('settings-row', `settings.set('${key}'): no setting has this key. Known: ${Object.keys(this._values).join(', ')}. Add the row with settings.define('${key}', ...) or the tab that has it (settings({ sections }))`);
164
175
  this._early.add(key);
165
176
  }
166
177
  this._values[key] = value; this._changed[key] = value;
167
- this._apply(key, value);
178
+ if (apply) this._apply(key, value);
168
179
  if (key in (this.presets.low || {})) this._values.quality = this._matchPreset();
169
180
  if (save) this.save();
170
181
  this.win.refresh();
@@ -183,25 +194,37 @@ export class Settings extends SettingsView {
183
194
  * value(s) the row restricts on the settings layer, the same way the built-in shadows row does: off holds the value off (a cutscene or the
184
195
  * scene cannot turn it back on), on allows what the scene chose; a number row from 0 to 1 is a factor on a number value.
185
196
  * A row a module defines from its install, init or a hook leaves with that module and gives its limits back; the player's choice waits for its return.
197
+ * The menu draws the row (a switch for true/false, a slider for a number with min/max, buttons for options) in the tab menu names, default
198
+ * 'options'; label is an i18n key or text, else the key. menu: false = a tab of the game's own draws it.
186
199
  * @param {string} key @param {any} def
187
- * @param {((value: any, engine: any) => void) | { apply?: (value: any, engine: any) => void, limits?: string | string[] }} [apply]
200
+ * @param {((value: any, engine: any) => void) | { apply?: (value: any, engine: any) => void, limits?: string | string[], menu?: string | false, label?: string, options?: any[], min?: number, max?: number, step?: number }} [apply]
188
201
  * @example engine.settings.define('volfog', true, { limits: 'post.volfog.enabled' }); // after engine.post.add(volFog)
189
202
  */
190
203
  define(key, def, apply) {
191
- const o = typeof apply === 'function' || apply == null ? { apply } : apply;
204
+ const o = readParams(`settings.define('${key}')`, DEFINE_KEYS, typeof apply === 'function' || apply == null ? { apply } : apply);
192
205
  const limits = o.limits == null ? null : [].concat(o.limits);
193
206
  if (limits) checkLimits(this, key, def, limits);
194
- const row = { def, apply: o.apply, limits };
207
+ if (o.menu !== undefined && o.menu !== false && typeof o.menu !== 'string') throw codedError('module-params', `settings.define('${key}', ..., { menu }): menu is a tab id ('options', 'graphics', your own) or false when your own tab draws the row; got ${JSON.stringify(o.menu)}`);
208
+ // a limits number row is a factor from 0 to 1, so its slider has its ends already
209
+ const factor = limits && typeof def === 'number';
210
+ const row = { def, apply: o.apply, limits, label: o.label, options: o.options, min: o.min ?? (factor ? 0 : undefined), max: o.max ?? (factor ? 1 : undefined), step: o.step, menu: o.menu ?? 'options' };
211
+ // a choice value is a string, number or boolean: a click and the saved file give back a JSON copy, and an object copy never equals the
212
+ // option again, so its button would lose the selected state (no deep compare: a plain value is the whole rule)
213
+ const odd = Array.isArray(o.options) ? o.options.map(x => Array.isArray(x) ? x[0] : x).find(v => !['string', 'number', 'boolean'].includes(typeof v)) : undefined;
214
+ if (odd !== undefined) throw codedError('settings-row', `settings.define('${key}', ..., { options }): a choice value is a string, number or boolean; got ${JSON.stringify(odd) ?? typeof odd}. Name the choice ('large') and map it in apply`);
215
+ const why = row.menu === false ? '' : rowKindProblem(row);
216
+ if (why) { warnOnce(coded('settings-row', `settings.define('${key}', ${JSON.stringify(def)}): the menu cannot draw this row (${why}), so the player has no control for it. Or menu: false when your own tab draws it`)); row.menu = false; }
195
217
  this.custom.set(key, row);
196
218
  const picked = this._picked(); // a preset's share of this row is only known now that the row says what it is a share of
197
219
  if (key in picked) this._values[key] = picked[key];
198
220
  else if (!(key in this._values)) this._values[key] = def;
199
221
  this._apply(key, this._values[key]);
200
222
  if (this._ready) this._values.quality = this._matchPreset();
223
+ this.win?.refresh(); // an open menu shows the new row now (the camera tab defines its rows before the window exists)
201
224
  this._leavesWithModule(() => {
202
225
  if (this.custom.get(key) !== row) return; // the name was defined again: that row is someone else's
203
226
  this.custom.delete(key);
204
- if (limits) releaseRow(this.engine, limits);
227
+ if (limits) releaseRow(this, key);
205
228
  if (!(key in this._changed)) delete this._values[key];
206
229
  });
207
230
  return this;
@@ -285,21 +308,30 @@ export class Settings extends SettingsView {
285
308
 
286
309
  // ---------- storage ----------
287
310
  _read() {
288
- try { const d = JSON.parse(localStorage.getItem(this.storageKey)); return d && typeof d === 'object' ? d : {}; } catch { return {}; }
311
+ let why = 'not an object';
312
+ try {
313
+ const raw = localStorage.getItem(this.storageKey);
314
+ if (raw == null) return {};
315
+ const d = JSON.parse(raw);
316
+ if (d && typeof d === 'object') return d;
317
+ } catch (e) { why = e.message; }
318
+ warnOnce(coded('save-write', `[settings] the stored settings could not be read (${why}); the defaults are used, and the next change overwrites the stored entry`));
319
+ return {};
289
320
  }
290
321
  save() {
291
322
  const bindings = this.engine.input.rebound(); // only the player's changes; restored through input.rebind on the next launch
292
323
  const data = { v: 2, values: { ...this._changed }, bindings, locale: this.engine.i18n.locale };
293
- try { localStorage.setItem(this.storageKey, JSON.stringify(data)); } catch { return false; }
294
- this.engine.events.emit('settings:change', this.values);
295
- return true;
324
+ let stored = true;
325
+ try { localStorage.setItem(this.storageKey, JSON.stringify(data)); } catch (e) { stored = false; warnOnce(coded('save-write', `[settings] could not store the settings (${e.message}); the choice is applied but will not survive a reload`)); }
326
+ this.engine.events.emit('settings:change', this.values); // also when the write failed: the value is applied, listeners must follow it
327
+ return stored;
296
328
  }
297
329
 
298
330
  // ---------- applying ----------
299
331
  _currentValues() {
300
332
  const e = this.engine, v = { pixelRatio: +e.adaptive.base.toFixed(2), shadows: allowed(e, 'shadows.enabled'), tier: null };
301
333
  v.antialias = e.post.authoredAA; // the default, not what this launch runs with: a choice stored for this launch is the player's, and reset() must get past it
302
- for (const k of POST_KEYS) v[k] = allowed(e, `post.${k}.enabled`); // a permission, known before the effect exists: this runs at install, the game adds its effects after
334
+ for (const k of POST_KEYS) v[k] = roleEffects(e, k).every(h => allowed(e, `post.${h.name}.enabled`)); // a permission, true while no effect of the role exists yet: this runs at install, the game adds its effects after
303
335
  v.adaptive = !!e.adaptive.on;
304
336
  for (const [bus, level] of Object.entries(e.audio.levels)) v['vol.' + bus] = level; // one slider per bus, the game's own buses too
305
337
  return v;
@@ -326,7 +358,7 @@ export class Settings extends SettingsView {
326
358
  const v = this._values, e = this.engine;
327
359
  for (const name of Object.keys(this.presets)) {
328
360
  const ok = Object.entries(this._presetValues(name)).every(([k, val]) => {
329
- if (k === 'tier' || (POST_KEYS.includes(k) && !e.post.get(k))) return true; // nothing the menu shows: no reason to call the picture custom
361
+ if (k === 'tier' || (POST_KEYS.includes(k) && !roleEffects(e, k).length)) return true; // nothing the menu shows: no reason to call the picture custom
330
362
  return v[k] === val;
331
363
  });
332
364
  if (ok) return name;
@@ -414,5 +446,5 @@ export function settings(opts = {}) {
414
446
 
415
447
  export const handRolled = [
416
448
  { kind: 'pause', seen: 'a pause or Esc handler of its own', use: 'settings({ freezeWorld: true }): Esc stops every system and opens the menu (recipe 63); engine.freeze(why) for a pause with no menu', quiet: /\bsettings\(|\bengine\.(freeze|flow|settings)\b|\buiFocus\(/, code: /\b(?:let|var)\s+(?:is|game)?paused\s*=/i, orRaw: /(?:\.key|\.code)\s*===?\s*['"]Escape['"]/, tags: false },
417
- { kind: 'settings', seen: 'a settings menu of its own', use: 'the settings module: volume, keys, quality and language in one menu that remembers itself; settings.define adds your own (recipe 26)', quiet: /\bsettings\(|\bengine\.settings\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, raw: /(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)[^,;{}]*(?:settings|options-?(?:menu|panel|screen)|pause-?menu)|(?:settings|options|pause)-?(?:menu|panel|screen)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)/i },
449
+ { kind: 'settings', seen: 'a settings menu of its own', use: 'engine.settings (settings()): volume, keys, quality and language in one menu that remembers itself; engine.settings.define adds your own (recipe 26)', quiet: /\bsettings\(|\bengine\.settings\b/, code: /\b(createElement|innerHTML|className|classList|getElementById|querySelector|\.id)\b/, raw: /(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)[^,;{}]*(?:settings|options-?(?:menu|panel|screen)|pause-?menu)|(?:settings|options|pause)-?(?:menu|panel|screen)[^,;{}]*(?:createElement|innerHTML|className|classList|getElementById|querySelector|\.id\b)/i },
418
450
  ];
@@ -4,7 +4,11 @@ import { codedError } from '../../core/base/errorHints.js';
4
4
  // the game (define). `s` is the Settings instance.
5
5
 
6
6
  /** The shared values each built-in row limits. A game's own row names its values with define(key, def, { limits }); both go through limit() */
7
- const BUILTIN_LIMITS = { shadows: ['shadows.enabled'], bloom: ['post.bloom.enabled'], ao: ['post.ao.enabled'] };
7
+ // The bloom and ao rows follow effects by the role they declare (about.acts, @threedog/post-effects), never by name: a game's 'glow' is a bloom. Every effect of the role follows the row
8
+ export const ROLE_ROWS = { bloom: 'glow', ao: 'ao' };
9
+ /** The effects a built-in post row follows now @param {any} e @param {string} key 'bloom' | 'ao' */
10
+ export const roleEffects = (e, key) => e.post.byRole(ROLE_ROWS[key], key);
11
+ const builtinLimits = e => ({ shadows: ['shadows.enabled'], ...Object.fromEntries(Object.keys(ROLE_ROWS).map(k => [k, roleEffects(e, k).map(h => `post.${h.name}.enabled`)])) });
8
12
 
9
13
  /**
10
14
  * The settings layer only restricts (core/ops/sharedPoint.js). A row's value on one shared point: true (or 1) drops the settings entry, so the scene's
@@ -21,12 +25,22 @@ function limit(e, name, val) {
21
25
  if (allow) p.release('settings');
22
26
  else p.take({ owner: 'settings', layer: 'settings', ...(p.kind === 'number' ? { mul: val === false ? 0 : val } : { set: val }) });
23
27
  }
24
- /** @internal a row leaves: no control is left to lift its limits, so it gives its shared values back @param {any} e @param {string[]} names */
25
- export function releaseRow(e, names) { for (const n of names) if (e.stacks.has(n)) e.stacks.get(n).release('settings'); }
26
- /** @internal the module leaves: so does every row */
27
- export function releaseLimits(s) {
28
- for (const names of [...Object.values(BUILTIN_LIMITS), ['tier'], ...[...s.custom.values()].map(c => c.limits ?? [])]) releaseRow(s.engine, names);
28
+ const lift = (e, n) => { if (e.stacks.has(n)) e.stacks.get(n).release('settings'); };
29
+ /**
30
+ * A row's value on its points, then what it holds afterwards. A row gives back the points it holds (s._held), never a fresh query: the bloom row follows
31
+ * effects by role, and the effects of a role change while the row is off (a legacy 'bloom' stops being one once a 'glow' declares acts: 'glow'), so a
32
+ * query made at release time misses the point the row holds and leaves it off for good. A held point the row no longer covers is let go here.
33
+ */
34
+ function limitRow(s, key, names, val) {
35
+ const e = s.engine;
36
+ for (const n of s._held.get(key) ?? []) if (!names.includes(n)) lift(e, n);
37
+ for (const n of names) limit(e, n, val);
38
+ s._held.set(key, names.filter(n => !allowed(e, n)));
29
39
  }
40
+ /** @internal a row leaves: no control is left to lift its limits, so it gives back every shared value it holds @param {any} s @param {string} key */
41
+ export function releaseRow(s, key) { for (const n of s._held.get(key) ?? []) lift(s.engine, n); s._held.delete(key); }
42
+ /** @internal the module leaves: so does every row, and the tier it chose */
43
+ export function releaseLimits(s) { for (const key of [...s._held.keys()]) releaseRow(s, key); lift(s.engine, 'tier'); }
30
44
  /** @internal the row's value fits the points it limits: a switch row (boolean) limits switches or numbers, a number row (a factor) only numbers */
31
45
  export function checkLimits(s, key, def, names) {
32
46
  const e = s.engine;
@@ -36,7 +50,7 @@ export function checkLimits(s, key, def, names) {
36
50
  const kind = e.stacks.get(n).kind;
37
51
  const ok = typeof def === 'boolean' ? kind === 'number' || kind === 'value' : typeof def === 'number' && kind === 'number';
38
52
  if (!ok) throw codedError('shared-settings', `settings.define('${key}', ${JSON.stringify(def)}, { limits: '${n}' }): '${n}' holds ${kind === 'number' ? 'a number' : 'a value'}; a row limits it with ${kind === 'number' ? 'a switch (false = 0) or a factor from 0 to 1' : 'a switch: true allows what the scene chose, false turns it off'}`);
39
- for (const [other, c] of [...Object.entries(BUILTIN_LIMITS).map(([k, l]) => [k, { limits: l }]), ...s.custom])
53
+ for (const [other, c] of [...Object.entries(builtinLimits(e)).map(([k, l]) => [k, { limits: l }]), ...s.custom])
40
54
  if (other !== key && c.limits?.includes(n)) throw codedError('shared-settings', `settings.define('${key}', { limits: '${n}' }): the row '${other}' already limits it; one row per value (the player would not know which one wins)`);
41
55
  }
42
56
  }
@@ -47,8 +61,8 @@ export function applySetting(s, key, val) {
47
61
  const e = s.engine;
48
62
  try {
49
63
  // shadows, bloom, ao and a game row's { limits }: off restricts, on allows what the game chose
50
- const limits = BUILTIN_LIMITS[key] ?? s.custom.get(key)?.limits;
51
- if (limits) for (const n of limits) limit(e, n, typeof val === 'number' ? val : !!val);
64
+ const limits = builtinLimits(e)[key] ?? s.custom.get(key)?.limits;
65
+ if (limits) limitRow(s, key, limits, typeof val === 'number' ? val : !!val);
52
66
  switch (key) {
53
67
  case 'pixelRatio': e.setPixelRatio(val); break;
54
68
  case 'antialias': e.post.nextAntialias(val); break;
@@ -9,6 +9,8 @@
9
9
  // data-locale="en" switch language
10
10
 
11
11
  import { setFov, lensFov } from '../../core/scene/view.js';
12
+ import { roleEffects } from './apply.js';
13
+ import { someLight } from '../../core/inspect/pictureMenu.js';
12
14
 
13
15
  const pct = v => Math.round(v * 100) + '%';
14
16
  /** Value shown beside a slider */
@@ -45,6 +47,33 @@ export function settingsTools(engine, esc) {
45
47
  };
46
48
  }
47
49
 
50
+ /** A defined row's text: an i18n key when one exists, else the text itself (the audio tab names a bus the same way) */
51
+ const labelOf = (e, text) => e.i18n.has(text) ? e.t(text) : text;
52
+ /**
53
+ * The rows settings.define() draws itself, in the tab its menu option names (default 'options'). Why the engine draws them: a row defined
54
+ * and drawn by no tab was a setting the player could never reach, and nothing said so (old-mine's two quality rows). menu: false = the game draws it.
55
+ * @param {any} tools @param {any} e @param {any} s @param {string | null} tab @returns {string}
56
+ */
57
+ export function definedRows(tools, e, s, tab) {
58
+ let h = '';
59
+ for (const [key, r] of s.custom) {
60
+ if (r.menu !== tab) continue;
61
+ const v = s.values[key], label = labelOf(e, r.label ?? key);
62
+ const ctl = r.options ? segmented(key, v, r.options.map(o => Array.isArray(o) ? [o[0], labelOf(e, String(o[1]))] : [o, labelOf(e, String(o))]), tools)
63
+ : typeof r.def === 'boolean' ? toggle(key, v, tools)
64
+ : range(key, v, r.min, r.max, r.step ?? (r.max - r.min) / 20, tools);
65
+ h += row(label, ctl, tools.esc);
66
+ }
67
+ return h;
68
+ }
69
+ /** Why the menu cannot draw a defined row ('' = it can). A number row needs its ends: a guessed range would cut off the game's own value */
70
+ export function rowKindProblem(r) {
71
+ if (r.options) return Array.isArray(r.options) && r.options.length ? '' : 'options is a non-empty list of values or [value, label] pairs';
72
+ if (typeof r.def === 'boolean') return '';
73
+ if (typeof r.def === 'number') return Number.isFinite(r.min) && Number.isFinite(r.max) && r.max > r.min ? '' : 'a number row needs { min, max } (a limits row from 0 to 1 has them already)';
74
+ return `a ${typeof r.def} default is drawn as a choice: pass options: [...]`;
75
+ }
76
+
48
77
  export const BUILTIN_SECTIONS = {
49
78
  graphics: {
50
79
  order: 10, title: e => e.t('settings.graphics'),
@@ -55,10 +84,10 @@ export const BUILTIN_SECTIONS = {
55
84
  const add = (key, label, ctl) => { if (!s._omit.has(key)) h += row(label, ctl, esc); }; // a row the game left out: settings({ sections: [{ id: 'graphics', omit }] })
56
85
  add('quality', t('settings.quality'), segmented('quality', v.quality, opts, tools, ['custom']));
57
86
  add('pixelRatio', t('settings.pixelRatio'), range('pixelRatio', v.pixelRatio, 0.5, 2, 0.05, tools));
58
- add('shadows', t('settings.shadows'), toggle('shadows', v.shadows, tools));
87
+ if (someLight(e.scene, l => l.castShadow)) add('shadows', t('settings.shadows'), toggle('shadows', v.shadows, tools)); // like bloom and ao: no row for an effect nothing uses
59
88
  add('antialias', t('settings.antialias'), toggle('antialias', v.antialias, tools));
60
- if (e.post.get('bloom')) add('bloom', t('settings.bloom'), toggle('bloom', v.bloom, tools));
61
- if (e.post.get('ao')) add('ao', t('settings.ao'), toggle('ao', v.ao, tools));
89
+ if (roleEffects(e, 'bloom').length) add('bloom', t('settings.bloom'), toggle('bloom', v.bloom, tools));
90
+ if (roleEffects(e, 'ao').length) add('ao', t('settings.ao'), toggle('ao', v.ao, tools));
62
91
  add('adaptive', t('settings.adaptive'), toggle('adaptive', v.adaptive, tools));
63
92
  // the ground's own rows: the slider reaches at least as far as the game's value and the share Low gave it
64
93
  const view = s.custom.get('viewChunks');
@@ -120,6 +149,9 @@ export const BUILTIN_SECTIONS = {
120
149
  // settings({ sections: ['graphics', 'audio', 'controls', 'game', 'camera'] }) or engine.settings.addSection('camera').
121
150
  // setup(s) runs once when the tab is added and registers the tab's own settings (saved like any other).
122
151
  export const OPTIONAL_SECTIONS = {
152
+ // The tab defined rows land in unless they name another. Settings adds it whatever list the game picked and it shows only while a row is in it;
153
+ // it sits in this one lookup so naming it (sections: ['options'], addSection('options')) works like any other tab name
154
+ options: { order: 60, title: e => e.t('settings.options'), when: e => [...(e.settings?.custom.values() ?? [])].some(r => r.menu === 'options'), render: () => '' },
123
155
  // Resume / load a slot / back to title (only when the game turned the title part on)
124
156
  game: {
125
157
  order: 5, title: e => e.t('settings.game'),
@@ -147,9 +179,10 @@ export const OPTIONAL_SECTIONS = {
147
179
  order: 25, title: e => e.t('settings.camera'), when: e => !!e.cameraRig,
148
180
  setup(s) {
149
181
  const e = s.engine, rig = () => e.cameraRig;
150
- s.define('camera.sensitivity', rig()?.sensitivity ?? 1, v => { if (rig() && 'sensitivity' in rig()) rig().sensitivity = v; });
151
- s.define('camera.invertY', rig()?.invertY ?? false, v => { if (rig() && 'invertY' in rig()) rig().invertY = v; });
152
- s.define('camera.fov', lensFov(e) ?? 50, v => setFov(e, v)); // the player's slider: yields to a fov the game took (engine.autoView.manual('fov'))
182
+ // menu: false: this tab draws the three rows itself, with their own ranges
183
+ s.define('camera.sensitivity', rig()?.sensitivity ?? 1, { menu: false, apply: v => { if (rig() && 'sensitivity' in rig()) rig().sensitivity = v; } });
184
+ s.define('camera.invertY', rig()?.invertY ?? false, { menu: false, apply: v => { if (rig() && 'invertY' in rig()) rig().invertY = v; } });
185
+ s.define('camera.fov', lensFov(e) ?? 50, { menu: false, apply: v => setFov(e, v) }); // the player's slider: yields to a fov the game took (engine.autoView.manual('fov'))
153
186
  // a new rig starts from its own defaults (and setCamera resets the fov): put the player's choices back on it
154
187
  s._track(e.events.on('camera:change', () => { for (const k of ['camera.sensitivity', 'camera.invertY', 'camera.fov']) s.custom.get(k)?.apply(s.values[k], e); }));
155
188
  },
@@ -16,6 +16,7 @@ export const STRINGS = {
16
16
  'settings.langName.zh-CN': '简体中文', 'settings.langName.en': 'English',
17
17
  'settings.game': '游戏', 'settings.resume': '继续游戏', 'settings.load': '读档', 'settings.toTitle': '回到标题',
18
18
  'settings.camera': '镜头', 'settings.sensitivity': '鼠标灵敏度', 'settings.invertY': '反转 Y 轴', 'settings.fov': '视野',
19
+ 'settings.options': '选项',
19
20
  },
20
21
  en: {
21
22
  'title.settings': 'Settings', 'module.settings': 'settings',
@@ -32,6 +33,7 @@ export const STRINGS = {
32
33
  'settings.langName.zh-CN': '简体中文', 'settings.langName.en': 'English',
33
34
  'settings.game': 'Game', 'settings.resume': 'Resume', 'settings.load': 'Load', 'settings.toTitle': 'Back to title',
34
35
  'settings.camera': 'Camera', 'settings.sensitivity': 'Mouse sensitivity', 'settings.invertY': 'Invert Y', 'settings.fov': 'Field of view',
36
+ 'settings.options': 'Options',
35
37
  },
36
38
  };
37
39
 
@@ -1,7 +1,8 @@
1
1
  // UI part of the settings menu (tabs, redraw, click/slider events); Settings inherits it.
2
- import { formatValue, BUILTIN_SECTIONS, OPTIONAL_SECTIONS, settingsTools } from './sections.js';
2
+ import { formatValue, BUILTIN_SECTIONS, OPTIONAL_SECTIONS, settingsTools, definedRows } from './sections.js';
3
3
  import { esc } from '../../ui/UI.js';
4
- import { codedError } from '../../core/base/errorHints.js';
4
+ import { codedError, coded } from '../../core/base/errorHints.js';
5
+ import { warnOnce } from '../../core/base/validate.js';
5
6
  import { reportError } from '../../core/base/errors.js';
6
7
 
7
8
  const CSS_ESC = s => (globalThis.CSS?.escape ? globalThis.CSS.escape(s) : String(s).replace(/["\\]/g, '\\$&'));
@@ -25,8 +26,22 @@ export class SettingsView {
25
26
  const sec = this.sections.get(this.current);
26
27
  let body = '';
27
28
  try { body = sec ? sec.render(tools, this.engine, this) : ''; } catch (err) { reportError(this.engine, err, `settings tab '${this.current}' render`, { soft: true }); }
29
+ this._checkDefinedRows(body);
30
+ body += definedRows(tools, this.engine, this, this.current); // the rows define() put in this tab, drawn by the same helpers as the built-in rows
28
31
  return { sections: list.map(([id, s]) => ({ id, title: s.title(this.engine), active: id === this.current })), current: this.current, body, values: { ...this.values } };
29
32
  }
33
+ /**
34
+ * @internal The two ways a defined row still goes wrong, said once each instead of drawn wrong in silence: a tab the game draws itself also
35
+ * draws a row the engine draws (two rows, pass menu: false), and a row names a tab the menu does not have (no row at all)
36
+ * @param {string} body the current tab's own HTML
37
+ */
38
+ _checkDefinedRows(body) {
39
+ for (const [key, r] of this.custom) {
40
+ if (r.menu === false) continue;
41
+ if (!this.sections.has(r.menu)) warnOnce(coded('settings-row', `settings.define('${key}', ..., { menu: '${r.menu}' }): the menu has no tab '${r.menu}', so the row shows nowhere. Tabs: ${[...this.sections.keys()].join(', ')}`));
42
+ else if (body.includes(`data-set="${esc(key)}"`) || body.includes(`data-range="${esc(key)}"`)) warnOnce(coded('settings-row', `settings tab '${this.current}' draws '${key}' itself and the engine draws it too (in '${r.menu}'): pass settings.define('${key}', ..., { menu: false, apply })`));
43
+ }
44
+ }
30
45
  _tools() { return settingsTools(this.engine, esc); }
31
46
  _render({ sections, body }, { esc }) {
32
47
  const tabs = sections.map(s => `<button type="button" role="tab" class="threedog-btn threedog-tab${s.active ? ' is-active' : ''}" aria-selected="${s.active}" data-tab="${esc(s.id)}">${esc(s.title)}</button>`).join('');
@@ -61,7 +76,8 @@ export class SettingsView {
61
76
  });
62
77
  el.addEventListener('change', ev => {
63
78
  const r = ev.target.closest?.('[data-range]'); if (!r) return;
64
- this.set(r.dataset.range, +r.value);
79
+ // the live 'input' above already applied this value; only the two world-rebuilding rows still wait for release
80
+ this.set(r.dataset.range, +r.value, { apply: r.dataset.range === 'density' || r.dataset.range === 'viewChunks' });
65
81
  });
66
82
  }
67
83
  }
@@ -9,6 +9,7 @@ import { domeFragment, loadSkybox, skyNodes } from './shader.js';
9
9
  import { DOME_FOG } from './fog.js';
10
10
  import { codedError } from '../../core/base/errorHints.js';
11
11
  import { isWebGPU } from '../../render/backend.js';
12
+ import { fogLook } from '../../render/fogLook.js';
12
13
 
13
14
  const isColorLike = v => typeof v === 'number' || typeof v === 'string' || !!v?.isColor;
14
15
 
@@ -17,7 +18,7 @@ export function prepareDome(sky, st) {
17
18
  sky._backdrop = resolveBackdrop(st);
18
19
  const f = DOME_FOG;
19
20
  // the fog object belongs to the game and may be replaced: read its color at draw time (fog.js fogBand turns the band on)
20
- const uniforms = { uFogBand: { value: 0 }, uFogColor: { get value() { return sky.engine.scene.fog?.color ?? sky.uniforms.uHorizon.value; } } };
21
+ const uniforms = { uFogBand: { value: 0 }, uFogColor: { get value() { return fogLook(sky.engine.scene, sky.engine.renderer)?.color ?? sky.uniforms.uHorizon.value; } } };
21
22
  return { uniforms, decl: f.decl, body: f.body, layers: [] };
22
23
  }
23
24
 
@@ -36,7 +37,16 @@ function resolveBackdrop(st) {
36
37
  */
37
38
  export function domeEntries(sky, st) {
38
39
  const e = sky.engine, scene = e.scene, U = sky.uniforms;
39
- let cloudsHook = null, added = null, addedHere = false;
40
+ // clone: the panorama copy replace() makes of a game's plain Texture; the sky made it, so the sky frees it on the next replace and on dispose (the game's texture stays)
41
+ let cloudsHook = null, added = null, addedHere = false, clone = null;
42
+ // detached before it is freed: a skybox asset still loading leaves the background as it was until it arrives, and a frame drawn meanwhile would upload
43
+ // the freed copy again, which nobody frees afterwards. The base background shows during that wait
44
+ const dropClone = () => {
45
+ if (!clone) return;
46
+ if (scene.background === clone) scene.background = e.baseBackground;
47
+ if (sky.skybox === clone) sky.skybox = null;
48
+ clone.dispose(); clone = null;
49
+ };
40
50
  const layers = new Map();
41
51
  // a skybox dims with the hour through scene.backgroundIntensity: it comes off with the skybox, or whatever shows next stays dimmed
42
52
  const undim = () => { if (sky.skybox && scene.background === sky.skybox) scene.backgroundIntensity = 1; };
@@ -88,13 +98,14 @@ export function domeEntries(sky, st) {
88
98
  if (added) { if (addedHere) scene.remove(added); added = null; addedHere = false; }
89
99
  undim();
90
100
  sky._ownSky = null; sky._noSky = impl === false; sky._panorama = null;
101
+ dropClone(); // every branch below replaces the background the copy was on
91
102
  // false: no drawn sky. The signals keep running and the scene shows its base background (a game's palette color lives there)
92
103
  if (impl === false) { sky.skybox = null; sky._backdrop = null; sky.dome.visible = false; scene.background = e.baseBackground; sky._oBg.manual(false); sky._oBg.mark(); return; }
93
104
  if (impl == null) { sky.skybox = null; scene.background = sky._backdrop?.color ?? null; sky.dome.visible = !sky._backdrop; sky._oBg.manual(false); sky._oBg.mark(); return; }
94
105
  sky.dome.visible = false; sky._backdrop = null; // a backdrop left on would be written over this sky every frame
95
106
  if (typeof impl === 'string') loadSkybox(sky, impl);
96
107
  else if (impl.isTexture) {
97
- const tex = impl.isCubeTexture || impl.mapping !== THREE.UVMapping ? impl : Object.assign(impl.clone(), { mapping: THREE.EquirectangularReflectionMapping });
108
+ const tex = impl.isCubeTexture || impl.mapping !== THREE.UVMapping ? impl : (clone = Object.assign(impl.clone(), { mapping: THREE.EquirectangularReflectionMapping }));
98
109
  scene.background = tex; sky.skybox = tex;
99
110
  } else if (impl.isObject3D) {
100
111
  addedHere = !impl.parent; if (addedHere) scene.add(engineOwned('sky', impl));
@@ -108,6 +119,7 @@ export function domeEntries(sky, st) {
108
119
  if (added && addedHere) scene.remove(added);
109
120
  undim();
110
121
  if (scene.background && (scene.background === sky.skybox || scene.background === sky._backdrop?.color)) scene.background = e.baseBackground;
122
+ dropClone();
111
123
  },
112
124
  };
113
125
  }
@@ -16,21 +16,36 @@ import { isWebGPU, webgpuPart } from '../../render/backend.js';
16
16
  const DEFAULT_INTERVAL = 1; // seconds between rebuilds (only when the sky actually changed)
17
17
  const LOW_TIER_SLOWER = 4; // by default a low-tier device rebuilds this many times less often (an interval the game gives stands): the cube cannot be made smaller (256 px is PMREMGenerator's floor)
18
18
 
19
- // Numbers that decide how the procedural sky looks right now: when they stay put the environment is not rebuilt
20
- function skyKey(u) {
21
- const f = x => Math.round(x * 400);
22
- return [...u.uTop.value.toArray(), ...u.uHorizon.value.toArray(), ...u.uSunDir.value.toArray(), ...u.uSunColor.value.toArray(), u.uNight.value, u.uWeatherCloud.value].map(f).join(',');
19
+ // Everything that decides how the procedural sky looks right now: when it stays put the environment is not rebuilt. It walks the dome's own uniforms
20
+ // (sun, moon, cloud colour / cover / speed and a game's layer uniforms are all in there, so a new one needs no edit here) and the dome material's
21
+ // shader revision (a changed clouds() / layer() hook). uTime is left out: it moves every frame, and cloud drift alone is not worth a rebuild
22
+ function skyKey(sky) {
23
+ const f = x => Math.round(x * 400), m = sky.dome.material, parts = [m.uuid, m.version];
24
+ for (const [k, u] of Object.entries(sky.uniforms)) {
25
+ if (k === 'uTime') continue;
26
+ const v = u.value;
27
+ if (typeof v === 'number') parts.push(f(v));
28
+ else if (v?.isColor) parts.push(f(v.r), f(v.g), f(v.b));
29
+ else if (v?.isVector2 || v?.isVector3 || v?.isVector4) parts.push(...v.toArray().map(f));
30
+ else if (v?.isTexture) parts.push(v.uuid);
31
+ }
32
+ return parts.join(',');
23
33
  }
24
34
 
25
35
  export const environmentMethods = {
26
36
  // engine.sky.environment(): the first build waits for the first frame's colors, later calls build at once
27
- _envStart({ into = null, interval = this.engine.tier === 'low' ? DEFAULT_INTERVAL * LOW_TIER_SLOWER : DEFAULT_INTERVAL, ...rest } = {}) {
37
+ _envStart({ into = null, interval = null, ...rest } = {}) {
28
38
  const bad = Object.keys(rest)[0];
29
39
  if (bad) throw codedError('sky-option', `engine.sky.environment({ ${bad} }): the options are into and interval. Intensity and rotation are plain three.js: scene.environmentIntensity, scene.environmentRotation`);
30
40
  if (into !== null && typeof into !== 'object') throw codedError('sky-option', 'engine.sky.environment({ into }): into is the object whose .environment is written, usually engine.scene');
31
- if (typeof interval !== 'number' || !(interval >= 0)) throw codedError('sky-option', `engine.sky.environment({ interval }): interval is seconds, 0 or more; got ${JSON.stringify(interval)}`);
41
+ if (interval !== null && (typeof interval !== 'number' || !(interval >= 0))) throw codedError('sky-option', `engine.sky.environment({ interval }): interval is seconds, 0 or more; got ${JSON.stringify(interval)}`);
32
42
  this._envOff(); // a second call replaces the first (a new interval, hot reload, another scene); the old handle's remove() then does nothing
33
- const env = this._env = { into, interval, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
43
+ // interval is read at each frame: the default follows the tier (a stored preset arrives after this call, and a later tier change reaches it with no listener);
44
+ // a number the game gave never changes
45
+ const e = this.engine, env = this._env = { into, get interval() { return interval ?? (e.tier === 'low' ? DEFAULT_INTERVAL * LOW_TIER_SLOWER : DEFAULT_INTERVAL); }, key: null, since: 0, builds: 0, target: null, deferred: !this._envFramed };
46
+ // an explicit call takes the map back from a game write; the warning's way back then names this `into`
47
+ this._oEnv.manual(false); this._oEnv.levels = { ...this._oEnv.levels, back: `engine.sky.environment({ into: ${into === e.scene ? 'engine.scene' : 'into'} })` };
48
+ this._oEnv.mark(); // what `into` holds now is the reference: the first build replaces it as before, only a later write by the game is a takeover
34
49
  if (!env.deferred) this._envBuild();
35
50
  // a lost context takes the map's pixels with it, and the key cannot see that: with the sky standing still (a fixed hour) the map would stay black
36
51
  env.restored = this.engine.events.on('page:contextrestored', () => { env.key = null; env.deferred = true; });
@@ -44,9 +59,10 @@ export const environmentMethods = {
44
59
  const e = this._env;
45
60
  if (!e) return;
46
61
  e.since += dt;
62
+ if (!this._oEnv.on) return; // the game wrote scene.environment: nothing is rebuilt while the sky has yielded (frame.js watchOwned)
47
63
  if (!e.deferred && e.since < e.interval) return;
48
64
  e.since = 0; e.deferred = false;
49
- if (skyKey(this.uniforms) !== e.key) this._envBuild();
65
+ if (skyKey(this) !== e.key) this._envBuild();
50
66
  },
51
67
 
52
68
  // Render the dome alone into a cube and prefilter it (PMREM). The dome mesh follows the camera, so a copy sharing its material is rendered
@@ -63,10 +79,10 @@ export const environmentMethods = {
63
79
  }
64
80
  /** @type {any} */ (this._envScene.children[0]).material = this.dome.material; // a game may have set engine.sky.dome.material
65
81
  const old = e.target, next = this._pmrem.fromScene(this._envScene, 0, 0.1, 100, { size: 256 });
66
- // a map the game wrote there since the last build is the game's: a direct three.js write takes the value over
67
- if (e.into && (!old || e.into.environment === old.texture)) e.into.environment = next.texture;
82
+ // a map the game wrote there is the game's: the owned check (frame.js) has yielded, and the sky writes it no more
83
+ if (e.into && this._oEnv.on) { e.into.environment = next.texture; this._oEnv.mark(); }
68
84
  e.target = next; old?.dispose();
69
- e.builds++; e.key = skyKey(this.uniforms);
85
+ e.builds++; e.key = skyKey(this);
70
86
  },
71
87
 
72
88
  // Renderer swap (fallback 'webgl'): the generator and the map belong to the old renderer, so the next frame builds them again on the new one
@@ -81,7 +97,7 @@ export const environmentMethods = {
81
97
  e?.restored.remove();
82
98
  if (e?.into && e.target && e.into.environment === e.target.texture) e.into.environment = null;
83
99
  e?.target?.dispose();
84
- this._env = null;
100
+ this._env = null; this._oEnv?.mark(); // the map it took off is not a write by the game
85
101
  this._pmrem?.dispose(); this._pmrem = null; this._envScene = null;
86
102
  },
87
103
  };
@@ -1,4 +1,4 @@
1
- // Sky fog (helper of Sky.js). The game's fog is plain three.js: engine.scene.fog; this file only reads it for the dome's fog band.
1
+ // Sky fog (helper of Sky.js). The game's fog is plain three.js: engine.scene.fog (WebGPU: scene.fogNode, render/fogLook.js); this file only reads it for the dome's fog band.
2
2
 
3
3
  // The dome's fog band: its lower band fades to the fog color so the line where fogged ground meets the sky does not show.
4
4
  // Always compiled in and switched by the uFogBand uniform (0 = off, mix(col, x, 0.0) is col exactly), so any fog color change at
@@ -5,6 +5,7 @@ import { defineOwned } from '../../core/ops/owned.js';
5
5
  import { applySeason } from './season.js';
6
6
  import { applyCover, skyTint } from './tint.js';
7
7
  import { fogBand } from './fog.js';
8
+ import { fogLook } from '../../render/fogLook.js';
8
9
  import { signalWatch } from '../../render/daylight.js';
9
10
  import { sunAngle } from '../../core/time/dayTime.js';
10
11
  import { LUMA } from '../../render/fxNumbers.js';
@@ -20,6 +21,7 @@ const lum = c => LUMA[0] * c.r + LUMA[1] * c.g + LUMA[2] * c.b;
20
21
  // The copyable takeover calls each owned property's warning quotes (core/ops/owned.js): the engine yields to a direct write, these say it explicitly
21
22
  const L = {
22
23
  background: { manual: 'engine.sky.dome.visible = false', back: 'engine.sky.replace(null)' },
24
+ environment: { manual: 'engine.sky.environment().remove()', back: 'engine.sky.environment()' },
23
25
  sunDir: { manual: "engine.autoView.manual('sunDir')", back: "engine.autoView.manual('sunDir', false)" },
24
26
  };
25
27
 
@@ -38,6 +40,9 @@ export function watchOwned(sky) {
38
40
  // the reference is the scene as the engine made it, not what is there now: picture code runs before start() (and may run before sky()), and a write
39
41
  // with no reference to differ from would leave the dome drawn over the game's background for good
40
42
  sky._oBg.mark([e.baseBackground, 1]);
43
+ // the environment map engine.sky.environment() writes into its `into` object: a game that writes scene.environment itself takes it, the sky stops building it (environment.js)
44
+ list.push(sky._oEnv = own('sky.environment', 'sky', 'environment', () => sky._env?.into?.environment ?? null, L.environment, [scene]));
45
+ sky._oEnv._onChange = o => { if (o.on && sky._env) sky._env.key = null; }; // handed back: the next interval builds it again
41
46
  // the sun: part 'view', so engine.autoView.manual('sunDir') is the one takeover entry. The shadow and the game's lights follow this value, so a sun at a chosen
42
47
  // direction has to survive the frame. sunDir and uSunDir are one vector (Sky.js), so a write to either name is seen here
43
48
  list.push(sky._oSun = defineOwned(e, { id: 'sky.sunDir', part: 'view', key: 'sunDir', read: () => sky.sunDir.toArray(), levels: L.sunDir, objects: [sky] }));
@@ -77,7 +82,7 @@ export function updateSky(sky) {
77
82
  sky._signals.check();
78
83
  sky.engine.uniforms.uSkyTop.value.copy(u.uTop.value); sky.engine.uniforms.uSkyHorizon.value.copy(bd ? bd.color : u.uHorizon.value);
79
84
  sky._signals.mark();
80
- u.uFogBand.value = fogBand(scene.fog, u.uHorizon.value); // compared to the dome's horizon (not the backdrop): the band is drawn on the dome
85
+ u.uFogBand.value = fogBand(fogLook(scene, sky.engine.renderer), u.uHorizon.value); // compared to the dome's horizon (not the backdrop): the band is drawn on the dome
81
86
  u.uSunColor.value.copy(a[3]).lerp(b[3], f); // the keyframes' sun color: the dome's sun disk, and a signal for the game's own sun (shader.js shares the object)
82
87
 
83
88
  const ang = sunAngle(t), elev = Math.sin(ang);