threedog 0.5.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 +276 -1
- package/README.md +18 -13
- package/core/{Animator.js → assets/Animator.js} +28 -18
- package/core/{Assets.js → assets/Assets.js} +116 -61
- package/core/{Baked.js → assets/Baked.js} +16 -25
- package/core/assets/assetEntry.js +237 -0
- package/core/{assetHot.js → assets/assetHot.js} +7 -6
- package/core/{assetLoad.js → assets/assetLoad.js} +66 -29
- package/core/assets/assetLod.js +113 -0
- package/core/{assetManifest.js → assets/assetManifest.js} +23 -12
- package/core/{assetReport.js → assets/assetReport.js} +9 -15
- package/core/{namedModel.js → assets/namedModel.js} +24 -16
- package/core/{Audio.js → audio/Audio.js} +27 -24
- 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} +154 -139
- package/core/{errorHints.js → base/errorHints.js} +9 -10
- package/core/{errors.js → base/errors.js} +9 -9
- package/core/{events.generated.js → base/events.generated.js} +2 -0
- package/core/{math.js → base/math.js} +22 -4
- package/core/{params.js → base/params.js} +3 -4
- package/core/base/util.js +32 -0
- package/core/{validate.js → base/validate.js} +29 -8
- package/core/{Engine.js → engine/Engine.js} +112 -105
- 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} +16 -16
- package/core/{loop.js → engine/loop.js} +80 -52
- package/core/{moduleSlots.js → engine/moduleSlots.js} +35 -10
- package/core/{moduleTypes.js → engine/moduleTypes.js} +30 -18
- package/core/{modules.js → engine/modules.js} +20 -17
- package/core/engine/page.js +125 -0
- package/core/{plugins.js → engine/plugins.js} +68 -103
- package/core/{services.js → engine/services.js} +47 -40
- package/core/{startup.js → engine/startup.js} +35 -35
- package/core/{Input.js → input/Input.js} +41 -27
- 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} +23 -22
- package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +60 -31
- package/core/{Describe.js → inspect/Describe.js} +33 -30
- package/core/{Inspect.js → inspect/Inspect.js} +14 -9
- package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +8 -10
- package/core/{InspectPerf.js → inspect/InspectPerf.js} +29 -16
- package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
- package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +9 -6
- package/core/inspect/UrlState.js +182 -0
- package/core/{catalog.js → inspect/catalog.js} +18 -5
- package/core/{checks.js → inspect/checks.js} +7 -5
- package/core/{debugView.js → inspect/debugView.js} +8 -8
- package/core/inspect/describeRender.js +148 -0
- package/core/{describeText.js → inspect/describeText.js} +17 -12
- package/core/inspect/geometryWatch.js +38 -0
- package/core/{lightWatch.js → inspect/lightWatch.js} +11 -9
- package/core/inspect/pictureWriters.js +342 -0
- 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} +37 -37
- package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -27
- package/core/{stackFrames.js → ops/stackFrames.js} +17 -6
- package/core/{stacks.js → ops/stacks.js} +18 -20
- 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} +27 -24
- package/core/{Views.js → scene/Views.js} +15 -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} +24 -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/scene/pictureSlots.js +33 -0
- package/core/{sceneDelta.js → scene/sceneDelta.js} +14 -6
- package/core/{sceneMethods.js → scene/sceneMethods.js} +36 -20
- package/core/scene/stepPoses.js +55 -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} +4 -3
- package/core/{things.js → scene/things.js} +19 -6
- package/core/{threePatches.js → scene/threePatches.js} +1 -1
- package/core/{tier.js → scene/tier.js} +1 -1
- package/core/scene/view.js +44 -0
- package/core/{Batching.js → stream/Batching.js} +85 -27
- package/core/{Stream.js → stream/Stream.js} +62 -33
- package/core/{batchGroups.js → stream/batchGroups.js} +18 -9
- package/core/{chunkStream.js → stream/chunkStream.js} +41 -1
- 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 +70 -63
- package/docs/API.md +30 -29
- package/docs/CODEMAP.md +98 -223
- package/docs/COMMANDS.md +80 -69
- package/docs/CONVENTIONS.md +87 -41
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/MIGRATING-0.8.md +169 -0
- package/docs/THREE.md +100 -49
- package/docs/api/assets.md +17 -16
- package/docs/api/audio.md +8 -7
- package/docs/api/budget.md +8 -4
- package/docs/api/calendar.md +10 -11
- package/docs/api/cameraRig.md +29 -29
- package/docs/api/characters.md +26 -19
- package/docs/api/clock.md +1 -1
- package/docs/api/collision.md +14 -11
- package/docs/api/content.md +6 -6
- package/docs/api/dialogue.md +3 -3
- package/docs/api/engine.md +82 -53
- package/docs/api/events.md +5 -3
- package/docs/api/flow.md +1 -1
- package/docs/api/grids.md +9 -2
- package/docs/api/ground.md +4 -5
- package/docs/api/hud.md +4 -1
- package/docs/api/i18n.md +6 -6
- package/docs/api/input.md +10 -9
- package/docs/api/interactions.md +6 -4
- package/docs/api/inventory.md +10 -11
- package/docs/api/jobs.md +5 -5
- package/docs/api/level.md +7 -8
- package/docs/api/lightPool.md +2 -7
- package/docs/api/music.md +3 -3
- package/docs/api/nav.md +10 -10
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +1 -1
- package/docs/api/particles.md +8 -5
- package/docs/api/photo.md +4 -2
- package/docs/api/pickups.md +7 -1
- package/docs/api/post.md +24 -5
- 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 +17 -14
- package/docs/api/stream.md +7 -7
- package/docs/api/swarm.md +34 -0
- package/docs/api/terrain.md +17 -12
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +2 -2
- package/docs/api/tools.md +30 -26
- package/docs/api/triggers.md +2 -0
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +11 -5
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +7 -3
- package/docs/api/weather.md +11 -6
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +6 -6
- package/docs/recipes/01-new-game.md +38 -57
- package/docs/recipes/02-npc.md +19 -20
- package/docs/recipes/03-items-pickups.md +47 -42
- package/docs/recipes/04-quests.md +3 -4
- package/docs/recipes/05-props-bake.md +72 -66
- package/docs/recipes/06-clock-events.md +30 -21
- package/docs/recipes/07-flow-scenes-pause.md +21 -17
- package/docs/recipes/08-weather-sky.md +117 -75
- package/docs/recipes/09-materials-lights-models.md +171 -0
- package/docs/recipes/10-blender-level.md +6 -7
- package/docs/recipes/11-vehicles.md +33 -25
- package/docs/recipes/12-navmesh.md +9 -8
- package/docs/recipes/13-animation.md +50 -22
- package/docs/recipes/14-custom-module.md +20 -17
- package/docs/recipes/15-perf.md +52 -29
- package/docs/recipes/16-dev-bridge.md +47 -57
- package/docs/recipes/18-world.md +45 -30
- package/docs/recipes/19-shooting-picking.md +11 -7
- package/docs/recipes/20-content-actions-save.md +36 -37
- package/docs/recipes/21-camera.md +41 -8
- package/docs/recipes/22-shop-gold.md +0 -4
- package/docs/recipes/23-ops.md +11 -11
- package/docs/recipes/26-ui-parts.md +56 -22
- package/docs/recipes/27-net.md +0 -2
- package/docs/recipes/28-terrain.md +126 -30
- package/docs/recipes/29-grid.md +16 -7
- package/docs/recipes/30-templates.md +62 -21
- package/docs/recipes/31-audio.md +9 -9
- package/docs/recipes/32-action-game.md +32 -9
- package/docs/recipes/33-stream-sources.md +2 -2
- package/docs/recipes/34-environment-lighting.md +164 -52
- package/docs/recipes/35-picture-from-reference.md +140 -0
- package/docs/recipes/36-ground-plants.md +105 -0
- package/docs/recipes/40-scene.md +105 -30
- package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +74 -106
- package/docs/recipes/44-water-weather-hooks.md +196 -0
- package/docs/recipes/45-cascaded-shadows.md +145 -25
- package/docs/recipes/46-blender-art-route.md +21 -25
- package/docs/recipes/49-game-module-contract.md +5 -5
- package/docs/recipes/50-own-renderer.md +3 -3
- package/docs/recipes/52-around-the-picture.md +137 -0
- package/docs/recipes/53-ground-up-close.md +65 -28
- package/docs/recipes/55-mods-time-wrap.md +25 -17
- package/docs/recipes/56-webgpu-tsl.md +73 -28
- package/docs/recipes/57-control.md +47 -1
- package/docs/recipes/58-input.md +3 -0
- package/docs/recipes/59-depth-post-effects.md +5 -5
- package/docs/recipes/60-judge-the-picture.md +47 -27
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +276 -0
- package/docs/recipes/63-third-person-start.md +90 -0
- package/docs/recipes/64-particles.md +35 -0
- package/docs/recipes/65-swarm.md +140 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +9 -7
- package/examples/action/main.js +5 -4
- package/examples/action/models.js +12 -14
- package/examples/action/picture/index.js +13 -0
- package/examples/action/picture/lights.js +35 -0
- package/examples/action/picture/materials.js +8 -0
- package/examples/action/picture/palette.js +33 -0
- package/examples/perf-island/.threedog/content-index.json +1 -0
- package/examples/{sheepisland → perf-island}/GAMEMAP.md +18 -14
- package/examples/{sheepisland → perf-island}/assets.js +2 -2
- package/examples/{sheepisland → perf-island}/content/templates.js +1 -1
- package/examples/{sheepisland → perf-island}/content/vegetation.js +3 -1
- package/examples/{sheepisland → perf-island}/main.js +22 -16
- package/examples/{sheepisland/style → perf-island}/models.js +13 -24
- package/examples/{sheepisland → perf-island}/params.js +1 -1
- package/examples/perf-island/picture/index.js +20 -0
- package/examples/perf-island/picture/lights.js +34 -0
- package/examples/perf-island/picture/materials.js +61 -0
- package/examples/perf-island/picture/palette.js +60 -0
- package/examples/perf-island/picture/sky.js +20 -0
- package/examples/{sheepisland → perf-island}/views.js +1 -1
- package/examples/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/GAMEMAP.md +91 -0
- package/examples/plain-picture/main.js +48 -0
- package/examples/plain-picture/picture/index.js +21 -0
- package/examples/plain-picture/picture/lights.js +54 -0
- package/examples/plain-picture/picture/materials.js +24 -0
- package/examples/plain-picture/picture/palette.js +16 -0
- package/examples/plain-picture/picture/sky.js +37 -0
- package/examples/pullable.json +31 -9
- package/examples/rc2d/GAMEMAP.md +10 -4
- package/examples/rc2d/README.md +11 -6
- package/examples/rc2d/main.js +26 -36
- package/examples/rc2d/picture/index.js +18 -0
- package/examples/rc2d/picture/lights.js +11 -0
- package/examples/rc2d/picture/materials.js +18 -0
- package/examples/rc2d/picture/palette.js +15 -0
- package/examples/rc2d/picture/post.js +11 -0
- package/examples/rc2d/rc2d.js +18 -28
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +15 -10
- package/examples/styletest/main.js +20 -30
- package/examples/styletest/models.js +29 -29
- package/examples/styletest/params.js +1 -4
- package/examples/styletest/picture/env.js +38 -0
- package/examples/styletest/picture/index.js +16 -0
- package/examples/styletest/picture/lights.js +9 -0
- package/examples/styletest/picture/materials.js +28 -0
- package/examples/styletest/picture/palette.js +22 -0
- package/examples/techniques/contact-shadows/README.md +22 -23
- package/examples/techniques/contact-shadows/contactShadows.js +32 -16
- package/examples/techniques/contact-shadows/main.js +20 -18
- package/examples/techniques/contact-shadows/picture/index.js +14 -0
- package/examples/techniques/contact-shadows/picture/lights.js +34 -0
- package/examples/techniques/contact-shadows/picture/materials.js +12 -0
- package/examples/techniques/contact-shadows/picture/palette.js +17 -0
- package/examples/techniques/day-night-grade/README.md +13 -16
- package/examples/techniques/day-night-grade/main.js +15 -25
- package/examples/techniques/day-night-grade/picture/index.js +20 -0
- package/examples/techniques/day-night-grade/picture/lights.js +45 -0
- package/examples/techniques/day-night-grade/picture/materials.js +15 -0
- package/examples/techniques/day-night-grade/picture/palette.js +59 -0
- package/examples/techniques/day-night-grade/picture/post.js +25 -0
- package/examples/techniques/day-night-grade/picture/sky.js +33 -0
- package/examples/techniques/interior-light/README.md +16 -13
- package/examples/techniques/interior-light/interiorLight.js +19 -17
- package/examples/techniques/interior-light/main.js +31 -68
- package/examples/techniques/interior-light/picture/index.js +24 -0
- package/examples/techniques/interior-light/picture/lights.js +52 -0
- package/examples/techniques/interior-light/picture/materials.js +13 -0
- package/examples/techniques/interior-light/picture/palette.js +32 -0
- package/examples/techniques/interior-light/picture/sky.js +40 -0
- package/examples/techniques/modular-building/README.md +8 -6
- package/examples/techniques/modular-building/kit.js +2 -2
- package/examples/techniques/modular-building/main.js +9 -17
- package/examples/techniques/modular-building/picture/index.js +17 -0
- package/examples/techniques/modular-building/picture/lights.js +26 -0
- package/examples/techniques/modular-building/picture/materials.js +13 -0
- package/examples/techniques/modular-building/picture/palette.js +23 -0
- package/examples/techniques/night-lights/README.md +15 -14
- package/examples/techniques/night-lights/main.js +20 -43
- package/examples/techniques/night-lights/nightLights.js +25 -21
- package/examples/techniques/night-lights/picture/index.js +18 -0
- package/examples/techniques/night-lights/picture/lights.js +44 -0
- package/examples/techniques/night-lights/picture/materials.js +15 -0
- package/examples/techniques/night-lights/picture/palette.js +34 -0
- package/examples/techniques/night-lights/picture/post.js +9 -0
- package/examples/techniques/night-lights/picture/sky.js +36 -0
- package/examples/techniques/outlines-and-rim/README.md +2 -2
- package/examples/techniques/outlines-and-rim/main.js +15 -38
- package/examples/techniques/outlines-and-rim/outlines.js +3 -3
- package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
- package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
- package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
- package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
- package/examples/techniques/procedural-animation/README.md +6 -4
- package/examples/techniques/procedural-animation/main.js +9 -7
- package/examples/techniques/procedural-animation/picture/index.js +15 -0
- package/examples/techniques/procedural-animation/picture/lights.js +35 -0
- package/examples/techniques/procedural-animation/picture/materials.js +10 -0
- package/examples/techniques/procedural-animation/picture/palette.js +16 -0
- package/examples/techniques/procedural-animation/picture/sky.js +31 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
- package/examples/techniques/procedural-surface/README.md +2 -0
- package/examples/techniques/procedural-surface/main.js +17 -55
- package/examples/techniques/procedural-surface/picture/index.js +14 -0
- package/examples/techniques/procedural-surface/picture/lights.js +18 -0
- package/examples/techniques/procedural-surface/picture/materials.js +34 -0
- package/examples/techniques/procedural-surface/picture/palette.js +15 -0
- package/examples/techniques/stylized-shading/README.md +13 -14
- package/examples/techniques/stylized-shading/main.js +11 -42
- package/examples/techniques/stylized-shading/picture/index.js +14 -0
- package/examples/techniques/stylized-shading/picture/lights.js +23 -0
- package/examples/techniques/stylized-shading/picture/materials.js +18 -0
- package/examples/techniques/stylized-shading/picture/palette.js +19 -0
- package/examples/techniques/stylized-shading/shading.js +2 -2
- package/examples/techniques/sun-and-key-light/README.md +20 -22
- package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
- package/examples/techniques/sun-and-key-light/main.js +19 -63
- package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
- package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
- package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
- package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
- package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
- package/examples/techniques/three-looks/README.md +21 -0
- package/examples/techniques/three-looks/main.js +58 -0
- package/examples/techniques/three-looks/picture/cartoon.js +23 -0
- package/examples/techniques/three-looks/picture/cinematic.js +27 -0
- package/examples/techniques/three-looks/picture/comic.js +27 -0
- package/examples/techniques/three-looks/picture/index.js +14 -0
- package/examples/techniques/three-looks/picture/sun.js +23 -0
- package/examples/techniques/wet-road/README.md +7 -4
- package/examples/techniques/wet-road/main.js +18 -38
- package/examples/techniques/wet-road/picture/index.js +17 -0
- package/examples/techniques/wet-road/picture/lights.js +57 -0
- package/examples/techniques/wet-road/picture/materials.js +16 -0
- package/examples/techniques/wet-road/picture/palette.js +24 -0
- package/examples/techniques/wet-road/picture/sky.js +46 -0
- package/examples/webgpu-tsl/GAMEMAP.md +10 -4
- package/examples/webgpu-tsl/README.md +13 -10
- package/examples/webgpu-tsl/main.js +30 -7
- package/examples/webgpu-tsl/picture/index.js +18 -0
- package/examples/webgpu-tsl/picture/lights.js +25 -0
- package/examples/webgpu-tsl/picture/materials.js +36 -0
- package/examples/webgpu-tsl/picture/palette.js +23 -0
- package/examples/webgpu-tsl/picture/post.js +16 -0
- package/examples/webgpu-tsl/picture/sky.js +30 -0
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +16 -12
- package/examples/world/art/humanoid.js +9 -13
- package/examples/world/art/index.js +2 -2
- package/examples/world/art/models.js +3 -4
- package/examples/world/art/shapes.js +2 -2
- package/examples/world/assets.js +2 -2
- package/examples/world/content/audio.js +1 -1
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +10 -10
- package/examples/world/models.js +17 -7
- package/examples/world/picture/index.js +20 -0
- package/examples/world/picture/lights.js +41 -0
- package/examples/world/picture/materials.js +34 -0
- package/examples/world/picture/palette.js +74 -0
- package/examples/world/picture/post.js +9 -0
- package/examples/world/picture/sky.js +39 -0
- package/index.d.ts +14 -22
- package/index.js +36 -36
- package/llms.txt +19 -21
- package/modules/ambience/Ambience.js +12 -9
- package/modules/calendar/Calendar.js +20 -20
- package/modules/calendar/index.js +14 -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 +51 -25
- package/modules/camera/contract.js +1 -0
- package/modules/camera/projection.js +2 -2
- package/modules/characters/Character.js +47 -39
- package/modules/characters/NPC.js +30 -22
- package/modules/characters/assetModel.js +18 -13
- 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 +172 -193
- package/modules/characters/moveHelpers.js +14 -3
- package/modules/characters/movers/common.js +22 -15
- package/modules/characters/movers/manual.js +4 -1
- package/modules/characters/movers/rapier.js +7 -6
- package/modules/characters/movers/simple.js +3 -3
- package/modules/characters/movers/support.js +32 -18
- package/modules/characters/npcAvoid.js +4 -4
- package/modules/characters/npcSim.js +28 -18
- 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 +19 -5
- package/modules/characters/useModel.js +5 -5
- package/modules/characters/walkTo.js +11 -17
- package/modules/collision/Collision.js +30 -22
- 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 +68 -98
- package/modules/content/loader.js +14 -17
- package/modules/content/markers.js +25 -0
- package/modules/content/models.js +66 -18
- 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 +19 -14
- package/modules/content/rules.js +34 -22
- package/modules/content/stages.js +7 -7
- package/modules/content/templates.js +24 -22
- 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 +115 -27
- package/modules/gameplay/Inventory.js +11 -12
- package/modules/gameplay/Quests.js +16 -9
- package/modules/gameplay/boxOps.js +1 -1
- package/modules/gameplay/dialogueBox.js +1 -1
- package/modules/gameplay/dialogueBubbles.js +4 -5
- package/modules/gameplay/interactionPrompt.js +1 -1
- package/modules/gameplay/interactions.contract.js +1 -1
- package/modules/gameplay/inventoryOps.js +2 -3
- package/modules/gameplay/pickups.js +81 -44
- package/modules/gameplay/questLog.js +2 -2
- package/modules/gameplay/questSave.js +3 -3
- package/modules/grid/Grid.js +1 -1
- package/modules/grid/Layer.js +16 -3
- package/modules/grid/index.js +47 -19
- package/modules/grid/preview.js +29 -20
- package/modules/grid/tiles.js +19 -23
- package/modules/hlod/index.js +38 -55
- package/modules/hud/index.js +27 -8
- package/modules/hud/parts.js +13 -11
- package/modules/level/contract.js +16 -0
- package/modules/level/heightfield.js +12 -10
- package/modules/level/index.js +48 -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 +34 -183
- package/modules/lights/slots.js +93 -0
- package/modules/lights/sources.js +88 -0
- package/modules/music/Music.js +31 -27
- 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 +49 -25
- package/modules/particles/effect.js +27 -10
- package/modules/particles/shaders.js +2 -1
- package/modules/photo/Photo.js +26 -27
- 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 +114 -45
- package/modules/settings/apply.js +10 -10
- package/modules/settings/sections.js +16 -14
- package/modules/settings/strings.js +1 -1
- package/modules/settings/view.js +3 -3
- package/modules/sky/Sky.js +125 -103
- package/modules/sky/clouds.js +22 -23
- package/modules/sky/dome.js +113 -0
- package/modules/sky/domeLayers.js +13 -13
- package/modules/sky/environment.js +47 -171
- package/modules/sky/fog.js +5 -180
- package/modules/sky/frame.js +42 -97
- package/modules/sky/season.js +9 -3
- package/modules/sky/shader.js +49 -44
- package/modules/sky/skyModule.js +25 -35
- package/modules/sky/tint.js +9 -11
- 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 +97 -62
- package/modules/terrain/chunkQueries.js +7 -24
- package/modules/terrain/chunkWorker.js +1 -1
- package/modules/terrain/draw.js +157 -0
- package/modules/terrain/index.js +60 -88
- package/modules/terrain/terrainColorMap.js +6 -3
- package/modules/terrain/terrainDefaults.js +4 -3
- package/modules/terrain/terrainEdit.js +32 -27
- package/modules/terrain/terrainGen.js +19 -14
- 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 +19 -15
- package/modules/vegetation/Vegetation.js +87 -39
- package/modules/vegetation/densityMap.js +4 -7
- package/modules/vegetation/draw.js +196 -0
- package/modules/vegetation/groundChunks.js +11 -31
- package/modules/vegetation/index.js +18 -16
- package/modules/vegetation/modelGeometry.js +3 -6
- package/modules/vegetation/nearFade.js +1 -1
- package/modules/water/Water.js +140 -93
- package/modules/water/surface.js +56 -56
- package/modules/weather/Weather.js +84 -38
- package/modules/weather/particles.js +18 -10
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/weatherDraw.js +145 -0
- package/modules/world/World.js +10 -10
- 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 +12 -10
- package/package.json +44 -8
- package/presets.js +3 -5
- package/render/PostFX.js +233 -63
- package/render/backend.js +72 -32
- package/render/cascades.js +200 -0
- package/render/cascades.tsl.js +93 -0
- package/render/daylight.js +56 -0
- package/render/detail.js +13 -12
- package/render/effects.js +60 -42
- package/render/fuse.js +3 -3
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +3 -3
- package/render/fx/detail.tsl.js +1 -1
- package/render/fx/index.js +10 -13
- 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 +6 -16
- package/render/fx/postWebGPU.tsl.js +55 -28
- package/render/fx/sky.tsl.js +34 -109
- package/render/fx/uniforms.tsl.js +4 -4
- package/render/fx/water.tsl.js +1 -1
- package/render/fx/wind.tsl.js +1 -1
- package/render/fxNumbers.js +3 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +11 -8
- package/render/lightmap.js +142 -0
- package/render/lights.js +26 -204
- package/render/lit.js +24 -0
- package/render/materials.js +47 -162
- package/render/mergeCommon.js +22 -0
- package/render/modeling.js +2 -2
- package/render/neutral.js +23 -0
- package/render/occlusion.js +200 -0
- package/render/ownFrame.js +5 -5
- package/render/patches.js +46 -41
- package/render/postWebGL.js +19 -9
- package/render/probes.js +182 -128
- 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/render/shadows.js +451 -0
- package/render/slots.js +11 -11
- package/render/terms.js +63 -113
- package/render/uniformDecl.js +2 -2
- package/types/core.d.ts +489 -405
- package/types/gameplay.d.ts +225 -114
- package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +23 -8
- 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/engine/page.d.ts +24 -0
- package/types/generated/core/{Input.d.ts → input/Input.d.ts} +21 -10
- package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
- package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +16 -8
- 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 +9 -1
- package/types/generated/modules/grid/index.d.ts +32 -8
- package/types/generated/modules/music/Music.d.ts +7 -5
- package/types/generated/modules/particles/Particles.d.ts +14 -7
- package/types/generated/modules/sky/Sky.d.ts +101 -23
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- 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 +51 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -10
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +7 -5
- package/types/generated/render/PostFX.d.ts +69 -20
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +20 -44
- package/types/generated/render/occlusion.d.ts +22 -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 +104 -73
- package/types/tsl.d.ts +45 -4
- package/types/world.d.ts +372 -86
- package/ui/Focus.js +21 -10
- package/ui/LoadingScreen.js +2 -2
- package/ui/Parts.js +12 -7
- package/ui/UI.js +17 -17
- package/ui/cursor.js +1 -1
- package/ui/defaults.js +3 -2
- package/ui/theme.js +36 -28
- package/ui/touchPart.js +1 -1
- package/core/UrlState.js +0 -110
- package/core/assetEntry.js +0 -106
- package/core/describeRender.js +0 -71
- package/core/holds.js +0 -134
- package/core/look/coreParts.js +0 -219
- package/core/look/part.js +0 -253
- package/core/look/points.js +0 -255
- package/core/look/report.js +0 -96
- package/core/look/shadowPart.js +0 -63
- package/core/look/state.js +0 -45
- package/core/look/write.js +0 -70
- package/core/page.js +0 -79
- package/core/shadowTypes.js +0 -16
- package/core/styleParts.js +0 -114
- package/core/util.js +0 -17
- package/docs/MIGRATING-0.3.md +0 -248
- package/docs/MIGRATING-0.4.md +0 -228
- package/docs/MIGRATING-0.5.md +0 -68
- package/docs/PERF.md +0 -245
- package/docs/api/style.md +0 -136
- package/docs/api/terrainLook.md +0 -10
- package/docs/api/vegetationLook.md +0 -10
- package/docs/api/weatherLook.md +0 -10
- package/docs/recipes/09-style.md +0 -218
- package/docs/recipes/35-style-from-reference.md +0 -153
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/37-terrain-look-hooks.md +0 -119
- package/docs/recipes/38-environment-look-hooks.md +0 -99
- package/docs/recipes/41-thing-registry.md +0 -97
- package/docs/recipes/42-terrain-shape.md +0 -64
- package/docs/recipes/44-water-weather-look-hooks.md +0 -144
- package/docs/recipes/47-island-snow-backdrop.md +0 -45
- package/docs/recipes/48-make-material.md +0 -75
- package/docs/recipes/52-look.md +0 -282
- package/docs/recipes/54-three-idioms.md +0 -88
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/.threedog/content-index.json +0 -1
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
- package/examples/webgpu-tsl/tslScene.js +0 -75
- package/examples/world/style/index.js +0 -61
- package/examples/world/style/plugins/10-bloom.js +0 -5
- package/modules/sky/cascades.js +0 -186
- package/modules/sky/cascades.tsl.js +0 -82
- package/modules/sky/look.js +0 -54
- package/modules/sky/lookFog.js +0 -76
- package/modules/sky/lookShadow.js +0 -62
- package/modules/sky/lookSky.js +0 -169
- package/modules/sky/shadow.js +0 -98
- package/modules/terrain/look.js +0 -83
- package/modules/terrain/lookGround.js +0 -66
- package/modules/vegetation/look.js +0 -119
- package/modules/vegetation/lookWind.js +0 -98
- package/modules/water/look.js +0 -91
- package/modules/water/surfaceDefaults.js +0 -3
- package/modules/weather/look.js +0 -74
- package/modules/weather/weatherLook.js +0 -135
- package/render/lookGlow.js +0 -139
- package/render/lookSurface.js +0 -224
- package/render/postLook.js +0 -164
- package/render/surface.js +0 -105
- package/types/generated/core/page.d.ts +0 -18
- package/types/generated/modules/weather/weatherLook.d.ts +0 -12
- package/types/style.d.ts +0 -671
- /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/{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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// adaptive resolution.
|
|
3
3
|
//
|
|
4
4
|
// Hook errors: onFixed / onFrame callbacks and module fixed / frame / afterRender hooks each run in try/catch and are handled by error tier (errors.js):
|
|
5
|
-
//
|
|
5
|
+
// picture / ui modules are disabled, errors elsewhere freeze gameplay in dev / tests and are recorded in engine.error, core steps such as render
|
|
6
6
|
// report only once; input.endFrame() sits in finally so "just pressed" always clears.
|
|
7
7
|
//
|
|
8
8
|
// What freezing (engine.freeze) stops: the whole fixed step is skipped (onFixed, module fixed, tick and every time view but ambient stop);
|
|
@@ -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,45 +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
|
-
|
|
84
|
-
|
|
90
|
+
this._picture?.frameStart();
|
|
91
|
+
advanceUiClock(this, dt); // headless pages: UI display timers run on the stepped time (core/time/uiClock.js)
|
|
92
|
+
writeDaylight(this); // before the hooks: an onFrame reads this frame's signal
|
|
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);
|
|
85
96
|
this._runHooks('frame', dt);
|
|
86
97
|
safe(this, 'stream.update', this.stream._update, SOFT, this.stream);
|
|
87
98
|
this.jobs.run({ deterministic });
|
|
@@ -89,38 +100,50 @@ export const loopMethods = {
|
|
|
89
100
|
safe(this, 'batching.update', this.batching.update, SOFT, this.batching); // last before rendering: picks up everything built this frame
|
|
90
101
|
safe(this, 'audio.tick', this.audio._tick, SOFT, this.audio); // positional sounds follow their objects (returns at once when there are none)
|
|
91
102
|
},
|
|
92
|
-
|
|
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
|
|
105
|
+
* run there wrote back the light it had just turned off) */
|
|
106
|
+
_render(dt, hooks = true) {
|
|
93
107
|
const r = this.renderer;
|
|
94
108
|
resetStats(r);
|
|
95
109
|
this._gameLights?.frame(); // plain PointLight / SpotLight at intensity 0 stop redrawing their shadow map (gameLights.js)
|
|
110
|
+
writeDaylight(this); // again: a time jump in onFrame / a module's frame hook after the first write must reach uDaylight / uTimeOfDay in the frame that draws it, with uSunDir
|
|
96
111
|
followFocus(this); // baseline sun (no sky module): its shadow box follows engine.focus (render/lights.js)
|
|
97
|
-
syncRoomEnvironment(this); // the baseline room map once a material reads scene.environment (one number compare on a quiet frame)
|
|
98
|
-
syncPlainTerms(this); // plain lit materials added since the last frame take the cloud shadow like the engine's own (render/terms.js)
|
|
99
112
|
const t0 = performance.now(); // measure
|
|
100
113
|
const gpu = this.adaptive.on ? this._gpu : null; // GPU time feeds adaptive resolution only; no queries while it is off
|
|
101
114
|
gpu?.begin();
|
|
102
115
|
// engine.onRender: camera and batching are final here. 'before' may render into its own targets (counted in renderer.info and the render phase)
|
|
103
|
-
const
|
|
116
|
+
const before = hooks ? this._onRender.before : [], after = hooks ? this._onRender.after : [];
|
|
117
|
+
const ctx = before.length || after.length ? { renderer: r, scene: this.scene, camera: this.camera, dt } : null;
|
|
104
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)
|
|
105
119
|
const draws = engineDraws(this), own = this._ownFrame;
|
|
106
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
|
|
107
122
|
try {
|
|
108
|
-
for (const f of
|
|
123
|
+
for (const f of before) { safe(this, STRINGS.onRender, f, null, undefined, ctx); r.setRenderTarget(null); }
|
|
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)
|
|
109
125
|
this._checkBackendAdds(); // WebGPU route: a WebGL-only material added since the last frame is named, not drawn blank (startup.js)
|
|
110
126
|
freshFrame(r); // WebGPU: step() several times in one task, or a renderOnce() earlier in this tick, must not reuse that scene pass
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
if (this._picture) this._picture.drawing = true;
|
|
128
|
+
if (draws) { this.batching.skip(); try { this.post.render(dt); } finally { this.batching.unskip(); } }
|
|
129
|
+
if (this._picture) this._picture.drawing = false;
|
|
130
|
+
for (const f of after) safe(this, STRINGS.onRender, f, null, undefined, ctx);
|
|
131
|
+
} finally { this._poses.undraw(); if (own) own.inside--; this._picture?.frameEnd(); }
|
|
114
132
|
gpu?.end();
|
|
115
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
|
|
116
134
|
this._compiled = this.budget.cost.rendered(performance.now() - t0, programCount(r) ?? -1, t0 / 1000); // measure
|
|
117
|
-
if (DEV && this.ready
|
|
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)
|
|
118
140
|
},
|
|
119
141
|
_runHooks(kind, dt) {
|
|
120
142
|
const p = this._prof;
|
|
121
|
-
const was = this._curModule;
|
|
122
|
-
for (const h of
|
|
123
|
-
|
|
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
|
|
124
147
|
const opts = h.opts ??= { module: h.mod };
|
|
125
148
|
this._curModule = h.mod; // the module type checks (moduleTypes.js) know whose hook is writing
|
|
126
149
|
if (!p) { safe(this, key, h.fn, opts, undefined, dt, this); continue; }
|
|
@@ -141,7 +164,7 @@ export const loopMethods = {
|
|
|
141
164
|
return r;
|
|
142
165
|
},
|
|
143
166
|
|
|
144
|
-
// ---------- nextFixed (
|
|
167
|
+
// ---------- nextFixed (halt / freeze / runState live in holds.js; step() below is the deterministic way to advance) ----------
|
|
145
168
|
/**
|
|
146
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.
|
|
147
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.
|
|
@@ -166,13 +189,15 @@ export const loopMethods = {
|
|
|
166
189
|
let acc = Math.min((this._acc || 0) + dt, MAX_CATCHUP), n = 0;
|
|
167
190
|
const f0 = performance.now(); // measure
|
|
168
191
|
let s0 = f0;
|
|
169
|
-
while (acc >= STEP) {
|
|
192
|
+
while (acc >= STEP && !this.disposed) { // a hook may dispose the engine
|
|
170
193
|
this._fixedStep(); acc -= STEP; n++;
|
|
171
194
|
const t = performance.now(); // measure
|
|
172
195
|
if (acc >= STEP && t - f0 + (t - s0) > CATCHUP_MS) { acc %= STEP; break; } // the next one would go over: drop the rest
|
|
173
196
|
s0 = t;
|
|
174
197
|
}
|
|
175
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;
|
|
176
201
|
return n;
|
|
177
202
|
},
|
|
178
203
|
|
|
@@ -184,14 +209,14 @@ export const loopMethods = {
|
|
|
184
209
|
const tick = now => {
|
|
185
210
|
if (this.disposed) return;
|
|
186
211
|
this._raf = requestAnimationFrame(tick);
|
|
187
|
-
const dt = Math.min(0.25, (now - last) / 1000); last = now;
|
|
188
|
-
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
|
|
189
214
|
// Adaptive resolution judges the frames up to the last one (cpuMs, GPU time and _compiled still describe it) and changes the
|
|
190
215
|
// render scale here, before this frame draws. Why not after the render: a canvas resize clears its drawing buffer, so a change made
|
|
191
216
|
// after the draw handed the compositor a blank frame (R2: a screenshot caught the 1 -> 0.9 frame black). Not counted in cpuMs
|
|
192
217
|
this._adapt(dt);
|
|
193
218
|
this._compiled = false;
|
|
194
|
-
// 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):
|
|
195
220
|
// fixed (input poll + fixed steps), frame (onFrame + module frame hooks + stream / jobs / batching), render (submitting the draw
|
|
196
221
|
// calls: three.js CPU work, upload of new objects, shader compiles; not GPU time), afterRender (module hooks). Adaptive resolution
|
|
197
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.
|
|
@@ -199,8 +224,8 @@ export const loopMethods = {
|
|
|
199
224
|
let c1, c2, c3;
|
|
200
225
|
try {
|
|
201
226
|
this.input.poll(dt);
|
|
202
|
-
//
|
|
203
|
-
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;
|
|
204
229
|
else this._catchUp(dt);
|
|
205
230
|
c1 = performance.now(); // measure
|
|
206
231
|
this._frameHooks(dt);
|
|
@@ -212,9 +237,9 @@ export const loopMethods = {
|
|
|
212
237
|
if (this._readyAt != null && this.ready) firstFrame(this, c3);
|
|
213
238
|
} finally { this.input.endFrame(); }
|
|
214
239
|
this._runHooks('afterRender', dt);
|
|
215
|
-
const c4 = performance.now(), P = this.
|
|
240
|
+
const c4 = performance.now(), P = this._cpuPhases; // measure
|
|
216
241
|
P.fixed = c1 - c0; P.frame = c2 - c1; P.render = c3 - c2; P.afterRender = c4 - c3;
|
|
217
|
-
this.
|
|
242
|
+
this._cpuMs = c4 - c0;
|
|
218
243
|
this.budget.sample(dt);
|
|
219
244
|
this.fps += (1 / Math.max(dt, 1e-3) - this.fps) * 0.05;
|
|
220
245
|
this._afterTick?.();
|
|
@@ -223,7 +248,7 @@ export const loopMethods = {
|
|
|
223
248
|
},
|
|
224
249
|
|
|
225
250
|
/**
|
|
226
|
-
* 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;
|
|
227
252
|
* frame hooks run once per frameEvery fixed steps (default 2, i.e. 30 Hz, dt = 1/30),
|
|
228
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
|
|
229
254
|
* render is true.
|
|
@@ -234,24 +259,27 @@ export const loopMethods = {
|
|
|
234
259
|
* cutscene across several step calls.
|
|
235
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
|
|
236
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
|
|
237
|
-
* 'ready').
|
|
262
|
+
* 'ready'); in dev that, and a step during a session change nobody awaited, warns once.
|
|
238
263
|
* Returns the result of describe() (null with { describe: false }, which callers that ignore it pass to skip the work).
|
|
239
264
|
*/
|
|
240
265
|
step(seconds, { render = true, frameEvery = 2, describe = true } = {}) {
|
|
241
266
|
if (this.disposed) return null; // nothing advances after dispose
|
|
242
267
|
if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds < 0)
|
|
243
268
|
throw codedError('step-seconds',
|
|
244
|
-
`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)`);
|
|
245
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');
|
|
246
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
|
|
247
274
|
let since = 0;
|
|
248
|
-
for (let i = 0; i < n; i++) {
|
|
275
|
+
for (let i = 0; i < n && !this.disposed; i++) { // a hook may dispose the engine
|
|
249
276
|
this._fixedStep();
|
|
250
277
|
if (++since >= frameEvery || i === n - 1) {
|
|
251
278
|
try { this._frameHooks(since * STEP, true); } finally { this.input.endFrame(); }
|
|
252
279
|
since = 0;
|
|
253
280
|
}
|
|
254
281
|
}
|
|
282
|
+
if (this.disposed) return null;
|
|
255
283
|
if (render) {
|
|
256
284
|
safe(this, STRINGS.render, this._render, SOFT, this, STEP);
|
|
257
285
|
this._runHooks('afterRender', STEP);
|
|
@@ -259,6 +287,6 @@ export const loopMethods = {
|
|
|
259
287
|
return describe ? this.describe() : null; // describe: false for internal loops that ignore the result (describe() walks every module)
|
|
260
288
|
},
|
|
261
289
|
|
|
262
|
-
// Adaptive resolution (core/adaptive.js): judged on frame cost; tests drive it with explicit cost / compiled values
|
|
263
|
-
_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); },
|
|
264
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
|
-
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries,
|
|
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 { fmt } from '
|
|
9
|
-
import { codedError } from '
|
|
10
|
-
import { reportError } from '
|
|
11
|
-
import {
|
|
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}',
|
|
@@ -17,6 +17,9 @@ const STRINGS = {
|
|
|
17
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
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
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}' })",
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
/** engine.use(a(), b(), { replaces: 'sky' }): the options object is the last argument and has `replaces` (a module always has a name) */
|
|
@@ -26,6 +29,11 @@ export const isUseOpts = o => !!o && typeof o === 'object' && !Array.isArray(o)
|
|
|
26
29
|
export function checkProvides(m) {
|
|
27
30
|
if (m.provides != null && !(Array.isArray(m.provides) && m.provides.every(s => typeof s === 'string' && s)))
|
|
28
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
|
+
}
|
|
29
37
|
}
|
|
30
38
|
|
|
31
39
|
export const slotMethods = {
|
|
@@ -48,13 +56,30 @@ export const slotMethods = {
|
|
|
48
56
|
throw codedError('module-replaces', fmt(STRINGS.byName, { name: m.name, dep }));
|
|
49
57
|
return gone;
|
|
50
58
|
},
|
|
51
|
-
/**
|
|
52
|
-
|
|
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) {
|
|
53
78
|
const m = this.modules.get(name);
|
|
54
79
|
this._dropTracked(name);
|
|
55
|
-
disposeLooksOf(this, name);
|
|
56
80
|
try { m.dispose?.(this); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
|
|
57
|
-
this.
|
|
81
|
+
this._picture?.partGone(m, swapping);
|
|
82
|
+
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); this.disabledModules.delete(name); delete this[name];
|
|
58
83
|
this._sortHooks();
|
|
59
84
|
return m;
|
|
60
85
|
},
|
|
@@ -1,20 +1,22 @@
|
|
|
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
|
-
//
|
|
3
|
-
// type: 'world' | '
|
|
4
|
-
// Why a type and not a rule in the docs: an AI follows the shape of the code, not a paragraph. A
|
|
5
|
-
// keys, is the start of two modules owning one thing; the check
|
|
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
|
+
// 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 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 '
|
|
12
|
+
import { DEV, fmt, warnOnce } from '../base/validate.js';
|
|
13
|
+
import { coded, codedError } from '../base/errorHints.js';
|
|
14
|
+
import { callerAt } from '../ops/stackFrames.js';
|
|
13
15
|
|
|
14
|
-
/** type -> what it may own (shown in the
|
|
16
|
+
/** type -> what it may own (shown in the unknown type error and in recipes/14) */
|
|
15
17
|
export const MODULE_TYPES = {
|
|
16
18
|
world: 'game state: save parts, world records, ops, ground / collision / navigation data (draws nothing)',
|
|
17
|
-
|
|
19
|
+
picture: 'what is seen and heard: picture values, three.js objects, particles, sounds (changes no game state)',
|
|
18
20
|
actor: 'characters: their control slots and movement values (other state only through ops)',
|
|
19
21
|
rules: 'game logic: save parts, ops, events; may take input, control or the camera for a while (a cutscene)',
|
|
20
22
|
ui: 'DOM panels and menus: declares input actions, runs ops (binds no keys, writes no game save)',
|
|
@@ -23,16 +25,15 @@ export const MODULE_TYPES = {
|
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
const STRINGS = {
|
|
26
|
-
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}",
|
|
27
28
|
unknown: "module {name} has type '{type}', which is not a module type. Fix: use one of {list}",
|
|
28
29
|
// rule broken at runtime: module, type, what it did, why not, the fix
|
|
29
30
|
broke: "module {name} (type '{type}') {did}: {why}. Fix: {fix}",
|
|
30
31
|
};
|
|
31
32
|
const RULES = {
|
|
32
33
|
// [types it is wrong for, why, fix]
|
|
33
|
-
'ops.define': [['
|
|
34
|
-
"define the op in a rules (or world) module and let the
|
|
35
|
-
'world.write': [['
|
|
34
|
+
'ops.define': [['picture'], 'a picture module only shows the game, it never adds actions that change it',
|
|
35
|
+
"define the op in a rules (or world) module and let the picture module read the state; or give {name} type: 'rules' if it really is game logic"],
|
|
36
|
+
'world.write': [['picture', 'ui'], 'world records are game state; a {type} module only reads them',
|
|
36
37
|
"run an op that writes it (engine.ops.run('<noun.verb>', args)) or move the write into a rules / world module"],
|
|
37
38
|
'input.bind': [['ui'], 'a ui module declares actions; which key does what is the game\'s choice',
|
|
38
39
|
"declare the action (ctx.input.action(name, { context })) and bind keys in the game: engine.input.bind(name, ['KeyE']) or createEngine({ bindings })"],
|
|
@@ -40,15 +41,14 @@ const RULES = {
|
|
|
40
41
|
'keep preferences in browser storage (engine.settings does), and game state in a rules / world module'],
|
|
41
42
|
};
|
|
42
43
|
|
|
43
|
-
/** _planUse:
|
|
44
|
+
/** _planUse: no type is 'rules'; any other must be one of MODULE_TYPES (unknown = error naming the fix) */
|
|
44
45
|
export function checkType(m) {
|
|
45
|
-
|
|
46
|
-
if (m.type
|
|
47
|
-
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(' | ') }));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* @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.
|
|
52
52
|
* what: 'ops.define' | 'world.write' | 'input.bind' | 'saves.register'; did: what it did, for the message ("defined op shop.buy").
|
|
53
53
|
*/
|
|
54
54
|
export function checkTypeRule(e, what, did) {
|
|
@@ -57,7 +57,7 @@ export function checkTypeRule(e, what, did) {
|
|
|
57
57
|
const [types, why, fix] = RULES[what];
|
|
58
58
|
if (!types.includes(m.type)) return;
|
|
59
59
|
const v = { name: m.name, type: m.type };
|
|
60
|
-
|
|
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}`);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/** @internal run fn with m as the current module (install, init's synchronous part, a hook); restores the previous one */
|
|
@@ -67,6 +67,18 @@ export function asModule(e, m, fn) {
|
|
|
67
67
|
try { return fn(); } finally { e._curModule = was; }
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @internal dev: a frame hook registered while a module installs stays that module's: it runs as the module, so the picture writers tool can tell two parts in one
|
|
72
|
+
* file apart (a stack cannot) and the type checks reach it. part / at let the leftovers check find a hook that outlived its module. Outside dev fn stays as it is.
|
|
73
|
+
*/
|
|
74
|
+
export function ownHook(e, fn) {
|
|
75
|
+
const m = DEV ? e._curModule : null;
|
|
76
|
+
if (!m) return fn;
|
|
77
|
+
const f = (...a) => asModule(e, m, () => fn(...a));
|
|
78
|
+
f.part = m.name; f.at = callerAt();
|
|
79
|
+
return f;
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
/** @internal describe().modules row: name, type, and provides / requires when there are any */
|
|
71
83
|
export function moduleRow(m) {
|
|
72
84
|
return { name: m.name, type: m.type, ...(m.provides?.length ? { provides: [...m.provides] } : {}), ...(m.requires?.length ? { requires: [...m.requires] } : {}) };
|
|
@@ -24,20 +24,19 @@
|
|
|
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
|
-
// holder first (its handles, slot,
|
|
30
|
-
// critical: true on a module makes a failed init() stop engine.start() with the reason; without it a failed init is reported (
|
|
29
|
+
// holder first (its handles, slot, drawing parts, dispose), and puts it back if the new install fails.
|
|
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;
|
|
31
31
|
// other types: error tiers in errors.js) and start() goes on.
|
|
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 '
|
|
40
|
-
import { disposeLooksOf } from './look/part.js';
|
|
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';
|
|
41
40
|
import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
|
|
42
41
|
import { checkType, asModule } from './moduleTypes.js';
|
|
43
42
|
|
|
@@ -86,10 +85,13 @@ function sortModules(list) {
|
|
|
86
85
|
}
|
|
87
86
|
if (out.length === list.length) return out;
|
|
88
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
|
|
89
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; } }
|
|
90
92
|
for (let n = left.values().next().value; !path.includes(n); n = [...succ.get(n)].find(x => left.has(x))) path.push(n);
|
|
91
93
|
const cyc = path.slice(path.indexOf([...succ.get(path.at(-1))].find(x => path.includes(x))));
|
|
92
|
-
throw codedError('module-cycle', STRINGS.cycle
|
|
94
|
+
throw codedError('module-cycle', fmt(STRINGS.cycle, { path: [...cyc, cyc[0]].join(' -> ') }));
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/** before / after across stages must agree with the stage order (the stage always wins), else the declaration would be silently ignored:
|
|
@@ -119,14 +121,15 @@ export const moduleMethods = {
|
|
|
119
121
|
const opts = isUseOpts(mods.at(-1)) ? mods.pop() : null;
|
|
120
122
|
const list = mods.flat(Infinity), gone = this._replaced(list, opts?.replaces);
|
|
121
123
|
const plan = this._planUse(list, gone), done = [];
|
|
122
|
-
// replaces: the holder goes first (its tracked handles, its slot, its
|
|
123
|
-
const removed = [...gone].map(n => this._unuse(n));
|
|
124
|
+
// replaces: the holder goes first (its tracked handles, its slot, its drawing parts, its dispose), so the newcomer's install sees a free slot
|
|
125
|
+
const removed = [...gone].map(n => this._unuse(n, true));
|
|
124
126
|
try {
|
|
125
127
|
for (const m of plan) {
|
|
126
128
|
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this);
|
|
127
129
|
done.push({ m, had, prev }); // before install(): what it tracked before throwing is removed too
|
|
128
130
|
this._modInst.set(m.name, {}); // this install's identity: install and init ctx check it, so a stale async init cannot act on a later install
|
|
129
131
|
const ctx = this._modCtx(m);
|
|
132
|
+
this._picture?.installing(m);
|
|
130
133
|
for (const slot of m.provides ?? []) ctx.track(this._slot(slot, m.name).take({ owner: m.name })); // shared-taken when another module holds it
|
|
131
134
|
const api = asModule(this, m, () => m.install?.(this, ctx)) ?? m; // asModule: the type checks know who is installing (moduleTypes.js)
|
|
132
135
|
catalogClaim(this, m.name, snap); // ops / save parts / describe names it registered show under it in engine.catalog()
|
|
@@ -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
|
|
@@ -145,14 +148,13 @@ export const moduleMethods = {
|
|
|
145
148
|
this._dropTracked(m.name);
|
|
146
149
|
if (installed) try { m.dispose?.(this); } catch { /* the install error below is the one to report */ }
|
|
147
150
|
}
|
|
148
|
-
for (const m of plan) disposeLooksOf(this, m.name); // look parts and driven keys of every module in the batch, the one that threw too (review M9)
|
|
149
151
|
this._sortHooks();
|
|
150
152
|
// a replaced module comes back, so a failed swap leaves the game as it was (it installs fresh: its old handles already went)
|
|
151
153
|
if (removed.length) try { this.use(...removed); } catch (e2) { reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
|
|
152
154
|
throw err;
|
|
153
155
|
}
|
|
154
156
|
this._sortHooks();
|
|
155
|
-
if (this.
|
|
157
|
+
if (this._initsDone) for (const m of plan) if (m.init) this._lateInit(m);
|
|
156
158
|
return this;
|
|
157
159
|
},
|
|
158
160
|
/** @internal validate a batch without touching the engine (so a failure leaves nothing half-installed);
|
|
@@ -217,6 +219,7 @@ export const moduleMethods = {
|
|
|
217
219
|
let set = this._modTracked.get(name);
|
|
218
220
|
if (!set) this._modTracked.set(name, set = new Set());
|
|
219
221
|
set.add(h);
|
|
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' })
|
|
@@ -288,7 +291,7 @@ export const moduleMethods = {
|
|
|
288
291
|
/** Run order of module hooks (module names, first to last), for debugging "who runs first". */
|
|
289
292
|
get moduleOrder() { return this._moduleOrder ?? []; },
|
|
290
293
|
|
|
291
|
-
/** Re-sort the module hooks in the main loop (disabled
|
|
294
|
+
/** Re-sort the module hooks in the main loop (disabled picture / ui modules are not put back). */
|
|
292
295
|
_sortHooks() {
|
|
293
296
|
const order = sortModules([...this.modules.values()]);
|
|
294
297
|
this._moduleOrder = order.map(m => m.name);
|