threedog 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +71 -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 +183 -59
- 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 +37 -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 +14 -13
- package/core/gridLoad.js +2 -1
- 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 +100 -41
- 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 +63 -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 +87 -100
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +220 -147
- package/docs/COMMANDS.md +56 -35
- package/docs/CONVENTIONS.md +90 -28
- 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 +11 -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 +38 -23
- 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 +63 -60
- 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 +28 -26
- 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 +29 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +11 -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 +48 -34
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +35 -21
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +151 -15
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +40 -9
- package/docs/recipes/08-weather-sky.md +145 -36
- package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +14 -6
- package/docs/recipes/14-custom-module.md +61 -29
- package/docs/recipes/15-perf.md +30 -9
- package/docs/recipes/16-dev-bridge.md +61 -37
- package/docs/recipes/18-world.md +16 -6
- package/docs/recipes/19-shooting-picking.md +6 -6
- package/docs/recipes/20-content-actions-save.md +55 -17
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +16 -10
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +34 -1
- package/docs/recipes/29-grid.md +34 -16
- 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 +26 -3
- package/docs/recipes/35-style-from-reference.md +88 -19
- package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
- package/docs/recipes/37-terrain-look-hooks.md +3 -2
- package/docs/recipes/38-environment-look-hooks.md +37 -26
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
- package/docs/recipes/44-water-weather-look-hooks.md +26 -17
- package/docs/recipes/45-cascaded-shadows.md +16 -7
- package/docs/recipes/47-island-snow-backdrop.md +7 -7
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-look.md +197 -61
- package/docs/recipes/53-ground-up-close.md +1 -1
- 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 -14
- 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/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +17 -16
- 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 +1 -1
- 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 +44 -45
- package/index.js +26 -22
- package/llms.txt +11 -4
- 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 +177 -42
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +4 -13
- 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 +2 -1
- 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 +96 -27
- 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 +186 -110
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- 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 +8 -2
- 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 +7 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +120 -39
- 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 +614 -240
- package/types/gameplay.d.ts +482 -312
- 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 +109 -81
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +158 -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 -22
- package/docs/api/entities.md +0 -61
- 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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Headless loading after start: a headless engine (?threedog-headless, createEngine({ headless: true })) has no real-time loop, so after start()
|
|
2
|
+
// nothing runs frames unless someone calls step(). Anything that makes the world load again after start (a species added with
|
|
3
|
+
// vegetation.define, terrain.setDensity, a teleport, a level swap) queued its work and waited for frames that never came: the page sat on
|
|
4
|
+
// "waiting for module terrain" forever, while the same page in a live browser loaded within a second.
|
|
5
|
+
//
|
|
6
|
+
// Why a load pump and not "step more" in the tools: step() is synchronous, and chunk results come back from workers between tasks, so no
|
|
7
|
+
// number of steps inside one call can finish a load. Only frames spread over real time can, which is what a live loop gives. So while the
|
|
8
|
+
// world is not settled, the headless engine runs the same loading frame start() runs (frame hooks, stream, jobs; game time does not move:
|
|
9
|
+
// dt 0, jobs drain deterministically), on a timer. A settled world runs nothing, so step()-driven tests keep their exact frame count.
|
|
10
|
+
//
|
|
11
|
+
// stateApplied waits for it too (Engine.js): screenshots, npm test and the dev bridge wait on stateApplied, so a load that began after
|
|
12
|
+
// start is finished before they capture. A load that never settles stops holding stateApplied after engine.loading.timeoutMs (same limit
|
|
13
|
+
// as start()) with one warning naming who is still waiting, so a stuck module cannot hang a tool.
|
|
14
|
+
import { DEV, warnOnce } from './validate.js';
|
|
15
|
+
import { coded } from './errorHints.js';
|
|
16
|
+
|
|
17
|
+
const TICK_MS = 16; // one loading frame per ~60 Hz tick: the same pace a live loop gives the workers
|
|
18
|
+
|
|
19
|
+
/** Modules whose isReady(e) is false, plus the stream when its required nearby builds are not done ([] = settled) */
|
|
20
|
+
export function unsettled(e) {
|
|
21
|
+
const who = [];
|
|
22
|
+
for (const m of e.modules.values()) if (m.isReady && !m.isReady(e)) who.push(m.name);
|
|
23
|
+
if (!e.stream.ready) who.push('the stream (required nearby builds)');
|
|
24
|
+
return who;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @internal start(): begin pumping loading frames for a headless engine (no-op for a live one, its loop already runs frames) */
|
|
28
|
+
export function startHeadlessLoad(e) {
|
|
29
|
+
if (!e.headless || e._headlessLoad) return;
|
|
30
|
+
const s = e._headlessLoad = { since: -1, stalled: false, timer: 0 };
|
|
31
|
+
const tick = () => {
|
|
32
|
+
if (e.disposed) return;
|
|
33
|
+
if (!unsettled(e).length) { s.since = -1; s.stalled = false; }
|
|
34
|
+
else {
|
|
35
|
+
const now = performance.now(); // measure: wall clock, only to stop a stuck load from holding stateApplied forever
|
|
36
|
+
if (s.since < 0) s.since = now;
|
|
37
|
+
// the same loading frame start() runs while it waits (startup.js _waitReady): frame hooks, stream, jobs; game time stays put
|
|
38
|
+
// (no input.endFrame: a key a test pressed before its next step() must still read as just pressed there)
|
|
39
|
+
e._frameHooks(0, true);
|
|
40
|
+
if (!s.stalled && now - s.since > e.loading.timeoutMs) {
|
|
41
|
+
s.stalled = true;
|
|
42
|
+
const who = unsettled(e);
|
|
43
|
+
if (DEV && who.length) warnOnce(coded('module-not-ready', `headless load after start stalled: still waiting after ${Math.round(e.loading.timeoutMs / 1000)} s for: ${who.join(', ')}; stateApplied no longer waits for it. A module's isReady(e) keeps returning false; fix that module, or raise engine.loading.timeoutMs if the load is just slow`));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
s.timer = setTimeout(tick, TICK_MS); // main-loop: a headless engine's stand-in for the live frame loop while something is loading
|
|
47
|
+
};
|
|
48
|
+
tick();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @internal stateApplied: true when the world is settled (or its post-start load gave up after timeoutMs); always true for a live engine */
|
|
52
|
+
export function headlessSettled(e) {
|
|
53
|
+
const s = e._headlessLoad;
|
|
54
|
+
return !s || s.stalled || !unsettled(e).length;
|
|
55
|
+
}
|
package/core/holds.js
CHANGED
|
@@ -1,91 +1,102 @@
|
|
|
1
|
-
// Who holds the engine still: pause
|
|
2
|
-
//
|
|
1
|
+
// Who holds the engine still: pause, freeze (each ends with its handle's remove()), runState, and the camera takeover (takeCamera / cameraOverride).
|
|
2
|
+
// Each is a named stack (core/stacks.js: 'pause' and 'freeze' kind any, 'camera' kind top), so they follow the same owner rules as every shared quantity:
|
|
3
|
+
// engine.freeze('menu') is engine.mod('freeze', { owner: 'menu' }) with the loop's side effects added (ending the last pause restarts the loop).
|
|
4
|
+
// One entry per mechanism: the handle's remove() ends a pause / freeze (there is no engine.resume / engine.unfreeze).
|
|
3
5
|
import { warnOnce } from './validate.js';
|
|
4
|
-
import { coded
|
|
5
|
-
import { ownerArgs } from './
|
|
6
|
+
import { coded } from './errorHints.js';
|
|
7
|
+
import { ownerArgs } from './sharedPoint.js';
|
|
6
8
|
|
|
7
|
-
// pause / freeze
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
// The pause / freeze handle is { owner, remove() } only: no chaining, so a pause is ended in exactly one way.
|
|
10
|
+
function handle(owner, remove) { return { owner, remove }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The three hold stacks: 'freeze' and 'pause' (kind any), 'camera' (kind top). services.js and the test engines call this, so both get the same stacks.
|
|
14
|
+
* The pause stack does the loop side effect itself (onChange), not engine.pause(): engine.mod('pause', { owner }), engine.pause(owner), the handle's
|
|
15
|
+
* remove() and _resume(owner) are then one behavior. Making mod('pause') throw instead would leave a quantity that engine.mod names in describe
|
|
16
|
+
* but refuses to change, a special case to remember; with onChange there is no path that holds the stack without stopping the loop.
|
|
17
|
+
* @param {any} engine
|
|
18
|
+
*/
|
|
19
|
+
export function defineHoldStacks(engine) {
|
|
20
|
+
engine.stacks.define('freeze', { kind: 'any', save: false }); // who froze gameplay
|
|
21
|
+
engine.stacks.define('pause', { kind: 'any', save: false, onChange: () => { // who paused the loop; it resumes only when empty
|
|
22
|
+
if (engine.stacks.get('pause').size()) engine.paused = true;
|
|
23
|
+
else if (!engine.disposed) { engine.paused = false; engine._loop(); }
|
|
24
|
+
} });
|
|
25
|
+
engine.stacks.define('camera', { kind: 'top', save: false }); // who holds the camera; the latest is in charge (cameraOverride)
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
export const holdMethods = {
|
|
17
29
|
/**
|
|
18
30
|
* Pause the real-time loop (the picture stops and the game stops advancing). owner names who paused (default 'game'; pause({ owner }) works too): the loop
|
|
19
|
-
* stays paused until every owner has resumed, and
|
|
31
|
+
* stays paused until every owner has resumed, and _resume(owner) by someone who did not pause does not undo another owner's pause.
|
|
20
32
|
* kind tells engine.runState what the pause means: 'test' (a test or the dev bridge holds it: 'test-paused'); any other pause reads as 'paused'.
|
|
21
|
-
* Returns a handle: remove() resumes this owner
|
|
33
|
+
* Returns a handle: remove() resumes this owner.
|
|
22
34
|
* @param {string | { owner?: string, kind?: 'test' }} [owner] @param {{ kind?: 'test' }} [opts]
|
|
23
|
-
* @returns {{ owner: string, remove(): void
|
|
24
|
-
* @example const p = engine.pause('perf-test'); ... p.remove();
|
|
35
|
+
* @returns {{ owner: string, remove(): void }}
|
|
36
|
+
* @example const p = engine.pause('perf-test'); ... p.remove();
|
|
25
37
|
*/
|
|
26
38
|
pause(owner, opts) {
|
|
27
39
|
const a = ownerArgs(owner, opts);
|
|
28
|
-
const
|
|
29
|
-
this.paused
|
|
30
|
-
return
|
|
40
|
+
const P = this.stacks.get('pause');
|
|
41
|
+
P.take({ owner: a.owner, value: { kind: a.opts.kind ?? null } }); // the stack's onChange sets this.paused (defineHoldStacks), same as engine.mod('pause')
|
|
42
|
+
return handle(a.owner, () => { if (P.has(a.owner)) this._resume(a.owner); });
|
|
31
43
|
},
|
|
32
44
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* an unfreeze by a non-owner is the same no-op but quiet, because UI parts release their freeze on every close whether or not they froze).
|
|
45
|
+
* @internal The dev bridge and tests: end owner's pause (the handle's remove() calls this); with no pause held (a headless engine) it starts live running.
|
|
46
|
+
* A call by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering).
|
|
36
47
|
* @param {string | { owner?: string }} [owner]
|
|
37
48
|
*/
|
|
38
|
-
|
|
49
|
+
_resume(owner) {
|
|
39
50
|
const { owner: o } = ownerArgs(owner);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
const P = this.stacks.get('pause');
|
|
52
|
+
if (P.size() && !P.has(o)) { warnOnce(coded('pause-owner', `ending the pause of '${o}': paused by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a pause with the handle pause() returned (p.remove()), or the pause stays`)); return this; }
|
|
53
|
+
// with holders the stack's onChange restarts the loop; with none (headless start) resume itself starts it
|
|
54
|
+
if (!P.release(o) && !P.size() && !this.disposed) { this.paused = false; this._loop(); }
|
|
43
55
|
return this;
|
|
44
56
|
},
|
|
45
|
-
// Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers,
|
|
57
|
+
// Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
|
|
46
58
|
// and rendering go on, so the picture and UI stay alive.
|
|
47
59
|
// Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
|
|
48
60
|
// Unlike pause(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
|
|
49
|
-
// have unfrozen. step() obeys freezes as well. Same
|
|
61
|
+
// have unfrozen. step() obeys freezes as well. Same owner rules as every stack (core/stacks.js).
|
|
50
62
|
/**
|
|
51
63
|
* Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
64
|
+
* Ambient animation (uniforms.uTime: wind, water, clouds) keeps moving behind the freeze; ambient: true stops it too (a photo / cutscene still).
|
|
65
|
+
* Returns a handle whose remove() releases this owner's freeze. Same as engine.mod('freeze', { owner }) plus the kind.
|
|
66
|
+
* @param {string | { owner?: string, kind?: 'title', ambient?: boolean }} [owner] @param {{ kind?: 'title', ambient?: boolean }} [opts]
|
|
67
|
+
* @returns {{ owner: string, remove(): void }}
|
|
55
68
|
*/
|
|
56
69
|
freeze(owner, opts) {
|
|
57
70
|
const a = ownerArgs(owner, opts);
|
|
58
|
-
|
|
71
|
+
const h = this.stacks.get('freeze').take({ owner: a.owner, value: { kind: a.opts.kind ?? null, ambient: !!a.opts.ambient } });
|
|
72
|
+
return handle(a.owner, h.remove);
|
|
59
73
|
},
|
|
60
|
-
/** Release owner's freeze (only that owner's) @param {string | { owner?: string }} [owner] */
|
|
61
|
-
unfreeze(owner) { this._freezers.release(ownerArgs(owner).owner); return this; },
|
|
62
74
|
/** True while someone has frozen gameplay */
|
|
63
|
-
get frozen() { return this.
|
|
75
|
+
get frozen() { return this.stacks.get('freeze').value(); },
|
|
64
76
|
/**
|
|
65
77
|
* The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
|
|
66
78
|
* state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'test-paused' (only pauses of kind 'test': the bridge or a test)
|
|
67
|
-
* | 'paused' (paused or frozen by owners, listed in `
|
|
68
|
-
*
|
|
79
|
+
* | 'paused' (paused or frozen by owners, listed in `owners`) | 'running';
|
|
80
|
+
* owners: every pause and freeze owner, so closing one part's pause can be told from a player's;
|
|
69
81
|
* blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
|
|
70
82
|
* 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
|
|
71
|
-
* @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running',
|
|
83
|
+
* @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', owners: string[], blockedBy: string[] }}
|
|
72
84
|
*/
|
|
73
85
|
get runState() {
|
|
74
|
-
const P = this.
|
|
86
|
+
const P = this.stacks.get('pause'), F = this.stacks.get('freeze'), owners = [...P.names(), ...F.names()];
|
|
75
87
|
const lv = this.loading?.view();
|
|
76
|
-
const onlyTest =
|
|
77
|
-
const state = !this.ready || !lv?.done ? 'loading' : F.some(d => d.kind === 'title') ? 'title-frozen'
|
|
78
|
-
: !
|
|
79
|
-
const blockedBy = (this.input?.
|
|
88
|
+
const onlyTest = owners.length > 0 && !F.size() && !P.entries().some(d => d.value.kind !== 'test');
|
|
89
|
+
const state = !this.ready || !lv?.done ? 'loading' : F.entries().some(d => d.value.kind === 'title') ? 'title-frozen'
|
|
90
|
+
: !owners.length && !this.paused ? 'running' : !owners.length || onlyTest ? 'test-paused' : 'paused';
|
|
91
|
+
const blockedBy = (this.input?.holders ?? []).filter(h => !h.pass).map(h => h.context);
|
|
80
92
|
if (F.has('error')) blockedBy.push('error');
|
|
81
93
|
if (lv?.blocked) blockedBy.push('loading');
|
|
82
|
-
return { state,
|
|
94
|
+
return { state, owners, blockedBy };
|
|
83
95
|
},
|
|
84
96
|
|
|
85
97
|
// ---------- camera takeover ----------
|
|
86
|
-
// While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride).
|
|
87
|
-
//
|
|
88
|
-
// and releasing it hands the camera back to the previous holder (or to the rig when none is left).
|
|
98
|
+
// While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). The 'camera' stack is kind top: the latest holder
|
|
99
|
+
// is in charge, and releasing it hands the camera back to the previous holder (or to the rig when none is left), never to nobody.
|
|
89
100
|
/**
|
|
90
101
|
* Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
|
|
91
102
|
* (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
|
|
@@ -95,12 +106,29 @@ export const holdMethods = {
|
|
|
95
106
|
*/
|
|
96
107
|
takeCamera(owner, opts) {
|
|
97
108
|
const a = ownerArgs(owner, opts, undefined);
|
|
98
|
-
|
|
109
|
+
const h = this.stacks.get('camera').take({ owner: a.owner, value: { ...a.opts, owner: a.owner } });
|
|
110
|
+
return { owner: a.owner, remove: h.remove };
|
|
99
111
|
},
|
|
100
112
|
/**
|
|
101
|
-
* The camera holder in charge ({ owner, focus? }), or null. Read-only:
|
|
113
|
+
* The camera holder in charge ({ owner, focus? }), or null. Read-only: take the camera with engine.takeCamera(owner).
|
|
102
114
|
* @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
|
|
103
115
|
*/
|
|
104
|
-
get cameraOverride() { return this.
|
|
105
|
-
set cameraOverride(_v) { renamed('cameraOverride'); },
|
|
116
|
+
get cameraOverride() { return this.stacks?.get('camera').value() ?? null; },
|
|
106
117
|
};
|
|
118
|
+
|
|
119
|
+
const HOLD_STACKS = { pause: 'pause', freeze: 'freeze', camera: 'camera', debugView: 'debug.view' };
|
|
120
|
+
/**
|
|
121
|
+
* Everyone who holds something, in one place (empty parts left out): pause / freeze / camera / debugView [{ owner, at }]; input [{ context, owner,
|
|
122
|
+
* pass }] (pushed input contexts); gates { action: [owners] } (input.gate). Every other shared value is in describe().shared (core/stacks.js).
|
|
123
|
+
* Lives here, next to the hold stacks it reads, so describe() and the input-holds test use the same function (no second copy).
|
|
124
|
+
* "Why can't I move / why is time slow" is answered here without knowing which module did it.
|
|
125
|
+
*/
|
|
126
|
+
export function describeHolds(e) {
|
|
127
|
+
const out = {};
|
|
128
|
+
for (const [k, n] of Object.entries(HOLD_STACKS)) { const h = e.stacks.has(n) ? e.stacks.get(n).holders() : []; if (h.length) out[k] = h; }
|
|
129
|
+
const inp = e.input.holders; if (inp.length) out.input = inp;
|
|
130
|
+
const g = e.stacks.has('input.gate') ? e.stacks.get('input.gate') : null, gates = {};
|
|
131
|
+
for (const id of g?.ids() ?? []) if (g.size(id)) gates[id] = g.names(id);
|
|
132
|
+
if (Object.keys(gates).length) out.gates = gates;
|
|
133
|
+
return out;
|
|
134
|
+
}
|
package/core/inputContext.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { codedError } from './errorHints.js';
|
|
2
|
+
// Input contexts. Like Unity Action Maps: a stack of named groups of actions. The top context shadows lower ones that bind the same key;
|
|
2
3
|
// an opaque context (the default) blocks everything below it, a `pass` context lets unrelated actions through. Menus, dialogue, cutscenes and
|
|
3
4
|
// full-screen UI push an opaque context instead of "locking input", so there is one mechanism, not two.
|
|
4
5
|
// Changes take effect at the start of the next fixed step (before the input snapshot), so a key pressed in step N never acts in both the old and the new context.
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
/** The base context: walking around (the common names: walk, vehicle, dialog, menu, cutscene; a game may add its own) */
|
|
8
|
+
export const BASE_CONTEXT = 'walk';
|
|
7
9
|
|
|
8
10
|
/** @internal */
|
|
9
11
|
export function initContexts(input) {
|
|
@@ -14,8 +16,10 @@ export function initContexts(input) {
|
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
/** @internal */
|
|
17
|
-
export function pushContext(input, name, { pass = false } = {}) {
|
|
18
|
-
|
|
19
|
+
export function pushContext(input, name, { pass = false, owner = name } = {}) {
|
|
20
|
+
// owner: who pushed it (describe().holds.input, runState.blockedBy), so "why can't I move" names a system, not only a context
|
|
21
|
+
if (typeof owner !== 'string' || !owner) throw codedError('input-owner', `input.push('${name}', { owner }): owner must be a non-empty string, e.g. input.push('${name}', { owner: 'shop-menu' })`, TypeError);
|
|
22
|
+
const entry = { name, pass, owner };
|
|
19
23
|
let gone = false;
|
|
20
24
|
input._pendingCtx.push({ add: entry });
|
|
21
25
|
return {
|
|
@@ -29,7 +33,7 @@ export function pushContext(input, name, { pass = false } = {}) {
|
|
|
29
33
|
export function readableMap(input) {
|
|
30
34
|
if (input._readable) return input._readable;
|
|
31
35
|
const keysOf = new Map();
|
|
32
|
-
for (const [, a] of input.actions) { const c = a.context || BASE_CONTEXT; let s = keysOf.get(c); if (!s) keysOf.set(c, s = new Set()); for (const k of
|
|
36
|
+
for (const [n, a] of input.actions) { const c = a.context || BASE_CONTEXT; let s = keysOf.get(c); if (!s) keysOf.set(c, s = new Set()); for (const k of input.keysOf(n)) s.add(k); }
|
|
33
37
|
const m = new Map(), stack = input._stack;
|
|
34
38
|
for (const [name, a] of input.actions) {
|
|
35
39
|
const ctx = a.context || BASE_CONTEXT;
|
|
@@ -39,7 +43,7 @@ export function readableMap(input) {
|
|
|
39
43
|
if (c.name === ctx) { ok = true; break; }
|
|
40
44
|
if (!c.pass) break;
|
|
41
45
|
const shadow = keysOf.get(c.name);
|
|
42
|
-
if (shadow &&
|
|
46
|
+
if (shadow && input.keysOf(name).some(k => shadow.has(k))) break;
|
|
43
47
|
}
|
|
44
48
|
m.set(name, ok);
|
|
45
49
|
}
|
|
@@ -60,7 +64,7 @@ export function applyContexts(input) {
|
|
|
60
64
|
const after = readableMap(input);
|
|
61
65
|
for (const [name, was] of before) {
|
|
62
66
|
if (!was || after.get(name)) continue;
|
|
63
|
-
for (const k of input.
|
|
67
|
+
for (const k of input.keysOf(name)) {
|
|
64
68
|
if (!input.keys.has(k)) continue; // even if another action on this key becomes readable: it needs a fresh press (F that boards must not also exit)
|
|
65
69
|
input.keys.delete(k); input._accP.delete(k); input._accR.delete(k); input._muted.add(k);
|
|
66
70
|
}
|
package/core/inputDefaults.js
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Only
|
|
3
|
-
// reads it.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
export const
|
|
8
|
-
moveForward: [
|
|
9
|
-
moveBack: [
|
|
10
|
-
moveLeft: [
|
|
11
|
-
moveRight: [
|
|
12
|
-
confirm: [
|
|
13
|
-
cancel: [
|
|
14
|
-
|
|
15
|
-
//
|
|
1
|
+
// The one default key preset and its labels. Split out of Input.js.
|
|
2
|
+
// Only the basics live here: the direction axis (input.axis, the touch stick), menu confirm / cancel and the UI cursor. Every game needs them and
|
|
3
|
+
// nothing in them does anything until a game or module reads them, so they are the base value of their action (the game's bind hides it).
|
|
4
|
+
// Every other key is the game's choice: modules declare actions and their context, never keys (input.action), and the game binds them
|
|
5
|
+
// (createEngine({ bindings }), engine.input.bind, or a presets.bindings.* map). This file and presets.js are the only places in the engine that
|
|
6
|
+
// may name a key (the static check in tests/specs/input-owners.mjs).
|
|
7
|
+
export const BASIC_KEYS = Object.freeze({
|
|
8
|
+
moveForward: Object.freeze(['KeyW', 'ArrowUp']),
|
|
9
|
+
moveBack: Object.freeze(['KeyS', 'ArrowDown']),
|
|
10
|
+
moveLeft: Object.freeze(['KeyA', 'ArrowLeft']),
|
|
11
|
+
moveRight: Object.freeze(['KeyD', 'ArrowRight']),
|
|
12
|
+
confirm: Object.freeze(['Space', 'Enter', 'PadA']),
|
|
13
|
+
cancel: Object.freeze(['Escape', 'PadB']),
|
|
14
|
+
// The UI choice cursor (ui/Focus.js) moves between dialogue choices and window controls with these. Read with pressedRaw only while a window or
|
|
15
|
+
// dialogue is on top of the UI focus stack (which holds an opaque input context), so sharing WASD / arrows with walking never moves the player
|
|
16
|
+
// and the cursor at once.
|
|
17
|
+
uiUp: Object.freeze(['ArrowUp', 'KeyW', 'PadUp']),
|
|
18
|
+
uiDown: Object.freeze(['ArrowDown', 'KeyS', 'PadDown']),
|
|
19
|
+
uiLeft: Object.freeze(['ArrowLeft', 'KeyA', 'PadLeft']),
|
|
20
|
+
uiRight: Object.freeze(['ArrowRight', 'KeyD', 'PadRight']),
|
|
21
|
+
});
|
|
22
|
+
export const BASIC_LABELS = { moveForward: 'input.moveForward', moveBack: 'input.moveBack', moveLeft: 'input.moveLeft', moveRight: 'input.moveRight',
|
|
23
|
+
confirm: 'input.confirm', cancel: 'input.cancel', uiUp: 'input.uiUp', uiDown: 'input.uiDown', uiLeft: 'input.uiLeft', uiRight: 'input.uiRight' };
|
|
24
|
+
// display names for actions a game binds before the module that reads them declares its label
|
|
16
25
|
export const BOUND_LABELS = { run: 'input.run', interact: 'input.interact', jump: 'input.jump' };
|
|
17
|
-
// Default gamepad keys for the neutral menu actions only (confirm / cancel / menu): added when the action is registered (override in createEngine({ padBindings
|
|
18
|
-
// })).
|
|
19
|
-
// Gameplay actions (jump, run, interact, inventory...) get pad keys the same way as keyboard keys: from the game or a preset (presets.player.*, presets.keys.*)
|
|
20
|
-
export const PAD_DEFAULTS = { confirm: 'PadA', cancel: 'PadB', menu: 'PadStart' };
|
|
21
|
-
const STRINGS = { redefine: 'Input action "{action}" defined twice: it already had keys {from}, now {to}; the later definition overrides. Ignore this if the change is intended; to change only the label, pass the same keys' };
|
|
22
|
-
export const fmtRedefine = (action, from, to) => STRINGS.redefine.replace('{action}', action).replace('{from}', from.join(', ')).replace('{to}', to.join(', '));
|
package/core/inputPad.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Gamepad
|
|
1
|
+
// Gamepad buttons. Standard layout names; like keyboard key names they can go into action bindings
|
|
2
2
|
const PAD_BUTTONS = ['PadA', 'PadB', 'PadX', 'PadY', 'PadLB', 'PadRB', 'PadLT', 'PadRT', 'PadSelect', 'PadStart', 'PadL3', 'PadR3', 'PadUp', 'PadDown', 'PadLeft', 'PadRight'];
|
|
3
3
|
|
|
4
4
|
/** Read the first connected gamepad into the input's keys, stick and look (every frame, allocates nothing) @internal */
|
package/core/inputPointer.js
CHANGED
|
@@ -43,6 +43,6 @@ export function bindPointer(input, canvas, signal) {
|
|
|
43
43
|
};
|
|
44
44
|
canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
|
|
45
45
|
// if the right button is bound to an action, do not show the browser menu
|
|
46
|
-
canvas.addEventListener('contextmenu', e => { if ([...input.actions.
|
|
46
|
+
canvas.addEventListener('contextmenu', e => { if ([...input.actions.keys()].some(n => input.keysOf(n).includes('Mouse2'))) e.preventDefault(); }, { signal });
|
|
47
47
|
canvas.addEventListener('wheel', e => { e.preventDefault(); input.look.zoom += Math.sign(e.deltaY); }, { passive: false, signal });
|
|
48
48
|
}
|
package/core/inputTouch.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function touchButton(inp, action, labelKey) {
|
|
15
15
|
if (!inp.touch || inp._touch.some(b => b.action === action)) return;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
inp._touchKeys.set(action, 'Touch:' + action); // kept beside the bound keys, so a rebind never drops the on-screen button
|
|
17
|
+
inp._readable = null;
|
|
18
18
|
inp._touch.push({ action, labelKey });
|
|
19
19
|
touchRefresh(inp);
|
|
20
20
|
}
|
package/core/lifecycle.js
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
|
-
// Engine lifecycle
|
|
1
|
+
// Engine lifecycle: dispose() and counts() for leak hunting.
|
|
2
|
+
//
|
|
3
|
+
// Part of Engine (mixed into Engine.prototype).
|
|
2
4
|
//
|
|
3
5
|
// Who cleans up what:
|
|
4
6
|
// - DOM listeners: attach to engine.signal (an AbortController); dispose aborts them all at once. Modules and games adding their own window / document listeners do the same:
|
|
5
7
|
// addEventListener('resize', fn, { signal: engine.signal })
|
|
6
8
|
// - UI elements: the engine and modules build UI under engine.uiRoot, removed as a whole on dispose; do not attach to document.body directly.
|
|
7
|
-
// - Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations: core clears them all
|
|
9
|
+
// - Events, onFixed / onFrame, clock timers, jobs, stream, ray registrations: core clears them all here. A module registers its own through
|
|
10
|
+
// ctx.track (modules.js), so they also leave when its install rolls back or its init fails, and go before its dispose hook runs.
|
|
8
11
|
// - Things core does not know about (Worker, physics world, Audio nodes, real-time timers): clean up in the module's dispose(e) hook, called in reverse install order.
|
|
9
12
|
// - GPU memory: every geometry, material and texture in the scene, the assets cache, the post composer, then renderer.dispose().
|
|
10
13
|
// Level changes do not come through here: things inside a level register with level.track(handle), and the level removes them itself on change.
|
|
11
14
|
|
|
12
|
-
import { coded } from './errorHints.js';
|
|
15
|
+
import { coded, codedError } from './errorHints.js';
|
|
16
|
+
import { dropOwned } from './owned.js';
|
|
17
|
+
import { reportError } from './errors.js';
|
|
18
|
+
import { releaseContext, memory } from '../render/backend.js';
|
|
19
|
+
import { dropPlainTerms } from '../render/terms.js';
|
|
20
|
+
|
|
21
|
+
/** The per-step / per-frame callback lists (onFixed, onFrame, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
22
|
+
export function clearHooks(e) {
|
|
23
|
+
e._fixed = []; e._fixedLate = []; e._frame = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)',
|
|
27
|
+
released: 'createEngine(): this canvas lost its WebGL context in an earlier engine.dispose(), so a new engine cannot draw on it; use a new canvas, or dispose the old engine with dispose({ keepContext: true })',
|
|
28
|
+
opts: 'engine.dispose(opts): opts is { keepContext?: boolean }; got {v}' };
|
|
13
29
|
|
|
14
|
-
|
|
30
|
+
// Canvases whose context dispose() released: a lost context cannot host a new renderer, so createEngine on one fails loudly instead of drawing black
|
|
31
|
+
const released = new WeakSet();
|
|
32
|
+
/** createEngine calls it before building its renderer on a canvas */
|
|
33
|
+
export function checkCanvasUsable(canvas) { if (canvas && released.has(canvas)) throw codedError('canvas-released', STRINGS.released); }
|
|
15
34
|
|
|
16
35
|
/** Dispose the geometry, materials and material textures used by an object */
|
|
17
36
|
function disposeObject(o) {
|
|
@@ -26,25 +45,42 @@ export const lifecycleMethods = {
|
|
|
26
45
|
/**
|
|
27
46
|
* Destroy the engine: stop the main loop, call each module's dispose(e) in reverse install order, then clean up core (listeners, timers, sound, UI, GPU memory).
|
|
28
47
|
* No callbacks fire afterwards and engine.disposed becomes true. Safe to call repeatedly.
|
|
48
|
+
* The engine's own renderer also gives its WebGL context back (renderer.forceContextLoss): browsers keep only about 16 live contexts, so a page that
|
|
49
|
+
* creates and disposes engines (level editor, tests, restart) would otherwise lose the oldest one. That canvas cannot host a new engine afterwards;
|
|
50
|
+
* keepContext: true keeps the context for a new engine on the same canvas. A renderer the game passed in (createEngine({ renderer })) is never released.
|
|
51
|
+
* @param {{ keepContext?: boolean }} [opts]
|
|
29
52
|
*/
|
|
30
|
-
dispose() {
|
|
53
|
+
dispose(opts = {}) {
|
|
54
|
+
if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', STRINGS.opts.replace('{v}', JSON.stringify(opts)));
|
|
31
55
|
if (this.disposed) return;
|
|
32
|
-
this.
|
|
56
|
+
this.phase = 'disposed'; this.paused = true;
|
|
33
57
|
cancelAnimationFrame(this._raf);
|
|
58
|
+
dropOwned(this, [...(this._owned?.values() ?? [])]); // owned.js keeps a page-wide list for allowOwned
|
|
34
59
|
for (const m of [...this.modules.values()].reverse()) {
|
|
35
60
|
this._modState.set(m.name, 'disposed');
|
|
61
|
+
this._dropTracked(m.name); // its listeners / timers go first, so nothing calls into the module while its dispose tears it down
|
|
36
62
|
if (!m.dispose) continue;
|
|
37
|
-
try { m.dispose(this); } catch (err) {
|
|
63
|
+
try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', STRINGS.failed.replace('{name}', m.name)), { soft: true }); }
|
|
38
64
|
}
|
|
39
65
|
this._abort.abort();
|
|
66
|
+
this._untrackValidate();
|
|
67
|
+
this._wraps?.dispose(); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
|
|
40
68
|
this.debug.dispose(); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
|
|
41
|
-
for (const part of [this.saves, this.audio, this.
|
|
42
|
-
this.
|
|
69
|
+
for (const part of [this.saves, this.audio, this.time, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
|
|
70
|
+
this._roomEnv?.dispose(); this._roomEnv = null;
|
|
71
|
+
clearHooks(this); this._afterTick = null;
|
|
43
72
|
this.scene.traverse(disposeObject);
|
|
44
|
-
|
|
73
|
+
// scene.environment is never disposed here: the engine's own maps (sky PMREM targets, the baseline room map) were freed above by their
|
|
74
|
+
// owners, and anything else is the game's texture (look.env.replace(myTexture) or a direct write), which stays the game's to free
|
|
75
|
+
this.scene.environment = null;
|
|
76
|
+
if (this.scene.background?.isTexture) this.scene.background.dispose();
|
|
45
77
|
this.assets.dispose();
|
|
46
78
|
this.post.dispose();
|
|
79
|
+
this._webglOnlyView?.remove(); this._webglOnlyView = null;
|
|
80
|
+
dropPlainTerms(this);
|
|
81
|
+
this._gpu?.dispose();
|
|
47
82
|
this.renderer.dispose();
|
|
83
|
+
if (this._ownsRenderer && !opts.keepContext) { releaseContext(this.renderer); released.add(this.renderer.domElement); }
|
|
48
84
|
this.ui._dispose();
|
|
49
85
|
this._materials.remove();
|
|
50
86
|
this._uiStyle.remove();
|
|
@@ -57,9 +93,9 @@ export const lifecycleMethods = {
|
|
|
57
93
|
* Each installed module with a counts(e) hook adds its own field under its name, e.g. world { records, views }, rigid (body count), particles { alive, emitters }, sky { timers }.
|
|
58
94
|
*/
|
|
59
95
|
counts() {
|
|
60
|
-
const mem = this.renderer
|
|
96
|
+
const mem = memory(this.renderer);
|
|
61
97
|
const c = {
|
|
62
|
-
listeners: this.events.size, fixed: this._fixed.length, frame: this._frame.length, timers: this.
|
|
98
|
+
listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length, timers: this.time.size,
|
|
63
99
|
statics: this.rays.statics.size, streamEntries: this.stream.entries.size, jobs: this.jobs.pending, commits: this.commits.pending,
|
|
64
100
|
geometries: mem.geometries, textures: mem.textures,
|
|
65
101
|
};
|
package/core/lightWatch.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// Cost: one array-length compare per frame; the scene walk that counts lights runs only in a frame whose program count went up (rare).
|
|
6
6
|
import { warnOnce } from './validate.js';
|
|
7
7
|
import { coded } from './errorHints.js';
|
|
8
|
+
import { programCount } from '../render/backend.js';
|
|
8
9
|
|
|
9
10
|
const MANY = 8; // above this many real-time lights every material's fragment shader loops over all of them: mobile GPUs slow down first
|
|
10
11
|
|
|
@@ -14,7 +15,7 @@ const STRINGS = {
|
|
|
14
15
|
changed: 'Shader programs were compiled during play ({from} -> {to}) and, compared with the last observation, the light layout also changed ({was} -> {now}). ' +
|
|
15
16
|
'three.js compiles every material again for a new light setup, so adding, removing or hiding a light mid-game freezes a frame. ' +
|
|
16
17
|
'Use engine.use(lightPool({ point: 8 })) and engine.lightPool.add(torch, {...}) for many lights, or fade a fixed set with intensity ' +
|
|
17
|
-
'(recipes/09-style
|
|
18
|
+
'(recipes/09-style.md "Lights and stalls")',
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
/** Visible lights by the kinds three.js counts in its light setup (ambient and probes do not change programs), as one comparable string */
|
|
@@ -28,16 +29,17 @@ export function lightSetup(scene) {
|
|
|
28
29
|
return `point ${point}, spot ${spot}, directional ${dir}, hemisphere ${hemi}, rect ${rect}`;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
/** Lights
|
|
32
|
+
/** Lights not kept at a fixed count. A module that holds a fixed set of lights and moves them around (a light pool: the recommended fix) marks
|
|
33
|
+
* each with userData.fixedCount = true; core reads the mark, not a module's naming scheme, so any pool, built-in or the game's, counts the same */
|
|
32
34
|
function countLoose(scene) {
|
|
33
35
|
let c = 0;
|
|
34
|
-
scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.
|
|
36
|
+
scene.traverseVisible(o => { if (o.isLight && !o.isAmbientLight && !o.isLightProbe && !o.userData.fixedCount) c++; });
|
|
35
37
|
return c;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
/** @param {any} e the engine (dev and ready only: the caller checks) */
|
|
39
41
|
export function watchLights(e) {
|
|
40
|
-
const n = e.renderer
|
|
42
|
+
const n = programCount(e.renderer);
|
|
41
43
|
if (n == null) return;
|
|
42
44
|
const first = !e._lightWatch;
|
|
43
45
|
const w = e._lightWatch ??= { n, lights: lightSetup(e.scene) };
|