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
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
// Gamepad buttons. Standard layout names; like keyboard key names they can go into action bindings
|
|
2
|
+
import { owns, padSeated } from './inputKeyboard.js';
|
|
3
|
+
|
|
2
4
|
const PAD_BUTTONS = ['PadA', 'PadB', 'PadX', 'PadY', 'PadLB', 'PadRB', 'PadLT', 'PadRT', 'PadSelect', 'PadStart', 'PadL3', 'PadR3', 'PadUp', 'PadDown', 'PadLeft', 'PadRight'];
|
|
3
5
|
|
|
4
|
-
/**
|
|
6
|
+
/** The pads seats own, each into its seat's keys ('PadA@1') and stick. No look: a shared screen has one camera */
|
|
7
|
+
function pollSeats(input, pads) {
|
|
8
|
+
const z = input.padDeadzone, cut = v => Math.abs(v) < z ? 0 : v;
|
|
9
|
+
for (const s of input.seats) {
|
|
10
|
+
if (s.pad === undefined) continue;
|
|
11
|
+
const gp = pads?.[s.pad];
|
|
12
|
+
if (!gp?.connected) {
|
|
13
|
+
s.padStick.x = s.padStick.y = 0;
|
|
14
|
+
if (s._padOn) { s._padOn = false; for (const b of PAD_BUTTONS) input._keyUp(`${b}@${s.pad}`); }
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
s._padOn = true;
|
|
18
|
+
const btns = gp.buttons;
|
|
19
|
+
for (let i = 0; i < btns.length && i < PAD_BUTTONS.length; i++) { const k = `${PAD_BUTTONS[i]}@${s.pad}`; if (btns[i].pressed) input._keyDown(k, 'pad'); else input._keyUp(k); }
|
|
20
|
+
s.padStick.x = cut(gp.axes[0] || 0); s.padStick.y = -cut(gp.axes[1] || 0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Read the first connected gamepad no seat owns into the input's keys, stick and look (every frame; without seats it allocates nothing). An engine that does not own the input reads no unbound pad, which releases what it held @internal */
|
|
5
25
|
export function pollPad(input, dt) {
|
|
6
26
|
const pads = navigator.getGamepads?.();
|
|
27
|
+
if (input.seats.length) pollSeats(input, pads);
|
|
7
28
|
let gp = null;
|
|
8
|
-
if (pads) for (let i = 0; i < pads.length && !gp; i++) if (pads[i]?.connected) gp = pads[i];
|
|
29
|
+
if (pads && owns(input)) for (let i = 0; i < pads.length && !gp; i++) if (pads[i]?.connected && !padSeated(i)) gp = pads[i];
|
|
9
30
|
if (!gp) {
|
|
10
31
|
input.padStick.x = input.padStick.y = 0;
|
|
11
32
|
if (input._padOn) { input._padOn = false; for (const b of PAD_BUTTONS) input._keyUp(b); } // disconnected (battery died): release what it held, once
|
|
@@ -30,6 +51,6 @@ export function keyLabel(input, action) {
|
|
|
30
51
|
const pad = keys.filter(k => k.startsWith('Pad')), kb = keys.filter(k => !k.startsWith('Pad'));
|
|
31
52
|
const use = input.lastDevice === 'pad' && pad.length ? pad : kb.length ? kb : pad;
|
|
32
53
|
// Key names go through the string table too (key.Space -> its localized name); fall back to the generic form if missing
|
|
33
|
-
const name = k => input.engine.i18n
|
|
54
|
+
const name = k => input.engine.i18n.has('key.' + k) ? input.engine.t('key.' + k) : keyName(k);
|
|
34
55
|
return use.map(name).filter((v, i, arr) => arr.indexOf(v) === i).join('/');
|
|
35
56
|
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
// The mouse / touch pointer part of input: drag to look, wheel to zoom, pointer state; mouse buttons act as keys (Mouse0 left / Mouse1 middle / Mouse2 right) passed to Input's _keyDown / _keyUp,
|
|
2
2
|
// the same path as the keyboard, so they can be defined as actions and enter the fixed-step snapshot. Touch taps are not mouse buttons (pointerType only accepts 'mouse').
|
|
3
3
|
|
|
4
|
+
/** e.button -> its bit in e.buttons (middle and right are the other way round) */
|
|
5
|
+
const BUTTON_BITS = [1, 4, 2, 8, 16];
|
|
6
|
+
|
|
4
7
|
/** Wire pointer events on the canvas to input (called once when Input is constructed). signal: engine.dispose() cancels all listeners at once */
|
|
5
8
|
export function bindPointer(input, canvas, signal) {
|
|
6
9
|
let drag = null;
|
|
10
|
+
// A second button pressed or released while another is held fires no pointerdown / pointerup, only a pointermove with e.button set (chorded
|
|
11
|
+
// buttons), and pointerup comes for the last button alone: e.buttons is the one true list. A shooter's aim + fire needs it, and a Mouse0 stuck down is the other half
|
|
12
|
+
const chord = e => { if (e.pointerType === 'mouse') BUTTON_BITS.forEach((bit, b) => { if (e.buttons & bit) input._keyDown('Mouse' + b, 'keyboard'); else input._keyUp('Mouse' + b); }); };
|
|
7
13
|
// pointer x / y are pixels from the canvas content box's top-left, ndc is -1..1 across that box: a canvas in a page section or editor
|
|
8
14
|
// panel picks the thing under the mouse, not the thing under the same window position. Read on every event (the canvas may have moved)
|
|
9
15
|
const place = e => {
|
|
10
|
-
|
|
16
|
+
// clientWidth counts padding, and pixelSize leaves up to k real pixels of it at the right and bottom, where the picture does not reach (core/scene/pixelRatio.js)
|
|
17
|
+
const st = canvas.style, p = input.pointer, b = canvas.getBoundingClientRect();
|
|
18
|
+
const w = (canvas.clientWidth || b.width || 1) - (parseFloat(st.paddingRight) || 0), h = (canvas.clientHeight || b.height || 1) - (parseFloat(st.paddingBottom) || 0);
|
|
11
19
|
p.x = e.clientX - b.left - canvas.clientLeft; p.y = e.clientY - b.top - canvas.clientTop;
|
|
12
20
|
p.ndcX = p.x / w * 2 - 1; p.ndcY = -(p.y / h) * 2 + 1;
|
|
13
21
|
};
|
|
@@ -24,8 +32,8 @@ export function bindPointer(input, canvas, signal) {
|
|
|
24
32
|
if (document.pointerLockElement !== canvas) canvas.setPointerCapture(e.pointerId);
|
|
25
33
|
}, { signal });
|
|
26
34
|
canvas.addEventListener('pointermove', e => {
|
|
27
|
-
const p = input.pointer;
|
|
28
35
|
place(e);
|
|
36
|
+
if (e.button >= 0 && drag && !drag.swallowed) chord(e); // -1 on a plain move
|
|
29
37
|
if (!drag || drag.id !== e.pointerId) return;
|
|
30
38
|
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
|
|
31
39
|
if (document.pointerLockElement === canvas) return;
|
|
@@ -39,7 +47,7 @@ export function bindPointer(input, canvas, signal) {
|
|
|
39
47
|
drag = null;
|
|
40
48
|
if (swallowed) return;
|
|
41
49
|
input.pointer.down = false;
|
|
42
|
-
|
|
50
|
+
chord(e);
|
|
43
51
|
};
|
|
44
52
|
canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
|
|
45
53
|
// if the right button is bound to an action, do not show the browser menu
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// A seat: one local player's share of the keyboard and gamepads, on a shared screen. It reads like engine.input (axis, down, pressed, released), through the same key sets,
|
|
2
|
+
// fixed-step snapshot and contexts, so a control function can't tell them apart. Only the routing differs: a seat hears its own keys and its own pad, nothing else.
|
|
3
|
+
// A pad's buttons come in as 'PadA@1' (inputPad.js), so a seat with a pad uses the game's pad bindings without binding anything itself, and that pad leaves engine.input.
|
|
4
|
+
import { readParams, keysSchema } from '../base/params.js';
|
|
5
|
+
import { codedError } from '../base/errorHints.js';
|
|
6
|
+
|
|
7
|
+
const SEAT_PARAMS = keysSchema(['pad', 'keys']);
|
|
8
|
+
|
|
9
|
+
/** A stick's (x, y) plus the four move actions as src reads them, at most length 1, into out: engine.input and a seat add up alike @internal */
|
|
10
|
+
export function moveAxis(src, x, y, out) {
|
|
11
|
+
if (src.down('moveForward')) y += 1;
|
|
12
|
+
if (src.down('moveBack')) y -= 1;
|
|
13
|
+
if (src.down('moveLeft')) x -= 1;
|
|
14
|
+
if (src.down('moveRight')) x += 1;
|
|
15
|
+
const l = Math.hypot(x, y); if (l > 1) { x /= l; y /= l; }
|
|
16
|
+
out.x = x; out.y = y;
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class Seat {
|
|
21
|
+
/** @param {any} input engine.input @param {{ pad?: number, keys?: Record<string, string | string[]> }} opts */
|
|
22
|
+
constructor(input, opts) {
|
|
23
|
+
readParams('engine.input.seat()', SEAT_PARAMS, opts);
|
|
24
|
+
const { pad, keys = {} } = opts;
|
|
25
|
+
if (pad !== undefined && !(Number.isInteger(pad) && pad >= 0)) throw codedError('input-seat', `engine.input.seat(): pad is a gamepad index (0, 1, ...), got ${JSON.stringify(pad)}`);
|
|
26
|
+
/** @internal */ this.input = input;
|
|
27
|
+
/** The gamepad index this seat owns, if any @type {number | undefined} */ this.pad = pad;
|
|
28
|
+
/** Who this seat acts for, as engine.actor for engine.input: createPlayer sets the player's id; interactions read it. Set it to hand the seat to a vehicle or a squad member @type {string | null} */ this.actor = null;
|
|
29
|
+
/** @internal action -> this seat's keyboard keys */ this.own = new Map(Object.entries(keys).map(([a, k]) => [a, [k].flat()]));
|
|
30
|
+
for (const s of input.seats) {
|
|
31
|
+
if (pad !== undefined && s.pad === pad) throw codedError('input-seat', `engine.input.seat(): pad ${pad} already has a seat; give each seat its own pad`);
|
|
32
|
+
for (const list of this.own.values()) for (const k of list) if ([...s.own.values()].some(l => l.includes(k))) throw codedError('input-seat', `engine.input.seat(): key ${k} already belongs to another seat`);
|
|
33
|
+
}
|
|
34
|
+
/** @internal the pad's stick, written by pollPad */ this.padStick = { x: 0, y: 0 };
|
|
35
|
+
/** @internal */ this._padOn = false;
|
|
36
|
+
/** @internal the axis of this fixed step */ this._fx = { x: 0, y: 0 };
|
|
37
|
+
}
|
|
38
|
+
/** Same list as engine.input.actions: actions are the game's, a seat only routes them */
|
|
39
|
+
get actions() { return this.input.actions; }
|
|
40
|
+
/** The keys that count for an action on this seat: its own, and the game's pad keys on its pad @internal */
|
|
41
|
+
_keysOf(action) {
|
|
42
|
+
const own = this.own.get(action) ?? [];
|
|
43
|
+
if (this.pad === undefined) return own;
|
|
44
|
+
return [...own, ...this.input.keysOf(action).filter(k => k.startsWith('Pad')).map(k => `${k}@${this.pad}`)];
|
|
45
|
+
}
|
|
46
|
+
/** Held, as engine.input.down @param {string} action @returns {boolean} */
|
|
47
|
+
down(action) { return this.input._has(action, 'keys', this._keysOf(action)); }
|
|
48
|
+
/** Just pressed, as engine.input.pressed @param {string} action @returns {boolean} */
|
|
49
|
+
pressed(action) { return this.input._has(action, 'pressed', this._keysOf(action)); }
|
|
50
|
+
/** Just released, as engine.input.released @param {string} action @returns {boolean} */
|
|
51
|
+
released(action) { return this.input._has(action, 'released', this._keysOf(action)); }
|
|
52
|
+
/** Movement direction, as engine.input.axis @returns {{ x: number, y: number }} */
|
|
53
|
+
get axis() {
|
|
54
|
+
if (!this.input.enabled) return { x: 0, y: 0 };
|
|
55
|
+
return this.input._inFixed ? { x: this._fx.x, y: this._fx.y } : this._axisInto({ x: 0, y: 0 });
|
|
56
|
+
}
|
|
57
|
+
/** @internal */
|
|
58
|
+
_axisInto(out) { return moveAxis(this, this.padStick.x, this.padStick.y, out); }
|
|
59
|
+
/** Give the keys and pad back: the pad goes to engine.input again if no other seat holds it */
|
|
60
|
+
remove() {
|
|
61
|
+
const I = this.input, at = I.seats.indexOf(this);
|
|
62
|
+
if (at < 0) return;
|
|
63
|
+
I.seats.splice(at, 1);
|
|
64
|
+
for (const k of [...I.keys]) if (k.endsWith(`@${this.pad}`)) I._keyUp(k);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -2,21 +2,38 @@
|
|
|
2
2
|
// Drawing is the UI part 'touch' (default ui/touchPart.js); a game replaces it or turns it off with createEngine({ ui: { touch: ... } }).
|
|
3
3
|
// press / release go to Input's _keyDown / _keyUp as the key 'Touch:<action>', the same path as real keys (snapshot and just-pressed behave identically).
|
|
4
4
|
/** @import { Input } from './Input.js' */
|
|
5
|
-
/** @import { TouchView } from '
|
|
5
|
+
/** @import { TouchView } from '../../types/core' */
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Touch button: registers the key 'Touch:<action>' on the action and asks the touch part to draw a button (touch devices only)
|
|
9
9
|
* @param {Input} inp
|
|
10
10
|
* @param {string} action
|
|
11
11
|
* @param {string} labelKey string-table key of the button text
|
|
12
|
+
* @returns {{ remove(): void }}
|
|
12
13
|
* @internal
|
|
13
14
|
*/
|
|
14
15
|
export function touchButton(inp, action, labelKey) {
|
|
15
|
-
if (!inp.touch
|
|
16
|
-
|
|
17
|
-
inp.
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (!inp.touch) return { remove() {} };
|
|
17
|
+
// counted: two parties may ask for one action, and the button stays until the last of them leaves
|
|
18
|
+
let b = inp._touch.find(x => x.action === action);
|
|
19
|
+
if (!b) {
|
|
20
|
+
inp._touchKeys.set(action, 'Touch:' + action); // kept beside the bound keys, so a rebind never drops the on-screen button
|
|
21
|
+
inp._readable = null;
|
|
22
|
+
inp._touch.push(b = { action, labelKey, users: 0 });
|
|
23
|
+
touchRefresh(inp);
|
|
24
|
+
}
|
|
25
|
+
b.users++;
|
|
26
|
+
let held = true;
|
|
27
|
+
return { remove() {
|
|
28
|
+
if (!held) return;
|
|
29
|
+
held = false;
|
|
30
|
+
if (--b.users) return;
|
|
31
|
+
inp._keyUp('Touch:' + action); // a thumb on it when it goes must not leave the action down
|
|
32
|
+
inp._touchKeys.delete(action);
|
|
33
|
+
inp._readable = null;
|
|
34
|
+
inp._touch.splice(inp._touch.indexOf(b), 1);
|
|
35
|
+
touchRefresh(inp);
|
|
36
|
+
} };
|
|
20
37
|
}
|
|
21
38
|
|
|
22
39
|
/**
|
|
@@ -34,7 +51,7 @@ export function touchStart(inp) {
|
|
|
34
51
|
function touchRefresh(inp) {
|
|
35
52
|
if (!inp._touchOn) return;
|
|
36
53
|
const stick = inp.joystick === true || (inp.joystick === 'auto' && inp.touch);
|
|
37
|
-
if (!stick && !inp._touch.length) return;
|
|
54
|
+
if (!stick && !inp._touch.length && !inp._touchPart) return; // a drawn part still hears that its last button left
|
|
38
55
|
const e = inp.engine, first = !inp._touchPart;
|
|
39
56
|
inp._touchPart ??= e.ui.get('touch');
|
|
40
57
|
/** @type {TouchView} */
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
// Categories: drawCalls, triangles, textures, cpuMs, fps, low1 (fps and low1 are lower bounds) + registered metrics (lights, shadowLights, shadowMaps, shadowMapSize, chunkApplyMs, rigidBodies...)
|
|
6
6
|
// + the apply-cost stages (applyTransitMs, applyBuildMs, applyColliderMs, applyUploadMs, applyStreamMs: ms per frame, see ApplyCost).
|
|
7
7
|
// "Who uses the most": draw calls are estimated by the userData.budgetTag of an object (or its parent); untagged counts as 'other'.
|
|
8
|
-
/** @import { Handle } from '
|
|
9
|
-
/** @import { BudgetLimits, BudgetReport, BudgetTagStat } from '
|
|
10
|
-
import { coded } from '
|
|
11
|
-
import { fmt, warnOnce } from '
|
|
12
|
-
import { r1 } from '
|
|
13
|
-
import { SHADOW_TYPES } from '
|
|
8
|
+
/** @import { Handle } from '../../types/common' */
|
|
9
|
+
/** @import { BudgetLimits, BudgetReport, BudgetTagStat } from '../../types/world' */
|
|
10
|
+
import { coded } from '../base/errorHints.js';
|
|
11
|
+
import { fmt, warnOnce } from '../base/validate.js';
|
|
12
|
+
import { r1 } from '../base/math.js';
|
|
13
|
+
import { SHADOW_TYPES } from '../../render/shadowTypes.js';
|
|
14
14
|
import * as THREE from 'three';
|
|
15
|
-
import { stats, shadowMaps } from '
|
|
15
|
+
import { stats, shadowMaps } from '../../render/backend.js';
|
|
16
16
|
|
|
17
17
|
const STRINGS = {
|
|
18
18
|
startup: 'Startup took {value} ms, over budget startupMs {limit} ms; slowest module: {top}',
|
|
@@ -28,14 +28,6 @@ const STAGES = ['transit', 'build', 'collider', 'upload', 'stream'];
|
|
|
28
28
|
const EMA = 0.1; // per-frame smoothing, the same factor chunkApplyMs always used
|
|
29
29
|
const COMPILES_KEPT = 20; // compile-stall frames remembered by ApplyCost.compiles
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* engine.budget.cost: where the main thread pays for background results (terrain chunks, vegetation, colliders, stream builds), split in stages.
|
|
33
|
-
* Always on (a few performance.now() calls per applied result). Stages: transit = worker round trip minus the worker's own compute (queueing,
|
|
34
|
-
* structured clone, waiting for a busy main thread: an async wait, not main-thread blocking, so it is an approximation); build = creating the
|
|
35
|
-
* three.js objects (geometry, meshes, instanced meshes); collider = physics colliders; upload = GPU upload and shader compile, approximated as the
|
|
36
|
-
* extra render time of frames that first draw new objects over the average render time of other frames; stream = the synchronous part of a stream
|
|
37
|
-
* build() callback.
|
|
38
|
-
*/
|
|
39
31
|
/** Bytes of the typed arrays in a plain result object, `depth` levels down @param {any} v @param {number} depth @returns {number} */
|
|
40
32
|
function arrayBytes(v, depth) {
|
|
41
33
|
if (ArrayBuffer.isView(v)) return v.byteLength;
|
|
@@ -45,7 +37,15 @@ function arrayBytes(v, depth) {
|
|
|
45
37
|
return n;
|
|
46
38
|
}
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
/**
|
|
41
|
+
* engine.budget.cost: where the main thread pays for background results (terrain chunks, vegetation, colliders, stream builds), split in stages.
|
|
42
|
+
* Always on (a few performance.now() calls per applied result). Stages: transit = worker round trip minus the worker's own compute (queueing,
|
|
43
|
+
* structured clone, waiting for a busy main thread: an async wait, not main-thread blocking, so it is an approximation); build = creating the
|
|
44
|
+
* three.js objects (geometry, meshes, instanced meshes); collider = physics colliders; upload = GPU upload and shader compile, approximated as the
|
|
45
|
+
* extra render time of frames that first draw new objects over the average render time of other frames; stream = the synchronous part of a stream
|
|
46
|
+
* build() callback.
|
|
47
|
+
*/
|
|
48
|
+
class ApplyCost {
|
|
49
49
|
/** @internal */
|
|
50
50
|
constructor() {
|
|
51
51
|
/** @internal */ this.t = {};
|
|
@@ -110,7 +110,7 @@ export class Budget {
|
|
|
110
110
|
/** @internal */ this.engine = engine;
|
|
111
111
|
/** Is it on? */
|
|
112
112
|
this.enabled = false;
|
|
113
|
-
/** Current limits @type {BudgetLimits} */
|
|
113
|
+
/** Current limits @type {BudgetLimits} @experimental */
|
|
114
114
|
this.limits = {};
|
|
115
115
|
/** @internal Module-defined categories: name -> { read, limit } @type {Map<string, { read: () => number, limit?: number }>} */
|
|
116
116
|
this.metrics = new Map();
|
|
@@ -131,7 +131,7 @@ export class Budget {
|
|
|
131
131
|
* @example engine.budget.enable({ drawCalls: 250, fps: 55 });
|
|
132
132
|
*/
|
|
133
133
|
enable(limits = {}) { this.enabled = true; this.limits = { ...limits }; this._dts = []; this._cpu = []; this._last = null; return this; }
|
|
134
|
-
/** Turn off */
|
|
134
|
+
/** Turn off @experimental */
|
|
135
135
|
disable() { this.enabled = false; this._last = null; }
|
|
136
136
|
/**
|
|
137
137
|
* Module-defined category: read() returns the current value, opts.limit is the limit (the game's enable() takes precedence). Returns a handle { remove() }
|
|
@@ -145,13 +145,13 @@ export class Budget {
|
|
|
145
145
|
this.metrics.set(name, m);
|
|
146
146
|
return { remove: () => { if (this.metrics.get(name) === m) this.metrics.delete(name); } };
|
|
147
147
|
}
|
|
148
|
-
/** Limit of a category; undefined if none was given (not checked) @param {string} name @returns {number | undefined} */
|
|
148
|
+
/** Limit of a category; undefined if none was given (not checked) @param {string} name @returns {number | undefined} @experimental */
|
|
149
149
|
limitOf(name) { return this.limits[name] ?? this.metrics.get(name)?.limit; }
|
|
150
150
|
|
|
151
151
|
/** @internal Called by the engine after each rendered frame: records frame time, checks once a second, and warns once per category over its limit */
|
|
152
152
|
sample(dt) {
|
|
153
153
|
if (!this.enabled) return;
|
|
154
|
-
this._dts.push(dt); this._cpu.push(this.engine.
|
|
154
|
+
this._dts.push(dt); this._cpu.push(this.engine._cpuMs ?? 0);
|
|
155
155
|
if (this._dts.length > WINDOW) { this._dts.shift(); this._cpu.shift(); }
|
|
156
156
|
if ((this._t += dt) < 1) return;
|
|
157
157
|
this._t = 0;
|
|
@@ -170,6 +170,7 @@ export class Budget {
|
|
|
170
170
|
* Called by the engine when startup finishes: warns if startupMs / moduleMs is exceeded and returns the offenders (empty array if none)
|
|
171
171
|
* @param {{ totalMs: number, modules: Record<string, { init?: number, ready?: number }> }} s
|
|
172
172
|
* @returns {{ category: 'startupMs' | 'moduleMs', value: number, limit: number, top: { tag: string, ms: number }[] }[]}
|
|
173
|
+
* @experimental
|
|
173
174
|
*/
|
|
174
175
|
checkStartup(s) {
|
|
175
176
|
if (!this.enabled) return [];
|
|
@@ -6,11 +6,16 @@
|
|
|
6
6
|
// One chain: every material / visibility change, from override() and from a view, is an entry in this._l. Removing any entry undoes the whole chain
|
|
7
7
|
// in reverse and re-applies the rest in order, so a view and an override on the same mesh can never restore each other's stale material, and nothing
|
|
8
8
|
// here disposes a material it did not create (stand-ins are cached on the original, so the original is never touched).
|
|
9
|
-
import {
|
|
9
|
+
import { MeshBasicMaterial } from 'three';
|
|
10
|
+
import { allowOwned } from '../ops/owned.js';
|
|
11
|
+
import { reportError } from '../base/errors.js';
|
|
12
|
+
import { codedError } from '../base/errorHints.js';
|
|
10
13
|
import { DebugView } from './debugView.js';
|
|
11
|
-
import { isWebGPU, webgpuPart } from '
|
|
12
|
-
import { reloadGlsl } from '
|
|
13
|
-
import { reloadAssets } from '
|
|
14
|
+
import { isWebGPU, webgpuPart } from '../../render/backend.js';
|
|
15
|
+
import { reloadGlsl } from '../../render/hotGlsl.js';
|
|
16
|
+
import { reloadAssets } from '../assets/assetHot.js';
|
|
17
|
+
import { hex } from './MaterialInfo.js';
|
|
18
|
+
import { isUnder } from '../base/util.js';
|
|
14
19
|
|
|
15
20
|
const KEYS = ['visible', 'material', 'apply'];
|
|
16
21
|
const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is internal: it needs patch.colorOf
|
|
@@ -19,18 +24,19 @@ const MATERIALS = ['flat', 'wire']; // 'cost' (the shaderCost view) is interna
|
|
|
19
24
|
function meshes(obj) { const out = []; obj.traverse(o => { if (o.isMesh || o.isPoints || o.isLine) out.push(o); }); return out; }
|
|
20
25
|
const patchInfo = p => ({ ...p, ...(p.apply && { apply: 'function' }) });
|
|
21
26
|
/** A value in describe(): plain data as is, a three.js object by its type (describe() stays JSON) */
|
|
22
|
-
const plain = v => (v === null || typeof v !== 'object' ? v : v.isColor ?
|
|
27
|
+
const plain = v => (v === null || typeof v !== 'object' ? v : v.isColor ? hex(v) : `<${v.type ?? 'object'}>`);
|
|
23
28
|
|
|
24
29
|
export class DebugOverrides {
|
|
25
30
|
/** @internal */
|
|
26
31
|
constructor(e) {
|
|
27
32
|
/** @internal */ this.e = e;
|
|
28
33
|
/** @internal the override chain, in apply order */ this._l = [];
|
|
34
|
+
/** @internal material -> { kind: stand-in } */ this._stands = new WeakMap();
|
|
29
35
|
/** @internal */ this._view = new DebugView(e, this);
|
|
30
36
|
/** The F3 debug panel (the debug() module), or null when it is not installed @type {any} */
|
|
31
37
|
this.panel = null;
|
|
32
38
|
// a load can replace the objects a thing id names: an override still holding the old object would show on nothing and lie in describe
|
|
33
|
-
e.events?.on?.('
|
|
39
|
+
e.events?.on?.('state:replaced', () => this._prune());
|
|
34
40
|
}
|
|
35
41
|
/**
|
|
36
42
|
* Diagnostic view: 'albedo' | 'lighting' | 'shadow' | 'normals' to look at one part of the render, 'overdraw' (bright = many layers on a pixel),
|
|
@@ -63,10 +69,21 @@ export class DebugOverrides {
|
|
|
63
69
|
* Asset hot swap: register the asset packs again (the new module of an edited assets.js) and build what changed (a new generator function,
|
|
64
70
|
* url or params schema); every live copy swaps geometry and material in place, the page, player, clock and world state stay. The vite preset
|
|
65
71
|
* calls it when an art module imported by the game's assets.js is saved; returns what was swapped (also in describe().assetSwaps).
|
|
66
|
-
* @example import packs from '
|
|
72
|
+
* @example import packs from '../assets.js'; if (import.meta.hot) import.meta.hot.accept('./assets.js', m => engine.debug.reloadAssets(m.default));
|
|
67
73
|
* @param {any} packs @returns {Promise<{ why: string, names: string[], copies: Record<string, number>, ms: number, partsChanged?: string[] }>}
|
|
68
74
|
*/
|
|
69
75
|
reloadAssets(packs) { return reloadAssets(this.e, packs); }
|
|
76
|
+
/**
|
|
77
|
+
* Watch one value the engine does not watch by default, on the dev server: who writes it (file:line, frame) goes into engine.explain({ value: name }), and two writers fighting
|
|
78
|
+
* over it give a one-line hint. It observes; every write goes through. In a release build it does nothing: watching is false.
|
|
79
|
+
* Only watched values are seen, and a write that leaves the value unchanged is not: a value that shows no conflict may still have one.
|
|
80
|
+
* @example engine.debug.watch('boss.hp', boss, 'hp'); engine.debug.watch('player.pos', player, 'position');
|
|
81
|
+
* @param {string} name what explain and describe('picture').picture.writers call it; a name already in use is refused (watching false)
|
|
82
|
+
* @param {any} object the object, or a Color, Vector or rotation itself
|
|
83
|
+
* @param {string} [key] a plain property; a Color, Vector or rotation held there is watched inside. A property behind a class accessor cannot be hooked (watching false)
|
|
84
|
+
* @returns {{ watching: boolean, remove(): void }} remove() forgets the name; the accessor stays until reload and passes values through
|
|
85
|
+
*/
|
|
86
|
+
watch(name, object, key) { return this.e._picture?.watchNamed(name, object, key) ?? { watching: false, remove() {} }; }
|
|
70
87
|
/** The active view ({ mode: 'off', owner: null } when none) @returns {{ mode: string, owner: string | null, what?: string }} */
|
|
71
88
|
viewState() { return this._view.state(); }
|
|
72
89
|
|
|
@@ -87,7 +104,8 @@ export class DebugOverrides {
|
|
|
87
104
|
override(owner, target, patch, value) {
|
|
88
105
|
if (!owner || typeof owner !== 'string') throw codedError('debug-override', "engine.debug.override(owner, target, patch): owner is a non-empty string naming who sets it, e.g. 'ai-session', so engine.debug.clear(owner) can remove it");
|
|
89
106
|
if (typeof patch === 'string') return this._value(owner, target, patch, value);
|
|
90
|
-
|
|
107
|
+
if (!patch || typeof patch !== 'object') throw codedError('debug-override', `engine.debug.override(owner, target, patch): patch is a field name with a value, or { ${KEYS.join(', ')} }; got ${patch}`);
|
|
108
|
+
for (const k of Object.keys(patch)) if (!KEYS.includes(k)) throw codedError('debug-override', `engine.debug.override: unknown field '${k}'. Fields: ${KEYS.join(', ')}, e.g. { visible: false } or { material: 'flat' }`);
|
|
91
109
|
if (patch.material !== undefined && !MATERIALS.includes(patch.material)) throw codedError('debug-override', `engine.debug.override: material must be ${MATERIALS.map(m => `'${m}'`).join(' or ')} (unlit base colour / wireframe), got ${JSON.stringify(patch.material)}`);
|
|
92
110
|
const byId = typeof target === 'string';
|
|
93
111
|
const obj = /** @type {any} */ (target)?.isObject3D ? target : this.e.thing(target).object;
|
|
@@ -107,7 +125,7 @@ export class DebugOverrides {
|
|
|
107
125
|
/** Active overrides as plain data (describe().scene.overrides) */
|
|
108
126
|
overrides() {
|
|
109
127
|
this._prune();
|
|
110
|
-
return
|
|
128
|
+
return this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) }));
|
|
111
129
|
}
|
|
112
130
|
/** @internal One three.js value on the chain: written now and again before each draw, so picture code that writes it per frame does not end the diagnosis */
|
|
113
131
|
_value(owner, obj, key, value) {
|
|
@@ -119,14 +137,17 @@ export class DebugOverrides {
|
|
|
119
137
|
if (now != null && value != null && typeof now !== typeof value) throw say(`'${key}' holds a ${typeof now}, got ${typeof value}${now.isColor ? ': pass a THREE.Color' : ''}`);
|
|
120
138
|
if (value === undefined) throw say(`give the value for '${key}' (null to clear it)`);
|
|
121
139
|
const apply = o => {
|
|
140
|
+
// allowed: a diagnostic is no game write, so the engine keeps driving an owned value (camera.far, tone) once the override ends
|
|
141
|
+
// put is the exemption's owner: one per override, so two overrides of one key on two objects do not end each other's
|
|
122
142
|
const was = o[key], put = () => { o[key] = value; };
|
|
143
|
+
allowOwned(put, [o]);
|
|
123
144
|
put();
|
|
124
145
|
const h = this.e.onRender(put);
|
|
125
|
-
return () => { h.remove(); o[key] = was; };
|
|
146
|
+
return () => { h.remove(); o[key] = was; allowOwned(put, false); };
|
|
126
147
|
};
|
|
127
148
|
return this._add({ owner, id: `${label}.${key}`, byId: false, obj, patch: { key, value: plain(value), apply }, undo: null });
|
|
128
149
|
}
|
|
129
|
-
/** Active overrides on one object, for engine.thing
|
|
150
|
+
/** Active overrides on one object, for engine.explain({ thing: id }) */
|
|
130
151
|
overridesOn(obj) { this._prune(); return this._l.filter(o => o.obj === obj && !o.view).map(o => ({ owner: o.owner, ...patchInfo(o.patch) })); }
|
|
131
152
|
/** Undo everything, drop / restore what the views put back, re-apply */
|
|
132
153
|
dispose() { this._rebuild(() => { this._l = []; }); this._view.active = null; }
|
|
@@ -141,7 +162,7 @@ export class DebugOverrides {
|
|
|
141
162
|
_drop(o) { if (this._l.includes(o)) this._rebuild(() => { this._l = this._l.filter(x => x !== o); }); }
|
|
142
163
|
/** @internal Undo the whole chain newest first, change the list, re-apply in order: no entry ever restores a value another entry set after it */
|
|
143
164
|
_rebuild(change) {
|
|
144
|
-
for (const x of [...this._l].reverse()) { x.undo?.(); x.undo = null; }
|
|
165
|
+
for (const x of [...this._l].reverse()) { try { x.undo?.(); } catch (err) { reportError(this.e, err, `undo of debug override ${x.id ?? x.owner}`, { soft: true }); } x.undo = null; }
|
|
145
166
|
change();
|
|
146
167
|
const keep = [];
|
|
147
168
|
for (const x of this._l) { try { this._apply(x); keep.push(x); } catch { /* an apply that throws now (its object was disposed) is dropped */ } }
|
|
@@ -158,30 +179,34 @@ export class DebugOverrides {
|
|
|
158
179
|
const { patch, obj } = o, undos = [];
|
|
159
180
|
const undo = () => { for (const u of undos.reverse()) u(); };
|
|
160
181
|
try {
|
|
161
|
-
|
|
182
|
+
// each undo puts back only what is still ours: a swap the game made meanwhile (a hit flash, a model change) stays
|
|
183
|
+
if (patch.visible !== undefined) { const was = obj.visible; obj.visible = patch.visible; undos.push(() => { if (obj.visible === patch.visible) obj.visible = was; }); }
|
|
162
184
|
if (patch.material) {
|
|
163
185
|
for (const m of meshes(obj)) {
|
|
164
186
|
const was = m.material;
|
|
165
187
|
if (!was) continue;
|
|
166
188
|
m.material = Array.isArray(was) ? was.map(x => this._stand(x, patch.material, patch.colorOf)) : this._stand(was, patch.material, patch.colorOf);
|
|
167
|
-
|
|
189
|
+
const put = m.material;
|
|
190
|
+
undos.push(() => { if (m.material === put) m.material = was; });
|
|
168
191
|
}
|
|
169
192
|
}
|
|
170
193
|
if (patch.apply) { const u = patch.apply(obj); if (typeof u === 'function') undos.push(u); }
|
|
171
194
|
} catch (err) { undo(); throw err; }
|
|
172
195
|
o.undo = undo;
|
|
173
196
|
}
|
|
174
|
-
/** @internal One cached unlit stand-in per material and kind,
|
|
197
|
+
/** @internal One cached unlit stand-in per material and kind. Beside the material, not on its userData: the stand-in points back (_dbgOf), and three's material.clone()
|
|
198
|
+
* writes userData through JSON, which threw on the circle for the rest of the session */
|
|
175
199
|
_stand(m, kind, colorOf) {
|
|
176
200
|
if (m.userData._dbgOf) m = m.userData._dbgOf; // already a stand-in (a view under an override): derive from the original, never stack copies
|
|
177
|
-
|
|
201
|
+
let cache = this._stands.get(m);
|
|
202
|
+
if (!cache) this._stands.set(m, cache = {});
|
|
178
203
|
if (cache[kind]) { if (colorOf) cache[kind].color.setHex(colorOf(m)); return cache[kind]; }
|
|
179
204
|
// a plain material on purpose: a diagnostic stand-in must not depend on the style it is diagnosing (rule 1 allows dev-only debug overlays)
|
|
180
205
|
// on WebGPURenderer a MeshBasicNodeMaterial carrying the material's shape nodes (a NodeMaterial's own, or a patched material's tsl chain): a
|
|
181
206
|
// plain stand-in would drop positionNode / vertexNode, so swaying trees froze and TSL-displaced meshes changed shape in the very view meant to
|
|
182
207
|
// show them; colorNode is its base color (not for cost)
|
|
183
208
|
const Node = isWebGPU(this.e.renderer) ? webgpuPart('classes', 'debug.view').MeshBasicNodeMaterial : null;
|
|
184
|
-
const s = new (Node ??
|
|
209
|
+
const s = new (Node ?? MeshBasicMaterial)({ color: colorOf ? colorOf(m) : m.color ?? 0xffffff, map: colorOf ? null : m.map ?? null, alphaMap: m.alphaMap ?? null, vertexColors: !!m.vertexColors,
|
|
185
210
|
transparent: !!m.transparent, opacity: m.opacity ?? 1, side: m.side, alphaTest: m.alphaTest ?? 0, wireframe: kind === 'wire', fog: false });
|
|
186
211
|
if (Node) { s.positionNode = m.positionNode ?? null; s.vertexNode = m.vertexNode ?? null; if (!colorOf) s.colorNode = m.colorNode ?? null; }
|
|
187
212
|
s.name = `debug:${kind}:${m.name || ''}`; s.userData._dbgOf = m;
|
|
@@ -190,4 +215,4 @@ export class DebugOverrides {
|
|
|
190
215
|
}
|
|
191
216
|
|
|
192
217
|
/** True while obj hangs under the scene (a removed thing is detached) */
|
|
193
|
-
function inScene(obj, scene) {
|
|
218
|
+
function inScene(obj, scene) { return !scene || isUnder(obj, scene); }
|
|
@@ -14,30 +14,32 @@
|
|
|
14
14
|
// ctx.near(at, info, weak): reports for the same `at` (same object) are merged; with weak = true only missing fields are filled (used by the interaction module).
|
|
15
15
|
// Display names (ground type, weather name) are not hard-coded here: they come from the string table, ground.<type> and weather.<name> (registered by the terrain and weather modules), and go into groundName / label.
|
|
16
16
|
// describeText, which turns this into text, lives in describeText.js.
|
|
17
|
+
import { Vector3 } from 'three';
|
|
17
18
|
import { describeText } from './describeText.js';
|
|
18
|
-
import { moduleRow } from '
|
|
19
|
+
import { moduleRow } from '../engine/moduleTypes.js';
|
|
19
20
|
import { inspect, explain } from './Inspect.js';
|
|
20
21
|
import { inspectScene } from './InspectScene.js';
|
|
21
22
|
import { inspectMaterials } from './InspectMaterials.js';
|
|
22
23
|
import { inspectPerf } from './InspectPerf.js';
|
|
23
|
-
import { codedError, coded } from '
|
|
24
|
-
import { r1 } from '
|
|
24
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
25
|
+
import { r1 } from '../base/math.js';
|
|
25
26
|
import { describeRender, describePicture, describeBackend } from './describeRender.js';
|
|
26
|
-
import { describeOwned, checkWrittenOnce } from '
|
|
27
|
-
import { describeScene } from '
|
|
28
|
-
import { describeHolds } from '
|
|
29
|
-
import { warnOnce } from '
|
|
30
|
-
import { stats } from '
|
|
31
|
-
import { threePatches } from '
|
|
32
|
-
import { describeSlots } from '
|
|
27
|
+
import { describeOwned, checkWrittenOnce } from '../ops/owned.js';
|
|
28
|
+
import { describeScene } from '../scene/thingOps.js';
|
|
29
|
+
import { describeHolds } from '../ops/holds.js';
|
|
30
|
+
import { warnOnce } from '../base/validate.js';
|
|
31
|
+
import { stats } from '../../render/backend.js';
|
|
32
|
+
import { threePatches } from '../scene/threePatches.js';
|
|
33
|
+
import { describeSlots } from '../engine/plugins.js';
|
|
33
34
|
/** describe().perf's draw counters (render/backend.js reads them per renderer) @param {any} r */
|
|
34
35
|
const drawStats = r => { const s = stats(r); return { drawCalls: s.drawCalls, triangles: s.triangles }; };
|
|
35
36
|
|
|
36
37
|
const NEAR_RADIUS = 30, NEAR_MAX = 15;
|
|
37
38
|
const COMPASS = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']; // north = -Z, east = +X
|
|
38
39
|
const RELATIVE = ['front', 'front-right', 'right', 'back-right', 'back', 'back-left', 'left', 'front-left']; // relative to the camera heading
|
|
39
|
-
|
|
40
|
-
const
|
|
40
|
+
// the core's own fields
|
|
41
|
+
const STANDARD = new Set(['unhandled', 'holds', 'input', 'wraps', 'slots', 'threePatches', 'renderer', 'vars', 'ready', 'error', 'disabledModules', 'moduleStates', 'loading', 'audio', 'time', 'player', 'camera', 'nearbyRadius', 'nearby', 'actions', 'ui', 'cutscene', 'modules', 'perf', 'scene', 'render', 'picture', 'owned', 'shared', 'control']);
|
|
42
|
+
const ACTIONS_MAX = 8; // what the player can do now, with why not: saves the AI a guess for a few dozen characters
|
|
41
43
|
const sector = a => Math.round(((a % (Math.PI * 2)) + Math.PI * 2) / (Math.PI / 4)) % 8;
|
|
42
44
|
|
|
43
45
|
/** Display name from the string table (prefix + key); null if missing (the text then uses the raw name) */
|
|
@@ -88,16 +90,17 @@ export function describeApi(e) {
|
|
|
88
90
|
return { describe: api, describeText: text, inspect: inspectApi, explain: q => explain(e, q) };
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
/** Only the modules that are not running normally (initializing / failed) appear in describe, so the common case adds nothing (null); engine.
|
|
93
|
+
/** Only the modules that are not running normally (initializing / failed / blocked) appear in describe, so the common case adds nothing (null); engine.explain({ module }) has all of them */
|
|
92
94
|
function pendingModules(e) {
|
|
93
95
|
const out = {};
|
|
94
96
|
for (const [name, st] of e._modState) if (st === 'initializing' || st === 'failed') out[name] = st;
|
|
97
|
+
for (const [name, by] of e._modBlocked) if (e._modState.get(name) !== 'failed') out[name] = `blocked by ${by.map(b => `${b.module} (${b.state})`).join(', ')}`;
|
|
95
98
|
return Object.keys(out).length ? out : null;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
// Engine tables no module hook writes into (hooks add to time / player / camera / ui / perf / cutscene / nearby): a describe({ only }) that asks
|
|
99
102
|
// for nothing else skips the hooks, describe.add and the action list
|
|
100
|
-
const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer']);
|
|
103
|
+
const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'audio', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer', 'spatial']);
|
|
101
104
|
const NONE = Symbol('none'); // a conditional section that is absent this time
|
|
102
105
|
|
|
103
106
|
/**
|
|
@@ -113,41 +116,46 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
|
113
116
|
ready: () => e.ready,
|
|
114
117
|
error: () => e.error, // gameplay error in dev / tests (gameplay is frozen)
|
|
115
118
|
unhandled: () => e._unhandled || NONE, // dev: first promise rejection nobody caught, and how many followed (errors.js)
|
|
116
|
-
disabledModules: () =>
|
|
119
|
+
disabledModules: () => Object.entries(e.moduleStates).filter(([, s]) => s === 'disabled').map(([n]) => n), // picture / ui modules switched off after an error
|
|
117
120
|
moduleStates: () => pendingModules(e) ?? NONE, // while a module is initializing or failed
|
|
118
121
|
loading: () => e.loading.view(), // what is pending / failed and whether it blocks the start (Loading.js)
|
|
119
|
-
time: () => ({ tick: e.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now),
|
|
122
|
+
time: () => ({ tick: e.time.tick, real: r1(e.time.now('real')), ambient: r1(e.time.now('ambient')), calendar: r1(e.clock.now), halted: e.halted, frozen: e.frozen, ...(e.frozen ? { frozenBy: e.stacks.get('freeze').names() } : {}), headless: e.headless, run: e.runState,
|
|
120
123
|
channels: e.time.describe(), rate: e.clock.rate }),
|
|
121
|
-
|
|
124
|
+
audio: () => { const i = e.audio?.info; return i && (Object.values(i.ducks).some(v => v !== 1) || Object.keys(i.voices).length) ? { ducks: i.ducks, voices: i.voices, state: i.state } : NONE; }, // only while a duck or a voice is active; ducks = target level per bus (Audio.info)
|
|
125
|
+
holds: () => describeHolds(e), // who holds halt / freeze / camera / input (holds.js)
|
|
122
126
|
input: () => e.input.describe(), // context stack, declared actions nobody bound, the player's rebindings (Input.js)
|
|
123
127
|
control: () => e.control.describe(), // who decides where each held character goes: { id: { owner, layer, waiting } } (control.js)
|
|
124
128
|
shared: () => e.stacks.describe(), // every shared value / slot with entries: value, writer, how it combined, who else wants it (stacks.js)
|
|
125
129
|
wraps: () => { const w = e._wraps?.describe(); return w && Object.keys(w).length ? w : NONE; }, // engine.wrap: { 'inventory.add': [owners, outermost first] }
|
|
130
|
+
vars: () => ({ flags: { ...e.vars.flags }, counters: { ...e.vars.counters } }), // story state: without it a snapshot said "same" after a flag was set
|
|
126
131
|
player: () => p ? {
|
|
127
132
|
x: r1(p.x), y: r1(p.y), z: r1(p.z),
|
|
128
133
|
ground: e.groundType(p.x, p.z),
|
|
129
134
|
groundName: nameOf(e, 'ground.', e.groundType(p.x, p.z)),
|
|
130
|
-
inWater: e.waterAt(p.x, p.z) > p.y,
|
|
135
|
+
inWater: e.waterAt(p.x, p.z, p.y) > p.y,
|
|
131
136
|
state: e.player.state ?? null, // the character module's own state name ('walk', 'jump'...): core passes it on and never interprets it
|
|
132
137
|
} : null,
|
|
133
|
-
//
|
|
134
|
-
|
|
138
|
+
// who answers ground queries and what the world's water is, so "why is there no ground / water here" is one read (ground.js, compositeGround.js)
|
|
139
|
+
spatial: () => ({ groundHolder: e.stacks.has('ground') ? e.stacks.get('ground').value() : null, voidY: e.ground.voidY(), waterLevel: e.ground.waterLevel,
|
|
140
|
+
waterBodies: e.waterBodies.length, ownWater: e.waterBodies.filter(b => b.query).length,
|
|
141
|
+
...(p ? { under: { ground: r1(e.surface(p.x, p.z, p.y)), water: r1(e.waterAt(p.x, p.z, p.y)) } } : {}) }),
|
|
142
|
+
camera: () => ({ type: null, projection: cam.isOrthographicCamera ? 'orthographic' : 'perspective', ...(cam.isOrthographicCamera ? { orthoSize: r1(cam.top - cam.bottom) } : {}), x: r1(cam.position.x), y: r1(cam.position.y), z: r1(cam.position.z),
|
|
135
143
|
focus: { x: r1(e.focus.x), z: r1(e.focus.z) }, override: e.cameraOverride?.owner ?? null }),
|
|
136
144
|
nearbyRadius: () => radius,
|
|
137
145
|
nearby: () => [],
|
|
138
|
-
ui: () => ({ windows: [...e.
|
|
146
|
+
ui: () => ({ windows: [...e._openWindows], inputLocked: !e.input.enabled, dialogue: null, parts: e.ui.describe() }), // windows include full-screen UI parts (title); parts: default / custom / off
|
|
139
147
|
cutscene: () => null,
|
|
140
148
|
modules: () => [...e.modules.values()].map(moduleRow), // { name, type, provides?, requires? } in install order (moduleTypes.js)
|
|
141
149
|
slots: () => describeSlots(e), // what is plugged in where, from which file, what it affects (plugins.js)
|
|
142
150
|
scene: () => describeScene(e), // engine.add / world things: counts by save tier and what will not survive a load (thingOps.js)
|
|
143
|
-
threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/threePatches.js)
|
|
151
|
+
threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/scene/threePatches.js)
|
|
144
152
|
owned: () => describeOwned(e), // every property the engine writes on its own and who writes it now (owned.js)
|
|
145
153
|
render: () => describeRender(e), // renderer / post / lights and who set each (describeRender.js)
|
|
146
154
|
picture: () => describePicture(e), // tone, fog, environment, background, lights, shadows as three.js holds them now (describeRender.js)
|
|
147
155
|
renderer: () => describeBackend(e), // asked for, drawing, why not WebGPU and what that backend can run (describeRender.js)
|
|
148
156
|
perf: () => ({
|
|
149
|
-
fps: e.
|
|
150
|
-
cpu: e.
|
|
157
|
+
fps: e.halted ? null : Math.round(e.fps), cpuMs: e.halted ? null : r1(e._cpuMs),
|
|
158
|
+
cpu: e.halted ? null : Object.fromEntries(Object.entries(e._cpuPhases).map(([k, v]) => [k, r1(v)])),
|
|
151
159
|
apply: e.budget.cost.report(),
|
|
152
160
|
...drawStats(e.renderer), pixelRatio: e.renderer.getPixelRatio(),
|
|
153
161
|
budget: e.budget.report(), startup: e.startup, stream: e.stream.stats, batching: e.batching.stats, jobs: e.jobs.pending, commits: { pending: e.commits.pending, ...e.commits.stats },
|
|
@@ -169,9 +177,9 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
|
169
177
|
|
|
170
178
|
/** Module describe hooks and describe.add, then the nearby list and the player's actions, into out */
|
|
171
179
|
function hooks(e, out, radius, center, extras) {
|
|
172
|
-
const dir = e.camera.getWorldDirection(new
|
|
180
|
+
const dir = e.camera.getWorldDirection(new Vector3()), camYaw = Math.atan2(dir.x, -dir.z);
|
|
173
181
|
// Nearby things: collect first, then sort and truncate once at the end
|
|
174
|
-
const found = new Map(), v = new
|
|
182
|
+
const found = new Map(), v = new Vector3();
|
|
175
183
|
const ctx = {
|
|
176
184
|
out, radius, center,
|
|
177
185
|
near(at, info, weak = false) {
|