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
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
// stateApplied waits for it too (Engine.js): screenshots, npm test and the dev bridge wait on stateApplied, so a load that began after
|
|
12
12
|
// start is finished before they capture. A load that never settles stops holding stateApplied after engine.loading.timeoutMs (same limit
|
|
13
13
|
// as start()) with one warning naming who is still waiting, so a stuck module cannot hang a tool.
|
|
14
|
-
import { DEV, warnOnce } from '
|
|
15
|
-
import { coded } from '
|
|
14
|
+
import { DEV, warnOnce } from '../base/validate.js';
|
|
15
|
+
import { coded } from '../base/errorHints.js';
|
|
16
16
|
|
|
17
17
|
const TICK_MS = 16; // one loading frame per ~60 Hz tick: the same pace a live loop gives the workers
|
|
18
18
|
|
|
@@ -27,7 +27,7 @@ export function unsettled(e) {
|
|
|
27
27
|
/** @internal start(): begin pumping loading frames for a headless engine (no-op for a live one, its loop already runs frames) */
|
|
28
28
|
export function startHeadlessLoad(e) {
|
|
29
29
|
if (!e.headless || e._headlessLoad) return;
|
|
30
|
-
const s = e._headlessLoad = { since: -1, stalled: false
|
|
30
|
+
const s = e._headlessLoad = { since: -1, stalled: false };
|
|
31
31
|
const tick = () => {
|
|
32
32
|
if (e.disposed) return;
|
|
33
33
|
if (!unsettled(e).length) { s.since = -1; s.stalled = false; }
|
|
@@ -43,7 +43,7 @@ export function startHeadlessLoad(e) {
|
|
|
43
43
|
if (DEV && who.length) warnOnce(coded('module-not-ready', `headless load after start stalled: still waiting after ${Math.round(e.loading.timeoutMs / 1000)} s for: ${who.join(', ')}; stateApplied no longer waits for it. A module's isReady(e) keeps returning false; fix that module, or raise engine.loading.timeoutMs if the load is just slow`));
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
setTimeout(tick, TICK_MS); // main-loop: a headless engine's stand-in for the live frame loop while something is loading
|
|
47
47
|
};
|
|
48
48
|
tick();
|
|
49
49
|
}
|
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
// - GPU memory: every geometry, material and texture in the scene, the assets cache, the post composer, then renderer.dispose().
|
|
13
13
|
// Level changes do not come through here: things inside a level register with level.track(handle), and the level removes them itself on change.
|
|
14
14
|
|
|
15
|
-
import { coded, codedError } from '
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
15
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
16
|
+
import { fmt } from '../base/validate.js';
|
|
17
|
+
import { dropOwned } from '../ops/owned.js';
|
|
18
|
+
import { reportError } from '../base/errors.js';
|
|
19
|
+
import { releaseContext, memory } from '../../render/backend.js';
|
|
19
20
|
|
|
20
|
-
/** The per-step / per-frame callback lists (onFixed, onFrame, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
21
|
+
/** The per-step / per-frame callback lists (onFixed, onFrame, animators, onRender, module hooks), empty: the constructor's starting state and what dispose leaves */
|
|
21
22
|
export function clearHooks(e) {
|
|
22
|
-
e._fixed = []; e._fixedLate = []; e._frame = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
|
|
23
|
+
e._fixed = []; e._fixedLate = []; e._frame = []; e._animate = []; e._onRender = { before: [], after: [] }; e._hooks = { fixed: [], frame: [], afterRender: [], skip: [] };
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
const STRINGS = { failed: '[engine] dispose hook of module {name} threw (the rest are still cleaned up)',
|
|
@@ -31,9 +32,9 @@ const released = new WeakSet();
|
|
|
31
32
|
/** createEngine calls it before building its renderer on a canvas */
|
|
32
33
|
export function checkCanvasUsable(canvas) { if (canvas && released.has(canvas)) throw codedError('canvas-released', STRINGS.released); }
|
|
33
34
|
|
|
34
|
-
/** Dispose the geometry, materials and
|
|
35
|
+
/** Dispose the GPU data of one scene object: geometry, materials and their textures, instance buffers, shadow map, bone texture */
|
|
35
36
|
function disposeObject(o) {
|
|
36
|
-
o.geometry?.dispose();
|
|
37
|
+
o.geometry?.dispose(); if (o.isInstancedMesh || o.isBatchedMesh || o.isLight) o.dispose(); o.skeleton?.dispose(); // instance buffers, batch textures, a light's shadow map, the bone texture
|
|
37
38
|
for (const m of [].concat(o.material || [])) {
|
|
38
39
|
for (const k in m) if (m[k]?.isTexture) m[k].dispose();
|
|
39
40
|
m.dispose();
|
|
@@ -50,20 +51,21 @@ export const lifecycleMethods = {
|
|
|
50
51
|
* @param {{ keepContext?: boolean }} [opts]
|
|
51
52
|
*/
|
|
52
53
|
dispose(opts = {}) {
|
|
53
|
-
if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', STRINGS.opts
|
|
54
|
+
if (opts === null || typeof opts !== 'object' || Object.keys(opts).some(k => k !== 'keepContext')) throw codedError('dispose-options', fmt(STRINGS.opts, { v: String(JSON.stringify(opts)) }));
|
|
54
55
|
if (this.disposed) return;
|
|
55
|
-
this.phase = 'disposed'; this.
|
|
56
|
+
this.phase = 'disposed'; this.halted = true;
|
|
56
57
|
cancelAnimationFrame(this._raf);
|
|
57
58
|
dropOwned(this, [...(this._owned?.values() ?? [])]); // owned.js keeps a page-wide list for allowOwned
|
|
58
59
|
for (const m of [...this.modules.values()].reverse()) {
|
|
59
60
|
this._modState.set(m.name, 'disposed');
|
|
60
61
|
this._dropTracked(m.name); // its listeners / timers go first, so nothing calls into the module while its dispose tears it down
|
|
61
62
|
if (!m.dispose) continue;
|
|
62
|
-
try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', STRINGS.failed
|
|
63
|
+
try { m.dispose(this); } catch (err) { reportError(this, err, coded('module-dispose', fmt(STRINGS.failed, { name: m.name })), { soft: true }); }
|
|
63
64
|
}
|
|
64
65
|
this._abort.abort();
|
|
65
66
|
this._untrackValidate();
|
|
66
67
|
this._wraps?.dispose(); // engine.wrap: every wrapped method back on its object (a game object or api may outlive the engine)
|
|
68
|
+
this._picture?.dispose(); // dev tool: its scene watchers go with the engine
|
|
67
69
|
this.debug.dispose(); // before the scene is disposed: undoes every diagnostic override and view (puts swapped materials back)
|
|
68
70
|
for (const part of [this.saves, this.audio, this.time, this.commits, this.jobs, this.threads, this.stream, this.batching, this.rays, this.events]) part.dispose();
|
|
69
71
|
clearHooks(this); this._afterTick = null;
|
|
@@ -93,7 +95,7 @@ export const lifecycleMethods = {
|
|
|
93
95
|
counts() {
|
|
94
96
|
const mem = memory(this.renderer);
|
|
95
97
|
const c = {
|
|
96
|
-
listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length, timers: this.time.size,
|
|
98
|
+
listeners: this.events.size, fixed: this._fixed.length + this._fixedLate.length, frame: this._frame.length + this._animate.length, timers: this.time.size,
|
|
97
99
|
statics: this.rays.statics.size, streamEntries: this.stream.entries.size, jobs: this.jobs.pending, commits: this.commits.pending,
|
|
98
100
|
geometries: mem.geometries, textures: mem.textures,
|
|
99
101
|
};
|
|
@@ -12,17 +12,18 @@
|
|
|
12
12
|
//
|
|
13
13
|
// Determinism: in engine.step() and headless loading frames, jobs ignore the real-time budget and drain the queue (see Jobs.js),
|
|
14
14
|
// and stream's synchronous builds are attached to the scene before step returns: same input and same seed (engine.random) give the same result.
|
|
15
|
-
import { reportError } from '
|
|
16
|
-
import { DEV, warnOnce } from '
|
|
17
|
-
import { codedError } from '
|
|
18
|
-
import { watchLights } from '
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
15
|
+
import { reportError } from '../base/errors.js';
|
|
16
|
+
import { DEV, warnOnce, fmt } from '../base/validate.js';
|
|
17
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
18
|
+
import { watchLights } from '../inspect/lightWatch.js';
|
|
19
|
+
import { watchGeometries } from '../inspect/geometryWatch.js';
|
|
20
|
+
import { followFocus } from '../../render/lights.js';
|
|
21
|
+
import { STEP } from '../time/time.js'; // fixed step length: 60 per second
|
|
22
|
+
import { adapt } from '../scene/adaptive.js';
|
|
23
|
+
import { advanceUiClock } from '../time/uiClock.js';
|
|
24
|
+
import { resetStats, programCount, freshFrame } from '../../render/backend.js';
|
|
25
|
+
import { engineDraws } from '../../render/ownFrame.js';
|
|
26
|
+
import { writeDaylight } from '../../render/daylight.js';
|
|
26
27
|
// Most real time one frame may turn into fixed steps (6 steps). A longer hitch slows the game for that frame
|
|
27
28
|
// instead of replaying it in a burst (no spiral of death, no jump after a stall).
|
|
28
29
|
const MAX_CATCHUP = 0.1;
|
|
@@ -32,8 +33,10 @@ const MAX_CATCHUP = 0.1;
|
|
|
32
33
|
const CATCHUP_MS = STEP * 2000;
|
|
33
34
|
// Dev message (console): which hook failed
|
|
34
35
|
const STRINGS = {
|
|
35
|
-
onFixed: 'onFixed callback', commits: 'background result apply (commits)', onFrame: 'onFrame callback', onRender: 'onRender callback', clock: 'clock timer', render: 'render',
|
|
36
|
+
onFixed: 'onFixed callback', commits: 'background result apply (commits)', onFrame: 'onFrame callback', animate: 'animator update', onRender: 'onRender callback', clock: 'clock timer', render: 'render',
|
|
36
37
|
hook: '{kind} hook of module {name}',
|
|
38
|
+
stepStart: 'engine.step() ran while start() is still loading: no game time passes, only frame hooks run. Wait for it first: await engine.start(); engine.step(1)',
|
|
39
|
+
stepSession: 'engine.step() ran while a new game, load or quit is still replacing the state: the step plays on a half-replaced world. Wait for it first: await engine.session.load(slot); engine.step(1)',
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
const SOFT = { soft: true }; // core steps (render, stream): report once only
|
|
@@ -43,47 +46,53 @@ const SOFT = { soft: true }; // core steps (render, stream): report once only
|
|
|
43
46
|
function safe(engine, key, fn, opts, self, a, b) {
|
|
44
47
|
try { fn.call(self, a, b); } catch (err) { reportError(engine, err, key, opts ?? undefined); }
|
|
45
48
|
}
|
|
49
|
+
/** Run one game callback list. remove() replaces the list, so a hook an earlier one removed in this pass (or a dispose) is skipped: it may sit on what its remover just tore down */
|
|
50
|
+
function runList(e, name, key, a) {
|
|
51
|
+
const list = e[name];
|
|
52
|
+
for (const f of list) if (e[name] === list || e[name].includes(f)) safe(e, key, f, null, undefined, a);
|
|
53
|
+
}
|
|
46
54
|
|
|
47
|
-
/** A freeze holder asked to stop ambient animation too (freeze(owner, { ambient: true })); only read while frozen */
|
|
48
55
|
// The first frame drawn after ready ends the first-frame measure (engine.startup.firstFrameMs, startup.js); one compare per frame after that
|
|
49
56
|
function firstFrame(e, at) {
|
|
50
57
|
const s = e.startup;
|
|
51
58
|
e._readyAt = null;
|
|
52
59
|
if (s) { s.phases.draw = Math.round(at - (s.phases.script + s.phases.construct + s.phases.setup + s.phases.init + s.phases.preload + s.phases.world + s.phases.compile)); s.firstFrameMs = Math.round(at); }
|
|
53
60
|
}
|
|
54
|
-
function ambientHeld(e) { for (const h of e.stacks.get('freeze').entries()) if (h.value?.ambient) return true; return false; }
|
|
55
61
|
|
|
56
62
|
export const loopMethods = {
|
|
57
63
|
_fixedStep() {
|
|
58
64
|
// No game time while start() loads (engine.phase): loading takes as long as the machine needs, so a step during it would make the opening
|
|
59
|
-
// tick
|
|
65
|
+
// tick and clock depend on machine speed (review 0.4 core B1). step() during loading (headless scenario settling) still runs frame
|
|
60
66
|
// hooks. An engine never started ('constructed': no loop, nothing loading) steps by hand only, for tests and tools that need no world
|
|
61
|
-
if (this.
|
|
67
|
+
if (this._inStart) return;
|
|
62
68
|
// input snapshot for this step: keys read in fixed depend only on the step count, not on how many steps a frame ran
|
|
63
69
|
this.input.beginFixed();
|
|
64
70
|
try {
|
|
65
71
|
// gameplay frozen: no clock moves, no channel, no mod({ for }) timer (frame hooks and render continue). uTime is the ambient clock (wind, water,
|
|
66
72
|
// clouds): it keeps moving behind a pause menu, the common expectation, unless a freezer asked freeze(owner, { ambient: true })
|
|
67
|
-
if (this.frozen) { this.time._frozenStep(!
|
|
68
|
-
this.time._beginStep(); // the one counter (core/time.js): this step's commits, ops and input records carry the new tick
|
|
73
|
+
if (this.frozen) { this.time._frozenStep(!this.still); return; }
|
|
74
|
+
this.time._beginStep(); // the one counter (core/time/time.js): this step's commits, ops and input records carry the new tick
|
|
69
75
|
this._inFixed = true; // ops log phase 'fixed' and the dev guard lets gameplay writes through
|
|
70
76
|
// due background results first, so this step's gameplay sees them; an engine stepped by hand before start() applies none (start() rebases them)
|
|
71
|
-
if (this.ready) safe(this, STRINGS.commits, this.commits.tick, null, this.commits, this.tick);
|
|
72
|
-
|
|
77
|
+
if (this.ready) safe(this, STRINGS.commits, this.commits.tick, null, this.commits, this.time.tick);
|
|
78
|
+
runList(this, '_fixed', STRINGS.onFixed, STEP);
|
|
73
79
|
this._runHooks('fixed', STEP);
|
|
74
|
-
|
|
80
|
+
runList(this, '_fixedLate', STRINGS.onFixed, STEP); // onFixed({ phase: 'late' }): reads this step's result
|
|
75
81
|
safe(this, STRINGS.clock, this.time._endStep, null, this.time); // ambient, channel and calendar seconds; timed mods end; timers fire
|
|
76
82
|
} finally { this._inFixed = false; this.input.endFixed(); }
|
|
77
83
|
},
|
|
78
|
-
/** Per frame: onFrame callbacks, module frame, stream, jobs. With deterministic true (step, headless loading) jobs ignore real time. */
|
|
84
|
+
/** @internal The loop and the dev tools. Per frame: onFrame callbacks, module frame, stream, jobs. With deterministic true (step, headless loading) jobs ignore real time. */
|
|
79
85
|
_frameHooks(dt, deterministic = false) {
|
|
86
|
+
if (this.disposed) return; // a fixed step of this frame disposed the engine (step() checks the same)
|
|
80
87
|
// one profile frame = one frame-hook cycle (the real loop: one per rendered frame; step(): one per frameEvery fixed steps). Counting rendered frames
|
|
81
88
|
// instead made step(render: false) divide by zero frames and report the whole run's milliseconds as one frame's
|
|
82
89
|
if (this._prof) this._prof.frames++;
|
|
83
90
|
this._picture?.frameStart();
|
|
84
|
-
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/uiClock.js)
|
|
91
|
+
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/time/uiClock.js)
|
|
85
92
|
writeDaylight(this); // before the hooks: an onFrame reads this frame's signal
|
|
86
|
-
|
|
93
|
+
runList(this, '_frame', STRINGS.onFrame, dt);
|
|
94
|
+
// after every onFrame, whoever registered first: an anim.sync / go / set made this frame shows this frame. Before the module frame hooks, which read the pose
|
|
95
|
+
runList(this, '_animate', STRINGS.animate, dt);
|
|
87
96
|
this._runHooks('frame', dt);
|
|
88
97
|
safe(this, 'stream.update', this.stream._update, SOFT, this.stream);
|
|
89
98
|
this.jobs.run({ deterministic });
|
|
@@ -91,7 +100,8 @@ export const loopMethods = {
|
|
|
91
100
|
safe(this, 'batching.update', this.batching.update, SOFT, this.batching); // last before rendering: picks up everything built this frame
|
|
92
101
|
safe(this, 'audio.tick', this.audio._tick, SOFT, this.audio); // positional sounds follow their objects (returns at once when there are none)
|
|
93
102
|
},
|
|
94
|
-
/** @
|
|
103
|
+
/** @internal The loop and the dev tools: one whole engine frame (onRender hooks, own-frame yielding, per-frame bookkeeping). engine.renderOnce stays the public draw: photo mode needs its picture even from a game that owns the frame, and a game may call it inside a hook.
|
|
104
|
+
* @param {number} dt @param {boolean} [hooks] false: draw without the game's onRender hooks (the picture check's probe renders: picture code
|
|
95
105
|
* run there wrote back the light it had just turned off) */
|
|
96
106
|
_render(dt, hooks = true) {
|
|
97
107
|
const r = this.renderer;
|
|
@@ -108,26 +118,32 @@ export const loopMethods = {
|
|
|
108
118
|
// the game drew the canvas itself since the last engine frame (own composer / render loop): it holds the frame, the engine yields (render/ownFrame.js)
|
|
109
119
|
const draws = engineDraws(this), own = this._ownFrame;
|
|
110
120
|
if (own) own.inside++;
|
|
121
|
+
this._poses.draw(); // moving things draw between the last two fixed steps (stepPoses.js); undone below, gameplay never sees it
|
|
111
122
|
try {
|
|
112
123
|
for (const f of before) { safe(this, STRINGS.onRender, f, null, undefined, ctx); r.setRenderTarget(null); }
|
|
113
|
-
this.shadows._frame(); // a game light's cascades, after 'before': picture code aims its light there, and the placement must be what is drawn (
|
|
124
|
+
this.shadows._frame(); // a game light's cascades, after 'before': picture code aims its light there, and the placement must be what is drawn (render/shadows.js)
|
|
114
125
|
this._checkBackendAdds(); // WebGPU route: a WebGL-only material added since the last frame is named, not drawn blank (startup.js)
|
|
115
126
|
freshFrame(r); // WebGPU: step() several times in one task, or a renderOnce() earlier in this tick, must not reuse that scene pass
|
|
116
127
|
if (this._picture) this._picture.drawing = true;
|
|
117
|
-
if (draws) this.post.render(dt);
|
|
128
|
+
if (draws) { this.batching.skip(); try { this.post.render(dt); } finally { this.batching.unskip(); } }
|
|
118
129
|
if (this._picture) this._picture.drawing = false;
|
|
119
130
|
for (const f of after) safe(this, STRINGS.onRender, f, null, undefined, ctx);
|
|
120
|
-
} finally { if (own) own.inside--; this._picture?.frameEnd(); }
|
|
131
|
+
} finally { this._poses.undraw(); if (own) own.inside--; this._picture?.frameEnd(); }
|
|
121
132
|
gpu?.end();
|
|
122
133
|
// frames that first draw new objects pay their GPU upload here (Budget.js ApplyCost); a frame that compiled shaders is not judged by adaptive resolution
|
|
123
134
|
this._compiled = this.budget.cost.rendered(performance.now() - t0, programCount(r) ?? -1, t0 / 1000); // measure
|
|
124
|
-
if (DEV && this.ready && !this._probing)
|
|
135
|
+
if (DEV && this.ready && !this._probing) {
|
|
136
|
+
watchLights(this); // dev: a light added / removed mid-play compiled new shaders (one long frame): say so (lightWatch.js)
|
|
137
|
+
watchGeometries(this, dt); // dev: geometries piling up that nothing in the scene uses (geometryWatch.js)
|
|
138
|
+
}
|
|
139
|
+
this._records?.step(dt); // WebGPU: free the records of meshes that left the scene, a slice per frame (render/recordSweep.js)
|
|
125
140
|
},
|
|
126
141
|
_runHooks(kind, dt) {
|
|
127
142
|
const p = this._prof;
|
|
128
|
-
const was = this._curModule;
|
|
129
|
-
for (const h of
|
|
130
|
-
|
|
143
|
+
const was = this._curModule, list = this._hooks[kind];
|
|
144
|
+
for (const h of list) {
|
|
145
|
+
if (this._hooks[kind] !== list && !this._hooks[kind].includes(h)) continue; // its module went earlier in this pass (unuse, disabled): no hook after its dispose
|
|
146
|
+
const key = h.key ??= fmt(STRINGS.hook, { name: h.name, kind }); // build the key once
|
|
131
147
|
const opts = h.opts ??= { module: h.mod };
|
|
132
148
|
this._curModule = h.mod; // the module type checks (moduleTypes.js) know whose hook is writing
|
|
133
149
|
if (!p) { safe(this, key, h.fn, opts, undefined, dt, this); continue; }
|
|
@@ -148,7 +164,7 @@ export const loopMethods = {
|
|
|
148
164
|
return r;
|
|
149
165
|
},
|
|
150
166
|
|
|
151
|
-
// ---------- nextFixed (
|
|
167
|
+
// ---------- nextFixed (halt / freeze / runState live in holds.js; step() below is the deterministic way to advance) ----------
|
|
152
168
|
/**
|
|
153
169
|
* Run fn at the start of the next fixed step (before that step's fixed hooks), from any callback (UI click, promise, worker result): gameplay state is safe to write there.
|
|
154
170
|
* Returns a Promise of fn's value (rejects if fn throws). Waits while frozen or loading. Built on engine.commits: applies in request order and survives save loads.
|
|
@@ -173,13 +189,15 @@ export const loopMethods = {
|
|
|
173
189
|
let acc = Math.min((this._acc || 0) + dt, MAX_CATCHUP), n = 0;
|
|
174
190
|
const f0 = performance.now(); // measure
|
|
175
191
|
let s0 = f0;
|
|
176
|
-
while (acc >= STEP) {
|
|
192
|
+
while (acc >= STEP && !this.disposed) { // a hook may dispose the engine
|
|
177
193
|
this._fixedStep(); acc -= STEP; n++;
|
|
178
194
|
const t = performance.now(); // measure
|
|
179
195
|
if (acc >= STEP && t - f0 + (t - s0) > CATCHUP_MS) { acc %= STEP; break; } // the next one would go over: drop the rest
|
|
180
196
|
s0 = t;
|
|
181
197
|
}
|
|
182
198
|
this._acc = acc;
|
|
199
|
+
// held while frozen: with no fixed steps positions stand still, and a moving ratio would make interpolated things shake in place
|
|
200
|
+
if (!this.frozen) this.stepBlend = acc / STEP;
|
|
183
201
|
return n;
|
|
184
202
|
},
|
|
185
203
|
|
|
@@ -191,14 +209,14 @@ export const loopMethods = {
|
|
|
191
209
|
const tick = now => {
|
|
192
210
|
if (this.disposed) return;
|
|
193
211
|
this._raf = requestAnimationFrame(tick);
|
|
194
|
-
const dt = Math.min(0.25, (now - last) / 1000); last = now;
|
|
195
|
-
if (this.
|
|
212
|
+
const dt = Math.min(0.25, Math.max(0, now - last) / 1000); last = now; // max: the first frame's timestamp can be older than the performance.now() above
|
|
213
|
+
if (this.halted) { this._acc = 0; return; } // halted: no advance, no render
|
|
196
214
|
// Adaptive resolution judges the frames up to the last one (cpuMs, GPU time and _compiled still describe it) and changes the
|
|
197
215
|
// render scale here, before this frame draws. Why not after the render: a canvas resize clears its drawing buffer, so a change made
|
|
198
216
|
// after the draw handed the compositor a blank frame (R2: a screenshot caught the 1 -> 0.9 frame black). Not counted in cpuMs
|
|
199
217
|
this._adapt(dt);
|
|
200
218
|
this._compiled = false;
|
|
201
|
-
// CPU time of one frame = main-thread work from here to the end of the afterRender hooks, in four phases (engine.
|
|
219
|
+
// CPU time of one frame = main-thread work from here to the end of the afterRender hooks, in four phases (engine._cpuPhases):
|
|
202
220
|
// fixed (input poll + fixed steps), frame (onFrame + module frame hooks + stream / jobs / batching), render (submitting the draw
|
|
203
221
|
// calls: three.js CPU work, upload of new objects, shader compiles; not GPU time), afterRender (module hooks). Adaptive resolution
|
|
204
222
|
// (before, above) and the startup readiness check (after) are not counted. Budget is sampled last so it sees this frame, not the previous one.
|
|
@@ -206,8 +224,8 @@ export const loopMethods = {
|
|
|
206
224
|
let c1, c2, c3;
|
|
207
225
|
try {
|
|
208
226
|
this.input.poll(dt);
|
|
209
|
-
//
|
|
210
|
-
if (this.page.
|
|
227
|
+
// coming back from a hidden tab drops the time spent away, so play resumes without a burst of steps (page.js)
|
|
228
|
+
if (this.page.consumeResync()) this._acc = 0;
|
|
211
229
|
else this._catchUp(dt);
|
|
212
230
|
c1 = performance.now(); // measure
|
|
213
231
|
this._frameHooks(dt);
|
|
@@ -219,9 +237,9 @@ export const loopMethods = {
|
|
|
219
237
|
if (this._readyAt != null && this.ready) firstFrame(this, c3);
|
|
220
238
|
} finally { this.input.endFrame(); }
|
|
221
239
|
this._runHooks('afterRender', dt);
|
|
222
|
-
const c4 = performance.now(), P = this.
|
|
240
|
+
const c4 = performance.now(), P = this._cpuPhases; // measure
|
|
223
241
|
P.fixed = c1 - c0; P.frame = c2 - c1; P.render = c3 - c2; P.afterRender = c4 - c3;
|
|
224
|
-
this.
|
|
242
|
+
this._cpuMs = c4 - c0;
|
|
225
243
|
this.budget.sample(dt);
|
|
226
244
|
this.fps += (1 / Math.max(dt, 1e-3) - this.fps) * 0.05;
|
|
227
245
|
this._afterTick?.();
|
|
@@ -230,7 +248,7 @@ export const loopMethods = {
|
|
|
230
248
|
},
|
|
231
249
|
|
|
232
250
|
/**
|
|
233
|
-
* Advance synchronously by seconds of real (fixed-step) time; channels and the calendar advance by their own scales (core/time.js): fixed hooks run at 60 Hz;
|
|
251
|
+
* Advance synchronously by seconds of real (fixed-step) time; channels and the calendar advance by their own scales (core/time/time.js): fixed hooks run at 60 Hz;
|
|
234
252
|
* frame hooks run once per frameEvery fixed steps (default 2, i.e. 30 Hz, dt = 1/30),
|
|
235
253
|
* so fast-forwarding 600 seconds runs only 18000 frame-hook calls with no rendering and finishes in seconds. Renders one frame at the end when
|
|
236
254
|
* render is true.
|
|
@@ -241,24 +259,27 @@ export const loopMethods = {
|
|
|
241
259
|
* cutscene across several step calls.
|
|
242
260
|
* seconds must be a finite number >= 0: step(0) advances nothing (no fixed step, no render), a negative or non-finite value throws; any positive
|
|
243
261
|
* value runs at least one fixed step. While start() is still loading it runs frame hooks only (no game time passes until engine.phase is
|
|
244
|
-
* 'ready').
|
|
262
|
+
* 'ready'); in dev that, and a step during a session change nobody awaited, warns once.
|
|
245
263
|
* Returns the result of describe() (null with { describe: false }, which callers that ignore it pass to skip the work).
|
|
246
264
|
*/
|
|
247
265
|
step(seconds, { render = true, frameEvery = 2, describe = true } = {}) {
|
|
248
266
|
if (this.disposed) return null; // nothing advances after dispose
|
|
249
267
|
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0)
|
|
250
268
|
throw codedError('step-seconds',
|
|
251
|
-
`engine.step(${String(seconds)}): seconds must be a finite number >= 0, e.g. engine.step(0.5) (
|
|
269
|
+
`engine.step(${String(seconds)}): seconds must be a finite number >= 0, e.g. engine.step(0.5) (real seconds; 1 / 60 is one fixed step)`);
|
|
252
270
|
if (seconds === 0) return describe ? this.describe() : null; // 0 advances nothing (a tiny positive value still runs one fixed step)
|
|
271
|
+
if (DEV && (this._inStart || this.session._busy)) warnOnce(coded('step-during-load', this._inStart ? STRINGS.stepStart : STRINGS.stepSession), 'step-during-load');
|
|
253
272
|
const n = Math.max(1, Math.round(seconds / STEP));
|
|
273
|
+
this.stepBlend = 1; // step() takes the state to the end of each step, so the latest state is what cameras read and what gets drawn
|
|
254
274
|
let since = 0;
|
|
255
|
-
for (let i = 0; i < n; i++) {
|
|
275
|
+
for (let i = 0; i < n && !this.disposed; i++) { // a hook may dispose the engine
|
|
256
276
|
this._fixedStep();
|
|
257
277
|
if (++since >= frameEvery || i === n - 1) {
|
|
258
278
|
try { this._frameHooks(since * STEP, true); } finally { this.input.endFrame(); }
|
|
259
279
|
since = 0;
|
|
260
280
|
}
|
|
261
281
|
}
|
|
282
|
+
if (this.disposed) return null;
|
|
262
283
|
if (render) {
|
|
263
284
|
safe(this, STRINGS.render, this._render, SOFT, this, STEP);
|
|
264
285
|
this._runHooks('afterRender', STEP);
|
|
@@ -266,6 +287,6 @@ export const loopMethods = {
|
|
|
266
287
|
return describe ? this.describe() : null; // describe: false for internal loops that ignore the result (describe() walks every module)
|
|
267
288
|
},
|
|
268
289
|
|
|
269
|
-
// Adaptive resolution (core/adaptive.js): judged on frame cost; tests drive it with explicit cost / compiled values
|
|
270
|
-
_adapt(dt, cost = Math.max(this.
|
|
290
|
+
// Adaptive resolution (core/scene/adaptive.js): judged on frame cost; tests drive it with explicit cost / compiled values
|
|
291
|
+
_adapt(dt, cost = Math.max(this._cpuMs, this._gpu?.ms ?? 0), compiled = !!this._compiled, gpuKnown = this._gpu?.ms != null) { adapt(this, dt, cost, compiled, gpuKnown); },
|
|
271
292
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Exclusive slots for modules ("only one may hold this": 'sky', 'inventory', a tone-mapping stage), mixed into Engine with modules.js.
|
|
2
|
-
// provides: ['inventory'] the module holds the slot while installed (a kind 'one' shared point, core/sharedPoint.js);
|
|
2
|
+
// provides: ['inventory'] the module holds the slot while installed (a kind 'one' shared point, core/ops/sharedPoint.js);
|
|
3
3
|
// a second provider is shared-taken, naming both and the replaces fix
|
|
4
4
|
// requires: ['inventory'] depend on the slot, not on whichever module gives it
|
|
5
5
|
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries, drawing parts, dispose)
|
|
6
6
|
// Why the slot is a shared point and not a module-name table: one owner registry for everything (describe().shared shows the holder beside
|
|
7
7
|
// every shared value, ctx.track releases it with the rest), so there is no second mechanism to learn. Kept apart from modules.js only for size.
|
|
8
|
-
import { DEV, fmt, closest, warnOnce } from '
|
|
9
|
-
import { codedError, coded } from '
|
|
10
|
-
import { reportError } from '
|
|
11
|
-
import { PICTURE_SLOTS } from '
|
|
8
|
+
import { DEV, fmt, closest, warnOnce } from '../base/validate.js';
|
|
9
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
10
|
+
import { reportError } from '../base/errors.js';
|
|
11
|
+
import { PICTURE_SLOTS } from '../scene/pictureSlots.js';
|
|
12
12
|
|
|
13
13
|
const STRINGS = {
|
|
14
14
|
provides: 'module {name}: provides is a list of exclusive slot names, e.g. provides: [\'inventory\']; got {got}',
|
|
@@ -79,7 +79,7 @@ export const slotMethods = {
|
|
|
79
79
|
this._dropTracked(name);
|
|
80
80
|
try { m.dispose?.(this); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
|
|
81
81
|
this._picture?.partGone(m, swapping);
|
|
82
|
-
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
|
|
82
|
+
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); this.disabledModules.delete(name); delete this[name];
|
|
83
83
|
this._sortHooks();
|
|
84
84
|
return m;
|
|
85
85
|
},
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
// Module types: what a module may own (a module's `stage` only says when it runs; its `type` says what it may own and how its errors are handled:
|
|
2
|
-
// picture / ui fail soft, see core/errors.js). Mixed into Engine with modules.js.
|
|
3
|
-
// type: 'world' | 'picture' | 'actor' | 'rules' | 'ui' | 'net' | 'tool' --
|
|
2
|
+
// picture / ui fail soft, see core/base/errors.js). Mixed into Engine with modules.js.
|
|
3
|
+
// type: 'world' | 'picture' | 'actor' | 'rules' | 'ui' | 'net' | 'tool' -- optional: a module without one is 'rules', game logic. An unknown name is an error (a typo).
|
|
4
4
|
// Why a type and not a rule in the docs: an AI follows the shape of the code, not a paragraph. A picture module that defines an op, or a ui module that binds
|
|
5
|
-
// keys, is the start of two modules owning one thing; the check
|
|
5
|
+
// keys, is often the start of two modules owning one thing; the check says so once, with the one-line fix, where it happens. It warns and never refuses: a game's
|
|
6
|
+
// own module may do what it needs, and only the game knows when that split is right.
|
|
6
7
|
// No subtypes: differences inside a type are the declarations the engine already checks (provides, requires, shared values written with ctx.mod,
|
|
7
8
|
// material slots patched, the post stage, backends, sounds).
|
|
8
9
|
// The checks are dev only and cheap: the engine knows which module is installing (install and the synchronous part of init) or running a hook
|
|
9
10
|
// (fixed / frame / afterRender / skip), and the few write points below ask it. A callback a module registered (an event listener, a timer) is not
|
|
10
11
|
// attributed: the check is a guard rail at the common places, not a sandbox.
|
|
11
|
-
import { DEV, fmt } from '
|
|
12
|
-
import { codedError } from '
|
|
13
|
-
import { callerAt } from '
|
|
12
|
+
import { DEV, fmt, warnOnce } from '../base/validate.js';
|
|
13
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
14
|
+
import { callerAt } from '../ops/stackFrames.js';
|
|
14
15
|
|
|
15
|
-
/** type -> what it may own (shown in the
|
|
16
|
+
/** type -> what it may own (shown in the unknown type error and in recipes/14) */
|
|
16
17
|
export const MODULE_TYPES = {
|
|
17
18
|
world: 'game state: save parts, world records, ops, ground / collision / navigation data (draws nothing)',
|
|
18
19
|
picture: 'what is seen and heard: picture values, three.js objects, particles, sounds (changes no game state)',
|
|
@@ -24,7 +25,6 @@ export const MODULE_TYPES = {
|
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
const STRINGS = {
|
|
27
|
-
missing: "module {name} has no type. Every module says what it owns. Fix: add type: '{guess}' to the module definition ({name}: { name: '{name}', type: '{guess}', ... }). Types: {list}",
|
|
28
28
|
unknown: "module {name} has type '{type}', which is not a module type. Fix: use one of {list}",
|
|
29
29
|
// rule broken at runtime: module, type, what it did, why not, the fix
|
|
30
30
|
broke: "module {name} (type '{type}') {did}: {why}. Fix: {fix}",
|
|
@@ -41,15 +41,14 @@ const RULES = {
|
|
|
41
41
|
'keep preferences in browser storage (engine.settings does), and game state in a rules / world module'],
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
/** _planUse:
|
|
44
|
+
/** _planUse: no type is 'rules'; any other must be one of MODULE_TYPES (unknown = error naming the fix) */
|
|
45
45
|
export function checkType(m) {
|
|
46
|
-
|
|
47
|
-
if (m.type
|
|
48
|
-
if (!(m.type in MODULE_TYPES)) throw codedError('module-type', fmt(STRINGS.unknown, { name: m.name, type: String(m.type), list }));
|
|
46
|
+
m.type ??= 'rules';
|
|
47
|
+
if (!Object.hasOwn(MODULE_TYPES, m.type)) throw codedError('module-type', fmt(STRINGS.unknown, { name: m.name, type: String(m.type), list: Object.keys(MODULE_TYPES).map(t => `'${t}'`).join(' | ') }));
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/**
|
|
52
|
-
* @internal dev check at a write point: the module installing or running a hook now
|
|
51
|
+
* @internal dev check at a write point: warns once when the module installing or running a hook now does `what` and its type does not usually own it.
|
|
53
52
|
* what: 'ops.define' | 'world.write' | 'input.bind' | 'saves.register'; did: what it did, for the message ("defined op shop.buy").
|
|
54
53
|
*/
|
|
55
54
|
export function checkTypeRule(e, what, did) {
|
|
@@ -58,7 +57,7 @@ export function checkTypeRule(e, what, did) {
|
|
|
58
57
|
const [types, why, fix] = RULES[what];
|
|
59
58
|
if (!types.includes(m.type)) return;
|
|
60
59
|
const v = { name: m.name, type: m.type };
|
|
61
|
-
|
|
60
|
+
warnOnce(coded('module-type-rule', fmt(STRINGS.broke, { ...v, did, why: fmt(why, v), fix: fmt(fix, v) })), `module-type-rule:${what}:${m.name}`);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
/** @internal run fn with m as the current module (install, init's synchronous part, a hook); restores the previous one */
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// Every install is its own instance (engine._modInst: name -> token): a ctx belongs to one install, not to a name. An async init that resumes after
|
|
25
25
|
// its module was unloaded (replaces, a plugin removed) and a same-named one installed must not act on the newcomer: what the stale ctx tracks is
|
|
26
26
|
// removed at once (dev warning naming the module), and its completion or failure changes no state and drops no handle of the newcomer.
|
|
27
|
-
// Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/sharedPoint.js) for the module before its install;
|
|
27
|
+
// Exclusive slots: provides: ['inventory'] takes each named slot (a kind 'one' shared point, core/ops/sharedPoint.js) for the module before its install;
|
|
28
28
|
// a second provider is shared-taken. requires may name a slot instead of a module. engine.use(mine(), { replaces: 'inventory' }) unloads the
|
|
29
29
|
// holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails.
|
|
30
30
|
// critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (picture / ui: disabled;
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
// Dependencies: requires must be installed first (throws if missing). optional is a soft dependency: an array is only recorded (for GAMEMAP and rule R16);
|
|
33
33
|
// written as { module: 'what is lost without it' }, start() warns once in dev when it is missing: use this form for optional dependencies
|
|
34
34
|
// that change gameplay results, which must not be skipped silently.
|
|
35
|
-
import { warnOnce, DEV, fmt, closest } from '
|
|
36
|
-
import { codedError, coded } from '
|
|
37
|
-
import { reportError } from '
|
|
38
|
-
import { catalog, catalogSnap, catalogClaim } from '
|
|
39
|
-
import { readParams } from '
|
|
35
|
+
import { warnOnce, DEV, fmt, closest } from '../base/validate.js';
|
|
36
|
+
import { codedError, coded } from '../base/errorHints.js';
|
|
37
|
+
import { reportError } from '../base/errors.js';
|
|
38
|
+
import { catalog, catalogSnap, catalogClaim } from '../inspect/catalog.js';
|
|
39
|
+
import { readParams } from '../base/params.js';
|
|
40
40
|
import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
|
|
41
41
|
import { checkType, asModule } from './moduleTypes.js';
|
|
42
42
|
|
|
@@ -85,10 +85,13 @@ function sortModules(list) {
|
|
|
85
85
|
}
|
|
86
86
|
if (out.length === list.length) return out;
|
|
87
87
|
// What is left is on a cycle or behind one: walk edges from any node; revisiting a node closes the cycle
|
|
88
|
+
// First drop, repeatedly, the nodes with no successor still left: those are only blocked behind a cycle (a walk starting there would dead-end
|
|
89
|
+
// on a node without a next step); every node that remains has a successor in the set, so the walk always ends in a real cycle
|
|
88
90
|
const left = new Set(list.filter(m => !out.includes(m)).map(m => m.name)), path = [];
|
|
91
|
+
for (let drop = true; drop;) { drop = false; for (const n of left) if (![...succ.get(n)].some(x => left.has(x))) { left.delete(n); drop = true; } }
|
|
89
92
|
for (let n = left.values().next().value; !path.includes(n); n = [...succ.get(n)].find(x => left.has(x))) path.push(n);
|
|
90
93
|
const cyc = path.slice(path.indexOf([...succ.get(path.at(-1))].find(x => path.includes(x))));
|
|
91
|
-
throw codedError('module-cycle', STRINGS.cycle
|
|
94
|
+
throw codedError('module-cycle', fmt(STRINGS.cycle, { path: [...cyc, cyc[0]].join(' -> ') }));
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
/** before / after across stages must agree with the stage order (the stage always wins), else the declaration would be silently ignored:
|
|
@@ -135,7 +138,7 @@ export const moduleMethods = {
|
|
|
135
138
|
// engine.<slot> is the provider's API too, so a module that requires 'inventory' reaches the game's own bag at engine.inventory after
|
|
136
139
|
// a replaces: dependents name the capability, never the module that gives it
|
|
137
140
|
for (const slot of m.provides ?? []) if (slot !== m.name) { this[slot] = api; ctx.track(this._aliasSlot(slot, api)); }
|
|
138
|
-
this._modState.set(m.name, m.init ? (this.
|
|
141
|
+
this._modState.set(m.name, m.init ? (this._initsDone ? 'initializing' : 'registered') : 'running');
|
|
139
142
|
}
|
|
140
143
|
} catch (err) {
|
|
141
144
|
for (const { m, had, prev } of done.reverse()) { // undo in reverse install order, like dispose
|
|
@@ -151,7 +154,7 @@ export const moduleMethods = {
|
|
|
151
154
|
throw err;
|
|
152
155
|
}
|
|
153
156
|
this._sortHooks();
|
|
154
|
-
if (this.
|
|
157
|
+
if (this._initsDone) for (const m of plan) if (m.init) this._lateInit(m);
|
|
155
158
|
return this;
|
|
156
159
|
},
|
|
157
160
|
/** @internal validate a batch without touching the engine (so a failure leaves nothing half-installed);
|
|
@@ -216,7 +219,7 @@ export const moduleMethods = {
|
|
|
216
219
|
let set = this._modTracked.get(name);
|
|
217
220
|
if (!set) this._modTracked.set(name, set = new Set());
|
|
218
221
|
set.add(h);
|
|
219
|
-
if (this._curModule === m) this._picture?.learn(m); // the module's own code called this: its file is the part's (core/pictureWriters.js)
|
|
222
|
+
if (this._curModule === m) this._picture?.learn(m); // the module's own code called this: its file is the part's (core/inspect/pictureWriters.js)
|
|
220
223
|
return h;
|
|
221
224
|
};
|
|
222
225
|
// mod: engine.mod with the module as owner, tracked. Why a ctx verb and not "guess the running module": in an async callback the guess is wrong;
|
|
@@ -277,7 +280,7 @@ export const moduleMethods = {
|
|
|
277
280
|
*/
|
|
278
281
|
get moduleStates() { return Object.fromEntries(this._modState); },
|
|
279
282
|
/**
|
|
280
|
-
* What this game can do, read from the registrations (see core/catalog.js): no argument = short list, a module id or op name = that entry expanded.
|
|
283
|
+
* What this game can do, read from the registrations (see core/inspect/catalog.js): no argument = short list, a module id or op name = that entry expanded.
|
|
281
284
|
* @param {string | { find?: string }} [id]
|
|
282
285
|
* @returns {any}
|
|
283
286
|
* @example engine.catalog(); engine.catalog('sky'); engine.catalog('shop.buy'); engine.catalog({ find: 'buy' })
|