threedog 0.2.0 → 0.5.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 +290 -0
- package/README.md +9 -8
- package/core/Animator.js +15 -12
- package/core/Assets.js +83 -16
- package/core/Audio.js +45 -38
- package/core/Baked.js +32 -8
- package/core/Batching.js +102 -15
- package/core/Budget.js +39 -18
- package/core/Clock.js +40 -80
- package/core/DebugOverrides.js +45 -10
- package/core/Describe.js +104 -43
- package/core/Engine.js +190 -57
- package/core/Events.js +4 -1
- package/core/I18n.js +25 -13
- package/core/Input.js +168 -79
- package/core/Inspect.js +2 -2
- package/core/InspectMaterials.js +85 -0
- package/core/InspectPerf.js +61 -0
- package/core/InspectScene.js +13 -2
- package/core/Loading.js +2 -1
- package/core/Ops.js +50 -9
- package/core/Random.js +9 -2
- package/core/Rays.js +5 -5
- package/core/SaveStore.js +41 -9
- package/core/Saves.js +71 -15
- package/core/Stream.js +14 -10
- package/core/Threads.js +26 -7
- package/core/UrlState.js +25 -9
- package/core/Views.js +9 -6
- package/core/actor.js +1 -1
- package/core/adaptive.js +93 -0
- package/core/assetEntry.js +22 -5
- package/core/assetHot.js +176 -0
- package/core/assetLoad.js +38 -11
- package/core/assetManifest.js +48 -9
- package/core/assetReport.js +1 -1
- package/core/audioRules.js +13 -11
- package/core/audioVoice.js +69 -42
- package/core/canvasBox.js +1 -2
- package/core/catalog.js +5 -2
- 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 +82 -15
- package/core/describeRender.js +43 -17
- package/core/describeText.js +41 -21
- package/core/engineCamera.js +32 -0
- package/core/errorCodes.js +438 -19
- package/core/errorHints.js +37 -141
- package/core/errors.js +31 -8
- package/core/events.generated.js +12 -7
- package/core/gameLights.js +62 -0
- package/core/grayMap.js +20 -0
- package/core/grid.js +128 -0
- package/core/gridLoad.js +20 -0
- 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 +48 -12
- package/core/lightWatch.js +6 -4
- package/core/look/coreParts.js +137 -30
- package/core/look/part.js +175 -95
- package/core/look/points.js +255 -0
- package/core/look/report.js +34 -17
- package/core/look/shadowPart.js +63 -0
- package/core/look/state.js +45 -0
- package/core/look/write.js +12 -28
- package/core/loop.js +101 -37
- package/core/math.js +11 -3
- package/core/moduleSlots.js +75 -0
- package/core/moduleTypes.js +73 -0
- package/core/modules.js +145 -27
- package/core/movement.js +2 -2
- package/core/namedModel.js +70 -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 +168 -0
- package/core/page.js +2 -1
- package/core/params.js +30 -8
- package/core/plugins.js +277 -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 +203 -0
- package/core/sceneMethods.js +35 -30
- 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 +2 -1
- package/core/sharedPoint.js +317 -0
- package/core/skip.js +36 -28
- package/core/stackFrames.js +34 -0
- package/core/stacks.js +166 -0
- package/core/startup.js +153 -11
- package/core/streamSources.js +0 -11
- package/core/styleParts.js +65 -47
- package/core/targeting.js +1 -1
- package/core/textureBytes.js +20 -0
- package/core/thingExplain.js +2 -2
- package/core/thingOps.js +29 -6
- package/core/things.js +21 -11
- 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 +7 -1
- package/core/validate.js +65 -86
- package/core/wrap.js +106 -0
- package/docs/AI.md +89 -97
- package/docs/API.md +32 -28
- package/docs/CODEMAP.md +224 -149
- package/docs/COMMANDS.md +57 -34
- package/docs/CONVENTIONS.md +92 -30
- package/docs/MIGRATING-0.3.md +248 -0
- package/docs/MIGRATING-0.4.md +228 -0
- package/docs/MIGRATING-0.5.md +68 -0
- package/docs/PERF.md +35 -7
- package/docs/THREE.md +79 -27
- package/docs/api/ambience.md +0 -1
- package/docs/api/assets.md +12 -9
- package/docs/api/audio.md +10 -14
- package/docs/api/calendar.md +41 -0
- package/docs/api/cameraRig.md +16 -5
- package/docs/api/characters.md +41 -25
- package/docs/api/clock.md +6 -5
- package/docs/api/collision.md +9 -6
- package/docs/api/content.md +6 -4
- package/docs/api/dialogue.md +9 -9
- package/docs/api/engine.md +65 -62
- package/docs/api/events.md +19 -14
- package/docs/api/grids.md +3 -3
- package/docs/api/ground.md +1 -1
- package/docs/api/hud.md +2 -2
- package/docs/api/i18n.md +1 -1
- package/docs/api/input.md +11 -6
- package/docs/api/interactions.md +7 -5
- package/docs/api/inventory.md +17 -16
- package/docs/api/level.md +0 -1
- package/docs/api/lightPool.md +3 -1
- package/docs/api/music.md +1 -1
- package/docs/api/nav.md +3 -0
- package/docs/api/openWorld.md +2 -1
- package/docs/api/particles.md +2 -2
- package/docs/api/photo.md +0 -2
- package/docs/api/pickups.md +15 -0
- package/docs/api/post.md +5 -4
- 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 +11 -44
- package/docs/api/stream.md +1 -1
- package/docs/api/style.md +31 -29
- package/docs/api/terrain.md +9 -6
- package/docs/api/terrainLook.md +10 -0
- package/docs/api/timeline.md +3 -4
- package/docs/api/tools.md +30 -13
- package/docs/api/triggers.md +5 -10
- package/docs/api/vegetation.md +12 -8
- package/docs/api/vegetationLook.md +10 -0
- package/docs/api/water.md +4 -20
- package/docs/api/weather.md +5 -15
- package/docs/api/weatherLook.md +10 -0
- package/docs/api/world.md +2 -1
- package/docs/recipes/01-new-game.md +71 -59
- package/docs/recipes/02-npc.md +46 -29
- package/docs/recipes/03-items-pickups.md +38 -24
- package/docs/recipes/04-quests.md +34 -27
- package/docs/recipes/05-props-bake.md +154 -18
- package/docs/recipes/06-clock-events.md +100 -52
- package/docs/recipes/07-flow-scenes-pause.md +41 -10
- package/docs/recipes/08-weather-sky.md +146 -37
- package/docs/recipes/09-style.md +218 -0
- package/docs/recipes/10-blender-level.md +14 -2
- package/docs/recipes/11-vehicles.md +64 -7
- package/docs/recipes/13-animation.md +34 -10
- package/docs/recipes/14-custom-module.md +65 -34
- package/docs/recipes/15-perf.md +35 -6
- package/docs/recipes/16-dev-bridge.md +65 -41
- package/docs/recipes/18-world.md +21 -8
- package/docs/recipes/19-shooting-picking.md +12 -11
- package/docs/recipes/20-content-actions-save.md +63 -25
- package/docs/recipes/21-camera.md +49 -16
- package/docs/recipes/22-shop-gold.md +18 -18
- package/docs/recipes/23-ops.md +17 -11
- package/docs/recipes/26-ui-parts.md +61 -12
- package/docs/recipes/27-net.md +12 -6
- package/docs/recipes/28-terrain.md +35 -2
- package/docs/recipes/29-grid.md +71 -33
- package/docs/recipes/30-templates.md +64 -12
- package/docs/recipes/31-audio.md +20 -12
- package/docs/recipes/32-action-game.md +35 -2
- package/docs/recipes/34-environment-lighting.md +27 -4
- package/docs/recipes/35-style-from-reference.md +115 -51
- package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
- package/docs/recipes/37-terrain-look-hooks.md +37 -15
- package/docs/recipes/38-environment-look-hooks.md +64 -48
- package/docs/recipes/40-scene.md +16 -13
- package/docs/recipes/41-thing-registry.md +11 -7
- package/docs/recipes/42-terrain-shape.md +3 -3
- package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
- package/docs/recipes/44-water-weather-look-hooks.md +30 -21
- package/docs/recipes/45-cascaded-shadows.md +17 -8
- package/docs/recipes/46-blender-art-route.md +4 -4
- package/docs/recipes/47-island-snow-backdrop.md +11 -10
- package/docs/recipes/48-make-material.md +11 -6
- package/docs/recipes/49-game-module-contract.md +46 -33
- package/docs/recipes/50-own-renderer.md +2 -2
- package/docs/recipes/51-capability-catalog.md +4 -4
- package/docs/recipes/52-look.md +228 -54
- package/docs/recipes/53-ground-up-close.md +58 -0
- package/docs/recipes/54-three-idioms.md +88 -0
- package/docs/recipes/55-mods-time-wrap.md +112 -0
- package/docs/recipes/56-webgpu-tsl.md +260 -0
- package/docs/recipes/57-control.md +65 -0
- package/docs/recipes/58-input.md +57 -0
- package/docs/recipes/59-depth-post-effects.md +83 -0
- package/docs/recipes/60-judge-the-picture.md +55 -0
- package/examples/action/.threedog/content-index.json +1 -0
- package/examples/action/GAMEMAP.md +17 -13
- 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/look.js +1 -1
- package/examples/action/main.js +10 -13
- package/examples/action/models.js +24 -23
- package/examples/pullable.json +111 -0
- package/examples/rc2d/.threedog/content-index.json +1 -0
- package/examples/rc2d/GAMEMAP.md +83 -0
- package/examples/rc2d/README.md +52 -0
- package/examples/rc2d/main.js +63 -0
- package/examples/rc2d/rc2d.js +197 -0
- package/examples/rc2d/shaders.js +144 -0
- package/examples/sheepisland/.threedog/content-index.json +1 -0
- package/examples/sheepisland/GAMEMAP.md +13 -11
- package/examples/sheepisland/assets.js +5 -0
- package/examples/sheepisland/main.js +17 -12
- package/examples/sheepisland/style/index.js +6 -6
- package/examples/styletest/.threedog/content-index.json +1 -0
- package/examples/styletest/GAMEMAP.md +15 -16
- package/examples/styletest/assets.js +6 -0
- package/examples/styletest/content/npcs.js +1 -1
- package/examples/styletest/content/templates.js +1 -1
- package/examples/styletest/content/vegetation.js +1 -1
- package/examples/styletest/look.js +1 -1
- package/examples/styletest/main.js +18 -17
- package/examples/styletest/models.js +1 -1
- package/examples/styletest/params.js +3 -3
- package/examples/techniques/contact-shadows/README.md +92 -0
- package/examples/techniques/contact-shadows/contactShadows.js +51 -0
- package/examples/techniques/contact-shadows/main.js +53 -0
- package/examples/techniques/day-night-grade/README.md +86 -0
- package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
- package/examples/techniques/day-night-grade/main.js +51 -0
- package/examples/techniques/interior-light/README.md +103 -0
- package/examples/techniques/interior-light/interiorLight.js +45 -0
- package/examples/techniques/interior-light/main.js +124 -0
- package/examples/techniques/modular-building/README.md +125 -0
- package/examples/techniques/modular-building/kit.js +426 -0
- package/examples/techniques/modular-building/main.js +47 -0
- package/examples/techniques/night-lights/README.md +94 -0
- package/examples/techniques/night-lights/main.js +70 -0
- package/examples/techniques/night-lights/nightLights.js +91 -0
- package/examples/techniques/outlines-and-rim/README.md +59 -0
- package/examples/techniques/outlines-and-rim/main.js +84 -0
- package/examples/techniques/outlines-and-rim/outlines.js +64 -0
- package/examples/techniques/procedural-animation/README.md +77 -0
- package/examples/techniques/procedural-animation/creature.js +44 -0
- package/examples/techniques/procedural-animation/main.js +45 -0
- package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
- package/examples/techniques/procedural-surface/README.md +67 -0
- package/examples/techniques/procedural-surface/main.js +103 -0
- package/examples/techniques/procedural-surface/surface.js +120 -0
- package/examples/techniques/stylized-shading/README.md +75 -0
- package/examples/techniques/stylized-shading/main.js +93 -0
- package/examples/techniques/stylized-shading/shading.js +131 -0
- package/examples/techniques/sun-and-key-light/README.md +135 -0
- package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
- package/examples/techniques/sun-and-key-light/main.js +95 -0
- package/examples/techniques/wet-road/README.md +99 -0
- package/examples/techniques/wet-road/main.js +68 -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 +84 -0
- package/examples/webgpu-tsl/README.md +42 -0
- package/examples/webgpu-tsl/main.js +21 -0
- package/examples/webgpu-tsl/tslScene.js +75 -0
- package/examples/world/.threedog/content-index.json +1 -0
- package/examples/world/GAMEMAP.md +22 -15
- package/examples/world/art/humanoid.js +42 -0
- package/examples/world/art/index.js +11 -0
- package/examples/world/art/models.js +58 -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/npcs.js +2 -2
- 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 +17 -13
- package/examples/world/style/index.js +61 -0
- package/examples/world/style/plugins/10-bloom.js +5 -0
- package/index.d.ts +50 -45
- package/index.js +27 -22
- package/llms.txt +20 -12
- 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 +81 -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 +70 -19
- package/modules/camera/contract.js +17 -0
- package/modules/camera/projection.js +11 -24
- package/modules/characters/Character.js +196 -59
- package/modules/characters/NPC.js +87 -36
- package/modules/characters/assetModel.js +27 -8
- 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 +87 -49
- package/modules/characters/moveHelpers.js +4 -5
- package/modules/characters/movers/common.js +97 -19
- package/modules/characters/movers/manual.js +20 -0
- package/modules/characters/movers/rapier.js +19 -16
- package/modules/characters/movers/simple.js +14 -11
- package/modules/characters/movers/support.js +172 -0
- package/modules/characters/npcAvoid.js +47 -42
- package/modules/characters/npcSim.js +12 -8
- 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 +46 -10
- package/modules/characters/useModel.js +1 -1
- package/modules/characters/vehicle.contract.js +21 -0
- package/modules/characters/walkTo.js +21 -7
- package/modules/collision/Collision.js +65 -25
- 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 +97 -28
- package/modules/content/loader.js +45 -33
- package/modules/content/models.js +11 -40
- package/modules/content/packs.js +6 -5
- package/modules/content/parts.js +41 -0
- package/modules/content/props.js +16 -9
- package/modules/content/rules.js +58 -0
- package/modules/content/stages.js +80 -0
- package/modules/content/templates.js +121 -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 +193 -67
- package/modules/gameplay/Inventory.js +69 -73
- 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 +18 -16
- package/modules/gameplay/pickups.js +268 -85
- package/modules/gameplay/questLog.js +4 -4
- package/modules/gameplay/quests.contract.js +17 -0
- package/modules/grid/Grid.js +92 -50
- package/modules/grid/Layer.js +14 -13
- package/modules/grid/index.js +60 -36
- package/modules/grid/ops.js +20 -18
- package/modules/grid/preview.js +15 -16
- package/modules/grid/strings.js +12 -0
- package/modules/grid/tiles.js +6 -5
- package/modules/hlod/index.js +51 -19
- package/modules/hud/index.js +35 -20
- package/modules/hud/parts.js +20 -7
- package/modules/level/heightfield.js +3 -1
- package/modules/level/index.js +45 -20
- package/modules/level/nodes.js +4 -3
- package/modules/lights/index.js +42 -18
- 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 +23 -14
- package/modules/particles/contract.js +17 -0
- package/modules/particles/effect.js +39 -11
- package/modules/photo/Photo.js +53 -36
- 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 +57 -52
- 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 +88 -176
- package/modules/sky/cascades.js +86 -25
- package/modules/sky/cascades.tsl.js +82 -0
- package/modules/sky/clouds.js +34 -19
- package/modules/sky/domeLayers.js +30 -15
- package/modules/sky/environment.js +83 -13
- package/modules/sky/fog.js +140 -95
- package/modules/sky/frame.js +112 -44
- package/modules/sky/look.js +22 -19
- package/modules/sky/lookFog.js +48 -52
- package/modules/sky/lookShadow.js +53 -41
- package/modules/sky/lookSky.js +82 -21
- package/modules/sky/season.js +21 -0
- package/modules/sky/shader.js +41 -19
- package/modules/sky/shadow.js +44 -20
- package/modules/sky/skyModule.js +45 -33
- package/modules/sky/tint.js +61 -0
- package/modules/terrain/ChunkManager.js +175 -108
- package/modules/terrain/chunkJob.js +1 -1
- package/modules/terrain/chunkQueries.js +6 -4
- package/modules/terrain/index.js +105 -50
- package/modules/terrain/look.js +83 -0
- package/modules/terrain/lookGround.js +21 -16
- package/modules/terrain/terrainDefaults.js +1 -1
- package/modules/terrain/terrainEdit.js +18 -20
- package/modules/terrain/terrainGen.js +5 -3
- 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 +107 -76
- package/modules/vegetation/Vegetation.js +190 -102
- package/modules/vegetation/densityMap.js +62 -0
- package/modules/vegetation/groundChunks.js +52 -58
- package/modules/vegetation/index.js +31 -10
- package/modules/vegetation/look.js +119 -0
- package/modules/vegetation/lookWind.js +71 -10
- package/modules/vegetation/modelGeometry.js +3 -2
- package/modules/vegetation/nearFade.js +45 -0
- package/modules/water/Water.js +65 -27
- package/modules/water/look.js +29 -18
- package/modules/water/surface.js +64 -25
- package/modules/water/surfaceDefaults.js +3 -0
- package/modules/weather/Weather.js +62 -104
- package/modules/weather/look.js +1 -2
- package/modules/weather/particles.js +24 -9
- package/modules/weather/strings.js +2 -2
- package/modules/weather/weatherLook.js +135 -0
- package/modules/world/World.js +24 -7
- 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 +7 -5
- package/package.json +8 -3
- package/presets.js +41 -27
- package/render/PostFX.js +145 -120
- package/render/backend.js +440 -0
- package/render/detail.js +150 -45
- package/render/effects.js +130 -38
- package/render/engineUniforms.js +10 -1
- package/render/fuse.js +5 -4
- package/render/fx/cloudShadow.tsl.js +16 -0
- package/render/fx/detail.tsl.js +66 -0
- package/render/fx/index.js +26 -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 +158 -0
- package/render/fx/season.tsl.js +13 -0
- package/render/fx/sky.tsl.js +260 -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/lighting.js +66 -14
- package/render/lights.js +223 -4
- package/render/lookGlow.js +139 -0
- package/render/lookSurface.js +99 -36
- package/render/materials.js +71 -52
- package/render/modeling.js +73 -0
- package/render/ownFrame.js +76 -0
- package/render/patches.js +311 -34
- package/render/postLook.js +124 -46
- package/render/postWebGL.js +197 -0
- package/render/probes.js +231 -0
- package/render/shaderErrors.js +154 -0
- package/render/slots.js +165 -0
- package/render/surface.js +53 -17
- package/render/terms.js +211 -0
- package/render/uniformDecl.js +3 -2
- package/types/common.d.ts +2 -2
- package/types/core.d.ts +620 -244
- package/types/gameplay.d.ts +494 -318
- 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 +44 -3
- package/types/generated/core/I18n.d.ts +2 -2
- package/types/generated/core/Input.d.ts +102 -31
- 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/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 +5 -5
- package/types/generated/modules/grid/index.d.ts +29 -17
- 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 +1 -1
- package/types/generated/modules/sky/Sky.d.ts +12 -104
- package/types/generated/modules/sky/skyModule.d.ts +1 -1
- package/types/generated/modules/timeline/Timeline.d.ts +8 -6
- package/types/generated/modules/weather/Weather.d.ts +17 -18
- package/types/generated/modules/weather/weatherLook.d.ts +12 -0
- package/types/generated/modules/world/World.d.ts +18 -3
- package/types/generated/render/PostFX.d.ts +67 -30
- package/types/generated/render/materials.d.ts +26 -20
- package/types/generated/render/modeling.d.ts +30 -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 +137 -44
- package/types/style.d.ts +125 -92
- package/types/tsl.d.ts +86 -0
- package/types/world.d.ts +164 -110
- package/ui/Focus.js +25 -14
- package/ui/LoadingScreen.js +1 -1
- package/ui/Parts.js +27 -11
- package/ui/UI.js +20 -10
- package/ui/cursor.js +115 -0
- package/ui/defaults.js +15 -11
- package/ui/theme.js +9 -6
- package/ui/touchPart.js +1 -1
- package/core/claims.js +0 -51
- package/core/look/layers.js +0 -136
- package/core/renamed.js +0 -21
- package/docs/api/entities.md +0 -61
- package/docs/recipes/09-style-pack.md +0 -234
- 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/layers.js +0 -69
- package/modules/terrain/chunkLevels.js +0 -40
- package/modules/terrain/mountTerrain.js +0 -32
- package/modules/world/cells.js +0 -42
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Exclusive slots for modules ("only one may hold this": 'sky', 'inventory', a tone-mapping stage), mixed into Engine with modules.js.
|
|
2
|
+
// provides: ['inventory'] the module holds the slot while installed (a kind 'one' shared point, core/sharedPoint.js);
|
|
3
|
+
// a second provider is shared-taken, naming both and the replaces fix
|
|
4
|
+
// requires: ['inventory'] depend on the slot, not on whichever module gives it
|
|
5
|
+
// engine.use(mine(), { replaces: 'inventory' }) unload the holder first (its tracked handles, slot, ctx.mod entries, look parts, dispose)
|
|
6
|
+
// Why the slot is a shared point and not a module-name table: one owner registry for everything (describe().shared shows the holder beside
|
|
7
|
+
// every shared value, ctx.track releases it with the rest), so there is no second mechanism to learn. Kept apart from modules.js only for size.
|
|
8
|
+
import { fmt } from './validate.js';
|
|
9
|
+
import { codedError } from './errorHints.js';
|
|
10
|
+
import { reportError } from './errors.js';
|
|
11
|
+
import { disposeLooksOf } from './look/part.js';
|
|
12
|
+
|
|
13
|
+
const STRINGS = {
|
|
14
|
+
provides: 'module {name}: provides is a list of exclusive slot names, e.g. provides: [\'inventory\']; got {got}',
|
|
15
|
+
notSlot: 'module {name} provides \'{slot}\', but \'{slot}\' is a shared value (kind {kind}), not an exclusive slot; pick a slot name of its own, or change the value with ctx.mod(\'{slot}\', { ... })',
|
|
16
|
+
noHolder: 'engine.use(..., { replaces: \'{slot}\' }): no installed module provides \'{slot}\', so there is nothing to replace. Fix: drop { replaces }, or check the slot name (describe().shared lists the slots held now)',
|
|
17
|
+
notProvided: 'engine.use(..., { replaces: \'{slot}\' }): none of the modules in this call provides \'{slot}\', so the swap would leave it empty. Fix: add provides: [\'{slot}\'] to the module that takes over from {holder}',
|
|
18
|
+
byName: 'engine.use(..., { replaces }): module {name} requires module \'{dep}\' by its name, and the swap unloads {dep}. Fix: in {name}, require the slot (requires: [\'<slot>\']) instead of the module name',
|
|
19
|
+
unuse: 'dispose hook of module {name} (unloaded by replaces)',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** engine.use(a(), b(), { replaces: 'sky' }): the options object is the last argument and has `replaces` (a module always has a name) */
|
|
23
|
+
export const isUseOpts = o => !!o && typeof o === 'object' && !Array.isArray(o) && !('name' in o) && 'replaces' in o;
|
|
24
|
+
|
|
25
|
+
/** _planUse: a module's provides must be a list of names (checked before anything installs) */
|
|
26
|
+
export function checkProvides(m) {
|
|
27
|
+
if (m.provides != null && !(Array.isArray(m.provides) && m.provides.every(s => typeof s === 'string' && s)))
|
|
28
|
+
throw codedError('module-provides', fmt(STRINGS.provides, { name: m.name, got: JSON.stringify(m.provides) }));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const slotMethods = {
|
|
32
|
+
/**
|
|
33
|
+
* @internal engine.use(mod, { replaces }): the installed modules that hold these slots, after checking the swap is well formed
|
|
34
|
+
* (the slot is held, the newcomer provides it, no installed module requires the old one by its module name).
|
|
35
|
+
* @returns {Set<string>} module names to unload
|
|
36
|
+
*/
|
|
37
|
+
_replaced(list, replaces) {
|
|
38
|
+
const gone = new Set();
|
|
39
|
+
if (replaces == null) return gone;
|
|
40
|
+
const provided = new Set(list.flatMap(m => m?.provides ?? []));
|
|
41
|
+
for (const slot of [].concat(replaces)) {
|
|
42
|
+
const holder = this.stacks.has(slot) && this.stacks.get(slot).kind === 'one' ? this.stacks.get(slot).value() : null;
|
|
43
|
+
if (!holder || !this.modules.has(holder)) throw codedError('module-replaces', fmt(STRINGS.noHolder, { slot }));
|
|
44
|
+
if (!provided.has(slot)) throw codedError('module-replaces', fmt(STRINGS.notProvided, { slot, holder }));
|
|
45
|
+
gone.add(holder);
|
|
46
|
+
}
|
|
47
|
+
for (const m of this.modules.values()) for (const dep of m.requires ?? []) if (gone.has(dep) && !gone.has(m.name) && !list.some(n => n?.name === dep) && !provided.has(dep))
|
|
48
|
+
throw codedError('module-replaces', fmt(STRINGS.byName, { name: m.name, dep }));
|
|
49
|
+
return gone;
|
|
50
|
+
},
|
|
51
|
+
/** @internal unload one installed module (replaces): tracked handles and slots, look parts, its dispose, the engine property; returns its definition */
|
|
52
|
+
_unuse(name) {
|
|
53
|
+
const m = this.modules.get(name);
|
|
54
|
+
this._dropTracked(name);
|
|
55
|
+
disposeLooksOf(this, name);
|
|
56
|
+
try { m.dispose?.(this); } catch (err) { reportError(this, err, fmt(STRINGS.unuse, { name }), { soft: true }); }
|
|
57
|
+
this.modules.delete(name); this._modState.delete(name); this._modInst.delete(name); delete this[name];
|
|
58
|
+
this._sortHooks();
|
|
59
|
+
return m;
|
|
60
|
+
},
|
|
61
|
+
/** @internal engine.<slot> -> the provider's API while it is installed (the returned handle is tracked by the provider, so it goes with it) */
|
|
62
|
+
_aliasSlot(slot, api) {
|
|
63
|
+
(this._slotAlias ??= new Set()).add(slot);
|
|
64
|
+
return { remove: () => { if (this[slot] === api) delete this[slot]; this._slotAlias.delete(slot); } };
|
|
65
|
+
},
|
|
66
|
+
/** @internal is this capability provided by an installed module? */
|
|
67
|
+
_provided(slot) { for (const m of this.modules.values()) if (m.provides?.includes(slot)) return true; return false; },
|
|
68
|
+
/** @internal the exclusive slot a module provides (a 'one' shared point, made on first use) */
|
|
69
|
+
_slot(slot, by) {
|
|
70
|
+
if (!this.stacks.has(slot)) return this.stacks.define(slot, { kind: 'one', save: false });
|
|
71
|
+
const s = this.stacks.get(slot);
|
|
72
|
+
if (s.kind !== 'one') throw codedError('module-provides', fmt(STRINGS.notSlot, { name: by, slot, kind: s.kind }));
|
|
73
|
+
return s;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
// look / ui fail soft, see core/errors.js). Mixed into Engine with modules.js.
|
|
3
|
+
// type: 'world' | 'look' | 'actor' | 'rules' | 'ui' | 'net' | 'tool' -- every module declares one, built-in or the game's (missing = error).
|
|
4
|
+
// Why a type and not a rule in the docs: an AI follows the shape of the code, not a paragraph. A look module that defines an op, or a ui module that binds
|
|
5
|
+
// keys, is the start of two modules owning one thing; the check names the rule and the one-line fix where the mistake is made.
|
|
6
|
+
// No subtypes: differences inside a type are the declarations the engine already checks (provides, requires, shared values written with ctx.mod,
|
|
7
|
+
// material slots patched, the post stage, backends, sounds).
|
|
8
|
+
// 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
|
+
// (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
|
+
// attributed: the check is a guard rail at the common places, not a sandbox.
|
|
11
|
+
import { DEV, fmt } from './validate.js';
|
|
12
|
+
import { codedError } from './errorHints.js';
|
|
13
|
+
|
|
14
|
+
/** type -> what it may own (shown in the missing / unknown type error and in recipes/14) */
|
|
15
|
+
export const MODULE_TYPES = {
|
|
16
|
+
world: 'game state: save parts, world records, ops, ground / collision / navigation data (draws nothing)',
|
|
17
|
+
look: 'what is seen and heard: look values, three.js objects, particles, sounds (changes no game state)',
|
|
18
|
+
actor: 'characters: their control slots and movement values (other state only through ops)',
|
|
19
|
+
rules: 'game logic: save parts, ops, events; may take input, control or the camera for a while (a cutscene)',
|
|
20
|
+
ui: 'DOM panels and menus: declares input actions, runs ops (binds no keys, writes no game save)',
|
|
21
|
+
net: 'multiplayer: remote characters and the transport (other modules only through ops and their public API)',
|
|
22
|
+
tool: 'a one-shot job (a photo, a bake) that undoes itself when it ends or fails',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
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
|
+
unknown: "module {name} has type '{type}', which is not a module type. Fix: use one of {list}",
|
|
28
|
+
// rule broken at runtime: module, type, what it did, why not, the fix
|
|
29
|
+
broke: "module {name} (type '{type}') {did}: {why}. Fix: {fix}",
|
|
30
|
+
};
|
|
31
|
+
const RULES = {
|
|
32
|
+
// [types it is wrong for, why, fix]
|
|
33
|
+
'ops.define': [['look'], 'a look module only shows the game, it never adds actions that change it',
|
|
34
|
+
"define the op in a rules (or world) module and let the look module read the state; or give {name} type: 'rules' if it really is game logic"],
|
|
35
|
+
'world.write': [['look', 'ui'], 'world records are game state; a {type} module only reads them',
|
|
36
|
+
"run an op that writes it (engine.ops.run('<noun.verb>', args)) or move the write into a rules / world module"],
|
|
37
|
+
'input.bind': [['ui'], 'a ui module declares actions; which key does what is the game\'s choice',
|
|
38
|
+
"declare the action (ctx.input.action(name, { context })) and bind keys in the game: engine.input.bind(name, ['KeyE']) or createEngine({ bindings })"],
|
|
39
|
+
'saves.register': [['ui'], 'a ui module keeps menus and preferences out of the game save (a load must not change the volume)',
|
|
40
|
+
'keep preferences in browser storage (engine.settings does), and game state in a rules / world module'],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** _planUse: the module's type must be one of MODULE_TYPES (missing or unknown = error naming the fix) */
|
|
44
|
+
export function checkType(m) {
|
|
45
|
+
const list = Object.keys(MODULE_TYPES).map(t => `'${t}'`).join(' | ');
|
|
46
|
+
if (m.type == null) throw codedError('module-type', fmt(STRINGS.missing, { name: m.name, guess: 'rules', list }));
|
|
47
|
+
if (!(m.type in MODULE_TYPES)) throw codedError('module-type', fmt(STRINGS.unknown, { name: m.name, type: String(m.type), list }));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @internal dev check at a write point: the module installing or running a hook now may not do `what` if its type forbids it.
|
|
52
|
+
* what: 'ops.define' | 'world.write' | 'input.bind' | 'saves.register'; did: what it did, for the message ("defined op shop.buy").
|
|
53
|
+
*/
|
|
54
|
+
export function checkTypeRule(e, what, did) {
|
|
55
|
+
const m = DEV ? e?._curModule : null;
|
|
56
|
+
if (!m) return;
|
|
57
|
+
const [types, why, fix] = RULES[what];
|
|
58
|
+
if (!types.includes(m.type)) return;
|
|
59
|
+
const v = { name: m.name, type: m.type };
|
|
60
|
+
throw codedError('module-type-rule', fmt(STRINGS.broke, { ...v, did, why: fmt(why, v), fix: fmt(fix, v) }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @internal run fn with m as the current module (install, init's synchronous part, a hook); restores the previous one */
|
|
64
|
+
export function asModule(e, m, fn) {
|
|
65
|
+
const was = e._curModule;
|
|
66
|
+
e._curModule = m;
|
|
67
|
+
try { return fn(); } finally { e._curModule = was; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @internal describe().modules row: name, type, and provides / requires when there are any */
|
|
71
|
+
export function moduleRow(m) {
|
|
72
|
+
return { name: m.name, type: m.type, ...(m.provides?.length ? { provides: [...m.provides] } : {}), ...(m.requires?.length ? { requires: [...m.requires] } : {}) };
|
|
73
|
+
}
|
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,36 @@
|
|
|
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, look 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 (look / 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
40
|
import { disposeLooksOf } from './look/part.js';
|
|
41
|
+
import { slotMethods, isUseOpts, checkProvides } from './moduleSlots.js';
|
|
42
|
+
import { checkType, asModule } from './moduleTypes.js';
|
|
28
43
|
|
|
29
44
|
/** Stage -> sort position */
|
|
30
|
-
const STAGES = { control: 100,
|
|
45
|
+
const STAGES = { control: 100, ground: 200, environment: 300, gameplay: 400, effects: 450, late: 500, audio: 510 };
|
|
31
46
|
const HOOKS = ['fixed', 'frame', 'afterRender', 'skip'];
|
|
32
47
|
const STRINGS = {
|
|
33
48
|
cycle: 'module order forms a cycle: {path} (check before / after on these modules)',
|
|
@@ -37,12 +52,21 @@ const STRINGS = {
|
|
|
37
52
|
called: 'engine.use received the module function {name} itself; call it: {name}()',
|
|
38
53
|
twice: 'module {name} is already installed; the second engine.use({name}()) is ignored',
|
|
39
54
|
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
|
-
|
|
55
|
+
// both ways out: the engine's part of that name, or the game's own provider (requires names a capability, never a particular module)
|
|
56
|
+
needs: "module {name} requires '{dep}', which no installed module provides. Fix: install the engine's part first, engine.use({dep}(), {name}(...)), "
|
|
57
|
+
+ "or your own module with provides: ['{dep}'] (then engine.{dep} is your module's API){typo}",
|
|
58
|
+
typo: " (did you mean '{hint}'? installed: {list})",
|
|
41
59
|
clash: 'module name {name} clashes with an existing engine property; pick another name',
|
|
60
|
+
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
61
|
lateInit: 'init of module {name} (installed after start)',
|
|
43
62
|
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
63
|
+ 'before / after only order modules inside one stage. Fix: give both modules the same stage, or remove {kind}: ["{b}"] from {a}',
|
|
45
64
|
};
|
|
65
|
+
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)";
|
|
66
|
+
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}';
|
|
67
|
+
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. '
|
|
68
|
+
+ 'The module installed under that name now is not affected';
|
|
69
|
+
const STALE_INIT = 'init of module {name}, which was unloaded before it finished';
|
|
46
70
|
const hookCache = new WeakMap(); // module definition -> { fixed, frame, afterRender, skip } hook entries (reused when re-sorting)
|
|
47
71
|
|
|
48
72
|
/** Sort modules by stage, before / after and install order (Kahn topological sort; among the ready ones take the earliest stage,
|
|
@@ -83,6 +107,7 @@ function checkStages(list) {
|
|
|
83
107
|
}
|
|
84
108
|
|
|
85
109
|
export const moduleMethods = {
|
|
110
|
+
...slotMethods, // provides / replaces (moduleSlots.js)
|
|
86
111
|
/**
|
|
87
112
|
* Install one or more modules in order; dependencies must be installed first; hook order is described at the top of this file.
|
|
88
113
|
* All-or-nothing: the batch is validated first, and if an install() throws, the modules this call installed are removed again.
|
|
@@ -91,24 +116,39 @@ export const moduleMethods = {
|
|
|
91
116
|
* `await engine.loading.settled()` waits for it; engine.moduleStates shows where each module is.
|
|
92
117
|
*/
|
|
93
118
|
use(...mods) {
|
|
94
|
-
const
|
|
119
|
+
const opts = isUseOpts(mods.at(-1)) ? mods.pop() : null;
|
|
120
|
+
const list = mods.flat(Infinity), gone = this._replaced(list, opts?.replaces);
|
|
121
|
+
const plan = this._planUse(list, gone), done = [];
|
|
122
|
+
// replaces: the holder goes first (its tracked handles, its slot, its look parts, its dispose), so the newcomer's install sees a free slot
|
|
123
|
+
const removed = [...gone].map(n => this._unuse(n));
|
|
95
124
|
try {
|
|
96
125
|
for (const m of plan) {
|
|
97
|
-
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this)
|
|
126
|
+
const had = Object.hasOwn(this, m.name), prev = this[m.name], snap = catalogSnap(this);
|
|
127
|
+
done.push({ m, had, prev }); // before install(): what it tracked before throwing is removed too
|
|
128
|
+
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
|
+
const ctx = this._modCtx(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
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)
|
|
111
149
|
this._sortHooks();
|
|
150
|
+
// a replaced module comes back, so a failed swap leaves the game as it was (it installs fresh: its old handles already went)
|
|
151
|
+
if (removed.length) try { this.use(...removed); } catch (e2) { reportError(this, e2, 'putting back the module a failed replaces removed', { soft: true }); }
|
|
112
152
|
throw err;
|
|
113
153
|
}
|
|
114
154
|
this._sortHooks();
|
|
@@ -117,8 +157,11 @@ export const moduleMethods = {
|
|
|
117
157
|
},
|
|
118
158
|
/** @internal validate a batch without touching the engine (so a failure leaves nothing half-installed);
|
|
119
159
|
* returns the modules to install */
|
|
120
|
-
_planUse(list) {
|
|
121
|
-
const names = new Set(this.modules.keys()), plan = [];
|
|
160
|
+
_planUse(list, gone = new Set()) {
|
|
161
|
+
const names = new Set([...this.modules.keys()].filter(n => !gone.has(n))), plan = [];
|
|
162
|
+
// requires names a module or a capability: another module's provides (depend on 'inventory', not on whichever module gives it)
|
|
163
|
+
const caps = new Set(names);
|
|
164
|
+
for (const n of names) for (const s of this.modules.get(n).provides ?? []) caps.add(s);
|
|
122
165
|
for (const m of list) {
|
|
123
166
|
if (!m) continue;
|
|
124
167
|
if (typeof m === 'function') throw codedError('module-called', fmt(STRINGS.called, { name: m.name }));
|
|
@@ -127,13 +170,20 @@ export const moduleMethods = {
|
|
|
127
170
|
if (m.order != null) throw codedError('module-stage', fmt(STRINGS.order, { name: m.name, list: Object.keys(STAGES).join(', ') }));
|
|
128
171
|
if (m.stage != null && !(m.stage in STAGES))
|
|
129
172
|
throw codedError('module-stage', fmt(STRINGS.stage, { name: m.name, stage: m.stage, list: Object.keys(STAGES).join(', ') }));
|
|
130
|
-
|
|
131
|
-
|
|
173
|
+
checkType(m);
|
|
174
|
+
for (const dep of m.requires || []) if (!caps.has(dep)) {
|
|
175
|
+
const hint = closest(dep, [...caps]);
|
|
176
|
+
throw codedError('module-requires', fmt(STRINGS.needs, { name: m.name, dep, typo: hint ? fmt(STRINGS.typo, { hint, list: [...caps].join(', ') }) : '' }));
|
|
177
|
+
}
|
|
178
|
+
checkProvides(m);
|
|
179
|
+
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))
|
|
180
|
+
throw codedError('module-provides', fmt(STRINGS.slotClash, { name: m.name, slot }));
|
|
132
181
|
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);
|
|
182
|
+
if (!gone.has(m.name) && m.name in this && this[m.name] !== undefined) throw codedError('module-name', fmt(STRINGS.clash, { name: m.name }));
|
|
183
|
+
names.add(m.name); caps.add(m.name); for (const s of m.provides ?? []) caps.add(s);
|
|
184
|
+
plan.push(m);
|
|
135
185
|
}
|
|
136
|
-
if (plan.length) { const all = [...this.modules.values(), ...plan]; checkStages(all); sortModules(all); }
|
|
186
|
+
if (plan.length) { const all = [...[...this.modules.values()].filter(m => !gone.has(m.name)), ...plan]; checkStages(all); sortModules(all); }
|
|
137
187
|
return plan;
|
|
138
188
|
},
|
|
139
189
|
/** @internal init of a module installed after start(): run now, tracked in engine.loading, errors through the error tiers;
|
|
@@ -142,9 +192,77 @@ export const moduleMethods = {
|
|
|
142
192
|
const L = this.loading, task = L._begin(m.name, 'module');
|
|
143
193
|
task.phase('build');
|
|
144
194
|
const snap = catalogSnap(this);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
195
|
+
// 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
|
|
196
|
+
const inst = this._modInst.get(m.name), ctx = this._modCtx(m, inst), live = () => this._isLive(m.name, inst);
|
|
197
|
+
L._track(Promise.resolve().then(() => asModule(this, m, () => m.init(this, ctx))).then(
|
|
198
|
+
() => { L._done(task); if (live()) { catalogClaim(this, m.name, snap); this._setModState(m, 'running'); } },
|
|
199
|
+
e => {
|
|
200
|
+
L._fail(task, e);
|
|
201
|
+
// unloaded meanwhile: its handles already went with it, and the state / handles under this name belong to the newcomer now
|
|
202
|
+
if (!live()) return reportError(this, e, fmt(STALE_INIT, { name: m.name }), { soft: true });
|
|
203
|
+
this._setModState(m, 'failed'); this._dropTracked(m.name); reportError(this, e, fmt(STRINGS.lateInit, { name: m.name }), { module: m });
|
|
204
|
+
}));
|
|
205
|
+
},
|
|
206
|
+
/** @internal is this install (token from engine._modInst) still the module installed under its name? */
|
|
207
|
+
_isLive(name, inst) { return !this.disposed && inst !== undefined && this._modInst.get(name) === inst; },
|
|
208
|
+
/** @internal the ctx install / init receive: track(handle) ties a handle to the module's life (see the top of this file) */
|
|
209
|
+
_modCtx(m, inst = this._modInst.get(m.name)) {
|
|
210
|
+
const name = m.name;
|
|
211
|
+
const track = h => {
|
|
212
|
+
if (typeof h?.remove !== 'function') throw codedError('module-handle', fmt(BAD_HANDLE, { name, got: String(h) }));
|
|
213
|
+
if (this.disposed) { h.remove(); return h; } // a late registration after dispose: nothing will ever remove it otherwise
|
|
214
|
+
// a registration from an install that is gone (replaced / unloaded while its async init awaited): filing it under the name would hand it
|
|
215
|
+
// to the newcomer, which would then own a listener it never made; remove it now instead
|
|
216
|
+
if (!this._isLive(name, inst)) { if (DEV) warnOnce(coded('module-handle', fmt(STALE, { name }))); h.remove(); return h; }
|
|
217
|
+
let set = this._modTracked.get(name);
|
|
218
|
+
if (!set) this._modTracked.set(name, set = new Set());
|
|
219
|
+
set.add(h);
|
|
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 look / 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,70 @@
|
|
|
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 { makeMaterial } from '../render/materials.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 owners = new WeakMap(); // engine → Set(owner): a hot swap walks every owner's prototypes of a changed name
|
|
44
|
+
/** Every prototype cache of this engine: [{ api, cache }] (cache: model key → Promise of the prototype). For core/assetHot.js @internal */
|
|
45
|
+
export const protoCaches = e => [...(owners.get(e) ?? [])].map(api => ({ api, cache: protos.get(api) }));
|
|
46
|
+
/**
|
|
47
|
+
* The shared prototype of a model name (or [name, ...params]): { obj, size, center, fromGeometry }. fromGeometry: the generator returned a bare
|
|
48
|
+
* geometry, wrapped here in a mesh of the 'prop' role; a caller with its own role (pickups: 'pickup' in the item's color) swaps that material. @internal
|
|
49
|
+
*/
|
|
50
|
+
export function protoOf(e, api, model) {
|
|
51
|
+
if (!protos.has(api)) protos.set(api, new Map());
|
|
52
|
+
(owners.get(e) ?? owners.set(e, new Set()).get(e)).add(api);
|
|
53
|
+
const cache = protos.get(api), key = JSON.stringify(model);
|
|
54
|
+
if (!cache.has(key)) {
|
|
55
|
+
const gen = cachedModel(e, model);
|
|
56
|
+
cache.set(key, (gen ? gen.then(r => {
|
|
57
|
+
const p = r.isObject3D ? r : new THREE.Mesh(r, makeMaterial('prop', { vertexColors: !!r.attributes.color }, e));
|
|
58
|
+
if (!r.isObject3D) p.userData.fromGeometry = true;
|
|
59
|
+
// the generator's own castShadow / receiveShadow are kept (a decal or flat rug that must not cast); the manifest entry can set them;
|
|
60
|
+
// a generator that set none gets cast + receive. Same rule as assets.model (core/assetEntry.js shadowDefaults)
|
|
61
|
+
return shadowDefaults(p, e.assets.entries.get(list(model)[0])?.opts);
|
|
62
|
+
}) : e.assets.model(list(model)[0])).then(obj => {
|
|
63
|
+
const box = new THREE.Box3().setFromObject(obj); // collision and the "build within what distance" check both use the prototype's bounding box, computed once
|
|
64
|
+
obj.userData.modelKey = key; // copies carry it (clone copies userData): a hot swap whose new model has other parts finds them by it
|
|
65
|
+
return { obj, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()), fromGeometry: !!obj.userData.fromGeometry };
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return cache.get(key);
|
|
69
|
+
}
|
|
70
|
+
|
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
|
}
|