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