threedog 0.7.0 → 0.8.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 +196 -1
- package/README.md +6 -9
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +98 -54
- package/core/{Baked.js → assets/Baked.js} +4 -4
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- 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} +6 -12
- package/core/{namedModel.js → assets/namedModel.js} +17 -13
- package/core/{Audio.js → audio/Audio.js} +26 -23
- 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} +10 -10
- package/core/{Random.js → base/Random.js} +5 -4
- package/core/{easing.js → base/easing.js} +1 -1
- package/core/{errorCodes.js → base/errorCodes.js} +98 -110
- package/core/{errorHints.js → base/errorHints.js} +5 -9
- package/core/{errors.js → base/errors.js} +6 -6
- package/core/{events.generated.js → base/events.generated.js} +1 -0
- package/core/{math.js → base/math.js} +15 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +28 -7
- package/core/{Engine.js → engine/Engine.js} +80 -77
- package/core/{Loading.js → engine/Loading.js} +4 -2
- package/core/{copies.js → engine/copies.js} +4 -4
- package/core/{headlessLoad.js → engine/headlessLoad.js} +4 -4
- package/core/{lifecycle.js → engine/lifecycle.js} +14 -12
- package/core/{loop.js → engine/loop.js} +68 -47
- package/core/{moduleSlots.js → engine/moduleSlots.js} +6 -6
- package/core/{moduleTypes.js → engine/moduleTypes.js} +13 -14
- package/core/{modules.js → engine/modules.js} +14 -11
- package/core/{page.js → engine/page.js} +36 -23
- package/core/{plugins.js → engine/plugins.js} +6 -9
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +26 -24
- package/core/{Input.js → input/Input.js} +30 -22
- package/core/{inputContext.js → input/inputContext.js} +14 -5
- package/core/{inputPad.js → input/inputPad.js} +1 -1
- package/core/{inputPointer.js → input/inputPointer.js} +8 -2
- package/core/{inputTouch.js → input/inputTouch.js} +1 -1
- package/core/{Budget.js → inspect/Budget.js} +21 -20
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +30 -16
- package/core/{Describe.js → inspect/Describe.js} +26 -22
- package/core/{Inspect.js → inspect/Inspect.js} +9 -7
- 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} +52 -20
- package/core/{catalog.js → inspect/catalog.js} +3 -3
- 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} +21 -20
- package/core/{describeText.js → inspect/describeText.js} +11 -6
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
- package/core/{pictureWriters.js → inspect/pictureWriters.js} +15 -16
- package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
- package/core/{Ops.js → ops/Ops.js} +16 -11
- package/core/{control.js → ops/control.js} +13 -12
- package/core/ops/holds.js +139 -0
- package/core/{opsAtomic.js → ops/opsAtomic.js} +2 -1
- package/core/{opsCheck.js → ops/opsCheck.js} +4 -5
- package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
- package/core/{opsRun.js → ops/opsRun.js} +7 -4
- package/core/{owned.js → ops/owned.js} +14 -17
- package/core/{sharedPoint.js → ops/sharedPoint.js} +8 -8
- package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
- package/core/{stacks.js → ops/stacks.js} +12 -14
- package/core/{wrap.js → ops/wrap.js} +8 -6
- package/core/{SaveStore.js → saves/SaveStore.js} +1 -1
- package/core/{Saves.js → saves/Saves.js} +58 -36
- package/core/{saveApply.js → saves/saveApply.js} +13 -9
- package/core/{saveFiles.js → saves/saveFiles.js} +17 -15
- package/core/{saveValues.js → saves/saveValues.js} +20 -3
- package/core/{saveVersions.js → saves/saveVersions.js} +4 -17
- package/core/{session.js → saves/session.js} +31 -17
- package/core/{Rays.js → scene/Rays.js} +23 -25
- package/core/{Views.js → scene/Views.js} +14 -6
- package/core/{adaptive.js → scene/adaptive.js} +15 -8
- package/core/{canvasBox.js → scene/canvasBox.js} +2 -3
- package/core/{engineCamera.js → scene/engineCamera.js} +1 -1
- 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} +4 -4
- package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
- package/core/{ground.js → scene/ground.js} +9 -9
- package/core/{movement.js → scene/movement.js} +3 -3
- package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
- package/core/{sceneDelta.js → scene/sceneDelta.js} +2 -2
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -13
- package/core/scene/stepPoses.js +55 -0
- package/core/{targeting.js → scene/targeting.js} +4 -5
- package/core/{thingExplain.js → scene/thingExplain.js} +6 -5
- package/core/{thingOps.js → scene/thingOps.js} +4 -3
- package/core/{things.js → scene/things.js} +18 -5
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{view.js → scene/view.js} +17 -16
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +60 -30
- package/core/{batchGroups.js → stream/batchGroups.js} +10 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
- package/core/{scatter.js → stream/scatter.js} +2 -2
- package/core/{streamSources.js → stream/streamSources.js} +12 -7
- package/core/{Commits.js → threads/Commits.js} +6 -5
- package/core/{Jobs.js → threads/Jobs.js} +12 -10
- package/core/{Threads.js → threads/Threads.js} +16 -16
- 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} +17 -10
- package/core/{dayTime.js → time/dayTime.js} +5 -1
- package/core/{skip.js → time/skip.js} +18 -17
- package/core/{time.js → time/time.js} +18 -12
- package/core/{uiClock.js → time/uiClock.js} +4 -4
- package/docs/AI.md +22 -19
- package/docs/API.md +24 -23
- package/docs/CODEMAP.md +76 -183
- package/docs/COMMANDS.md +66 -58
- package/docs/CONVENTIONS.md +54 -14
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +78 -29
- 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 +29 -29
- package/docs/api/characters.md +23 -18
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +12 -9
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +45 -43
- package/docs/api/events.md +3 -2
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +1 -1
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +7 -7
- package/docs/api/interactions.md +4 -4
- package/docs/api/inventory.md +9 -9
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -7
- package/docs/api/lightPool.md +1 -6
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +2 -2
- package/docs/api/post.md +20 -3
- package/docs/api/quests.md +3 -3
- package/docs/api/rays.md +5 -7
- package/docs/api/rigid.md +27 -18
- package/docs/api/saves.md +8 -7
- package/docs/api/settings.md +9 -8
- package/docs/api/sky.md +8 -7
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +7 -8
- package/docs/api/terrainDraw.md +1 -1
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +25 -22
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -3
- package/docs/api/vegetationDraw.md +1 -1
- package/docs/api/water.md +1 -1
- package/docs/api/weather.md +9 -9
- package/docs/api/weatherDraw.md +3 -3
- package/docs/api/world.md +5 -5
- package/docs/recipes/01-new-game.md +25 -40
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +27 -43
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +29 -39
- package/docs/recipes/06-clock-events.md +27 -18
- package/docs/recipes/07-flow-scenes-pause.md +12 -17
- package/docs/recipes/08-weather-sky.md +88 -34
- package/docs/recipes/09-materials-lights-models.md +22 -36
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +30 -22
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +39 -17
- package/docs/recipes/14-custom-module.md +14 -13
- package/docs/recipes/15-perf.md +49 -26
- package/docs/recipes/16-dev-bridge.md +32 -52
- package/docs/recipes/18-world.md +36 -23
- package/docs/recipes/19-shooting-picking.md +4 -2
- package/docs/recipes/20-content-actions-save.md +30 -35
- package/docs/recipes/21-camera.md +33 -5
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +10 -10
- package/docs/recipes/26-ui-parts.md +22 -12
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +117 -21
- package/docs/recipes/29-grid.md +2 -2
- package/docs/recipes/30-templates.md +55 -19
- package/docs/recipes/31-audio.md +5 -5
- package/docs/recipes/32-action-game.md +15 -6
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +67 -19
- package/docs/recipes/35-picture-from-reference.md +10 -17
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +7 -11
- package/docs/recipes/43-shader-patches-surfaces.md +20 -41
- package/docs/recipes/44-water-weather-hooks.md +48 -43
- package/docs/recipes/45-cascaded-shadows.md +39 -17
- package/docs/recipes/46-blender-art-route.md +7 -8
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/52-around-the-picture.md +54 -98
- package/docs/recipes/53-ground-up-close.md +61 -24
- package/docs/recipes/55-mods-time-wrap.md +12 -16
- package/docs/recipes/56-webgpu-tsl.md +16 -14
- package/docs/recipes/57-control.md +9 -2
- package/docs/recipes/58-input.md +2 -2
- package/docs/recipes/59-depth-post-effects.md +1 -1
- package/docs/recipes/60-judge-the-picture.md +29 -24
- package/docs/recipes/62-picture-code.md +49 -17
- package/docs/recipes/63-third-person-start.md +17 -4
- package/docs/recipes/64-particles.md +1 -1
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -2
- package/examples/{sheepisland → perf-island}/.threedog/content-index.json +1 -1
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +12 -11
- 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 +1 -0
- package/examples/rc2d/GAMEMAP.md +3 -2
- package/examples/rc2d/main.js +1 -3
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +3 -2
- 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 +1 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +4 -3
- package/examples/world/picture/sky.js +1 -1
- package/index.d.ts +8 -7
- package/index.js +31 -31
- package/llms.txt +9 -13
- package/modules/ambience/Ambience.js +11 -8
- package/modules/calendar/Calendar.js +19 -19
- package/modules/calendar/index.js +13 -13
- package/modules/calendar/schedule.js +11 -6
- package/modules/calendar/seasons.js +7 -7
- package/modules/camera/FirstPersonCamera.js +2 -2
- package/modules/camera/FixedCamera.js +14 -15
- package/modules/camera/FollowCamera.js +4 -4
- package/modules/camera/RtsCamera.js +11 -11
- package/modules/camera/common.js +48 -24
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +33 -30
- package/modules/characters/NPC.js +27 -19
- package/modules/characters/assetModel.js +14 -10
- package/modules/characters/astar.js +7 -5
- package/modules/characters/behaviors.js +4 -5
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +168 -214
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +16 -14
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +8 -8
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +23 -17
- package/modules/characters/npcView.js +6 -5
- package/modules/characters/pathAsync.js +12 -10
- package/modules/characters/pathWorker.js +1 -1
- package/modules/characters/player.js +108 -0
- package/modules/characters/playerStrings.js +2 -2
- package/modules/characters/proceduralRig.js +2 -2
- package/modules/characters/useModel.js +3 -3
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +26 -20
- package/modules/collision/contract.js +15 -0
- package/modules/content/explain.js +1 -2
- package/modules/content/fields.js +24 -3
- package/modules/content/ids.js +2 -2
- package/modules/content/index.js +61 -99
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +10 -7
- package/modules/content/packs.js +3 -3
- package/modules/content/parts.js +2 -2
- package/modules/content/places.js +35 -0
- package/modules/content/props.js +17 -14
- package/modules/content/rules.js +25 -21
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +20 -20
- package/modules/content/words.js +34 -0
- package/modules/debug/DebugPanel.js +10 -43
- package/modules/flow/contract.js +1 -1
- package/modules/flow/index.js +11 -7
- package/modules/gameplay/Container.js +12 -11
- package/modules/gameplay/Containers.js +14 -5
- package/modules/gameplay/Dialogue.js +13 -11
- package/modules/gameplay/Interactions.js +37 -24
- package/modules/gameplay/Inventory.js +8 -9
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +3 -4
- package/modules/gameplay/inventoryOps.js +0 -1
- package/modules/gameplay/pickups.js +22 -23
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +4 -4
- package/modules/grid/index.js +7 -8
- package/modules/grid/preview.js +7 -7
- package/modules/grid/tiles.js +6 -6
- package/modules/hlod/index.js +37 -55
- package/modules/hud/index.js +17 -11
- package/modules/hud/parts.js +4 -4
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +47 -152
- package/modules/level/load.js +79 -0
- package/modules/level/meshes.js +65 -0
- package/modules/level/nodes.js +6 -7
- package/modules/lights/index.js +28 -181
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +30 -26
- package/modules/music/rules.js +1 -1
- package/modules/nav/contract.js +14 -0
- package/modules/nav/index.js +11 -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 +5 -4
- package/modules/net/sync.js +2 -2
- package/modules/net/transports.js +2 -2
- package/modules/particles/Particles.js +11 -8
- package/modules/particles/effect.js +7 -5
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +15 -17
- package/modules/rigid/RigidBodies.js +66 -43
- package/modules/rigid/Vehicles.js +2 -3
- package/modules/rigid/ragdoll.js +287 -0
- package/modules/rigid/ragdollBones.js +159 -0
- package/modules/rigid/sync.js +6 -6
- package/modules/settings/Settings.js +108 -39
- package/modules/settings/apply.js +6 -6
- package/modules/settings/sections.js +16 -14
- 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 +14 -27
- package/modules/sky/tint.js +1 -1
- package/modules/swarm/Swarm.js +346 -0
- package/modules/swarm/draw.js +68 -0
- package/modules/swarm/grid.js +63 -0
- package/modules/terrain/ChunkManager.js +70 -52
- 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 +28 -34
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +2 -1
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +17 -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 +27 -19
- package/modules/timeline/Tween.js +6 -6
- package/modules/timeline/shots.js +5 -7
- package/modules/triggers/index.js +9 -9
- package/modules/vegetation/Vegetation.js +30 -23
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +23 -18
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +8 -6
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +16 -16
- package/modules/water/surface.js +3 -3
- package/modules/weather/Weather.js +41 -30
- package/modules/weather/particles.js +8 -8
- package/modules/weather/weatherDraw.js +22 -18
- package/modules/world/World.js +8 -8
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -12
- package/modules/world/persist.js +73 -25
- package/modules/world/pos.js +4 -4
- package/modules/world/records.js +28 -8
- package/modules/world/sim.js +4 -4
- package/modules/world/state.js +12 -5
- package/modules/world/thingSource.js +4 -2
- package/modules/world/views.js +11 -9
- package/package.json +42 -7
- package/presets.js +1 -3
- package/render/PostFX.js +39 -27
- package/render/backend.js +26 -32
- 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/patchNodes.tsl.js +5 -15
- package/render/fx/postWebGPU.tsl.js +27 -23
- 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 +1 -1
- package/render/lighting.js +5 -3
- package/render/lightmap.js +20 -20
- 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 +20 -4
- package/render/ownFrame.js +4 -4
- package/render/patches.js +13 -13
- package/render/postWebGL.js +12 -10
- package/render/probes.js +16 -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 +57 -11
- package/render/slots.js +7 -7
- package/render/terms.js +22 -24
- package/render/uniformDecl.js +1 -1
- package/types/core.d.ts +200 -153
- package/types/gameplay.d.ts +163 -91
- 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} +7 -15
- 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} +12 -8
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +2 -2
- package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +4 -3
- package/types/generated/core/{control.d.ts → ops/control.d.ts} +4 -10
- package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +37 -13
- package/types/generated/core/{session.d.ts → saves/session.d.ts} +2 -1
- package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
- package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +1 -1
- package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
- package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +18 -16
- 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/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 +1 -1
- 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 +2 -1
- package/types/generated/modules/water/Water.d.ts +1 -0
- package/types/generated/modules/weather/Weather.d.ts +16 -12
- package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
- package/types/generated/modules/world/World.d.ts +5 -3
- package/types/generated/render/PostFX.d.ts +17 -11
- 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 +11 -11
- package/types/physics.d.ts +99 -70
- package/types/tsl.d.ts +37 -4
- package/types/world.d.ts +38 -71
- package/ui/Focus.js +10 -9
- package/ui/Parts.js +4 -3
- package/ui/UI.js +7 -7
- package/ui/defaults.js +3 -2
- package/ui/theme.js +5 -3
- package/core/assetEntry.js +0 -109
- package/core/holds.js +0 -134
- package/core/shadowTypes.js +0 -16
- package/core/util.js +0 -17
- 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/core/{Vars.js → base/Vars.js} +0 -0
- /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/{opsFail.js → ops/opsFail.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/{tier.js → scene/tier.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
|
@@ -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.
|
|
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,15 @@
|
|
|
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
33
|
import { pollPad, keyLabel } from './inputPad.js';
|
|
34
34
|
import { BASIC_KEYS, BASIC_LABELS, BOUND_LABELS } from './inputDefaults.js';
|
|
35
|
-
import { initContexts, pushContext, readableMap, applyContexts, BASE_CONTEXT } from './inputContext.js';
|
|
35
|
+
import { initContexts, pushContext, readableMap, applyContexts, settledStack, BASE_CONTEXT } from './inputContext.js';
|
|
36
36
|
|
|
37
37
|
const NONE = Object.freeze([]);
|
|
38
38
|
const ACTION_OPTS = ['context', 'label', 'optional', 'keys', 'owner'];
|
|
@@ -52,13 +52,14 @@ export class Input {
|
|
|
52
52
|
/** @internal */ this._fx = { keys: new Set(), pressed: new Set(), released: new Set(), x: 0, y: 0 }; // this fixed step's snapshot
|
|
53
53
|
/** @internal */ this._live = { keys: this.keys, pressed: this.justPressed, released: this.justReleased };
|
|
54
54
|
/** @internal */ this._inFixed = false;
|
|
55
|
+
/** @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
56
|
/** This frame's look-drag amount (pixels) and wheel notches */
|
|
56
57
|
this.look = { dx: 0, dy: 0, zoom: 0 };
|
|
57
58
|
/** Mouse/touch pointer @type {Pointer} */
|
|
58
59
|
this.pointer = { x: 0, y: 0, ndcX: 0, ndcY: 0, down: false, clicked: false, button: 0 };
|
|
59
60
|
/** 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
61
|
this.swallowLockClick = /** @type {null | (() => boolean)} */ (null);
|
|
61
|
-
/** On-screen stick (touch) */
|
|
62
|
+
/** On-screen stick (touch) @experimental */
|
|
62
63
|
this.stick = { x: 0, y: 0 };
|
|
63
64
|
/** Auto movement (stress tests, test scripts) @type {Autopilot | null} */
|
|
64
65
|
this.autopilot = null;
|
|
@@ -72,9 +73,9 @@ export class Input {
|
|
|
72
73
|
/** @internal */ this.padDeadzone = padDeadzone;
|
|
73
74
|
/** @internal */ this.padLookSpeed = padLookSpeed;
|
|
74
75
|
/** @internal */ this.padStick = { x: 0, y: 0 };
|
|
75
|
-
/** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} */
|
|
76
|
+
/** Most recently used device: UI key hints follow it @type {'keyboard' | 'pad' | 'touch'} @experimental */
|
|
76
77
|
this.lastDevice = 'keyboard';
|
|
77
|
-
/** Is this a touch device? */
|
|
78
|
+
/** Is this a touch device? @experimental */
|
|
78
79
|
this.touch = matchMedia('(pointer: coarse)').matches;
|
|
79
80
|
/** @internal touch buttons the game asked for [{ action, labelKey }]; drawn by the UI part 'touch' (inputTouch.js) */ this._touch = [];
|
|
80
81
|
for (const a of Object.keys(BASIC_KEYS)) this.actions.set(a, { labelKey: BASIC_LABELS[a], context: BASE_CONTEXT, optional: false, by: 'engine' });
|
|
@@ -87,8 +88,8 @@ export class Input {
|
|
|
87
88
|
if (e.code === 'Space' || e.code === 'Tab' || e.code.startsWith('Arrow')) e.preventDefault();
|
|
88
89
|
}, { signal });
|
|
89
90
|
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); });
|
|
91
|
+
// 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)
|
|
92
|
+
engine.events.on('page:blur', () => { for (const k of [...this.keys]) this._keyUp(k); this._muted.clear(); }); // a muted key's keyup is lost the same way
|
|
92
93
|
|
|
93
94
|
bindPointer(this, canvas, signal);
|
|
94
95
|
|
|
@@ -118,15 +119,19 @@ export class Input {
|
|
|
118
119
|
+ `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
120
|
}
|
|
120
121
|
// 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 };
|
|
122
|
+
const entry = cur?.by && cur.by !== owner ? cur : { labelKey: label || cur?.labelKey || name, context, optional, by: owner, users: 0 };
|
|
122
123
|
if (entry !== cur) this.actions.set(name, entry);
|
|
124
|
+
entry.users++;
|
|
123
125
|
this._readable = null;
|
|
124
126
|
const bound = keys !== undefined ? this.bind(name, keys, { owner }) : null;
|
|
125
127
|
let gone = false;
|
|
126
128
|
return { name, remove: () => {
|
|
127
129
|
if (gone) return; gone = true;
|
|
128
130
|
bound?.remove();
|
|
129
|
-
if (this.actions.get(name)
|
|
131
|
+
if (--entry.users !== 0 || this.actions.get(name) !== entry) return; // a sharing owner keeps it
|
|
132
|
+
// keys someone else bound stay readable: back to an action only bound, as bind() makes it
|
|
133
|
+
if (this._keys.size(name)) this.actions.set(name, { labelKey: entry.labelKey, context: BASE_CONTEXT, optional: false, by: null }); else this.actions.delete(name);
|
|
134
|
+
this._readable = null;
|
|
130
135
|
} };
|
|
131
136
|
}
|
|
132
137
|
/**
|
|
@@ -147,15 +152,14 @@ export class Input {
|
|
|
147
152
|
return { owner, remove: () => { for (const h of hs) h.remove(); } };
|
|
148
153
|
}
|
|
149
154
|
keys = [].concat(keys ?? NONE);
|
|
150
|
-
if (keys.some(k => typeof k !== 'string' || !k)) throw codedError('
|
|
155
|
+
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
156
|
if (!this.actions.has(name)) this.actions.set(name, { labelKey: BOUND_LABELS[name] || name, context: BASE_CONTEXT, optional: false, by: null });
|
|
152
157
|
// 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
158
|
const other = this._keys.holders(name).find(h => h.layer === 'game' && h.owner !== owner);
|
|
154
159
|
if (other && DEV) {
|
|
155
160
|
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
|
|
161
|
+
+ `Rule: one owner binds an action. Fix: keep one of the two binds, or bind another action name`);
|
|
157
162
|
}
|
|
158
|
-
this._readable = null;
|
|
159
163
|
return this._keys.take({ owner, id: name, set: Object.freeze([...keys]), layer: 'game' });
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
@@ -205,6 +209,7 @@ export class Input {
|
|
|
205
209
|
/**
|
|
206
210
|
* 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
211
|
* @param {string} action @returns {readonly string[]}
|
|
212
|
+
* @experimental
|
|
208
213
|
*/
|
|
209
214
|
keysOf(action) {
|
|
210
215
|
const k = this._keys.value(action, BASIC_KEYS[action] ?? null) ?? NONE, t = this._touchKeys.get(action);
|
|
@@ -243,6 +248,7 @@ export class Input {
|
|
|
243
248
|
/**
|
|
244
249
|
* 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
250
|
* @example if (engine.input.released('fire')) shoot(charge);
|
|
251
|
+
* @experimental
|
|
246
252
|
*/
|
|
247
253
|
released(action) { return this._has(action, 'released'); }
|
|
248
254
|
/**
|
|
@@ -272,13 +278,15 @@ export class Input {
|
|
|
272
278
|
const unbound = [...this.actions.keys()].filter(n => this.isUnbound(n));
|
|
273
279
|
return { stack: this._stack.map(c => (c.owner && c.owner !== c.name ? `${c.name}(owner: ${c.owner})` : c.name)), unbound, rebound: this.rebound() };
|
|
274
280
|
}
|
|
275
|
-
/** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} */
|
|
281
|
+
/** Names of the active contexts, bottom to top (pending switches apply at the next fixed step) @returns {string[]} @experimental */
|
|
276
282
|
get contexts() { return this._stack.map(c => c.name); }
|
|
277
283
|
/**
|
|
278
|
-
* Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read)
|
|
284
|
+
* Who holds input, bottom to top above the base context: [{ context, owner, pass }] (pass: unrelated gameplay actions still read).
|
|
285
|
+
* 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
286
|
* @returns {{ context: string, owner: string, pass: boolean }[]}
|
|
287
|
+
* @experimental
|
|
280
288
|
*/
|
|
281
|
-
get holders() { return this.
|
|
289
|
+
get holders() { return settledStack(this).slice(1).map(c => ({ context: c.name, owner: c.owner, pass: c.pass })); }
|
|
282
290
|
/**
|
|
283
291
|
* 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
292
|
* 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 +301,7 @@ export class Input {
|
|
|
293
301
|
return this.engine.mod('input.gate', { ...o, id: action });
|
|
294
302
|
}
|
|
295
303
|
/** @internal true while someone holds this action's gate */
|
|
296
|
-
_gated(action) {
|
|
304
|
+
_gated(action) { return (this._gateStack ??= this.engine.stacks.get('input.gate')).size(action) > 0; }
|
|
297
305
|
/**
|
|
298
306
|
* False while an opaque context (menu, dialogue, cutscene...) covers gameplay: no game action can be read, and cameras ignore picture/zoom @returns {boolean}
|
|
299
307
|
*/
|
|
@@ -336,5 +344,5 @@ export class Input {
|
|
|
336
344
|
|
|
337
345
|
|
|
338
346
|
/** @internal */
|
|
339
|
-
endFrame() { this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
|
|
347
|
+
endFrame() { this.frameCount++; this.justPressed.clear(); this.justReleased.clear(); this.look.dx = this.look.dy = this.look.zoom = 0; this.pointer.clicked = false; }
|
|
340
348
|
}
|
|
@@ -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);
|
|
@@ -30,6 +30,6 @@ export function keyLabel(input, action) {
|
|
|
30
30
|
const pad = keys.filter(k => k.startsWith('Pad')), kb = keys.filter(k => !k.startsWith('Pad'));
|
|
31
31
|
const use = input.lastDevice === 'pad' && pad.length ? pad : kb.length ? kb : pad;
|
|
32
32
|
// 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
|
|
33
|
+
const name = k => input.engine.i18n.has('key.' + k) ? input.engine.t('key.' + k) : keyName(k);
|
|
34
34
|
return use.map(name).filter((v, i, arr) => arr.indexOf(v) === i).join('/');
|
|
35
35
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
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 => {
|
|
@@ -24,8 +30,8 @@ export function bindPointer(input, canvas, signal) {
|
|
|
24
30
|
if (document.pointerLockElement !== canvas) canvas.setPointerCapture(e.pointerId);
|
|
25
31
|
}, { signal });
|
|
26
32
|
canvas.addEventListener('pointermove', e => {
|
|
27
|
-
const p = input.pointer;
|
|
28
33
|
place(e);
|
|
34
|
+
if (e.button >= 0 && drag && !drag.swallowed) chord(e); // -1 on a plain move
|
|
29
35
|
if (!drag || drag.id !== e.pointerId) return;
|
|
30
36
|
const dx = e.clientX - drag.x, dy = e.clientY - drag.y;
|
|
31
37
|
if (document.pointerLockElement === canvas) return;
|
|
@@ -39,7 +45,7 @@ export function bindPointer(input, canvas, signal) {
|
|
|
39
45
|
drag = null;
|
|
40
46
|
if (swallowed) return;
|
|
41
47
|
input.pointer.down = false;
|
|
42
|
-
|
|
48
|
+
chord(e);
|
|
43
49
|
};
|
|
44
50
|
canvas.addEventListener('pointerup', end, { signal }); canvas.addEventListener('pointercancel', end, { signal });
|
|
45
51
|
// if the right button is bound to an action, do not show the browser menu
|
|
@@ -2,7 +2,7 @@
|
|
|
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)
|
|
@@ -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,13 +24,14 @@ 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;
|
|
@@ -63,7 +69,7 @@ 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); }
|
|
@@ -87,7 +93,8 @@ export class DebugOverrides {
|
|
|
87
93
|
override(owner, target, patch, value) {
|
|
88
94
|
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
95
|
if (typeof patch === 'string') return this._value(owner, target, patch, value);
|
|
90
|
-
|
|
96
|
+
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}`);
|
|
97
|
+
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
98
|
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
99
|
const byId = typeof target === 'string';
|
|
93
100
|
const obj = /** @type {any} */ (target)?.isObject3D ? target : this.e.thing(target).object;
|
|
@@ -107,7 +114,7 @@ export class DebugOverrides {
|
|
|
107
114
|
/** Active overrides as plain data (describe().scene.overrides) */
|
|
108
115
|
overrides() {
|
|
109
116
|
this._prune();
|
|
110
|
-
return
|
|
117
|
+
return this._l.filter(o => !o.view).map(o => ({ owner: o.owner, target: o.id, ...patchInfo(o.patch) }));
|
|
111
118
|
}
|
|
112
119
|
/** @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
120
|
_value(owner, obj, key, value) {
|
|
@@ -119,10 +126,13 @@ export class DebugOverrides {
|
|
|
119
126
|
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
127
|
if (value === undefined) throw say(`give the value for '${key}' (null to clear it)`);
|
|
121
128
|
const apply = o => {
|
|
129
|
+
// allowed: a diagnostic is no game write, so the engine keeps driving an owned value (camera.far, tone) once the override ends
|
|
130
|
+
// 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
131
|
const was = o[key], put = () => { o[key] = value; };
|
|
132
|
+
allowOwned(put, [o]);
|
|
123
133
|
put();
|
|
124
134
|
const h = this.e.onRender(put);
|
|
125
|
-
return () => { h.remove(); o[key] = was; };
|
|
135
|
+
return () => { h.remove(); o[key] = was; allowOwned(put, false); };
|
|
126
136
|
};
|
|
127
137
|
return this._add({ owner, id: `${label}.${key}`, byId: false, obj, patch: { key, value: plain(value), apply }, undo: null });
|
|
128
138
|
}
|
|
@@ -141,7 +151,7 @@ export class DebugOverrides {
|
|
|
141
151
|
_drop(o) { if (this._l.includes(o)) this._rebuild(() => { this._l = this._l.filter(x => x !== o); }); }
|
|
142
152
|
/** @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
153
|
_rebuild(change) {
|
|
144
|
-
for (const x of [...this._l].reverse()) { x.undo?.(); x.undo = null; }
|
|
154
|
+
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
155
|
change();
|
|
146
156
|
const keep = [];
|
|
147
157
|
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 +168,34 @@ export class DebugOverrides {
|
|
|
158
168
|
const { patch, obj } = o, undos = [];
|
|
159
169
|
const undo = () => { for (const u of undos.reverse()) u(); };
|
|
160
170
|
try {
|
|
161
|
-
|
|
171
|
+
// each undo puts back only what is still ours: a swap the game made meanwhile (a hit flash, a model change) stays
|
|
172
|
+
if (patch.visible !== undefined) { const was = obj.visible; obj.visible = patch.visible; undos.push(() => { if (obj.visible === patch.visible) obj.visible = was; }); }
|
|
162
173
|
if (patch.material) {
|
|
163
174
|
for (const m of meshes(obj)) {
|
|
164
175
|
const was = m.material;
|
|
165
176
|
if (!was) continue;
|
|
166
177
|
m.material = Array.isArray(was) ? was.map(x => this._stand(x, patch.material, patch.colorOf)) : this._stand(was, patch.material, patch.colorOf);
|
|
167
|
-
|
|
178
|
+
const put = m.material;
|
|
179
|
+
undos.push(() => { if (m.material === put) m.material = was; });
|
|
168
180
|
}
|
|
169
181
|
}
|
|
170
182
|
if (patch.apply) { const u = patch.apply(obj); if (typeof u === 'function') undos.push(u); }
|
|
171
183
|
} catch (err) { undo(); throw err; }
|
|
172
184
|
o.undo = undo;
|
|
173
185
|
}
|
|
174
|
-
/** @internal One cached unlit stand-in per material and kind,
|
|
186
|
+
/** @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()
|
|
187
|
+
* writes userData through JSON, which threw on the circle for the rest of the session */
|
|
175
188
|
_stand(m, kind, colorOf) {
|
|
176
189
|
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
|
-
|
|
190
|
+
let cache = this._stands.get(m);
|
|
191
|
+
if (!cache) this._stands.set(m, cache = {});
|
|
178
192
|
if (cache[kind]) { if (colorOf) cache[kind].color.setHex(colorOf(m)); return cache[kind]; }
|
|
179
193
|
// 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
194
|
// on WebGPURenderer a MeshBasicNodeMaterial carrying the material's shape nodes (a NodeMaterial's own, or a patched material's tsl chain): a
|
|
181
195
|
// plain stand-in would drop positionNode / vertexNode, so swaying trees froze and TSL-displaced meshes changed shape in the very view meant to
|
|
182
196
|
// show them; colorNode is its base color (not for cost)
|
|
183
197
|
const Node = isWebGPU(this.e.renderer) ? webgpuPart('classes', 'debug.view').MeshBasicNodeMaterial : null;
|
|
184
|
-
const s = new (Node ??
|
|
198
|
+
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
199
|
transparent: !!m.transparent, opacity: m.opacity ?? 1, side: m.side, alphaTest: m.alphaTest ?? 0, wireframe: kind === 'wire', fog: false });
|
|
186
200
|
if (Node) { s.positionNode = m.positionNode ?? null; s.vertexNode = m.vertexNode ?? null; if (!colorOf) s.colorNode = m.colorNode ?? null; }
|
|
187
201
|
s.name = `debug:${kind}:${m.name || ''}`; s.userData._dbgOf = m;
|
|
@@ -190,4 +204,4 @@ export class DebugOverrides {
|
|
|
190
204
|
}
|
|
191
205
|
|
|
192
206
|
/** True while obj hangs under the scene (a removed thing is detached) */
|
|
193
|
-
function inScene(obj, scene) {
|
|
207
|
+
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) */
|
|
@@ -97,7 +99,7 @@ function pendingModules(e) {
|
|
|
97
99
|
|
|
98
100
|
// Engine tables no module hook writes into (hooks add to time / player / camera / ui / perf / cutscene / nearby): a describe({ only }) that asks
|
|
99
101
|
// 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']);
|
|
102
|
+
const TABLES = new Set(['ready', 'error', 'disabledModules', 'loading', 'audio', 'holds', 'input', 'control', 'shared', 'modules', 'slots', 'scene', 'threePatches', 'owned', 'render', 'picture', 'renderer']);
|
|
101
103
|
const NONE = Symbol('none'); // a conditional section that is absent this time
|
|
102
104
|
|
|
103
105
|
/**
|
|
@@ -116,13 +118,15 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
|
116
118
|
disabledModules: () => [...e.disabledModules], // picture / ui modules disabled after an error
|
|
117
119
|
moduleStates: () => pendingModules(e) ?? NONE, // while a module is initializing or failed
|
|
118
120
|
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),
|
|
121
|
+
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
122
|
channels: e.time.describe(), rate: e.clock.rate }),
|
|
121
|
-
|
|
123
|
+
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)
|
|
124
|
+
holds: () => describeHolds(e), // who holds halt / freeze / camera / input (holds.js)
|
|
122
125
|
input: () => e.input.describe(), // context stack, declared actions nobody bound, the player's rebindings (Input.js)
|
|
123
126
|
control: () => e.control.describe(), // who decides where each held character goes: { id: { owner, layer, waiting } } (control.js)
|
|
124
127
|
shared: () => e.stacks.describe(), // every shared value / slot with entries: value, writer, how it combined, who else wants it (stacks.js)
|
|
125
128
|
wraps: () => { const w = e._wraps?.describe(); return w && Object.keys(w).length ? w : NONE; }, // engine.wrap: { 'inventory.add': [owners, outermost first] }
|
|
129
|
+
vars: () => ({ flags: { ...e.vars.flags }, counters: { ...e.vars.counters } }), // story state: without it a snapshot said "same" after a flag was set
|
|
126
130
|
player: () => p ? {
|
|
127
131
|
x: r1(p.x), y: r1(p.y), z: r1(p.z),
|
|
128
132
|
ground: e.groundType(p.x, p.z),
|
|
@@ -130,24 +134,24 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
|
130
134
|
inWater: e.waterAt(p.x, p.z) > p.y,
|
|
131
135
|
state: e.player.state ?? null, // the character module's own state name ('walk', 'jump'...): core passes it on and never interprets it
|
|
132
136
|
} : null,
|
|
133
|
-
// projection: engine.camera is an EngineCamera (core/engineCamera.js) that a rig may switch to orthographic; said here so the switch is never hidden
|
|
137
|
+
// projection: engine.camera is an EngineCamera (core/scene/engineCamera.js) that a rig may switch to orthographic; said here so the switch is never hidden
|
|
134
138
|
camera: () => ({ type: null, projection: cam.orthoSize ? 'orthographic' : 'perspective', ...(cam.orthoSize ? { orthoSize: r1(cam.orthoSize) } : {}), x: r1(cam.position.x), y: r1(cam.position.y), z: r1(cam.position.z),
|
|
135
139
|
focus: { x: r1(e.focus.x), z: r1(e.focus.z) }, override: e.cameraOverride?.owner ?? null }),
|
|
136
140
|
nearbyRadius: () => radius,
|
|
137
141
|
nearby: () => [],
|
|
138
|
-
ui: () => ({ windows: [...e.
|
|
142
|
+
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
143
|
cutscene: () => null,
|
|
140
144
|
modules: () => [...e.modules.values()].map(moduleRow), // { name, type, provides?, requires? } in install order (moduleTypes.js)
|
|
141
145
|
slots: () => describeSlots(e), // what is plugged in where, from which file, what it affects (plugins.js)
|
|
142
146
|
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)
|
|
147
|
+
threePatches: () => threePatches.list(), // page-wide changes to three.js classes still on (core/scene/threePatches.js)
|
|
144
148
|
owned: () => describeOwned(e), // every property the engine writes on its own and who writes it now (owned.js)
|
|
145
149
|
render: () => describeRender(e), // renderer / post / lights and who set each (describeRender.js)
|
|
146
150
|
picture: () => describePicture(e), // tone, fog, environment, background, lights, shadows as three.js holds them now (describeRender.js)
|
|
147
151
|
renderer: () => describeBackend(e), // asked for, drawing, why not WebGPU and what that backend can run (describeRender.js)
|
|
148
152
|
perf: () => ({
|
|
149
|
-
fps: e.
|
|
150
|
-
cpu: e.
|
|
153
|
+
fps: e.halted ? null : Math.round(e.fps), cpuMs: e.halted ? null : r1(e._cpuMs),
|
|
154
|
+
cpu: e.halted ? null : Object.fromEntries(Object.entries(e._cpuPhases).map(([k, v]) => [k, r1(v)])),
|
|
151
155
|
apply: e.budget.cost.report(),
|
|
152
156
|
...drawStats(e.renderer), pixelRatio: e.renderer.getPixelRatio(),
|
|
153
157
|
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 +173,9 @@ function describe(e, { radius = NEAR_RADIUS, center: at, only } = {}, extras) {
|
|
|
169
173
|
|
|
170
174
|
/** Module describe hooks and describe.add, then the nearby list and the player's actions, into out */
|
|
171
175
|
function hooks(e, out, radius, center, extras) {
|
|
172
|
-
const dir = e.camera.getWorldDirection(new
|
|
176
|
+
const dir = e.camera.getWorldDirection(new Vector3()), camYaw = Math.atan2(dir.x, -dir.z);
|
|
173
177
|
// Nearby things: collect first, then sort and truncate once at the end
|
|
174
|
-
const found = new Map(), v = new
|
|
178
|
+
const found = new Map(), v = new Vector3();
|
|
175
179
|
const ctx = {
|
|
176
180
|
out, radius, center,
|
|
177
181
|
near(at, info, weak = false) {
|