threedog 1.1.0 → 1.3.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 +893 -798
- package/README.md +1 -1
- package/core/assets/Animator.js +41 -3
- package/core/assets/Assets.js +100 -24
- package/core/assets/assetEntry.js +73 -20
- package/core/assets/assetHot.js +68 -16
- package/core/assets/assetLoad.js +6 -6
- package/core/assets/assetLod.js +9 -2
- package/core/assets/assetManifest.js +12 -2
- package/core/assets/assetPart.js +54 -0
- package/core/assets/ik.js +271 -0
- package/core/assets/modelNeeds.js +37 -0
- package/core/assets/namedModel.js +102 -29
- package/core/assets/nodeVisibility.js +15 -0
- package/core/audio/Audio.js +36 -4
- package/core/audio/audioReverb.js +99 -0
- package/core/audio/audioRules.js +1 -1
- package/core/audio/audioVoice.js +1 -1
- package/core/base/Events.js +14 -4
- package/core/base/Random.js +1 -1
- package/core/base/Vars.js +1 -1
- package/core/base/docRef.js +51 -0
- package/core/base/errorCodes.js +187 -126
- package/core/base/errorHints.js +9 -7
- package/core/base/errors.js +25 -10
- package/core/base/events.generated.js +2 -0
- package/core/base/freeParts.js +76 -0
- package/core/base/math.js +28 -0
- package/core/base/sections.js +5 -5
- package/core/base/validate.js +31 -3
- package/core/engine/Engine.js +17 -7
- package/core/engine/Loading.js +5 -3
- package/core/engine/copies.js +1 -1
- package/core/engine/headlessLoad.js +4 -1
- package/core/engine/lifecycle.js +32 -16
- package/core/engine/loop.js +71 -27
- package/core/engine/moduleSlots.js +2 -2
- package/core/engine/moduleTypes.js +3 -3
- package/core/engine/modules.js +65 -39
- package/core/engine/page.js +6 -3
- package/core/engine/services.js +6 -5
- package/core/engine/startup.js +8 -7
- package/core/input/Input.js +28 -14
- package/core/input/inputContext.js +28 -16
- package/core/input/inputKeyboard.js +31 -3
- package/core/input/inputPad.js +4 -0
- package/core/input/inputPointer.js +2 -1
- package/core/input/inputSeat.js +1 -1
- package/core/inspect/Budget.js +109 -19
- package/core/inspect/DebugOverrides.js +28 -4
- package/core/inspect/Describe.js +17 -9
- package/core/inspect/Inspect.js +4 -2
- package/core/inspect/InspectMaterials.js +3 -1
- package/core/inspect/InspectPerf.js +19 -9
- package/core/inspect/InspectScene.js +32 -7
- package/core/inspect/MaterialInfo.js +19 -2
- package/core/inspect/UrlState.js +50 -28
- package/core/inspect/catalog.js +28 -9
- package/core/inspect/debugView.js +2 -1
- package/core/inspect/describeRender.js +25 -13
- package/core/inspect/describeText.js +14 -6
- package/core/inspect/lightWatch.js +1 -1
- package/core/inspect/metadata.generated.js +35 -17
- package/core/inspect/pictureChecks.js +148 -0
- package/core/inspect/pictureMenu.js +84 -0
- package/core/inspect/pictureWriters.js +26 -6
- package/core/inspect/textureBytes.js +12 -2
- package/core/inspect/toolDoor.js +2 -4
- package/core/ops/Ops.js +11 -4
- package/core/ops/holds.js +27 -10
- package/core/ops/opsAtomic.js +15 -7
- package/core/ops/opsGuard.js +2 -2
- package/core/ops/opsRun.js +8 -7
- package/core/ops/sharedPoint.js +72 -21
- package/core/ops/stacks.js +56 -16
- package/core/saves/SaveStore.js +9 -3
- package/core/saves/Saves.js +32 -23
- package/core/saves/saveApply.js +96 -44
- package/core/saves/saveIds.js +1 -1
- package/core/saves/saveVersions.js +7 -5
- package/core/saves/session.js +17 -8
- package/core/saves/stateReplace.js +34 -15
- package/core/scene/Rays.js +52 -10
- package/core/scene/Views.js +36 -15
- package/core/scene/adaptive.js +144 -21
- package/core/scene/drawOnly.js +17 -0
- package/core/scene/gameLights.js +47 -4
- package/core/scene/sceneMethods.js +13 -11
- package/core/scene/stepPoses.js +11 -3
- package/core/scene/targeting.js +5 -3
- package/core/scene/thingOps.js +1 -1
- package/core/scene/tier.js +15 -0
- package/core/stream/Batching.js +30 -7
- package/core/stream/Stream.js +26 -7
- package/core/stream/batchGroups.js +2 -2
- package/core/stream/chunkStream.js +7 -5
- package/core/stream/prepare.js +77 -0
- package/core/time/skip.js +3 -1
- package/core/time/time.js +4 -2
- package/docs/AI.md +82 -83
- package/docs/API.md +16 -16
- package/docs/CODEMAP.md +17 -11
- package/docs/COMMANDS.md +139 -142
- package/docs/CONVENTIONS.md +37 -49
- package/docs/MIGRATING-0.8.md +2 -2
- package/docs/MIGRATING-1.0.md +2 -2
- package/docs/THREE.md +30 -35
- package/docs/api/assets.md +3 -1
- package/docs/api/audio.md +4 -2
- package/docs/api/budget.md +5 -0
- package/docs/api/characters.md +10 -8
- package/docs/api/collision.md +6 -4
- package/docs/api/engine.md +16 -16
- package/docs/api/events.md +3 -2
- package/docs/api/ground.md +6 -5
- package/docs/api/hud.md +4 -2
- package/docs/api/input.md +5 -5
- package/docs/api/particles.md +2 -1
- package/docs/api/photo.md +3 -0
- package/docs/api/post.md +7 -4
- package/docs/api/quests.md +2 -2
- package/docs/api/rays.md +1 -2
- package/docs/api/saves.md +7 -7
- package/docs/api/settings.md +2 -2
- package/docs/api/tools.md +3 -1
- package/docs/api/vars.md +1 -1
- package/docs/api/vegetation.md +4 -2
- package/docs/api/world.md +1 -1
- package/docs/recipes/01-new-game.md +16 -17
- package/docs/recipes/02-npc.md +22 -18
- package/docs/recipes/03-items-pickups.md +37 -35
- package/docs/recipes/04-quests.md +15 -10
- package/docs/recipes/05-props-bake.md +101 -95
- package/docs/recipes/06-clock-events.md +28 -28
- package/docs/recipes/07-flow-scenes-pause.md +29 -26
- package/docs/recipes/08-weather-sky.md +52 -64
- package/docs/recipes/09-materials-lights-models.md +26 -17
- package/docs/recipes/10-blender-level.md +15 -10
- package/docs/recipes/11-vehicles.md +12 -7
- package/docs/recipes/12-navmesh.md +44 -26
- package/docs/recipes/13-animation.md +56 -45
- package/docs/recipes/14-custom-module.md +21 -18
- package/docs/recipes/15-perf.md +61 -55
- package/docs/recipes/16-dev-bridge.md +24 -33
- package/docs/recipes/18-world.md +36 -42
- package/docs/recipes/19-shooting-picking.md +20 -15
- package/docs/recipes/20-content-actions-save.md +48 -56
- package/docs/recipes/21-camera.md +45 -54
- package/docs/recipes/22-shop-gold.md +12 -7
- package/docs/recipes/23-ops.md +25 -23
- package/docs/recipes/26-ui-parts.md +67 -47
- package/docs/recipes/27-net.md +12 -7
- package/docs/recipes/28-terrain.md +24 -21
- package/docs/recipes/29-grid.md +32 -27
- package/docs/recipes/30-templates.md +21 -20
- package/docs/recipes/31-audio.md +39 -22
- package/docs/recipes/32-action-game.md +19 -14
- package/docs/recipes/33-stream-sources.md +15 -11
- package/docs/recipes/34-environment-lighting.md +126 -70
- package/docs/recipes/35-picture-from-reference.md +8 -8
- package/docs/recipes/36-ground-plants.md +27 -21
- package/docs/recipes/40-scene.md +19 -28
- package/docs/recipes/43-shader-patches-surfaces.md +15 -12
- package/docs/recipes/44-water-weather-hooks.md +34 -31
- package/docs/recipes/45-cascaded-shadows.md +35 -26
- package/docs/recipes/46-blender-art-route.md +7 -2
- package/docs/recipes/49-game-module-contract.md +13 -8
- package/docs/recipes/50-own-renderer.md +6 -2
- package/docs/recipes/51-capability-catalog.md +15 -8
- package/docs/recipes/52-around-the-picture.md +34 -32
- package/docs/recipes/53-ground-up-close.md +6 -1
- package/docs/recipes/55-mods-time-wrap.md +27 -19
- package/docs/recipes/56-webgpu-tsl.md +75 -43
- package/docs/recipes/57-control.md +18 -13
- package/docs/recipes/58-input.md +26 -16
- package/docs/recipes/59-depth-post-effects.md +8 -3
- package/docs/recipes/60-judge-the-picture.md +10 -9
- package/docs/recipes/61-deploy.md +5 -0
- package/docs/recipes/62-picture-code.md +72 -79
- package/docs/recipes/63-third-person-start.md +48 -45
- package/docs/recipes/64-particles.md +22 -10
- package/docs/recipes/65-swarm.md +18 -13
- package/docs/recipes/66-common-tasks.md +38 -35
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/action/GAMEMAP.md +2 -3
- package/examples/action/main.js +3 -3
- package/examples/action/picture/lights.js +3 -1
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/perf-island/GAMEMAP.md +3 -3
- package/examples/perf-island/picture/lights.js +2 -1
- package/examples/plain-picture/GAMEMAP.md +1 -1
- package/examples/rc2d/GAMEMAP.md +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/styletest/GAMEMAP.md +2 -2
- package/examples/styletest/main.js +1 -1
- package/examples/techniques/interior-light/README.md +3 -3
- package/examples/techniques/interior-light/interiorLight.js +2 -4
- package/examples/techniques/interior-light/picture/lights.js +2 -1
- package/examples/techniques/modular-building/picture/lights.js +3 -1
- package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
- package/examples/techniques/procedural-animation/README.md +1 -1
- package/examples/techniques/procedural-animation/main.js +1 -1
- package/examples/webgpu-tsl/GAMEMAP.md +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/examples/world/GAMEMAP.md +2 -3
- package/examples/world/art/humanoid.js +1 -1
- package/examples/world/main.js +6 -3
- package/index.d.ts +2 -2
- package/llms.txt +101 -0
- package/modules/ambience/Ambience.js +21 -5
- package/modules/calendar/index.js +9 -5
- package/modules/calendar/schedule.js +23 -8
- package/modules/camera/FirstPersonCamera.js +3 -1
- package/modules/camera/FollowCamera.js +10 -5
- package/modules/camera/RtsCamera.js +4 -3
- package/modules/camera/common.js +70 -8
- package/modules/camera/contract.js +1 -1
- package/modules/characters/Character.js +16 -10
- package/modules/characters/NPC.js +31 -19
- package/modules/characters/assetModel.js +14 -9
- package/modules/characters/astar.js +6 -1
- package/modules/characters/contract.js +2 -2
- package/modules/characters/index.js +34 -22
- package/modules/characters/movers/manual.js +1 -1
- package/modules/characters/movers/rapier.js +17 -2
- package/modules/characters/movers/simple.js +1 -1
- package/modules/characters/movers/support.js +16 -7
- package/modules/characters/npcAvoid.js +2 -2
- package/modules/characters/npcSim.js +3 -2
- package/modules/characters/pathAsync.js +24 -8
- package/modules/characters/pathJob.js +1 -1
- package/modules/characters/player.js +10 -9
- package/modules/characters/playerStrings.js +5 -5
- package/modules/characters/proceduralRig.js +5 -5
- package/modules/characters/useModel.js +6 -0
- package/modules/characters/walkTo.js +1 -1
- package/modules/collision/Collision.js +29 -18
- package/modules/collision/grid.js +22 -4
- package/modules/content/index.js +3 -1
- package/modules/content/loader.js +1 -1
- package/modules/content/models.js +82 -33
- package/modules/content/props.js +2 -1
- package/modules/content/rules.js +11 -5
- package/modules/content/templates.js +3 -3
- package/modules/content/words.js +2 -2
- package/modules/debug/DebugPanel.js +9 -9
- package/modules/flow/index.js +9 -6
- package/modules/gameplay/Dialogue.js +34 -20
- package/modules/gameplay/Interactions.js +19 -15
- package/modules/gameplay/Inventory.js +9 -4
- package/modules/gameplay/Quests.js +12 -10
- package/modules/gameplay/pickups.js +23 -11
- package/modules/grid/index.js +1 -1
- package/modules/grid/preview.js +2 -2
- package/modules/grid/tiles.js +1 -1
- package/modules/hlod/index.js +4 -1
- package/modules/hud/index.js +47 -10
- package/modules/hud/parts.js +28 -9
- package/modules/level/geometry.js +8 -3
- package/modules/level/index.js +10 -5
- package/modules/level/load.js +4 -2
- package/modules/lights/sources.js +1 -1
- package/modules/music/Music.js +22 -4
- package/modules/nav/index.js +20 -10
- package/modules/particles/Particles.js +31 -14
- package/modules/particles/effect.js +20 -5
- package/modules/particles/lit.js +72 -0
- package/modules/photo/Photo.js +72 -28
- package/modules/photo/pathTrace.js +106 -0
- package/modules/rigid/RigidBodies.js +23 -14
- package/modules/rigid/Vehicles.js +3 -13
- package/modules/rigid/sync.js +2 -1
- package/modules/settings/Settings.js +52 -20
- package/modules/settings/apply.js +23 -9
- package/modules/settings/sections.js +39 -6
- package/modules/settings/strings.js +2 -0
- package/modules/settings/view.js +19 -3
- package/modules/sky/dome.js +15 -3
- package/modules/sky/environment.js +28 -12
- package/modules/sky/fog.js +1 -1
- package/modules/sky/frame.js +6 -1
- package/modules/sky/shader.js +4 -3
- package/modules/sky/skyModule.js +8 -4
- package/modules/swarm/Swarm.js +1 -1
- package/modules/terrain/ChunkManager.js +61 -15
- package/modules/terrain/chunkJob.js +2 -2
- package/modules/terrain/index.js +20 -5
- package/modules/terrain/terrainEdit.js +8 -4
- package/modules/terrain/terrainTexture.js +4 -2
- package/modules/timeline/Timeline.js +4 -3
- package/modules/timeline/Tween.js +3 -0
- package/modules/timeline/letterbox.js +1 -0
- package/modules/triggers/index.js +36 -17
- package/modules/vegetation/Vegetation.js +81 -19
- package/modules/vegetation/densityMap.js +13 -8
- package/modules/vegetation/draw.js +147 -24
- package/modules/vegetation/groundChunks.js +20 -5
- package/modules/vegetation/index.js +3 -3
- package/modules/vegetation/modelGeometry.js +9 -4
- package/modules/water/Water.js +11 -8
- package/modules/weather/Weather.js +7 -2
- package/modules/weather/shaders.js +25 -5
- package/modules/weather/weatherDraw.js +20 -6
- package/modules/world/World.js +2 -1
- package/modules/world/index.js +2 -2
- package/modules/world/persist.js +6 -2
- package/modules/world/views.js +15 -2
- package/package.json +5 -1
- package/presets.js +5 -5
- package/render/PostFX.js +102 -42
- package/render/backend.js +142 -16
- package/render/bindingLimits.js +59 -0
- package/render/cascades.js +3 -1
- package/render/cascades.tsl.js +2 -0
- package/render/daylight.js +7 -1
- package/render/detail.js +7 -4
- package/render/effects.js +27 -8
- package/render/fogLook.js +24 -0
- package/render/fuse.js +5 -2
- package/render/fx/compareLevel.tsl.js +23 -0
- package/render/fx/detail.tsl.js +9 -7
- package/render/fx/index.js +9 -2
- package/render/fx/library.tsl.js +1 -0
- package/render/fx/lightShaft.tsl.js +114 -0
- package/render/fx/noise.tsl.js +25 -8
- package/render/fx/objectOrigin.tsl.js +39 -10
- package/render/fx/particles.tsl.js +23 -6
- package/render/fx/patchNodes.tsl.js +17 -12
- package/render/fx/pcss.tsl.js +51 -0
- package/render/fx/postWebGPU.tsl.js +104 -29
- package/render/fx/sky.tsl.js +3 -9
- package/render/fxNumbers.js +10 -4
- package/render/impostor.tsl.js +107 -0
- package/render/lighting.js +33 -1
- package/render/lightmap.js +42 -28
- package/render/lights.js +19 -3
- package/render/materials.js +6 -4
- package/render/mergeCommon.js +4 -1
- package/render/occlusion.js +14 -4
- package/render/patches.js +79 -41
- package/render/postRuns.js +32 -0
- package/render/postWebGL.js +97 -10
- package/render/probes.js +10 -14
- package/render/shaderErrors.js +44 -7
- package/render/shadowCache.tsl.js +33 -5
- package/render/shadows.js +42 -16
- package/render/slots.js +8 -5
- package/render/vertexInputs.js +52 -0
- package/types/core.d.ts +115 -47
- package/types/gameplay.d.ts +56 -23
- package/types/generated/core/audio/Audio.d.ts +27 -1
- package/types/generated/core/base/Random.d.ts +1 -1
- package/types/generated/core/input/Input.d.ts +6 -8
- package/types/generated/core/input/inputSeat.d.ts +1 -1
- package/types/generated/core/inspect/Budget.d.ts +26 -0
- package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
- package/types/generated/core/saves/Saves.d.ts +10 -7
- package/types/generated/core/saves/session.d.ts +8 -2
- package/types/generated/core/scene/Rays.d.ts +1 -3
- package/types/generated/core/scene/Views.d.ts +17 -3
- package/types/generated/modules/particles/Particles.d.ts +1 -1
- package/types/generated/modules/world/World.d.ts +2 -1
- package/types/generated/render/PostFX.d.ts +35 -9
- package/types/physics.d.ts +796 -764
- package/types/pixel.d.ts +1 -1
- package/types/tsl.d.ts +62 -1
- package/types/world.d.ts +12 -3
- package/ui/Focus.js +7 -5
- package/ui/Parts.js +1 -1
- package/ui/touchPart.js +6 -3
|
@@ -9,7 +9,7 @@ import { xzOf, yOf } from '../../core/base/math.js';
|
|
|
9
9
|
import { surfaceOr } from '../../core/scene/ground.js';
|
|
10
10
|
|
|
11
11
|
import { readParams, keysSchema } from '../../core/base/params.js';
|
|
12
|
-
import { CollisionGrid, gridBlocks, bodyHits } from './grid.js';
|
|
12
|
+
import { CollisionGrid, gridBlocks, bodyHits, passesThrough, passesOf } from './grid.js';
|
|
13
13
|
import { codedError } from '../../core/base/errorHints.js';
|
|
14
14
|
|
|
15
15
|
/** One axis of the slab test: narrows S.t0 / S.t1 to where the ray is inside |o + d t| <= h; false when it misses */
|
|
@@ -20,7 +20,13 @@ function slab(S, o, d, h) {
|
|
|
20
20
|
return S.t0 <= S.t1;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y', 'occluder'], CIRCLE_KEYS = ['radius', 'height', 'occluder'], SEG_KEYS = ['thickness', 'height', 'y', 'occluder'], BLOCK_KEYS = ['bounds'];
|
|
23
|
+
const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y', 'occluder', 'layer'], CIRCLE_KEYS = ['radius', 'height', 'occluder', 'layer'], SEG_KEYS = ['thickness', 'height', 'y', 'occluder', 'layer'], BLOCK_KEYS = ['bounds'];
|
|
24
|
+
|
|
25
|
+
/** A collider's layer option: one name, or undefined for "stops every mover" (what every collider did before layers) */
|
|
26
|
+
function layerOf(where, v) {
|
|
27
|
+
if (v === undefined || (typeof v === 'string' && v)) return v;
|
|
28
|
+
throw codedError('collision-misuse', `${where}: layer is one name, e.g. { layer: 'gate' } (movers with passes: ['gate'] go through it, every other mover is stopped); got ${JSON.stringify(v)}`, TypeError);
|
|
29
|
+
}
|
|
24
30
|
|
|
25
31
|
export class Collision {
|
|
26
32
|
/**
|
|
@@ -80,34 +86,36 @@ export class Collision {
|
|
|
80
86
|
|
|
81
87
|
/**
|
|
82
88
|
* Add a circle collider (pillar, statue, campfire): position is the centre, radius (default 0.5), height (default 6). It stands on the ground and stops walkers on every floor; a pillar upstairs is an addBox with a y.
|
|
83
|
-
* occluder: false keeps it from pulling the follow camera in (walkers are still stopped), e.g. forest trunks the camera may pass through.
|
|
89
|
+
* occluder: false keeps it from pulling the follow camera in (walkers are still stopped), e.g. forest trunks the camera may pass through.
|
|
90
|
+
* layer: a name; movers whose passes list names it go through (walking, paths, navmesh), every other mover is stopped. Left out: it stops every mover. Sight lines and the camera ignore it. Returns a handle { remove() }
|
|
91
|
+
* @example engine.collision.addBox(gate, { halfWidth: 2, halfDepth: 0.3, layer: 'gate' }); // a character made with passes: ['gate'] walks through, the rest are stopped
|
|
84
92
|
*/
|
|
85
93
|
addCircle(position, opts = {}) {
|
|
86
94
|
opts = readParams('collision.addCircle()', keysSchema(CIRCLE_KEYS), opts);
|
|
87
|
-
const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6, occ: opts.occluder !== false };
|
|
95
|
+
const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6, occ: opts.occluder !== false, ly: layerOf('collision.addCircle()', opts.layer) };
|
|
88
96
|
this._circles.add(c); this._grid.add(c, false); this.version++;
|
|
89
97
|
return { remove: () => { if (!this._circles.delete(c)) return; this._grid.remove(c); this.version++; } };
|
|
90
98
|
}
|
|
91
99
|
/**
|
|
92
100
|
* Add a rectangle collider (house, fence): position is the centre; halfWidth / halfDepth (default 1), rotation about the Y axis (radians),
|
|
93
|
-
* height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels); occluder
|
|
101
|
+
* height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels); occluder and layer as in addCircle. Returns a handle { remove() }
|
|
94
102
|
*/
|
|
95
103
|
addBox(position, opts = {}) {
|
|
96
104
|
opts = readParams('collision.addBox()', keysSchema(BOX_KEYS), opts);
|
|
97
105
|
const [x, z] = xzOf(position), hw = opts.halfWidth ?? 1, hd = opts.halfDepth ?? 1, rot = opts.rotation ?? 0;
|
|
98
|
-
const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd), occ: opts.occluder !== false };
|
|
106
|
+
const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd), occ: opts.occluder !== false, ly: layerOf('collision.addBox()', opts.layer) };
|
|
99
107
|
this._boxes.add(b); this._grid.add(b, true); this.version++;
|
|
100
108
|
return { remove: () => { if (!this._boxes.delete(b)) return; this._grid.remove(b); this.version++; } };
|
|
101
109
|
}
|
|
102
110
|
/**
|
|
103
|
-
* Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y and
|
|
111
|
+
* Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y, occluder and layer as in addBox.
|
|
104
112
|
* It is a rotated box in the same grid, so a gap between two segments is a gate. Returns a handle { remove() }
|
|
105
113
|
*/
|
|
106
114
|
addSegment(a, b, opts = {}) {
|
|
107
115
|
opts = readParams('collision.addSegment()', keysSchema(SEG_KEYS), opts);
|
|
108
116
|
const [ax, az] = xzOf(a), [bx, bz] = xzOf(b);
|
|
109
117
|
// box-local +x is (cos r, -sin r) in world, so r = -atan2(dz, dx)
|
|
110
|
-
return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y, occluder: opts.occluder });
|
|
118
|
+
return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y, occluder: opts.occluder, layer: opts.layer });
|
|
111
119
|
}
|
|
112
120
|
/**
|
|
113
121
|
* Mark ground as impassable where fn(x, z) is true (river, lava, cliff edge). Walkers are stopped at its edge (sliding along it) and walkable() says no.
|
|
@@ -130,12 +138,12 @@ export class Collision {
|
|
|
130
138
|
}
|
|
131
139
|
return false;
|
|
132
140
|
}
|
|
133
|
-
/** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m), occluder as in addBox. Returns a handle { remove() } */
|
|
134
|
-
addObject(obj, { pad = 0, occluder = true } = {}) {
|
|
141
|
+
/** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m), occluder and layer as in addBox. Returns a handle { remove() } */
|
|
142
|
+
addObject(obj, { pad = 0, occluder = true, layer } = {}) {
|
|
135
143
|
obj.updateMatrixWorld(true);
|
|
136
144
|
// a THREE.LOD is measured by its full model: a low level may stick out a little, and collision must not change with which levels exist
|
|
137
145
|
const box = new Box3().setFromObject(obj.isLOD ? obj.levels[0].object : obj), c = box.getCenter(new Vector3()), s = box.getSize(new Vector3());
|
|
138
|
-
return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y, y: box.min.y, occluder });
|
|
146
|
+
return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y, y: box.min.y, occluder, layer });
|
|
139
147
|
}
|
|
140
148
|
|
|
141
149
|
// The per-frame walkers below pass state through fields instead of building callbacks: resolve() and cameraDistance() run every step / frame.
|
|
@@ -165,9 +173,10 @@ export class Collision {
|
|
|
165
173
|
/**
|
|
166
174
|
* @internal Push a character of radius `radius` out of obstacles; edits pos.x / pos.z directly. Returns whether a collision happened.
|
|
167
175
|
* A box with an explicit `y` occupies y .. y + height, and stops only a body (pos.y .. + movement.height) that overlaps that span: a wall upstairs leaves the floor below free.
|
|
168
|
-
* A box without `y` is a footprint, as is every box when pos has no y: those stop at any height. walkableAt and A* read boxes the same way (bodyHits)
|
|
176
|
+
* A box without `y` is a footprint, as is every box when pos has no y: those stop at any height. walkableAt and A* read boxes the same way (bodyHits).
|
|
177
|
+
* passes: the mover's layer list (passesOf); a collider whose layer it names does not push it
|
|
169
178
|
*/
|
|
170
|
-
resolve(pos, radius = this.engine.movement.radius) {
|
|
179
|
+
resolve(pos, radius = this.engine.movement.radius, passes) {
|
|
171
180
|
const sPos = this._rPos, sRad = this._rRad;
|
|
172
181
|
this._rPos = pos; this._rRad = radius; this._rHit = false;
|
|
173
182
|
const g = this.engine.ground, y = pos.y, body = this.engine.movement.height;
|
|
@@ -176,6 +185,7 @@ export class Collision {
|
|
|
176
185
|
const list = this._grid.query(pos.x, pos.z, radius + 2);
|
|
177
186
|
for (let i = 0; i < list.length; i++) {
|
|
178
187
|
const it = list[i];
|
|
188
|
+
if (passesThrough(it, passes)) continue;
|
|
179
189
|
if (!it._b) this._pushCircle(pos, it.x, it.z, it.r, radius);
|
|
180
190
|
else if (bodyHits(it, y, body)) this._pushBox(pos, it, radius);
|
|
181
191
|
}
|
|
@@ -186,8 +196,8 @@ export class Collision {
|
|
|
186
196
|
return hit;
|
|
187
197
|
}
|
|
188
198
|
|
|
189
|
-
/** Can anyone stand here (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (m, default engine.movement.radius). A position with y asks about the floor that height picks */
|
|
190
|
-
walkable(position, { radius = this.engine.movement.radius } = {}) { const [x, z] = xzOf(position); return this.walkableAt(x, z, radius, yOf(position)); }
|
|
199
|
+
/** Can anyone stand here (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (m, default engine.movement.radius), passes its layer list (addBox { layer }). A position with y asks about the floor that height picks */
|
|
200
|
+
walkable(position, { radius = this.engine.movement.radius, passes } = {}) { const [x, z] = xzOf(position); return this.walkableAt(x, z, radius, yOf(position), passesOf('collision.walkable()', passes)); }
|
|
191
201
|
/**
|
|
192
202
|
* Line of sight with height: is the 3D segment a -> b free of colliders (boxes, circles, terrain trees)? Positions like addBox ([x, y, z] / Vector3 / Object3D).
|
|
193
203
|
* Heights count: a 1 m wall does not block a sight line passing 3 m above it; a collider's `y` and `height` are honoured (no `y` = sits on the ground).
|
|
@@ -252,11 +262,12 @@ export class Collision {
|
|
|
252
262
|
get grid() { return this._grid; }
|
|
253
263
|
/**
|
|
254
264
|
* Same as walkable but takes plain numbers (inner loop of A* pathfinding and spawn search, allocates nothing; like engine.surface(x, z)). radius defaults to engine.movement.radius.
|
|
255
|
-
* y picks the floor as in surface(), and only the floor it picks counts, so [x, 0, z] on raised ground asks about that ground. Left out: the top ground, and every box blocks at any height
|
|
265
|
+
* y picks the floor as in surface(), and only the floor it picks counts, so [x, 0, z] on raised ground asks about that ground. Left out: the top ground, and every box blocks at any height.
|
|
266
|
+
* passes: the mover's layer list as passesOf returns it (the inner loop of A* does not read it again)
|
|
256
267
|
*/
|
|
257
|
-
walkableAt(x, z, radius = this.engine.movement.radius, y) {
|
|
268
|
+
walkableAt(x, z, radius = this.engine.movement.radius, y, passes) {
|
|
258
269
|
const f = y === undefined ? y : surfaceOr(this.engine, x, z, y, y);
|
|
259
|
-
return this.groundWalkable(x, z, f) && !this.blockedAt(x, z, radius) && !this._groundBlocks(x, z, radius) && !gridBlocks(this._grid, x, z, radius, f, this.engine.movement.height);
|
|
270
|
+
return this.groundWalkable(x, z, f) && !this.blockedAt(x, z, radius) && !this._groundBlocks(x, z, radius) && !gridBlocks(this._grid, x, z, radius, f, this.engine.movement.height, passes);
|
|
260
271
|
}
|
|
261
272
|
/** @internal Ground shape half of walkableAt (water, slope): a smooth field, so async pathfinding samples it on a raster; colliders are tested exactly there */
|
|
262
273
|
groundWalkable(x, z, y) {
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
// Grid index of colliders: register each by bounding circle in the cells it covers; queries look at a few nearby cells instead of scanning all colliders.
|
|
2
2
|
// Results are ordered circles first, then boxes, each in insertion order, exactly the callback order of a linear scan (resolve edits the position in turn, so a different order changes the result).
|
|
3
|
-
// Worker-safe (no
|
|
3
|
+
// Worker-safe (no three.js, no engine objects): the path worker (characters/pathJob.js) rebuilds the same grid from the colliders it mirrors.
|
|
4
|
+
// Collider layers live here too (passesOf, passesThrough): every reader of colliders, the worker and nav included, asks the same two functions.
|
|
5
|
+
import { codedError } from '../../core/base/errorHints.js';
|
|
4
6
|
const CELL = 8, MAX_CELLS = 64, KEY = 1048576; // colliders too large (covering > 64 cells) skip the grid and are scanned linearly, so registration cost does not blow up
|
|
5
7
|
/** Does a body with its feet at y reach this box? A box without a y of its own is a footprint, and a body without y is anywhere: both hit. Written so an undefined on either side falls through to true */
|
|
6
8
|
export const bodyHits = (it, y, body) => !(y >= it.y + it.h || y + body <= it.y);
|
|
9
|
+
/**
|
|
10
|
+
* A mover's passes option (character option; findPath, findPathAsync and walkable option): the collider layers it goes through. Read here for every entry,
|
|
11
|
+
* sorted and without repeats so one set is one navmesh, never two. Left out or empty: undefined, which every reader takes as "stopped by everything", as before
|
|
12
|
+
*/
|
|
13
|
+
export function passesOf(where, v) {
|
|
14
|
+
if (v === undefined || v === null) return undefined;
|
|
15
|
+
if (!Array.isArray(v) || !v.every(n => typeof n === 'string' && n)) throw codedError('collision-misuse', `${where}: passes is a list of collider layer names, e.g. passes: ['gate']; got ${JSON.stringify(v)}`, TypeError);
|
|
16
|
+
return v.length ? Object.freeze([...new Set(v)].sort()) : undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Does a mover go through this collider: it has a layer (addBox / addCircle { layer }) and the mover's passes list names it. The one test every reader
|
|
20
|
+
* of colliders makes (resolve, walkableAt, A* here and in the worker, the navmesh cut per passes list, the rapier mover), so they cannot disagree.
|
|
21
|
+
* A collider without a layer, or a mover without passes, answers false on the first comparison: what existed before costs one undefined check.
|
|
22
|
+
*/
|
|
23
|
+
export const passesThrough = (it, passes) => it.ly !== undefined && passes !== undefined && passes.includes(it.ly);
|
|
7
24
|
|
|
8
25
|
const byOrder = (a, b) => a._b - b._b || a._o - b._o;
|
|
9
26
|
|
|
@@ -56,11 +73,12 @@ export class CollisionGrid {
|
|
|
56
73
|
|
|
57
74
|
/**
|
|
58
75
|
* Does a collider in the grid block a character of `radius` standing at (x, z)? The obstacle half of Collision.walkableAt,
|
|
59
|
-
* shared with the pathfinding worker (it rebuilds a grid from the same colliders), so both answer identically. Worker-safe
|
|
60
|
-
* y, body: the feet and height of the character; a box on another floor does not block it. Left out, every box blocks.
|
|
76
|
+
* shared with the pathfinding worker (it rebuilds a grid from the same colliders), so both answer identically. Worker-safe.
|
|
77
|
+
* y, body: the feet and height of the character; a box on another floor does not block it. Left out, every box blocks. passes: the mover's layer list (passesThrough).
|
|
61
78
|
*/
|
|
62
|
-
export function gridBlocks(grid, x, z, radius, y, body) {
|
|
79
|
+
export function gridBlocks(grid, x, z, radius, y, body, passes) {
|
|
63
80
|
for (const it of grid.query(x, z, radius + 1)) {
|
|
81
|
+
if (passesThrough(it, passes)) continue;
|
|
64
82
|
if (!it._b) { if (Math.hypot(x - it.x, z - it.z) < radius + it.r) return true; continue; }
|
|
65
83
|
if (!bodyHits(it, y, body)) continue;
|
|
66
84
|
const dx = x - it.x, dz = z - it.z, lx = dx * it.c - dz * it.s, lz = dx * it.s + dz * it.c;
|
package/modules/content/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { sectionsOf } from '../../core/base/sections.js';
|
|
|
27
27
|
import { addProps, needWorld } from './props.js';
|
|
28
28
|
import { templateOf, spawnTemplate, placeTemplate, defineTemplates } from './templates.js';
|
|
29
29
|
import { refit } from './models.js';
|
|
30
|
+
import { holdProtos } from '../../core/assets/namedModel.js';
|
|
30
31
|
import { packsOf } from './packs.js';
|
|
31
32
|
import { IdCheck } from './ids.js';
|
|
32
33
|
import { fieldsOf } from './fields.js';
|
|
@@ -221,8 +222,9 @@ export function content() {
|
|
|
221
222
|
install(engine, ctx) { engine.i18n.add({ 'zh-CN': { 'module.content': '内容' }, en: { 'module.content': 'content' } });
|
|
222
223
|
const e = st.e = engine;
|
|
223
224
|
st.track = ctx.track; // templates.js subscribes on content.load: those listeners belong to the module too
|
|
225
|
+
ctx.track(holdProtos(e, api)); // the model prototypes its props and templates clone (namedModel.js): unloading content gives them back
|
|
224
226
|
ctx.things.explainWith(contentExplain);
|
|
225
|
-
ctx.saves.
|
|
227
|
+
ctx.saves.define('content', { ...marksPart(api, st), atomic: true });
|
|
226
228
|
for (const holder of ['collision', 'collider3d']) ctx.feeds(holder, () => refit(e));
|
|
227
229
|
ctx.track(e.events.on('engine:ready', () => { checkOps(e, st); checkRefs(st); }));
|
|
228
230
|
ctx.track(e.events.on('module:restored', ({ modules }) => api._replay(modules)));
|
|
@@ -116,7 +116,7 @@ function loadSteps(e, api, c, st) {
|
|
|
116
116
|
// game kinds stay registered across loads, so a later content.load({ recipes }) without rules still finds them
|
|
117
117
|
if (c.rules) steps.push({ commit() { each(c.rules.conditions, (name, d) => api.condition(name, d)); Object.assign(st.kinds, c.rules.kinds); } });
|
|
118
118
|
// a pack's actions are the game's own (owner 'game'): loading the pack again replaces them, it is not a second binder
|
|
119
|
-
if (c.actions) steps.push({ undo: () => e.input.keepActions(Object.keys(c.actions)), commit: () => each(c.actions, (name, a) => e.input.
|
|
119
|
+
if (c.actions) steps.push({ undo: () => e.input.keepActions(Object.keys(c.actions)), commit: () => each(c.actions, (name, a) => e.input.define(name, { label: a.label, keys: a.keys, ...(a.context ? { context: a.context } : {}) })) });
|
|
120
120
|
// audio: sounds / footsteps by name into engine.audio.config, rules to ambience() / music() (core/audio/audioRules.js). A pack loaded again
|
|
121
121
|
// replaces its own rules (hot reload): a named pack by its name, an unnamed one by the data object itself, so loading the same object
|
|
122
122
|
// twice never stacks its rules (a fresh key per load did); two different unnamed objects both keep theirs
|
|
@@ -1,35 +1,60 @@
|
|
|
1
1
|
// Models of placed content records: clone the shared prototype of a model name (core/assets/namedModel.js protoOf, the one path every system uses),
|
|
2
2
|
// align it and its collision to the record (props and template instances).
|
|
3
3
|
import * as THREE from 'three';
|
|
4
|
-
import { codedError } from '../../core/base/errorHints.js';
|
|
5
|
-
import {
|
|
4
|
+
import { codedError, coded } from '../../core/base/errorHints.js';
|
|
5
|
+
import { warnOnce } from '../../core/base/validate.js';
|
|
6
|
+
import { protoOf, copyLeft, protoLease } from '../../core/assets/namedModel.js';
|
|
6
7
|
import { wrapLod } from '../../core/assets/assetLod.js';
|
|
7
8
|
import { Vector3 } from 'three';
|
|
8
|
-
import {
|
|
9
|
+
import { cloneModel } from '../../core/base/freeParts.js';
|
|
9
10
|
import { list } from '../../core/base/util.js';
|
|
11
|
+
import { rotOf, scaleOf } from '../../core/base/math.js';
|
|
12
|
+
import { isTilted, layerIgnored } from './rules.js';
|
|
10
13
|
|
|
11
14
|
const BASE_BAND = 0.2; // the share of the model's height above the ground that counts as its base
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* Every part with geometry under a model root, with its matrix in model space: frame (the root's own matrix as built) times the local matrices down to the part.
|
|
18
|
+
* Why local matrices and not matrixWorld: a copy already placed (a hot swap measures it again) is measured as built, and two copies of the same parts give the
|
|
19
|
+
* very same numbers, which is what baseOf's cache keys on. A LOD's low levels are left out: they only stand in on screen, collision is the full model's. @internal
|
|
20
|
+
*/
|
|
21
|
+
function partsOf(root, frame) {
|
|
22
|
+
const out = [];
|
|
23
|
+
const walk = (o, m) => {
|
|
24
|
+
if (o.userData.lodLevel) return;
|
|
25
|
+
if (o.geometry?.attributes?.position) out.push({ o, m });
|
|
26
|
+
for (const c of o.children) { if (c.matrixAutoUpdate) c.updateMatrix(); walk(c, m.clone().multiply(c.matrix)); }
|
|
27
|
+
};
|
|
28
|
+
walk(root, frame);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Where a model stands, in model space: { x, z } centre and width of the base (its larger side, so a plain box keeps the same radius). Takes a prototype or a
|
|
34
|
+
* prepared copy's measure (measureOf), and only a circle collider asks, so box colliders and props without one never walk triangles.
|
|
15
35
|
* Why this measure: the base is the geometry in the lowest fifth of the height above y = 0 (above its lowest point when it floats), clipped from the triangles, because a crown or an arm starts higher, a tall box has no vertex halfway up and a boulder's belly is what walkers hit.
|
|
16
|
-
*
|
|
36
|
+
* Cached per prototype by the parts themselves (geometry and matrix): copies whose setup only swapped materials share the prototype's base, while a setup that
|
|
37
|
+
* thickened the trunk under the same crown gets its own. Overall bounds would not tell those two apart. @internal
|
|
17
38
|
*/
|
|
18
|
-
export function baseOf(
|
|
19
|
-
if (
|
|
39
|
+
export function baseOf(m) {
|
|
40
|
+
if (m.base) return m.base;
|
|
41
|
+
if (!m.parts) { m.obj.updateMatrix(); m.parts = partsOf(m.obj, m.obj.matrix.clone()); } // a prototype: never placed, its root matrix is its frame
|
|
42
|
+
const cache = ((m.owner ?? m).bases ??= new Map());
|
|
43
|
+
// an instanced part falls back to its own instances' bounds, which its geometry does not name: such a part is not shared
|
|
44
|
+
const key = m.parts.map(({ o, m: at }) => (o.isInstancedMesh || o.isBatchedMesh ? `own${o.id}` : o.geometry.id) + ':' + at.elements.join(',')).join('|');
|
|
45
|
+
if (cache.has(key)) return m.base = cache.get(key);
|
|
20
46
|
const meshes = [], p = new Vector3();
|
|
21
47
|
let bottom = Infinity, top = -Infinity, instanced = false;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const pos = m.geometry.attributes.position, at = new Float32Array(pos.count * 3);
|
|
48
|
+
for (const { o, m: at } of m.parts) {
|
|
49
|
+
if (!o.isMesh) continue;
|
|
50
|
+
instanced ||= !!(o.isInstancedMesh || o.isBatchedMesh);
|
|
51
|
+
const pos = o.geometry.attributes.position, xyz = new Float32Array(pos.count * 3);
|
|
27
52
|
for (let i = 0; i < pos.count; i++) {
|
|
28
|
-
p.fromBufferAttribute(pos, i).applyMatrix4(
|
|
53
|
+
p.fromBufferAttribute(pos, i).applyMatrix4(at).toArray(xyz, i * 3);
|
|
29
54
|
bottom = Math.min(bottom, p.y); top = Math.max(top, p.y);
|
|
30
55
|
}
|
|
31
|
-
meshes.push({ at, index:
|
|
32
|
-
}
|
|
56
|
+
meshes.push({ at: xyz, index: o.geometry.index });
|
|
57
|
+
}
|
|
33
58
|
const low = top > 0 ? Math.max(bottom, 0) : bottom, high = low + (top - low) * BASE_BAND;
|
|
34
59
|
let x0 = Infinity, x1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
35
60
|
const take = (x, z) => { x0 = Math.min(x0, x); x1 = Math.max(x1, x); z0 = Math.min(z0, z); z1 = Math.max(z1, z); };
|
|
@@ -43,9 +68,11 @@ export function baseOf(proto) {
|
|
|
43
68
|
for (let i = 0; i + 2 < n; i += 3) { const a = v(i), b = v(i + 1), c = v(i + 2); edge(at, a, b); edge(at, b, c); edge(at, c, a); }
|
|
44
69
|
}
|
|
45
70
|
// shortcut: instanced parts and models without triangles (points, lines, sprites) use the bounding box; measure their instances if a prop ever needs it
|
|
46
|
-
const { size, center } =
|
|
47
|
-
|
|
71
|
+
const { size, center } = m;
|
|
72
|
+
m.base = instanced || x0 > x1 ? { x: center.x, z: center.z, width: Math.max(size.x, size.z) }
|
|
48
73
|
: { x: (x0 + x1) / 2, z: (z0 + z1) / 2, width: Math.max(x1 - x0, z1 - z0) };
|
|
74
|
+
cache.set(key, m.base);
|
|
75
|
+
return m.base;
|
|
49
76
|
}
|
|
50
77
|
|
|
51
78
|
/**
|
|
@@ -68,28 +95,28 @@ export function settle(e, rec, o, solid, mul = 1) {
|
|
|
68
95
|
for (const h of ud.colliders.splice(0)) h.remove();
|
|
69
96
|
// a solid prop blocks the camera with its whole mesh, not only its footprint collider: crowns and eaves stand outside the footprint, and no game code should have to say so
|
|
70
97
|
const blocks = !!solid.collide && solid.collide.occluder !== false && solid.occluder !== false;
|
|
71
|
-
if (solid.static !== false && e.rays) { o.updateMatrixWorld(true); ud.unstatic = e.
|
|
98
|
+
if (solid.static !== false && e.rays) { o.updateMatrixWorld(true); ud.unstatic = e.assets.addStatic(o, { occluder: blocks }); }
|
|
72
99
|
if (!solid.collide) return;
|
|
73
|
-
const { collide } = solid, set = typeof collide === 'object' ? collide : null, base = set || collide === 'circle' ? baseOf(ud.
|
|
74
|
-
const size = ud.
|
|
100
|
+
const { collide } = solid, set = typeof collide === 'object' ? collide : null, base = set?.circle !== undefined || collide === 'circle' ? baseOf(ud.measure) : null, layer = set?.layer;
|
|
101
|
+
const size = ud.measure.size.clone().multiply(new THREE.Vector3(...sv));
|
|
102
|
+
// a turned-over solid is held by collider3d, which has no layers: said once, and the prop stops every mover (a world.set that tilts it must not throw mid-game)
|
|
103
|
+
const lost = layerIgnored(rec, collide);
|
|
104
|
+
if (lost) warnOnce(coded('content-layer-ignored', `prop ${JSON.stringify(rec.id ?? rec.model)}: ${lost}`), 'content-layer:' + (rec.id ?? rec.model));
|
|
75
105
|
if (tilted) { // a turned-over solid is not a footprint on the ground: the three-axis provider holds it (o.quaternion carries the same turn the model has)
|
|
76
|
-
const mid = ud.
|
|
106
|
+
const mid = ud.measure.center.clone().multiply(new THREE.Vector3(...sv)).applyQuaternion(o.quaternion).add(o.position);
|
|
77
107
|
ud.colliders.push(e.collider3d.addSolid(base
|
|
78
108
|
? { position: [mid.x, mid.y, mid.z], radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]) }
|
|
79
109
|
: { position: [mid.x, mid.y, mid.z], size: [size.x, size.y, size.z], rotation: rot }));
|
|
80
110
|
return;
|
|
81
111
|
}
|
|
82
112
|
if (!e.collision) return;
|
|
83
|
-
const c = base ?? ud.
|
|
113
|
+
const c = base ?? ud.measure.center, ox = c.x * sv[0], oz = c.z * sv[2];
|
|
84
114
|
const cx = x + ox * Math.cos(rot[1]) + oz * Math.sin(rot[1]), cz = z - ox * Math.sin(rot[1]) + oz * Math.cos(rot[1]);
|
|
85
115
|
ud.colliders.push(base
|
|
86
|
-
? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]), height: size.y, occluder: blocks })
|
|
87
|
-
: e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot[1], height: size.y, occluder: blocks }));
|
|
116
|
+
? e.collision.addCircle({ x: cx, z: cz }, { radius: (set?.circle ?? base.width / 2) * Math.max(sv[0], sv[2]), height: size.y, occluder: blocks, layer })
|
|
117
|
+
: e.collision.addBox({ x: cx, z: cz }, { halfWidth: size.x / 2, halfDepth: size.z / 2, rotation: rot[1], height: size.y, occluder: blocks, layer }));
|
|
88
118
|
}
|
|
89
119
|
/** Is the model still as settle aligned it, with its collider in the holder installed now (a new one starts empty; with none there is nothing to do yet)? update asks every frame for every built prop, because world.move sends no event @internal */
|
|
90
|
-
/** rot / scale of a record as [x, y, z]: a number is the facing about Y and a uniform scale, as it always was; an array sets each axis (the model's Euler order XYZ) */
|
|
91
|
-
export const rotOf = rec => Array.isArray(rec.rot) ? rec.rot : [0, rec.rot ?? 0, 0];
|
|
92
|
-
export const scaleOf = (rec, mul = 1) => (Array.isArray(rec.scale) ? rec.scale : [rec.scale ?? 1, rec.scale ?? 1, rec.scale ?? 1]).map(v => v * mul);
|
|
93
120
|
const fitOf = (rec, mul) => JSON.stringify([rec.position.x, rec.position.z, rec.ground === false ? rec.position.y : null, rotOf(rec), scaleOf(rec, mul)]);
|
|
94
121
|
export const fits = (e, o, rec, mul = 1) => { const h = holderOf(e, rec); return (!h || o.userData.holder === h) && o.userData.fit === fitOf(rec, mul); };
|
|
95
122
|
const shapeOf = (rec, mul) => JSON.stringify([rotOf(rec), scaleOf(rec, mul)]);
|
|
@@ -97,26 +124,48 @@ const shapeOf = (rec, mul) => JSON.stringify([rotOf(rec), scaleOf(rec, mul)]);
|
|
|
97
124
|
export const fitsShape = (o, rec, mul = 1) => o.userData.shape === shapeOf(rec, mul);
|
|
98
125
|
/** A tilted solid needs the three-axis provider (collider3d); the same error at load (props.js) and at build, so a mistake shows once, early @internal */
|
|
99
126
|
export const tiltError = rec => codedError('content-misuse', `prop ${JSON.stringify(rec.id ?? rec.model)}: collide on a model turned about x or z (rot ${JSON.stringify(rec.rot)}) needs a collider3d provider: install rigid() (or your own collider3d), or set collide: false`);
|
|
100
|
-
export const isTilted = rec => { const r = rotOf(rec); return !!(r[0] || r[2]); };
|
|
101
127
|
const holderOf = (e, rec) => isTilted(rec) ? e.collider3d : e.collision;
|
|
102
128
|
|
|
103
129
|
/** Clone the shared prototype of a model for one record and align it (props and template instances). skeletonClone: a skinned part of a plain clone keeps the prototype's bones and draws where they stand @internal */
|
|
104
130
|
export async function buildModel(e, api, rec, model, solid, mul = 1) {
|
|
105
131
|
const proto = await protoOf(e, api, model), name = list(model)[0], lod = rec.lod ?? solid.lod;
|
|
106
|
-
//
|
|
107
|
-
const
|
|
132
|
+
// the record keeps only the word `lod`, so a save holds no level
|
|
133
|
+
const lease = protoLease(e, proto, `content:${rec.id ?? name}`); // at clone time, before any wait: a hot swap during the LOD wait retires the prototype's own lease
|
|
134
|
+
try {
|
|
135
|
+
const o = lod ? await wrapLod(e.assets, name, cloneModel(proto.obj), { distances: Array.isArray(lod) ? lod : undefined, scale: Math.max(...scaleOf(rec, mul)) }) : cloneModel(proto.obj);
|
|
108
136
|
o.name ||= name; o.userData.name ??= name;
|
|
137
|
+
// one order: copy, the game's setup, measure, then settle registers rays and colliders. A setup that throws gives back what the copy took (Assets.handOut)
|
|
138
|
+
e.assets.handOut(o, name);
|
|
139
|
+
o.updateMatrix();
|
|
140
|
+
const frame = o.matrix.clone(); // before settle places it: what the parts are measured in, now and after a hot swap
|
|
109
141
|
o.userData.proto = proto; o.userData.colliders = [];
|
|
142
|
+
// a hot swap gives the copy new parts and a new prototype (core/assets/assetHot.js): measured again by this same rule, and the next align reads it
|
|
143
|
+
(o.userData.remeasure = () => { o.userData.measure = measureOf(e, o.userData.proto, o, frame); })();
|
|
110
144
|
o.userData.refit = r => { if (!solid.body && !fits(e, o, r, mul)) settle(e, r, o, solid, mul); }; // a body places itself; a stale solid or mul is put right by the presenter's next update
|
|
111
145
|
// a file model only: a generator's prototype is pinned for good (Assets.cached), so nothing could free it. The built prop counts in describe().assets until it is torn down
|
|
112
|
-
|
|
146
|
+
o.userData.lease = lease;
|
|
113
147
|
if (rec.batch === false) o.userData.batch = false; // opt out of engine.batching for this record
|
|
114
148
|
o.position.set(rec.position.x, 0, rec.position.z); // world puts the model on the record after build; height and collision are aligned here
|
|
115
149
|
settle(e, rec, o, solid, mul);
|
|
116
150
|
return o;
|
|
151
|
+
} catch (err) { lease?.remove(); throw err; } // a build that fails gives the lease back (handOut gave back the copy's own)
|
|
117
152
|
}
|
|
118
153
|
/** ctx.feeds: every built solid goes into the holder installed now, so the line after use() reads it. The presenters' update asks the same every frame, for what moved @internal */
|
|
119
154
|
export const refit = e => { for (const rec of e.world?.query({}) ?? []) e.world.view(rec.id)?.userData.refit?.(rec); };
|
|
120
155
|
|
|
121
|
-
/**
|
|
122
|
-
|
|
156
|
+
/**
|
|
157
|
+
* What collision and bodies measure for one built copy: { obj, size, center } like a prototype, so baseOf takes either. The prototype when no setup ran on the
|
|
158
|
+
* copy; else the copy as prepared, from its parts (partsOf: as built whatever its place now, never a LOD's low levels, so collision is the same with lod on or
|
|
159
|
+
* off). Only the bounds here, cheap (each geometry's own box); the base waits for a circle collider (baseOf). frame: the root's matrix as built (a LOD's is identity) @internal
|
|
160
|
+
*/
|
|
161
|
+
function measureOf(e, proto, o, frame) {
|
|
162
|
+
if (!e.assets.prepared(o)) return proto;
|
|
163
|
+
const parts = partsOf(o, frame), box = new THREE.Box3(), b = new THREE.Box3();
|
|
164
|
+
// the box three's Box3.setFromObject takes (protoOf measures the prototype with it): an instanced or skinned part's own, else its geometry's
|
|
165
|
+
const own = x => x.boundingBox ?? (x.computeBoundingBox(), x.boundingBox);
|
|
166
|
+
for (const { o: p, m } of parts) box.union(b.copy(p.boundingBox !== undefined ? own(p) : own(p.geometry)).applyMatrix4(m));
|
|
167
|
+
return { obj: o, parts, owner: proto, size: box.getSize(new THREE.Vector3()), center: box.getCenter(new THREE.Vector3()) };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Tear down only: geometry and material belong to the shared prototype, the next build clones it again; dropCopy gives back what the copy itself took (LOD levels' leases, Animators, bones) @internal */
|
|
171
|
+
export function unbuildModel(e, o) { o.userData.lease?.remove(); o.userData.unstatic?.remove(); for (const h of o.userData.colliders) h.remove(); o.removeFromParent(); e.assets.dropCopy(o); copyLeft(e); } // copyLeft: a retired prototype's material this copy drew may go now
|
package/modules/content/props.js
CHANGED
|
@@ -17,7 +17,8 @@ import { buildModel, settle, fits, unbuildModel } from './models.js';
|
|
|
17
17
|
import { placeTemplate } from './templates.js';
|
|
18
18
|
import { srcOf } from './ids.js';
|
|
19
19
|
import { placeY } from '../../core/scene/ground.js';
|
|
20
|
-
import {
|
|
20
|
+
import { tiltError } from './models.js';
|
|
21
|
+
import { isTilted } from './rules.js';
|
|
21
22
|
import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
|
|
22
23
|
import { list } from '../../core/base/util.js';
|
|
23
24
|
import { DEV, fmt, closest } from '../../core/base/validate.js';
|
package/modules/content/rules.js
CHANGED
|
@@ -79,7 +79,7 @@ const RULE_STRINGS = {
|
|
|
79
79
|
id: { type: 'string', optional: true, desc: 'stable id (needed when entries are later inserted in the middle)' },
|
|
80
80
|
model: { type: 'any', desc: "model name, or [name, ...args] for a generated model" }, ...at, ...pose, ...copied,
|
|
81
81
|
ground: { type: 'bool', optional: true, desc: 'false = do not snap to the ground: y is the height in the world' },
|
|
82
|
-
collide: { label: 'Collision', rare: true, type: 'any', optional: true, desc: "collision: 'box', 'circle', { circle
|
|
82
|
+
collide: { label: 'Collision', rare: true, type: 'any', optional: true, desc: "collision: 'box', 'circle', { circle?: radius, occluder?: false, layer?: 'gate' } (layer: characters with passes: ['gate'] walk through), or false = none" },
|
|
83
83
|
occluder: { label: 'Blocks camera', rare: true, type: 'bool', optional: true, desc: 'false = a solid prop the follow camera may pass through (walkers are still stopped)' },
|
|
84
84
|
static: { label: 'Never moves', rare: true, type: 'bool', optional: true, desc: 'never moves (may be merged into one draw call)' },
|
|
85
85
|
batch: { label: 'Merge copies', rare: true, type: 'bool', optional: true, desc: 'false = never batch this copy' },
|
|
@@ -137,10 +137,16 @@ export const PLACEMENT_FIELDS = RULE_STRINGS.fields;
|
|
|
137
137
|
/** Why a prop's or template's `collide` is wrong, or null. One rule for the load and content-check: a mistyped object must not quietly become a box */
|
|
138
138
|
export function collideProblem(v) {
|
|
139
139
|
if (v === undefined || v === false || v === 'box' || v === 'circle') return null;
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
const keys = isObject(v) ? Object.keys(v) : [];
|
|
141
|
+
const form = keys.length > 0 && keys.every(k => k === 'circle' || k === 'occluder' || k === 'layer');
|
|
142
|
+
if (form && (v.circle === undefined || Number.isFinite(v.circle) && v.circle > 0) && (v.occluder === undefined || typeof v.occluder === 'boolean')
|
|
143
|
+
&& (v.layer === undefined || typeof v.layer === 'string' && v.layer)) return null;
|
|
144
|
+
return `must be one of false, "box", "circle" or { circle?: radius in meters above 0 (a box without it), occluder?: false, layer?: 'gate' }, got ${JSON.stringify(v)}`;
|
|
143
145
|
}
|
|
146
|
+
/** A prop turned about X or Z (not only faced about Y): the three-axis provider holds it. One reading for the load and content-check */
|
|
147
|
+
export const isTilted = rec => Array.isArray(rec?.rot) && !!(rec.rot[0] || rec.rot[2]);
|
|
148
|
+
/** Why a layer is ignored, or null: collide.layer on a tilted prop (collider3d has no layers, so it stops every mover). The load warns with it, content-check reports it */
|
|
149
|
+
export const layerIgnored = (rec, collide) => isTilted(rec) && isObject(collide) && collide.layer ? 'collide.layer needs an upright model; this tilted one stops every mover' : null;
|
|
144
150
|
/** Why a place cannot load, or null: a turned place moves everything standing on it, so a bad rot stops at the load and in content-check alike */
|
|
145
151
|
export const placeProblem = p => p?.rot !== undefined && !Number.isFinite(p.rot) ? `rot must be a number of radians about Y, got ${JSON.stringify(p.rot)}` : null;
|
|
146
152
|
/** Clock time notation 'HH:MM' (24-hour) */
|
|
@@ -168,7 +174,7 @@ export const unknownContent = (name, game) => `unknown content "${name}". Known:
|
|
|
168
174
|
+ `For the game's own data, register it in content/rules.js: export default { kinds: { ${name}: { desc: '…', load: (e, data) => { … } } } }, and list \`rules\` in content/index.js too: the loader only knows what it is handed`;
|
|
169
175
|
/** Error text for an effects key in a game's content/rules.js */
|
|
170
176
|
export const NO_GAME_EFFECTS = "content/rules.js: effects is not a key here. Register the action as an op (engine.ops.define('noun.verb', { can, run }) in main.js) "
|
|
171
|
-
+ "and call it from content with { op: ['noun.verb', { args }] }; see recipes/23-ops.md";
|
|
177
|
+
+ "and call it from content with { op: ['noun.verb', { args }] }; see recipes/23-ops.md §2";
|
|
172
178
|
|
|
173
179
|
const say = (vocab, x) => Object.entries(x).map(([k, v]) => vocab[k]?.describe?.(v) ?? `${k} ${JSON.stringify(v)}`);
|
|
174
180
|
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
// and its whole state (turn, speed, asleep) with it in the save part 'rigid'. A copy nothing moved stays out of the save.
|
|
26
26
|
// Ids: an instance with state (state / container / interact / body) should have a written id (ids.js); without one dev warns.
|
|
27
27
|
import { checkOptions, freezeDef, missingText, fmt, DEV } from '../../core/base/validate.js';
|
|
28
|
-
import { xzOf } from '../../core/base/math.js';
|
|
28
|
+
import { xzOf, scaleOf } from '../../core/base/math.js';
|
|
29
29
|
import { placeY } from '../../core/scene/ground.js';
|
|
30
|
-
import { buildModel, settle, fits, fitsShape, unbuildModel
|
|
30
|
+
import { buildModel, settle, fits, fitsShape, unbuildModel } from './models.js';
|
|
31
31
|
import { srcOf, stateful, templateId } from './ids.js';
|
|
32
32
|
import { PLACEMENT_FIELDS, collideProblem } from './rules.js';
|
|
33
33
|
import { fieldsShape } from './fields.js';
|
|
@@ -219,7 +219,7 @@ const SETTLE = 0.05; // meters: a body that only settled (contact with uneven
|
|
|
219
219
|
* - A copy moved with no state (rebuilt by a new holder, a save without it, or a record moved after that state: rigid drops it): it starts awake at the record, so one left in the air comes down.
|
|
220
220
|
*/
|
|
221
221
|
function addBody(e, rec, o, d) {
|
|
222
|
-
const { shape, ...opts } = d.body, s = o.userData.
|
|
222
|
+
const { shape, ...opts } = d.body, s = o.userData.measure.size, ud = o.userData, p = rec.position;
|
|
223
223
|
ud.batch = false; ud.bodyFrom = d.body; ud.holder = bodyHolder(e);
|
|
224
224
|
const half = s.y * scaleOf(rec)[1] / 2, floor = e.surface(p.x, p.z, rec.floor) + half;
|
|
225
225
|
// a state from the save decides this copy's place, even when the record reads as unmoved (put back by an undo): resting it would rewrite the baseline to a place it is not at
|
package/modules/content/words.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Running condition and effect words: content.test and content.run. The vocabulary is rules.js, the built-in meanings are in loader.js.
|
|
2
|
-
import { warnMissing, warnOnce } from '../../core/base/validate.js';
|
|
2
|
+
import { warnMissing, warnOnce, syncOnly } from '../../core/base/validate.js';
|
|
3
3
|
import { coded } from '../../core/base/errorHints.js';
|
|
4
4
|
import { parseClock } from '../../core/time/dayTime.js';
|
|
5
5
|
import { list } from '../../core/base/util.js';
|
|
@@ -34,7 +34,7 @@ export function runWords(e, api, effects, a, actor) {
|
|
|
34
34
|
for (const x of list(a)) for (const [k, v] of Object.entries(x)) {
|
|
35
35
|
const d = effects.get(k);
|
|
36
36
|
if (!d) { warnMissing('effect', k, [...effects.keys()]); continue; }
|
|
37
|
-
try { const r = d.run(e, d.raw ? v : norm(e, api, d.ref, v), v, ctx); if (isRunFailure(r)) failed.push({ word: k, code: r.code, facts: r.facts }); } catch (err) { first ??= err; threw++; }
|
|
37
|
+
try { const r = d.run(e, d.raw ? v : norm(e, api, d.ref, v), v, ctx); syncOnly(r, `content word { ${k} }`, true); if (isRunFailure(r)) failed.push({ word: k, code: r.code, facts: r.facts }); } catch (err) { first ??= err; threw++; }
|
|
38
38
|
}
|
|
39
39
|
const answer = failed.length ? failure({ code: failed[0].code, facts: { failed } }) : { ok: true };
|
|
40
40
|
if (failed.length) {
|
|
@@ -10,7 +10,7 @@ import { stats } from '../../render/backend.js';
|
|
|
10
10
|
/** engine.debug.panel (the debug panel) */
|
|
11
11
|
export class DebugPanel {
|
|
12
12
|
/** @internal */
|
|
13
|
-
constructor(engine, { open = false } = {}) {
|
|
13
|
+
constructor(engine, { open = false } = {}, mod = null) {
|
|
14
14
|
/** @internal */ this.engine = engine;
|
|
15
15
|
/** Panel root element @type {HTMLElement} */
|
|
16
16
|
this.el = document.createElement('div');
|
|
@@ -70,7 +70,7 @@ export class DebugPanel {
|
|
|
70
70
|
return i;
|
|
71
71
|
};
|
|
72
72
|
if (e.calendar) {
|
|
73
|
-
bind('ts', () => e.clock.rate, v =>
|
|
73
|
+
bind('ts', () => e.clock.rate, v => mod('clock.rate', { set: v, layer: 'debug' }), v => v + '×'); // ctx.mod: the module's own tracked entry, so the game's rate comes back when the panel leaves
|
|
74
74
|
/** @internal */ this.tod = bind('tod', () => e.calendar.timeOfDay, v => e.calendar.timeOfDay = v, () => e.calendar.clock);
|
|
75
75
|
}
|
|
76
76
|
const ws = q('[data-s="weather"]');
|
|
@@ -124,13 +124,13 @@ const DEBUG_PANEL_PARAMS = keysSchema(['open']);
|
|
|
124
124
|
*/
|
|
125
125
|
export function debug(opts = {}) {
|
|
126
126
|
readParams('debugPanel', DEBUG_PANEL_PARAMS, opts);
|
|
127
|
-
let d = null; const prof = { n: 0, t: 0
|
|
127
|
+
let d = null; const prof = { n: 0, t: 0 };
|
|
128
128
|
return {
|
|
129
129
|
name: 'debugPanel', skipKind: 'none', type: 'ui', params: DEBUG_PANEL_PARAMS, options: opts, label: 'Debug panel', optional: ['calendar', 'weather', 'terrain'],
|
|
130
130
|
install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.debugPanel': '调试面板' }, en: { 'module.debugPanel': 'debug panel' } });
|
|
131
|
-
d = new DebugPanel(e, opts); e.debug.panel = d;
|
|
131
|
+
d = new DebugPanel(e, opts, ctx.mod); e.debug.panel = d;
|
|
132
132
|
// the toggle action has no key of its own (presets.bindings.debug binds F3); optional: the panel works by code (panel.el.hidden) too
|
|
133
|
-
ctx.input.
|
|
133
|
+
ctx.input.define('debugPanel', { label: 'debug.toggle', optional: true });
|
|
134
134
|
return d;
|
|
135
135
|
},
|
|
136
136
|
dispose(e) { if (e.debug.panel === d) e.debug.panel = null; d?.el.remove(); },
|
|
@@ -138,11 +138,11 @@ export function debug(opts = {}) {
|
|
|
138
138
|
// open matters to a screenshot (the panel covers a corner)
|
|
139
139
|
describe() { return { open: !d.el.hidden }; },
|
|
140
140
|
afterRender(dt, e) {
|
|
141
|
-
prof.n++; prof.t += dt;
|
|
142
|
-
if (prof.t < 0.5) return;
|
|
141
|
+
prof.n++; prof.t += dt;
|
|
142
|
+
if (prof.t < 0.5) return; // the text refreshes twice a second; the ms it shows and judges is the budget's median, the one reading describe and inspect.perf give
|
|
143
143
|
const s = e.terrain?.stats || {}, info = stats(e.renderer);
|
|
144
|
-
d.stats({ fps: prof.n / prof.t, cpu:
|
|
145
|
-
prof.n = prof.t =
|
|
144
|
+
d.stats({ fps: prof.n / prof.t, cpu: e.budget._frameMs()?.ms ?? 0, calls: info.drawCalls, tris: info.triangles, visible: s.visible ?? 0, loaded: s.loaded ?? 0, instances: s.instances ?? 0, apply: s.applyMs ?? 0, queued: s.queued ?? 0 });
|
|
145
|
+
prof.n = prof.t = 0;
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
148
|
}
|
package/modules/flow/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const FLOW_PARAMS = keysSchema(['start']);
|
|
|
27
27
|
*/
|
|
28
28
|
export function flow(opts = {}) {
|
|
29
29
|
readParams('flow', FLOW_PARAMS, opts);
|
|
30
|
-
let e = null, sig = null, chain = Promise.resolve(), held = null, frozen = null;
|
|
30
|
+
let e = null, sig = null, chain = Promise.resolve(), held = null, frozen = null, leaving = false, queued = null;
|
|
31
31
|
const states = new Map([['playing', {}], ['paused', { freeze: true, lockInput: true }]]);
|
|
32
32
|
// turn freeze / input lock on or off for one state
|
|
33
33
|
const hold = (def, on) => {
|
|
@@ -46,15 +46,18 @@ export function flow(opts = {}) {
|
|
|
46
46
|
go(name) {
|
|
47
47
|
const to = states.get(name);
|
|
48
48
|
if (!to) { warnMissing('flowState', name, [...states.keys()]); return; }
|
|
49
|
+
// a go() asked from inside an exit waits for it: the state is still the old one there, and leaving it twice would recurse or overwrite the state just entered
|
|
50
|
+
if (leaving) { queued = name; return; }
|
|
49
51
|
const from = api.state, def = states.get(from);
|
|
50
52
|
if (from === name) return;
|
|
51
|
-
|
|
53
|
+
leaving = true;
|
|
54
|
+
try { def.exit?.(e, name); } catch (err) { queued = null; throw err; } finally { leaving = false; }
|
|
52
55
|
hold(def, false);
|
|
53
56
|
api.state = name;
|
|
54
57
|
hold(to, true);
|
|
55
58
|
if (to.music !== undefined) to.music === null ? e.music?.stop() : e.music?.play(to.music);
|
|
56
|
-
to.enter?.(e, from);
|
|
57
|
-
|
|
59
|
+
try { to.enter?.(e, from); e.events.emit('flow:change', { from, to: name }); } catch (err) { queued = null; throw err; }
|
|
60
|
+
if (queued !== null) { const next = queued; queued = null; api.go(next); } // the exit's own go(), now that this change is complete
|
|
58
61
|
},
|
|
59
62
|
/** Scene transition: lock input → fade out → fade music → (autosave: 'auto' saves slot 'auto') → fn() → wait for modules ready → fade in → unlock. Repeated calls are queued.
|
|
60
63
|
* A new game or load that goes through before the fade out ends drops the transition, one still in line included, as if it was never asked: fn was written for the state that is gone.
|
|
@@ -78,7 +81,7 @@ export function flow(opts = {}) {
|
|
|
78
81
|
if (autosave === 'auto') e.saves.save('auto');
|
|
79
82
|
turn = stateTurn(e); // from here until the far door stands, the world is between two states
|
|
80
83
|
await e.ops.allow(async () => { await fn?.(); }); // the scene swap is loading: the ops guard lets its writes through
|
|
81
|
-
await whenSettled(e);
|
|
84
|
+
await whenSettled(e, undefined, true);
|
|
82
85
|
if (sig?.aborted) return;
|
|
83
86
|
if (m && prev && !m.current && !m.ruled && !replaced()) m.play(prev); // no track rule: resume the previous track after the switch. A new game or load has its own music, however fn started it; a level load nobody awaited is still this playthrough
|
|
84
87
|
await fadeScreen(e, 0, { seconds: fade });
|
|
@@ -113,7 +116,7 @@ export function flow(opts = {}) {
|
|
|
113
116
|
dispose() { frozen?.remove(); held?.remove(); frozen = held = null; },
|
|
114
117
|
// ?play / applyState({ play }): leave the start state (a title) the way its Start button does; session:start then goes to 'playing'
|
|
115
118
|
stateKeys: ['play'],
|
|
116
|
-
applyState(e, { play }) { if (play != null && opts.start && opts.start !== 'playing' && api.state === opts.start) return e.session.newGame(); },
|
|
119
|
+
applyState(e, { play }, turn) { if (play != null && opts.start && opts.start !== 'playing' && api.state === opts.start) return e.session.newGame({ turn }); }, // inside the scene request's turn: in line it would wait for itself
|
|
117
120
|
describe() { return { state: api.state, transitioning: api.transitioning }; },
|
|
118
121
|
};
|
|
119
122
|
}
|