threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
package/modules/rigid/sync.js
CHANGED
|
@@ -5,11 +5,11 @@ import * as THREE from 'three';
|
|
|
5
5
|
// Chunks around physics stream sources ([cx, cz, rings] each): terrain uses triangle-mesh colliders (identical to what is drawn), vegetation uses cylinders.
|
|
6
6
|
// Data comes from the ground API ground.chunkCollision
|
|
7
7
|
// Building a trimesh costs a few ms and the broadphase pays again on the next world step; a whole new ring (9 chunks, or after a teleport) in one fixed step
|
|
8
|
-
// was the worst frame of streaming. So once playing, the chunk under the source is built at once and the others
|
|
8
|
+
// was the worst frame of streaming. So once playing, the chunk under the source is built at once and the others go CHUNKS_PER_STEP per step, nearest first.
|
|
9
9
|
// Returns true while chunks are still waiting, so the caller syncs again on the next step instead of after 0.5 s.
|
|
10
10
|
const CHUNKS_PER_STEP = 1;
|
|
11
11
|
export function syncTerrain(r, src) {
|
|
12
|
-
const e = r.engine, R = r.
|
|
12
|
+
const e = r.engine, R = r.rapier, want = new Set(), todo = [];
|
|
13
13
|
for (const [pcx, pcz, n] of src) for (let dz = -n; dz <= n; dz++) for (let dx = -n; dx <= n; dx++) {
|
|
14
14
|
const cx = pcx + dx, cz = pcz + dz, key = cx + ',' + cz; if (want.has(key)) continue; want.add(key);
|
|
15
15
|
todo.push({ cx, cz, key, d: Math.max(Math.abs(dx), Math.abs(dz)) });
|
|
@@ -74,7 +74,7 @@ function nearChunks(x, z, d, CH, fn) {
|
|
|
74
74
|
}
|
|
75
75
|
/** Build / drop trunk cylinders for the chunks near the anchors (only where the terrain collider is already built). Returns true while chunks are still queued */
|
|
76
76
|
export function syncTrees(r, focus, CH) {
|
|
77
|
-
const e = r.engine, R = r.
|
|
77
|
+
const e = r.engine, R = r.rapier, a = anchors(r, focus), want = new Map(), keep = new Set();
|
|
78
78
|
for (let i = 0; i < a.length; i += 2) {
|
|
79
79
|
nearChunks(a[i], a[i + 1], r.treeRadius + TREE_KEEP, CH, (cx, cz, d) => {
|
|
80
80
|
const key = cx + ',' + cz; keep.add(key);
|
|
@@ -112,7 +112,7 @@ function dropTrees(r, key) {
|
|
|
112
112
|
// Vegetation on a level model or code-built ground has no chunked collision: its trunks reach us only as circles through
|
|
113
113
|
// ground.forEachCollider (the same source character collision and path planning read). Make them cylinders around the physics sources
|
|
114
114
|
export function syncGroundTrees(r, src, CH) {
|
|
115
|
-
const e = r.engine, G = e.ground, R = r.
|
|
115
|
+
const e = r.engine, G = e.ground, R = r.rapier, half = r.treeColliderHeight / 2, want = new Set();
|
|
116
116
|
if (G.forEachCollider) for (const [pcx, pcz, n] of src) {
|
|
117
117
|
G.forEachCollider((pcx + 0.5) * CH, (pcz + 0.5) * CH, (n + 0.5) * CH * Math.SQRT2, (x, z, rad) => {
|
|
118
118
|
const key = x + ',' + z + ',' + rad;
|
|
@@ -129,30 +129,61 @@ function dropTerrain(r, key) {
|
|
|
129
129
|
if (t) for (const c of t.colliders) r.world.removeCollider(c, false);
|
|
130
130
|
r.terrain.delete(key);
|
|
131
131
|
}
|
|
132
|
+
// Chunk copies of a ground source that left: terrain and trunks are copies of the ground too, and nothing else asks for them once chunkCollision is gone. Answers whether any went.
|
|
133
|
+
export function dropChunks(r) {
|
|
134
|
+
if (r.engine.ground.chunkCollision || !(r.terrain.size || r.trees.size)) return false;
|
|
135
|
+
for (const key of [...r.terrain.keys()]) dropTerrain(r, key);
|
|
136
|
+
for (const key of [...r.trees.keys()]) dropTrees(r, key);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
132
139
|
// Houses and pillars from the collision module, as physics colliders: engine.collision.mirror does the add / remove diff (shared with nav), this
|
|
133
|
-
// only says how one collider is built and dropped. Built lazily: the mirror lives on the collision module, which rigid requires.
|
|
140
|
+
// only says how one collider is built and dropped. Built lazily: the mirror lives on the collision module, which rigid requires. A mirror knows one module, so another
|
|
141
|
+
// collision module (replaces) drops the old colliders and starts a new mirror. Answers whether a collider changed.
|
|
134
142
|
const UP = new THREE.Vector3(0, 1, 0), Q = new THREE.Quaternion();
|
|
135
143
|
export function syncStatics(r) {
|
|
136
|
-
r.
|
|
144
|
+
r._collision.sync(() => { r._statics?.clear(true); r._statics = null; });
|
|
145
|
+
r._statics ??= r.engine.collision?.mirror({
|
|
137
146
|
add(type, o) {
|
|
138
|
-
const R = r.
|
|
139
|
-
|
|
140
|
-
Q.
|
|
141
|
-
|
|
147
|
+
const R = r.rapier, g = o.y ?? r.engine.surface(o.x, o.z);
|
|
148
|
+
Q.setFromAxisAngle(UP, o.rot ?? 0);
|
|
149
|
+
const shape = type === 'box' ? R.ColliderDesc.cuboid(o.hw, o.h / 2, o.hd).setRotation({ x: Q.x, y: Q.y, z: Q.z, w: Q.w }) : R.ColliderDesc.cylinder(o.h / 2, o.r);
|
|
150
|
+
const c = r.world.createCollider(shape.setTranslation(o.x, g + o.h / 2, o.z));
|
|
151
|
+
if (o.y == null) r._onGround.set(o, c);
|
|
152
|
+
return c;
|
|
142
153
|
},
|
|
143
|
-
remove(
|
|
144
|
-
});
|
|
145
|
-
r._statics
|
|
154
|
+
remove(c, o) { r._onGround.delete(o); r.world.removeCollider(c, false); },
|
|
155
|
+
}) ?? null;
|
|
156
|
+
return !!r._statics?.sync();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The ground moved under a world box: a collider that stands on the ground, one with no y of its own, stands on what is there now. Mirror data keeps no height, so nothing else would tell it. No area: all of them */
|
|
160
|
+
export function restandStatics(r, { x0 = -Infinity, z0 = -Infinity, x1 = Infinity, z1 = Infinity } = {}) {
|
|
161
|
+
for (const [o, c] of r._onGround) if (o.x + o.r >= x0 && o.x - o.r <= x1 && o.z + o.r >= z0 && o.z - o.r <= z1) { c.setTranslation({ x: o.x, y: r.engine.surface(o.x, o.z) + o.h / 2, z: o.z }); r._behind = true; }
|
|
146
162
|
}
|
|
147
163
|
|
|
148
|
-
// Ground of a level (hand-built scene): one static triangle mesh, rebuilt when the level changes
|
|
164
|
+
// Ground of a level (hand-built scene): one static triangle mesh, rebuilt when the level changes. The provider's staticTrimeshes names the source
|
|
165
|
+
// (engine.ground itself is a fresh object whenever a collider source joins, and that alone must not rebuild it). A new ground of any kind stands the world boxes on it again:
|
|
166
|
+
// a level at another height sends no ground:change. Answers whether the triangles changed.
|
|
149
167
|
export function syncLevel(r) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
r._standOn.sync(() => restandStatics(r));
|
|
169
|
+
return !!r._level.sync(() => {
|
|
170
|
+
const G = r.engine.ground, old = r._levelColliders || [];
|
|
171
|
+
r._levelColliders = []; // before anything can throw: the retry must not remove these twice
|
|
172
|
+
for (const c of old) r.world.removeCollider(c, false);
|
|
173
|
+
const desc = t => r.rapier.ColliderDesc.trimesh(t.positions, t.indices).setFriction(0.9);
|
|
174
|
+
for (const t of G.staticTrimeshes?.() ?? []) r._levelColliders.push(r.world.createCollider(desc(t)));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A ground with no collision of its own stands on an infinite flat plane at y = 0, unless the game turned it off. One more copy of the ground, so it comes and goes with the ground
|
|
179
|
+
// source: left standing it is an invisible floor over a level installed later. Answers whether it changed.
|
|
180
|
+
export const wantsFloor = r => { const G = r.engine.ground; return r.fallbackFloor && !G.chunkCollision && !G.staticTrimeshes; };
|
|
181
|
+
export function syncFloor(r) {
|
|
182
|
+
return !!r._floor.sync(() => {
|
|
183
|
+
const want = wantsFloor(r);
|
|
184
|
+
if (want && !r._floorCollider) r._floorCollider = r.world.createCollider(r.rapier.ColliderDesc.cuboid(5000, 0.5, 5000).setTranslation(0, -0.5, 0));
|
|
185
|
+
else if (!want && r._floorCollider) { r.world.removeCollider(r._floorCollider, false); r._floorCollider = null; }
|
|
186
|
+
});
|
|
156
187
|
}
|
|
157
188
|
|
|
158
189
|
// ---------- Game-set body / collider state across RigidBodies._fresh ----------
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
//
|
|
11
11
|
// Tabs: default graphics, audio, keys, language, saves. Optional built-ins, off unless asked for: 'game' (resume / load / back to title) and
|
|
12
12
|
// 'camera' (mouse sensitivity, invert Y, field of view): settings({ sections: ['game', 'graphics', 'audio', 'controls', 'camera'] }) or addSection('camera').
|
|
13
|
+
// An entry { id: 'graphics', omit: ['pixelRatio', 'antialias'] } in that list leaves rows out of the graphics tab.
|
|
13
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())).
|
|
14
15
|
//
|
|
15
16
|
// A game's own settings page (e.g. "Gameplay"):
|
|
@@ -32,33 +33,70 @@ import { makeWindow, injectUICSS, uiFocus } from '../../ui/UI.js';
|
|
|
32
33
|
import { BUILTIN_SECTIONS } from './sections.js';
|
|
33
34
|
import { STRINGS, CSS } from './strings.js';
|
|
34
35
|
import { SettingsView } from './view.js';
|
|
35
|
-
import { applySetting, allowed, checkLimits } from './apply.js';
|
|
36
|
-
import { readParams, keysSchema } from '../../core/params.js';
|
|
37
|
-
import {
|
|
36
|
+
import { applySetting, allowed, checkLimits, releaseLimits, releaseRow } from './apply.js';
|
|
37
|
+
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
38
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
39
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
40
|
+
import { pixelSizeOn } from '../../core/scene/pixelRatio.js';
|
|
41
|
+
import { trackForModule } from '../../core/engine/moduleTypes.js';
|
|
38
42
|
|
|
39
|
-
// Graphics presets. Values are performance
|
|
43
|
+
// Graphics presets. Values are performance steps, not art; a game can override with settings({ presets: { low: {...} } })
|
|
44
|
+
// A preset never states a look. A switch is a permission (true lets the game's choice through), and pixelRatio, viewChunks and density are shares (0 to 1) of what this device and
|
|
45
|
+
// this game start with, so the top preset lets everything through and no preset raises anything. A fixed number is wrong on one game or the other: 5 chunks cuts a game built for 8,
|
|
46
|
+
// and a ratio of 1 is an upscaled picture on a 2x screen (core/scene/tier.js). tier: what engine.tier reads under this preset; null leaves it to the device
|
|
40
47
|
const PRESETS = {
|
|
41
|
-
low: { pixelRatio: 0.75, shadows: false, antialias: false, bloom: false, ao: false, viewChunks:
|
|
42
|
-
medium: { pixelRatio: 1, shadows: true, antialias: true, bloom: false, ao: false, viewChunks:
|
|
43
|
-
high: { pixelRatio: 1
|
|
48
|
+
low: { pixelRatio: 0.75, shadows: false, antialias: false, bloom: false, ao: false, viewChunks: 0.6, density: 0.5, tier: 'low' },
|
|
49
|
+
medium: { pixelRatio: 1, shadows: true, antialias: true, bloom: false, ao: false, viewChunks: 0.8, density: 0.75, tier: null },
|
|
50
|
+
high: { pixelRatio: 1, shadows: true, antialias: true, bloom: true, ao: true, viewChunks: 1, density: 1, tier: 'high' },
|
|
44
51
|
};
|
|
45
|
-
//
|
|
52
|
+
// Preset rows that are shares, and how each share lands on its whole
|
|
53
|
+
const SHARES = { pixelRatio: n => +n.toFixed(2), viewChunks: n => Math.max(1, Math.round(n)), density: n => +n.toFixed(2) };
|
|
54
|
+
// Settings keys that switch a post effect of the same name; a key whose effect the game did not add is hidden and ignored
|
|
46
55
|
const POST_KEYS = ['bloom', 'ao'];
|
|
47
56
|
|
|
57
|
+
/**
|
|
58
|
+
* 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.
|
|
59
|
+
* @param {any} sections @returns {Set<string>}
|
|
60
|
+
*/
|
|
61
|
+
function omittedRows(sections) {
|
|
62
|
+
const entry = Array.isArray(sections) ? sections.find(s => typeof s === 'object') : null;
|
|
63
|
+
if (!entry) return new Set();
|
|
64
|
+
readParams('settings sections', keysSchema(['id', 'omit']), entry);
|
|
65
|
+
const rows = ['quality', 'adaptive', ...Object.keys(PRESETS.low)], bad = (entry.omit ?? []).filter(k => !rows.includes(k));
|
|
66
|
+
if (entry.id !== 'graphics' || bad.length) throw codedError('settings-tab', `settings({ sections }): an entry with omit is { id: 'graphics', omit: [...] } with rows from ${rows.join(', ')}; got ${JSON.stringify(entry)}`);
|
|
67
|
+
return new Set(entry.omit);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What a stored file says the player changed. A version 1 file held every value, so there only a value that differs from today's default can be
|
|
72
|
+
* the player's, and 'quality' was a label worked out from the rest.
|
|
73
|
+
* @param {any} stored @param {Record<string, any>} defaults @returns {Record<string, any>}
|
|
74
|
+
*/
|
|
75
|
+
function playerValues(stored, defaults) {
|
|
76
|
+
const v = stored.values || {};
|
|
77
|
+
if (stored.v >= 2) return { ...v };
|
|
78
|
+
return Object.fromEntries(Object.entries(v).filter(([k, val]) => k !== 'quality' && val !== defaults[k]));
|
|
79
|
+
}
|
|
80
|
+
|
|
48
81
|
export class Settings extends SettingsView {
|
|
49
82
|
constructor(engine, { action = 'cancel', storageKey, presets = {}, sections = true, freezeWorld = false } = {}, track) {
|
|
50
83
|
super();
|
|
51
84
|
/** @internal the module's ctx.track: listeners the settings and its sections add leave with the module */ this._track = track;
|
|
52
85
|
this.engine = engine;
|
|
53
86
|
this.action = action;
|
|
87
|
+
/** @internal */ this._leftOut = omittedRows(sections);
|
|
54
88
|
this.presets = { ...PRESETS };
|
|
55
|
-
for (const k in presets)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
89
|
+
for (const k in presets) {
|
|
90
|
+
// loud, because a game's old fixed number (a ratio of 2, 5 chunks) would otherwise multiply the device's or the game's own
|
|
91
|
+
for (const row of ['viewChunks', 'density']) if (presets[k][row] > 1) throw codedError('module-params', `settings({ presets: { ${k}: { ${row}: ${presets[k][row]} } } }): a preset's ${row} is a share from 0 to 1 of the game's own value`);
|
|
92
|
+
if (presets[k].pixelRatio > 1) throw codedError('module-params', `settings({ presets: { ${k}: { pixelRatio: ${presets[k].pixelRatio} } } }): a preset's pixelRatio is a share from 0 to 1 of the ratio the engine picked for this device. For a fixed ratio call engine.setPixelRatio`);
|
|
93
|
+
this.presets[k] = { ...(this.presets[k] || {}), ...presets[k] };
|
|
94
|
+
}
|
|
95
|
+
this.storageKey = storageKey || engine.saves.storageKey('settings');
|
|
59
96
|
this.sections = new Map();
|
|
60
97
|
this.custom = new Map(); // game's custom settings: key -> { def, apply }
|
|
61
|
-
|
|
98
|
+
/** @internal keys set before start() with no row yet: init() reports the ones no row came for */ this._early = new Set();
|
|
99
|
+
/** @internal the action waiting for a key press, and its focus entry: the menu cursor rests above it, or Space and Enter would press a control instead of being bound */ this._capturing = null;
|
|
62
100
|
this.current = null; // current tab
|
|
63
101
|
this.freezeWorld = freezeWorld;
|
|
64
102
|
|
|
@@ -69,15 +107,19 @@ export class Settings extends SettingsView {
|
|
|
69
107
|
injectUICSS(CSS);
|
|
70
108
|
|
|
71
109
|
const stored = this._read();
|
|
72
|
-
this.saved = stored; // raw data read back
|
|
73
110
|
// 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
|
|
74
111
|
// declares an action is installed, so nothing waits for "every action registered"
|
|
75
112
|
for (const [a, k] of Object.entries(stored.bindings || {})) if (Array.isArray(k) && k.length) engine.input.rebind(a, k);
|
|
76
|
-
this.
|
|
77
|
-
|
|
113
|
+
this._defaults = this._currentValues(); // the engine's own values before the player's saved ones: what reset() goes back to
|
|
114
|
+
// 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
|
+
// resolution, the game), so one volume change no longer pins every graphics value for all later launches
|
|
116
|
+
/** @internal key -> value; 'quality' names a chosen preset, the rows after it override it */ this._changed = playerValues(stored, this._defaults);
|
|
117
|
+
this._values = { ...this._defaults, ...this._picked() };
|
|
118
|
+
this._values.quality = this._matchPreset();
|
|
119
|
+
for (const [k, v] of Object.entries(this._picked())) this._apply(k, v);
|
|
78
120
|
// Tabs: true = the default set; a list picks built-in and optional tabs by name (optional ones register their own settings in setup)
|
|
79
121
|
if (sections === true) for (const [id, s] of Object.entries(BUILTIN_SECTIONS)) this.sections.set(id, s);
|
|
80
|
-
else if (sections) for (const
|
|
122
|
+
else if (sections) for (const s of sections) this._builtin(s.id ?? s);
|
|
81
123
|
if (stored.locale && engine.i18n.languages.includes(stored.locale) && stored.locale !== engine.i18n.locale) engine.i18n.setLocale(stored.locale);
|
|
82
124
|
|
|
83
125
|
this.win = makeWindow(engine, {
|
|
@@ -93,7 +135,7 @@ export class Settings extends SettingsView {
|
|
|
93
135
|
track(this.win);
|
|
94
136
|
// The back key (Esc) has one entry point: with an empty focus stack it opens the menu; while the menu is open the window's onCancel handles it
|
|
95
137
|
this.focus = uiFocus(engine);
|
|
96
|
-
this.focus.setRoot(() => this.open());
|
|
138
|
+
track(this.focus.setRoot(() => this.open())); // unloaded, the back key must not open a window that left the page and hold the input behind it
|
|
97
139
|
// The close button, the back key and code close() all go through the window's toggle, emitting ui:open / ui:close
|
|
98
140
|
track(engine.events.on('ui:open', id => { if (id === 'settings') this._pause(true); }));
|
|
99
141
|
track(engine.events.on('ui:close', id => { if (id === 'settings') this._pause(false); }));
|
|
@@ -101,27 +143,46 @@ export class Settings extends SettingsView {
|
|
|
101
143
|
}
|
|
102
144
|
|
|
103
145
|
// ---------- reading and writing settings ----------
|
|
146
|
+
/** Every setting's value, read only. The render scale comes from the renderer: adaptive resolution and the game move it, and a stored copy was a second answer to describe().render.scale */
|
|
147
|
+
/**
|
|
148
|
+
* @internal Rows out of play now: the game's, and under pixelSize the two that would change the ratio, so no preset, stored value or slider reaches it
|
|
149
|
+
* while it is on, and they come back with setPixelSize(null).
|
|
150
|
+
*/
|
|
151
|
+
get _omit() { return pixelSizeOn(this.engine) ? new Set([...this._leftOut, 'pixelRatio', 'adaptive']) : this._leftOut; }
|
|
152
|
+
get values() { return { ...this._values, pixelRatio: +this.engine.renderer.getPixelRatio().toFixed(2) }; }
|
|
104
153
|
get(key) { return this.values[key]; }
|
|
105
|
-
/**
|
|
154
|
+
/** @internal Someone answers for this key: a built-in row, a defined one, or a bus's slider @param {string} key */
|
|
155
|
+
_hasRow(key) { return key in this._defaults || this.custom.has(key) || (key.startsWith('vol.') && key.slice(4) in this.engine.audio.levels); }
|
|
156
|
+
/**
|
|
157
|
+
* 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
|
+
* applied. Before start() a module's row may still come, so an unknown key waits and init() reports it.
|
|
159
|
+
*/
|
|
106
160
|
set(key, value, { save = true } = {}) {
|
|
107
161
|
if (key === 'quality') return this.preset(value);
|
|
108
|
-
this.
|
|
162
|
+
if (!this._hasRow(key)) {
|
|
163
|
+
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
|
+
this._early.add(key);
|
|
165
|
+
}
|
|
166
|
+
this._values[key] = value; this._changed[key] = value;
|
|
109
167
|
this._apply(key, value);
|
|
110
|
-
if (key in (this.presets.low || {})) this.
|
|
168
|
+
if (key in (this.presets.low || {})) this._values.quality = this._matchPreset();
|
|
111
169
|
if (save) this.save();
|
|
112
170
|
this.win.refresh();
|
|
113
171
|
}
|
|
114
172
|
/** Graphics preset */
|
|
115
173
|
preset(name) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
174
|
+
if (!this.presets[name]) return;
|
|
175
|
+
const p = this._presetValues(name);
|
|
176
|
+
// the name is stored, not its numbers: the ratio is worked out again on the next launch, where the tier may differ
|
|
177
|
+
for (const k in p) { this._values[k] = p[k]; delete this._changed[k]; this._apply(k, p[k]); }
|
|
178
|
+
this._values.quality = this._changed.quality = name;
|
|
119
179
|
this.save(); this.win.refresh();
|
|
120
180
|
}
|
|
121
181
|
/**
|
|
122
182
|
* A game's custom setting: default value + apply function (called at once with the saved value), or { apply, limits }. limits names the shared
|
|
123
183
|
* 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
|
|
124
184
|
* 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
|
+
* 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.
|
|
125
186
|
* @param {string} key @param {any} def
|
|
126
187
|
* @param {((value: any, engine: any) => void) | { apply?: (value: any, engine: any) => void, limits?: string | string[] }} [apply]
|
|
127
188
|
* @example engine.settings.define('volfog', true, { limits: 'post.volfog.enabled' }); // after engine.post.add(volFog)
|
|
@@ -130,26 +191,67 @@ export class Settings extends SettingsView {
|
|
|
130
191
|
const o = typeof apply === 'function' || apply == null ? { apply } : apply;
|
|
131
192
|
const limits = o.limits == null ? null : [].concat(o.limits);
|
|
132
193
|
if (limits) checkLimits(this, key, def, limits);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
this.
|
|
194
|
+
const row = { def, apply: o.apply, limits };
|
|
195
|
+
this.custom.set(key, row);
|
|
196
|
+
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
|
+
if (key in picked) this._values[key] = picked[key];
|
|
198
|
+
else if (!(key in this._values)) this._values[key] = def;
|
|
199
|
+
this._apply(key, this._values[key]);
|
|
200
|
+
if (this._ready) this._values.quality = this._matchPreset();
|
|
201
|
+
this._leavesWithModule(() => {
|
|
202
|
+
if (this.custom.get(key) !== row) return; // the name was defined again: that row is someone else's
|
|
203
|
+
this.custom.delete(key);
|
|
204
|
+
if (limits) releaseRow(this.engine, limits);
|
|
205
|
+
if (!(key in this._changed)) delete this._values[key];
|
|
206
|
+
});
|
|
136
207
|
return this;
|
|
137
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* @internal A row or tab made while a module runs leaves with that module (trackForModule); one the game made, or an async callback, stays
|
|
211
|
+
*/
|
|
212
|
+
_leavesWithModule(drop) { trackForModule(this.engine, { remove: () => { drop(); this.win?.refresh(); } }); }
|
|
138
213
|
/** Add a tab */
|
|
139
214
|
addSection(id, def) {
|
|
140
215
|
if (def === undefined) { this._builtin(id); this.win.refresh(); return this; }
|
|
141
216
|
const { title, render, bind, when, order = 100 } = def;
|
|
142
|
-
|
|
217
|
+
const section = { title: typeof title === 'function' ? title : () => title, render, bind, when, order };
|
|
218
|
+
this.sections.set(id, section);
|
|
219
|
+
this._leavesWithModule(() => { if (this.sections.get(id) === section) this.sections.delete(id); });
|
|
143
220
|
this.win.refresh();
|
|
144
221
|
return this;
|
|
145
222
|
}
|
|
146
|
-
removeSection(id) { this.sections.delete(id); if (this.current === id) this.current = null; this.win.refresh(); }
|
|
147
223
|
|
|
148
224
|
get isOpen() { return this.win.open; }
|
|
225
|
+
/** Action name waiting for a key press, or null @type {string | null} */
|
|
226
|
+
get capturing() { return this._capturing?.action ?? null; }
|
|
227
|
+
set capturing(action) {
|
|
228
|
+
this._capturing?.hold.remove();
|
|
229
|
+
this._capturing = action ? { action, hold: this.focus.push('settings-key', { cancel: () => this._cancel() }) } : null;
|
|
230
|
+
}
|
|
149
231
|
open() { if (!this.win.open) this.win.toggle(true); }
|
|
150
232
|
close() { this.capturing = null; if (this.win.open) this.win.toggle(false); }
|
|
151
233
|
toggle(on = !this.win.open) { on ? this.open() : this.close(); }
|
|
152
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Put one setting (or, with no key, every setting) back to its default: the value the engine or the game's define() started with, before the player's saved ones.
|
|
237
|
+
* Keys stay as they are (resetBindings does those). Why here and not in the game: the built-in defaults (volumes, graphics) are known only to the engine,
|
|
238
|
+
* and a graphics change leaves the quality on 'custom', which is no preset to go back to.
|
|
239
|
+
* @param {string} [key]
|
|
240
|
+
* @example engine.settings.reset('vol.music') · engine.settings.reset()
|
|
241
|
+
*/
|
|
242
|
+
reset(key) {
|
|
243
|
+
const def = k => this.custom.has(k) ? this.custom.get(k).def : this._defaults[k];
|
|
244
|
+
// 'quality' is no value of its own (it is the name of the preset the graphics values match): resetting it resets the graphics values the presets set
|
|
245
|
+
const keys = key === undefined ? Object.keys(this._values).filter(k => k !== 'quality' && !this._omit.has(k)) : key === 'quality' ? Object.keys(this._presetValues('low')) : [key];
|
|
246
|
+
if (key === undefined || key === 'quality') delete this._changed.quality;
|
|
247
|
+
const preset = this._presetValues(this._changed.quality); // a row a kept preset sets must stay stored, or the preset takes it back on the next launch
|
|
248
|
+
for (const k of keys) {
|
|
249
|
+
if (!(k in this._values) || def(k) === undefined) { if (key !== undefined) warnOnce(`settings.reset('${k}'): no setting with this key (known: ${Object.keys(this._values).join(', ')})`); continue; }
|
|
250
|
+
this.set(k, def(k), { save: false });
|
|
251
|
+
if (!(k in preset)) delete this._changed[k];
|
|
252
|
+
}
|
|
253
|
+
this.save();
|
|
254
|
+
}
|
|
153
255
|
/** Reset all keys to the game's (takes every player rebinding away) */
|
|
154
256
|
resetBindings() {
|
|
155
257
|
const inp = this.engine.input;
|
|
@@ -187,62 +289,69 @@ export class Settings extends SettingsView {
|
|
|
187
289
|
}
|
|
188
290
|
save() {
|
|
189
291
|
const bindings = this.engine.input.rebound(); // only the player's changes; restored through input.rebind on the next launch
|
|
190
|
-
const data = { v:
|
|
191
|
-
this.saved = data;
|
|
292
|
+
const data = { v: 2, values: { ...this._changed }, bindings, locale: this.engine.i18n.locale };
|
|
192
293
|
try { localStorage.setItem(this.storageKey, JSON.stringify(data)); } catch { return false; }
|
|
193
294
|
this.engine.events.emit('settings:change', this.values);
|
|
194
295
|
return true;
|
|
195
296
|
}
|
|
196
297
|
|
|
197
298
|
// ---------- applying ----------
|
|
198
|
-
/**
|
|
199
|
-
* @internal The chunk table that "view distance" and "vegetation density" drive: the terrain's, or vegetation's own over a level / code-built ground; null
|
|
200
|
-
* without either
|
|
201
|
-
*/
|
|
202
|
-
chunkHost() { return this.engine.terrain ?? this.engine.vegetation?.host ?? null; }
|
|
203
299
|
_currentValues() {
|
|
204
|
-
const e = this.engine, v = { pixelRatio: +e.
|
|
205
|
-
v.antialias = e.post.
|
|
206
|
-
for (const k of POST_KEYS)
|
|
207
|
-
|
|
208
|
-
const H = this.chunkHost();
|
|
209
|
-
if (H) { v.viewChunks = H.viewChunks ?? 4; v.density = H.density ?? 1; }
|
|
300
|
+
const e = this.engine, v = { pixelRatio: +e.adaptive.base.toFixed(2), shadows: allowed(e, 'shadows.enabled'), tier: null };
|
|
301
|
+
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
|
|
303
|
+
v.adaptive = !!e.adaptive.on;
|
|
210
304
|
for (const [bus, level] of Object.entries(e.audio.levels)) v['vol.' + bus] = level; // one slider per bus, the game's own buses too
|
|
211
|
-
this.values = v;
|
|
212
|
-
v.quality = this._matchPreset();
|
|
213
305
|
return v;
|
|
214
306
|
}
|
|
307
|
+
/** A preset's values in this game on this device: each share made a value. A share of a row nobody offered is left out. Nothing for 'custom' or no preset @param {string} [name] */
|
|
308
|
+
_presetValues(name) {
|
|
309
|
+
const out = {};
|
|
310
|
+
for (const [k, v] of Object.entries(this.presets[name] ?? {})) {
|
|
311
|
+
if (this._omit.has(k)) continue;
|
|
312
|
+
if (!(k in SHARES)) { out[k] = v; continue; }
|
|
313
|
+
const whole = k === 'pixelRatio' ? this.engine.adaptive.base : this.custom.get(k)?.def;
|
|
314
|
+
if (whole != null) out[k] = SHARES[k](v * whole);
|
|
315
|
+
}
|
|
316
|
+
return out;
|
|
317
|
+
}
|
|
318
|
+
/** What the player chose: the preset, then the rows moved after it */
|
|
319
|
+
_picked() {
|
|
320
|
+
const { quality, ...rows } = this._changed;
|
|
321
|
+
for (const k of this._omit) delete rows[k];
|
|
322
|
+
return { ...this._presetValues(quality), ...rows };
|
|
323
|
+
}
|
|
324
|
+
// reads what was asked for (_values), not the live ratio: adaptive resolution lowering the scale is not the player picking 'custom'
|
|
215
325
|
_matchPreset() {
|
|
216
|
-
const v = this.
|
|
217
|
-
for (const
|
|
218
|
-
const ok = Object.entries(
|
|
219
|
-
if (
|
|
220
|
-
if (POST_KEYS.includes(k) && !e.post.get(k)) return true;
|
|
326
|
+
const v = this._values, e = this.engine;
|
|
327
|
+
for (const name of Object.keys(this.presets)) {
|
|
328
|
+
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
|
|
221
330
|
return v[k] === val;
|
|
222
331
|
});
|
|
223
332
|
if (ok) return name;
|
|
224
333
|
}
|
|
225
334
|
return 'custom';
|
|
226
335
|
}
|
|
227
|
-
_applyAll() { for (const k in this.values) this._apply(k, this.values[k]); }
|
|
228
336
|
_apply(key, val) { applySetting(this, key, val); }
|
|
229
337
|
|
|
230
|
-
|
|
231
338
|
// ---------- module hooks ----------
|
|
232
339
|
init() {
|
|
233
|
-
// At start() every module is installed
|
|
340
|
+
// At start() every module is installed, and the modules before this one have offered their rows (the view distance and density rows are the ground's)
|
|
234
341
|
this._ready = true;
|
|
235
|
-
const
|
|
236
|
-
for (const k of
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this.
|
|
342
|
+
const picked = this._picked(), e = this.engine;
|
|
343
|
+
for (const k of this._early) if (!this._hasRow(k)) warnOnce(coded('settings-row', `settings.set('${k}') before start: no row came for this key, so nothing applied it`));
|
|
344
|
+
// start() may have learned the real device on the WebGPU route and written its default ratio over the player's
|
|
345
|
+
this._defaults.pixelRatio = +e.adaptive.base.toFixed(2);
|
|
346
|
+
this._values.pixelRatio = picked.pixelRatio ?? this._defaults.pixelRatio;
|
|
347
|
+
if ('pixelRatio' in picked) this._apply('pixelRatio', picked.pixelRatio);
|
|
348
|
+
this._values.quality = this._matchPreset();
|
|
242
349
|
}
|
|
243
350
|
frame() {
|
|
244
351
|
const inp = this.engine.input;
|
|
245
352
|
if (this.capturing) {
|
|
353
|
+
if (!this.win.open) { this.capturing = null; return; } // closed by its close button: a focus entry left here would hold the back key
|
|
354
|
+
if (this._capturing.hold.fresh) return; // the confirm press that opened it is not the new key
|
|
246
355
|
const code = [...inp.justPressed][0];
|
|
247
356
|
// The back key is routed to _cancel by the UI focus stack (cancels rebinding); nothing to do here
|
|
248
357
|
if (code && !inp.keysOf('cancel').includes(code)) { const a = this.capturing; this.capturing = null; this.rebind(a, code); }
|
|
@@ -281,14 +390,14 @@ const SETTINGS_PARAMS = keysSchema(['action', 'storageKey', 'presets', 'sections
|
|
|
281
390
|
* Settings menu module. Installs engine.settings. Install it after the other modules.
|
|
282
391
|
* @param opts action the action that opens the menu (default the basic 'cancel'; another one the game binds); storageKey storage key; presets override graphics presets;
|
|
283
392
|
* sections which tabs: true (default) graphics, audio, controls, language, saves; a list picks by name, including the optional 'game' (resume, load, back to
|
|
284
|
-
* title) and 'camera' (sensitivity, invert Y, field of view); false for none;
|
|
393
|
+
* title) and 'camera' (sensitivity, invert Y, field of view); false for none; an entry { id: 'graphics', omit: [...] } leaves rows out of that tab;
|
|
285
394
|
* freezeWorld pause gameplay while the menu is open (with flow it switches to flow's 'paused', otherwise engine.freeze; rendering continues), default false
|
|
286
395
|
*/
|
|
287
396
|
export function settings(opts = {}) {
|
|
288
397
|
readParams('settings', SETTINGS_PARAMS, opts);
|
|
289
398
|
let s = null;
|
|
290
399
|
return {
|
|
291
|
-
name: 'settings', type: 'ui', params: SETTINGS_PARAMS, options: opts, label: 'Settings', optional: ['
|
|
400
|
+
name: 'settings', skipKind: 'none', type: 'ui', params: SETTINGS_PARAMS, options: opts, label: 'Settings', optional: ['flow', 'cameraRig'], stage: 'effects',
|
|
292
401
|
install(e, ctx) {
|
|
293
402
|
s = new Settings(e, opts, ctx.track);
|
|
294
403
|
ctx.track(e.ui.titleItem('settings', { label: x => x.t('title.settings'), run: () => s.open() })); // the title screen's Settings button
|
|
@@ -296,7 +405,14 @@ export function settings(opts = {}) {
|
|
|
296
405
|
},
|
|
297
406
|
init() { s.init(); },
|
|
298
407
|
frame() { s.frame(); },
|
|
408
|
+
// the tracked ui:close listener went first, so what an open menu holds is given back here
|
|
409
|
+
dispose() { s.capturing = null; s._pause(false); releaseLimits(s); },
|
|
299
410
|
// the values the player chose (quality preset, volumes, ...) explain a picture or a sound level; open / tab / capturing say the menu holds the input
|
|
300
411
|
describe() { return { open: s.isOpen, tab: s.current, capturing: s.capturing, values: { ...s.values } }; },
|
|
301
412
|
};
|
|
302
413
|
}
|
|
414
|
+
|
|
415
|
+
export const handRolled = [
|
|
416
|
+
{ 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 },
|
|
418
|
+
];
|
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import { reportError } from '../../core/errors.js';
|
|
2
|
-
import { codedError } from '../../core/errorHints.js';
|
|
3
|
-
// Apply one setting to the engine (helper of Settings.js): the built-in keys (pixel ratio, shadows, post effects,
|
|
4
|
-
// the game
|
|
1
|
+
import { reportError } from '../../core/base/errors.js';
|
|
2
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
3
|
+
// Apply one setting to the engine (helper of Settings.js): the built-in keys (pixel ratio, shadows, post effects, quality tier, audio buses) and the rows of modules and of
|
|
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
7
|
const BUILTIN_LIMITS = { shadows: ['shadows.enabled'], bloom: ['post.bloom.enabled'], ao: ['post.ao.enabled'] };
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* The settings layer only restricts (core/sharedPoint.js). A row's value on one shared point: true (or 1) drops the settings entry, so the scene's
|
|
10
|
+
* 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
|
|
11
11
|
* own choice shows again; false switches it off (set false on a switch, mul 0 on a number); a number from 0 to 1 is a factor (mul) on a number.
|
|
12
12
|
* Why never "force on": a cutscene or a dark cave that switched shadows off must not be switched back on by the menu; describe().shared then
|
|
13
13
|
* says the settings allow it and which owner below turned it off.
|
|
14
14
|
* @param {any} e @param {string} name the shared point ('shadows.enabled') @param {boolean | number} val
|
|
15
15
|
*/
|
|
16
16
|
function limit(e, name, val) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
17
|
+
const allow = val === true || val === 1;
|
|
18
|
+
// an effect not added yet (settings install before the game's boot code) has no point: the limit waits on one made now, and add() starts under it. Allowing has nothing to lift
|
|
19
|
+
if (!e.stacks.has(name) && (allow || !name.startsWith('post.'))) return;
|
|
20
|
+
const p = e.stacks.has(name) ? e.stacks.get(name) : e.post.switchPoint(name);
|
|
21
|
+
if (allow) p.release('settings');
|
|
20
22
|
else p.take({ owner: 'settings', layer: 'settings', ...(p.kind === 'number' ? { mul: val === false ? 0 : val } : { set: val }) });
|
|
21
23
|
}
|
|
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);
|
|
29
|
+
}
|
|
22
30
|
/** @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 */
|
|
23
31
|
export function checkLimits(s, key, def, names) {
|
|
24
32
|
const e = s.engine;
|
|
25
33
|
const known = () => e.stacks.list().filter(n => n.endsWith('.enabled')).join(', ');
|
|
26
34
|
for (const n of names) {
|
|
27
|
-
if (typeof n !== 'string' || !e.stacks.has(n)) throw codedError('unknown-name', `settings.define('${key}', ${JSON.stringify(def)}, { limits }): no shared value ${JSON.stringify(n)}. Define the row after the effect exists (engine.post.add,
|
|
35
|
+
if (typeof n !== 'string' || !e.stacks.has(n)) throw codedError('unknown-name', `settings.define('${key}', ${JSON.stringify(def)}, { limits }): no shared value ${JSON.stringify(n)}. Define the row after the effect exists (engine.post.add, engine.stacks.define). Switches now: ${known()}; every name: engine.stacks.list()`);
|
|
28
36
|
const kind = e.stacks.get(n).kind;
|
|
29
37
|
const ok = typeof def === 'boolean' ? kind === 'number' || kind === 'value' : typeof def === 'number' && kind === 'number';
|
|
30
38
|
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'}`);
|
|
@@ -42,11 +50,10 @@ export function applySetting(s, key, val) {
|
|
|
42
50
|
const limits = BUILTIN_LIMITS[key] ?? s.custom.get(key)?.limits;
|
|
43
51
|
if (limits) for (const n of limits) limit(e, n, typeof val === 'number' ? val : !!val);
|
|
44
52
|
switch (key) {
|
|
45
|
-
case 'pixelRatio':
|
|
46
|
-
case 'antialias': e.post.
|
|
53
|
+
case 'pixelRatio': e.setPixelRatio(val); break;
|
|
54
|
+
case 'antialias': e.post.nextAntialias(val); break;
|
|
55
|
+
case 'tier': if (val) e.mod('tier', { owner: 'settings', layer: 'settings', set: val }); else e.stacks.get('tier').release('settings'); break;
|
|
47
56
|
case 'adaptive': if (e.adaptive) { e.adaptive.on = val; if (!val && e.adaptive.max) e.setPixelRatio(e.adaptive.max); } break;
|
|
48
|
-
case 'viewChunks': { const H = s.chunkHost(); if (H?.setViewChunks && H.viewChunks !== val) H.setViewChunks(val); break; }
|
|
49
|
-
case 'density': { const H = s.chunkHost(); if (H?.setDensity && H.density !== val) H.setDensity(val); break; }
|
|
50
57
|
default:
|
|
51
58
|
// a saved slider for a bus this build no longer has is skipped, not an error
|
|
52
59
|
if (key.startsWith('vol.')) { if (key.slice(4) in e.audio.levels) e.audio.setVolume(key.slice(4), val); }
|