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,5 +1,11 @@
|
|
|
1
|
-
// "Who wrote this
|
|
2
|
-
//
|
|
1
|
+
// "Who wrote this value": the file:line and frame that changed it, a short history, and a one-line hint when two places fight over it. Dev server only (npm run dev,
|
|
2
|
+
// threedog snap): the install line in Engine.js is the one test a bundler drops, so a release build has none of this. It observes; every write goes through.
|
|
3
|
+
//
|
|
4
|
+
// What is watched, and why these: picture values (a light, the fog, tone, environment, background, a material color), because nothing else stands between two picture
|
|
5
|
+
// files; values the engine writes on its own (core/ops/owned.js), because the engine yields quietly and "who took it" was the missing fact; shared points, which
|
|
6
|
+
// keep their owner and line anyway, so they need no hook at all; and whatever the game names with engine.debug.watch.
|
|
7
|
+
// What is not, on purpose: every other three.js property. An accessor on each would be the wrapper this engine promises not to be (docs/design.md 5.5), so
|
|
8
|
+
// an unwatched value says "not tracked", and no answer here ever says two writers do not exist (valueHistory.js LIMIT).
|
|
3
9
|
//
|
|
4
10
|
// Why accessors and a stack, not per-hook attribution: picture/index.js calls all its parts from one engine.onRender, so "which hook was running" names the
|
|
5
11
|
// wiring file for every value. Only the call stack of the write tells parts apart. Why own accessors on r / g / b and x / y / z: Color and Vector3 are
|
|
@@ -9,51 +15,60 @@
|
|
|
9
15
|
// changes nothing is ignored, and a value written every frame is looked at every EVERY frames (staggered). What still gets a stack at once: the first
|
|
10
16
|
// frames, a value that was not written last frame (a one-shot write), and a frame with more writes to a value than its last looked-at frame had (a
|
|
11
17
|
// new writer). So `framesAgo` says how old the answer is, and `writtenSince` says the value moved after that, unseen. An answer is never presented as
|
|
12
|
-
// fresher than it is.
|
|
18
|
+
// fresher than it is. A close record (owned and game-named values) also looks at the first write of every frame: an owned value moves every frame by the engine's own
|
|
19
|
+
// hand, so a single outside write would otherwise pass as usual, and the yield would have no line to give. That costs one stack per frame per moving value, not one per write.
|
|
20
|
+
//
|
|
21
|
+
// Why also "taking turns": two writers that never share a frame (one on even frames, one in a timer) overwrite each other just the same. But one state handing a value to
|
|
22
|
+
// another is normal, so it takes TURNS changes of writer within WINDOW frames. Each change seen also asks for a look next frame, or sampling would rarely see the next one.
|
|
13
23
|
//
|
|
14
24
|
// Why two places in one function are not a fight: fog.color.copy(a) then fog.color.lerp(b, t) is a value computed in steps. A place is a file plus a
|
|
15
25
|
// function name, plus the part running it. shortcut: outside parts, two anonymous functions or two same-named methods in one file count as one place, so a fight between them goes unwarned;
|
|
16
26
|
// upgrade by comparing function start lines if an agent reports one.
|
|
17
27
|
//
|
|
18
|
-
// Parts (modules, core/pictureSlots.js): a value in a slot a part holds has a declared owner, so a write from anyone else is reported at once, naming the holder and
|
|
28
|
+
// Parts (modules, core/scene/pictureSlots.js): a value in a slot a part holds has a declared owner, so a write from anyone else is reported at once, naming the holder and
|
|
19
29
|
// both lines, not only when the two land in one frame (a held value written by a stray in another state would never be a fight). Who wrote it: the module running
|
|
20
|
-
// now (install, its hooks: core/moduleTypes.js ownHook), else any frame in a file that part's code ran from (an event listener, a timer). A file two parts share
|
|
30
|
+
// now (install, its hooks: core/engine/moduleTypes.js ownHook), else any frame in a file that part's code ran from (an event listener, a timer). A file two parts share
|
|
21
31
|
// cannot say which of them it was, so it counts as the holder: a warning that accuses the owner would teach agents to ignore this one.
|
|
22
32
|
// What cannot be seen: a write made before the holder took the slot, and a part added under another object rather than the scene root (see added).
|
|
23
33
|
//
|
|
24
34
|
// Leftovers: three.js objects have no owner, so ctx.track only removes what it was handed. Each root a picture part adds and each post effect is remembered until it
|
|
25
35
|
// leaves; what is still there after the part is gone, and a hook that outlived it, is reported by name. It observes, like the rest: nothing is cleaned up for the part.
|
|
26
|
-
import { warnOnce, fmt } from '
|
|
27
|
-
import { coded } from '
|
|
28
|
-
import { notePatch } from '
|
|
29
|
-
import { sceneVisitor } from '
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
36
|
+
import { warnOnce, fmt } from '../base/validate.js';
|
|
37
|
+
import { coded } from '../base/errorHints.js';
|
|
38
|
+
import { notePatch } from '../scene/threePatches.js';
|
|
39
|
+
import { sceneVisitor, onSceneRoot } from '../scene/sceneDelta.js';
|
|
40
|
+
import { stackFrames, frameText, callerAt, engineFile } from '../ops/stackFrames.js';
|
|
41
|
+
import { slotOfValue, slotHolder } from '../scene/pictureSlots.js';
|
|
42
|
+
import { LIMIT, remember, historyText, partsOf, sharedAnswer } from './valueHistory.js';
|
|
33
43
|
|
|
34
44
|
const EVERY = 30; // frames between two looks at a value written every frame: a stale answer is at most half a second old
|
|
35
45
|
const DEPTH = 10; // three's own frames above the writer: setter, Color.copy, lerpColors ... always fewer
|
|
46
|
+
const TURNS = 6, WINDOW = 240; // changes of writer within 4 seconds at 60 frames: a state change makes one or two, a fight makes one per frame
|
|
36
47
|
const NOT = {
|
|
37
48
|
before: 'not tracked: set before it entered the scene',
|
|
38
49
|
start: 'not tracked: three.js default or set before the engine was made',
|
|
39
50
|
own: 'not tracked: this object defines the property with its own accessor',
|
|
40
51
|
none: 'not tracked: never written since tracking began',
|
|
41
52
|
noFile: 'not tracked: the last write had no source file (console, eval or the picture check)',
|
|
53
|
+
hidden: 'not tracked: it is no plain property a hook can sit on, so its writers cannot be seen',
|
|
42
54
|
};
|
|
43
55
|
// three.js and pre-bundled libraries are never "the writer": the line that called them is
|
|
44
56
|
const SKIP = /\/deps\/|\/node_modules\/|\/three(?:\.[a-z]+)*\.js$/;
|
|
45
|
-
const SELF = /core\/pictureWriters\.js$/;
|
|
46
|
-
const CORE = /\/(?:core|render)\/[^/]+$/; // with engineFile: core and render write for the engine; modules/ count as parts, they hold slots like any other
|
|
57
|
+
const SELF = /core\/inspect\/pictureWriters\.js$/;
|
|
58
|
+
const CORE = /\/(?:core|render)\/(?:[^/]+\/)?[^/]+$/; // with engineFile: core and render (and their folders: core/ops/x.js) write for the engine; modules/ count as parts, they hold slots like any other
|
|
47
59
|
const MATERIALS_MAX = 40; // describe() stays small on a big scene; explain still answers any one of them
|
|
48
60
|
const SHARED_FIX = "make it a shared value: the owner defines it with engine.stacks.define(name, { base: 1 }) and reads it where it writes three.js, the others change it with ctx.mod(name, { mul: 0.5 }); for an amount that moves, take it once, const h = ctx.mod(name, { mul: 1 }), and call h.change(x) each frame (recipes/62-picture-code.md)";
|
|
49
61
|
const STRINGS = {
|
|
50
|
-
conflict:
|
|
62
|
+
conflict: "{value}: two writers {how}, {first} and {second}; the last write stands. engine.explain({ value: '{value}' }) has the history and the fix",
|
|
63
|
+
fix: 'Fix, one of: (1) one place keeps the write, delete the other{claim}; (2) if both need a say, ' + SHARED_FIX,
|
|
51
64
|
claim: ", and that part declares it with provides: ['{slot}']",
|
|
52
65
|
held: "{value} is held by part '{holder}' (provides: ['{slot}'], {place}), but {at} ({who}) wrote it too. The later write is what is drawn, so one of them never shows. Fix, one of: (1) delete the write at {at}; " +
|
|
53
66
|
"(2) if that code should own it, give it provides: ['{slot}'] and install it with engine.use(thatPart(), { replaces: '{slot}' }), which unloads '{holder}'; (3) if both need a say, " + SHARED_FIX,
|
|
54
67
|
leftover: "part '{name}' is gone, but what it added is still there: {list}. Fix: in its install, hand each one to ctx.track, e.g. ctx.track({ remove() { e.scene.remove(obj); obj.geometry.dispose(); } }), or undo it in the part's dispose()",
|
|
55
68
|
};
|
|
56
69
|
|
|
70
|
+
const HOW = { frame: 'in one frame', turns: 'taking turns across frames' };
|
|
71
|
+
|
|
57
72
|
const page = { off: false, nextId: 0 }; // off: threePatches.off('picture-writers'), page-wide like the list
|
|
58
73
|
|
|
59
74
|
/** The writer of the running write: { at: 'picture/sky.js:12', key } or null when no frame names a source file */
|
|
@@ -68,8 +83,12 @@ function writerNow() {
|
|
|
68
83
|
return { at: frameText(f), key: `${f.file}|${f.fn}`, file: f.file, frames: all.slice(i), engine: all.slice(0, i + 1).some(x => CORE.test(x.file) && engineFile(x.file)) };
|
|
69
84
|
}
|
|
70
85
|
|
|
71
|
-
// name: the value's writers name while it can be in a slot (null: a material); ownBy / ownAt: the holder's last write; last: the slot and whether its holder wrote last
|
|
72
|
-
|
|
86
|
+
// name: the value's writers name while it can be in a slot (null: a material); ownBy / ownAt: the holder's last write; last: the slot and whether its holder wrote last;
|
|
87
|
+
// same: another record already hooks this property and answers for this one; close: see the header; owned: the engine's modules write it, so they are no party to a fight;
|
|
88
|
+
// game: named by engine.debug.watch; turn*: the writer last seen, across frames
|
|
89
|
+
const newRec = (why, name = null) => ({ id: page.nextId++, at: null, why, seen: 0, wrote: -1, f: -1, n: 0, usual: 0, next: 0, sample: true, placeKey: null, placeAt: null, placeBy: null, fought: false, fight: null, name, ownBy: null, ownAt: null, last: null,
|
|
90
|
+
history: [], same: null, close: false, owned: false, game: false, turnKey: null, turnAt: null, turnBy: null, turns: 0, turnFrom: -Infinity });
|
|
91
|
+
const real = r => r.same ?? r;
|
|
73
92
|
const who = name => name ? `part '${name}'` : 'code outside any part';
|
|
74
93
|
|
|
75
94
|
class Writers {
|
|
@@ -88,7 +107,8 @@ class Writers {
|
|
|
88
107
|
this.addedBy = new WeakMap(); // thing -> part
|
|
89
108
|
this.top = new Map(); // 'fog.far' -> record (scene, fog and renderer values)
|
|
90
109
|
this.parts = new WeakMap(); // light or material -> { intensity: record, ... }
|
|
91
|
-
this.
|
|
110
|
+
this.hooked = new WeakMap(); // object -> Map(key -> record): one accessor per property, so a second record of it (a color two objects share, an owned value that is also a picture value) answers through the first
|
|
111
|
+
this.shared = new Map(); // shared point -> its history (no record: nothing is hooked)
|
|
92
112
|
const s = e.scene, r = e.renderer;
|
|
93
113
|
this.number(r, 'toneMapping', this.named('renderer.toneMapping', NOT.start));
|
|
94
114
|
this.number(r, 'toneMappingExposure', this.named('renderer.toneMappingExposure', NOT.start));
|
|
@@ -106,14 +126,20 @@ class Writers {
|
|
|
106
126
|
const m = /** @type {any} */ (o).material;
|
|
107
127
|
if (m) for (const x of [].concat(m)) this.material(x);
|
|
108
128
|
} });
|
|
129
|
+
for (const o of e._owned?.values() ?? []) this.owned(o); // the view's values exist before this tool does
|
|
109
130
|
}
|
|
110
131
|
|
|
111
132
|
named(label, why) { const r = newRec(why, () => label); this.top.set(label, r); return r; }
|
|
112
133
|
|
|
113
134
|
/** Own accessor for one plain value; false when the object has none to replace. Reads and writes pass straight through */
|
|
114
135
|
slot(o, key, rec, after) {
|
|
136
|
+
let mine = this.hooked.get(o);
|
|
137
|
+
const had = mine?.get(key);
|
|
138
|
+
if (had) { if (had !== rec) rec.same = real(had); return true; }
|
|
115
139
|
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
116
140
|
if (!d || !('value' in d) || !d.configurable) { if (rec.why !== NOT.none || !d) rec.why = NOT.own; return false; }
|
|
141
|
+
if (!mine) this.hooked.set(o, mine = new Map());
|
|
142
|
+
mine.set(key, rec);
|
|
117
143
|
let v = d.value;
|
|
118
144
|
const t = this;
|
|
119
145
|
Object.defineProperty(o, key, { configurable: true, enumerable: d.enumerable, get: () => v,
|
|
@@ -122,10 +148,46 @@ class Writers {
|
|
|
122
148
|
}
|
|
123
149
|
number(o, key, rec) { this.slot(o, key, rec); }
|
|
124
150
|
/** The components of a Color or Vector3, all reporting to one record: to the game it is one value */
|
|
125
|
-
watch(c, keys, rec) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
watch(c, keys, rec) { for (const k of keys) this.slot(c, k, rec); }
|
|
152
|
+
/** A value changed in place, or a plain property; false when there is nothing to hook */
|
|
153
|
+
hook(rec, o, key) {
|
|
154
|
+
const c = partsOf(o) ? o : key != null && partsOf(o?.[key]) ? o[key] : null;
|
|
155
|
+
if (c) { this.watch(c, partsOf(c), rec); return true; }
|
|
156
|
+
return key != null && !!o && this.slot(o, key, rec);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** An engine-written value (core/ops/owned.js): spec.objects names what it lives on, and its key is the property where there is one (view.pixelRatio has none: the renderer keeps it private) */
|
|
160
|
+
owned(o) {
|
|
161
|
+
if (page.off) return;
|
|
162
|
+
const rec = this.top.get(o.id) ?? this.named(o.id, NOT.start); // a module reinstalled: same name, maybe new objects, and the history goes on
|
|
163
|
+
let any = false;
|
|
164
|
+
for (const x of o.objects) any = this.hook(rec, x, o.key) || any;
|
|
165
|
+
if (!rec.at) rec.why = any ? NOT.start : NOT.hidden;
|
|
166
|
+
real(rec).close = real(rec).owned = true;
|
|
167
|
+
}
|
|
168
|
+
/** The last line outside the engine that wrote this owned value, for the yield warning and describe().owned. Null when no look saw it @param {string} id */
|
|
169
|
+
outside(id) {
|
|
170
|
+
const r = this.top.get(id);
|
|
171
|
+
return r ? real(r).history.findLast(x => !x.engine)?.at ?? null : null;
|
|
172
|
+
}
|
|
173
|
+
/** A take on a shared point (sharedPoint.js). No stack: the entry already holds its line @param {string} name @param {{ owner: string, where: string | null }} ent */
|
|
174
|
+
sharedTook(name, ent) {
|
|
175
|
+
if (page.off) return;
|
|
176
|
+
let h = this.shared.get(name);
|
|
177
|
+
if (!h) this.shared.set(name, h = []);
|
|
178
|
+
remember(h, { at: ent.where, frame: this.frame, owner: ent.owner });
|
|
179
|
+
}
|
|
180
|
+
/** engine.debug.watch: a game's own value, the same record as any other. A name in use is refused: it would hide what that name answers @param {string} label @param {any} o @param {string} [key] */
|
|
181
|
+
watchNamed(label, o, key) {
|
|
182
|
+
const old = this.top.get(label);
|
|
183
|
+
if (page.off || (old && !old.game)) return { watching: false, remove() {} };
|
|
184
|
+
const rec = this.named(label, NOT.none);
|
|
185
|
+
rec.game = true;
|
|
186
|
+
const watching = this.hook(rec, o, key);
|
|
187
|
+
if (!watching) rec.why = NOT.hidden;
|
|
188
|
+
real(rec).close = true;
|
|
189
|
+
// the accessors stay, like threePatches.off: they pass values through, and another record may be answering through them
|
|
190
|
+
return { watching, remove: () => { if (this.top.get(label) === rec) this.top.delete(label); real(rec).close = false; } };
|
|
129
191
|
}
|
|
130
192
|
/** A color held in a property: the components, and the property itself (light.color = other replaces the object the components were on) */
|
|
131
193
|
color(o, key, rec) {
|
|
@@ -165,9 +227,9 @@ class Writers {
|
|
|
165
227
|
}
|
|
166
228
|
|
|
167
229
|
/** The hot path: runs on every write that changed a value. No stack unless the header's rules ask for one */
|
|
168
|
-
wrote(
|
|
230
|
+
wrote(hit) {
|
|
169
231
|
if (page.off || this.drawing || this.e._probing) return;
|
|
170
|
-
const fr = this.frame;
|
|
232
|
+
const rec = real(hit), fr = this.frame;
|
|
171
233
|
rec.wrote = fr;
|
|
172
234
|
if (rec.f !== fr) {
|
|
173
235
|
const cold = fr - rec.f > 1;
|
|
@@ -177,19 +239,35 @@ class Writers {
|
|
|
177
239
|
}
|
|
178
240
|
rec.n++;
|
|
179
241
|
if (!rec.sample) {
|
|
180
|
-
|
|
181
|
-
|
|
242
|
+
const more = rec.n > rec.usual;
|
|
243
|
+
if (!more && !(rec.close && rec.n === 1)) return;
|
|
244
|
+
if (more) { rec.sample = true; rec.next = fr + 1; } // more writes than usual: this one may be a new writer; next frame sees all of them from the first
|
|
182
245
|
}
|
|
183
|
-
rec.usual = rec.n;
|
|
246
|
+
rec.usual = Math.max(rec.usual, rec.n);
|
|
184
247
|
this.stacks++;
|
|
185
248
|
const w = writerNow();
|
|
186
249
|
rec.seen = fr;
|
|
187
250
|
if (!w) { rec.at = null; rec.why = NOT.noFile; rec.placeKey = null; return; }
|
|
251
|
+
if (rec.owned && engineFile(w.file)) w.engine = true; // a module's write to an engine-owned value is the engine's: yielding is the rule there, not a fight
|
|
188
252
|
const by = this.partsOf(w);
|
|
189
253
|
this.claim(rec, w, by);
|
|
254
|
+
remember(rec.history, { at: w.at, frame: fr, part: by[0], engine: w.engine });
|
|
255
|
+
rec.at = w.at; rec.why = null;
|
|
256
|
+
if (w.engine) return; // the engine is no party to a fight: it yields, or it is a debug view
|
|
190
257
|
const place = `${w.key}|${by[0] ?? ''}`; // the part too: two parts' anonymous hooks in one file are two places
|
|
191
|
-
if (fr > 0 && rec.placeKey && rec.placeKey !== place && !rec.fought) this.fight(rec, rec.placeAt, rec.placeBy, w.at, by[0]);
|
|
192
|
-
|
|
258
|
+
if (fr > 0 && rec.placeKey && rec.placeKey !== place && !rec.fought) this.fight(rec, rec.placeAt, rec.placeBy, w.at, by[0], 'frame');
|
|
259
|
+
this.turn(rec, place, w.at, by[0] ?? null, fr);
|
|
260
|
+
rec.placeKey = place; rec.placeAt = w.at; rec.placeBy = by[0] ?? null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** The writer seen changed since the last look: often enough, in a short enough time, and it is a fight that never shares a frame */
|
|
264
|
+
turn(rec, place, at, by, fr) {
|
|
265
|
+
const was = rec.turnKey, wasAt = rec.turnAt, wasBy = rec.turnBy;
|
|
266
|
+
rec.turnKey = place; rec.turnAt = at; rec.turnBy = by;
|
|
267
|
+
if (rec.fought || fr === 0 || !was || was === place) return;
|
|
268
|
+
rec.next = fr + 1;
|
|
269
|
+
if (fr - rec.turnFrom > WINDOW) { rec.turnFrom = fr; rec.turns = 0; }
|
|
270
|
+
if (++rec.turns >= TURNS) this.fight(rec, wasAt, wasBy, at, by, 'turns');
|
|
193
271
|
}
|
|
194
272
|
|
|
195
273
|
/** The parts this write can be from: the running module alone, else every part that ran from a file on the stack, nearest first */
|
|
@@ -231,14 +309,14 @@ class Writers {
|
|
|
231
309
|
const E = /** @type {ErrorConstructor & { stackTraceLimit?: number }} */ (Error), lim = E.stackTraceLimit;
|
|
232
310
|
E.stackTraceLimit = DEPTH;
|
|
233
311
|
const stack = new Error().stack; E.stackTraceLimit = lim;
|
|
234
|
-
const f = stackFrames(stack ?? '').find(x => !SELF.test(x.file) && !/core\/modules\.js$/.test(x.file));
|
|
312
|
+
const f = stackFrames(stack ?? '').find(x => !SELF.test(x.file) && !/core\/engine\/modules\.js$/.test(x.file));
|
|
235
313
|
if (f && !engineFile(f.file)) this.noteFile(f.file, m.name, frameText(f));
|
|
236
314
|
}
|
|
237
315
|
|
|
238
316
|
/**
|
|
239
317
|
* A scene root or a post effect just added: which picture part it belongs to, if any.
|
|
240
318
|
* shortcut: only scene roots are seen. A light put under the camera or under another part's group is no root and goes unreported; upgrade through the visitor's
|
|
241
|
-
* pending adds in core/sceneDelta.js if an agent reports one.
|
|
319
|
+
* pending adds in core/scene/sceneDelta.js if an agent reports one.
|
|
242
320
|
*/
|
|
243
321
|
added(kind, thing, name) {
|
|
244
322
|
if (page.off) return;
|
|
@@ -261,7 +339,7 @@ class Writers {
|
|
|
261
339
|
const left = [];
|
|
262
340
|
for (const [thing, r] of mine ?? []) if (!thing._removed) left.push(r); // _removed: a post handle; a scene root that left is already out of the map
|
|
263
341
|
const e = this.e;
|
|
264
|
-
for (const list of [e._onRender.before, e._onRender.after, e._frame, e._fixed, e._fixedLate]) for (const f of list) if (f.part === m.name) left.push({ kind: 'hook', name: 'frame callback', at: f.at });
|
|
342
|
+
for (const list of [e._onRender.before, e._onRender.after, e._frame, e._animate, e._fixed, e._fixedLate]) for (const f of list) if (f.part === m.name) left.push({ kind: 'hook', name: 'frame callback', at: f.at });
|
|
265
343
|
if (!swapping) for (const [name, on] of [['scene.fog', e.scene], ['scene.environment', e.scene], ['scene.background', e.scene]]) {
|
|
266
344
|
const r = this.top.get(name), key = name.slice(6);
|
|
267
345
|
if (r?.last?.holder === m.name && r.last.writer === 'holder' && on[key] != null) left.push({ kind: 'value', name, at: r.at });
|
|
@@ -272,12 +350,12 @@ class Writers {
|
|
|
272
350
|
warnOnce(coded('picture-leftover', fmt(STRINGS.leftover, { name: m.name, list })), `picture-leftover\0${m.name}\0${list}`);
|
|
273
351
|
}
|
|
274
352
|
|
|
275
|
-
fight(rec, first, firstBy, second, secondBy) {
|
|
353
|
+
fight(rec, first, firstBy, second, secondBy, how) {
|
|
276
354
|
rec.fought = true;
|
|
277
|
-
const label = this.labelOf(rec) ?? 'a
|
|
355
|
+
const label = this.labelOf(rec) ?? 'a watched value';
|
|
278
356
|
const said = (at, by) => by ? `${at} (part '${by}')` : at;
|
|
279
|
-
this.fights.push({ value: label, first, second, ...(firstBy ? { firstBy } : {}), ...(secondBy ? { secondBy } : {}) });
|
|
280
|
-
warnOnce(coded('picture-conflict', fmt(STRINGS.conflict, { value: label, first: said(first, firstBy), second: said(second, secondBy)
|
|
357
|
+
this.fights.push(rec.fight = { value: label, how, first, second, ...(firstBy ? { firstBy } : {}), ...(secondBy ? { secondBy } : {}) });
|
|
358
|
+
warnOnce(coded('picture-conflict', fmt(STRINGS.conflict, { value: label, how: HOW[how], first: said(first, firstBy), second: said(second, secondBy) })), `picture-conflict\0${rec.id}`);
|
|
281
359
|
}
|
|
282
360
|
|
|
283
361
|
/** Every value with a name, in one pass: lights and materials are found through the scene, so their names are the current ones */
|
|
@@ -301,9 +379,10 @@ class Writers {
|
|
|
301
379
|
for (const m of mats) add('material', m, m.name || `${m.type}-${m.uuid.slice(0, 6)}`);
|
|
302
380
|
return out;
|
|
303
381
|
}
|
|
304
|
-
labelOf(rec) { for (const [k, r] of this.everyValue()) if (r === rec) return k; return null; }
|
|
382
|
+
labelOf(rec) { for (const [k, r] of this.everyValue()) if (real(r) === rec) return k; return null; }
|
|
305
383
|
|
|
306
|
-
answer(
|
|
384
|
+
answer(hit) {
|
|
385
|
+
const r = real(hit);
|
|
307
386
|
if (!r.at) return { at: null, note: r.why };
|
|
308
387
|
return { at: r.at, framesAgo: this.frame - r.seen, ...(r.wrote > r.seen ? { writtenSince: true } : {}), ...(r.last ?? {}) };
|
|
309
388
|
}
|
|
@@ -312,19 +391,23 @@ class Writers {
|
|
|
312
391
|
const values = {};
|
|
313
392
|
let mats = 0, more = 0;
|
|
314
393
|
for (const [k, r] of this.everyValue()) {
|
|
315
|
-
if (k.startsWith('material:')) { if (!r.at) continue; if (++mats > MATERIALS_MAX) { more++; continue; } }
|
|
394
|
+
if (k.startsWith('material:')) { if (!real(r).at) continue; if (++mats > MATERIALS_MAX) { more++; continue; } }
|
|
316
395
|
values[k] = this.answer(r);
|
|
317
396
|
}
|
|
318
|
-
return { tracked: true, frame: this.frame, stacks: this.stacks, values, conflicts: this.fights, held: this.held.map(({ key, ...h }) => h), leftovers: this.leftovers, ...(more ? { moreMaterials: more } : {}) };
|
|
397
|
+
return { tracked: true, limit: LIMIT, frame: this.frame, stacks: this.stacks, values, conflicts: this.fights, held: this.held.map(({ key, ...h }) => h), leftovers: this.leftovers, ...(more ? { moreMaterials: more } : {}) };
|
|
319
398
|
}
|
|
320
|
-
/** One value by its describe name @param {string} label */
|
|
399
|
+
/** One value by its describe name, a shared point's name or a name given to engine.debug.watch @param {string} label */
|
|
321
400
|
why(label) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
401
|
+
if (page.off) return { ok: false, text: `${label}: not tracked: threePatches.off('picture-writers') turned this off`, detail: null };
|
|
402
|
+
const hit = this.everyValue().get(label);
|
|
403
|
+
if (!hit && this.e.stacks.has(label)) return sharedAnswer(this.e, label, this.shared.get(label) ?? []);
|
|
404
|
+
if (!hit) return { ok: false, text: `${label}: not tracked, so nothing is known about its writers. Names: describe('picture').picture.writers; any value: engine.debug.watch('${label}', object, 'key')`, detail: null };
|
|
405
|
+
const r = real(hit), a = this.answer(hit), fight = r.fight, slot = slotOfValue(label);
|
|
325
406
|
const owner = !a.slot ? '' : a.writer === 'holder' ? `, by part '${a.holder}', which holds ${a.slot}` : `, by ${who(a.by)}, a stray write: part '${a.holder}' holds ${a.slot}`;
|
|
326
407
|
const age = a.framesAgo ? `, looked at ${a.framesAgo} frames ago${a.writtenSince ? ' (written since, not looked at)' : ''}` : '';
|
|
327
|
-
|
|
408
|
+
const end = fight ? `Two writers ${HOW[fight.how]}: ${fight.first} and ${fight.second}. ${fmt(STRINGS.fix, { claim: slot ? fmt(STRINGS.claim, { slot }) : '' })}` : `No fight seen; ${LIMIT}`;
|
|
409
|
+
const text = [`${label}: ${a.at ? `last changed at ${a.at}${owner}${age}` : a.note}`, historyText(r.history), end].filter(Boolean).join('. ');
|
|
410
|
+
return { ok: !!a.at, text, detail: { ...a, history: r.history, ...(fight ? { conflict: fight } : {}) } };
|
|
328
411
|
}
|
|
329
412
|
|
|
330
413
|
/** Top of a frame's hooks. Two frame hooks with no draw between (engine.step many frames, one draw) are two frames: a state change between them is no fight */
|
|
@@ -336,8 +419,8 @@ class Writers {
|
|
|
336
419
|
|
|
337
420
|
/** @param {any} e */
|
|
338
421
|
export function installPictureWriters(e) {
|
|
339
|
-
notePatch('picture-writers', 'dev server only: intensity, color, position of lights, scene.fog and its values, renderer.toneMapping / toneMappingExposure, scene.environment / background and their intensities, material color / emissive / opacity: an own get / set on each, and on the
|
|
422
|
+
notePatch('picture-writers', 'dev server only: intensity, color, position of lights, scene.fog and its values, renderer.toneMapping / toneMappingExposure, scene.environment / background and their intensities, material color / emissive / opacity, the camera and other values the engine writes on its own (describe().owned), and values named with engine.debug.watch: an own get / set on each, and on the components of a Color, Vector or rotation (core/inspect/pictureWriters.js)',
|
|
340
423
|
() => { page.off = true; }, // accessors already placed stay and only pass values through; new objects get none
|
|
341
|
-
{ scope: 'objects in the scene', lost: "describe('picture').writers
|
|
424
|
+
{ scope: 'objects in the scene', lost: "describe('picture').writers and explain({ value }) stop answering, engine.debug.watch watches nothing, and two writers are no longer warned about" });
|
|
342
425
|
e._picture = new Writers(e);
|
|
343
426
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// are not evaluated, so it over-counts) plus SAMPLER_WEIGHT per active sampler. A ranking aid, not a GPU timing: use it to find the heaviest
|
|
5
5
|
// materials, then measure with the GPU tools (Spector.js through `threedog capture`).
|
|
6
6
|
// Plain three.js equivalent: renderer.info.programs (the list) and gl.getShaderSource / gl.getActiveUniform on program.program.
|
|
7
|
-
import { isWebGPU, nodeProgram, programList } from '
|
|
7
|
+
import { isWebGPU, nodeProgram, programList } from '../../render/backend.js';
|
|
8
8
|
|
|
9
9
|
const SAMPLER_WEIGHT = 25;
|
|
10
10
|
const SAMPLERS = new Set([0x8B5E, 0x8B60, 0x8B62, 0x8B5F, 0x8DC1, 0x8DD2, 0x8DCA, 0x8DCC, 0x8DCF, 0x8DD7, 0x8DC4]); // GL sampler uniform types
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// engine._tools: the one door packages/tools has into the engine's internals, for what no game needs: draw a frame while halted, run the frame hooks, hand a halt back, read the
|
|
2
|
+
// frame cost. Why a door and not the private names: about twenty sites in tools called them directly, so renaming one in core broke a tool with no error until it ran. Now core can
|
|
3
|
+
// rename freely behind these words, and rule R68 fails any other reach from packages/tools. Internal: on no public page, not in the types.
|
|
4
|
+
/** @param {any} e @returns {any} */
|
|
5
|
+
export const toolDoor = e => ({
|
|
6
|
+
/** Draw one frame; hooks false leaves the frame hooks out @param {number} dt @param {boolean} [hooks] */
|
|
7
|
+
render: (dt, hooks) => e._render(dt, hooks),
|
|
8
|
+
/** Run the frame hooks with no draw, the way a halted frame does @param {number} dt @param {boolean} [halted] */
|
|
9
|
+
frameHooks: (dt, halted) => e._frameHooks(dt, halted),
|
|
10
|
+
/** Hand back the halt this owner took @param {string} owner */
|
|
11
|
+
resume: owner => e._unhalt(owner),
|
|
12
|
+
/** Main-thread ms of the last real-time frame */
|
|
13
|
+
get cpuMs() { return e._cpuMs ?? 0; },
|
|
14
|
+
/** What the light watch saw (lightWatch.js) */
|
|
15
|
+
get lightWatch() { return e._lightWatch; },
|
|
16
|
+
/** The picture check is rendering: what it changes and puts back is not the game's */
|
|
17
|
+
get probing() { return e._probing; },
|
|
18
|
+
set probing(on) { e._probing = on; },
|
|
19
|
+
/** Whether a material is a debug view's stand-in, not one of the game's @param {any} m */
|
|
20
|
+
standIn: m => !!m?.userData?._dbgOf,
|
|
21
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The small, plain half of the writers tool (core/inspect/pictureWriters.js): one value's history and the words that report it.
|
|
2
|
+
//
|
|
3
|
+
// Why a short history and not only "last writer": two writers that take turns look like one writer to whoever asks at the wrong moment. Why runs of one line
|
|
4
|
+
// and not one row per write: a value written every frame would push everything else out in a few frames, and the older line is the one being looked for.
|
|
5
|
+
//
|
|
6
|
+
// Why every answer without a fight carries LIMIT: an open engine cannot prove two pieces of plain code never meet (docs/design.md 4.6), and an AI reads
|
|
7
|
+
// "no conflicts" as "safe". Only watched values are seen, a write that changes nothing is invisible, and most values are only looked at now and then.
|
|
8
|
+
const KEEP = 8; // runs kept per value: enough to show two writers alternating, small enough to read in one line
|
|
9
|
+
export const LIMIT = 'none seen is not proof of none: only watched values are seen, and writes are sampled';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What can be hooked inside a value: three.js changes these in place, so a hook on the property that holds them would see nothing. Quaternion and Euler keep theirs in
|
|
13
|
+
* underscore fields behind prototype accessors, and those fields are what an own get / set can sit on.
|
|
14
|
+
* @param {any} v @returns {string | string[] | null}
|
|
15
|
+
*/
|
|
16
|
+
export const partsOf = v => v?.isColor ? 'rgb' : v?.isVector3 ? 'xyz' : v?.isVector2 ? 'xy' : v?.isQuaternion ? ['_x', '_y', '_z', '_w'] : v?.isEuler ? ['_x', '_y', '_z'] : null;
|
|
17
|
+
|
|
18
|
+
/** Add one seen write to a history: the same line again extends its run @param {any[]} h @param {{ at: string | null, frame: number, part?: string | null, owner?: string, engine?: boolean }} w */
|
|
19
|
+
export function remember(h, { at, frame, part, owner, engine }) {
|
|
20
|
+
const top = h[h.length - 1];
|
|
21
|
+
if (top?.at === at && top?.owner === owner) { top.lastFrame = frame; top.times++; return; }
|
|
22
|
+
h.push({ at, frame, lastFrame: frame, times: 1, ...(part ? { part } : {}), ...(owner ? { owner } : {}), ...(engine ? { engine } : {}) });
|
|
23
|
+
if (h.length > KEEP) h.shift();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const run = r => `${r.at ?? 'an unknown line'}${r.owner ? ` (${r.owner})` : r.engine ? ' (engine)' : r.part ? ` (part '${r.part}')` : ''} frame ${r.frame}${r.times > 1 ? `, ${r.times} looks to frame ${r.lastFrame}` : ''}`;
|
|
27
|
+
/** The last runs, newest first, as one clause @param {any[]} h */
|
|
28
|
+
export const historyText = h => h.length ? `Seen: ${h.slice(-3).reverse().map(run).join('; ')}` : '';
|
|
29
|
+
|
|
30
|
+
/** explain's answer for a shared point: it composes, so its entries and their lines are the whole story of the point, not of what it drives @param {any} e @param {string} label @param {any[]} h */
|
|
31
|
+
export function sharedAnswer(e, label, h) {
|
|
32
|
+
const row = e.stacks.get(label).row();
|
|
33
|
+
const text = [`${label}: shared point, now ${JSON.stringify(row.value)}, led by ${row.writer}${row.at ? ` (${row.at})` : ''}${row.how ? `, ${row.how}` : ''}`, historyText(h), 'Direct writes to what it drives are not seen here'];
|
|
34
|
+
return { ok: true, text: text.filter(Boolean).join('. '), detail: { ...row, history: h } };
|
|
35
|
+
}
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
// which lands "after step N" and replays the same. Args must be plain data and self-contained (aim direction goes in the args).
|
|
11
11
|
// The guard (ops.guard) backs "don't go around it": in dev, saved gameplay state written outside loading, fixed steps and ops
|
|
12
12
|
// is reported (see recipes/23-ops.md). Dev argument checks live in opsCheck.js.
|
|
13
|
-
import { DEV, missingText, warnOnce } from '
|
|
14
|
-
import { checkTypeRule, asModule } from '
|
|
15
|
-
import { checkDef, checkArgs, devError,
|
|
16
|
-
import { coded, codedError } from '
|
|
13
|
+
import { DEV, fmt, missingText, warnOnce } from '../base/validate.js';
|
|
14
|
+
import { checkTypeRule, asModule } from '../engine/moduleTypes.js';
|
|
15
|
+
import { checkDef, checkArgs, devError, SOURCES } from './opsCheck.js';
|
|
16
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
17
17
|
import { guardWrite } from './opsGuard.js';
|
|
18
18
|
import { failure, isStructured, opsBlocked } from './opsFail.js';
|
|
19
19
|
import { runOp } from './opsRun.js';
|
|
20
20
|
import { newRing, logEntry, recentEntries } from './opsHistory.js';
|
|
21
|
-
import { defaultsOf, withDefaults } from '
|
|
21
|
+
import { defaultsOf, withDefaults } from '../base/params.js';
|
|
22
|
+
import { reportError } from '../base/errors.js';
|
|
22
23
|
|
|
23
24
|
const STRINGS = {
|
|
24
25
|
dup: "ops.define('{name}'): already defined. To replace it call remove() on the handle define returned first",
|
|
@@ -44,10 +45,10 @@ export class Ops {
|
|
|
44
45
|
/** @internal */ this._inCan = null;
|
|
45
46
|
/** @internal > 0 while state may be written without an op (save load, applyState, net sync) */ this._allowDepth = 0;
|
|
46
47
|
/** @internal request counter (net replies carry it) */ this._seq = 0;
|
|
47
|
-
/** @internal ctx of the innermost running op (nested ops inherit source and
|
|
48
|
+
/** @internal ctx of the innermost running op (nested ops inherit source, actor and session) */ this._last = null;
|
|
48
49
|
/** @internal set through route() (net clients): (def, args, opts) => result to return instead of running locally, or null to run here */ this._route = null;
|
|
49
50
|
/** @internal true while route() is held: every write outside allow() is reported, even in fixed steps and ops (own movement, world.move, excepted) */ this._client = false;
|
|
50
|
-
/** Counter
|
|
51
|
+
/** Counter that only goes up: each committed op, undo, load and rollback bumps it (a failed op that changed nothing does not); every run result carries it, so "did anything change since I looked" is one compare */
|
|
51
52
|
this.revision = 0;
|
|
52
53
|
/** @internal depth of atomic runs in progress, and after hooks waiting for the outermost one to commit */ this._txDepth = 0; this._txAfter = [];
|
|
53
54
|
this.historySize = 256;
|
|
@@ -78,7 +79,7 @@ export class Ops {
|
|
|
78
79
|
* run (and can) may fail with { ok: false, code, facts, nextActions } (facts: object or list [{ id, field, actual, expected? }]); nextActions are the game's own suggestions.
|
|
79
80
|
* owner (optional, checked by net() for peer requests): args => world record id whose `owner` field must equal the requesting actor.
|
|
80
81
|
* @param {string} name
|
|
81
|
-
* targets (optional): the thing ids, kinds or template names this op is for; engine.thing
|
|
82
|
+
* targets (optional): the thing ids, kinds or template names this op is for; engine.explain({ thing: id }).ops lists it ('*' = any thing).
|
|
82
83
|
* @param {{ run: (e: any, args: any, ctx: OpContext) => any, can?: (e: any, args: any, ctx: OpContext) => true | string | { code: string, facts?: object, nextActions?: { op: string, args?: object }[] }, targets?: string | string[], args?: Record<string, string | { type: string, default?: any, min?: number, max?: number, values?: any[], desc?: string, optional?: boolean }>, offers?: (e: any, ctx: OpContext) => object[], reasons?: Record<string, string>, desc?: string, undo?: (e: any, args: any, value: any) => void, net?: 'peer' | 'local', owner?: (args: any) => string, atomic?: boolean, after?: (e: any, args: any, value: any, ctx: OpContext) => void }} def
|
|
83
84
|
* @returns {{ remove(): void }}
|
|
84
85
|
* @example
|
|
@@ -110,7 +111,7 @@ export class Ops {
|
|
|
110
111
|
|
|
111
112
|
/**
|
|
112
113
|
* Run an op now (synchronously): checks args (dev), calls can, then run, and logs it. Returns { ok: true, value, revision } or { ok: false, code, facts, nextActions, revision } (revision = ops.revision, counts committed ops); can may also return { code, facts?, nextActions? }.
|
|
113
|
-
* Pass a fresh args object each call (it is kept in the history; in dev it is frozen). opts.source: 'player' | 'game' | 'bridge' | 'test' | 'replay' | 'net'
|
|
114
|
+
* Pass a fresh args object each call (it is kept in the history; in dev it is frozen). opts.source: 'player' | 'game' | 'bridge' | 'test' | 'replay' | 'net' | 'editor'
|
|
114
115
|
* (default: 'game' inside a fixed step, 'player' between steps); opts.actor: who does it (world record id, default engine.actor, which is 'player' unless the game hands control elsewhere).
|
|
115
116
|
* @param {string} name
|
|
116
117
|
* @param {object} [args]
|
|
@@ -128,6 +129,7 @@ export class Ops {
|
|
|
128
129
|
|
|
129
130
|
/**
|
|
130
131
|
* Reverse a finished op with the undo(e, args, value) its definition declared: pass the same args and the value run returned.
|
|
132
|
+
* canUndo(e, args, value) in the definition answers like can (true, a reason, a structured failure) when the world may have moved on so far that it cannot be reversed.
|
|
131
133
|
* Returns { ok: true }, or { ok: false, code: 'noUndo', facts: { op }, nextActions } when the op did not declare undo. The undo runs as an op write (the dev guard stays quiet).
|
|
132
134
|
* @example const r = engine.ops.run('inventory.trade', { take: 'rusty_key', give: 'gold_key' }); engine.ops.undo('inventory.trade', { take: 'rusty_key', give: 'gold_key' }, r.value);
|
|
133
135
|
* @param {string} name
|
|
@@ -140,10 +142,32 @@ export class Ops {
|
|
|
140
142
|
const d = this._def(name);
|
|
141
143
|
if (!d) return this._res(failure({ code: 'unknownOp', facts: { op: name } }));
|
|
142
144
|
if (typeof d.undo !== 'function') return this._res(failure({ code: 'noUndo', facts: { op: name }, nextActions: [] }));
|
|
145
|
+
const blocked = opsBlocked(this.engine); // as run: a load in progress or a gameplay error
|
|
146
|
+
if (blocked) return this._res(failure(blocked));
|
|
147
|
+
// as run: a broken op is reported and answered, a thrown error is not the caller's to catch
|
|
148
|
+
const broke = err => { if (err?.opsDevError) throw err; reportError(this.engine, err, `ops.undo('${name}')`); return this._res(failure('error')); };
|
|
149
|
+
let no;
|
|
150
|
+
try { no = d.canUndo?.(this.engine, args, value) ?? true; } catch (err) { return broke(err); }
|
|
151
|
+
if (no !== true) return this._res(failure(no)); // as can: answered, and nothing changed, so the revision stays
|
|
152
|
+
const ctx = this._ctx(name, args, opts, this._stack.length ? this._last : null);
|
|
143
153
|
this._allowDepth++;
|
|
144
|
-
try {
|
|
154
|
+
try {
|
|
155
|
+
// the op's code is the defining module's, not the caller's (run)
|
|
156
|
+
asModule(this.engine, null, () => this._as(name, ctx, () => d.undo(this.engine, args, value, ctx)));
|
|
157
|
+
} catch (err) {
|
|
158
|
+
return broke(err);
|
|
159
|
+
} finally {
|
|
160
|
+
this._allowDepth--;
|
|
161
|
+
this.revision++; // the state changed, a half-done undo too: "did anything change since I looked" must see it
|
|
162
|
+
}
|
|
145
163
|
return { ok: true };
|
|
146
164
|
}
|
|
165
|
+
/** @internal Run fn as part of op `name` with its ctx, when the op is not on the stack (undo, an after hook held for the commit, a use after a walk): nested ops, ops.actor and content words read it */
|
|
166
|
+
_as(name, ctx, fn) {
|
|
167
|
+
const prev = this._last;
|
|
168
|
+
this._stack.push(name); this._last = ctx;
|
|
169
|
+
try { return fn(); } finally { this._stack.pop(); this._last = prev; }
|
|
170
|
+
}
|
|
147
171
|
|
|
148
172
|
/**
|
|
149
173
|
* Ask without doing: runs only can (no state change, no history). For greying out buttons and input buffers.
|
|
@@ -162,7 +186,12 @@ export class Ops {
|
|
|
162
186
|
const blocked = opsBlocked(this.engine);
|
|
163
187
|
if (blocked) return this._res(failure(blocked));
|
|
164
188
|
let res;
|
|
165
|
-
try { res = this._can(d, args, ctx); } catch (err) {
|
|
189
|
+
try { res = this._can(d, args, ctx); } catch (err) {
|
|
190
|
+
if (err?.opsDevError) throw err;
|
|
191
|
+
// soft: buttons and describe() ask every frame, and asking must not freeze a game; the run path stops it. The reason stays in the answer
|
|
192
|
+
reportError(this.engine, err, `ops.can('${name}')`, { soft: true });
|
|
193
|
+
res = { code: 'error', facts: { message: String(err?.message ?? err) } };
|
|
194
|
+
}
|
|
166
195
|
return this._res(res === true ? { ok: true } : failure(res));
|
|
167
196
|
}
|
|
168
197
|
|
|
@@ -237,10 +266,11 @@ export class Ops {
|
|
|
237
266
|
* @param {any} args
|
|
238
267
|
* @param {{ reason: string, actor?: string, source?: string }} why source defaults to 'net'
|
|
239
268
|
* @returns {void}
|
|
269
|
+
* @experimental
|
|
240
270
|
*/
|
|
241
|
-
refused(name, args, { reason, actor = '', source = 'net' }) { this._log(name, args, { source, actor, tick: this.engine.tick }, false, reason, 0); }
|
|
271
|
+
refused(name, args, { reason, actor = '', source = 'net' }) { this._log(name, args, { source, actor, tick: this.engine.time.tick }, false, reason, 0); }
|
|
242
272
|
/** @internal A separator in the history (save load): later entries belong to a different world state */
|
|
243
|
-
_mark(label) { this._log(label, null, { tick: this.engine.tick, source: 'game', actor: '' }, true, null, 0); }
|
|
273
|
+
_mark(label) { this._log(label, null, { tick: this.engine.time.tick, source: 'game', actor: '' }, true, null, 0); }
|
|
244
274
|
/**
|
|
245
275
|
* Run fn with guarded writes allowed (loading a save, applying a scenario, net sync); works for an async fn too (allowed until its Promise settles). Returns what fn returns.
|
|
246
276
|
* @experimental
|
|
@@ -274,7 +304,7 @@ export class Ops {
|
|
|
274
304
|
if (!SOURCES.includes(source)) throw devError(fmt(STRINGS.badSource, { name, source }));
|
|
275
305
|
if (args) checkArgs(e, this.defs.get(name), args);
|
|
276
306
|
}
|
|
277
|
-
return { source, actor: opts?.actor ?? parent?.actor ?? e.actor, tick: e.tick, frozen: e.frozen };
|
|
307
|
+
return { source, actor: opts?.actor ?? parent?.actor ?? e.actor, tick: e.time.tick, frozen: e.frozen, session: parent?.session ?? e.session.id };
|
|
278
308
|
}
|
|
279
309
|
/** @internal returns true or a reason string */
|
|
280
310
|
_can(d, args, ctx) {
|