threedog 0.7.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +411 -1
- package/README.md +8 -11
- package/core/{Animator.js → assets/Animator.js} +30 -18
- package/core/{Assets.js → assets/Assets.js} +131 -56
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +302 -0
- package/core/{assetHot.js → assets/assetHot.js} +9 -7
- package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
- package/core/{assetReport.js → assets/assetReport.js} +7 -14
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +47 -25
- package/core/{audioRules.js → audio/audioRules.js} +8 -5
- package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
- package/core/{Events.js → base/Events.js} +3 -3
- package/core/{I18n.js → base/I18n.js} +15 -12
- package/core/{Random.js → base/Random.js} +7 -4
- package/core/{Vars.js → base/Vars.js} +14 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +151 -125
- package/core/{errorHints.js → base/errorHints.js} +17 -10
- package/core/{errors.js → base/errors.js} +12 -10
- package/core/{events.generated.js → base/events.generated.js} +11 -0
- package/core/base/follows.js +26 -0
- package/core/base/math.js +66 -0
- package/core/{params.js → base/params.js} +5 -6
- package/core/base/saveValues.js +81 -0
- package/core/base/sections.js +97 -0
- package/core/base/spelling.js +32 -0
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +34 -34
- package/core/{Engine.js → engine/Engine.js} +137 -91
- package/core/{Loading.js → engine/Loading.js} +34 -5
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
- package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
- package/core/{loop.js → engine/loop.js} +88 -49
- package/core/engine/moduleSlots.js +176 -0
- package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
- package/core/engine/modules.js +503 -0
- package/core/{page.js → engine/page.js} +59 -29
- package/core/{plugins.js → engine/plugins.js} +21 -12
- package/core/{services.js → engine/services.js} +50 -40
- package/core/{startup.js → engine/startup.js} +66 -54
- package/core/{Input.js → input/Input.js} +67 -39
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/input/inputKeyboard.js +39 -0
- package/core/{inputPad.js → input/inputPad.js} +24 -3
- package/core/{inputPointer.js → input/inputPointer.js} +11 -3
- package/core/input/inputSeat.js +66 -0
- package/core/{inputTouch.js → input/inputTouch.js} +24 -7
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
- package/core/{Describe.js → inspect/Describe.js} +34 -26
- package/core/{Inspect.js → inspect/Inspect.js} +39 -10
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
- package/core/{UrlState.js → inspect/UrlState.js} +60 -24
- package/core/{catalog.js → inspect/catalog.js} +15 -8
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +4 -4
- package/core/{describeRender.js → inspect/describeRender.js} +24 -22
- package/core/{describeText.js → inspect/describeText.js} +17 -8
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/inspect/metadata.generated.js +4140 -0
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/inspect/toolDoor.js +21 -0
- package/core/inspect/valueHistory.js +35 -0
- package/core/{Ops.js → ops/Ops.js} +44 -14
- package/core/{control.js → ops/control.js} +57 -31
- package/core/ops/holds.js +140 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
- package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
- package/core/{opsFail.js → ops/opsFail.js} +5 -7
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +9 -6
- package/core/{owned.js → ops/owned.js} +33 -19
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +34 -15
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
- package/core/{Saves.js → saves/Saves.js} +171 -54
- package/core/saves/saveApply.js +312 -0
- package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
- package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
- package/core/saves/session.js +231 -0
- package/core/saves/stateReplace.js +184 -0
- package/core/{Rays.js → scene/Rays.js} +44 -30
- package/core/{Views.js → scene/Views.js} +16 -8
- package/core/{adaptive.js → scene/adaptive.js} +19 -9
- package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
- package/core/scene/compositeGround.js +72 -0
- package/core/scene/floor.js +17 -0
- package/core/{gameLights.js → scene/gameLights.js} +17 -7
- package/core/{grayMap.js → scene/grayMap.js} +8 -2
- package/core/{grid.js → scene/grid.js} +6 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/scene/ground.contract.js +14 -0
- package/core/scene/ground.js +139 -0
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/scene/pixel.js +154 -0
- package/core/scene/pixelRatio.js +167 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
- package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
- package/core/scene/stepPoses.js +60 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
- package/core/{thingOps.js → scene/thingOps.js} +25 -16
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +10 -0
- package/core/scene/view.js +161 -0
- package/core/{Batching.js → stream/Batching.js} +85 -28
- package/core/{Stream.js → stream/Stream.js} +80 -38
- package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +7 -4
- package/core/{streamSources.js → stream/streamSources.js} +14 -8
- package/core/{Commits.js → threads/Commits.js} +17 -11
- package/core/{Jobs.js → threads/Jobs.js} +25 -13
- package/core/{Threads.js → threads/Threads.js} +21 -18
- package/core/{threadPure.js → threads/threadPure.js} +7 -5
- package/core/{threadServe.js → threads/threadServe.js} +3 -3
- package/core/{Clock.js → time/Clock.js} +20 -11
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +28 -21
- package/core/{time.js → time/time.js} +32 -20
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +92 -72
- package/docs/API.md +33 -28
- package/docs/CODEMAP.md +121 -200
- package/docs/COMMANDS.md +77 -70
- package/docs/CONVENTIONS.md +167 -24
- package/docs/MIGRATING-0.8.md +171 -0
- package/docs/MIGRATING-1.0.md +101 -0
- package/docs/THREE.md +140 -38
- package/docs/api/assets.md +12 -13
- package/docs/api/audio.md +6 -5
- package/docs/api/budget.md +4 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +32 -29
- package/docs/api/characters.md +35 -24
- package/docs/api/clock.md +1 -1
- package/docs/api/collider3d.md +9 -0
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +18 -17
- package/docs/api/dialogue.md +5 -4
- package/docs/api/engine.md +58 -54
- package/docs/api/events.md +17 -6
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +6 -7
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +9 -8
- package/docs/api/interactions.md +5 -5
- package/docs/api/inventory.md +10 -10
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +10 -9
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +14 -12
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +10 -7
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +3 -3
- package/docs/api/post.md +21 -5
- package/docs/api/quests.md +7 -5
- package/docs/api/rays.md +7 -7
- package/docs/api/rigid.md +29 -19
- package/docs/api/saves.md +13 -11
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +8 -9
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +6 -8
- package/docs/api/terrainDraw.md +2 -2
- package/docs/api/timeline.md +4 -4
- package/docs/api/tools.md +27 -22
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +2 -2
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +27 -12
- package/docs/api/weatherDraw.md +4 -4
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +28 -43
- package/docs/recipes/02-npc.md +21 -23
- package/docs/recipes/03-items-pickups.md +37 -53
- package/docs/recipes/04-quests.md +5 -4
- package/docs/recipes/05-props-bake.md +34 -44
- package/docs/recipes/06-clock-events.md +31 -22
- package/docs/recipes/07-flow-scenes-pause.md +30 -32
- package/docs/recipes/08-weather-sky.md +91 -37
- package/docs/recipes/09-materials-lights-models.md +25 -39
- package/docs/recipes/10-blender-level.md +22 -11
- package/docs/recipes/11-vehicles.md +44 -24
- package/docs/recipes/12-navmesh.md +60 -15
- package/docs/recipes/13-animation.md +70 -22
- package/docs/recipes/14-custom-module.md +33 -20
- package/docs/recipes/15-perf.md +51 -28
- package/docs/recipes/16-dev-bridge.md +39 -58
- package/docs/recipes/18-world.md +49 -28
- package/docs/recipes/19-shooting-picking.md +7 -4
- package/docs/recipes/20-content-actions-save.md +55 -40
- package/docs/recipes/21-camera.md +47 -25
- package/docs/recipes/22-shop-gold.md +21 -16
- package/docs/recipes/23-ops.md +28 -24
- package/docs/recipes/26-ui-parts.md +25 -14
- package/docs/recipes/27-net.md +3 -5
- package/docs/recipes/28-terrain.md +119 -23
- package/docs/recipes/29-grid.md +3 -3
- package/docs/recipes/30-templates.md +63 -30
- package/docs/recipes/31-audio.md +7 -7
- package/docs/recipes/32-action-game.md +21 -11
- package/docs/recipes/33-stream-sources.md +6 -3
- package/docs/recipes/34-environment-lighting.md +72 -25
- package/docs/recipes/35-picture-from-reference.md +20 -23
- package/docs/recipes/36-ground-plants.md +106 -0
- package/docs/recipes/40-scene.md +18 -21
- package/docs/recipes/43-shader-patches-surfaces.md +27 -48
- package/docs/recipes/44-water-weather-hooks.md +56 -50
- package/docs/recipes/45-cascaded-shadows.md +41 -20
- package/docs/recipes/46-blender-art-route.md +9 -10
- package/docs/recipes/49-game-module-contract.md +7 -6
- package/docs/recipes/50-own-renderer.md +3 -2
- package/docs/recipes/51-capability-catalog.md +14 -8
- package/docs/recipes/52-around-the-picture.md +56 -100
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +17 -20
- package/docs/recipes/56-webgpu-tsl.md +28 -15
- package/docs/recipes/57-control.md +39 -12
- package/docs/recipes/58-input.md +15 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +30 -25
- package/docs/recipes/62-picture-code.md +129 -39
- package/docs/recipes/63-third-person-start.md +19 -5
- package/docs/recipes/64-particles.md +54 -5
- package/docs/recipes/65-swarm.md +140 -0
- package/docs/recipes/66-common-tasks.md +313 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +5 -5
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
- package/examples/{sheepisland → perf-island}/assets.js +1 -1
- package/examples/{sheepisland → perf-island}/main.js +8 -8
- package/examples/{sheepisland → perf-island}/models.js +1 -1
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
- package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/GAMEMAP.md +4 -1
- package/examples/rc2d/GAMEMAP.md +4 -3
- package/examples/rc2d/main.js +1 -3
- package/examples/rc2d/rc2d.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +6 -5
- package/examples/techniques/contact-shadows/contactShadows.js +1 -1
- package/examples/techniques/contact-shadows/main.js +1 -1
- package/examples/techniques/interior-light/main.js +1 -1
- package/examples/techniques/modular-building/README.md +7 -6
- package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +2 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +9 -7
- package/examples/world/main.js +3 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +16 -12
- package/index.js +53 -32
- package/llms.txt +11 -14
- package/modules/ambience/Ambience.js +16 -11
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +18 -16
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +5 -5
- package/modules/camera/FixedCamera.js +43 -30
- package/modules/camera/FollowCamera.js +24 -15
- package/modules/camera/RtsCamera.js +12 -11
- package/modules/camera/common.js +72 -37
- package/modules/camera/contract.js +1 -0
- package/modules/camera/pixelSnap.js +62 -0
- package/modules/characters/Character.js +166 -70
- package/modules/characters/NPC.js +84 -44
- package/modules/characters/assetModel.js +16 -12
- package/modules/characters/astar.js +48 -27
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/character.contract.js +21 -0
- package/modules/characters/contract.js +17 -3
- package/modules/characters/index.js +240 -226
- package/modules/characters/moveHelpers.js +88 -12
- package/modules/characters/mover.contract.js +14 -0
- package/modules/characters/movers/common.js +22 -18
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +18 -10
- package/modules/characters/movers/simple.js +26 -13
- package/modules/characters/movers/support.js +24 -13
- package/modules/characters/npcAvoid.js +19 -16
- package/modules/characters/npcSim.js +88 -32
- package/modules/characters/npcView.js +19 -11
- package/modules/characters/pathAsync.js +81 -29
- package/modules/characters/pathJob.js +38 -21
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +120 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/seat.js +56 -0
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/vehicle.contract.js +8 -5
- package/modules/characters/walkTo.js +40 -33
- package/modules/collision/Collision.js +69 -45
- package/modules/collision/contract.js +15 -0
- package/modules/collision/grid.js +6 -1
- package/modules/content/explain.js +2 -3
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +5 -3
- package/modules/content/index.js +132 -114
- package/modules/content/loader.js +117 -140
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +54 -17
- package/modules/content/packs.js +5 -4
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +36 -0
- package/modules/content/props.js +22 -17
- package/modules/content/rules.js +47 -61
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +80 -49
- package/modules/content/words.js +47 -0
- package/modules/debug/DebugPanel.js +14 -45
- package/modules/flow/contract.js +2 -1
- package/modules/flow/index.js +30 -16
- package/modules/gameplay/Container.js +17 -13
- package/modules/gameplay/Containers.js +23 -6
- package/modules/gameplay/Dialogue.js +93 -34
- package/modules/gameplay/Interactions.js +93 -51
- package/modules/gameplay/Inventory.js +64 -22
- package/modules/gameplay/Quests.js +146 -30
- package/modules/gameplay/boxOps.js +8 -1
- package/modules/gameplay/dialogueBubbles.js +16 -12
- package/modules/gameplay/inventoryOps.js +11 -8
- package/modules/gameplay/pickups.js +63 -37
- package/modules/gameplay/questLog.js +4 -2
- package/modules/gameplay/questSave.js +9 -4
- package/modules/gameplay/quests.contract.js +1 -1
- package/modules/grid/Grid.js +2 -2
- package/modules/grid/Layer.js +12 -8
- package/modules/grid/index.js +28 -23
- package/modules/grid/ops.js +43 -46
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +42 -57
- package/modules/hud/index.js +22 -14
- package/modules/hud/parts.js +8 -8
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +29 -31
- package/modules/level/index.js +113 -161
- package/modules/level/load.js +196 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +40 -23
- package/modules/lights/index.js +33 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +90 -0
- package/modules/music/Music.js +34 -28
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +16 -0
- package/modules/nav/index.js +180 -49
- package/modules/nav/navPath.js +45 -10
- package/modules/net/Client.js +7 -7
- package/modules/net/Host.js +7 -7
- package/modules/net/Net.js +1 -1
- package/modules/net/index.js +6 -5
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +95 -29
- package/modules/particles/effect.js +86 -32
- package/modules/particles/shaders.js +19 -1
- package/modules/photo/Photo.js +23 -23
- package/modules/rigid/RigidBodies.js +255 -89
- package/modules/rigid/Vehicles.js +17 -8
- package/modules/rigid/collider3d.contract.js +26 -0
- package/modules/rigid/ragdoll.js +298 -0
- package/modules/rigid/ragdollBones.js +209 -0
- package/modules/rigid/refresh.js +10 -0
- package/modules/rigid/sync.js +51 -20
- package/modules/settings/Settings.js +177 -61
- package/modules/settings/apply.js +20 -13
- package/modules/settings/sections.js +19 -14
- package/modules/settings/strings.js +2 -2
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +29 -22
- package/modules/sky/clouds.js +7 -7
- package/modules/sky/dome.js +33 -20
- package/modules/sky/domeLayers.js +9 -9
- package/modules/sky/environment.js +6 -6
- package/modules/sky/frame.js +19 -10
- package/modules/sky/season.js +7 -1
- package/modules/sky/shader.js +24 -25
- package/modules/sky/skyModule.js +17 -28
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +356 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +71 -59
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +14 -11
- package/modules/terrain/index.js +42 -42
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +45 -29
- package/modules/terrain/terrainGen.js +19 -12
- package/modules/terrain/terrainIsland.js +2 -2
- package/modules/terrain/terrainMesh.js +7 -6
- package/modules/terrain/terrainShape.js +8 -10
- package/modules/terrain/terrainShapeMain.js +3 -3
- package/modules/timeline/Timeline.js +83 -43
- package/modules/timeline/Tween.js +25 -19
- package/modules/timeline/shots.js +24 -17
- package/modules/triggers/index.js +95 -28
- package/modules/vegetation/Vegetation.js +34 -26
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +39 -18
- package/modules/vegetation/groundChunks.js +21 -38
- package/modules/vegetation/index.js +37 -12
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +20 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +52 -40
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +28 -23
- package/modules/world/World.js +28 -15
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +30 -17
- package/modules/world/persist.js +90 -27
- package/modules/world/pos.js +5 -5
- package/modules/world/records.js +37 -11
- package/modules/world/sim.js +78 -27
- package/modules/world/simFar.js +2 -2
- package/modules/world/state.js +43 -11
- package/modules/world/thingSource.js +20 -5
- package/modules/world/views.js +27 -14
- package/package.json +48 -7
- package/presets.js +1 -3
- package/render/PostFX.js +83 -53
- package/render/backend.js +31 -33
- package/render/cascades.js +17 -12
- package/render/cascades.tsl.js +5 -8
- package/render/daylight.js +20 -3
- package/render/detail.js +8 -7
- package/render/effects.js +28 -25
- package/render/fuse.js +3 -3
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +5 -10
- package/render/fx/library.tsl.js +11 -0
- package/render/fx/lighting.tsl.js +2 -1
- package/render/fx/nodeErrors.tsl.js +2 -2
- package/render/fx/objectOrigin.tsl.js +1 -2
- package/render/fx/particles.tsl.js +8 -6
- package/render/fx/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +30 -26
- package/render/fx/sky.tsl.js +15 -17
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +2 -2
- package/render/lighting.js +5 -3
- package/render/lightmap.js +41 -21
- package/render/lights.js +6 -6
- package/render/lit.js +24 -0
- package/render/materials.js +8 -7
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/occlusion.js +62 -15
- package/render/ownFrame.js +4 -4
- package/render/patches.js +15 -15
- package/render/postWebGL.js +15 -12
- package/render/probes.js +41 -19
- package/render/recordSweep.js +117 -0
- package/render/shaderErrors.js +10 -9
- package/render/shadowCache.tsl.js +107 -0
- package/render/shadowTypes.js +9 -0
- package/{core → render}/shadows.js +59 -13
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +336 -202
- package/types/gameplay.d.ts +254 -130
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
- package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
- package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
- package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
- package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
- package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
- package/types/generated/core/input/inputSeat.d.ts +26 -0
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
- package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
- package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
- package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
- package/types/generated/modules/calendar/Calendar.d.ts +10 -11
- package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
- package/types/generated/modules/grid/Grid.d.ts +1 -0
- package/types/generated/modules/grid/Layer.d.ts +1 -1
- package/types/generated/modules/grid/index.d.ts +3 -3
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +5 -4
- package/types/generated/modules/sky/Sky.d.ts +21 -10
- package/types/generated/modules/swarm/Swarm.d.ts +80 -0
- package/types/generated/modules/timeline/Timeline.d.ts +7 -5
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +14 -16
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +11 -7
- package/types/generated/render/PostFX.d.ts +21 -23
- package/types/generated/render/materials.d.ts +1 -0
- package/types/generated/render/occlusion.d.ts +9 -0
- package/types/generated/render/patches.d.ts +1 -0
- package/types/generated/ui/Focus.d.ts +1 -0
- package/types/generated/ui/UI.d.ts +1 -0
- package/types/nav.d.ts +47 -15
- package/types/physics.d.ts +150 -73
- package/types/pixel.d.ts +75 -0
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +48 -75
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +13 -5
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +7 -5
- package/core/assetEntry.js +0 -109
- package/core/engineCamera.js +0 -32
- package/core/ground.js +0 -104
- package/core/holds.js +0 -134
- package/core/math.js +0 -48
- package/core/moduleSlots.js +0 -100
- package/core/modules.js +0 -314
- package/core/saveApply.js +0 -210
- package/core/saveValues.js +0 -46
- package/core/session.js +0 -174
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- package/core/view.js +0 -43
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -320
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/MIGRATING-0.6.md +0 -126
- package/docs/PERF.md +0 -245
- package/docs/recipes/36-sky-ground-plants.md +0 -158
- package/docs/recipes/37-terrain-hooks.md +0 -115
- package/docs/recipes/38-environment-hooks.md +0 -67
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/47-island-snow-backdrop.md +0 -43
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/plain-picture/FINDINGS.md +0 -53
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/modules/camera/projection.js +0 -21
- /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
- /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
- /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
- /package/core/{actor.js → ops/actor.js} +0 -0
- /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
- /package/core/{saveIds.js → saves/saveIds.js} +0 -0
- /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
- /package/core/{cells.js → stream/cells.js} +0 -0
- /package/core/{streamCells.js → stream/streamCells.js} +0 -0
- /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
- /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
- /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
- /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
|
@@ -2,30 +2,35 @@
|
|
|
2
2
|
// Every step is a task in engine.loading, so the loading screen, describe().loading and `threedog loading` name the same current item.
|
|
3
3
|
// A critical asset (manifest critical: true) that fails stops start() with the reason instead of starting a broken game.
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { movedOwned } from '../ops/owned.js';
|
|
6
|
+
import { reportError } from '../base/errors.js';
|
|
6
7
|
import { asModule } from './moduleTypes.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { whenSettled } from './headlessLoad.js';
|
|
9
|
+
import { catalogSnap, catalogClaim } from '../inspect/catalog.js';
|
|
10
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
11
|
+
import { warnOnce, DEV_SERVER, fmt } from '../base/validate.js';
|
|
12
|
+
import { touchStart } from '../input/inputTouch.js';
|
|
11
13
|
import { Loading, failureText } from './Loading.js';
|
|
12
14
|
import { startHeadlessLoad } from './headlessLoad.js';
|
|
13
15
|
import * as THREE from 'three';
|
|
14
|
-
import { isWebGPU, backendName, whyNoWebGPU, firstNodeMaterial, webglOnlyOn, tier as detectTier, timerContext, rendererSwapped, compileThrough } from '
|
|
15
|
-
import { bindUniforms } from '
|
|
16
|
-
import { nameShaderErrors } from '
|
|
17
|
-
import { forcedTier
|
|
18
|
-
import { GpuTimer } from '
|
|
19
|
-
import {
|
|
16
|
+
import { isWebGPU, backendName, whyNoWebGPU, firstNodeMaterial, webglOnlyOn, tier as detectTier, timerContext, rendererSwapped, compileThrough } from '../../render/backend.js';
|
|
17
|
+
import { bindUniforms } from '../../render/engineUniforms.js';
|
|
18
|
+
import { nameShaderErrors } from '../../render/shaderErrors.js';
|
|
19
|
+
import { forcedTier } from '../scene/tier.js';
|
|
20
|
+
import { GpuTimer } from '../scene/adaptive.js';
|
|
21
|
+
import { tierRatio, carryRatio, pixelSizeOn } from '../scene/pixelRatio.js';
|
|
22
|
+
import { sceneVisitor } from '../scene/sceneDelta.js';
|
|
20
23
|
import { plugAtStart } from './plugins.js';
|
|
21
24
|
|
|
22
25
|
const DEV_STRINGS = {
|
|
23
26
|
initFailed: 'init of module {name}',
|
|
24
27
|
blocked: 'Startup blocked: {n} critical item(s) failed to load, the game cannot start:\n {list}',
|
|
25
|
-
|
|
26
|
-
disposed: 'engine.start()
|
|
28
|
+
initStalled: "Startup stalled: init() of module '{name}' has not ended after {s} s with nothing loading. Fix what it waits for, or raise engine.loading.timeoutMs if it is only slow",
|
|
29
|
+
disposed: 'engine.start(): engine.dispose() ran, so this engine will not start; a disposed engine cannot start, create a new one',
|
|
27
30
|
};
|
|
28
31
|
|
|
32
|
+
const disposedError = () => codedError('engine-disposed', DEV_STRINGS.disposed);
|
|
33
|
+
|
|
29
34
|
export const startupMethods = {
|
|
30
35
|
/**
|
|
31
36
|
* What loading is doing now: tasks with phase / error / source, view() for the summary describe().loading shows.
|
|
@@ -34,23 +39,30 @@ export const startupMethods = {
|
|
|
34
39
|
*/
|
|
35
40
|
get loading() { return this._loading ||= new Loading(this); },
|
|
36
41
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Start the game: init modules, preload, apply scenario parameters, wait until the world is ready. A second call returns the first call's Promise.
|
|
44
|
+
* dispose() rejects it at once with engine-disposed, and a start() after dispose() rejects the same way, also on an engine that had finished starting.
|
|
45
|
+
*/
|
|
46
|
+
start() {
|
|
47
|
+
this._born.start ||= performance.now(); // measure
|
|
48
|
+
// raced, not only checked after each await: what _start awaits can stay pending for good after dispose (a model, a game's init), and whoever booted the engine must still hear
|
|
49
|
+
return (this._starting ??= Promise.race([this._start(), new Promise((_, stop) => this.signal.addEventListener('abort', () => stop(disposedError()), { once: true }))]));
|
|
50
|
+
},
|
|
39
51
|
|
|
40
|
-
/** @internal stop when dispose() ran during
|
|
41
|
-
_alive(
|
|
52
|
+
/** @internal stop the rest of _start when dispose() ran during one of its awaits */
|
|
53
|
+
_alive() { if (this.disposed) throw disposedError(); },
|
|
42
54
|
|
|
43
55
|
/** @internal */
|
|
44
56
|
async _start() {
|
|
57
|
+
this._alive();
|
|
45
58
|
// Dev server only (npm run dev): if main.js forgot window.engine = engine, set it so the dev bridge and console can find the engine; leave an existing one alone (including tests with several engines)
|
|
46
59
|
if (DEV_SERVER && typeof window !== 'undefined' && !window.engine) window.engine = this;
|
|
47
|
-
this.
|
|
48
|
-
this.phase = 'loading'; // from here until the world is built: frame hooks only, no fixed step (loop.js)
|
|
60
|
+
this.phase = 'starting'; // from here until the world is built: frame hooks only, no fixed step (loop.js)
|
|
49
61
|
await this.saves.whenReady; // read the save index into memory (IndexedDB is async) so saves.list / check are synchronous afterwards
|
|
50
|
-
this._alive(
|
|
62
|
+
this._alive();
|
|
51
63
|
await this._startRenderer(); // WebGPURenderer: init (or fall back) before anything draws or compiles; WebGL: nothing to do
|
|
52
64
|
plugAtStart(this); // the plugins folder: before module init, so a module from a plugin inits with the others (plugins.js)
|
|
53
|
-
this._alive(
|
|
65
|
+
this._alive();
|
|
54
66
|
this._checkOptional(); // optional dependencies that affect gameplay are missing: warn once in dev (modules.js)
|
|
55
67
|
if (!this.headless) this._loop();
|
|
56
68
|
this.ui._check(); // a UI part name the game set but no module declared is a typo: fail now, not silently
|
|
@@ -58,7 +70,7 @@ export const startupMethods = {
|
|
|
58
70
|
const ls = this.ui.get('loading'), t0 = performance.now(), L = this.loading; // measure
|
|
59
71
|
const ms = t => Math.round(performance.now() - t); // measure
|
|
60
72
|
const timing = {}; // module name -> { init, ready } in ms (ready = time spent waiting for isReady)
|
|
61
|
-
for (const m of this.modules.values()) if (m.init) {
|
|
73
|
+
for (const m of this.modules.values()) if (m.init && !this._modBlocked.has(m.name)) { // a blocked one inits if its provider comes up (modules.js)
|
|
62
74
|
const task = L._begin(m.name, 'module', { critical: !!m.critical });
|
|
63
75
|
task.phase('build');
|
|
64
76
|
ls?.update({ progress: 0.1, text: this.t('common.preparing', { name: this.moduleName(m) }) });
|
|
@@ -66,29 +78,30 @@ export const startupMethods = {
|
|
|
66
78
|
this._setModState(m, 'initializing'); // no hooks until init succeeded (modules.js)
|
|
67
79
|
const snap = catalogSnap(this); // what init registers belongs to this module in engine.catalog()
|
|
68
80
|
const inst = this._modInst.get(m.name); // a plugin removed while init awaits: its completion must not touch a same-named newcomer (modules.js)
|
|
69
|
-
try { await asModule(this, m, () => m.init(this, this._modCtx(m, inst))); if (this._isLive(m.name, inst)) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } L._done(task); }
|
|
81
|
+
try { await L._limit(Promise.resolve(asModule(this, m, () => m.init(this, this._modCtx(m, inst)))), () => Math.max(...[...L.tasks.values()].map(x => x.at)), () => codedError('module-not-ready', fmt(DEV_STRINGS.initStalled, { name: m.name, s: String(Math.round(L.timeoutMs / 1000)) }))); if (this._isLive(m.name, inst)) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } L._done(task); }
|
|
70
82
|
catch (e) {
|
|
71
83
|
L._fail(task, e);
|
|
72
84
|
if (this._isLive(m.name, inst)) { this._setModState(m, 'failed'); this._dropTracked(m.name); } // a failed module keeps no listener on half-built state
|
|
73
85
|
// a critical module stops start() with the reason (below); any other failure is reported by severity and start() goes on
|
|
74
|
-
if (!m.critical) reportError(this, e, DEV_STRINGS.initFailed
|
|
86
|
+
if (!m.critical) reportError(this, e, fmt(DEV_STRINGS.initFailed, { name: m.name }), { module: m });
|
|
75
87
|
}
|
|
76
88
|
if (this._fatal().length) return this._blocked(this._fatal());
|
|
77
89
|
timing[m.name] = { init: ms(t) };
|
|
78
|
-
this._alive(
|
|
90
|
+
this._alive();
|
|
79
91
|
}
|
|
80
|
-
this.
|
|
92
|
+
this.phase = 'loading'; // a module installed from now on runs its init at once (modules.js)
|
|
93
|
+
this._initWaiting(); // one that was installed before the provider it waits for
|
|
81
94
|
const tp = performance.now(); // measure
|
|
82
95
|
const progress = p => ls?.update({ progress: 0.2 + p * 0.3, text: L.text() ?? this.t('common.loadingAssets') });
|
|
83
96
|
// fonts the UI picture names (ui.fonts: asset names) load with the preload, so the first menu never flashes the fallback font;
|
|
84
97
|
// an unknown name rejects here with the manifest line to add
|
|
85
98
|
await Promise.all([this.assets.preload(progress), ...this.ui.fonts.map(n => this.assets.font(n))]);
|
|
86
99
|
const preloadMs = ms(tp), tr = performance.now(); // measure
|
|
87
|
-
this._alive(
|
|
100
|
+
this._alive();
|
|
88
101
|
if (this._fatal().length) return this._blocked(this._fatal());
|
|
89
102
|
let streamMs = null; // time until the "required nearby" builds in the stream registry finished
|
|
90
103
|
await this._urlState.early(); // scenario parameters: save, position, time, weather
|
|
91
|
-
this._alive(
|
|
104
|
+
this._alive();
|
|
92
105
|
ls?.update({ progress: 0.5, text: this.t('common.generating', { name: this.t('common.world') }) });
|
|
93
106
|
await this._waitReady(timing, tr, ms, v => { streamMs = v; }, () => streamMs).catch(why => Array.isArray(why) ? this._blocked(why) : Promise.reject(why));
|
|
94
107
|
// Compile every visible material for the current lights now, behind the loading screen, instead of stalling the first frame that shows it
|
|
@@ -109,7 +122,7 @@ export const startupMethods = {
|
|
|
109
122
|
// the page's thread is idle until the GPU is done: the one-time warm-ups modules queued run now instead of in the first frame (rigid)
|
|
110
123
|
for (const f of this._whileCompiling.splice(0)) { try { f(); } catch (err) { reportError(this, err, 'warm-up while compiling', { soft: true }); } }
|
|
111
124
|
await Promise.all([compiling, post]);
|
|
112
|
-
this._alive(
|
|
125
|
+
this._alive();
|
|
113
126
|
// One hidden frame behind the loading screen: shadow depth materials, the post passes and the background quad are programs compileAsync
|
|
114
127
|
// never sees, and without this frame they compiled in the first frame the player saw (a 300 ms hitch measured)
|
|
115
128
|
if (!this.headless) { try { this._render(0); } catch (err) { reportError(this, err, 'render (warm-up frame)', { soft: true }); } }
|
|
@@ -128,11 +141,12 @@ export const startupMethods = {
|
|
|
128
141
|
this.budget.checkStartup(this.startup);
|
|
129
142
|
ls?.update({ progress: 1, text: '' }); ls?.hide();
|
|
130
143
|
this.ops.allow(() => this.events.emit('engine:ready')); // engine:ready listeners finish setting up the game; still loading for the ops guard
|
|
144
|
+
this.events.emit('state:replaced', { undone: false }); // the first state is a door too: what is derived reads it here
|
|
131
145
|
this.session._capture(); // the state engine.session.newGame() returns to: set up, nothing played yet
|
|
132
146
|
this.ui.open('title'); // the title screen, only when the game turned it on (createEngine({ ui: { title: {...} } }))
|
|
133
147
|
await this._urlState.late(); // scenario parameters: skip the cutscene, wait, align the time, then emit state:applied
|
|
134
148
|
startHeadlessLoad(this); // headless: what the game sets up after start (a species, a teleport) still loads with no step() (headlessLoad.js)
|
|
135
|
-
this._alive(
|
|
149
|
+
this._alive();
|
|
136
150
|
this.phase = 'running';
|
|
137
151
|
return this;
|
|
138
152
|
},
|
|
@@ -148,13 +162,13 @@ export const startupMethods = {
|
|
|
148
162
|
if (!isWebGPU(r)) { this._backend = { requested: 'webgl', backend: 'webgl', reason: null }; return; }
|
|
149
163
|
const forced = !!r.backend?.parameters?.forceWebGL; // the game asked for the WebGL2 backend itself: not a fallback
|
|
150
164
|
let reason = forced || (r.initialized && r.backend.isWebGPUBackend) ? null : await whyNoWebGPU();
|
|
151
|
-
this._alive(
|
|
165
|
+
this._alive();
|
|
152
166
|
if (reason && want.fallback === 'error') {
|
|
153
167
|
throw codedError('renderer-backend', `[threedog] WebGPU unavailable (${reason}) and createEngine({ fallback: 'error' }) asked not to fall back; `
|
|
154
168
|
+ "fallback: 'webgl2' runs the same renderer on WebGL2 (your TSL keeps working), 'webgl' runs WebGLRenderer (GLSL only)");
|
|
155
169
|
}
|
|
156
170
|
if (reason && want.fallback === 'webgl') this._swapToWebGL(r);
|
|
157
|
-
else if (!r.initialized) { await r.init(); this._alive(
|
|
171
|
+
else if (!r.initialized) { await r.init(); this._alive(); }
|
|
158
172
|
const backend = backendName(this.renderer);
|
|
159
173
|
// the probe said yes but three still fell back (a device lost in between): say so all the same
|
|
160
174
|
if (!forced && backend === 'webgl2') reason ??= 'three fell back to its WebGL2 backend during init()';
|
|
@@ -165,12 +179,13 @@ export const startupMethods = {
|
|
|
165
179
|
// the GPU is known only now (adapterInfo after init): the default quality follows the real device
|
|
166
180
|
if (!(this.headless && forcedTier())) {
|
|
167
181
|
const t = detectTier(this.renderer);
|
|
168
|
-
|
|
182
|
+
const was = this._deviceTier; // the device's, not engine.tier: a preset picked at install must not read as the device changing
|
|
183
|
+
if (t !== was) tierRatio(this, t);
|
|
169
184
|
// MSAA defaults from the tier too (Engine.js: antialias ?? tier !== 'low'); decided from a WebGL probe before the WebGPU
|
|
170
185
|
// adapter was known, so a low-tier device could keep MSAA on the WebGPU route (found by the WebGPU parity test). Untouched when the game
|
|
171
|
-
// chose, or changed it since. The
|
|
172
|
-
const aaDefault = this._createParams.antialias == null && this.post.antialias === (
|
|
173
|
-
if (t !==
|
|
186
|
+
// or the player chose, or changed it since. The canvas's own samples stay as made: the new value is for the post chain, when an effect runs it
|
|
187
|
+
const aaDefault = this._createParams.antialias == null && !pixelSizeOn(this) && this.post.antialias === (was !== 'low') && this.post.authoredAA === this.post.antialias;
|
|
188
|
+
if (t !== was && aaDefault) this.post.antialias = this.post.authoredAA = t !== 'low';
|
|
174
189
|
this.tier = t;
|
|
175
190
|
}
|
|
176
191
|
this.post?._sync(); // effects held by tier or backend (PostFX _held) are only known now
|
|
@@ -183,18 +198,18 @@ export const startupMethods = {
|
|
|
183
198
|
*/
|
|
184
199
|
_swapToWebGL(old) {
|
|
185
200
|
// the canvas's own MSAA as the post chain wants it, so an effect-free frame still draws straight to the canvas (PostFX active)
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
r.
|
|
201
|
+
// a transparent canvas the game asked for on its own renderer stays transparent; an engine-built one keeps the opaque WebGL default (WebGPURenderer's alpha is true by default, so it says nothing there)
|
|
202
|
+
const alpha = !this._ownsRenderer && old.alpha !== false;
|
|
203
|
+
const r = new THREE.WebGLRenderer({ canvas: old.domElement, alpha, antialias: this.post.antialias, powerPreference: 'high-performance' });
|
|
204
|
+
carryRatio(old, r, new THREE.Vector2());
|
|
189
205
|
r.shadowMap.enabled = old.shadowMap.enabled; r.shadowMap.type = old.shadowMap.type;
|
|
190
206
|
r.toneMapping = old.toneMapping; r.toneMappingExposure = old.toneMappingExposure; r.outputColorSpace = old.outputColorSpace;
|
|
191
207
|
r.setClearColor(old.getClearColor(new THREE.Color()), old.getClearAlpha());
|
|
192
208
|
r.info.autoReset = false;
|
|
193
209
|
nameShaderErrors(r); bindUniforms(r, this.uniforms);
|
|
194
210
|
try { old.dispose(); } catch { /* never initialized: nothing of it reached the GPU */ }
|
|
195
|
-
// owned rows name the renderer object they live on (tween exemptions, core/owned.js)
|
|
196
|
-
for (const row of [this._oTone, this._oPixelRatio]) if (row) row.objects = row.objects.map(o => (o === old ? r : o));
|
|
197
211
|
this.renderer = r;
|
|
212
|
+
movedOwned(this, new Map([[old, r]])); // owned rows name the renderer object they live on (tween exemptions, core/ops/owned.js)
|
|
198
213
|
// parts built for the old renderer before start(): the post chain (its backend and every effect's part), then whatever registered a rebuild
|
|
199
214
|
this.post._setBackend();
|
|
200
215
|
rendererSwapped(this);
|
|
@@ -212,7 +227,7 @@ export const startupMethods = {
|
|
|
212
227
|
+ '(the same WebGPURenderer on WebGL2: TSL keeps working), or give these objects a GLSL material too');
|
|
213
228
|
return;
|
|
214
229
|
}
|
|
215
|
-
// one visitor on the engine's "entered the scene" mechanism (core/sceneDelta.js): the whole scene now, then only what is added later,
|
|
230
|
+
// one visitor on the engine's "entered the scene" mechanism (core/scene/sceneDelta.js): the whole scene now, then only what is added later,
|
|
216
231
|
// checked each frame by _checkBackendAdds; a material swapped in (mesh.material = m) counts as an add.
|
|
217
232
|
// shortcut: an onBeforeCompile assigned to a material already in the scene is not seen; an add after it is. Upgrade if games do that.
|
|
218
233
|
const found = [];
|
|
@@ -229,7 +244,7 @@ export const startupMethods = {
|
|
|
229
244
|
const found = this._webglOnlyFound;
|
|
230
245
|
if (!found.length) return;
|
|
231
246
|
const msgs = found.splice(0);
|
|
232
|
-
for (const msg of msgs) reportError(this, codedError('renderer-backend', `[threedog] ${msg} (added after start())`), msg);
|
|
247
|
+
for (const msg of msgs) reportError(this, codedError('renderer-backend', `[threedog] ${msg} (added after start())`), msg, { soft: true }); // a picture problem: reported, gameplay carries on
|
|
233
248
|
},
|
|
234
249
|
|
|
235
250
|
/** Critical items that failed: assets, track() steps and modules declared critical: true (a non-critical module's init error goes through reportError instead) */
|
|
@@ -237,7 +252,7 @@ export const startupMethods = {
|
|
|
237
252
|
|
|
238
253
|
/** A critical item failed: keep the loading screen up with the failure, log it (errors.log in dev) and reject start() with every reason */
|
|
239
254
|
_blocked(fatal) {
|
|
240
|
-
const err = codedError(fatal.some(t => t.kind === 'module') ? 'module-critical' : 'asset-critical', DEV_STRINGS.blocked
|
|
255
|
+
const err = codedError(fatal.some(t => t.kind === 'module') ? 'module-critical' : 'asset-critical', fmt(DEV_STRINGS.blocked, { n: fatal.length, list: fatal.map(failureText).join('\n ') }));
|
|
241
256
|
this.ui.get('loading')?.update({ progress: 1, text: this.t('loading.failed', { name: fatal.map(t => t.name).join(', ') }), failed: fatal });
|
|
242
257
|
reportError(this, err, 'engine.start()', { soft: true }); // logged once (errors.log in dev), then start() rejects with it
|
|
243
258
|
throw err;
|
|
@@ -248,10 +263,9 @@ export const startupMethods = {
|
|
|
248
263
|
const ls = this.ui.get('loading');
|
|
249
264
|
return new Promise((res, rej) => {
|
|
250
265
|
let done = false;
|
|
251
|
-
const t0 = performance.now(); // measure: wall clock, so a module that never turns ready ends the wait instead of hanging
|
|
252
266
|
const check = () => {
|
|
253
267
|
if (done) return;
|
|
254
|
-
|
|
268
|
+
this._alive();
|
|
255
269
|
// Headless mode has no real-time loop: run one frame by hand (time does not advance, jobs ignore real time) so terrain and other modules keep loading
|
|
256
270
|
if (this.headless) this._frameHooks(0, true);
|
|
257
271
|
const waiting = [...this.modules.values()].filter(m => m.isReady && !m.isReady(this));
|
|
@@ -259,17 +273,15 @@ export const startupMethods = {
|
|
|
259
273
|
if (this.stream.ready && getStream() == null) setStream(ms(tr));
|
|
260
274
|
const fatal = this._fatal(); // a critical step tracked by a module can fail while we wait
|
|
261
275
|
if (fatal.length || (!waiting.length && getStream() != null)) { done = true; this._afterTick = null; if (fatal.length) rej(fatal); else res(); return; }
|
|
262
|
-
if (performance.now() - t0 > this.loading.timeoutMs) { // measure
|
|
263
|
-
done = true; this._afterTick = null;
|
|
264
|
-
const who = [...waiting.map(m => m.name), ...(this.stream.ready ? [] : ['the stream (required nearby builds)'])];
|
|
265
|
-
rej(codedError('module-not-ready', DEV_STRINGS.stalled.replace('{s}', String(Math.round(this.loading.timeoutMs / 1000))).replace('{list}', who.join(', '))));
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
276
|
ls?.update({ progress: 0.5 + 0.5 * (1 - waiting.length / this.modules.size), text: this.loading.text() ?? this.t('common.generating', { name: this.t('common.world') }) });
|
|
269
277
|
};
|
|
270
|
-
|
|
271
|
-
this._afterTick =
|
|
278
|
+
// a throw (a module's isReady) must end the wait: in a timer or a frame nothing would catch it, and start() would never settle
|
|
279
|
+
const guarded = () => { try { check(); } catch (err) { done = true; this._afterTick = null; rej(err); } };
|
|
280
|
+
const poll = () => { guarded(); if (!done) setTimeout(poll, 20); }; // main-loop: poll for readiness while loading (a dispose rejects on the next check)
|
|
281
|
+
this._afterTick = guarded;
|
|
272
282
|
poll();
|
|
283
|
+
// the limit is whenSettled's, the one every wait for "ready" has
|
|
284
|
+
if (!done) whenSettled(this, () => !done).catch(err => { if (!done) { done = true; this._afterTick = null; rej(err); } });
|
|
273
285
|
});
|
|
274
286
|
},
|
|
275
287
|
};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// - the GAME BINDS keys: createEngine({ bindings: { jump: ['Space'] } }), engine.input.bind('jump', ['Space']) or a whole preset map
|
|
7
7
|
// engine.input.bind(presets.bindings.dialogNumbers). The basics (WASD / arrows move, confirm, cancel, UI cursor) are the one default preset.
|
|
8
8
|
// - the PLAYER REBINDS: engine.input.rebind('jump', ['KeyJ']) (the settings menu calls it and saves it).
|
|
9
|
-
// Keys are the shared point 'input.keys' (core/sharedPoint.js), one record per action: the default preset is its base, the game binds on the game
|
|
9
|
+
// Keys are the shared point 'input.keys' (core/ops/sharedPoint.js), one record per action: the default preset is its base, the game binds on the game
|
|
10
10
|
// layer, the player's rebind on the settings layer (it replaces). describe().shared['input.keys[jump]'] says who bound what.
|
|
11
11
|
// Two different owners binding one action is input-bound-twice in dev (with the fix); a module's bindings and declarations go with the module.
|
|
12
12
|
// Reading an action nobody bound reports input-unbound once in dev (naming the one-line bind), unless its declaration said optional: true.
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// Gameplay (onFixed, module fixed) reads a snapshot taken at the start of each fixed step: reads within one step agree, and "just pressed" counts exactly once,
|
|
16
16
|
// never lost, whatever the frame rate. UI keys and camera (onFrame, module frame) read this frame's latest state.
|
|
17
17
|
// Contexts (inputContext.js): a stack, the top one wins. Base 'walk'; 'vehicle' passes unrelated actions through; 'dialog', 'menu', 'cutscene' are opaque.
|
|
18
|
-
// Window blur / tab hide (page:blur from core/page.js) releases every held key.
|
|
18
|
+
// Window blur / tab hide (page:blur from core/engine/page.js) releases every held key. Several engines on one page: the one last pressed or focused hears the keyboard and the gamepads (inputKeyboard.js).
|
|
19
19
|
// engine.input.label('interact') -> "E" (UI hints); engine.input.axis -> { x, y } movement direction (moveLeft/Right/Forward/Back + sticks)
|
|
20
20
|
//
|
|
21
21
|
// Mouse buttons are keys too: 'Mouse0' left / 'Mouse1' middle / 'Mouse2' right (real mouse only; touch taps do not count); gamepad buttons are 'PadA' etc.
|
|
@@ -24,15 +24,17 @@
|
|
|
24
24
|
// (click-to-move via screenToGround); clicked is true only on this frame and a drag does not count,
|
|
25
25
|
// gameplay (fire, attack) must not read it; bind a Mouse0 action instead
|
|
26
26
|
|
|
27
|
-
/** @import { Pointer, Autopilot } from '
|
|
28
|
-
import { coded, codedError } from '
|
|
29
|
-
import { checkTypeRule } from '
|
|
30
|
-
import { warnMissing, warnOnce, missingText, DEV } from '
|
|
27
|
+
/** @import { Pointer, Autopilot } from '../../types/core' */
|
|
28
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
29
|
+
import { checkTypeRule } from '../engine/moduleTypes.js';
|
|
30
|
+
import { warnMissing, warnOnce, missingText, DEV } from '../base/validate.js';
|
|
31
31
|
import { touchButton } from './inputTouch.js';
|
|
32
32
|
import { bindPointer } from './inputPointer.js';
|
|
33
|
+
import { bindKeyboard } from './inputKeyboard.js';
|
|
33
34
|
import { pollPad, keyLabel } from './inputPad.js';
|
|
35
|
+
import { Seat, moveAxis } from './inputSeat.js';
|
|
34
36
|
import { BASIC_KEYS, BASIC_LABELS, BOUND_LABELS } from './inputDefaults.js';
|
|
35
|
-
import { initContexts, pushContext, readableMap, applyContexts, BASE_CONTEXT } from './inputContext.js';
|
|
37
|
+
import { initContexts, pushContext, readableMap, applyContexts, settledStack, BASE_CONTEXT } from './inputContext.js';
|
|
36
38
|
|
|
37
39
|
const NONE = Object.freeze([]);
|
|
38
40
|
const ACTION_OPTS = ['context', 'label', 'optional', 'keys', 'owner'];
|
|
@@ -52,13 +54,15 @@ export class Input {
|
|
|
52
54
|
/** @internal */ this._fx = { keys: new Set(), pressed: new Set(), released: new Set(), x: 0, y: 0 }; // this fixed step's snapshot
|
|
53
55
|
/** @internal */ this._live = { keys: this.keys, pressed: this.justPressed, released: this.justReleased };
|
|
54
56
|
/** @internal */ this._inFixed = false;
|
|
57
|
+
/** @internal local players' seats (inputSeat.js) */ this.seats = [];
|
|
58
|
+
/** @internal frames ended so far. A press lives until endFrame, so this is what "the same press" means to ui/Focus.js, from any fixed step or frame hook */ this.frameCount = 0;
|
|
55
59
|
/** This frame's look-drag amount (pixels) and wheel notches */
|
|
56
60
|
this.look = { dx: 0, dy: 0, zoom: 0 };
|
|
57
61
|
/** Mouse/touch pointer @type {Pointer} */
|
|
58
62
|
this.pointer = { x: 0, y: 0, ndcX: 0, ndcY: 0, down: false, clicked: false, button: 0 };
|
|
59
63
|
/** Set by a camera that locks the mouse on click: true while the next mouse press would only lock it, so that press is not delivered as Mouse0 / a click @internal */
|
|
60
64
|
this.swallowLockClick = /** @type {null | (() => boolean)} */ (null);
|
|
61
|
-
/** On-screen stick (touch) */
|
|
65
|
+
/** On-screen stick (touch) @experimental */
|
|
62
66
|
this.stick = { x: 0, y: 0 };
|
|
63
67
|
/** Auto movement (stress tests, test scripts) @type {Autopilot | null} */
|
|
64
68
|
this.autopilot = null;
|
|
@@ -72,23 +76,18 @@ export class Input {
|
|
|
72
76
|
/** @internal */ this.padDeadzone = padDeadzone;
|
|
73
77
|
/** @internal */ this.padLookSpeed = padLookSpeed;
|
|
74
78
|
/** @internal */ this.padStick = { x: 0, y: 0 };
|
|
75
|
-
/** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} */
|
|
79
|
+
/** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} @experimental */
|
|
76
80
|
this.lastDevice = 'keyboard';
|
|
77
|
-
/** Is this a touch device? */
|
|
81
|
+
/** Is this a touch device? @experimental */
|
|
78
82
|
this.touch = matchMedia('(pointer: coarse)').matches;
|
|
79
83
|
/** @internal touch buttons the game asked for [{ action, labelKey }]; drawn by the UI part 'touch' (inputTouch.js) */ this._touch = [];
|
|
80
84
|
for (const a of Object.keys(BASIC_KEYS)) this.actions.set(a, { labelKey: BASIC_LABELS[a], context: BASE_CONTEXT, optional: false, by: 'engine' });
|
|
81
85
|
this.bind(bindings); // createEngine({ bindings }): the game's keys, owner 'game'
|
|
82
86
|
|
|
83
87
|
const { signal } = engine; // engine.dispose() cancels all listeners at once
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (e.code === 'Space' || e.code === 'Tab' || e.code.startsWith('Arrow')) e.preventDefault();
|
|
88
|
-
}, { signal });
|
|
89
|
-
addEventListener('keyup', e => this._keyUp(e.code), { signal });
|
|
90
|
-
// Losing focus swallows the keyup events, so release everything when the page goes away (window blur or tab hidden; core/page.js owns those listeners)
|
|
91
|
-
engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); });
|
|
88
|
+
bindKeyboard(this, canvas, signal);
|
|
89
|
+
// Losing focus swallows the keyup events, so release everything when the page goes away (window blur or tab hidden; core/engine/page.js owns those listeners)
|
|
90
|
+
engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); this._muted.clear(); this.stick.x = this.stick.y = 0; }); // a muted key's keyup and the stick's pointerup are lost the same way
|
|
92
91
|
|
|
93
92
|
bindPointer(this, canvas, signal);
|
|
94
93
|
|
|
@@ -118,17 +117,36 @@ export class Input {
|
|
|
118
117
|
+ `Rule: an action belongs to one context. Fix: give one of them another name (e.g. '${owner}.${name}'), or declare it in the same context`);
|
|
119
118
|
}
|
|
120
119
|
// a second owner declaring the same action in the same context shares the first declaration (two modules may read one 'interact')
|
|
121
|
-
const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner };
|
|
120
|
+
const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner, users: 0 };
|
|
122
121
|
if (entry !== cur) this.actions.set(name, entry);
|
|
122
|
+
entry.users++;
|
|
123
123
|
this._readable = null;
|
|
124
124
|
const bound = keys !== undefined ? this.bind(name, keys, { owner }) : null;
|
|
125
125
|
let gone = false;
|
|
126
126
|
return { name, remove: () => {
|
|
127
127
|
if (gone) return; gone = true;
|
|
128
128
|
bound?.remove();
|
|
129
|
-
if (this.actions.get(name)
|
|
129
|
+
if (--entry.users !== 0 || this.actions.get(name) !== entry) return; // a sharing owner keeps it
|
|
130
|
+
// keys someone else bound stay readable: back to an action only bound, as bind() makes it
|
|
131
|
+
if (this._keys.size(name)) this.actions.set(name, { labelKey: entry.labelKey, context: BASE_CONTEXT, optional: false, by: null }); else this.actions.delete(name);
|
|
132
|
+
this._readable = null;
|
|
130
133
|
} };
|
|
131
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* @internal A failed content load puts these actions back, declarations and the game's keys (core/base/sections.js undo): the function that does it
|
|
137
|
+
* @param {string[]} names @returns {() => void}
|
|
138
|
+
*/
|
|
139
|
+
keepActions(names) {
|
|
140
|
+
const gameKeys = n => this._keys.holders(n).find(h => h.layer === 'game' && h.owner === 'game')?.value;
|
|
141
|
+
const was = names.map(n => [n, this.actions.get(n), gameKeys(n)]);
|
|
142
|
+
return () => {
|
|
143
|
+
for (const [n, entry, keys] of was) {
|
|
144
|
+
if (gameKeys(n) !== keys) { const h = this.bind(n, keys ?? NONE); if (!keys) h.remove(); }
|
|
145
|
+
if (entry) this.actions.set(n, entry); else this.actions.delete(n);
|
|
146
|
+
}
|
|
147
|
+
this._readable = null;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
132
150
|
/**
|
|
133
151
|
* Bind keys to an action (the game's choice; owner 'game'). Takes one action or a whole map, e.g. a preset: bind(presets.bindings.rtsRotate).
|
|
134
152
|
* Binding again as the same owner replaces; a DIFFERENT owner binding the same action throws input-bound-twice in dev (release: the later wins).
|
|
@@ -147,22 +165,22 @@ export class Input {
|
|
|
147
165
|
return { owner, remove: () => { for (const h of hs) h.remove(); } };
|
|
148
166
|
}
|
|
149
167
|
keys = [].concat(keys ?? NONE);
|
|
150
|
-
if (keys.some(k => typeof k !== 'string' || !k)) throw codedError('
|
|
168
|
+
if (keys.some(k => typeof k !== 'string' || !k)) throw codedError('input-keys', `input.bind('${name}', ${JSON.stringify(keys)}): keys are key names like 'KeyE', 'Space', 'PadA', 'Mouse0'`, TypeError);
|
|
151
169
|
if (!this.actions.has(name)) this.actions.set(name, { labelKey: BOUND_LABELS[name] || name, context: BASE_CONTEXT, optional: false, by: null });
|
|
152
170
|
// checked here, before the shared point's own conflict rule, so the message talks about keys (mul / add make no sense for a key list)
|
|
153
171
|
const other = this._keys.holders(name).find(h => h.layer === 'game' && h.owner !== owner);
|
|
154
172
|
if (other && DEV) {
|
|
155
173
|
throw codedError('input-bound-twice', `input.bind('${name}'): '${other.owner}' already binds it (${other.value.join(', ') || 'no key'}${other.at ? `, ${other.at}` : ''}), now '${owner}' binds ${keys.join(', ') || 'no key'}. `
|
|
156
|
-
+ `Rule: one owner binds an action. Fix: keep one of the two
|
|
174
|
+
+ `Rule: one owner binds an action. Fix: keep one of the two binds, or bind another action name`);
|
|
157
175
|
}
|
|
158
|
-
this._readable = null;
|
|
159
176
|
return this._keys.take({ owner, id: name, set: Object.freeze([...keys]), layer: 'game' });
|
|
160
177
|
}
|
|
161
178
|
/**
|
|
162
179
|
* Touch button (appears only on touch devices); pressing it triggers the action. labelKey is the string-table key of the button text (updates when the
|
|
163
|
-
* language changes)
|
|
180
|
+
* language changes). Returns { remove() }: a module tracks it, so the button leaves with the module
|
|
181
|
+
* @param {string} action @param {string} labelKey @returns {{ remove(): void }}
|
|
164
182
|
*/
|
|
165
|
-
touchButton(action, labelKey) { touchButton(this, action, labelKey); }
|
|
183
|
+
touchButton(action, labelKey) { return touchButton(this, action, labelKey); }
|
|
166
184
|
|
|
167
185
|
/**
|
|
168
186
|
* Press (down true) or release an action from code, through the same path as a real key: tests, AI drivers, replays. Presses the action's first bound key
|
|
@@ -182,6 +200,13 @@ export class Input {
|
|
|
182
200
|
}
|
|
183
201
|
/** @internal */
|
|
184
202
|
_keyUp(code) { this._muted.delete(code); if (this.keys.delete(code)) { this.justReleased.add(code); this._accR.add(code); } }
|
|
203
|
+
/**
|
|
204
|
+
* A local player's share of the input on a shared screen: its own keys and gamepad, read like engine.input (axis, down, pressed, released). Pass it to createPlayer({ id, input }).
|
|
205
|
+
* pad: gamepad index; that pad leaves engine.input and answers the game's pad bindings here. keys: { action: keys } for this seat alone. Two seats on one pad or key throw `input-seat`.
|
|
206
|
+
* @example const two = engine.input.seat({ pad: 1, keys: { moveForward: 'KeyI', moveBack: 'KeyK', moveLeft: 'KeyJ', moveRight: 'KeyL', jump: 'KeyU' } });
|
|
207
|
+
* @param {{ pad?: number, keys?: Record<string, string | string[]> }} [opts] @returns {Seat}
|
|
208
|
+
*/
|
|
209
|
+
seat(opts = {}) { const s = new Seat(this, opts); this.seats.push(s); return s; }
|
|
185
210
|
/** @internal Called at the start of each frame: read the gamepad (runs every frame, allocates nothing) */
|
|
186
211
|
poll(dt) { pollPad(this, dt); }
|
|
187
212
|
/**
|
|
@@ -205,6 +230,7 @@ export class Input {
|
|
|
205
230
|
/**
|
|
206
231
|
* All keys bound to an action: the player's rebinding, else the game's bind, else the default preset (basics only); plus its touch button
|
|
207
232
|
* @param {string} action @returns {readonly string[]}
|
|
233
|
+
* @experimental
|
|
208
234
|
*/
|
|
209
235
|
keysOf(action) {
|
|
210
236
|
const k = this._keys.value(action, BASIC_KEYS[action] ?? null) ?? NONE, t = this._touchKeys.get(action);
|
|
@@ -229,7 +255,7 @@ export class Input {
|
|
|
229
255
|
/** Key name shown in the UI, e.g. "E" @param {string} action @returns {string} */
|
|
230
256
|
label(action) { return keyLabel(this, action); }
|
|
231
257
|
/** Which copy to read: the snapshot inside fixed steps, this frame's latest state elsewhere @internal */
|
|
232
|
-
_has(action, set) { this._known(action); if (!readableMap(this).get(action) || this._gated(action)) return false; const S = (this._inFixed ? this._fx : this._live)[set]; return
|
|
258
|
+
_has(action, set, keys = this.keysOf(action)) { this._known(action); if (!readableMap(this).get(action) || this._gated(action)) return false; const S = (this._inFixed ? this._fx : this._live)[set]; return keys.some(k => S.has(k)); }
|
|
233
259
|
/** Held (a snapshot of this step in fixed, the latest state in frame) @param {string} action @returns {boolean} */
|
|
234
260
|
down(action) { return this._has(action, 'keys'); }
|
|
235
261
|
/**
|
|
@@ -243,6 +269,7 @@ export class Input {
|
|
|
243
269
|
/**
|
|
244
270
|
* Just released (which copy is read is the same as pressed; for things like release-to-fire after charging) @param {string} action @returns {boolean}
|
|
245
271
|
* @example if (engine.input.released('fire')) shoot(charge);
|
|
272
|
+
* @experimental
|
|
246
273
|
*/
|
|
247
274
|
released(action) { return this._has(action, 'released'); }
|
|
248
275
|
/**
|
|
@@ -272,13 +299,15 @@ export class Input {
|
|
|
272
299
|
const unbound = [...this.actions.keys()].filter(n => this.isUnbound(n));
|
|
273
300
|
return { stack: this._stack.map(c => (c.owner && c.owner !== c.name ? `${c.name}(owner: ${c.owner})` : c.name)), unbound, rebound: this.rebound() };
|
|
274
301
|
}
|
|
275
|
-
/** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} */
|
|
302
|
+
/** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} @experimental */
|
|
276
303
|
get contexts() { return this._stack.map(c => c.name); }
|
|
277
304
|
/**
|
|
278
|
-
* Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read)
|
|
305
|
+
* Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read).
|
|
306
|
+
* Pushes and removes count at once, before the next fixed step applies them: on a halted page a closed window is not a holder any more
|
|
279
307
|
* @returns {{ context: string, owner: string, pass: boolean }[]}
|
|
308
|
+
* @experimental
|
|
280
309
|
*/
|
|
281
|
-
get holders() { return this.
|
|
310
|
+
get holders() { return settledStack(this).slice(1).map(c => ({ context: c.name, owner: c.owner, pass: c.pass })); }
|
|
282
311
|
/**
|
|
283
312
|
* Close one action while anyone holds its gate (stun: no jump; a tutorial: no attack yet), without a whole input context. Same rules as every
|
|
284
313
|
* engine.mod stack (it is the shared point 'input.gate', one entry per owner and action): only the owner opens it, { for } ends it by itself.
|
|
@@ -293,7 +322,7 @@ export class Input {
|
|
|
293
322
|
return this.engine.mod('input.gate', { ...o, id: action });
|
|
294
323
|
}
|
|
295
324
|
/** @internal true while someone holds this action's gate */
|
|
296
|
-
_gated(action) {
|
|
325
|
+
_gated(action) { return (this._gateStack ??= this.engine.stacks.get('input.gate')).size(action) > 0; }
|
|
297
326
|
/**
|
|
298
327
|
* False while an opaque context (menu, dialogue, cutscene...) covers gameplay: no game action can be read, and cameras ignore picture/zoom @returns {boolean}
|
|
299
328
|
*/
|
|
@@ -312,14 +341,7 @@ export class Input {
|
|
|
312
341
|
_axisInto(out) {
|
|
313
342
|
out.x = out.y = 0;
|
|
314
343
|
if (!this.enabled) return out;
|
|
315
|
-
|
|
316
|
-
if (this.down('moveForward')) y += 1;
|
|
317
|
-
if (this.down('moveBack')) y -= 1;
|
|
318
|
-
if (this.down('moveLeft')) x -= 1;
|
|
319
|
-
if (this.down('moveRight')) x += 1;
|
|
320
|
-
const l = Math.hypot(x, y); if (l > 1) { x /= l; y /= l; }
|
|
321
|
-
out.x = x; out.y = y;
|
|
322
|
-
return out;
|
|
344
|
+
return moveAxis(this, this.stick.x + this.padStick.x, this.stick.y + this.padStick.y, out);
|
|
323
345
|
}
|
|
324
346
|
/** Take the snapshot at the start of a fixed step (also while frozen, so keys pressed during a freeze do not take effect only after unfreezing) @internal */
|
|
325
347
|
beginFixed() {
|
|
@@ -329,6 +351,7 @@ export class Input {
|
|
|
329
351
|
let t = f.pressed; f.pressed = this._accP; this._accP = t; t.clear(); // swap the two copies, no allocation
|
|
330
352
|
t = f.released; f.released = this._accR; this._accR = t; t.clear();
|
|
331
353
|
this._axisInto(f);
|
|
354
|
+
for (const s of this.seats) s._axisInto(s._fx);
|
|
332
355
|
this._inFixed = true;
|
|
333
356
|
}
|
|
334
357
|
/** @internal */
|
|
@@ -336,5 +359,10 @@ export class Input {
|
|
|
336
359
|
|
|
337
360
|
|
|
338
361
|
/** @internal */
|
|
339
|
-
endFrame() { this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
|
|
362
|
+
endFrame() { this.frameCount++; this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
|
|
340
363
|
}
|
|
364
|
+
|
|
365
|
+
export const handRolled = [
|
|
366
|
+
{ kind: 'keys', seen: 'a raw keydown / keyup listener', use: "engine.input.action('jump', { label, keys }) in a module, the game binds keys with engine.input.bind (rebinding, contexts, gamepad); read engine.input.pressed(name) (recipe 58)", raw: /(?:^|[^\w.])(?:(?:window|document|self|globalThis|canvas|document\.body|[\w.]*domElement)\.)?(?:addEventListener\s*\(\s*['"]|on)key(?:down|up)\b/, yields: { kind: 'pause', raw: /['"]Escape['"]/ } },
|
|
367
|
+
{ kind: 'lock', seen: 'an input lock of its own', use: "engine.input.push('ride', { owner }) takes the keys and h.remove() gives them back: no key sticks, and describe().holds.input shows who holds them (recipe 07 §2b)", quiet: /\b(engine|e|eng|ctx)\.input\.(push|gate)\b|\blockInput\b/, code: /\b(?:let|var)\s+(?:input|controls?|keys)(?:Locked|Disabled|Enabled|Frozen)\s*=/i, tags: false },
|
|
368
|
+
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { codedError } from '
|
|
1
|
+
import { codedError } from '../base/errorHints.js';
|
|
2
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;
|
|
3
3
|
// an opaque context (the default) blocks everything below it, a `pass` context lets unrelated actions through. Menus, dialogue, cutscenes and
|
|
4
4
|
// full-screen UI push an opaque context instead of "locking input", so there is one mechanism, not two.
|
|
@@ -50,15 +50,24 @@ export function readableMap(input) {
|
|
|
50
50
|
return input._readable = m;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** Queued pushes and removes played onto a stack @internal */
|
|
54
|
+
function playQueue(q, stack) {
|
|
55
|
+
for (const op of q) {
|
|
56
|
+
if (op.add) stack.push(op.add);
|
|
57
|
+
else { const i = stack.indexOf(op.del); if (i > 0) stack.splice(i, 1); }
|
|
58
|
+
}
|
|
59
|
+
return stack;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The stack as the next fixed step will leave it: what reports read, because a halted page may wait long for that step @internal */
|
|
63
|
+
export function settledStack(input) { return playQueue(input._pendingCtx, input._stack.slice()); }
|
|
64
|
+
|
|
53
65
|
/** Apply queued push/remove at the start of a fixed step; held keys of newly blocked actions are cleared (a key stays dead until released) @internal */
|
|
54
66
|
export function applyContexts(input) {
|
|
55
67
|
const q = input._pendingCtx;
|
|
56
68
|
if (!q.length) return;
|
|
57
69
|
const before = readableMap(input);
|
|
58
|
-
|
|
59
|
-
if (op.add) input._stack.push(op.add);
|
|
60
|
-
else { const i = input._stack.indexOf(op.del); if (i > 0) input._stack.splice(i, 1); }
|
|
61
|
-
}
|
|
70
|
+
playQueue(q, input._stack);
|
|
62
71
|
q.length = 0;
|
|
63
72
|
input._readable = null;
|
|
64
73
|
const after = readableMap(input);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The keyboard part of input. A key event is the window's and a gamepad is the page's, so every engine on a page gets them, and two games side by side would both walk.
|
|
2
|
+
// One rule: the engine last pressed or focused owns the keyboard and the gamepads no seat is bound to (its canvas or anything in its uiRoot). Until then the first engine on the page does, as it would alone:
|
|
3
|
+
// a second engine appearing takes nothing away, and with a single engine nothing here ever changes who hears a key. A press elsewhere on the page moves nothing.
|
|
4
|
+
// Only a keydown is gated. A keyup always counts, and what the old owner held it lets go of at the handover: its keyup may come much later.
|
|
5
|
+
// Mouse buttons and on-screen buttons are the engine's own: those keys stay as they are. Gamepads are polled: a former owner's next poll reads no pad and lets go (inputPad.js).
|
|
6
|
+
|
|
7
|
+
const NOT_KEYBOARD = /^(Mouse|Pad|Touch:)/;
|
|
8
|
+
/** The Inputs alive on this page; the first is the owner, the one after it had the keyboard before and gets it back if the owner goes */
|
|
9
|
+
const inputs = [];
|
|
10
|
+
|
|
11
|
+
/** Does this engine.input own the keyboard and gamepads now? @internal @param {any} input */
|
|
12
|
+
export const owns = input => inputs[0] === input;
|
|
13
|
+
|
|
14
|
+
/** Is this pad bound to a seat of any engine on the page? A seat was told its pad: it hears it whoever owns the input, and the owner does not read it too @internal @param {number} i */
|
|
15
|
+
export const padSeated = i => inputs.some(input => input.seats.some(s => s.pad === i));
|
|
16
|
+
|
|
17
|
+
/** @param {any} input the engine.input that takes the keyboard */
|
|
18
|
+
function take(input) {
|
|
19
|
+
const [owner] = inputs;
|
|
20
|
+
if (owner === input) return;
|
|
21
|
+
for (const k of [...owner.keys]) if (!NOT_KEYBOARD.test(k)) owner._keyUp(k);
|
|
22
|
+
inputs.splice(inputs.indexOf(input), 1);
|
|
23
|
+
inputs.unshift(input);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Wire the keyboard to input (called once when Input is constructed). signal: engine.dispose() cancels all listeners at once @param {any} input @param {HTMLCanvasElement} canvas @param {AbortSignal} signal */
|
|
27
|
+
export function bindKeyboard(input, canvas, signal) {
|
|
28
|
+
inputs.push(input);
|
|
29
|
+
const claim = e => { if (e.target === canvas || input.engine.uiRoot.contains(e.target)) take(input); };
|
|
30
|
+
addEventListener('pointerdown', claim, { signal, capture: true }); // on the window, capturing: a game's stopPropagation must not hide the press
|
|
31
|
+
addEventListener('focusin', claim, { signal, capture: true });
|
|
32
|
+
addEventListener('keydown', e => {
|
|
33
|
+
if (!owns(input) || /INPUT|TEXTAREA|SELECT/.test(e.target.tagName)) return;
|
|
34
|
+
input._keyDown(e.code, 'keyboard');
|
|
35
|
+
if (e.code === 'Space' || e.code === 'Tab' || e.code.startsWith('Arrow')) e.preventDefault();
|
|
36
|
+
}, { signal });
|
|
37
|
+
addEventListener('keyup', e => input._keyUp(e.code), { signal });
|
|
38
|
+
signal.addEventListener('abort', () => inputs.splice(inputs.indexOf(input), 1));
|
|
39
|
+
}
|