threedog 0.2.1 → 0.7.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 +371 -1
- package/README.md +21 -12
- package/core/Animator.js +15 -12
- package/core/Assets.js +92 -26
- package/core/Audio.js +45 -38
- package/core/Baked.js +30 -15
- package/core/Batching.js +102 -15
- package/core/Budget.js +40 -19
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +75 -25
- package/core/Describe.js +105 -45
- package/core/Engine.js +203 -75
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +175 -80
- package/core/Inspect.js +8 -5
- package/core/InspectMaterials.js +84 -0
- package/core/InspectPerf.js +68 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/MaterialInfo.js +7 -5
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +12 -7
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +13 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +69 -13
- package/core/Views.js +10 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +27 -7
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +44 -19
- package/core/assetManifest.js +53 -11
- package/core/assetReport.js +5 -5
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/batchGroups.js +9 -1
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +21 -5
- package/core/cells.js +62 -0
- package/core/checks.js +10 -8
- package/core/chunkStream.js +87 -0
- package/core/control.js +149 -0
- package/core/copies.js +32 -0
- package/core/dayTime.js +12 -6
- package/core/debugView.js +85 -18
- package/core/describeRender.js +117 -21
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +478 -32
- package/core/errorHints.js +41 -142
- package/core/errors.js +31 -8
- package/core/events.generated.js +13 -7
- package/core/gameLights.js +69 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +14 -13
- package/core/gridLoad.js +2 -1
- package/core/ground.js +6 -4
- package/core/headlessLoad.js +55 -0
- package/core/holds.js +78 -50
- package/core/inputContext.js +11 -7
- package/core/inputDefaults.js +24 -21
- package/core/inputPad.js +1 -1
- package/core/inputPointer.js +1 -1
- package/core/inputTouch.js +2 -2
- package/core/lifecycle.js +46 -12
- package/core/lightWatch.js +9 -5
- package/core/loop.js +109 -43
- package/core/math.js +18 -3
- package/core/moduleSlots.js +100 -0
- package/core/moduleTypes.js +86 -0
- package/core/modules.js +147 -29
- package/core/movement.js +2 -2
- package/core/namedModel.js +74 -0
- package/core/opsCheck.js +3 -3
- package/core/opsFail.js +15 -6
- package/core/opsGuard.js +4 -4
- package/core/opsRun.js +4 -3
- package/core/owned.js +171 -0
- package/core/page.js +44 -10
- package/core/params.js +30 -8
- package/core/pictureSlots.js +33 -0
- package/core/pictureWriters.js +343 -0
- package/core/plugins.js +245 -0
- package/core/saveApply.js +99 -17
- package/core/saveFiles.js +8 -6
- package/core/saveValues.js +46 -0
- package/core/saveVersions.js +20 -3
- package/core/scatter.js +48 -19
- package/core/sceneDelta.js +211 -0
- package/core/sceneMethods.js +31 -33
- package/core/screenToGround.js +1 -1
- package/core/services.js +27 -11
- package/core/session.js +28 -25
- package/core/shaderCost.js +78 -0
- package/core/shadowTypes.js +3 -2
- package/core/shadows.js +405 -0
- package/core/sharedPoint.js +303 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +45 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -13
- package/core/streamSources.js +0 -11
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +3 -3
- package/core/thingOps.js +29 -6
- package/core/things.js +22 -12
- package/core/threadPure.js +7 -3
- package/core/threePatches.js +47 -0
- package/core/tier.js +21 -10
- package/core/time.js +236 -0
- package/core/uiClock.js +25 -0
- package/core/util.js +8 -2
- package/core/validate.js +66 -87
- package/core/view.js +43 -0
- package/core/wrap.js +106 -0
- package/docs/AI.md +95 -104
- package/docs/API.md +35 -31
- package/docs/CODEMAP.md +231 -176
- package/docs/COMMANDS.md +63 -39
- package/docs/CONVENTIONS.md +99 -31
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +320 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/MIGRATING-0.6.md +126 -0
- package/docs/MIGRATING-0.7.md +39 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +82 -28
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +15 -11
- package/docs/api/audio.md +10 -14
- package/docs/api/budget.md +4 -0
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -24
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +10 -7
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +95 -65
- package/docs/api/events.md +20 -14
- package/docs/api/grids.md +10 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +5 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +13 -7
- package/docs/api/interactions.md +10 -6
- package/docs/api/inventory.md +17 -17
- package/docs/api/level.md +0 -2
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/occlusion.md +5 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +6 -3
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +21 -0
- package/docs/api/post.md +8 -5
- package/docs/api/quests.md +2 -3
- package/docs/api/rigid.md +16 -14
- package/docs/api/saves.md +6 -4
- package/docs/api/settings.md +2 -3
- package/docs/api/sky.md +18 -49
- package/docs/api/stream.md +1 -1
- package/docs/api/terrain.md +16 -7
- package/docs/api/terrainDraw.md +12 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +32 -15
- package/docs/api/triggers.md +7 -10
- package/docs/api/vegetation.md +17 -9
- package/docs/api/vegetationDraw.md +10 -0
- package/docs/api/water.md +9 -21
- package/docs/api/weather.md +10 -15
- package/docs/api/weatherDraw.md +10 -0
- package/docs/api/world.md +3 -2
- package/docs/recipes/01-new-game.md +52 -42
- package/docs/recipes/02-npc.md +24 -7
- package/docs/recipes/03-items-pickups.md +57 -22
- package/docs/recipes/04-quests.md +12 -5
- package/docs/recipes/05-props-bake.md +174 -22
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +50 -10
- package/docs/recipes/08-weather-sky.md +134 -37
- package/docs/recipes/09-materials-lights-models.md +185 -0
- package/docs/recipes/10-blender-level.md +16 -4
- package/docs/recipes/11-vehicles.md +67 -10
- package/docs/recipes/13-animation.md +23 -9
- package/docs/recipes/14-custom-module.md +63 -29
- package/docs/recipes/15-perf.md +31 -10
- package/docs/recipes/16-dev-bridge.md +74 -40
- package/docs/recipes/18-world.md +26 -14
- package/docs/recipes/19-shooting-picking.md +12 -10
- package/docs/recipes/20-content-actions-save.md +60 -18
- package/docs/recipes/21-camera.md +55 -17
- package/docs/recipes/22-shop-gold.md +3 -3
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +86 -13
- package/docs/recipes/27-net.md +11 -5
- package/docs/recipes/28-terrain.md +36 -3
- package/docs/recipes/29-grid.md +46 -19
- package/docs/recipes/30-templates.md +72 -15
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +51 -4
- package/docs/recipes/34-environment-lighting.md +108 -21
- package/docs/recipes/35-picture-from-reference.md +147 -0
- package/docs/recipes/36-sky-ground-plants.md +158 -0
- package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -12
- package/docs/recipes/38-environment-hooks.md +67 -0
- package/docs/recipes/40-scene.md +114 -32
- package/docs/recipes/42-terrain-shape.md +2 -2
- package/docs/recipes/43-shader-patches-surfaces.md +206 -0
- package/docs/recipes/44-water-weather-hooks.md +191 -0
- package/docs/recipes/45-cascaded-shadows.md +130 -23
- package/docs/recipes/46-blender-art-route.md +17 -20
- package/docs/recipes/47-island-snow-backdrop.md +13 -15
- package/docs/recipes/49-game-module-contract.md +30 -17
- package/docs/recipes/50-own-renderer.md +4 -4
- package/docs/recipes/51-capability-catalog.md +3 -3
- package/docs/recipes/52-around-the-picture.md +181 -0
- package/docs/recipes/53-ground-up-close.md +12 -12
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +124 -0
- package/docs/recipes/56-webgpu-tsl.md +303 -0
- package/docs/recipes/57-control.md +104 -0
- package/docs/recipes/58-input.md +60 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +70 -0
- package/docs/recipes/61-deploy.md +27 -0
- package/docs/recipes/62-picture-code.md +244 -0
- package/docs/recipes/63-third-person-start.md +77 -0
- package/docs/recipes/64-particles.md +35 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +20 -14
- package/examples/action/assets.js +8 -0
- package/examples/action/content/actions.js +1 -1
- package/examples/action/content/audio.js +5 -5
- package/examples/action/main.js +12 -15
- package/examples/action/models.js +23 -24
- 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/plain-picture/.threedog/content-index.json +1 -0
- package/examples/plain-picture/FINDINGS.md +53 -0
- package/examples/plain-picture/GAMEMAP.md +90 -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 +133 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +88 -0
- package/examples/rc2d/README.md +57 -0
- package/examples/rc2d/main.js +55 -0
- 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 +187 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +22 -17
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/content/templates.js +1 -1
- package/examples/sheepisland/content/vegetation.js +3 -1
- package/examples/sheepisland/main.js +29 -18
- package/examples/sheepisland/{style/models.js → models.js} +13 -24
- package/examples/sheepisland/picture/index.js +20 -0
- package/examples/sheepisland/picture/lights.js +34 -0
- package/examples/sheepisland/picture/materials.js +61 -0
- package/examples/sheepisland/picture/palette.js +60 -0
- package/examples/sheepisland/picture/sky.js +20 -0
- package/examples/sheepisland/views.js +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +25 -22
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/main.js +25 -34
- package/examples/styletest/models.js +30 -30
- package/examples/styletest/params.js +2 -5
- 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 +91 -0
- package/examples/techniques/contact-shadows/contactShadows.js +67 -0
- package/examples/techniques/contact-shadows/main.js +55 -0
- 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 +83 -0
- package/examples/techniques/day-night-grade/main.js +41 -0
- 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 +106 -0
- package/examples/techniques/interior-light/interiorLight.js +47 -0
- package/examples/techniques/interior-light/main.js +87 -0
- 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 +126 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +39 -0
- 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 +95 -0
- package/examples/techniques/night-lights/main.js +47 -0
- package/examples/techniques/night-lights/nightLights.js +95 -0
- 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 +59 -0
- package/examples/techniques/outlines-and-rim/main.js +61 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- 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 +79 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +47 -0
- 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 +118 -0
- package/examples/techniques/procedural-surface/README.md +69 -0
- package/examples/techniques/procedural-surface/main.js +65 -0
- 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/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +74 -0
- package/examples/techniques/stylized-shading/main.js +62 -0
- 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 +131 -0
- package/examples/techniques/sun-and-key-light/README.md +133 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +71 -0
- package/examples/techniques/sun-and-key-light/main.js +51 -0
- 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 +102 -0
- package/examples/techniques/wet-road/main.js +48 -0
- 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/techniques/wet-road/wetRoad.js +209 -0
- package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
- package/examples/webgpu-tsl/GAMEMAP.md +89 -0
- package/examples/webgpu-tsl/README.md +45 -0
- package/examples/webgpu-tsl/main.js +44 -0
- 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 -0
- package/examples/world/GAMEMAP.md +31 -21
- package/examples/world/art/humanoid.js +38 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +57 -0
- package/examples/world/art/shapes.js +9 -0
- package/examples/world/assets.js +6 -0
- package/examples/world/content/audio.js +5 -5
- package/examples/world/content/items.js +1 -1
- package/examples/world/content/npcs.js +1 -1
- package/examples/world/content/props.js +1 -1
- package/examples/world/content/rules.js +1 -1
- package/examples/world/content/templates.js +1 -1
- package/examples/world/content/vegetation.js +1 -1
- package/examples/world/main.js +22 -18
- 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 +44 -54
- package/index.js +29 -25
- package/llms.txt +24 -15
- package/modules/ambience/Ambience.js +34 -23
- package/modules/calendar/Calendar.js +163 -0
- package/modules/calendar/contract.js +21 -0
- package/modules/calendar/index.js +82 -0
- package/modules/{sky → calendar}/schedule.js +17 -16
- package/modules/calendar/seasons.js +55 -0
- package/modules/camera/FirstPersonCamera.js +6 -15
- package/modules/camera/FixedCamera.js +33 -15
- package/modules/camera/FollowCamera.js +90 -16
- package/modules/camera/RtsCamera.js +18 -17
- package/modules/camera/common.js +73 -20
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +188 -48
- package/modules/characters/NPC.js +92 -41
- package/modules/characters/assetModel.js +8 -16
- package/modules/characters/behaviors.js +2 -1
- package/modules/characters/contract.js +13 -0
- package/modules/characters/footsteps.js +1 -1
- package/modules/characters/index.js +112 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +102 -19
- package/modules/characters/movers/manual.js +23 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +186 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +17 -9
- package/modules/characters/npcView.js +44 -16
- package/modules/characters/pathAsync.js +7 -3
- package/modules/characters/playerStrings.js +4 -3
- package/modules/characters/proceduralRig.js +19 -4
- package/modules/characters/useModel.js +2 -2
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +69 -27
- package/modules/collision/grid.js +8 -6
- package/modules/content/explain.js +2 -2
- package/modules/content/fields.js +102 -0
- package/modules/content/ids.js +8 -6
- package/modules/content/index.js +104 -27
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +58 -42
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +20 -11
- package/modules/content/rules.js +66 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +123 -30
- package/modules/debug/DebugPanel.js +24 -17
- package/modules/flow/contract.js +16 -0
- package/modules/flow/index.js +21 -15
- package/modules/gameplay/Container.js +41 -32
- package/modules/gameplay/Containers.js +30 -15
- package/modules/gameplay/Dialogue.js +113 -55
- package/modules/gameplay/Interactions.js +273 -72
- package/modules/gameplay/Inventory.js +72 -76
- package/modules/gameplay/Quests.js +75 -39
- package/modules/gameplay/boxOps.js +3 -3
- package/modules/gameplay/dialogue.contract.js +21 -0
- package/modules/gameplay/dialogueBox.js +4 -2
- package/modules/gameplay/dialogueBubbles.js +116 -0
- package/modules/gameplay/interactionPrompt.js +4 -1
- package/modules/gameplay/interactions.contract.js +16 -0
- package/modules/gameplay/inventory.contract.js +23 -0
- package/modules/gameplay/inventoryOps.js +19 -17
- package/modules/gameplay/pickups.js +306 -85
- package/modules/gameplay/questLog.js +6 -6
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +27 -13
- package/modules/grid/index.js +96 -43
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +37 -29
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +19 -22
- package/modules/hlod/index.js +52 -19
- package/modules/hud/index.js +48 -20
- package/modules/hud/parts.js +28 -13
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +49 -23
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +47 -19
- package/modules/music/Music.js +38 -21
- package/modules/music/rules.js +1 -1
- package/modules/nav/index.js +48 -42
- package/modules/net/Client.js +13 -6
- package/modules/net/Host.js +19 -5
- package/modules/net/Net.js +2 -1
- package/modules/net/index.js +13 -8
- package/modules/net/sync.js +9 -8
- package/modules/net/transports.js +77 -27
- package/modules/particles/Particles.js +58 -28
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +54 -11
- package/modules/photo/Photo.js +56 -38
- package/modules/rigid/RigidBodies.js +194 -32
- package/modules/rigid/Vehicles.js +18 -15
- package/modules/rigid/sync.js +62 -17
- package/modules/settings/Settings.js +60 -55
- package/modules/settings/apply.js +38 -3
- package/modules/settings/sections.js +5 -3
- package/modules/settings/strings.js +3 -2
- package/modules/settings/view.js +5 -3
- package/modules/sky/Sky.js +132 -205
- package/modules/sky/clouds.js +37 -23
- package/modules/sky/dome.js +100 -0
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +45 -99
- package/modules/sky/fog.js +9 -139
- package/modules/sky/frame.js +60 -56
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +63 -35
- package/modules/sky/skyModule.js +52 -37
- package/modules/sky/tint.js +59 -0
- package/modules/terrain/ChunkManager.js +194 -110
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/draw.js +154 -0
- package/modules/terrain/index.js +87 -54
- package/modules/terrain/terrainDefaults.js +2 -2
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +6 -4
- package/modules/terrain/terrainIsland.js +5 -4
- package/modules/terrain/terrainShape.js +12 -12
- package/modules/terrain/terrainShapeMain.js +8 -7
- package/modules/terrain/terrainTexture.js +21 -19
- package/modules/timeline/Timeline.js +95 -43
- package/modules/timeline/Tween.js +18 -10
- package/modules/timeline/letterbox.js +2 -2
- package/modules/timeline/shots.js +5 -1
- package/modules/triggers/index.js +111 -76
- package/modules/vegetation/Vegetation.js +229 -112
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/draw.js +191 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +32 -11
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +8 -2
- package/modules/water/Water.js +157 -72
- package/modules/water/surface.js +86 -47
- package/modules/weather/Weather.js +96 -103
- package/modules/weather/particles.js +37 -14
- package/modules/weather/shaders.js +1 -1
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherDraw.js +141 -0
- package/modules/world/World.js +26 -9
- package/modules/world/explain.js +1 -1
- package/modules/world/index.js +18 -4
- package/modules/world/persist.js +62 -2
- package/modules/world/pos.js +3 -2
- package/modules/world/records.js +8 -6
- package/modules/world/sim.js +60 -20
- package/modules/world/simFar.js +4 -3
- package/modules/world/state.js +3 -2
- package/modules/world/thingSource.js +1 -1
- package/modules/world/views.js +8 -6
- package/package.json +8 -3
- package/presets.js +43 -29
- package/render/PostFX.js +318 -135
- package/render/backend.js +486 -0
- package/render/cascades.js +195 -0
- package/render/cascades.tsl.js +96 -0
- package/render/daylight.js +39 -0
- package/render/detail.js +122 -41
- package/render/effects.js +155 -48
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cel.tsl.js +42 -0
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +28 -0
- package/render/fx/lighting.tsl.js +28 -0
- package/render/fx/nodeErrors.tsl.js +68 -0
- package/render/fx/noise.tsl.js +12 -0
- package/render/fx/objectOrigin.tsl.js +42 -0
- package/render/fx/particles.tsl.js +139 -0
- package/render/fx/patchNodes.tsl.js +403 -0
- package/render/fx/postWebGPU.tsl.js +181 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +187 -0
- package/render/fx/uniforms.tsl.js +67 -0
- package/render/fx/water.tsl.js +53 -0
- package/render/fx/wind.tsl.js +22 -0
- package/render/fxNumbers.js +36 -0
- package/render/hotGlsl.js +24 -0
- package/render/layers.js +14 -0
- package/render/lighting.js +71 -18
- package/render/lightmap.js +142 -0
- package/render/lights.js +47 -6
- package/render/materials.js +55 -152
- package/render/modeling.js +73 -0
- package/render/neutral.js +23 -0
- package/render/occlusion.js +184 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +317 -35
- package/render/postWebGL.js +205 -0
- package/render/probes.js +288 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/terms.js +163 -0
- package/render/uniformDecl.js +4 -3
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +757 -346
- package/types/gameplay.d.ts +539 -330
- package/types/generated/core/Audio.d.ts +26 -42
- package/types/generated/core/Batching.d.ts +6 -2
- package/types/generated/core/Budget.d.ts +2 -8
- package/types/generated/core/DebugOverrides.d.ts +58 -9
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +110 -32
- package/types/generated/core/Ops.d.ts +31 -0
- package/types/generated/core/Random.d.ts +2 -2
- package/types/generated/core/Saves.d.ts +10 -2
- package/types/generated/core/Stream.d.ts +1 -1
- package/types/generated/core/Threads.d.ts +4 -1
- package/types/generated/core/Views.d.ts +0 -1
- package/types/generated/core/audioVoice.d.ts +17 -9
- package/types/generated/core/control.d.ts +55 -0
- package/types/generated/core/page.d.ts +9 -2
- package/types/generated/core/session.d.ts +2 -1
- package/types/generated/modules/ambience/Ambience.d.ts +0 -9
- package/types/generated/modules/calendar/Calendar.d.ts +84 -0
- package/types/generated/modules/calendar/index.d.ts +10 -0
- package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
- package/types/generated/modules/grid/Grid.d.ts +61 -25
- package/types/generated/modules/grid/Layer.d.ts +13 -5
- package/types/generated/modules/grid/index.d.ts +56 -20
- package/types/generated/modules/music/Music.d.ts +5 -3
- package/types/generated/modules/net/index.d.ts +3 -3
- package/types/generated/modules/net/transports.d.ts +12 -3
- package/types/generated/modules/particles/Particles.d.ts +13 -6
- package/types/generated/modules/sky/Sky.d.ts +85 -110
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/water/Water.d.ts +50 -3
- package/types/generated/modules/weather/Weather.d.ts +44 -15
- package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
- package/types/generated/modules/world/World.d.ts +20 -5
- package/types/generated/render/PostFX.d.ts +109 -29
- package/types/generated/render/lighting.d.ts +29 -0
- package/types/generated/render/materials.d.ts +31 -50
- package/types/generated/render/modeling.d.ts +30 -0
- package/types/generated/render/occlusion.d.ts +13 -0
- package/types/generated/render/patches.d.ts +16 -2
- package/types/generated/ui/UI.d.ts +6 -3
- package/types/nav.d.ts +6 -0
- package/types/physics.d.ts +140 -45
- package/types/tsl.d.ts +94 -0
- package/types/world.d.ts +489 -122
- package/ui/Focus.js +35 -14
- package/ui/LoadingScreen.js +3 -3
- package/ui/Parts.js +35 -15
- package/ui/UI.js +27 -17
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +36 -27
- package/ui/touchPart.js +2 -2
- package/core/claims.js +0 -51
- package/core/look/coreParts.js +0 -112
- package/core/look/layers.js +0 -136
- package/core/look/part.js +0 -173
- package/core/look/report.js +0 -79
- package/core/look/write.js +0 -86
- package/core/renamed.js +0 -22
- package/core/styleParts.js +0 -98
- package/docs/api/entities.md +0 -61
- package/docs/api/style.md +0 -134
- package/docs/recipes/09-style-pack.md +0 -169
- package/docs/recipes/35-style-from-reference.md +0 -84
- package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
- package/docs/recipes/38-environment-look-hooks.md +0 -88
- package/docs/recipes/41-thing-registry.md +0 -93
- package/docs/recipes/43-shader-patches-surface-looks.md +0 -135
- package/docs/recipes/44-water-weather-look-hooks.md +0 -135
- package/docs/recipes/48-make-material.md +0 -70
- package/docs/recipes/52-look.md +0 -146
- package/examples/action/look.js +0 -5
- package/examples/sheepisland/style/index.js +0 -79
- package/examples/styletest/look.js +0 -11
- package/examples/styletest/overrides.js +0 -33
- package/examples/styletest/panel.js +0 -135
- package/modules/entities/Entities.js +0 -243
- package/modules/entities/build.js +0 -25
- package/modules/entities/index.js +0 -4
- package/modules/sky/calendar.js +0 -80
- package/modules/sky/cascades.js +0 -125
- package/modules/sky/layers.js +0 -69
- package/modules/sky/look.js +0 -51
- package/modules/sky/lookFog.js +0 -80
- package/modules/sky/lookShadow.js +0 -50
- package/modules/sky/lookSky.js +0 -108
- package/modules/sky/shadow.js +0 -74
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/lookGround.js +0 -61
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/vegetation/lookWind.js +0 -37
- package/modules/water/look.js +0 -80
- package/modules/weather/look.js +0 -75
- package/modules/world/cells.js +0 -42
- package/render/lookSurface.js +0 -161
- package/render/postLook.js +0 -86
- package/render/surface.js +0 -69
- package/types/style.d.ts +0 -643
package/core/modules.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// See CLAUDE.md "writing a module" for the module shape; dispose is called by lifecycle.js in reverse install order.
|
|
3
3
|
//
|
|
4
4
|
// Run order (fixed / frame / afterRender / skip hooks): by stage first, then before / after within a stage, then install order.
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// stage only orders hooks; what a module may own and what happens when it throws come from its type (moduleTypes.js, errors.js).
|
|
6
|
+
// Stages (first to last): control timeline, camera -> ground terrain, level -> environment weather, sky, water
|
|
7
|
+
// -> gameplay interactions, dialogue, trigger zones -> effects particles, settings, objective markers
|
|
7
8
|
// -> late (the default) characters, physics, navigation... -> audio music
|
|
8
9
|
// before / after: lists of module names (not-installed names are ignored); they order modules only inside one stage.
|
|
9
10
|
// One that contradicts the stage order (a 'control' module with after: ['sky']) makes use() throw naming both modules and stages;
|
|
@@ -12,22 +13,35 @@
|
|
|
12
13
|
// before anything installs; if a module's install() then throws, the modules this call already installed are removed again
|
|
13
14
|
// (engine.name, module table, hooks; their dispose() runs) and the error is rethrown.
|
|
14
15
|
// Module state (engine.moduleStates): registered -> initializing -> running | failed; disposed after engine.dispose(). Modules without init() are
|
|
15
|
-
// running at once. fixed / frame / afterRender / skip hooks run only for modules
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
16
|
+
// running at once. fixed / frame / afterRender / skip hooks run only for running modules, so no module gets a hook before its init() finished
|
|
17
|
+
// (during start() or when installed later).
|
|
18
|
+
// Ownership: install(e, ctx) and init(e, ctx) get ctx = { name, track(handle), mod(point, o), control.take(character, o) }. A handle passed to ctx.track (events.on, onFixed, onFrame,
|
|
19
|
+
// clock timers, audio.measure... anything with remove()) belongs to the module and is removed with it: when the use() batch rolls back,
|
|
20
|
+
// when its init fails, and on engine.dispose() (before the module's own dispose). Listeners a module adds go through it, so an install
|
|
21
|
+
// that fails halfway leaves no ghost listener behind (review 0.4 A; the rollback spec checks every built-in module).
|
|
22
|
+
// ctx.mod(point, o) = ctx.track(engine.mod(point, { ...o, owner: ctx.name })): a module's changes to shared values go with it too.
|
|
23
|
+
// ctx.input.action(name, { context }) / ctx.input.bind(name, keys): the module's input declarations and bindings, gone with it too.
|
|
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
|
+
// 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
|
+
// 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;
|
|
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, 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
|
+
// other types: error tiers in errors.js) and start() goes on.
|
|
19
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);
|
|
20
33
|
// written as { module: 'what is lost without it' }, start() warns once in dev when it is missing: use this form for optional dependencies
|
|
21
34
|
// that change gameplay results, which must not be skipped silently.
|
|
22
|
-
import {
|
|
35
|
+
import { warnOnce, DEV, fmt, closest } from './validate.js';
|
|
23
36
|
import { codedError, coded } from './errorHints.js';
|
|
24
37
|
import { reportError } from './errors.js';
|
|
25
38
|
import { catalog, catalogSnap, catalogClaim } from './catalog.js';
|
|
26
39
|
import { readParams } from './params.js';
|
|
27
|
-
import {
|
|
40
|
+
import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
|
|
41
|
+
import { checkType, asModule } from './moduleTypes.js';
|
|
28
42
|
|
|
29
43
|
/** Stage -> sort position */
|
|
30
|
-
const STAGES = { control: 100,
|
|
44
|
+
const STAGES = { control: 100, ground: 200, environment: 300, gameplay: 400, effects: 450, late: 500, audio: 510 };
|
|
31
45
|
const HOOKS = ['fixed', 'frame', 'afterRender', 'skip'];
|
|
32
46
|
const STRINGS = {
|
|
33
47
|
cycle: 'module order forms a cycle: {path} (check before / after on these modules)',
|
|
@@ -37,12 +51,21 @@ const STRINGS = {
|
|
|
37
51
|
called: 'engine.use received the module function {name} itself; call it: {name}()',
|
|
38
52
|
twice: 'module {name} is already installed; the second engine.use({name}()) is ignored',
|
|
39
53
|
readyHook: 'module {name}: the load-complete hook is named isReady(e) (ready is always a boolean property in the engine); ready(e) will not be called',
|
|
40
|
-
|
|
54
|
+
// both ways out: the engine's part of that name, or the game's own provider (requires names a capability, never a particular module)
|
|
55
|
+
needs: "module {name} requires '{dep}', which no installed module provides. Fix: install the engine's part first, engine.use({dep}(), {name}(...)), "
|
|
56
|
+
+ "or your own module with provides: ['{dep}'] (then engine.{dep} is your module's API){typo}",
|
|
57
|
+
typo: " (did you mean '{hint}'? installed: {list})",
|
|
41
58
|
clash: 'module name {name} clashes with an existing engine property; pick another name',
|
|
59
|
+
slotClash: "module {name} provides '{slot}', but engine.{slot} is already an engine property, so dependents could not reach it there. Fix: pick another slot name",
|
|
42
60
|
lateInit: 'init of module {name} (installed after start)',
|
|
43
61
|
conflict: 'module {a} (stage "{sa}") sets {kind}: ["{b}"], but module {b} is in stage "{sb}", which always runs {kind} stage "{sa}" (stage order: {list}); '
|
|
44
62
|
+ 'before / after only order modules inside one stage. Fix: give both modules the same stage, or remove {kind}: ["{b}"] from {a}',
|
|
45
63
|
};
|
|
64
|
+
const CTX_OWNER = "ctx.mod('{point}', { owner }) in module {name}: ctx.mod names the module as the owner itself; drop owner (use engine.mod for another owner name)";
|
|
65
|
+
const BAD_HANDLE = 'ctx.track(handle) in module {name}: handle must have remove(), like the result of engine.events.on / onFixed / clock.after; got {got}';
|
|
66
|
+
const STALE = 'module {name} registered something after it was unloaded (its async init or a callback resumed after replaces / unload); it was removed at once. '
|
|
67
|
+
+ 'The module installed under that name now is not affected';
|
|
68
|
+
const STALE_INIT = 'init of module {name}, which was unloaded before it finished';
|
|
46
69
|
const hookCache = new WeakMap(); // module definition -> { fixed, frame, afterRender, skip } hook entries (reused when re-sorting)
|
|
47
70
|
|
|
48
71
|
/** Sort modules by stage, before / after and install order (Kahn topological sort; among the ready ones take the earliest stage,
|
|
@@ -83,6 +106,7 @@ function checkStages(list) {
|
|
|
83
106
|
}
|
|
84
107
|
|
|
85
108
|
export const moduleMethods = {
|
|
109
|
+
...slotMethods, // provides / replaces (moduleSlots.js)
|
|
86
110
|
/**
|
|
87
111
|
* Install one or more modules in order; dependencies must be installed first; hook order is described at the top of this file.
|
|
88
112
|
* All-or-nothing: the batch is validated first, and if an install() throws, the modules this call installed are removed again.
|
|
@@ -91,24 +115,39 @@ export const moduleMethods = {
|
|
|
91
115
|
* `await engine.loading.settled()` waits for it; engine.moduleStates shows where each module is.
|
|
92
116
|
*/
|
|
93
117
|
use(...mods) {
|
|
94
|
-
const
|
|
118
|
+
const opts = isUseOpts(mods.at(-1)) ? mods.pop() : null;
|
|
119
|
+
const list = mods.flat(Infinity), gone = this._replaced(list, opts?.replaces);
|
|
120
|
+
const plan = this._planUse(list, gone), done = [];
|
|
121
|
+
// replaces: the holder goes first (its tracked handles, its slot, its drawing parts, its dispose), so the newcomer's install sees a free slot
|
|
122
|
+
const removed = [...gone].map(n => this._unuse(n, true));
|
|
95
123
|
try {
|
|
96
124
|
for (const m of plan) {
|
|
97
|
-
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this)
|
|
125
|
+
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this);
|
|
126
|
+
done.push({ m, had, prev }); // before install(): what it tracked before throwing is removed too
|
|
127
|
+
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
|
|
128
|
+
const ctx = this._modCtx(m);
|
|
129
|
+
this._picture?.installing(m);
|
|
130
|
+
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
|
+
const api = asModule(this, m, () => m.install?.(this, ctx)) ?? m; // asModule: the type checks know who is installing (moduleTypes.js)
|
|
98
132
|
catalogClaim(this, m.name, snap); // ops / save parts / describe names it registered show under it in engine.catalog()
|
|
99
133
|
this.modules.set(m.name, m);
|
|
100
134
|
if (m.name) this[m.name] = api;
|
|
101
|
-
|
|
135
|
+
// 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
|
+
// a replaces: dependents name the capability, never the module that gives it
|
|
137
|
+
for (const slot of m.provides ?? []) if (slot !== m.name) { this[slot] = api; ctx.track(this._aliasSlot(slot, api)); }
|
|
102
138
|
this._modState.set(m.name, m.init ? (this._started ? 'initializing' : 'registered') : 'running');
|
|
103
139
|
}
|
|
104
140
|
} catch (err) {
|
|
105
141
|
for (const { m, had, prev } of done.reverse()) { // undo in reverse install order, like dispose
|
|
106
|
-
this.modules.
|
|
142
|
+
const installed = this.modules.get(m.name) === m;
|
|
143
|
+
this.modules.delete(m.name); this._modState.delete(m.name); this._modInst.delete(m.name);
|
|
107
144
|
if (had) this[m.name] = prev; else delete this[m.name]; // put back what was there (an undefined slot stays undefined), never blank it
|
|
108
|
-
|
|
145
|
+
this._dropTracked(m.name);
|
|
146
|
+
if (installed) try { m.dispose?.(this); } catch { /* the install error below is the one to report */ }
|
|
109
147
|
}
|
|
110
|
-
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)
|
|
111
148
|
this._sortHooks();
|
|
149
|
+
// a replaced module comes back, so a failed swap leaves the game as it was (it installs fresh: its old handles already went)
|
|
150
|
+
if (removed.length) try { this.use(...removed); } catch (e2) { reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
|
|
112
151
|
throw err;
|
|
113
152
|
}
|
|
114
153
|
this._sortHooks();
|
|
@@ -117,8 +156,11 @@ export const moduleMethods = {
|
|
|
117
156
|
},
|
|
118
157
|
/** @internal validate a batch without touching the engine (so a failure leaves nothing half-installed);
|
|
119
158
|
* returns the modules to install */
|
|
120
|
-
_planUse(list) {
|
|
121
|
-
const names = new Set(this.modules.keys()), plan = [];
|
|
159
|
+
_planUse(list, gone = new Set()) {
|
|
160
|
+
const names = new Set([...this.modules.keys()].filter(n => !gone.has(n))), plan = [];
|
|
161
|
+
// requires names a module or a capability: another module's provides (depend on 'inventory', not on whichever module gives it)
|
|
162
|
+
const caps = new Set(names);
|
|
163
|
+
for (const n of names) for (const s of this.modules.get(n).provides ?? []) caps.add(s);
|
|
122
164
|
for (const m of list) {
|
|
123
165
|
if (!m) continue;
|
|
124
166
|
if (typeof m === 'function') throw codedError('module-called', fmt(STRINGS.called, { name: m.name }));
|
|
@@ -127,13 +169,20 @@ export const moduleMethods = {
|
|
|
127
169
|
if (m.order != null) throw codedError('module-stage', fmt(STRINGS.order, { name: m.name, list: Object.keys(STAGES).join(', ') }));
|
|
128
170
|
if (m.stage != null && !(m.stage in STAGES))
|
|
129
171
|
throw codedError('module-stage', fmt(STRINGS.stage, { name: m.name, stage: m.stage, list: Object.keys(STAGES).join(', ') }));
|
|
130
|
-
|
|
131
|
-
|
|
172
|
+
checkType(m);
|
|
173
|
+
for (const dep of m.requires || []) if (!caps.has(dep)) {
|
|
174
|
+
const hint = closest(dep, [...caps]);
|
|
175
|
+
throw codedError('module-requires', fmt(STRINGS.needs, { name: m.name, dep, typo: hint ? fmt(STRINGS.typo, { hint, list: [...caps].join(', ') }) : '' }));
|
|
176
|
+
}
|
|
177
|
+
checkProvides(m);
|
|
178
|
+
for (const slot of m.provides ?? []) if (slot !== m.name && !gone.has(slot) && !names.has(slot) && slot in this && this[slot] !== undefined && !this._slotAlias?.has(slot))
|
|
179
|
+
throw codedError('module-provides', fmt(STRINGS.slotClash, { name: m.name, slot }));
|
|
132
180
|
if (DEV && m.params && m.options) readParams(m.name, m.params, m.options); // a definition built by hand still gets its options checked
|
|
133
|
-
if (m.name in this && this[m.name] !== undefined) throw codedError('module-name', fmt(STRINGS.clash, { name: m.name }));
|
|
134
|
-
names.add(m.name);
|
|
181
|
+
if (!gone.has(m.name) && m.name in this && this[m.name] !== undefined) throw codedError('module-name', fmt(STRINGS.clash, { name: m.name }));
|
|
182
|
+
names.add(m.name); caps.add(m.name); for (const s of m.provides ?? []) caps.add(s);
|
|
183
|
+
plan.push(m);
|
|
135
184
|
}
|
|
136
|
-
if (plan.length) { const all = [...this.modules.values(), ...plan]; checkStages(all); sortModules(all); }
|
|
185
|
+
if (plan.length) { const all = [...[...this.modules.values()].filter(m => !gone.has(m.name)), ...plan]; checkStages(all); sortModules(all); }
|
|
137
186
|
return plan;
|
|
138
187
|
},
|
|
139
188
|
/** @internal init of a module installed after start(): run now, tracked in engine.loading, errors through the error tiers;
|
|
@@ -142,9 +191,78 @@ export const moduleMethods = {
|
|
|
142
191
|
const L = this.loading, task = L._begin(m.name, 'module');
|
|
143
192
|
task.phase('build');
|
|
144
193
|
const snap = catalogSnap(this);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
194
|
+
// the instance and its ctx are taken now, not when the microtask runs: by then a same-named module may be installed in its place
|
|
195
|
+
const inst = this._modInst.get(m.name), ctx = this._modCtx(m, inst), live = () => this._isLive(m.name, inst);
|
|
196
|
+
L._track(Promise.resolve().then(() => asModule(this, m, () => m.init(this, ctx))).then(
|
|
197
|
+
() => { L._done(task); if (live()) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } },
|
|
198
|
+
e => {
|
|
199
|
+
L._fail(task, e);
|
|
200
|
+
// unloaded meanwhile: its handles already went with it, and the state / handles under this name belong to the newcomer now
|
|
201
|
+
if (!live()) return reportError(this, e, fmt(STALE_INIT, { name: m.name }), { soft: true });
|
|
202
|
+
this._setModState(m, 'failed'); this._dropTracked(m.name); reportError(this, e, fmt(STRINGS.lateInit, { name: m.name }), { module: m });
|
|
203
|
+
}));
|
|
204
|
+
},
|
|
205
|
+
/** @internal is this install (token from engine._modInst) still the module installed under its name? */
|
|
206
|
+
_isLive(name, inst) { return !this.disposed && inst !== undefined && this._modInst.get(name) === inst; },
|
|
207
|
+
/** @internal the ctx install / init receive: track(handle) ties a handle to the module's life (see the top of this file) */
|
|
208
|
+
_modCtx(m, inst = this._modInst.get(m.name)) {
|
|
209
|
+
const name = m.name;
|
|
210
|
+
const track = h => {
|
|
211
|
+
if (typeof h?.remove !== 'function') throw codedError('module-handle', fmt(BAD_HANDLE, { name, got: String(h) }));
|
|
212
|
+
if (this.disposed) { h.remove(); return h; } // a late registration after dispose: nothing will ever remove it otherwise
|
|
213
|
+
// a registration from an install that is gone (replaced / unloaded while its async init awaited): filing it under the name would hand it
|
|
214
|
+
// to the newcomer, which would then own a listener it never made; remove it now instead
|
|
215
|
+
if (!this._isLive(name, inst)) { if (DEV) warnOnce(coded('module-handle', fmt(STALE, { name }))); h.remove(); return h; }
|
|
216
|
+
let set = this._modTracked.get(name);
|
|
217
|
+
if (!set) this._modTracked.set(name, set = new Set());
|
|
218
|
+
set.add(h);
|
|
219
|
+
if (this._curModule === m) this._picture?.learn(m); // the module's own code called this: its file is the part's (core/pictureWriters.js)
|
|
220
|
+
return h;
|
|
221
|
+
};
|
|
222
|
+
// 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;
|
|
223
|
+
// and a handle that is not tracked is a weather multiplier still on after the module went
|
|
224
|
+
const mod = (point, o) => {
|
|
225
|
+
if (o?.owner !== undefined) throw codedError('mod-owner', fmt(CTX_OWNER, { point, name }));
|
|
226
|
+
return track(this.mod(point, { ...o, owner: name }));
|
|
227
|
+
};
|
|
228
|
+
// input: declare actions / bind the keys the game handed the module, owned by the module (removed with it); never a key of its own
|
|
229
|
+
const input = {
|
|
230
|
+
action: (n, o) => track(this.input.action(n, { ...o, owner: name })),
|
|
231
|
+
bind: (n, keys) => track(this.input.bind(n, keys, { owner: name })),
|
|
232
|
+
};
|
|
233
|
+
// control: engine.control.take with the module as default owner, tracked, so a module that goes (unload, rollback, replaces) hands back every
|
|
234
|
+
// character it was steering. Unlike mod an owner may be given: one module can hold several characters on its own names (one per cutscene run).
|
|
235
|
+
// A hold that ends by itself leaves the tracked set too, so a module taking control often (a cutscene a minute) does not pile up dead handles.
|
|
236
|
+
// Taking the same character again under the same owner replaces the hold, so the stale handle leaves the tracked set as well.
|
|
237
|
+
const held = new Map(); // `${id} ${owner}` -> the live handle
|
|
238
|
+
const control = {
|
|
239
|
+
take: (who, o = {}) => {
|
|
240
|
+
const h = this.control.take(who, { ...o, owner: o.owner ?? name }), end = h.remove, key = `${h.id} ${h.owner}`;
|
|
241
|
+
const old = held.get(key);
|
|
242
|
+
if (old) this._modTracked.get(name)?.delete(old);
|
|
243
|
+
held.set(key, h);
|
|
244
|
+
h.remove = () => { end(); if (held.get(key) === h) held.delete(key); this._modTracked.get(name)?.delete(h); };
|
|
245
|
+
return track(h);
|
|
246
|
+
},
|
|
247
|
+
has: (who, owner = name) => this.control.has(who, owner),
|
|
248
|
+
};
|
|
249
|
+
// whileCompiling: a one-time warm-up (a WASM library's first call) run while start() waits for the GPU to compile shaders, when the page's
|
|
250
|
+
// thread is idle anyway (startup.js); after start() it runs at once
|
|
251
|
+
// It checks the install like track does: a warm-up queued by an install that was unloaded before start() ran the queue must not run
|
|
252
|
+
// (it would touch state of an install that is gone), and one asked for by an install that is already stale is not queued at all
|
|
253
|
+
const whileCompiling = fn => {
|
|
254
|
+
if (!this._isLive(name, inst)) return;
|
|
255
|
+
const run = () => { if (this._isLive(name, inst)) fn(); };
|
|
256
|
+
if (this.ready) run(); else this._whileCompiling.push(run);
|
|
257
|
+
};
|
|
258
|
+
return { name, track, mod, input, control, whileCompiling };
|
|
259
|
+
},
|
|
260
|
+
/** @internal remove every handle a module tracked; one that throws is reported and the rest still go */
|
|
261
|
+
_dropTracked(name) {
|
|
262
|
+
const set = this._modTracked.get(name);
|
|
263
|
+
if (!set) return;
|
|
264
|
+
this._modTracked.delete(name);
|
|
265
|
+
for (const h of set) { try { h.remove(); } catch (err) { reportError(this, err, `remove() of a handle module ${name} tracked`, { soft: true }); } }
|
|
148
266
|
},
|
|
149
267
|
/** @internal move a module to a new state and refresh the hooks (initializing / failed modules run none) */
|
|
150
268
|
_setModState(m, state) {
|
|
@@ -170,14 +288,14 @@ export const moduleMethods = {
|
|
|
170
288
|
/** Run order of module hooks (module names, first to last), for debugging "who runs first". */
|
|
171
289
|
get moduleOrder() { return this._moduleOrder ?? []; },
|
|
172
290
|
|
|
173
|
-
/** Re-sort the module hooks in the main loop (disabled
|
|
291
|
+
/** Re-sort the module hooks in the main loop (disabled picture / ui modules are not put back). */
|
|
174
292
|
_sortHooks() {
|
|
175
293
|
const order = sortModules([...this.modules.values()]);
|
|
176
294
|
this._moduleOrder = order.map(m => m.name);
|
|
177
295
|
for (const k of HOOKS) this._hooks[k] = [];
|
|
178
296
|
for (const m of order) {
|
|
179
297
|
const st = this._modState.get(m.name);
|
|
180
|
-
if (this.disabledModules.has(m.name) || st
|
|
298
|
+
if (this.disabledModules.has(m.name) || st !== 'running') continue; // registered (init not run yet), initializing, failed: no hooks
|
|
181
299
|
let c = hookCache.get(m);
|
|
182
300
|
if (!c) hookCache.set(m, c = {});
|
|
183
301
|
for (const k of HOOKS) if (m[k]) this._hooks[k].push(c[k] ??= { fn: m[k].bind(m), name: m.name, mod: m });
|
|
@@ -189,7 +307,7 @@ export const moduleMethods = {
|
|
|
189
307
|
for (const m of this.modules.values()) {
|
|
190
308
|
const opt = m.optional;
|
|
191
309
|
if (!opt || Array.isArray(opt)) continue;
|
|
192
|
-
for (const [dep, what] of Object.entries(opt)) if (!this.modules.has(dep))
|
|
310
|
+
for (const [dep, what] of Object.entries(opt)) if (!this.modules.has(dep) && !this._provided(dep))
|
|
193
311
|
warnOnce(coded('module-requires', fmt(STRINGS.optional, { name: m.name, dep, what })));
|
|
194
312
|
}
|
|
195
313
|
},
|
package/core/movement.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the A* fallback pathfinding, the level heightfield step height and Character's default radius / step all read engine.movement by default, so no one keeps a private number.
|
|
4
4
|
// Core only holds this data and depends on no module (hard rule 2); a module's same-named option can still be passed and acts as an override.
|
|
5
5
|
// createEngine({ movement: { radius: 0.5 } }) -> engine.movement.radius === 0.5 (read-only, never changed at runtime)
|
|
6
|
-
import {
|
|
6
|
+
import { readParams, keysSchema } from './params.js';
|
|
7
7
|
import { codedError } from './errorHints.js';
|
|
8
8
|
|
|
9
9
|
/** Defaults (meters / degrees): radius is the character radius, height the character height, maxSlope the steepest walkable slope (degrees), stepHeight the step it can climb directly. */
|
|
@@ -11,7 +11,7 @@ export const MOVEMENT_DEFAULTS = { radius: 0.4, height: 1.8, maxSlope: 48, stepH
|
|
|
11
11
|
|
|
12
12
|
/** Build the read-only movement parameters. slopeRatio (rise over run) is maxSlope converted to a ratio, which lightweight collision tests against. */
|
|
13
13
|
export function createMovement(opts = {}) {
|
|
14
|
-
|
|
14
|
+
readParams('createEngine({ movement })', keysSchema(Object.keys(MOVEMENT_DEFAULTS)), opts);
|
|
15
15
|
const m = { ...MOVEMENT_DEFAULTS, ...opts };
|
|
16
16
|
for (const k of Object.keys(MOVEMENT_DEFAULTS)) if (!(m[k] > 0)) throw codedError('movement', `movement.${k} must be a positive number; got ${m[k]}`);
|
|
17
17
|
m.slopeRatio = Math.tan(m.maxSlope * Math.PI / 180);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// A model, used by name: the one path for "a model made in code (or a file), reused by name". Content (props, templates, vegetation), pickups and
|
|
2
|
+
// vegetation.define all resolve a model name here, so caching (baked file -> dev cache -> build), the per-name prototype and the shadow rule exist once.
|
|
3
|
+
// It lives in core because several modules need it and none of them owns it (content, inventory, vegetation): no module depends on another for it.
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
import { neutralMaterial } from '../render/neutral.js';
|
|
6
|
+
import { shadowDefaults } from './assetEntry.js';
|
|
7
|
+
import { paramValues } from './assetManifest.js';
|
|
8
|
+
|
|
9
|
+
/** One value or a list, as a list @internal */
|
|
10
|
+
export const list = v => (Array.isArray(v) ? v : [v]);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A model name (name or [name, params...]) whose asset entry is a generator (an asset pack's procedural model) goes through assets.cached:
|
|
14
|
+
* name = model name, params count into the cache key. Returns a Promise (geometry or Object3D); null for a file model or an unknown name (assets.model takes those)
|
|
15
|
+
*/
|
|
16
|
+
export function cachedModel(e, m) {
|
|
17
|
+
const [name, ...args0] = list(m), fn = e.assets.builder(name);
|
|
18
|
+
if (!fn) return null;
|
|
19
|
+
// every model asked for by name is remembered, so a dev hot swap (core/assetHot.js) can build the same name + params list again
|
|
20
|
+
const made = (e.assets._made ||= new Map());
|
|
21
|
+
(made.get(name) ?? made.set(name, new Map()).get(name)).set(JSON.stringify(m), m);
|
|
22
|
+
// a generator with a params schema gets one object: defaults < dev panel values < the call's own object (assetManifest.js paramValues)
|
|
23
|
+
const entry = e.assets.entries.get(name), args = entry?.schema ? [paramValues(entry, args0[0])] : args0;
|
|
24
|
+
// pass the generator function to cached as is (dev cache hashes its source); wrap only when there are several params
|
|
25
|
+
return args.length > 1 ? e.assets.cached(name, function (p) { return fn.apply(this, p); }, args) : e.assets.cached(name, fn, args[0]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A model name in model / lod position: 'pine' or ['flower', 0xff0000] (content data and vegetation.define take the same form) @internal */
|
|
29
|
+
export const isModelName = m => typeof m === 'string' || Array.isArray(m) && typeof m[0] === 'string';
|
|
30
|
+
/**
|
|
31
|
+
* A vegetation model by name: { geometry } for a generator that returns geometry or for a file model (its first mesh), { model } for a generator
|
|
32
|
+
* that returns an Object3D (one material per mesh kept). content's vegetation table and vegetation.define(name, { model: 'pine' }) both resolve here,
|
|
33
|
+
* so a name means the same thing in data and in code. @internal
|
|
34
|
+
*/
|
|
35
|
+
export async function vegetationModel(e, m) {
|
|
36
|
+
const r = await (cachedModel(e, m) ?? e.assets.geometry(list(m)[0]));
|
|
37
|
+
return r?.isObject3D ? { model: r } : { geometry: r };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// One prototype per model name: a generator entry -> assets.cached (baked file / dev cache); a file entry -> assets.model. Content names models only (no paths).
|
|
41
|
+
// The only entry for "reuse a code-made model by name": content props / templates / vegetation and ground pickups all take it from here, so cache, bake and shadow rules exist once.
|
|
42
|
+
const protos = new WeakMap(); // owner (engine.content, or the inventory for pickups) → Map(model key → Promise<{ obj, size, center, fromGeometry }>)
|
|
43
|
+
const protoPalette = new WeakMap(); // prototype promise → the palette it was built from (null for a file model)
|
|
44
|
+
const owners = new WeakMap(); // engine → Set(owner): a hot swap walks every owner's prototypes of a changed name
|
|
45
|
+
/** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assetHot.js @internal */
|
|
46
|
+
export const protoCaches = e => [...(owners.get(e) ?? [])].map(api => ({ api, cache: protos.get(api) }));
|
|
47
|
+
/**
|
|
48
|
+
* The shared prototype of a model name (or [name, ...params]): { obj, size, center, fromGeometry }. fromGeometry: the generator returned a bare
|
|
49
|
+
* geometry, wrapped here in a mesh of neutral gray; a caller with a material of its own (pickups) swaps that one. @internal
|
|
50
|
+
*/
|
|
51
|
+
export function protoOf(e, api, model) {
|
|
52
|
+
if (!protos.has(api)) protos.set(api, new Map());
|
|
53
|
+
(owners.get(e) ?? owners.set(e, new Set()).get(e)).add(api);
|
|
54
|
+
const cache = protos.get(api), key = JSON.stringify(model), palette = e.assets.builder(list(model)[0]) ? e.assets._paletteKey : null;
|
|
55
|
+
// a palette written since this prototype was built: the next placement builds again, the same rule assets.cached has by its key
|
|
56
|
+
if (cache.has(key) && protoPalette.get(cache.get(key)) !== palette) cache.delete(key);
|
|
57
|
+
if (!cache.has(key)) {
|
|
58
|
+
const gen = cachedModel(e, model);
|
|
59
|
+
cache.set(key, (gen ? gen.then(r => {
|
|
60
|
+
const p = r.isObject3D ? r : new THREE.Mesh(r, neutralMaterial('prop', { vertexColors: !!r.attributes.color }));
|
|
61
|
+
if (!r.isObject3D) p.userData.fromGeometry = true;
|
|
62
|
+
// the generator's own castShadow / receiveShadow are kept (a decal or flat rug that must not cast); the manifest entry can set them;
|
|
63
|
+
// a generator that set none gets cast + receive. Same rule as assets.model (core/assetEntry.js shadowDefaults)
|
|
64
|
+
return shadowDefaults(p, e.assets.entries.get(list(model)[0])?.opts);
|
|
65
|
+
}) : e.assets.model(list(model)[0])).then(obj => {
|
|
66
|
+
const box = new THREE.Box3().setFromObject(obj); // collision and the "build within what distance" check both use the prototype's bounding box, computed once
|
|
67
|
+
obj.userData.modelKey = key; // copies carry it (clone copies userData): a hot swap whose new model has other parts finds them by it
|
|
68
|
+
return { obj, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()), fromGeometry: !!obj.userData.fromGeometry };
|
|
69
|
+
}));
|
|
70
|
+
protoPalette.set(cache.get(key), palette);
|
|
71
|
+
}
|
|
72
|
+
return cache.get(key);
|
|
73
|
+
}
|
|
74
|
+
|
package/core/opsCheck.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Each message says what is wrong and how to write it, because the reader is usually an AI that will fix the call from the text alone.
|
|
3
3
|
import { closest, fmt } from './validate.js';
|
|
4
4
|
import { codedError } from './errorHints.js';
|
|
5
|
-
import { parseSchema, whyBad,
|
|
5
|
+
import { parseSchema, whyBad, checkOf, OP_TYPES as TYPES } from './params.js'; // one type check for op args and module params
|
|
6
6
|
|
|
7
7
|
export const SOURCES = ['player', 'game', 'bridge', 'test', 'replay', 'net'];
|
|
8
8
|
const NAME = /^[a-z][a-zA-Z0-9]*(\.[a-z][a-zA-Z0-9]*)+$/;
|
|
@@ -77,7 +77,7 @@ export function checkArgs(e, d, args) {
|
|
|
77
77
|
for (const key in d.shape) {
|
|
78
78
|
const s = d.shape[key], v = args[key];
|
|
79
79
|
if (v === undefined) { if (!s.optional) throw devError(fmt(STRINGS.missing, { name, key, shape: shapeText })); continue; }
|
|
80
|
-
if (!
|
|
80
|
+
if (!checkOf(s.type)(v)) throw devError(fmt(STRINGS.wrong, { name, key, type: s.type === 'position' ? '[x, y, z]' : s.type, got: JSON.stringify(v), shape: shapeText }));
|
|
81
81
|
const range = whyBad(s, v); // min / max / values of the full schema form
|
|
82
82
|
if (range) throw devError(fmt(STRINGS.range, { name, key, why: range, shape: shapeText }));
|
|
83
83
|
if (s.type === 'id' && e._things.sources.length && !e._things.source(v)) throw devError(fmt(STRINGS.noRecord, { name, key, id: v }));
|
|
@@ -89,7 +89,7 @@ export function argRange(d, args) {
|
|
|
89
89
|
if (!d.shape || !args) return null;
|
|
90
90
|
for (const key in d.shape) {
|
|
91
91
|
const s = d.shape[key], v = args[key];
|
|
92
|
-
if (v === undefined || !
|
|
92
|
+
if (v === undefined || !checkOf(s.type)(v)) { if (v !== undefined) return { code: 'badArgs', facts: [{ id: d.name, field: key, actual: v, expected: s.type }] }; continue; }
|
|
93
93
|
const why = whyBad(s, v);
|
|
94
94
|
if (why) return { code: 'badArgs', facts: [{ id: d.name, field: key, actual: v, expected: why }] };
|
|
95
95
|
}
|
package/core/opsFail.js
CHANGED
|
@@ -2,17 +2,26 @@
|
|
|
2
2
|
// can: () => cond ? true : { code: 'noMoney', facts: { need: 5, have: 2 }, nextActions: [{ op: 'job.work', args: {} }] }
|
|
3
3
|
// facts: an object ({ need: 5, have: 2 }) or a list [{ id, field, actual, expected? }] (which record / field was wrong, and what it should have been). nextActions are declared by the game here, never guessed by the engine.
|
|
4
4
|
// run may fail the same way: return or throw { ok: false, code, facts?, nextActions? } (the op then counts as failed; an atomic op is rolled back).
|
|
5
|
-
// Every failed result from run / can / undo is normalized to { ok: false, code, facts, nextActions }; `code` is the name to read.
|
|
6
|
-
// is a hidden (non-enumerable) trap: reading it throws renamed-api and names result.code, in every build.
|
|
7
|
-
import { renamed } from './errorHints.js';
|
|
5
|
+
// Every failed result from run / can / undo is normalized to { ok: false, code, facts, nextActions }; `code` is the name to read.
|
|
8
6
|
const NONE = Object.freeze([]), NO_FACTS = Object.freeze({});
|
|
9
|
-
const TRAP = { get() { return renamed('reason'); }, enumerable: false, configurable: true };
|
|
10
7
|
|
|
11
|
-
/** @param {string | { code: string, facts?: object, nextActions?: any[] }} r a code string or a structured failure @returns {{ ok: false, code: string, facts: object, nextActions: any[]
|
|
8
|
+
/** @param {string | { code: string, facts?: object, nextActions?: any[] }} r a code string or a structured failure @returns {{ ok: false, code: string, facts: object, nextActions: any[] }} */
|
|
12
9
|
export function failure(r) {
|
|
13
10
|
const out = typeof r === 'string' ? { ok: false, code: r, facts: NO_FACTS, nextActions: NONE }
|
|
14
11
|
: { ok: false, code: r.code, facts: r.facts ?? NO_FACTS, nextActions: r.nextActions ?? NONE };
|
|
15
|
-
return
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Freeze owner held while a save's parts load (saveApply.js). A part's load() may return a Promise (an async terrain, a streamed world): until the
|
|
16
|
+
* last part is applied the game is half old, half new, so fixed steps stop (freeze) and ops refuse with code 'loading' (a click or a net message
|
|
17
|
+
* arriving in that gap would change the old state and be wiped, or act on a mix). Shared here so ops and the loader name the same owner.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export const PARTS_LOADING = 'threedog:load-parts';
|
|
21
|
+
/** Why ops refuse right now: 'halted' (a gameplay error froze the game), 'loading' (save parts still loading), or null @internal */
|
|
22
|
+
export function opsBlocked(e) {
|
|
23
|
+
const f = e.stacks.get('freeze');
|
|
24
|
+
return f.has('error') ? 'halted' : f.has(PARTS_LOADING) ? 'loading' : null;
|
|
16
25
|
}
|
|
17
26
|
/** True when can returned a usable structured failure */
|
|
18
27
|
export const isStructured = r => r !== null && typeof r === 'object' && typeof r.code === 'string' && r.code.length > 0;
|
package/core/opsGuard.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Ops.guard(where) is the public entry; the work is here.
|
|
3
3
|
import { coded } from './errorHints.js';
|
|
4
4
|
import { devError, fmt } from './opsCheck.js';
|
|
5
|
+
import { warnOnce } from './validate.js';
|
|
5
6
|
|
|
6
7
|
const STRINGS = {
|
|
7
8
|
canWrote: "{name}'s can changed state ({where}). can is read-only; change state in run",
|
|
@@ -18,9 +19,8 @@ export function guardWrite(ops, where) {
|
|
|
18
19
|
if (ops._client ? !e.ready || ops._allowDepth > 0 || where === 'world.move' : !e.ready || e._inFixed || ops._stack.length || ops._allowDepth > 0) return;
|
|
19
20
|
// first caller outside the engine: skip frames in engine folders, or in the bundle file this guard itself lives in
|
|
20
21
|
const lines = (new Error().stack || '').split('\n'), file = l => l.match(/\(?([^()\s]+?):\d+:\d+\)?$/)?.[1], own = file(lines[1] || '');
|
|
21
|
-
|
|
22
|
+
// 0 Error, 1 guardWrite, 2 Ops.guard, 3 the module method that called guard, then its callers
|
|
23
|
+
const at = lines.slice(4).find(l => !/\/(core|modules)\//.test(l) && file(l) !== own)?.trim() ?? '';
|
|
22
24
|
const key = where + '|' + at;
|
|
23
|
-
|
|
24
|
-
ops._warned.add(key);
|
|
25
|
-
console.warn(coded('ops-guard', fmt(ops._client ? STRINGS.clientGuard : STRINGS.guard, { where, at: at ? ', called ' + at : '' })));
|
|
25
|
+
warnOnce(coded('ops-guard', fmt(ops._client ? STRINGS.clientGuard : STRINGS.guard, { where, at: at ? ', called ' + at : '' })), 'ops-guard\0' + key); // once per call site
|
|
26
26
|
}
|
package/core/opsRun.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
import { DEV } from './validate.js';
|
|
4
4
|
import { devError, fmt, argRange } from './opsCheck.js';
|
|
5
5
|
import { reportError } from './errors.js';
|
|
6
|
-
import { failure, isRunFailure } from './opsFail.js';
|
|
6
|
+
import { failure, isRunFailure, opsBlocked } from './opsFail.js';
|
|
7
7
|
import { snapshot, rollback, markRolledBack } from './opsAtomic.js';
|
|
8
8
|
import { withDefaults } from './params.js';
|
|
9
9
|
|
|
10
10
|
const MAX_DEPTH = 16;
|
|
11
|
-
|
|
11
|
+
const RUN_STRINGS = {
|
|
12
12
|
canRun: "{name}'s can called ops.run('{inner}'). can is read-only; call other ops from run",
|
|
13
13
|
loop: 'ops call each other in a loop (deeper than ' + MAX_DEPTH + '): {chain}',
|
|
14
14
|
};
|
|
@@ -31,7 +31,8 @@ export function runOp(ops, name, args, opts) {
|
|
|
31
31
|
const parent = ops._stack.length ? ops._last : null;
|
|
32
32
|
const ctx = ops._ctx(name, args, opts, parent);
|
|
33
33
|
const depth = ops._stack.length, ev = e.events, where = `ops.run('${name}')`;
|
|
34
|
-
|
|
34
|
+
const blocked = opsBlocked(e);
|
|
35
|
+
if (blocked) { ops._log(name, args, ctx, false, blocked, depth); return ops._res(failure(blocked)); }
|
|
35
36
|
if (DEV && args && typeof args === 'object') Object.freeze(args);
|
|
36
37
|
const failed = (f, h) => { // a failed run: log it, trace it with its code
|
|
37
38
|
if (h) { h.ok = false; h.code = f.code; } else ops._log(name, args, ctx, false, f.code, depth);
|