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
package/core/assetEntry.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// The life of one engine.assets entry, split from Assets.js (which keeps the public API and the manifest):
|
|
2
|
-
// load: fetchEntry runs the load as a task in engine.loading and, for a registered non-critical file that fails, falls back (gray placeholder / silence / the entry's fallback)
|
|
3
|
-
// free: freeEntry gives the GPU memory back, deferred while model copies are still in the scene; shareModel marks what copies share so engine.remove does not dispose it
|
|
4
|
-
// Plain functions that take the Assets instance, so they stay out of the class's public surface.
|
|
5
|
-
import { warnOnce, fmt } from './validate.js';
|
|
6
|
-
import { codedError, coded } from './errorHints.js';
|
|
7
|
-
import { loadGltf, loadTexture, loadFont, generated, placeholder, LoadError } from './assetLoad.js';
|
|
8
|
-
import { failureText } from './Loading.js';
|
|
9
|
-
import { paramValues } from './assetManifest.js';
|
|
10
|
-
|
|
11
|
-
const STRINGS = {
|
|
12
|
-
failed: 'Asset failed to load: {what}',
|
|
13
|
-
fellBack: '; using {fallback} instead, the game continues (mark it critical: true if the game cannot start without it)',
|
|
14
|
-
missingRefs: 'Asset loaded with missing references: {what} (missing {list}); materials show without those files',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/** Mark a model template's geometry and materials as shared (copies share them; engine.remove must not dispose them) */
|
|
18
|
-
function shareModel(a, g) {
|
|
19
|
-
g.scene.traverse(o => { if (o.geometry) a.shared.add(o.geometry); for (const m of [].concat(o.material || [])) a.shared.add(m); });
|
|
20
|
-
return g;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Shadow flags of a model copy, one rule for files, generators and content props: an explicit castShadow / receiveShadow (the model() call,
|
|
25
|
-
* then the manifest entry) wins; otherwise a generator that set either flag on any of its meshes decided for itself and is kept as built
|
|
26
|
-
* (a decal that must not cast stays that way); otherwise (a file, or a generator that set nothing) every mesh casts and receives.
|
|
27
|
-
* @param {import('three').Object3D} root
|
|
28
|
-
* @param {{ castShadow?: boolean, receiveShadow?: boolean }} [set]
|
|
29
|
-
*/
|
|
30
|
-
export function shadowDefaults(root, { castShadow, receiveShadow } = {}) {
|
|
31
|
-
let decided = false;
|
|
32
|
-
root.traverse(o => { if (/** @type {any} */ (o).isMesh && (o.castShadow || o.receiveShadow)) decided = true; });
|
|
33
|
-
const cast = castShadow ?? (decided ? null : true), recv = receiveShadow ?? (decided ? null : true);
|
|
34
|
-
root.traverse(o => { if (/** @type {any} */ (o).isMesh) { if (cast != null) o.castShadow = cast; if (recv != null) o.receiveShadow = recv; } });
|
|
35
|
-
return root;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Load an entry as a task in engine.loading; a registered, non-critical file that fails resolves to its fallback */
|
|
39
|
-
export function fetchEntry(a, e) {
|
|
40
|
-
// shortcut: the stale build stays in memory while its copies live and is not disposed after them; freeing it needs a user count per build, worth it if a game rewrites the palette often
|
|
41
|
-
if (a._stale(e)) e.promise = e.value = null;
|
|
42
|
-
if (e.promise) return e.promise;
|
|
43
|
-
e.palette = a._paletteKey;
|
|
44
|
-
const L = a.engine.loading, name = e.variantOf ?? e.name ?? e.url;
|
|
45
|
-
const t = L._begin(name, e.type, { critical: e.opts.critical === true, url: e.opts.build || e.opts.texture ? null : e.url, manifest: e.manifest ?? null });
|
|
46
|
-
if (e.type === 'model') {
|
|
47
|
-
const load = e.opts.build ? (t.phase('build'), generated(a, e.url, e.opts.build, e.schema ? paramValues(e) : e.opts.params, t)) : loadGltf(a, e.url, t);
|
|
48
|
-
e.promise = load.then(g => shareModel(a, g));
|
|
49
|
-
} else if (e.type === 'texture') e.promise = loadTexture(a, e, t);
|
|
50
|
-
else if (e.type === 'font') e.promise = loadFont(a, e, t);
|
|
51
|
-
else if (e.type === 'sound' && e.opts.build) e.promise = Promise.resolve(e.opts.build); // a synth function: nothing to download
|
|
52
|
-
else if (e.type === 'sound') {
|
|
53
|
-
t.phase('download');
|
|
54
|
-
e.promise = a.engine.audio.load(e.url).catch(err => { throw new LoadError(err.reason ?? err.message, { url: e.url }); }); // reason: the bare cause, the asset line adds name and path
|
|
55
|
-
}
|
|
56
|
-
e.promise = e.promise.then(v => {
|
|
57
|
-
L._done(t);
|
|
58
|
-
const what = `${e.type} "${name}" <- ${e.url}`;
|
|
59
|
-
if (t.missing.length) warnOnce(coded('asset-missing-ref', fmt(STRINGS.missingRefs, { what, list: t.missing.join(', ') })));
|
|
60
|
-
return (e.value = v);
|
|
61
|
-
}, err => failedEntry(a, e, t, err));
|
|
62
|
-
return e.promise;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** A load failed: a registered file entry degrades (warn + fallback); anything else is recorded and rethrown to the caller */
|
|
66
|
-
function failedEntry(a, e, t, err) {
|
|
67
|
-
e.promise = null;
|
|
68
|
-
const degrade = e.named && !e.opts.build && !e.opts.critical;
|
|
69
|
-
const fb = degrade ? (e.opts.fallback ?? (e.type === 'sound' ? 'silence' : e.type === 'font' ? 'the system font' : 'gray placeholder')) : null;
|
|
70
|
-
a.engine.loading._fail(t, err, fb);
|
|
71
|
-
const msg = fmt(STRINGS.failed, { what: failureText(t) });
|
|
72
|
-
if (!degrade) throw codedError('asset-load', msg);
|
|
73
|
-
warnOnce(coded('asset-load', msg + fmt(STRINGS.fellBack, { fallback: e.opts.fallback ? `"${fb}"` : fb })));
|
|
74
|
-
if (e.opts.fallback) return (e.promise = fetchEntry(a, a._resolve(e.opts.fallback, e.type))); // e.value stays null: the fallback entry owns the memory
|
|
75
|
-
e.value = e.type === 'model' ? shareModel(a, placeholder('model')) : placeholder(e.type);
|
|
76
|
-
return (e.promise = Promise.resolve(e.value));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Free an entry's GPU memory; while model copies are still in use it waits (releasePending) and the last engine.remove frees it */
|
|
80
|
-
export function freeEntry(e) {
|
|
81
|
-
if (!e.value) return;
|
|
82
|
-
if (e.users > 0) { e.releasePending = true; return; }
|
|
83
|
-
if (e.type === 'texture' && !e.opts.texture) e.value.dispose(); // a Texture the game registered is the game's: never disposed here
|
|
84
|
-
if (e.type === 'font') document.fonts.delete(e.value); // a released font stops matching its family
|
|
85
|
-
if (e.value.isBufferGeometry) e.value.dispose(); // code-generated geometry
|
|
86
|
-
else if (e.type === 'model') {
|
|
87
|
-
(e.value.scene ?? e.value).traverse?.(o => {
|
|
88
|
-
if (!o.isMesh) return;
|
|
89
|
-
o.geometry.dispose();
|
|
90
|
-
[].concat(o.material).forEach(m => { for (const k in m) if (m[k]?.isTexture) m[k].dispose(); m.dispose(); });
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
e.value = null; e.promise = null; e.releasePending = e.pinned = false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Load the entries preload() wants and report progress; returns { loaded, failed, ok } (Assets.preload documents it) */
|
|
97
|
-
export async function preloadEntries(a, onProgress, onlyMarked) {
|
|
98
|
-
// generators and fonts only when marked: a font pack may hold many faces, and only those ui.fonts names (or preload: true) are wanted
|
|
99
|
-
const list = [...a.entries.entries()].filter(([, e]) => e.opts.build || e.type === 'font' ? e.opts.preload : !onlyMarked || e.opts.preload);
|
|
100
|
-
let done = 0;
|
|
101
|
-
onProgress?.(list.length ? 0 : 1, '');
|
|
102
|
-
// critical failures are reported by start(); others not already warned about (generated models) are warned here
|
|
103
|
-
await Promise.all(list.map(([name, e]) => fetchEntry(a, e).catch(err => { if (!e.opts.critical) warnOnce(err.message); }).finally(() => {
|
|
104
|
-
done++;
|
|
105
|
-
onProgress?.(done / list.length, name);
|
|
106
|
-
})));
|
|
107
|
-
const failed = list.filter(([name, e]) => a.engine.loading.get(name, e.type)?.phase === 'failed').map(([name]) => name);
|
|
108
|
-
return { loaded: list.length - failed.length, failed, ok: !failed.length };
|
|
109
|
-
}
|
package/core/engineCamera.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// engine.camera's class: a THREE.PerspectiveCamera that can also draw orthographic (camera rigs with projection: 'orthographic').
|
|
2
|
-
//
|
|
3
|
-
// Why a subclass and not a swap to THREE.OrthographicCamera: engine.camera is one object that the render pass, post chain, cascaded shadows,
|
|
4
|
-
// sky, particles and every module hold a reference to; a swap would leave them drawing with the old camera. Why not a method replaced on the
|
|
5
|
-
// instance: that would be a second, invisible takeover form on a plain three.js object that nothing reports. Here the behavior is the class's
|
|
6
|
-
// own method, marked by camera.isEngineCamera and reported by describe().camera.projection; a game that wants a real THREE.OrthographicCamera renders with its own (engine.renderer.render(scene, cam)).
|
|
7
|
-
// While orthoSize is set, isPerspectiveCamera / isOrthographicCamera and left / right / top / bottom follow, so code that branches on the camera
|
|
8
|
-
// type (three's renderer, raycaster, CSM) keeps working. Resize needs nothing extra: canvasBox sets camera.aspect and calls updateProjectionMatrix().
|
|
9
|
-
import * as THREE from 'three';
|
|
10
|
-
|
|
11
|
-
export class EngineCamera extends THREE.PerspectiveCamera {
|
|
12
|
-
constructor(fov, aspect, near, far) {
|
|
13
|
-
super(fov, aspect, near, far);
|
|
14
|
-
/** World units covered by the view height while orthographic (before zoom); 0 = perspective. Set through a camera rig's projection */
|
|
15
|
-
this.orthoSize = 0;
|
|
16
|
-
/** Marks engine.camera's class (minified builds rename it): the orthographic switch lives in this class, never on the instance */
|
|
17
|
-
this.isEngineCamera = true;
|
|
18
|
-
}
|
|
19
|
-
updateProjectionMatrix() {
|
|
20
|
-
if (!this.orthoSize) return super.updateProjectionMatrix();
|
|
21
|
-
const top = this.orthoSize / 2 / this.zoom, right = top * this.aspect;
|
|
22
|
-
this.left = -right; this.right = right; this.top = top; this.bottom = -top;
|
|
23
|
-
this.projectionMatrix.makeOrthographic(-right, right, top, -top, this.near, this.far, this.coordinateSystem);
|
|
24
|
-
this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
|
|
25
|
-
}
|
|
26
|
-
copy(source, recursive) {
|
|
27
|
-
super.copy(source, recursive);
|
|
28
|
-
this.orthoSize = source.orthoSize ?? 0;
|
|
29
|
-
this.isOrthographicCamera = !!this.orthoSize; this.isPerspectiveCamera = !this.orthoSize;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
}
|
package/core/ground.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// Ground API (part of Engine, mixed into Engine.prototype): whoever provides ground height is the "terrain" -- a procedural terrain module, a hand-made level, or a flat plane.
|
|
2
|
-
// The queries below take (x, z), or a Vector3 / Object3D directly: engine.surface(mesh.position)
|
|
3
|
-
import { xzOf } from './math.js';
|
|
4
|
-
import { DEV } from './validate.js';
|
|
5
|
-
import { readParams, keysSchema } from './params.js';
|
|
6
|
-
import { codedError } from './errorHints.js';
|
|
7
|
-
|
|
8
|
-
// Default ground: an infinite flat plane at y = 0. A terrain or level module replaces it
|
|
9
|
-
export const flatGround = {
|
|
10
|
-
height: () => 0, slope: () => 0, type: () => 'default', waterLevel: -Infinity,
|
|
11
|
-
// is there ground at (x, z): false only off the outline of terrain({ shape }), where height is -Infinity
|
|
12
|
-
has: () => true,
|
|
13
|
-
// height below which something has fallen out of the world (terrain:void); only an outline sets a finite one
|
|
14
|
-
voidY: () => -Infinity,
|
|
15
|
-
};
|
|
16
|
-
const NO_GROUND = '{who}: there is no ground at ({x}, {z}) (outside terrain({ shape })){left}; check engine.ground.has(x, z) first';
|
|
17
|
-
const noGround = (who, x, z, left = '') => NO_GROUND.replace('{who}', who).replace('{x}', x.toFixed(1)).replace('{z}', z.toFixed(1)).replace('{left}', left);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Ground height for a place-it-here entry (spawn, props, pickups, npcs, placeAt). Beyond terrain({ shape }) surface() is -Infinity, and that must never
|
|
21
|
-
* reach a position (a save turns it into null / NaN and the object vanishes): dev throws with the fix, release keeps `fallback`. @internal
|
|
22
|
-
*/
|
|
23
|
-
export function placeY(e, who, x, z, refY, fallback = 0) {
|
|
24
|
-
const y = e.surface(x, z, refY);
|
|
25
|
-
if (y !== -Infinity) return y;
|
|
26
|
-
if (DEV) throw codedError('ground-missing', noGround(who, x, z));
|
|
27
|
-
return fallback;
|
|
28
|
-
}
|
|
29
|
-
/** Ground height for a visual-only reader (hud anchor, grid tiles, camera start, shot path): off the island use `fallback`, never throw. @internal */
|
|
30
|
-
export function surfaceOr(e, x, z, refY, fallback = 0) {
|
|
31
|
-
const y = e.surface(x, z, refY);
|
|
32
|
-
return y === -Infinity ? fallback : y;
|
|
33
|
-
}
|
|
34
|
-
const WATER_KEYS = ['position', 'radius', 'halfWidth', 'halfDepth', 'level'];
|
|
35
|
-
|
|
36
|
-
// engine.ground.forEachCollider = the provider's own followed by every added source; absent when there is none
|
|
37
|
-
function joinColliders(e) {
|
|
38
|
-
const own = e._groundOwn ?? null, extra = e._groundExtra ?? [];
|
|
39
|
-
const all = own ? [own, ...extra] : extra.slice();
|
|
40
|
-
const g = { ...e.ground };
|
|
41
|
-
if (all.length) g.forEachCollider = (x, z, range, fn) => { for (let i = 0; i < all.length; i++) all[i](x, z, range, fn); };
|
|
42
|
-
else delete g.forEachCollider;
|
|
43
|
-
e.ground = g;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const groundMethods = {
|
|
47
|
-
setGround(g) { this._groundOwn = g.forEachCollider ?? null; this.ground = { ...flatGround, ...g }; joinColliders(this); },
|
|
48
|
-
/**
|
|
49
|
-
* @internal module plumbing: add a source of static circle colliders (x, z, r) to engine.ground.forEachCollider, which collision and path
|
|
50
|
-
* planning read. It survives a later setGround (a level installed after the module), so a module streaming its own colliders
|
|
51
|
-
* (plants scattered over a level model) need not care who provides the ground. Returns { remove() }
|
|
52
|
-
* @param {(x: number, z: number, range: number, fn: (x: number, z: number, r: number) => void) => void} forEach
|
|
53
|
-
*/
|
|
54
|
-
addGroundColliders(forEach) {
|
|
55
|
-
const list = (this._groundExtra ||= []);
|
|
56
|
-
list.push(forEach); joinColliders(this);
|
|
57
|
-
return { remove: () => { const i = list.indexOf(forEach); if (i >= 0) { list.splice(i, 1); joinColliders(this); } } };
|
|
58
|
-
},
|
|
59
|
-
/** Ground height. For multi-layer ground (bridges, caves) pass a reference height refY: it picks the highest layer not above refY plus one step; without it, the highest layer. When passing an object, the second argument is refY */
|
|
60
|
-
surface(x, z, refY) {
|
|
61
|
-
if (typeof x === 'object') { refY = z; [x, z] = xzOf(x); }
|
|
62
|
-
return this.ground.height(x, z, refY);
|
|
63
|
-
},
|
|
64
|
-
/** Slope */
|
|
65
|
-
slope(x, z) { if (typeof x === 'object') [x, z] = xzOf(x); return this.ground.slope(x, z); },
|
|
66
|
-
/** Ground type (grass, sand...), used by footsteps and particles */
|
|
67
|
-
groundType(x, z) { if (typeof x === 'object') [x, z] = xzOf(x); return this.ground.type(x, z); },
|
|
68
|
-
/** Put an object on the ground beneath it (y = ground height + offset); returns the object. With multi-layer ground the object's current y is the reference height: things under a bridge stay on the ground, things on it land on the deck */
|
|
69
|
-
snapToGround(obj, offset = 0) {
|
|
70
|
-
const p = obj.position, y = this.surface(p.x, p.z, p.y);
|
|
71
|
-
if (y === -Infinity) { // never write an infinite y: the object would vanish and poison bounds and physics
|
|
72
|
-
if (DEV) throw codedError('ground-missing', noGround('engine.snapToGround()', p.x, p.z, ', so the object was left where it is'));
|
|
73
|
-
return obj;
|
|
74
|
-
}
|
|
75
|
-
p.y = y + offset; return obj;
|
|
76
|
-
},
|
|
77
|
-
/** Water surface height at a point: water bodies (lake, pond, river segment) first, else the global water level; -Infinity if there is no water */
|
|
78
|
-
waterAt(x, z) {
|
|
79
|
-
if (typeof x === 'object') [x, z] = xzOf(x);
|
|
80
|
-
let lv = this.ground.waterLevel;
|
|
81
|
-
const bodies = this.waterBodies;
|
|
82
|
-
for (let i = 0; i < bodies.length; i++) { // indexed: runs per sample, no iterator
|
|
83
|
-
const b = bodies[i];
|
|
84
|
-
const inside = b.radius != null ? (x - b.x) ** 2 + (z - b.z) ** 2 < b.radius * b.radius
|
|
85
|
-
: Math.abs(x - b.x) < b.hw && Math.abs(z - b.z) < b.hd;
|
|
86
|
-
if (inside && b.level > lv) lv = b.level;
|
|
87
|
-
}
|
|
88
|
-
return lv;
|
|
89
|
-
},
|
|
90
|
-
/** Add a water body: a circle { position, radius, level } or a rectangle { position, halfWidth, halfDepth, level } (meters). Returns a handle { body, remove() }. The water module draws it */
|
|
91
|
-
addWaterBody(opts) {
|
|
92
|
-
readParams('engine.addWaterBody()', keysSchema(WATER_KEYS), opts);
|
|
93
|
-
const [x, z] = xzOf(opts.position);
|
|
94
|
-
const b = opts.radius != null ? { x, z, radius: opts.radius, level: opts.level }
|
|
95
|
-
: { x, z, hw: opts.halfWidth ?? 1, hd: opts.halfDepth ?? 1, level: opts.level };
|
|
96
|
-
this.waterBodies.push(b); this.events.emit('water:add', b);
|
|
97
|
-
const remove = () => {
|
|
98
|
-
if (!this.waterBodies.includes(b)) return;
|
|
99
|
-
this.waterBodies = this.waterBodies.filter(x => x !== b);
|
|
100
|
-
this.events.emit('water:remove', b);
|
|
101
|
-
};
|
|
102
|
-
return { body: b, remove };
|
|
103
|
-
},
|
|
104
|
-
};
|
package/core/holds.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// Who holds the engine still: pause, freeze (each ends with its handle's remove()), runState, and the camera takeover (takeCamera / cameraOverride).
|
|
2
|
-
// Each is a named stack (core/stacks.js: 'pause' and 'freeze' kind any, 'camera' kind top), so they follow the same owner rules as every shared quantity:
|
|
3
|
-
// engine.freeze('menu') is engine.mod('freeze', { owner: 'menu' }) with the loop's side effects added (ending the last pause restarts the loop).
|
|
4
|
-
// One entry per mechanism: the handle's remove() ends a pause / freeze (there is no engine.resume / engine.unfreeze).
|
|
5
|
-
import { warnOnce } from './validate.js';
|
|
6
|
-
import { coded } from './errorHints.js';
|
|
7
|
-
import { ownerArgs } from './sharedPoint.js';
|
|
8
|
-
|
|
9
|
-
// The pause / freeze handle is { owner, remove() } only: no chaining, so a pause is ended in exactly one way.
|
|
10
|
-
function handle(owner, remove) { return { owner, remove }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The three hold stacks: 'freeze' and 'pause' (kind any), 'camera' (kind top). services.js and the test engines call this, so both get the same stacks.
|
|
14
|
-
* The pause stack does the loop side effect itself (onChange), not engine.pause(): engine.mod('pause', { owner }), engine.pause(owner), the handle's
|
|
15
|
-
* remove() and _resume(owner) are then one behavior. Making mod('pause') throw instead would leave a quantity that engine.mod names in describe
|
|
16
|
-
* but refuses to change, a special case to remember; with onChange there is no path that holds the stack without stopping the loop.
|
|
17
|
-
* @param {any} engine
|
|
18
|
-
*/
|
|
19
|
-
export function defineHoldStacks(engine) {
|
|
20
|
-
engine.stacks.define('freeze', { kind: 'any', save: false }); // who froze gameplay
|
|
21
|
-
engine.stacks.define('pause', { kind: 'any', save: false, onChange: () => { // who paused the loop; it resumes only when empty
|
|
22
|
-
if (engine.stacks.get('pause').size()) engine.paused = true;
|
|
23
|
-
else if (!engine.disposed) { engine.paused = false; engine._loop(); }
|
|
24
|
-
} });
|
|
25
|
-
engine.stacks.define('camera', { kind: 'top', save: false }); // who holds the camera; the latest is in charge (cameraOverride)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const holdMethods = {
|
|
29
|
-
/**
|
|
30
|
-
* Pause the real-time loop (the picture stops and the game stops advancing). owner names who paused (default 'game'; pause({ owner }) works too): the loop
|
|
31
|
-
* stays paused until every owner has resumed, and _resume(owner) by someone who did not pause does not undo another owner's pause.
|
|
32
|
-
* kind tells engine.runState what the pause means: 'test' (a test or the dev bridge holds it: 'test-paused'); any other pause reads as 'paused'.
|
|
33
|
-
* Returns a handle: remove() resumes this owner.
|
|
34
|
-
* @param {string | { owner?: string, kind?: 'test' }} [owner] @param {{ kind?: 'test' }} [opts]
|
|
35
|
-
* @returns {{ owner: string, remove(): void }}
|
|
36
|
-
* @example const p = engine.pause('perf-test'); ... p.remove();
|
|
37
|
-
*/
|
|
38
|
-
pause(owner, opts) {
|
|
39
|
-
const a = ownerArgs(owner, opts);
|
|
40
|
-
const P = this.stacks.get('pause');
|
|
41
|
-
P.take({ owner: a.owner, value: { kind: a.opts.kind ?? null } }); // the stack's onChange sets this.paused (defineHoldStacks), same as engine.mod('pause')
|
|
42
|
-
return handle(a.owner, () => { if (P.has(a.owner)) this._resume(a.owner); });
|
|
43
|
-
},
|
|
44
|
-
/**
|
|
45
|
-
* @internal The dev bridge and tests: end owner's pause (the handle's remove() calls this); with no pause held (a headless engine) it starts live running.
|
|
46
|
-
* A call by a non-owner while others hold a pause is ignored with a dev warning (a pause that silently stays stops even rendering).
|
|
47
|
-
* @param {string | { owner?: string }} [owner]
|
|
48
|
-
*/
|
|
49
|
-
_resume(owner) {
|
|
50
|
-
const { owner: o } = ownerArgs(owner);
|
|
51
|
-
const P = this.stacks.get('pause');
|
|
52
|
-
if (P.size() && !P.has(o)) { warnOnce(coded('pause-owner', `ending the pause of '${o}': paused by ${P.names().map(n => `'${n}'`).join(', ')}, not by '${o}'. End a pause with the handle pause() returned (p.remove()), or the pause stays`)); return this; }
|
|
53
|
-
// with holders the stack's onChange restarts the loop; with none (headless start) resume itself starts it
|
|
54
|
-
if (!P.release(o) && !P.size() && !this.disposed) { this.paused = false; this._loop(); }
|
|
55
|
-
return this;
|
|
56
|
-
},
|
|
57
|
-
// Gameplay freeze (menus, flow 'paused'): no fixed steps (movement, timers, tick and every time view but ambient stop) while frame hooks
|
|
58
|
-
// and rendering go on, so the picture and UI stay alive.
|
|
59
|
-
// Gameplay logic (quest checks, cutscene waits) belongs in fixed, or check engine.frozen first in frame (see the top of this file).
|
|
60
|
-
// Unlike pause(), which stops rendering too and is for tests and step(). owner is the freezer's name; play resumes only when all
|
|
61
|
-
// have unfrozen. step() obeys freezes as well. Same owner rules as every stack (core/stacks.js).
|
|
62
|
-
/**
|
|
63
|
-
* Freeze gameplay for owner (default 'game'; freeze({ owner, kind }) works too). kind 'title' marks a title screen waiting for start (runState 'title-frozen').
|
|
64
|
-
* Ambient animation (uniforms.uTime: wind, water, clouds) keeps moving behind the freeze; ambient: true stops it too (a photo / cutscene still).
|
|
65
|
-
* Returns a handle whose remove() releases this owner's freeze. Same as engine.mod('freeze', { owner }) plus the kind.
|
|
66
|
-
* @param {string | { owner?: string, kind?: 'title', ambient?: boolean }} [owner] @param {{ kind?: 'title', ambient?: boolean }} [opts]
|
|
67
|
-
* @returns {{ owner: string, remove(): void }}
|
|
68
|
-
*/
|
|
69
|
-
freeze(owner, opts) {
|
|
70
|
-
const a = ownerArgs(owner, opts);
|
|
71
|
-
const h = this.stacks.get('freeze').take({ owner: a.owner, value: { kind: a.opts.kind ?? null, ambient: !!a.opts.ambient } });
|
|
72
|
-
return handle(a.owner, h.remove);
|
|
73
|
-
},
|
|
74
|
-
/** True while someone has frozen gameplay */
|
|
75
|
-
get frozen() { return this.stacks.get('freeze').value(); },
|
|
76
|
-
/**
|
|
77
|
-
* The one answer to "why is the page (not) advancing"; the dev bridge and the MCP tools copy it as-is.
|
|
78
|
-
* state: 'loading' | 'title-frozen' (a freeze of kind 'title' is up, waiting for start) | 'test-paused' (only pauses of kind 'test': the bridge or a test)
|
|
79
|
-
* | 'paused' (paused or frozen by owners, listed in `owners`) | 'running';
|
|
80
|
-
* owners: every pause and freeze owner, so closing one part's pause can be told from a player's;
|
|
81
|
-
* blockedBy: what keeps the player's input from driving the game: each opaque input context ('win-settings', 'ui-title', 'dialogue', 'cutscene'...),
|
|
82
|
-
* 'error' (a gameplay error froze the game) and 'loading' (the loading screen blocks).
|
|
83
|
-
* @returns {{ state: 'loading' | 'title-frozen' | 'test-paused' | 'paused' | 'running', owners: string[], blockedBy: string[] }}
|
|
84
|
-
*/
|
|
85
|
-
get runState() {
|
|
86
|
-
const P = this.stacks.get('pause'), F = this.stacks.get('freeze'), owners = [...P.names(), ...F.names()];
|
|
87
|
-
const lv = this.loading?.view();
|
|
88
|
-
const onlyTest = owners.length > 0 && !F.size() && !P.entries().some(d => d.value.kind !== 'test');
|
|
89
|
-
const state = !this.ready || !lv?.done ? 'loading' : F.entries().some(d => d.value.kind === 'title') ? 'title-frozen'
|
|
90
|
-
: !owners.length && !this.paused ? 'running' : !owners.length || onlyTest ? 'test-paused' : 'paused';
|
|
91
|
-
const blockedBy = (this.input?.holders ?? []).filter(h => !h.pass).map(h => h.context);
|
|
92
|
-
if (F.has('error')) blockedBy.push('error');
|
|
93
|
-
if (lv?.blocked) blockedBy.push('loading');
|
|
94
|
-
return { state, owners, blockedBy };
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// ---------- camera takeover ----------
|
|
98
|
-
// While anyone holds the camera, no camera module moves it (camera/common.js reads cameraOverride). The 'camera' stack is kind top: the latest holder
|
|
99
|
-
// is in charge, and releasing it hands the camera back to the previous holder (or to the rig when none is left), never to nobody.
|
|
100
|
-
/**
|
|
101
|
-
* Take the camera over: camera modules leave engine.camera alone until every holder has released it. The latest holder is in charge; its focus
|
|
102
|
-
* (optional) is where the world loads around. Returns { remove() } (only this owner's claim). engine.cameraOverride shows the holder in charge.
|
|
103
|
-
* @param {string | { owner: string, focus?: import('three').Vector3 }} owner @param {{ focus?: import('three').Vector3, [k: string]: any }} [opts] extra fields stay readable on cameraOverride
|
|
104
|
-
* @returns {{ owner: string, remove(): void }}
|
|
105
|
-
* @example const cam = engine.takeCamera('photo-mode', { focus: engine.player.position }); ... cam.remove();
|
|
106
|
-
*/
|
|
107
|
-
takeCamera(owner, opts) {
|
|
108
|
-
const a = ownerArgs(owner, opts, undefined);
|
|
109
|
-
const h = this.stacks.get('camera').take({ owner: a.owner, value: { ...a.opts, owner: a.owner } });
|
|
110
|
-
return { owner: a.owner, remove: h.remove };
|
|
111
|
-
},
|
|
112
|
-
/**
|
|
113
|
-
* The camera holder in charge ({ owner, focus? }), or null. Read-only: take the camera with engine.takeCamera(owner).
|
|
114
|
-
* @type {{ owner: string, focus?: import('three').Vector3, [k: string]: any } | null}
|
|
115
|
-
*/
|
|
116
|
-
get cameraOverride() { return this.stacks?.get('camera').value() ?? null; },
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const HOLD_STACKS = { pause: 'pause', freeze: 'freeze', camera: 'camera', debugView: 'debug.view' };
|
|
120
|
-
/**
|
|
121
|
-
* Everyone who holds something, in one place (empty parts left out): pause / freeze / camera / debugView [{ owner, at }]; input [{ context, owner,
|
|
122
|
-
* pass }] (pushed input contexts); gates { action: [owners] } (input.gate). Every other shared value is in describe().shared (core/stacks.js).
|
|
123
|
-
* Lives here, next to the hold stacks it reads, so describe() and the input-holds test use the same function (no second copy).
|
|
124
|
-
* "Why can't I move / why is time slow" is answered here without knowing which module did it.
|
|
125
|
-
*/
|
|
126
|
-
export function describeHolds(e) {
|
|
127
|
-
const out = {};
|
|
128
|
-
for (const [k, n] of Object.entries(HOLD_STACKS)) { const h = e.stacks.has(n) ? e.stacks.get(n).holders() : []; if (h.length) out[k] = h; }
|
|
129
|
-
const inp = e.input.holders; if (inp.length) out.input = inp;
|
|
130
|
-
const g = e.stacks.has('input.gate') ? e.stacks.get('input.gate') : null, gates = {};
|
|
131
|
-
for (const id of g?.ids() ?? []) if (g.size(id)) gates[id] = g.names(id);
|
|
132
|
-
if (Object.keys(gates).length) out.gates = gates;
|
|
133
|
-
return out;
|
|
134
|
-
}
|
package/core/math.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// Small shared helpers
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import { codedError } from './errorHints.js';
|
|
4
|
-
|
|
5
|
-
// API convention: a position is one argument. The old (x, z, ...) form arrives as a number; throw with the fix (otherwise it silently becomes the origin)
|
|
6
|
-
const STRINGS = { position: 'A position must be passed as one argument: Vector3 / object / [x, y, z] / { x, z } (see the API conventions); got ' };
|
|
7
|
-
const POS_ERR = STRINGS.position;
|
|
8
|
-
// A horizontal position missing x or z (a 2-element [x, z] array reads z as undefined; { x, y } has no z) would become 0 silently
|
|
9
|
-
// (player.placeAt([10, 20]) at z = 0): say which part is missing and how to write it
|
|
10
|
-
const XZ_ERR = 'A horizontal position needs finite x and z: pass [x, y, z] (a 2-element [x, z] array does not work) or { x, z }; got ';
|
|
11
|
-
|
|
12
|
-
/** Round to one decimal (describe, budget reports) @param {number} v @returns {number} */
|
|
13
|
-
export const r1 = v => Math.round(v * 10) / 10;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Show a value someone set (style post params, exposure, light intensity) without changing it: 4 significant digits, never fewer than
|
|
17
|
-
* the integer part. r1 is for measurements (positions, ms); a set value rounded to one decimal misreports it (bloom 0.25 read as 0.3,
|
|
18
|
-
* contrast 1.12 as 1.1, R5), and a reader then "fixes" a value that was already right. 4 digits only drops float noise (0.30000000000000004).
|
|
19
|
-
* @param {number} v @returns {number}
|
|
20
|
-
*/
|
|
21
|
-
export const rv = v => (Number.isFinite(v) && v !== 0 ? Number(v.toPrecision(Math.max(4, Math.floor(Math.log10(Math.abs(v))) + 1))) : v);
|
|
22
|
-
|
|
23
|
-
/** Normalize a Vector3 / Object3D / [x, y, z] / { x, y, z } into a Vector3 */
|
|
24
|
-
export function vec3(v, out = new THREE.Vector3()) {
|
|
25
|
-
if (!v) return out;
|
|
26
|
-
if (typeof v !== 'object') throw codedError('options-object', POS_ERR + JSON.stringify(v), TypeError);
|
|
27
|
-
if (v.isVector3) return out.copy(v);
|
|
28
|
-
if (v.isObject3D) return out.copy(v.position);
|
|
29
|
-
if (Array.isArray(v)) return out.set(v[0] ?? 0, v[1] ?? 0, v[2] ?? 0);
|
|
30
|
-
return out.set(v.x ?? 0, v.y ?? 0, v.z ?? 0);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** The height a position names, or undefined when it names none ({ x, z }) */
|
|
34
|
-
export function yOf(v) {
|
|
35
|
-
if (v?.isObject3D) v = v.position;
|
|
36
|
-
const y = Array.isArray(v) ? v[1] : v?.y;
|
|
37
|
-
return Number.isFinite(y) ? y : undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Get the horizontal coordinates [x, z] from a Vector3 / Object3D / [x, y, z] / { x, z } */
|
|
41
|
-
export function xzOf(v) {
|
|
42
|
-
if (!v || typeof v !== 'object') throw codedError('options-object', POS_ERR + JSON.stringify(v), TypeError);
|
|
43
|
-
if (v.isObject3D) v = v.position;
|
|
44
|
-
const x = Array.isArray(v) ? v[0] : v.x, z = Array.isArray(v) ? v[2] : v.z;
|
|
45
|
-
if (!Number.isFinite(x) || !Number.isFinite(z)) throw codedError('options-object', XZ_ERR + JSON.stringify(v), TypeError);
|
|
46
|
-
return [x, z];
|
|
47
|
-
}
|
|
48
|
-
|
package/core/moduleSlots.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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);
|
|
3
|
-
// a second provider is shared-taken, naming both and the replaces fix
|
|
4
|
-
// requires: ['inventory'] depend on the slot, not on whichever module gives it
|
|
5
|
-
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries, drawing parts, dispose)
|
|
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
|
-
// 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 './validate.js';
|
|
9
|
-
import { codedError, coded } from './errorHints.js';
|
|
10
|
-
import { reportError } from './errors.js';
|
|
11
|
-
import { PICTURE_SLOTS } from './pictureSlots.js';
|
|
12
|
-
|
|
13
|
-
const STRINGS = {
|
|
14
|
-
provides: 'module {name}: provides is a list of exclusive slot names, e.g. provides: [\'inventory\']; got {got}',
|
|
15
|
-
notSlot: 'module {name} provides \'{slot}\', but \'{slot}\' is a shared value (kind {kind}), not an exclusive slot; pick a slot name of its own, or change the value with ctx.mod(\'{slot}\', { ... })',
|
|
16
|
-
noHolder: 'engine.use(..., { replaces: \'{slot}\' }): no installed module provides \'{slot}\', so there is nothing to replace. Fix: drop { replaces }, or check the slot name (describe().shared lists the slots held now)',
|
|
17
|
-
notProvided: 'engine.use(..., { replaces: \'{slot}\' }): none of the modules in this call provides \'{slot}\', so the swap would leave it empty. Fix: add provides: [\'{slot}\'] to the module that takes over from {holder}',
|
|
18
|
-
byName: 'engine.use(..., { replaces }): module {name} requires module \'{dep}\' by its name, and the swap unloads {dep}. Fix: in {name}, require the slot (requires: [\'<slot>\']) instead of the module name',
|
|
19
|
-
unuse: 'dispose hook of module {name} (unloaded by replaces)',
|
|
20
|
-
misspelt: "picture module {name} provides '{slot}', which is not a picture slot, so no other part collides with it and the writers tool cannot see it. Fix: provides: ['{hint}'] (the slots: {list})",
|
|
21
|
-
notIn: "engine.unuse('{name}'): no such module is installed. Installed: {list}",
|
|
22
|
-
needed: "engine.unuse('{name}'): module {dep} requires '{slot}', and nothing else provides it. Fix: unload {dep} first, or swap in another provider: engine.use(mine(), { replaces: '{slot}' })",
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** engine.use(a(), b(), { replaces: 'sky' }): the options object is the last argument and has `replaces` (a module always has a name) */
|
|
26
|
-
export const isUseOpts = o => !!o && typeof o === 'object' && !Array.isArray(o) && !('name' in o) && 'replaces' in o;
|
|
27
|
-
|
|
28
|
-
/** _planUse: a module's provides must be a list of names (checked before anything installs) */
|
|
29
|
-
export function checkProvides(m) {
|
|
30
|
-
if (m.provides != null && !(Array.isArray(m.provides) && m.provides.every(s => typeof s === 'string' && s)))
|
|
31
|
-
throw codedError('module-provides', fmt(STRINGS.provides, { name: m.name, got: JSON.stringify(m.provides) }));
|
|
32
|
-
// a misspelt claim is worse than none: it reads as declared and guards nothing. Picture modules only, and only a near miss: their own slots stay free
|
|
33
|
-
if (DEV && m.type === 'picture') for (const slot of m.provides ?? []) {
|
|
34
|
-
const hint = slot in PICTURE_SLOTS ? null : closest(slot, Object.keys(PICTURE_SLOTS));
|
|
35
|
-
if (hint) warnOnce(coded('module-provides', fmt(STRINGS.misspelt, { name: m.name, slot, hint, list: Object.keys(PICTURE_SLOTS).join(', ') })));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const slotMethods = {
|
|
40
|
-
/**
|
|
41
|
-
* @internal engine.use(mod, { replaces }): the installed modules that hold these slots, after checking the swap is well formed
|
|
42
|
-
* (the slot is held, the newcomer provides it, no installed module requires the old one by its module name).
|
|
43
|
-
* @returns {Set<string>} module names to unload
|
|
44
|
-
*/
|
|
45
|
-
_replaced(list, replaces) {
|
|
46
|
-
const gone = new Set();
|
|
47
|
-
if (replaces == null) return gone;
|
|
48
|
-
const provided = new Set(list.flatMap(m => m?.provides ?? []));
|
|
49
|
-
for (const slot of [].concat(replaces)) {
|
|
50
|
-
const holder = this.stacks.has(slot) && this.stacks.get(slot).kind === 'one' ? this.stacks.get(slot).value() : null;
|
|
51
|
-
if (!holder || !this.modules.has(holder)) throw codedError('module-replaces', fmt(STRINGS.noHolder, { slot }));
|
|
52
|
-
if (!provided.has(slot)) throw codedError('module-replaces', fmt(STRINGS.notProvided, { slot, holder }));
|
|
53
|
-
gone.add(holder);
|
|
54
|
-
}
|
|
55
|
-
for (const m of this.modules.values()) for (const dep of m.requires ?? []) if (gone.has(dep) && !gone.has(m.name) && !list.some(n => n?.name === dep) && !provided.has(dep))
|
|
56
|
-
throw codedError('module-replaces', fmt(STRINGS.byName, { name: m.name, dep }));
|
|
57
|
-
return gone;
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Unload one installed module: its tracked handles, its slots and ctx.mod entries, its dispose. What it added some other way stays (dev reports a picture module's
|
|
61
|
-
* leftovers). To swap a holder use engine.use(mine(), { replaces: 'slot' }).
|
|
62
|
-
* @example engine.unuse('rain');
|
|
63
|
-
* @param {string} name
|
|
64
|
-
*/
|
|
65
|
-
unuse(name) {
|
|
66
|
-
const m = this.modules.get(name);
|
|
67
|
-
if (!m) throw codedError('module-unuse', fmt(STRINGS.notIn, { name, list: [...this.modules.keys()].join(', ') || 'none' }));
|
|
68
|
-
const gives = [name, ...(m.provides ?? [])], others = [...this.modules.values()].filter(o => o !== m);
|
|
69
|
-
for (const o of others) for (const dep of o.requires ?? []) if (gives.includes(dep) && !others.some(p => p.name === dep || p.provides?.includes(dep)))
|
|
70
|
-
throw codedError('module-unuse', fmt(STRINGS.needed, { name, dep: o.name, slot: dep }));
|
|
71
|
-
this._unuse(name);
|
|
72
|
-
},
|
|
73
|
-
/**
|
|
74
|
-
* @internal unload one installed module (engine.unuse, replaces, a plugin taken out): tracked handles and slots, drawing parts, its dispose, the engine property;
|
|
75
|
-
* returns its definition. swapping: a newcomer takes over its slots, so what it wrote to them is the newcomer's to replace
|
|
76
|
-
*/
|
|
77
|
-
_unuse(name, swapping = false) {
|
|
78
|
-
const m = this.modules.get(name);
|
|
79
|
-
this._dropTracked(name);
|
|
80
|
-
try { m.dispose?.(this); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
|
|
81
|
-
this._picture?.partGone(m, swapping);
|
|
82
|
-
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
|
|
83
|
-
this._sortHooks();
|
|
84
|
-
return m;
|
|
85
|
-
},
|
|
86
|
-
/** @internal engine.<slot> -> the provider's API while it is installed (the returned handle is tracked by the provider, so it goes with it) */
|
|
87
|
-
_aliasSlot(slot, api) {
|
|
88
|
-
(this._slotAlias ??= new Set()).add(slot);
|
|
89
|
-
return { remove: () => { if (this[slot] === api) delete this[slot]; this._slotAlias.delete(slot); } };
|
|
90
|
-
},
|
|
91
|
-
/** @internal is this capability provided by an installed module? */
|
|
92
|
-
_provided(slot) { for (const m of this.modules.values()) if (m.provides?.includes(slot)) return true; return false; },
|
|
93
|
-
/** @internal the exclusive slot a module provides (a 'one' shared point, made on first use) */
|
|
94
|
-
_slot(slot, by) {
|
|
95
|
-
if (!this.stacks.has(slot)) return this.stacks.define(slot, { kind: 'one', save: false });
|
|
96
|
-
const s = this.stacks.get(slot);
|
|
97
|
-
if (s.kind !== 'one') throw codedError('module-provides', fmt(STRINGS.notSlot, { name: by, slot, kind: s.kind }));
|
|
98
|
-
return s;
|
|
99
|
-
},
|
|
100
|
-
};
|