threedog 0.5.0 → 0.7.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 +81 -1
- package/README.md +21 -13
- package/core/Assets.js +23 -12
- package/core/Audio.js +1 -1
- package/core/Baked.js +14 -23
- package/core/Budget.js +2 -2
- package/core/DebugOverrides.js +33 -18
- package/core/Describe.js +10 -11
- package/core/Engine.js +50 -46
- package/core/I18n.js +2 -2
- package/core/Input.js +11 -5
- package/core/Inspect.js +6 -3
- package/core/InspectMaterials.js +2 -3
- package/core/InspectPerf.js +11 -4
- package/core/MaterialInfo.js +7 -5
- package/core/Rays.js +7 -2
- package/core/Stream.js +2 -3
- package/core/UrlState.js +49 -9
- package/core/Views.js +1 -0
- package/core/adaptive.js +2 -2
- package/core/assetEntry.js +5 -2
- package/core/assetLoad.js +13 -15
- package/core/assetManifest.js +6 -3
- package/core/assetReport.js +4 -4
- package/core/batchGroups.js +9 -1
- package/core/catalog.js +16 -3
- package/core/chunkStream.js +1 -1
- package/core/copies.js +1 -1
- package/core/debugView.js +4 -4
- package/core/describeRender.js +104 -28
- package/core/describeText.js +6 -6
- package/core/errorCodes.js +72 -45
- package/core/errorHints.js +4 -1
- package/core/errors.js +4 -4
- package/core/events.generated.js +1 -0
- package/core/gameLights.js +9 -2
- package/core/lifecycle.js +2 -4
- package/core/lightWatch.js +5 -3
- package/core/loop.js +18 -11
- package/core/math.js +7 -0
- package/core/moduleSlots.js +32 -7
- package/core/moduleTypes.js +20 -7
- package/core/modules.js +7 -7
- package/core/namedModel.js +8 -4
- package/core/owned.js +33 -30
- package/core/page.js +43 -10
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +64 -96
- package/core/sceneDelta.js +12 -4
- package/core/sceneMethods.js +2 -9
- package/core/services.js +1 -1
- package/core/shadowTypes.js +1 -1
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +5 -19
- package/core/stackFrames.js +16 -5
- package/core/stacks.js +6 -6
- package/core/startup.js +9 -11
- package/core/thingExplain.js +1 -1
- package/core/things.js +1 -1
- package/core/tier.js +1 -1
- package/core/util.js +1 -1
- package/core/validate.js +1 -1
- package/core/view.js +43 -0
- package/docs/AI.md +62 -58
- package/docs/API.md +15 -15
- package/docs/CODEMAP.md +36 -54
- package/docs/COMMANDS.md +28 -25
- package/docs/CONVENTIONS.md +36 -30
- package/docs/MIGRATING-0.4.md +93 -1
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/THREE.md +24 -22
- package/docs/api/assets.md +5 -3
- package/docs/api/audio.md +2 -2
- package/docs/api/budget.md +4 -0
- package/docs/api/characters.md +3 -1
- package/docs/api/collision.md +2 -2
- package/docs/api/engine.md +47 -20
- package/docs/api/events.md +2 -1
- package/docs/api/grids.md +8 -1
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +3 -0
- package/docs/api/input.md +3 -2
- package/docs/api/interactions.md +3 -1
- package/docs/api/inventory.md +1 -2
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +1 -1
- package/docs/api/occlusion.md +5 -0
- package/docs/api/particles.md +6 -3
- package/docs/api/pickups.md +6 -0
- package/docs/api/post.md +5 -3
- package/docs/api/sky.md +12 -10
- package/docs/api/terrain.md +12 -6
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/tools.md +8 -7
- package/docs/api/triggers.md +2 -0
- package/docs/api/vegetation.md +7 -2
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +6 -2
- package/docs/api/weather.md +5 -0
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +19 -23
- package/docs/recipes/03-items-pickups.md +25 -4
- package/docs/recipes/05-props-bake.md +53 -37
- package/docs/recipes/06-clock-events.md +3 -3
- package/docs/recipes/07-flow-scenes-pause.md +12 -3
- package/docs/recipes/08-weather-sky.md +45 -57
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +2 -2
- package/docs/recipes/11-vehicles.md +3 -3
- package/docs/recipes/13-animation.md +13 -7
- package/docs/recipes/14-custom-module.md +7 -5
- package/docs/recipes/15-perf.md +3 -3
- package/docs/recipes/16-dev-bridge.md +22 -12
- package/docs/recipes/18-world.md +10 -8
- package/docs/recipes/19-shooting-picking.md +7 -5
- package/docs/recipes/20-content-actions-save.md +6 -2
- package/docs/recipes/21-camera.md +8 -3
- package/docs/recipes/23-ops.md +1 -1
- package/docs/recipes/26-ui-parts.md +35 -11
- package/docs/recipes/28-terrain.md +12 -12
- package/docs/recipes/29-grid.md +14 -5
- package/docs/recipes/30-templates.md +8 -3
- package/docs/recipes/31-audio.md +4 -4
- package/docs/recipes/32-action-game.md +18 -4
- package/docs/recipes/34-environment-lighting.md +102 -38
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +106 -27
- package/docs/recipes/42-terrain-shape.md +1 -1
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +121 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +10 -12
- package/docs/recipes/49-game-module-contract.md +1 -1
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +18 -18
- package/docs/recipes/55-mods-time-wrap.md +17 -5
- package/docs/recipes/56-webgpu-tsl.md +66 -23
- package/docs/recipes/57-control.md +39 -0
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +39 -24
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +7 -5
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +8 -3
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +25 -33
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/sheepisland/.threedog/content-index.json +1 -1
- package/examples/sheepisland/GAMEMAP.md +13 -10
- package/examples/sheepisland/assets.js +2 -2
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +15 -9
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -11
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +30 -67
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +4 -3
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +5 -3
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +9 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +15 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +7 -16
- package/index.js +7 -7
- package/llms.txt +15 -13
- package/modules/ambience/Ambience.js +1 -1
- package/modules/calendar/Calendar.js +1 -1
- package/modules/calendar/index.js +1 -0
- package/modules/camera/FirstPersonCamera.js +1 -1
- package/modules/camera/FixedCamera.js +2 -2
- package/modules/camera/RtsCamera.js +1 -1
- package/modules/camera/common.js +7 -5
- package/modules/characters/Character.js +15 -10
- package/modules/characters/NPC.js +5 -5
- package/modules/characters/assetModel.js +5 -4
- package/modules/characters/index.js +28 -3
- package/modules/characters/movers/common.js +6 -1
- package/modules/characters/movers/manual.js +3 -0
- package/modules/characters/movers/support.js +25 -11
- package/modules/characters/npcSim.js +5 -1
- package/modules/characters/proceduralRig.js +18 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/collision/Collision.js +4 -2
- package/modules/content/index.js +8 -0
- package/modules/content/models.js +56 -11
- package/modules/content/props.js +5 -3
- package/modules/content/rules.js +12 -4
- package/modules/content/templates.js +5 -3
- package/modules/gameplay/Interactions.js +91 -16
- package/modules/gameplay/Inventory.js +3 -3
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +1 -1
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -2
- package/modules/gameplay/pickups.js +62 -24
- package/modules/gameplay/questLog.js +2 -2
- package/modules/grid/Layer.js +13 -0
- package/modules/grid/index.js +40 -11
- package/modules/grid/preview.js +24 -15
- package/modules/grid/tiles.js +15 -19
- package/modules/hlod/index.js +3 -2
- package/modules/hud/index.js +13 -0
- package/modules/hud/parts.js +9 -7
- package/modules/level/index.js +5 -4
- package/modules/lights/index.js +12 -8
- package/modules/music/Music.js +1 -1
- package/modules/particles/Particles.js +41 -20
- package/modules/particles/effect.js +21 -6
- package/modules/photo/Photo.js +11 -10
- package/modules/settings/Settings.js +7 -7
- package/modules/settings/apply.js +5 -5
- package/modules/settings/sections.js +2 -2
- package/modules/settings/strings.js +1 -1
- package/modules/sky/Sky.js +104 -89
- package/modules/sky/clouds.js +16 -17
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +5 -5
- package/modules/sky/environment.js +45 -169
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +26 -90
- package/modules/sky/season.js +3 -3
- package/modules/sky/shader.js +35 -29
- package/modules/sky/skyModule.js +25 -22
- package/modules/sky/tint.js +9 -11
- package/modules/terrain/ChunkManager.js +29 -12
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +44 -66
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +1 -1
- package/modules/terrain/terrainGen.js +2 -2
- package/modules/triggers/index.js +10 -6
- package/modules/vegetation/Vegetation.js +58 -17
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +1 -1
- package/modules/vegetation/index.js +10 -10
- package/modules/water/Water.js +135 -88
- package/modules/water/surface.js +53 -53
- package/modules/weather/Weather.js +52 -17
- package/modules/weather/particles.js +13 -5
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +2 -2
- package/modules/world/views.js +1 -1
- package/package.json +3 -2
- package/presets.js +2 -2
- package/render/PostFX.js +199 -41
- package/render/backend.js +52 -6
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +5 -5
- package/render/effects.js +41 -26
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/index.js +7 -5
- package/render/fx/patchNodes.tsl.js +1 -1
- package/render/fx/postWebGPU.tsl.js +30 -7
- package/render/fx/sky.tsl.js +19 -92
- package/render/fx/water.tsl.js +1 -1
- package/render/layers.js +14 -0
- package/render/lighting.js +6 -5
- package/render/lightmap.js +142 -0
- package/render/lights.js +23 -201
- package/render/materials.js +44 -160
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +1 -1
- package/render/patches.js +34 -29
- package/render/postWebGL.js +11 -3
- package/render/probes.js +179 -122
- package/render/slots.js +4 -4
- package/render/terms.js +53 -101
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +333 -296
- package/types/gameplay.d.ts +65 -26
- package/types/generated/core/Audio.d.ts +1 -1
- package/types/generated/core/DebugOverrides.d.ts +14 -6
- package/types/generated/core/Input.d.ts +9 -2
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/modules/grid/Layer.d.ts +8 -0
- package/types/generated/modules/grid/index.d.ts +29 -5
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -18
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +33 -3
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +2 -2
- package/types/generated/render/PostFX.d.ts +53 -10
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +19 -44
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/physics.d.ts +5 -3
- package/types/tsl.d.ts +8 -0
- package/types/world.d.ts +376 -57
- package/ui/Focus.js +12 -2
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +8 -4
- package/ui/UI.js +10 -10
- package/ui/cursor.js +1 -1
- package/ui/theme.js +33 -27
- package/ui/touchPart.js +1 -1
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/styleParts.js +0 -114
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
package/core/shadows.js
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// engine.shadows: the shadow engineering in three.js shape: each entry takes a light the game hands it and returns a handle. cascades(light): 2-4 maps along the
|
|
2
|
+
// view. box(light): the one shadow map's box follows something. budget(light): the map redraws every N frames. mapSize(light, n): resolution after the first draw.
|
|
3
|
+
// enabled: the master switch. include(mat).
|
|
4
|
+
// Why in core: they work with no module installed, on any DirectionalLight, so a game that lights its world itself (createEngine({ lights: false })) has them all.
|
|
5
|
+
// What stays the game's: a light nobody handed in is never touched, and the light's color, intensity, castShadow, visible and shadow values are only read. Filter,
|
|
6
|
+
// bias, radius and the first map size are plain three.js (renderer.shadowMap.type, light.shadow.*). Cascades and a box have to move a light to place it, so while they
|
|
7
|
+
// are on the light's position and target hold the placement (WebGL; three's node moves stand-ins on WebGPU): a game's later write to light.position, or a new
|
|
8
|
+
// light.target, still sets the direction, and remove() puts both back as the game left them. light.target is swapped for a stand-in because the placement
|
|
9
|
+
// writes target.position, and a game's target is often its player (light.target = player).
|
|
10
|
+
// The engine's placeholder sun is the engine's own light: a sky holds a box on it (sunBox) with the real target, and a direct write to that target yields (owned.js).
|
|
11
|
+
import * as THREE from 'three';
|
|
12
|
+
import { codedError } from './errorHints.js';
|
|
13
|
+
import { warnOnce } from './validate.js';
|
|
14
|
+
import { readParams } from './params.js';
|
|
15
|
+
import { defineOwned, dropOwned, ownedRow } from './owned.js';
|
|
16
|
+
import { isWebGPU, onRendererSwap, setShadowUpdate, shadowsOn } from '../render/backend.js';
|
|
17
|
+
import { CASCADE_DEFAULTS, CASCADE_SPLITS, createCascades, dropCascades, includeInCascades } from '../render/cascades.js';
|
|
18
|
+
|
|
19
|
+
const WHERE = 'engine.shadows.cascades';
|
|
20
|
+
const PARAMS = {
|
|
21
|
+
count: { type: 'int', default: 3, min: 1, max: 4, desc: 'shadow maps along the view; 1 = one map that follows the camera' },
|
|
22
|
+
maxFar: { type: 'number', default: CASCADE_DEFAULTS.maxFar, min: 0.001, desc: 'meters from the camera they cover' },
|
|
23
|
+
split: { type: 'any', default: CASCADE_DEFAULTS.split, desc: "'practical' | 'uniform' | 'logarithmic' | (count, near, far, out) => void" },
|
|
24
|
+
fade: { type: 'bool', default: CASCADE_DEFAULTS.fade, desc: 'cross-fade at the borders' },
|
|
25
|
+
lightMargin: { type: 'number', default: CASCADE_DEFAULTS.lightMargin, min: 0, desc: 'meters behind each cascade box toward the light still caught as casters' },
|
|
26
|
+
low: { type: 'object', optional: true, desc: 'on low-tier devices: { count } (default 1, one map that follows the camera)' },
|
|
27
|
+
};
|
|
28
|
+
const STRINGS = {
|
|
29
|
+
light: `${WHERE}(light): needs a three.js DirectionalLight (cascades split a parallel light's shadow); got {got}`,
|
|
30
|
+
scene: `${WHERE}(light): the light must be a direct child of engine.scene first (cascades place it in world space): engine.scene.add(light)`,
|
|
31
|
+
cast: `${WHERE}(light): set light.castShadow = true first; the engine does not write that on your light`,
|
|
32
|
+
twice: `${WHERE}(light): this engine already has a cascades handle; change it with handle.set({ ... }) or call handle.remove() first (an engine draws one set)`,
|
|
33
|
+
boxed: `${WHERE}(light): this light has a shadow box, and both place the light; call the box handle's remove() first`,
|
|
34
|
+
split: `${WHERE}: split must be ${CASCADE_SPLITS.map(s => `'${s}'`).join(' | ')} or a function (count, near, far, out) => void; got {got}`,
|
|
35
|
+
low: `${WHERE}: low must be { count } with a whole number 1 to 4; got {got}`,
|
|
36
|
+
};
|
|
37
|
+
const fail = (k, got) => { throw codedError('shadow-cascades', STRINGS[k].replace('{got}', JSON.stringify(got) ?? String(got))); };
|
|
38
|
+
const refuse = msg => { throw codedError('shadow-cascades', msg); };
|
|
39
|
+
|
|
40
|
+
const BOX = 'engine.shadows.box';
|
|
41
|
+
const BOX_PARAMS = {
|
|
42
|
+
follow: { type: 'any', default: 'focus', desc: "what the box centers on: 'focus' (engine.focus) | 'camera' | an Object3D | () => Vector3 | false (it stays on the light's target)" },
|
|
43
|
+
extent: { type: 'number', optional: true, min: 1, desc: "half size of the box in meters; left out: the light's own shadow camera stays as it is" },
|
|
44
|
+
snap: { type: 'any', default: 0.5, desc: "center snap grid in meters, or 'texel' (one shadow pixel: no shimmer on a moving camera)" },
|
|
45
|
+
ahead: { type: 'number', default: 0, desc: 'meters the center is shifted in front of the view' },
|
|
46
|
+
};
|
|
47
|
+
const BUDGET = 'engine.shadows.budget';
|
|
48
|
+
const MAP = 'engine.shadows.mapSize';
|
|
49
|
+
const BUDGET_PARAMS = { every: { type: 'int', default: 1, min: 1, desc: 'redraw the shadow map every N frames; 1 = every frame' } };
|
|
50
|
+
|
|
51
|
+
function readBox(o) {
|
|
52
|
+
const v = readParams(BOX, BOX_PARAMS, o), f = v.follow;
|
|
53
|
+
if (!(f === false || f === 'focus' || f === 'camera' || f?.isObject3D || typeof f === 'function')) refuse(`${BOX}: follow must be 'focus' | 'camera' | an Object3D | () => Vector3 | false; got ${JSON.stringify(f)}`);
|
|
54
|
+
if (v.snap !== 'texel' && !(typeof v.snap === 'number' && v.snap >= 0)) refuse(`${BOX}: snap must be meters (a number, 0 = none) or 'texel'; got ${JSON.stringify(v.snap)}`);
|
|
55
|
+
return v;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Where a light's box goes: the followed thing (and `ahead`), snapped. Shared by a game's light and the engine sun */
|
|
59
|
+
function boxCenter(e, light) {
|
|
60
|
+
const f = new THREE.Vector3(), r = new THREE.Vector3(), u = new THREE.Vector3(), ahead = new THREE.Vector3(), last = new THREE.Vector3();
|
|
61
|
+
let key = '', seen = false;
|
|
62
|
+
/** @param {THREE.Vector3} at written with the center @param {THREE.Vector3} dir unit vector toward the light @param {any} o the box options */
|
|
63
|
+
return (at, dir, o) => {
|
|
64
|
+
const cam = e.camera, s = light.shadow;
|
|
65
|
+
if (o.follow === 'camera') at.copy(cam.position);
|
|
66
|
+
else if (o.follow?.isObject3D) o.follow.getWorldPosition(at);
|
|
67
|
+
else if (typeof o.follow === 'function') at.copy(o.follow());
|
|
68
|
+
else at.copy(e.focus);
|
|
69
|
+
if (o.ahead) { cam.getWorldDirection(ahead); ahead.y = 0; if (ahead.lengthSq() > 1e-6) at.addScaledVector(ahead.normalize(), o.ahead); }
|
|
70
|
+
let now;
|
|
71
|
+
if (o.snap === 'texel') {
|
|
72
|
+
// the light-space right and up axes (matching the shadow camera lookAt), rounded to one shadow pixel along each
|
|
73
|
+
const sc = s.camera, texel = (sc.right - sc.left) / s.mapSize.x;
|
|
74
|
+
f.copy(dir).negate();
|
|
75
|
+
r.crossVectors(f, cam.up); if (r.lengthSq() < 1e-8) r.set(1, 0, 0); r.normalize();
|
|
76
|
+
u.crossVectors(r, f);
|
|
77
|
+
const a = Math.round(at.dot(r) / texel), b = Math.round(at.dot(u) / texel), c = at.dot(f);
|
|
78
|
+
at.copy(r).multiplyScalar(a * texel).addScaledVector(u, b * texel).addScaledVector(f, c);
|
|
79
|
+
now = a + ',' + b;
|
|
80
|
+
} else {
|
|
81
|
+
const g = o.snap || 1e-3;
|
|
82
|
+
at.x = Math.round(at.x / g) * g; at.z = Math.round(at.z / g) * g;
|
|
83
|
+
now = at.x + ',' + at.z;
|
|
84
|
+
}
|
|
85
|
+
// under a budget: redraw early only when the center left a quarter of the box (teleport, fast travel); otherwise the budget's own rhythm
|
|
86
|
+
if (!seen) { last.copy(at); seen = true; }
|
|
87
|
+
if (!s.autoUpdate && now !== key && last.distanceToSquared(at) > (s.camera.right / 4) ** 2) s.needsUpdate = true;
|
|
88
|
+
if (s.needsUpdate) last.copy(at);
|
|
89
|
+
key = now;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Write the half size on the light's shadow camera @param {any} light @param {number} ext */
|
|
94
|
+
function setExtent(light, ext) { const c = light.shadow.camera; c.left = c.bottom = -ext; c.right = c.top = ext; c.updateProjectionMatrix(); }
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A box on a game's light: position and target hold the placement, what the game writes stays the direction (see the header)
|
|
98
|
+
* @param {any} e @param {any} light @param {object} first
|
|
99
|
+
* @param {number} [back] meters the light stands behind the center, the shadow camera reaching extent past it; left out: where the game put it, its near / far as they are
|
|
100
|
+
*/
|
|
101
|
+
function gameBox(e, light, first, back) {
|
|
102
|
+
let o = readBox(first), sized = false;
|
|
103
|
+
const sc = light.shadow.camera, was = { left: sc.left, right: sc.right, top: sc.top, bottom: sc.bottom, near: sc.near, far: sc.far };
|
|
104
|
+
const own = { position: light.position.clone(), target: light.target };
|
|
105
|
+
const proxy = new THREE.Object3D(), placed = new THREE.Vector3(Infinity, 0, 0), at = new THREE.Vector3(), dir = new THREE.Vector3(), center = boxCenter(e, light);
|
|
106
|
+
light.target = proxy;
|
|
107
|
+
const size = ext => { setExtent(light, ext); sized = true; };
|
|
108
|
+
if (back !== undefined) Object.assign(sc, { near: 1, far: back + o.extent });
|
|
109
|
+
if (o.extent !== undefined) size(o.extent);
|
|
110
|
+
const readGame = () => {
|
|
111
|
+
if (light.target !== proxy) { own.target = light.target; light.target = proxy; }
|
|
112
|
+
if (!light.position.equals(placed)) own.position.copy(light.position);
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
frame() {
|
|
116
|
+
readGame();
|
|
117
|
+
own.target.updateWorldMatrix(true, false);
|
|
118
|
+
at.setFromMatrixPosition(own.target.matrixWorld);
|
|
119
|
+
dir.copy(own.position).sub(at);
|
|
120
|
+
const dist = dir.length();
|
|
121
|
+
dir.normalize();
|
|
122
|
+
if (o.follow !== false) center(at, dir, o);
|
|
123
|
+
proxy.position.copy(at); proxy.updateMatrixWorld(); // not in the scene: nothing else refreshes it
|
|
124
|
+
light.position.copy(at).addScaledVector(dir, back ?? dist); placed.copy(light.position);
|
|
125
|
+
},
|
|
126
|
+
set(next) { o = readBox({ ...o, ...next }); if (next.extent !== undefined) size(o.extent); },
|
|
127
|
+
remove() {
|
|
128
|
+
readGame();
|
|
129
|
+
light.position.copy(own.position); light.target = own.target;
|
|
130
|
+
if (sized) { Object.assign(sc, was); sc.updateProjectionMatrix(); } // never sized: what the game wrote there is the game's
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The box on the engine's own sun: the real target moves, so engine.lights.sun.target.position reads as ever, and a direct write to it yields ('shadow.follow').
|
|
137
|
+
* @param {any} e @param {any} light @param {object} first @param {(() => number)} [distance] how far the light sits from the center; left out: where it is now
|
|
138
|
+
*/
|
|
139
|
+
function sunBox(e, light, first, distance) {
|
|
140
|
+
let o = readBox(first);
|
|
141
|
+
const dir = new THREE.Vector3(), tp = light.target.position, center = boxCenter(e, light);
|
|
142
|
+
const held = defineOwned(e, { id: 'shadow.follow', part: 'shadow', key: 'follow', read: () => tp.toArray(), objects: [light.target, tp],
|
|
143
|
+
levels: { manual: 'engine.shadows.box(engine.lights.sun, { follow: false })', back: "engine.shadows.box(engine.lights.sun, { follow: 'focus' })" } });
|
|
144
|
+
if (o.extent !== undefined) setExtent(light, o.extent);
|
|
145
|
+
if (o.follow === false) held.manual(true);
|
|
146
|
+
held.mark();
|
|
147
|
+
return {
|
|
148
|
+
frame() {
|
|
149
|
+
if (e._cascades?.light === light) return; // the cascades place it now; the box comes back with their remove()
|
|
150
|
+
held.check();
|
|
151
|
+
dir.subVectors(light.position, tp);
|
|
152
|
+
const dist = distance?.() ?? dir.length();
|
|
153
|
+
dir.normalize();
|
|
154
|
+
if (held.on) center(tp, dir, o);
|
|
155
|
+
light.position.copy(tp).addScaledVector(dir, dist);
|
|
156
|
+
light.target.updateMatrixWorld();
|
|
157
|
+
held.mark();
|
|
158
|
+
},
|
|
159
|
+
set(next) {
|
|
160
|
+
o = readBox({ ...o, ...next });
|
|
161
|
+
if (next.extent !== undefined) setExtent(light, o.extent);
|
|
162
|
+
if ('follow' in next) held.manual(next.follow === false); // the game said what it wants: a yield from before is over
|
|
163
|
+
},
|
|
164
|
+
get options() { return o; },
|
|
165
|
+
remove() { dropOwned(e, [held]); },
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The update budget of one light: its own flags (three reads them on both renderers), so a light nobody handed in keeps redrawing */
|
|
170
|
+
function ownBudget(e, light, first) {
|
|
171
|
+
const s = light.shadow, was = s.autoUpdate;
|
|
172
|
+
let every = 1, n = 0, type = e.renderer.shadowMap.type;
|
|
173
|
+
const set = o => { every = readParams(BUDGET, BUDGET_PARAMS, { every, ...o }).every; s.autoUpdate = every <= 1; s.needsUpdate = true; n = 0; };
|
|
174
|
+
set(first);
|
|
175
|
+
return {
|
|
176
|
+
frame() {
|
|
177
|
+
if (every <= 1) return;
|
|
178
|
+
// a filter switch rebuilds the maps only of lights that draw that frame (WebGLShadowMap), so a light that skipped it would keep the old kind of map
|
|
179
|
+
const t = e.renderer.shadowMap.type;
|
|
180
|
+
if (t === type && ++n < every) return;
|
|
181
|
+
type = t; n = 0; s.needsUpdate = true;
|
|
182
|
+
},
|
|
183
|
+
set,
|
|
184
|
+
redraw() { s.needsUpdate = true; n = 0; },
|
|
185
|
+
remove() { s.autoUpdate = was; s.needsUpdate = true; },
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The master switch: the renderer's switch only. Both renderers stop drawing and sampling shadow maps when renderer.shadowMap.enabled is false (WebGL:
|
|
191
|
+
* WebGLShadowMap.render returns and programs drop USE_SHADOWMAP; WebGPU: the shadow and light nodes check it), so no light's castShadow is touched: castShadow
|
|
192
|
+
* stays the game's, and what the game set is what casts when they come back. Materials recompile once (the shadow define changes).
|
|
193
|
+
* @param {any} e @param {boolean} on
|
|
194
|
+
*/
|
|
195
|
+
function switchShadows(e, on) {
|
|
196
|
+
if (shadowsOn(e) === on) return; // nothing changed: no scene walk, no recompile
|
|
197
|
+
e.renderer.shadowMap.enabled = on;
|
|
198
|
+
e.scene.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
|
|
199
|
+
e.events.emit('settings:shadows', on);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The running handle's cascades. The WebGL half keeps what the game wrote apart from the placement; see the header */
|
|
203
|
+
function ownCascades(e, light, first) {
|
|
204
|
+
let o = readOptions(first), c = null, key = '', own = null, box = null;
|
|
205
|
+
const proxy = new THREE.Object3D(), placed = new THREE.Vector3(), dir = new THREE.Vector3();
|
|
206
|
+
const readGame = () => {
|
|
207
|
+
if (light.target !== proxy) { own.target = light.target; light.target = proxy; }
|
|
208
|
+
if (!light.position.equals(placed)) own.position.copy(light.position);
|
|
209
|
+
};
|
|
210
|
+
const off = () => {
|
|
211
|
+
box?.remove(); box = null;
|
|
212
|
+
if (!c) return;
|
|
213
|
+
if (own) { readGame(); light.position.copy(own.position); light.target = own.target; own = null; }
|
|
214
|
+
dropCascades(e);
|
|
215
|
+
c = null; key = '';
|
|
216
|
+
};
|
|
217
|
+
const sync = () => {
|
|
218
|
+
const n = e.tier === 'low' ? o.low?.count ?? 1 : o.count; // low tier: one map unless the game says so
|
|
219
|
+
const want = (n > 1 ? [n, o.maxFar, o.fade, o.lightMargin, o.split] : [o.maxFar, o.lightMargin]).join('|');
|
|
220
|
+
if (want === key) return;
|
|
221
|
+
off();
|
|
222
|
+
key = want;
|
|
223
|
+
if (n <= 1) {
|
|
224
|
+
// one map still has to cover what the cascades would: left alone it stays three's default 10 m box where the game put the light. Centered on the camera, as far
|
|
225
|
+
// as maxFar each way and lightMargin behind, as the cascades reach. The engine sun needs none: a sky's box or the baseline follow (render/lights.js) moves it
|
|
226
|
+
if (light !== e.lights?.sun) box = gameBox(e, light, { follow: 'camera', extent: o.maxFar, snap: 'texel' }, o.lightMargin + o.maxFar);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
c = createCascades(e, light, { ...o, cascades: n }, WHERE);
|
|
230
|
+
if (c.isCascadeNode) return;
|
|
231
|
+
own = { position: light.position.clone(), target: light.target };
|
|
232
|
+
proxy.position.copy(light.target.position);
|
|
233
|
+
placed.set(Infinity, 0, 0);
|
|
234
|
+
light.target = proxy;
|
|
235
|
+
e.scene.traverse(l => { // on WebGL the cascade order is the order of the shadow-casting lights
|
|
236
|
+
if (l.isDirectionalLight && l.castShadow && l.visible && !c.lights.includes(l)) warnOnce(`${WHERE}: DirectionalLight '${l.name || l.uuid.slice(0, 8)}' casts shadows too, which breaks the cascade order; set castShadow = false on it`);
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
const swap = onRendererSwap(e, () => { if (c?.isCascadeNode) { off(); sync(); } }); // fallback 'webgl': the shadow node has no meaning on the new renderer
|
|
240
|
+
sync();
|
|
241
|
+
return {
|
|
242
|
+
frame() {
|
|
243
|
+
box?.frame();
|
|
244
|
+
if (!c) return;
|
|
245
|
+
const every = light.shadow.autoUpdate && e.renderer.shadowMap.autoUpdate ? 1 : 2; // 2 = "not every frame": a budget, or a game's own autoUpdate = false
|
|
246
|
+
if (c.isCascadeNode) { light.target.updateMatrixWorld(); c.frame(null, every); return; }
|
|
247
|
+
readGame();
|
|
248
|
+
own.target.updateWorldMatrix(true, false);
|
|
249
|
+
dir.setFromMatrixPosition(own.target.matrixWorld).negate().add(own.position).normalize();
|
|
250
|
+
c.frame(dir, every);
|
|
251
|
+
placed.copy(light.position);
|
|
252
|
+
proxy.updateMatrixWorld(); // not in the scene: nothing else refreshes it
|
|
253
|
+
},
|
|
254
|
+
set(next) { o = readOptions({ ...o, ...next }); sync(); },
|
|
255
|
+
remove() { off(); swap.remove(); },
|
|
256
|
+
get csm() { return c; },
|
|
257
|
+
/** the light while one map's box places it, else null */
|
|
258
|
+
get boxed() { return box ? light : null; },
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function readOptions(o) {
|
|
263
|
+
const v = readParams(WHERE, PARAMS, o);
|
|
264
|
+
if (typeof v.split !== 'function' && !CASCADE_SPLITS.includes(v.split)) fail('split', v.split);
|
|
265
|
+
const low = v.low?.count;
|
|
266
|
+
if (v.low && (Object.keys(v.low).some(k => k !== 'count') || !(Number.isInteger(low) && low >= 1 && low <= 4))) fail('low', v.low);
|
|
267
|
+
return v;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** @param {any} e @param {{ owned: boolean }} o owned: the engine made the renderer (a game's own renderer keeps its shadow settings) */
|
|
271
|
+
export function defineShadows(e, { owned }) {
|
|
272
|
+
let live = null, sky = null;
|
|
273
|
+
const boxes = new Map(), budgets = new Map();
|
|
274
|
+
if (owned) e.renderer.shadowMap.enabled = true; // the placeholder sun casts, so things read as standing on the ground; the switch below turns it off
|
|
275
|
+
// one point, because separate switches (an option, a method, the settings menu) each decided on their own and disagreed about what is on
|
|
276
|
+
const point = e.stacks.define('shadows.enabled', { kind: 'value', base: shadowsOn(e), save: false, manual: "engine.mod('shadows.enabled', { owner, layer: 'system', set })",
|
|
277
|
+
onChange: () => switchShadows(e, !!point.value()) });
|
|
278
|
+
const hold = (map, light, h) => {
|
|
279
|
+
const remove = () => { if (map.get(light) !== h) return; h.remove(); map.delete(light); };
|
|
280
|
+
map.set(light, h);
|
|
281
|
+
e.signal.addEventListener('abort', remove, { once: true });
|
|
282
|
+
return remove;
|
|
283
|
+
};
|
|
284
|
+
e.shadows = {
|
|
285
|
+
/**
|
|
286
|
+
* Master shadow switch, true while shadows are drawn. Writes renderer.shadowMap.enabled only, never a light's castShadow; materials recompile once, so switch
|
|
287
|
+
* on a menu, not per frame. A cutscene holds it with engine.mod('shadows.enabled', { owner, layer: 'system', set: false }); the settings menu restricts it.
|
|
288
|
+
* @example engine.shadows.enabled = false;
|
|
289
|
+
* @type {boolean}
|
|
290
|
+
*/
|
|
291
|
+
get enabled() { return shadowsOn(e); },
|
|
292
|
+
set enabled(v) {
|
|
293
|
+
if (typeof v !== 'boolean') refuse(`engine.shadows.enabled: true or false; got ${JSON.stringify(v)}`);
|
|
294
|
+
point.take({ owner: 'game', set: v });
|
|
295
|
+
},
|
|
296
|
+
/**
|
|
297
|
+
* Cascaded shadows for a DirectionalLight: sharp near the camera, wide far away, following the camera. The light stays yours: color, intensity and shadow
|
|
298
|
+
* values are read from it. Low-tier devices get one map, which follows the camera, unless `low: { count }` says otherwise. WebGPURenderer needs `import 'threedog/tsl'`.
|
|
299
|
+
* @example
|
|
300
|
+
* const sun = new THREE.DirectionalLight('#fff4e0', 3); sun.position.set(40, 80, 30); sun.castShadow = true; engine.scene.add(sun);
|
|
301
|
+
* const shadows = engine.shadows.cascades(sun, { count: 3, maxFar: 150 });
|
|
302
|
+
* shadows.set({ count: 2 }); shadows.remove();
|
|
303
|
+
* @param {any} light a DirectionalLight in engine.scene, castShadow on (engine.lights.sun too)
|
|
304
|
+
* @param {{ count?: number, maxFar?: number, split?: string | Function, fade?: boolean, lightMargin?: number, low?: { count: number } }} [options]
|
|
305
|
+
* @returns {{ set(options: object): void, remove(): void, readonly light: any, readonly csm: any }}
|
|
306
|
+
*/
|
|
307
|
+
cascades(light, options = {}) {
|
|
308
|
+
if (!light?.isDirectionalLight) fail('light', light?.type ?? light);
|
|
309
|
+
if (light.parent !== e.scene) fail('scene');
|
|
310
|
+
if (!light.castShadow) fail('cast');
|
|
311
|
+
if (live) fail('twice');
|
|
312
|
+
if (boxes.has(light) && light !== e.lights.sun) fail('boxed');
|
|
313
|
+
const set = ownCascades(e, light, options);
|
|
314
|
+
live = set;
|
|
315
|
+
const remove = () => { if (live !== set) return; set.remove(); live = null; };
|
|
316
|
+
e.signal.addEventListener('abort', remove, { once: true });
|
|
317
|
+
return { light, set: o => set.set(o), remove, get csm() { return set.csm; } };
|
|
318
|
+
},
|
|
319
|
+
/**
|
|
320
|
+
* Keep a DirectionalLight's one shadow map around something that moves, so a wide world needs no giant map. The light keeps its direction: its position minus
|
|
321
|
+
* its target, including what you write later. Nothing follows anything until you call this; remove() puts the light back. On engine.lights.sun under a sky it
|
|
322
|
+
* changes the engine's own box, and remove() restores that.
|
|
323
|
+
* @example
|
|
324
|
+
* const box = engine.shadows.box(sun, { follow: player, extent: 40, snap: 'texel' });
|
|
325
|
+
* box.set({ extent: 60 }); box.remove();
|
|
326
|
+
* @param {any} light a DirectionalLight in engine.scene
|
|
327
|
+
* @param {{ follow?: 'focus' | 'camera' | any | (() => any) | false, extent?: number, snap?: number | 'texel', ahead?: number }} [options]
|
|
328
|
+
* @returns {{ set(options: object): void, remove(): void }}
|
|
329
|
+
*/
|
|
330
|
+
box(light, options = {}) {
|
|
331
|
+
if (!light?.isDirectionalLight) refuse(`${BOX}(light): needs a three.js DirectionalLight; got ${light?.type ?? light}`);
|
|
332
|
+
if (light.parent !== e.scene) refuse(`${BOX}(light): the light must be a direct child of engine.scene first (the box is placed in world space): engine.scene.add(light)`);
|
|
333
|
+
if (sky && light === e.lights.sun) { // the engine's box under a sky: the game changes it, remove() gives its options back
|
|
334
|
+
const h = sky, base = { ...h.options, extent: light.shadow.camera.right }; // the sky sized the camera itself, so its options may hold no extent
|
|
335
|
+
h.set(options);
|
|
336
|
+
return { set: o => h.set(o), remove: () => h.set(base) };
|
|
337
|
+
}
|
|
338
|
+
if (boxes.has(light)) refuse(`${BOX}(light): this light has a box already; change it with handle.set({ ... }) or call handle.remove() first`);
|
|
339
|
+
if (e._cascades?.light === light || live?.boxed === light) refuse(`${BOX}(light): this light has cascades, and both place the light; call the cascades handle's remove() first`);
|
|
340
|
+
const h = light === e.lights.sun ? sunBox(e, light, options) : gameBox(e, light, options);
|
|
341
|
+
return { set: o => h.set(o), remove: hold(boxes, light, h) };
|
|
342
|
+
},
|
|
343
|
+
/**
|
|
344
|
+
* Redraw a light's shadow map only every N frames: a third of the fill cost at every: 3. Other lights are not touched. A box or cascades on the same light
|
|
345
|
+
* redraw early after a jump; call redraw() when something moved on a frame that matters. remove() puts light.shadow.autoUpdate back.
|
|
346
|
+
* @example
|
|
347
|
+
* const budget = engine.shadows.budget(sun, { every: 3 });
|
|
348
|
+
* budget.redraw(); budget.set({ every: 1 }); budget.remove();
|
|
349
|
+
* @param {any} light any three.js light with a shadow
|
|
350
|
+
* @param {{ every?: number }} [options]
|
|
351
|
+
* @returns {{ set(options: { every?: number }): void, redraw(): void, remove(): void }}
|
|
352
|
+
*/
|
|
353
|
+
budget(light, options = {}) {
|
|
354
|
+
if (!light?.isLight || !light.shadow) refuse(`${BUDGET}(light): needs a three.js light with a shadow; got ${light?.type ?? light}`);
|
|
355
|
+
if (budgets.has(light)) refuse(`${BUDGET}(light): this light has a budget already; change it with handle.set({ every }) or call handle.remove() first`);
|
|
356
|
+
const h = ownBudget(e, light, options);
|
|
357
|
+
return { set: o => h.set(o), redraw: () => h.redraw(), remove: hold(budgets, light, h) };
|
|
358
|
+
},
|
|
359
|
+
/**
|
|
360
|
+
* Change a light's shadow resolution at any time, with cascades every cascade's map: raise it for one shot, lower it from a settings menu. Before the first
|
|
361
|
+
* draw light.shadow.mapSize.set() is all it takes; after it a map exists at the old size, and three allocates on WebGL only while shadow.map is null.
|
|
362
|
+
* The cascades copied the light's size only when built, so a later change reached the nearest one at most. WebGPU's shadow node resizes its own map on every redraw.
|
|
363
|
+
* @example engine.shadows.mapSize(sun, 4096);
|
|
364
|
+
* @param {any} light any three.js light with a shadow
|
|
365
|
+
* @param {number} width pixels @param {number} [height] pixels, default width
|
|
366
|
+
* @returns {void}
|
|
367
|
+
*/
|
|
368
|
+
mapSize(light, width, height = width) {
|
|
369
|
+
if (!light?.isLight || !light.shadow) refuse(`${MAP}(light, width): needs a three.js light with a shadow; got ${light?.type ?? light}`);
|
|
370
|
+
if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) refuse(`${MAP}(light, width, height?): sizes are whole pixels above 0; got ${JSON.stringify([width, height])}`);
|
|
371
|
+
const gpu = isWebGPU(e.renderer), c = e._cascades?.light === light ? e._cascades.lights.filter(l => l !== light) : [];
|
|
372
|
+
let changed = false;
|
|
373
|
+
for (const sh of [light.shadow, ...c.map(l => l.shadow)]) {
|
|
374
|
+
if (sh.mapSize.x === width && sh.mapSize.y === height) continue;
|
|
375
|
+
sh.mapSize.set(width, height); changed = true;
|
|
376
|
+
if (!gpu) { sh.map?.dispose(); sh.map = null; }
|
|
377
|
+
}
|
|
378
|
+
if (changed) setShadowUpdate(e.renderer, e.scene, { now: true }); // a resized map is empty until redrawn (a budget)
|
|
379
|
+
},
|
|
380
|
+
/**
|
|
381
|
+
* Let cascades patch a ShaderMaterial (lights: true) of yours. Built-in lit materials need nothing.
|
|
382
|
+
* @example engine.shadows.include(myLitShaderMaterial);
|
|
383
|
+
* @param {any} material @returns {any} the material
|
|
384
|
+
*/
|
|
385
|
+
include(material) { return includeInCascades(e, material); },
|
|
386
|
+
/** three's CSM object of the cascades on now (the shadow node on WebGPURenderer); null when off @type {any} */
|
|
387
|
+
get csm() { return e._cascades ?? null; },
|
|
388
|
+
/** @internal a sky's box on the engine's own sun: the engine calling its own entry on its own placeholder @param {object} options @param {() => number} distance */
|
|
389
|
+
sunBox(options, distance) {
|
|
390
|
+
const light = e.lights.sun, h = sky = sunBox(e, light, options, distance), remove = hold(boxes, light, h);
|
|
391
|
+
return { remove() { sky = null; remove(); } };
|
|
392
|
+
},
|
|
393
|
+
/** @internal the render step, after every game hook of the frame. Budgets first: the placements read what they asked for */
|
|
394
|
+
_frame() {
|
|
395
|
+
for (const b of budgets.values()) b.frame();
|
|
396
|
+
for (const b of boxes.values()) b.frame();
|
|
397
|
+
live?.frame();
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
// describe().owned shows which of the game's own materials carry the csm patch (built-in lit types the game made are patched too; render/cascades.js)
|
|
401
|
+
ownedRow(e, 'shadow.csm', () => {
|
|
402
|
+
const g = e._cascades?.gameMaterials();
|
|
403
|
+
return g?.length ? { part: 'shadow', key: 'csm', writer: 'engine (csm patch on your built-in lit materials; recipes/45)', materials: g } : undefined;
|
|
404
|
+
});
|
|
405
|
+
}
|
package/core/sharedPoint.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Shared points: the ONE way several owners change a shared thing (time channels, the calendar rate, pause / freeze / camera holders, move speed,
|
|
2
|
-
// input gates
|
|
2
|
+
// input gates, shadows.enabled, sky.tint, post values, a game's own). One entry, one line:
|
|
3
3
|
// const h = engine.mod('time.enemies', { owner: 'bullet-time', mul: 0.35, for: 2 }); // bullet time; h.remove() ends it early
|
|
4
4
|
// ctx.mod('time.world', { mul: 0.8, layer: 'effect' }); // inside a module: owned by it, removed with it
|
|
5
5
|
// Why entries and not "write the field, remember the old value": with two effects the remembered value is wrong as soon as they end in another
|
|
@@ -19,18 +19,17 @@
|
|
|
19
19
|
// It sits above system: a cutscene or menu cannot turn back on what the player turned off; only debug overrides the player
|
|
20
20
|
// - kinds: 'number' (default) | 'value' (any data: a color, a string, a boolean; set only) | 'any' (true while anyone holds it: pause, gates)
|
|
21
21
|
// | 'top' (the latest holder is in charge: the camera) | 'one' (an exclusive slot: a second holder is shared-taken; module `provides`)
|
|
22
|
-
// - a direct three.js write of what a point drives: the engine yields (point.yieldToThree()), describe says writer 'three (engine yielded)'
|
|
23
22
|
// Plain JS stays first-class: a game's own fields and onFixed logic never need this; it is for things several owners write.
|
|
24
23
|
// The registry (engine.stacks: define / get / mod, save, timers, describe().shared) is core/stacks.js.
|
|
25
24
|
import { codedError, coded } from './errorHints.js';
|
|
26
25
|
import { DEV, warnOnce, note } from './validate.js';
|
|
27
26
|
import { callerAt } from './stackFrames.js';
|
|
28
27
|
|
|
29
|
-
/** The one layer table, lowest first. Who uses which: engine = the engine's own defaults and drivers,
|
|
28
|
+
/** The one layer table, lowest first. Who uses which: engine = the engine's own defaults and drivers, game = game code and
|
|
30
29
|
* game modules (the default), effect = temporary effects (weather, bullet time), system = cutscenes, menus, photo tools, settings = the
|
|
31
30
|
* player's settings menu (restrict only), debug = debug overrides and panels. Settings is above system so the player's restriction holds in a
|
|
32
31
|
* cutscene too (screen shake turned off stays off there); only debug can override it. */
|
|
33
|
-
export const LAYERS = { engine: 0,
|
|
32
|
+
export const LAYERS = { engine: 0, game: 200, effect: 300, system: 400, settings: 500, debug: 600 };
|
|
34
33
|
const NUM_OPS = ['set', 'add', 'mul', 'clamp'];
|
|
35
34
|
const LAYERED = new Set(['number', 'value']);
|
|
36
35
|
const KINDS = ['number', 'value', 'any', 'top', 'one'];
|
|
@@ -62,7 +61,7 @@ export function ownerArgs(a, b, fallback = 'game') {
|
|
|
62
61
|
return { owner: /** @type {string | undefined} */ (a) ?? fallback, opts: b ?? {} };
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
/** '
|
|
64
|
+
/** 'sky.flash' or 'move.speed[player]': the name a message and describe().shared use */
|
|
66
65
|
const label = (name, id) => (id == null ? name : `${name}[${id}]`);
|
|
67
66
|
|
|
68
67
|
/** One shared point. Made by engine.stacks.define; games normally only call engine.mod(name, ...) and read value(). */
|
|
@@ -75,7 +74,7 @@ export class Stack {
|
|
|
75
74
|
for (const [k, b] of [['min', min], ['max', max]]) if (typeof b !== 'number' || Number.isNaN(b)) throw codedError('shared-value', `engine.stacks.define('${name}', { ${k} }): ${k} is a number (leave it out for no bound), got ${shown(b)}`);
|
|
76
75
|
if (min > max) throw codedError('shared-value', `engine.stacks.define('${name}', { min, max }): min must be <= max, got min ${min} > max ${max}. Fix: { min: ${max}, max: ${min} }`);
|
|
77
76
|
this.min = min; this.max = max; this.save = save; this.per = per; this.onChange = onChange;
|
|
78
|
-
/** the copyable "take it over on purpose" call the conflict error offers (a
|
|
77
|
+
/** the copyable "take it over on purpose" call the conflict error offers (a module's own takeover entry); default: a set on the system layer */
|
|
79
78
|
this.manual = manual;
|
|
80
79
|
/** the settings layer may set here (key bindings: the player's rebinding replaces the game's keys, it is not a restriction) */
|
|
81
80
|
this.settingsSet = settingsSet;
|
|
@@ -83,7 +82,6 @@ export class Stack {
|
|
|
83
82
|
this._by = new Map();
|
|
84
83
|
// value memo: id -> { ver, base, v }. Movers read speed / gravity per character per step; every change goes through _changed, which bumps _ver
|
|
85
84
|
this._ver = 0; this._memo = new Map();
|
|
86
|
-
/** @internal set while someone wrote the three.js property directly: { at } */ this._yielded = null;
|
|
87
85
|
}
|
|
88
86
|
/** @internal */
|
|
89
87
|
_map(id, make) { let m = this._by.get(id ?? ''); if (!m && make) this._by.set(id ?? '', m = new Map()); return m; }
|
|
@@ -274,7 +272,6 @@ export class Stack {
|
|
|
274
272
|
const r = { value: this.value(id ?? undefined), writer: lead ? lead.owner : 'default' };
|
|
275
273
|
if (lead?.layer && LAYERED.has(this.kind)) r.layer = lead.layer;
|
|
276
274
|
if (lead?.where) r.at = lead.where;
|
|
277
|
-
if (this._yielded) Object.assign(r, { writer: 'three (engine yielded)', at: this._yielded.at ?? r.at });
|
|
278
275
|
const hiddenBelow = lead && LAYERED.has(this.kind) ? LAYERS[lead.layer] : -Infinity;
|
|
279
276
|
r.also = list.filter(e => e !== lead).map(e => {
|
|
280
277
|
const h = this._show(e);
|
|
@@ -298,17 +295,6 @@ export class Stack {
|
|
|
298
295
|
}
|
|
299
296
|
return parts.join(' ');
|
|
300
297
|
}
|
|
301
|
-
/**
|
|
302
|
-
* The hook for direct three.js writes: whoever applies this point to a three.js property found a value it did not write there (the game
|
|
303
|
-
* wrote it), so the engine stops applying it (the applier checks point.yielded) and describe says writer 'three (engine yielded)'.
|
|
304
|
-
* Not an error: three.js is always writable. reclaim() hands it back to the layers.
|
|
305
|
-
* @param {string | null} [at] where the outside write was seen, if known
|
|
306
|
-
*/
|
|
307
|
-
yieldToThree(at = null) { if (this._yielded) return; this._yielded = { at }; this._changed(); }
|
|
308
|
-
/** Hand a yielded point back to the layers (look.<part>.manual(key, false) and the like) */
|
|
309
|
-
reclaim() { if (!this._yielded) return; this._yielded = null; this._changed(); }
|
|
310
|
-
/** True while a direct three.js write holds it (see yieldToThree) */
|
|
311
|
-
get yielded() { return !!this._yielded; }
|
|
312
298
|
/** The ids that have entries (per-record points) */
|
|
313
299
|
ids() { return [...this._by.keys()].filter(k => k !== ''); }
|
|
314
300
|
/** Drop every entry */
|
package/core/stackFrames.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
// Read 'file.js:50' places out of an Error stack: where a thing was added (things.js)
|
|
1
|
+
// Read 'file.js:50' places out of an Error stack: where a thing was added (things.js) or took
|
|
2
2
|
// a shared point (sharedPoint.js: the conflict error names both sides' lines).
|
|
3
3
|
// Why one file: the two copies of the frame regex drifted apart once already (a query string after the file name, a Windows path), and a fix made in
|
|
4
4
|
// one never reached the other. Both read V8 and Firefox / Safari frame lines ("at f (http://host/src/main.js?v=1:50:7)" and "f@http://host/src/main.js:50:7").
|
|
5
5
|
import { DEV } from './validate.js';
|
|
6
6
|
const FRAME = /\(?((?:[a-z]+:\/\/[^/\s]+)?[^\s()]+?\.[cm]?[jt]sx?)(?:\?[^:\s)]*)?:(\d+):\d+\)?\s*$/i;
|
|
7
7
|
const FUNC = /^[^@\s/]*@(?=[a-z]+:\/\/)/i;
|
|
8
|
+
const NAME = /^\s*(?:at\s+(?:async\s+)?([^\s(]+(?: \[as [^\]]+\])?)\s+\(|([^@\s/]+)@)/; // V8 "at name (file" / Firefox "name@file"; none for an anonymous function
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* The frames of a stack text that name a source file, outermost call last: [{ file, line }]. file keeps its URL host (so a caller can tell engine
|
|
11
|
+
* The frames of a stack text that name a source file, outermost call last: [{ file, line, fn }]. fn: the function name, '' when anonymous. file keeps its URL host (so a caller can tell engine
|
|
11
12
|
* files from game files by path) with Windows backslashes turned into slashes.
|
|
12
|
-
* @param {string} stack @returns {{ file: string, line: number }[]}
|
|
13
|
+
* @param {string} stack @returns {{ file: string, line: number, fn: string }[]}
|
|
13
14
|
*/
|
|
14
15
|
export function stackFrames(stack) {
|
|
15
16
|
const out = [];
|
|
16
17
|
// FUNC: a Firefox / Safari line puts the function name before the URL ("add@http://..."); dropped only before a scheme, so '/@scope/' paths stay
|
|
17
|
-
for (const l of String(stack ?? '').split('\n')) { const f = FRAME.exec(l); if (f) out.push({ file: f[1].replace(FUNC, '').replace(/\\/g, '/'), line: +f[2] }); }
|
|
18
|
+
for (const l of String(stack ?? '').split('\n')) { const f = FRAME.exec(l); if (f) { const n = NAME.exec(l); out.push({ file: f[1].replace(FUNC, '').replace(/\\/g, '/'), line: +f[2], fn: n?.[1] ?? n?.[2] ?? '' }); } }
|
|
18
19
|
return out;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -22,6 +23,16 @@ export function stackFrames(stack) {
|
|
|
22
23
|
export const frameText = f => `${f.file.replace(/^[a-z]+:\/\/[^/]+\//i, '').replace(/^\/+/, '')}:${f.line}`;
|
|
23
24
|
|
|
24
25
|
const ENGINE_FRAME = /(?:engine|threedog)\/(?:core|modules|render|ui)\//; // engine code (engine.mod called from inside the engine) is skipped: `at` names the game's line
|
|
26
|
+
const ENGINE_PARTS = /^(?:core|modules|render|ui)\//;
|
|
27
|
+
// the engine's own folder as this page's server names it. Why not only the path pattern above: a page served from the engine's folder (its tests) has
|
|
28
|
+
// /core/x.js with no 'engine' in it, and a game's own core/ folder must not pass for the engine's. String work, not new URL('..', import.meta.url): a bundler reads that form as an asset
|
|
29
|
+
const engineDir = () => import.meta.url.replace(/\?.*$/, '').replace(/[^/]*\/[^/]*$/, '');
|
|
30
|
+
|
|
31
|
+
/** Is this frame file the engine's own code? @param {string} file a frame's file */
|
|
32
|
+
export function engineFile(file) {
|
|
33
|
+
const dir = engineDir();
|
|
34
|
+
return ENGINE_FRAME.test(file) || (file.startsWith(dir) && ENGINE_PARTS.test(file.slice(dir.length)));
|
|
35
|
+
}
|
|
25
36
|
|
|
26
37
|
/** 'main.js:50' of the first caller outside the engine (dev only: release builds keep no stacks) */
|
|
27
38
|
export function callerAt() {
|
|
@@ -29,6 +40,6 @@ export function callerAt() {
|
|
|
29
40
|
const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error); // stackTraceLimit is V8's (Chrome), not in the DOM typings
|
|
30
41
|
const lim = E.stackTraceLimit; E.stackTraceLimit = 14;
|
|
31
42
|
const stack = String(new Error().stack ?? ''); E.stackTraceLimit = lim;
|
|
32
|
-
const f = stackFrames(stack).find(x => !
|
|
43
|
+
const f = stackFrames(stack).find(x => !engineFile(x.file));
|
|
33
44
|
return f ? frameText(f) : null;
|
|
34
45
|
}
|
package/core/stacks.js
CHANGED
|
@@ -5,9 +5,9 @@ import { DEV, warnOnce } from './validate.js';
|
|
|
5
5
|
import { Stack } from './sharedPoint.js';
|
|
6
6
|
|
|
7
7
|
const KEYS = ['owner', 'set', 'add', 'mul', 'clamp', 'value', 'for', 'clock', 'id', 'layer'];
|
|
8
|
-
// Saved: engine /
|
|
8
|
+
// Saved: engine / game / effect entries (what the playthrough did). Not saved: system / debug (menus, cutscenes, debug: "what the
|
|
9
9
|
// screen is doing now", retaken after a load), settings (the settings module re-applies the player's choices from its own prefs)
|
|
10
|
-
const SAVED = new Set(['engine', '
|
|
10
|
+
const SAVED = new Set(['engine', 'game', 'effect']);
|
|
11
11
|
const saved = e => SAVED.has(e.layer);
|
|
12
12
|
|
|
13
13
|
/** engine.stacks: every shared point by name; engine.mod(name, o) is the one way to change one */
|
|
@@ -23,7 +23,7 @@ export class Stacks {
|
|
|
23
23
|
this._at = () => engine.clock?.now ?? 0;
|
|
24
24
|
this._hooked = false; this._hook();
|
|
25
25
|
}
|
|
26
|
-
/** @internal saves and world:remove. The registry is made before them (Engine.js: the
|
|
26
|
+
/** @internal saves and world:remove. The registry is made before them (Engine.js: the drawing parts' points exist from the first drawing part on);
|
|
27
27
|
* createServices calls this again once saves and events exist */
|
|
28
28
|
_hook() {
|
|
29
29
|
const e = this.engine;
|
|
@@ -37,7 +37,7 @@ export class Stacks {
|
|
|
37
37
|
* (true while held), 'top' (latest holder wins), 'one' (an exclusive slot; modules take theirs with `provides`).
|
|
38
38
|
* per: true = one value per record id (mod with { id }); per: 'optional' = an entry with { id } is that record's, one without is every record's
|
|
39
39
|
* (move.speed: haste on the player, mud on everyone). save: false keeps it out of saves (screen state like the camera holder).
|
|
40
|
-
* manual: the copyable takeover call the conflict error offers (a
|
|
40
|
+
* manual: the copyable takeover call the conflict error offers (a drawing part's manual()).
|
|
41
41
|
* @param {string} name @param {{ kind?: 'number' | 'value' | 'any' | 'top' | 'one', base?: any, min?: number, max?: number, per?: boolean | 'optional', save?: boolean, manual?: string, settingsSet?: boolean, onChange?: (id: string | null) => void }} [o]
|
|
42
42
|
* @returns {Stack}
|
|
43
43
|
* @example engine.stacks.define('damageTaken', { per: true, min: 0 }); engine.mod('damageTaken', { owner: 'shield', id: 'player', mul: 0.5, for: 3 });
|
|
@@ -61,7 +61,7 @@ export class Stacks {
|
|
|
61
61
|
list() { return [...this._all.keys()]; }
|
|
62
62
|
/**
|
|
63
63
|
* The one entry: change a shared point; returns a handle whose remove() ends only this owner's entry.
|
|
64
|
-
* @param {string} name @param {{ owner: string, set?: any, add?: number, mul?: number, clamp?: { min?: number, max?: number }, value?: any, for?: number, clock?: string, id?: string, layer?: 'engine' | '
|
|
64
|
+
* @param {string} name @param {{ owner: string, set?: any, add?: number, mul?: number, clamp?: { min?: number, max?: number }, value?: any, for?: number, clock?: string, id?: string, layer?: 'engine' | 'game' | 'effect' | 'system' | 'settings' | 'debug' }} o
|
|
65
65
|
* @returns {{ owner: string, remove(): void, change(value: any): boolean }} remove() ends it; change(v) rewrites its value in place (same op, layer)
|
|
66
66
|
*/
|
|
67
67
|
mod(name, o) {
|
|
@@ -79,7 +79,7 @@ export class Stacks {
|
|
|
79
79
|
if (s.per) {
|
|
80
80
|
for (const id of s.ids()) out[`${s.name}[${id}]`] = s.row(id);
|
|
81
81
|
if (s.size()) out[`${s.name}[*]`] = s.row();
|
|
82
|
-
} else if (s.size()
|
|
82
|
+
} else if (s.size()) out[s.name] = s.row();
|
|
83
83
|
}
|
|
84
84
|
return out;
|
|
85
85
|
}
|