@wildshard/engine 0.1.19 → 0.1.21
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 +16 -0
- package/lint/engine-sides.json +5 -0
- package/package.json +5 -2
- package/scripts/app-build/gen.ts +11 -0
- package/scripts/cell-mem-bench.mjs +2 -0
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +532 -0
- package/scripts/grid-crossing-nightly.mjs +5 -4
- package/scripts/grid-crossing-report.mjs +5 -2
- package/scripts/grid-crossing-tour.mjs +36 -12
- package/scripts/grid-crossing-walk-proof.mjs +4 -2
- package/scripts/hover-speed-probe.mjs +136 -0
- package/scripts/land.mjs +2 -1
- package/scripts/loading-flow/benchmax.mjs +34 -11
- package/scripts/loading-flow/deskbench.mjs +276 -0
- package/scripts/loading-flow/stalls.d.mts +17 -3
- package/scripts/loading-flow/stalls.mjs +82 -3
- package/scripts/net-lag-proof.mjs +3 -2
- package/scripts/nightly-model.ts +9 -6
- package/scripts/offline-proof.mjs +7 -1
- package/scripts/online-rig.mjs +9 -7
- package/scripts/parity/boot-smoke.mjs +13 -2
- package/scripts/pin-format.ts +5 -2
- package/scripts/pins-reuse.d.mts +1 -0
- package/scripts/pins-reuse.mjs +22 -0
- package/scripts/release-cook.mjs +109 -0
- package/scripts/scratch-dir.mjs +95 -0
- package/scripts/scratch-sweep.mjs +182 -0
- package/scripts/tsconfig.json +2 -12
- package/scripts/vps/harden-prometheus.sh +3 -0
- package/scripts/vps/rebuild.sh +35 -9
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -1
- package/scripts/worktree-reap.mjs +54 -8
- package/scripts/worktree.mjs +19 -5
- package/src/client/engine/anim/rigParser.ts +2 -2
- package/src/client/engine/boot/contentRead.ts +54 -5
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- package/src/client/engine/core/Game.ts +63 -19
- package/src/client/engine/core/gpuOnly.ts +10 -0
- package/src/client/engine/core/renderBudget.ts +134 -0
- package/src/client/engine/core/shadowLayer.ts +18 -0
- package/src/client/engine/explore/pick.ts +13 -1
- package/src/client/engine/net/predictor.ts +12 -4
- package/src/client/engine/net/redial.ts +40 -5
- package/src/client/engine/player/TouchControls.ts +3 -2
- package/src/client/engine/render/dataLook.ts +70 -7
- package/src/client/engine/render/families/pbr.ts +2 -0
- package/src/client/engine/render/families/registry.ts +11 -2
- package/src/client/engine/render/families/sceneSurface.ts +118 -0
- package/src/client/engine/render/look.ts +7 -1
- package/src/client/engine/render/precompile.ts +4 -2
- package/src/client/engine/render/tiers.ts +4 -1
- package/src/client/engine/telemetry/browserErrors.ts +3 -1
- package/src/client/engine/ui/ErrorModal.ts +1 -1
- package/src/client/engine/ui/Loading.ts +14 -2
- package/src/client/engine/ui/errorScreen.ts +51 -9
- package/src/client/engine/ui/hoverBoost.ts +31 -4
- package/src/client/engine/ui/styles/touch.css +6 -0
- package/src/client/engine/world/declaredProps.ts +5 -1
- package/src/client/engine/world/skyRig.ts +4 -1
- package/src/client/engine/world/terrainTileView.ts +64 -23
- package/src/client/game/boot/spawnDownload.ts +44 -6
- package/src/client/game/devScene/hook.ts +149 -12
- package/src/client/game/devScene/liveLook.ts +21 -0
- package/src/client/game/grid/live.ts +47 -10
- package/src/client/game/grid/liveSession.ts +25 -6
- package/src/client/game/grid/pageEntry.ts +12 -1
- package/src/client/game/grid/productInputs.ts +22 -11
- package/src/client/game/grid/session.ts +15 -4
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/session/finish.ts +4 -1
- package/src/client/game/shardfile/client.ts +24 -7
- package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientViews.ts +36 -8
- package/src/client/game/shardfile/clientWorker.ts +4 -4
- package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
- package/src/client/game/shardfile/groundMerge.ts +59 -5
- package/src/client/game/shardfile/hybrid.ts +2 -0
- package/src/client/game/shardfile/look.ts +1 -1
- package/src/client/game/shardfile/slabLibrary.ts +115 -49
- package/src/client/game/shardfile/tileContent.ts +1 -1
- package/src/client/game/shardfile/tileDriver.ts +38 -11
- package/src/client/game/shardfile/wirePage.ts +7 -3
- package/src/client/game/shardfile/worldScenes.ts +17 -10
- package/src/client/host/online/doctor.ts +20 -7
- package/src/client/host/online/doctorView.ts +2 -0
- package/src/client/host/online/linkScreens.ts +95 -11
- package/src/client/host/online/reconnectStrip.ts +3 -2
- package/src/client/host/online/release.ts +87 -16
- package/src/client/host/online/releaseScreens.ts +108 -0
- package/src/client/host/online/shell.ts +24 -5
- package/src/client/host/online/voice.ts +45 -1
- package/src/client/host/online/voiceUi.ts +24 -6
- package/src/client/host/standalone/shell.ts +37 -1
- package/src/server/engine/sim/playerSim.ts +1 -1
- package/src/server/game/grid/simulation.ts +12 -6
- package/src/server/game/quest/eliteDrops.ts +7 -3
- package/src/server/game/riding/nativeTaming.ts +13 -2
- package/src/server/host/dedicated/cellHost.ts +21 -2
- package/src/server/host/dedicated/cellProtocol.ts +2 -0
- package/src/server/host/dedicated/cellWorker.ts +1 -1
- package/src/server/host/dedicated/dedicatedRoom.ts +38 -8
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- package/src/server/host/dedicated/serverMetrics.ts +9 -0
- package/src/server/host/dedicated/workerTable.ts +31 -24
- package/src/server/host/standalone/gridServer.ts +1 -1
- package/src/server/host/standalone/serverHost.ts +56 -10
- package/src/server/host/standalone/serverProduct.ts +9 -7
- package/src/server/host/standalone/serverRuntime.ts +1 -1
- package/src/shared/engine/boot/loadingWaits.ts +10 -2
- package/src/shared/engine/core/config.ts +3 -0
- package/src/shared/engine/core/framePacing.ts +12 -1
- package/src/shared/engine/physics/terrainTiles.ts +20 -4
- package/src/shared/engine/player/hoverSpeed.ts +3 -3
- package/src/shared/engine/strings.ts +12 -1
- package/src/shared/game/devColliders.ts +60 -0
- package/src/shared/game/devGameplay.ts +41 -0
- package/src/shared/game/grid/rules.ts +12 -0
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* the optional `outline` hook (`clientMaterials().outline`): a graph that declares `stages.outline` draws its hull as each
|
|
7
7
|
* mesh's second draw (terrain tiles, fine prop tiles, library panels and models; the coarse L1 proxy keeps one draw).
|
|
8
8
|
*/
|
|
9
|
-
import { AdditiveBlending, Box3, BufferAttribute, BufferGeometry, Material, Mesh, StaticDrawUsage, type Object3D, type Texture } from 'three';
|
|
9
|
+
import { AdditiveBlending, Box3, BufferAttribute, BufferGeometry, Material, Mesh, ShaderMaterial, StaticDrawUsage, type Object3D, type Texture } from 'three';
|
|
10
10
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
11
|
+
import { installTerrainTile, isCoarse, maskTerrainTile } from '@wildshard/engine/world/terrainTileView';
|
|
12
|
+
import { decodeTerrainTile, type TerrainTileData } from '@wildshard/format/terrainTileBytes';
|
|
13
13
|
import { coarseTileMask } from '@wildshard/engine/world/coarseTileMask';
|
|
14
14
|
import { installDeclaredProps, type PropSurfaceBinding } from '@wildshard/engine/world/declaredProps';
|
|
15
15
|
import type { ClientWorldViews, ResidentTile } from './tileContent';
|
|
16
16
|
import type { GraphOutlineHook } from './clientGraphs';
|
|
17
|
-
import { groundMerge } from './groundMerge';
|
|
17
|
+
import { groundMerge, mergeView } from './groundMerge';
|
|
18
18
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
19
19
|
import { geometryBoundsSteps } from '@wildshard/engine/world/geometryBounds';
|
|
20
20
|
import { workSlice } from '@wildshard/engine/core/workSlice';
|
|
@@ -28,6 +28,21 @@ const FLAT = 0.01, FLOOR = 0.1;
|
|
|
28
28
|
const isGlow = (material: Material): boolean => material.userData['graphRawOutput'] === true && material.userData['graphMeshMap'] !== true;
|
|
29
29
|
|
|
30
30
|
function isMesh(object: Object3D): object is Mesh { return object instanceof Mesh; }
|
|
31
|
+
/**
|
|
32
|
+
* SHARD-SOURCE AP8: a fine tile mesh that may draw in its material's cross-tile merge: a plain drawn mesh (not instanced or
|
|
33
|
+
* skinned, no morphs, no groups, no hull under it) on one opaque built-in family material. Left out: see-through surfaces
|
|
34
|
+
* and cards (they sort or face the camera one by one), swaying ones (a phase per prop), graph shaders (they may read
|
|
35
|
+
* the mesh's own space) and mirrored meshes.
|
|
36
|
+
*/
|
|
37
|
+
function mergeable(mesh: Mesh): mesh is Mesh<BufferGeometry, Material> {
|
|
38
|
+
const material: unknown = mesh.material, geometry: unknown = mesh.geometry;
|
|
39
|
+
if (Object.getPrototypeOf(mesh) !== Mesh.prototype || !mesh.visible || mesh.children.length > 0 || !isMaterial(material) || !isGeometry(geometry)) return false;
|
|
40
|
+
if (material instanceof ShaderMaterial || material.transparent || material.userData['sceneAlpha'] === true || material.userData['sceneCard'] === true) return false;
|
|
41
|
+
if (geometry.groups.length > 0 || Object.keys(geometry.morphAttributes).length > 0 || !geometry.hasAttribute('position')) return false;
|
|
42
|
+
// a mirrored mesh (negative scale) would keep its triangles' order in the merge and turn inside out: three flips winding per object
|
|
43
|
+
mesh.updateWorldMatrix(true, false); if (mesh.matrixWorld.determinant() < 0) return false;
|
|
44
|
+
return Object.keys(geometry.attributes).every((name) => !name.startsWith('_') && !name.startsWith('ws'));
|
|
45
|
+
}
|
|
31
46
|
/** a fine tile has nothing under it to hide */
|
|
32
47
|
function noMask(excluded: ReadonlySet<number>): void { if (excluded.size > 0) throw new Error('shardfile views: only a coarse tile masks quadrants'); }
|
|
33
48
|
|
|
@@ -37,7 +52,8 @@ function noMask(excluded: ReadonlySet<number>): void { if (excluded.size > 0) th
|
|
|
37
52
|
* only attaches it. Terrain takes wire bytes or `TerrainTileData` already decoded off the main thread.
|
|
38
53
|
*/
|
|
39
54
|
export interface ClientTileViews {
|
|
40
|
-
|
|
55
|
+
/** `ground`: where fine tiles merge (AP8; absent: `root`); a ring passes its shared root, as for props */
|
|
56
|
+
terrain: (input: Uint8Array | TerrainTileData, root: Object3D, scope: Scope, shadow: boolean, ground?: Object3D) => ResidentTile;
|
|
41
57
|
/** `ground`: where a drawn splat ground's tiles merge (absent: `root`); a ring passes its shared root, as each tile's
|
|
42
58
|
* `root` is its own group */
|
|
43
59
|
props: (props: NonNullable<Shardfile['props']>, key: string, bytes: Uint8Array, root: Object3D, scope: Scope, additional?: ReadonlyMap<string, Uint8Array>, ground?: Object3D) => Promise<ResidentTile | null>;
|
|
@@ -60,7 +76,9 @@ interface ViewPorts { terrain: string | NonNullable<Shardfile['terrain']> | null
|
|
|
60
76
|
/** The terrain's shadow flags (`terrain.shadow`): a tile casts only when `cast` (and the shadow disc says so), receives only when `receive` (absent: both). */
|
|
61
77
|
terrainShadow?: NonNullable<Shardfile['terrain']>['shadow'] | undefined;
|
|
62
78
|
/** The tiles' draw order among the opaque surfaces (`terrain.order`, three's renderOrder; absent: TERRAIN_ORDER). */
|
|
63
|
-
terrainOrder?: number | undefined
|
|
79
|
+
terrainOrder?: number | undefined;
|
|
80
|
+
/** SHARD-SOURCE AP8: a fine tile's static props draw merged per material across tiles (`propMerge`; absent: true) */
|
|
81
|
+
mergeProps?: boolean }
|
|
64
82
|
|
|
65
83
|
/** G784: absent `terrain.order`, the ground draws before the opaque surfaces laid on it (a road, a yard, a path), so a
|
|
66
84
|
* surface at the ground's depth always wins its tie. At renderOrder 0 three broke those ties by material id: a world's
|
|
@@ -88,12 +106,16 @@ export function clientTileViews(ports: ViewPorts): ClientTileViews {
|
|
|
88
106
|
if (material === undefined) throw new Error('shardfile views: the terrain family has no resolved material');
|
|
89
107
|
const cast = ports.terrainShadow?.cast ?? true, receive = ports.terrainShadow?.receive ?? true;
|
|
90
108
|
return {
|
|
91
|
-
terrain: (input, root, scope, shadow) => {
|
|
109
|
+
terrain: (input, root, scope, shadow, groundRoot) => {
|
|
92
110
|
if (material === null) throw new Error('shardfile views: a terrain tile in a shard without terrain');
|
|
93
|
-
const
|
|
111
|
+
const data = input instanceof Uint8Array ? decodeTerrainTile(input) : input;
|
|
112
|
+
const mesh = installTerrainTile(data, { root, scope, material, shadow: cast && shadow, ...(ports.lattice === undefined ? {} : { lattice: ports.lattice }) });
|
|
94
113
|
if (!receive) mesh.receiveShadow = false;
|
|
95
114
|
mesh.renderOrder = ports.terrainOrder ?? TERRAIN_ORDER;
|
|
96
115
|
const hulls = ports.outline?.(mesh, material, scope) ?? [];
|
|
116
|
+
// AP8: a fine tile with no hull draws in the terrain's merge, one view draw a 250 m block; it still casts itself
|
|
117
|
+
// (the shadow pass only) while its shadow disc says so. A coarse tile keeps its own mesh for its quadrant mask.
|
|
118
|
+
if ((ports.mergeProps ?? true) && hulls.length === 0 && !isCoarse(data)) mergeView(groundRoot ?? root, mesh, material, scope);
|
|
97
119
|
// a coarse tile's mask moves its draw range; its hull (a shallow geometry copy) follows
|
|
98
120
|
const mask = (excluded: ReadonlySet<number>): void => { maskTerrainTile(mesh, excluded); for (const hull of hulls) hull.geometry.setDrawRange(mesh.geometry.drawRange.start, mesh.geometry.drawRange.count); };
|
|
99
121
|
return { mask, shadow: cast ? (enabled) => { mesh.castShadow = enabled; } : () => undefined };
|
|
@@ -171,6 +193,12 @@ export function clientTileViews(ports: ViewPorts): ClientTileViews {
|
|
|
171
193
|
for (const { mesh, box } of lit) {
|
|
172
194
|
if (box.max.y - box.min.y < FLAT && box.max.y <= floor + FLOOR) mesh.castShadow = false; else casters.push(mesh);
|
|
173
195
|
}
|
|
196
|
+
// AP8: a fine tile's plain static meshes join their material's merge under the shared root, so a view draws each
|
|
197
|
+
// material once a 250 m block, not once a tile; each still casts itself (the shadow pass only) as its disc says
|
|
198
|
+
if (row.lod === 0 && (ports.mergeProps ?? true)) {
|
|
199
|
+
const meshes: Mesh[] = []; root.traverse((object) => { if (isMesh(object)) meshes.push(object); });
|
|
200
|
+
for (const mesh of meshes) if (mergeable(mesh)) mergeView(parent, mesh, mesh.material, scope);
|
|
201
|
+
}
|
|
174
202
|
const shadow = (enabled: boolean): void => { for (const mesh of casters) mesh.castShadow = enabled; };
|
|
175
203
|
if (row.lod === 1) {
|
|
176
204
|
const apply = coarseTileMask(root, row.x, row.z, scope);
|
|
@@ -162,8 +162,8 @@ export interface WorkerClientReport {
|
|
|
162
162
|
retired: Readonly<Record<string, number>>;
|
|
163
163
|
/** The longest a row of each kind took to spawn, in ms: a model built late shows here. */
|
|
164
164
|
spawnMs: Readonly<Record<string, number>>;
|
|
165
|
-
/** What
|
|
166
|
-
missed: Readonly<NetPlayer['predictor']['missed']>; misses: readonly (readonly number[])[];
|
|
165
|
+
/** What corrections disagreed on, and server-owned transitions that were deliberately not corrections. */
|
|
166
|
+
missed: Readonly<NetPlayer['predictor']['missed']>; misses: readonly (readonly number[])[]; authoritative: Readonly<NetPlayer['predictor']['authoritative']>;
|
|
167
167
|
}
|
|
168
168
|
/** A fight as a proof reads it: its row, where its body stands and the server's name for it. */
|
|
169
169
|
export type WorkerClientFight = EncounterRow & { readonly at: { readonly x: number; readonly y: number; readonly z: number } | null; readonly name: string | null };
|
|
@@ -465,7 +465,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
465
465
|
if (shell.redials === true) others = new (await import('@wildshard/engine/net/otherPlayers')).OtherPlayers(client, ports.scene, scope, player.position);
|
|
466
466
|
if (new URLSearchParams(location.search).has('bossGod')) shell.bossGod();
|
|
467
467
|
bootMark('server:ready-send'); shell.ready();
|
|
468
|
-
const started = diagnosticNow(), report: WorkerClientReport = { drawn: wirePage.drawn, frames: 0, framesPerSecond: 0, ticksPerSecond: 0, correctionsPerMinute: 0, corrections: 0, retired: {}, spawnMs: {}, missed: net.predictor.missed, misses: net.predictor.misses, worstOffset: 0, queue: 0, replaysPerFrame: 0, delayMs: 0, jitterMs: 0, interpHeld: 0, interpStarved: 0, mainMsP95: 0, workerTickMs: 0, rows: 0, attacks: 0, hits: 0, kills: 0, refused: 0, held: 0, dropped: 0, hp: 0, falls: 0, closed: null, x: 0, z: 0, cell: 0, serverX: 0, serverZ: 0, restored, savedTick: -1, savedOk: false, receipts: [], quests: {}, flags: [], paid: 0, fights: [], owned: {}, sky: null, day: null, clawed: false, own: null, movers: 0, posed: 0, sand: 0 };
|
|
468
|
+
const started = diagnosticNow(), report: WorkerClientReport = { drawn: wirePage.drawn, frames: 0, framesPerSecond: 0, ticksPerSecond: 0, correctionsPerMinute: 0, corrections: 0, retired: {}, spawnMs: {}, missed: net.predictor.missed, misses: net.predictor.misses, authoritative: net.predictor.authoritative, worstOffset: 0, queue: 0, replaysPerFrame: 0, delayMs: 0, jitterMs: 0, interpHeld: 0, interpStarved: 0, mainMsP95: 0, workerTickMs: 0, rows: 0, attacks: 0, hits: 0, kills: 0, refused: 0, held: 0, dropped: 0, hp: 0, falls: 0, closed: null, x: 0, z: 0, cell: 0, serverX: 0, serverZ: 0, restored, savedTick: -1, savedOk: false, receipts: [], quests: {}, flags: [], paid: 0, fights: [], owned: {}, sky: null, day: null, clawed: false, own: null, movers: 0, posed: 0, sand: 0 };
|
|
469
469
|
if (unseated) void shell.booted.then(answer => { report.restored = answer.restored; bootMark('server:seated-late'); return undefined; }, () => undefined);
|
|
470
470
|
scope.onDispose(client.onLedger(receipt => { report.receipts.push(`${receipt.grant}:${receipt.name}`); }));
|
|
471
471
|
const contacts: NetCombatEvent[] = [];
|
|
@@ -556,7 +556,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
556
556
|
report.frames++;
|
|
557
557
|
if (firstTick === -1 && tick > 0) firstTick = tick;
|
|
558
558
|
report.ticksPerSecond = firstTick === -1 ? 0 : (tick - firstTick) / ((now - ticksFrom) / 1000); // each world keeps its own clock
|
|
559
|
-
report.missed = predictor.missed; report.corrections = predictor.corrections; report.correctionsPerMinute = predictor.corrections / seconds * 60; report.worstOffset = net.worstOffset; report.queue = predictor.pending;
|
|
559
|
+
report.missed = predictor.missed; report.authoritative = predictor.authoritative; report.corrections = predictor.corrections; report.correctionsPerMinute = predictor.corrections / seconds * 60; report.worstOffset = net.worstOffset; report.queue = predictor.pending;
|
|
560
560
|
report.replaysPerFrame = predictor.replays / report.frames; report.delayMs = client.clock.delayMs; report.jitterMs = client.clock.jitterMs; report.interpHeld = client.interpolator.held; report.interpStarved = client.interpolator.starved;
|
|
561
561
|
report.refused = net.attacks.refused; report.attacks = net.attacks.pending; report.held = net.heldSlot;
|
|
562
562
|
if (report.closed === null && client.closed !== null && !ended && client.closed !== 'reload' && shell.redials !== true) showError(`The game's server stopped (${client.closed})`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
2
|
-
import { buildHeld, frameBudgetSpent, frameDue, presenting } from '@wildshard/engine/core/framePacing';
|
|
2
|
+
import { buildHeld, buildUrgent, frameBudgetSpent, frameDue, presenting } from '@wildshard/engine/core/framePacing';
|
|
3
3
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
4
4
|
import { buildYield, WORK_SLICE_MS } from '@wildshard/engine/core/workSlice';
|
|
5
5
|
|
|
@@ -26,6 +26,6 @@ export function constructionCheckpoint(owner: Scope): Promise<void> | undefined
|
|
|
26
26
|
return buildYield(owner).then(() => { requireOwner(owner); loadingAt = diagnosticNow(); return undefined; });
|
|
27
27
|
}
|
|
28
28
|
loadingAt = undefined;
|
|
29
|
-
if (live && (buildHeld() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS)) return undefined;
|
|
29
|
+
if (live && (buildHeld() || buildUrgent() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS)) return undefined;
|
|
30
30
|
return buildYield(owner).then(() => { requireOwner(owner); return undefined; });
|
|
31
31
|
}
|
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
* tile's vertex colours, say, are left out when a fine tile has none). A merged mesh receives shadow and never casts (as
|
|
13
13
|
* the tiles), and leaves with its block's last member. Each tile keeps its transformed attributes and its kept triangles
|
|
14
14
|
* (refreshed when its transform, an attribute's version or its hidden quadrants change), so a rebuild is copies.
|
|
15
|
+
*
|
|
16
|
+
* SHARD-SOURCE AP8: static props and fine terrain tiles merge the same way (`propMerge`): one view mesh per material,
|
|
17
|
+
* receive flag and render order per 250 m block and vertex layout, normals and tangents turned with their positions, so a
|
|
18
|
+
* view draws a material once across tiles. The merged mesh never casts: a member that casts keeps casting itself from
|
|
19
|
+
* SHADOW_LAYER (the shadow pass only, `castShadow` still its tile's shadow disc), so each light's cascades cull it as before.
|
|
15
20
|
*/
|
|
16
|
-
import { Box3, BufferAttribute, BufferGeometry, InterleavedBufferAttribute, Matrix4, Mesh, Sphere, Vector3, type Material, type Object3D } from 'three';
|
|
21
|
+
import { Box3, BufferAttribute, BufferGeometry, InterleavedBufferAttribute, Matrix3, Matrix4, Mesh, Sphere, Vector3, type Material, type Object3D } from 'three';
|
|
17
22
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
23
|
+
import { MERGED_COPY, MERGED_VIEW, SHADOW_LAYER } from '@wildshard/engine/core/shadowLayer';
|
|
18
24
|
|
|
19
25
|
const HALF = 250, COARSE = 125, BLOCK = 250;
|
|
20
26
|
/** an attribute's change count (an interleaved one counts on its buffer) */
|
|
@@ -36,11 +42,15 @@ interface Member {
|
|
|
36
42
|
}
|
|
37
43
|
interface Block { readonly members: Map<Mesh, Member>; merged: Mesh | null; queued: boolean }
|
|
38
44
|
|
|
45
|
+
/** How members group into blocks: `quadrant` 250 m blocks (a ground's channels are those every member has), `cell` the
|
|
46
|
+
* 500 m cell by vertex layout, `block` 250 m blocks by vertex layout (props: a member never loses a channel). */
|
|
47
|
+
export type MergeGrouping = 'quadrant' | 'cell' | 'block';
|
|
48
|
+
|
|
39
49
|
export class GroundMerge {
|
|
40
50
|
private readonly blocks = new Map<string, Block>();
|
|
41
51
|
/** `onRebuild`: each new merged mesh, before it draws (its shadow flags, render order or a terrain's mesh slot) */
|
|
42
|
-
constructor(private readonly parent: Object3D, private readonly material: Material, private readonly name: string, private readonly onRebuild?: (mesh: Mesh) => void, readonly grouping:
|
|
43
|
-
if (grouping !== 'quadrant' && grouping !== 'cell') throw new Error('Unknown ground merge grouping');
|
|
52
|
+
constructor(private readonly parent: Object3D, private readonly material: Material, private readonly name: string, private readonly onRebuild?: (mesh: Mesh) => void, readonly grouping: MergeGrouping = 'quadrant') {
|
|
53
|
+
if (grouping !== 'quadrant' && grouping !== 'cell' && grouping !== 'block') throw new Error('Unknown ground merge grouping');
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
/** The tile's ground `mesh` joins (hidden itself) until `scope` ends. Detached meshes are already parent-local;
|
|
@@ -100,7 +110,7 @@ export class GroundMerge {
|
|
|
100
110
|
const size = this.grouping === 'cell' ? HALF * 2 : BLOCK;
|
|
101
111
|
const cell = `${String(Math.floor((x + HALF) / size))},${String(Math.floor((z + HALF) / size))}`;
|
|
102
112
|
if (this.grouping === 'quadrant') return cell;
|
|
103
|
-
// A cell merge never drops a channel supplied by another
|
|
113
|
+
// A cell (or block) merge never drops a channel supplied by another member.
|
|
104
114
|
const layout = Object.entries(member.mesh.geometry.attributes).map(([name, attribute]) => `${name}:${String(attribute.itemSize)}:${String(attribute.normalized)}`).sort().join('|');
|
|
105
115
|
return `${cell}|${layout}`;
|
|
106
116
|
}
|
|
@@ -131,10 +141,13 @@ export class GroundMerge {
|
|
|
131
141
|
if (member.mesh.parent === null) toParent.copy(member.mesh.matrix);
|
|
132
142
|
else toParent.multiplyMatrices(parentInverse, member.mesh.matrixWorld);
|
|
133
143
|
const transform = toParent.elements.join(',');
|
|
144
|
+
// AP8: a prop's normals and tangents turn with it (a ground's channels copy as they are)
|
|
145
|
+
const turned = this.grouping === 'block' && !isTranslation(toParent), normalMatrix = turned ? new Matrix3().getNormalMatrix(toParent) : null;
|
|
134
146
|
const attributes = names.map(name => {
|
|
135
147
|
const attribute = geometry.getAttribute(name);
|
|
136
148
|
if (attribute.count !== position.count) throw new Error(`Ground merge member lacks ${name}`);
|
|
137
|
-
const
|
|
149
|
+
const directed = turned && (name === 'normal' || name === 'tangent') && attribute.itemSize >= 3;
|
|
150
|
+
const key = name === 'position' || directed ? transform : '', known = member.attributes.get(name);
|
|
138
151
|
if (known !== undefined && known.key === key && known.version === versionOf(attribute)) return known.values;
|
|
139
152
|
const size = attribute.itemSize, out = new Float32Array(attribute.count * size);
|
|
140
153
|
if (name === 'position') {
|
|
@@ -148,6 +161,14 @@ export class GroundMerge {
|
|
|
148
161
|
out[i * 3 + 1] = ((e[1] ?? 0) * x + (e[5] ?? 1) * y + (e[9] ?? 0) * z + (e[13] ?? 0)) * w;
|
|
149
162
|
out[i * 3 + 2] = ((e[2] ?? 0) * x + (e[6] ?? 0) * y + (e[10] ?? 1) * z + (e[14] ?? 0)) * w;
|
|
150
163
|
}
|
|
164
|
+
} else if (directed) {
|
|
165
|
+
const m = name === 'normal' ? normalMatrix : new Matrix3().setFromMatrix4(toParent), v = new Vector3();
|
|
166
|
+
if (m === null) throw new Error('Ground merge normal without its matrix');
|
|
167
|
+
for (let i = 0; i < attribute.count; i++) {
|
|
168
|
+
v.set(attribute.getComponent(i, 0), attribute.getComponent(i, 1), attribute.getComponent(i, 2)).applyMatrix3(m).normalize();
|
|
169
|
+
out[i * size] = v.x; out[i * size + 1] = v.y; out[i * size + 2] = v.z;
|
|
170
|
+
if (size === 4) out[i * size + 3] = attribute.getComponent(i, 3);
|
|
171
|
+
}
|
|
151
172
|
} else {
|
|
152
173
|
const plain = plainFloats(attribute);
|
|
153
174
|
if (plain === null) for (let i = 0; i < attribute.count; i++) for (let c = 0; c < size; c++) out[i * size + c] = attribute.getComponent(i, c);
|
|
@@ -220,6 +241,12 @@ export class GroundMerge {
|
|
|
220
241
|
}
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
/** a transform with no rotation or scale (its upper 3 x 3 the identity) */
|
|
245
|
+
function isTranslation(m: Matrix4): boolean {
|
|
246
|
+
const e = m.elements;
|
|
247
|
+
return e[0] === 1 && e[1] === 0 && e[2] === 0 && e[4] === 0 && e[5] === 1 && e[6] === 0 && e[8] === 0 && e[9] === 0 && e[10] === 1;
|
|
248
|
+
}
|
|
249
|
+
|
|
223
250
|
const merges = new WeakMap<Object3D, Map<Material, GroundMerge>>();
|
|
224
251
|
/** The one merge of `material` under `parent` (made on first use; each block empties itself as its last member leaves). */
|
|
225
252
|
export function groundMerge(parent: Object3D, material: Material, name: string, grouping: 'quadrant' | 'cell' = 'quadrant'): GroundMerge {
|
|
@@ -230,3 +257,30 @@ export function groundMerge(parent: Object3D, material: Material, name: string,
|
|
|
230
257
|
if (merge.grouping !== grouping) throw new Error('Ground merge grouping changed for its material');
|
|
231
258
|
return merge;
|
|
232
259
|
}
|
|
260
|
+
|
|
261
|
+
/** How a merged prop mesh draws: whether it receives shadow, and its render order (each its own merge). */
|
|
262
|
+
export interface PropDraw { readonly receive: boolean; readonly order: number }
|
|
263
|
+
const propMerges = new WeakMap<Object3D, Map<Material, Map<string, GroundMerge>>>();
|
|
264
|
+
/** SHARD-SOURCE AP8: the one static prop merge of `material` drawn as `draw` under `parent`: 250 m blocks by vertex layout. */
|
|
265
|
+
export function propMerge(parent: Object3D, material: Material, draw: PropDraw): GroundMerge {
|
|
266
|
+
let byMaterial = propMerges.get(parent);
|
|
267
|
+
if (byMaterial === undefined) { byMaterial = new Map(); propMerges.set(parent, byMaterial); }
|
|
268
|
+
let byDraw = byMaterial.get(material);
|
|
269
|
+
if (byDraw === undefined) { byDraw = new Map(); byMaterial.set(material, byDraw); }
|
|
270
|
+
const key = `${String(draw.receive)}|${String(draw.order)}`;
|
|
271
|
+
let merge = byDraw.get(key);
|
|
272
|
+
if (merge === undefined) {
|
|
273
|
+
merge = new GroundMerge(parent, material, MERGED_COPY, (mesh) => { mesh.castShadow = false; mesh.receiveShadow = draw.receive; mesh.renderOrder = draw.order; }, 'block');
|
|
274
|
+
byDraw.set(key, merge);
|
|
275
|
+
}
|
|
276
|
+
return merge;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** AP8: `mesh` joins its merge for the view; it keeps drawing only into the shadow maps (SHADOW_LAYER) while it may cast. */
|
|
280
|
+
export function mergeView(parent: Object3D, mesh: Mesh, material: Material, scope: Scope): void {
|
|
281
|
+
if (mesh.material !== material) throw new Error('Prop merge member draws another material');
|
|
282
|
+
propMerge(parent, material, { receive: mesh.receiveShadow, order: mesh.renderOrder }).add(mesh, scope);
|
|
283
|
+
// SHARD-SOURCE ss4d: still the World Explorer's to pick (explore/pick.ts reads this mark), though it draws on SHADOW_LAYER
|
|
284
|
+
mesh.visible = true; mesh.layers.set(SHADOW_LAYER); mesh.userData[MERGED_VIEW] = true;
|
|
285
|
+
scope.onDispose(() => { mesh.userData[MERGED_VIEW] = false; });
|
|
286
|
+
}
|
|
@@ -399,6 +399,8 @@ export class HybridRuntimeSession {
|
|
|
399
399
|
timings(): { readonly current: Readonly<Pick<HybridHookTiming, 'instance' | 'hook' | 'start'>> | null; readonly completed: readonly HybridHookTiming[] } {
|
|
400
400
|
return { current: this.currentHook, completed: [...this.completedHooks] };
|
|
401
401
|
}
|
|
402
|
+
/** GC6: the cells whose entry is being prepared on the road (for the tour's trace) */
|
|
403
|
+
preparing(): readonly string[] { return [...this.installations.keys()]; }
|
|
402
404
|
/** Finish an actually requested entry before its frame transfer. Neighbours use inert prepare() only.
|
|
403
405
|
* A source must leave first; entered services and parent runtime slots publish only at enter(). */
|
|
404
406
|
prepareEntry(instance: string, signal?: AbortSignal): Promise<boolean> {
|
|
@@ -22,7 +22,7 @@ export function shardfileLook(look: Shardfile['look'], assets?: ReadonlyMap<stri
|
|
|
22
22
|
// B2: `grade.tone` is a grade choice, not a light setting: it holds on every tier, with or without the row (so do M4.7's
|
|
23
23
|
// exposure and vignette); the bloom radius rides the bloom, which the row and the tier gate
|
|
24
24
|
return dataLook({ day: look.day ?? DATA_LOOK_DAY, dayOverride: look.dayOverride, keys: look.keys, lut, neutral: look.grade.tone === 'neutral', aces: look.grade.tone === 'aces',
|
|
25
|
-
exposure: look.grade.exposure, vignette: look.grade.vignette ?? null, bloomRadius: resolved.bloom.radius,
|
|
25
|
+
exposure: look.grade.exposure, vignette: look.grade.vignette ?? null, bloomRadius: resolved.bloom.radius, sky: look.sky?.graph ?? null,
|
|
26
26
|
light: { rim: resolved.rim, pools: resolved.pools, heightFogDensity: resolved.atmosphere.fogHeightDensity, lamps: resolved.lamps, bounce: resolved.bounce, environment: resolved.environment,
|
|
27
27
|
shadow: resolved.shadow, motes: resolved.motes } });
|
|
28
28
|
}
|
|
@@ -2,6 +2,7 @@ import { Box3, BufferGeometry, InstancedBufferAttribute, InstancedMesh, Mesh, Sp
|
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
import { prepareRigLoader } from '@wildshard/engine/anim/rig';
|
|
4
4
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
5
|
+
import { pageScope } from '@wildshard/engine/app/resources';
|
|
5
6
|
import { ownSceneResource } from '@wildshard/engine/app/sceneOwnership';
|
|
6
7
|
import { workSlice } from '@wildshard/engine/core/workSlice';
|
|
7
8
|
import { nativeWholeGeometry } from '@wildshard/engine/models/nativeGeometry';
|
|
@@ -11,6 +12,7 @@ import type { ShardProduct } from '../../../shared/game/shardfile/shardProduct';
|
|
|
11
12
|
import { runtimeProduct } from './runtimeProduct';
|
|
12
13
|
import { SharedTileBuilds, type TileContent } from './tileContent';
|
|
13
14
|
import type { ControlRefinement } from './controlRefinement';
|
|
15
|
+
import { tilesSettling } from './tileDriver';
|
|
14
16
|
|
|
15
17
|
type WholeLibrary = Extract<WorldScenesSection['libraries'][number], { kind: 'whole' }>;
|
|
16
18
|
type SlabTile = WorldSceneSlabLibrary['tiles'][number];
|
|
@@ -21,6 +23,12 @@ const EMPTY: ReadonlySet<number> = new Set();
|
|
|
21
23
|
function slabMesh(node: Object3D): node is Mesh { return node instanceof Mesh; }
|
|
22
24
|
function materialList(mesh: Mesh): Material[] { return Array.isArray(mesh.material) ? mesh.material : [mesh.material]; }
|
|
23
25
|
|
|
26
|
+
/** NB3: the longest a loader publication waits for one more bank read before it publishes what it holds */
|
|
27
|
+
const GATHER_MS = 250;
|
|
28
|
+
|
|
29
|
+
/** One slab part waiting to publish: its instanced chunk, the anchor it joins, and the holder scope that retires it. */
|
|
30
|
+
export interface SlabPart { readonly part: InstancedMesh; readonly anchor: Mesh; readonly scope: Scope }
|
|
31
|
+
|
|
24
32
|
/** a tile's chunks in file order, then each file's chunk order (as its build returns their geometries) */
|
|
25
33
|
const chunksOf = (entry: SlabTile): readonly WorldSceneSlabChunk[] => entry.files.flatMap(file => file.chunks);
|
|
26
34
|
|
|
@@ -76,17 +84,25 @@ export class SlabLibrary {
|
|
|
76
84
|
private readonly entries = new Map<number, SlabTile>();
|
|
77
85
|
private readonly keys = new Map<string, WorldSceneSlabKey>();
|
|
78
86
|
private serial = 0;
|
|
79
|
-
|
|
87
|
+
/** the parts waiting for the one publication cursor, and whether it is running (`publish`) */
|
|
88
|
+
private readonly waiting: { readonly parts: readonly SlabPart[]; readonly mount: () => Promise<void>; readonly done: () => void; readonly fail: (error: unknown) => void }[] = [];
|
|
89
|
+
private publishing = false;
|
|
90
|
+
private readonly bounds: ReadonlyMap<number, ShardProduct['shardfile']['tiles'][number]['bounds']>;
|
|
91
|
+
private readonly product: ShardProduct;
|
|
92
|
+
/** bank reads running now, and the publication waiting for one to finish (NB3: the loader's gather) */
|
|
93
|
+
private reads = 0;
|
|
94
|
+
private readonly readDone: (() => void)[] = [];
|
|
80
95
|
constructor(owner: Scope, product: ShardProduct, private readonly whole: WholeLibrary, private readonly row: WorldSceneSlabLibrary,
|
|
81
96
|
private readonly queue: ControlRefinement, private readonly cover: (tile: number) => Promise<void>,
|
|
82
|
-
private readonly prepare?: (
|
|
97
|
+
private readonly prepare?: (parts: readonly SlabPart[]) => Promise<void>) {
|
|
83
98
|
if (row.of !== whole.id) throw new Error('Slab library covers another library');
|
|
84
99
|
for (const key of row.keys) {
|
|
85
100
|
if (key.castFrom !== undefined) throw new Error('Slab key casting from a band has no run-time draw');
|
|
86
101
|
for (const source of key.sources) { if (this.keys.has(source)) throw new Error('Slab source belongs to two keys'); this.keys.set(source, key); }
|
|
87
102
|
}
|
|
88
103
|
for (const model of whole.models) if (!this.keys.has(model.id)) throw new Error(`Slab library omits refine model ${model.id}`);
|
|
89
|
-
const bounds = new Map(product.shardfile.tiles.filter(tile => tile.lod === 0).map(tile => [tile.z * 8 + tile.x, tile.drawBounds ?? tile.bounds] as const));
|
|
104
|
+
const bounds = this.bounds = new Map(product.shardfile.tiles.filter(tile => tile.lod === 0).map(tile => [tile.z * 8 + tile.x, tile.drawBounds ?? tile.bounds] as const));
|
|
105
|
+
this.product = product;
|
|
90
106
|
const declared = new Set(product.shardfile.files.filter(file => file.kind === 'glb').map(file => file.hash));
|
|
91
107
|
for (const entry of row.tiles) {
|
|
92
108
|
for (const tile of entry.covers ?? [entry.tile]) if (!bounds.has(tile)) throw new Error(`Slabs require a declared fine tile: ${String(tile)}`);
|
|
@@ -94,38 +110,87 @@ export class SlabLibrary {
|
|
|
94
110
|
this.entries.set(entry.tile, entry);
|
|
95
111
|
}
|
|
96
112
|
this.builds = new SharedTileBuilds(owner, async (tile, scope) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
this.reads++;
|
|
114
|
+
try { return await this.read(tile, scope); }
|
|
115
|
+
finally { this.reads--; for (const wake of this.readDone.splice(0)) wake(); }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** One storage bank's chunk geometries: read and decoded in the refinement queue, its covered tiles first covered. */
|
|
119
|
+
private async read(tile: number, scope: Scope): Promise<BufferGeometry[]> {
|
|
120
|
+
const { row, queue, bounds, product } = this;
|
|
121
|
+
const entry = this.entries.get(tile); if (entry === undefined) throw new Error('Missing slab tile');
|
|
122
|
+
const chunks: BufferGeometry[] = [];
|
|
123
|
+
let box = bounds.get(tile);
|
|
124
|
+
if (entry.covers !== undefined) {
|
|
125
|
+
const min: [number, number, number] = [Infinity, Infinity, Infinity], max: [number, number, number] = [-Infinity, -Infinity, -Infinity];
|
|
126
|
+
for (const logical of entry.covers) {
|
|
127
|
+
const covered = bounds.get(logical); if (covered === undefined) throw new Error('Missing slab logical bounds');
|
|
128
|
+
for (const axis of [0, 1, 2] as const) { min[axis] = Math.min(min[axis], covered.min[axis]); max[axis] = Math.max(max[axis], covered.max[axis]); }
|
|
107
129
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
box = { min, max };
|
|
131
|
+
}
|
|
132
|
+
// A shared bank is visible wherever any of its actual logical coverage
|
|
133
|
+
// is visible. Its storage address alone cannot fence its publication.
|
|
134
|
+
const at = { x: entry.covers === undefined || box === undefined ? -250 + (tile % 8 + 0.5) * 62.5 : (box.min[0] + box.max[0]) / 2,
|
|
135
|
+
y: box === undefined ? 0 : (box.min[1] + box.max[1]) / 2,
|
|
136
|
+
z: entry.covers === undefined || box === undefined ? -250 + (Math.floor(tile / 8) + 0.5) * 62.5 : (box.min[2] + box.max[2]) / 2,
|
|
137
|
+
...(box === undefined ? {} : { bounds: box }) };
|
|
138
|
+
await queue.add(`${row.id}:${String(tile)}:${String(this.serial++)}`, at, async () => {
|
|
139
|
+
if (scope.disposed || scope.disposing) return;
|
|
140
|
+
for (const logical of entry.covers ?? [tile]) await this.cover(logical);
|
|
141
|
+
for (const file of entry.files) {
|
|
115
142
|
if (scope.disposed || scope.disposing) return;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (const geometry of read) ownSceneResource(geometry, scope);
|
|
123
|
-
chunks.push(...read);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
if (!scope.disposed && !scope.disposing && chunks.length !== chunksOf(entry).length) throw new Error('Slab tile chunk count differs from its row');
|
|
127
|
-
return chunks;
|
|
143
|
+
let read: readonly BufferGeometry[];
|
|
144
|
+
try { read = await readSlabChunks(scope, product, tile, file); }
|
|
145
|
+
catch (error) { if (scope.disposed || scope.disposing) return; throw error; }
|
|
146
|
+
for (const geometry of read) ownSceneResource(geometry, scope);
|
|
147
|
+
chunks.push(...read);
|
|
148
|
+
}
|
|
128
149
|
});
|
|
150
|
+
if (!scope.disposed && !scope.disposing && chunks.length !== chunksOf(entry).length) throw new Error('Slab tile chunk count differs from its row');
|
|
151
|
+
return chunks;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The library's one publication cursor: `parts` are prepared (the native warm and its completed-draw fence) before they
|
|
155
|
+
* mount (`mount`, inside the cursor), never while another publication's preparation runs. In play a publication is one queued part list (one part);
|
|
156
|
+
* NINE-DRAGON-BENCHMAX NB3: under the loader's settle a publication takes every list waiting when it starts, so one warm
|
|
157
|
+
* covers what was ~50 serialized ones on Nine's spawn view (~75 ms each on a cold phone). A failed preparation fails
|
|
158
|
+
* every list it covered; a retired holder's part is left out of the next publication.
|
|
159
|
+
*/
|
|
160
|
+
private publish(parts: readonly SlabPart[], mount: () => Promise<void>): Promise<void> {
|
|
161
|
+
return new Promise<void>((resolve, reject) => { this.waiting.push({ parts, mount, done: resolve, fail: reject }); void this.drain(); });
|
|
162
|
+
}
|
|
163
|
+
private async drain(): Promise<void> {
|
|
164
|
+
if (this.publishing) return;
|
|
165
|
+
this.publishing = true;
|
|
166
|
+
try {
|
|
167
|
+
while (this.waiting.length > 0) {
|
|
168
|
+
// under the loader a publication first gathers: while banks are still reading it waits for them (each wait capped
|
|
169
|
+
// at GATHER_MS, so a read that never runs can't hold it), and then takes every part they produced at once
|
|
170
|
+
for (let gathered = true; gathered && tilesSettling() && this.reads > 0;) {
|
|
171
|
+
gathered = await new Promise<boolean>(resolve => {
|
|
172
|
+
let settled = false;
|
|
173
|
+
const settle = (read: boolean): void => { if (!settled) { settled = true; resolve(read); } };
|
|
174
|
+
pageScope.timeout(GATHER_MS, () => { settle(false); });
|
|
175
|
+
this.readDone.push(() => { settle(true); });
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
const lists = tilesSettling() ? this.waiting.splice(0) : this.waiting.splice(0, 1);
|
|
179
|
+
const parts = lists.flatMap(list => list.parts).filter(({ scope }) => !scope.disposed && !scope.disposing);
|
|
180
|
+
try { if (this.prepare !== undefined && parts.length > 0) await this.prepare(parts); }
|
|
181
|
+
catch (error) {
|
|
182
|
+
// a holder retired during a shared preparation fails only its own list; the live lists publish again
|
|
183
|
+
const retired = (list: (typeof lists)[number]): boolean => list.parts.some(({ scope }) => scope.disposed || scope.disposing);
|
|
184
|
+
const live = lists.filter(list => !retired(list));
|
|
185
|
+
if (live.length < lists.length && live.length > 0) { for (const list of lists) if (retired(list)) list.fail(error); this.waiting.unshift(...live); }
|
|
186
|
+
else for (const list of lists) list.fail(error);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
for (const list of lists) {
|
|
190
|
+
try { await list.mount(); list.done(); } catch (error) { list.fail(error); }
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} finally { this.publishing = false; }
|
|
129
194
|
}
|
|
130
195
|
/** an anchor's frozen stand-in until its key's first chunk: no channels (the anchor stays hidden) */
|
|
131
196
|
geometry(id: string): BufferGeometry | null { return this.whole.models.some(model => model.id === id) ? new BufferGeometry() : null; }
|
|
@@ -159,7 +224,7 @@ export class SlabLibrary {
|
|
|
159
224
|
const drawn: InstancedMesh[] = [];
|
|
160
225
|
if (lifetime.disposed || lifetime.disposing || scope.disposed || scope.disposing) return drawn;
|
|
161
226
|
scope.onDispose(() => { for (const part of drawn) { part.removeFromParent(); part.dispose(); } drawn.length = 0; });
|
|
162
|
-
const slice = workSlice(undefined, scope);
|
|
227
|
+
const slice = workSlice(undefined, scope), parts: SlabPart[] = [];
|
|
163
228
|
for (const [index, chunk] of chunksOf(entry).entries()) {
|
|
164
229
|
if (chunk.key !== key.id) continue;
|
|
165
230
|
if (lifetime.disposed || lifetime.disposing || scope.disposed || scope.disposing) return drawn;
|
|
@@ -171,23 +236,24 @@ export class SlabLibrary {
|
|
|
171
236
|
part.name = `${mesh.name}:slab:${String(tile)}:${String(index)}`; part.matrixAutoUpdate = false;
|
|
172
237
|
part.castShadow = key.castShadow; part.receiveShadow = key.receiveShadow; part.renderOrder = key.renderOrder;
|
|
173
238
|
part.layers.mask = key.layers; part.frustumCulled = key.frustumCulled;
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
239
|
+
drawn.push(part); parts.push({ part, anchor: mesh, scope });
|
|
240
|
+
}
|
|
241
|
+
// All keys share one publication cursor. A CPU-budget yield alone can
|
|
242
|
+
// mount several still-culled chunks before a turn first uploads them.
|
|
243
|
+
// Preparation lends the actual native geometry to the existing warmer;
|
|
244
|
+
// it must finish its completed-draw fence before another key enters.
|
|
245
|
+
// In play one part a publication (and a frame); under the loader's card a
|
|
246
|
+
// publication takes every part waiting then (NB3, `publish`).
|
|
247
|
+
for (let at = 0; at < parts.length;) {
|
|
248
|
+
const batch = tilesSettling() ? parts.slice(at) : parts.slice(at, at + 1);
|
|
249
|
+
at += batch.length;
|
|
250
|
+
if (lifetime.disposed || lifetime.disposing || scope.disposed || scope.disposing) return drawn;
|
|
251
|
+
await this.publish(batch, async () => {
|
|
252
|
+
if (lifetime.disposed || lifetime.disposing || scope.disposed || scope.disposing) return;
|
|
187
253
|
if (!laid) lay();
|
|
188
|
-
mesh.add(part);
|
|
189
|
-
await slice.yield();
|
|
190
|
-
}
|
|
254
|
+
for (const { part } of batch) mesh.add(part);
|
|
255
|
+
await (tilesSettling() ? slice.check() : slice.yield());
|
|
256
|
+
});
|
|
191
257
|
}
|
|
192
258
|
return drawn;
|
|
193
259
|
});
|
|
@@ -331,7 +331,7 @@ export function clientRingPorts(instances: ReadonlyMap<string, ClientRingInstanc
|
|
|
331
331
|
const tiles = await prepareClientTile(source, assets, key, scope, {
|
|
332
332
|
terrain: async (bytes, owner) => {
|
|
333
333
|
const data = await ports.decoder.decode(bytes); if (owner.disposed || owner.disposing) throw new Error('shardfile rings: tile dropped while decoding');
|
|
334
|
-
return views.terrain(data, group, owner, false);
|
|
334
|
+
return views.terrain(data, group, owner, false, instance.root);
|
|
335
335
|
},
|
|
336
336
|
props: (props, address, bytes, owner, additional) => views.props(props, address, bytes, group, owner, additional, instance.root),
|
|
337
337
|
});
|