@wildshard/engine 0.1.23 → 0.1.24
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 +7 -0
- package/index.html +17 -4
- package/lint/engine-sides.json +7 -0
- package/package.json +29 -3
- package/scripts/app-build/titlePreloads.mjs +8 -5
- package/scripts/bake-road-surfaces.entry.ts +18 -0
- package/scripts/bake-road-surfaces.mjs +44 -0
- package/scripts/changelog.mjs +2 -1
- package/scripts/goldens/capture.mjs +18 -6
- package/scripts/goldens/native-residency.d.mts +1 -0
- package/scripts/goldens/native-residency.mjs +14 -1
- package/scripts/grid-road-lag.mjs +209 -0
- package/scripts/keep-copy.mjs +64 -12
- package/scripts/land.d.mts +4 -1
- package/scripts/land.mjs +85 -3
- package/scripts/loading-flow/benchmax.mjs +2 -0
- package/scripts/map-hash.mjs +1 -1
- package/scripts/nightly-tag.mjs +2 -4
- package/scripts/page-release/content.mjs +19 -10
- package/scripts/page-release/flow.d.mts +3 -2
- package/scripts/page-release/flow.mjs +31 -21
- package/scripts/page-release/packs.d.mts +5 -0
- package/scripts/page-release/packs.mjs +13 -3
- package/scripts/page-release/preview.d.mts +2 -0
- package/scripts/page-release/preview.mjs +74 -0
- package/scripts/page-release.mjs +13 -5
- package/scripts/road-drive-proof.mjs +269 -0
- package/scripts/road-memory-probe.mjs +129 -0
- package/scripts/scratch-dir.mjs +4 -4
- package/scripts/server-release/github.mjs +59 -26
- package/scripts/server-release/publish.mjs +15 -1
- package/scripts/server-release/sign.mjs +8 -4
- package/scripts/test_prebuilt_output.py +3 -1
- package/scripts/turn-in-shots.mjs +83 -0
- package/scripts/vitest-bench-observe-proof.py +168 -0
- package/scripts/vitest-bench.py +122 -77
- package/scripts/vps/rebuild.sh +3 -1
- package/scripts/worktree-reap.mjs +21 -9
- package/scripts/worktree.mjs +1 -1
- package/scripts/zone-gate-proof.mjs +93 -0
- package/src/client/engine/boot/sw.ts +3 -1
- package/src/client/engine/core/ktx2.ts +30 -9
- package/src/client/engine/models/place.ts +7 -5
- package/src/client/engine/pwa/sw.js +57 -2
- package/src/client/engine/render/precompile.ts +6 -0
- package/src/client/engine/render/tiers.ts +9 -0
- package/src/client/engine/ui/playerReload.ts +5 -5
- package/src/client/game/boot/bytes.generated.ts +4 -1
- package/src/client/game/boot/versions.generated.ts +8 -5
- package/src/client/game/grid/cellClip.ts +70 -6
- package/src/client/game/grid/gateCard.css +9 -0
- package/src/client/game/grid/gateCard.ts +67 -0
- package/src/client/game/grid/live.ts +17 -3
- package/src/client/game/grid/liveSession.ts +15 -5
- package/src/client/game/grid/neighbourLife.ts +10 -1
- package/src/client/game/grid/neighbourPanels.ts +29 -2
- package/src/client/game/grid/pageEntry.ts +21 -0
- package/src/client/game/grid/regionalWorld.ts +5 -0
- package/src/client/game/grid/roadCompressedSurfaces.ts +69 -0
- package/src/client/game/grid/roadLook.ts +5 -73
- package/src/client/game/grid/roadLookPlatform.ts +11 -6
- package/src/client/game/grid/roadSurfaceMaps.ts +80 -0
- package/src/client/game/grid/roadTilePool.ts +4 -0
- package/src/client/game/grid/session.ts +52 -12
- package/src/client/game/grid/softWallLook.ts +6 -1
- package/src/client/game/plugin/ui.ts +3 -0
- package/src/client/game/session/play.ts +3 -0
- package/src/client/game/shardfile/clientSource.ts +5 -2
- package/src/client/game/shardfile/clientWorker.ts +3 -2
- package/src/client/game/shardfile/slabLibrary.ts +37 -0
- package/src/client/game/shardfile/slabRanges.ts +145 -0
- package/src/client/host/online/shell.ts +2 -2
- package/src/client/host/standalone/shell.ts +4 -1
- package/src/server/game/grid/simulation.ts +27 -4
- package/src/server/game/plugin/simulation.ts +2 -0
- package/src/server/game/shardfile/dataRespawn.ts +47 -0
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/server/host/standalone/gridServer.ts +18 -6
- package/src/server/host/standalone/roadWorld.ts +30 -0
- package/src/server/host/standalone/serverHost.ts +2 -2
- package/src/shared/engine/entities/AnimalSim.ts +10 -0
- package/src/shared/engine/physics/transferWalls.ts +9 -4
- package/src/shared/game/grid/allocator.ts +8 -1
- package/src/shared/game/grid/gateCount.ts +27 -0
- package/src/shared/game/grid/zoneWalls.ts +64 -0
- package/src/shared/game/strings.ts +2 -0
- package/src/shared/host/standalone/harnessPlace.ts +4 -0
- package/src/test/engine/simState.ts +134 -0
- package/src/test/game/builtProduct.ts +6 -0
- package/src/test/game/headless/admittedProductCache.ts +61 -0
- package/src/test/game/headless/checkedReplayPipeline.ts +21 -0
- package/src/test/game/headless/nativeBounds.ts +27 -0
- package/src/test/game/headless/processUsage.ts +22 -0
- package/src/test/game/headless/productSession.ts +39 -0
- package/src/test/game/headless/ropeBodies.ts +60 -0
- package/src/test/game/headless/worker.ts +34 -0
- package/src/test/game/headlessNative.ts +114 -0
- package/src/test/game/headlessWorker.ts +43 -0
- package/src/test/tsconfig.game.json +3 -0
|
@@ -135,6 +135,10 @@ export class RoadTilePool {
|
|
|
135
135
|
}
|
|
136
136
|
private makeMesh(geometry: BufferGeometry): Mesh<BufferGeometry, Material> {
|
|
137
137
|
const mesh = new Mesh(geometry, this.material); mesh.name = this.name;
|
|
138
|
+
// ZE2d: an empty pool (no resident tile) draws nothing. three links a program in `setProgram` before it reads the
|
|
139
|
+
// draw count, so a drawn empty geometry linked a position-less, flat-shaded variant of the material per lighting state
|
|
140
|
+
// (RP4's retired whole-road mesh, again): 133 to 167 ms a link walking back into Nalati
|
|
141
|
+
mesh.visible = geometry.getAttribute('position') !== undefined;
|
|
138
142
|
mesh.receiveShadow = this.receiveShadow; mesh.renderOrder = this.renderOrder; mesh.castShadow = false;
|
|
139
143
|
mesh.matrixAutoUpdate = false; mesh.updateMatrix(); return mesh;
|
|
140
144
|
}
|
|
@@ -51,7 +51,9 @@ import { WATER_UNBOUNDED, waterExtent } from '@wildshard/engine/world/waves';
|
|
|
51
51
|
import type { Renderer } from '@wildshard/engine/render/renderer';
|
|
52
52
|
import { generatePlatform, generatePlatformSliced, type GeneratedStrip, type PlatformCell, type StripProfile } from '@wildshard/engine/sim/strips';
|
|
53
53
|
import { GridAssembly, type GridCell } from '../../../shared/game/grid/assembly';
|
|
54
|
-
import {
|
|
54
|
+
import { bufferAt, walledCells, zoneWallEdges } from '../../../shared/game/grid/zoneWalls';
|
|
55
|
+
import { GateCount, type GateCountState } from '../../../shared/game/grid/gateCount';
|
|
56
|
+
import { GateCard } from './gateCard';
|
|
55
57
|
import { DEVSERVER, gridMode } from './menu';
|
|
56
58
|
import { gridCells, pageGridInstance } from '../plugin/context';
|
|
57
59
|
import { prepareHomeMetadata, withInitialHomeMetadata } from './homeMetadata';
|
|
@@ -96,7 +98,7 @@ import type { ClientAssets } from '../shardfile/clientAssets';
|
|
|
96
98
|
import { admittedGraphAuthority, clientMaterials } from '../shardfile/clientMaterials';
|
|
97
99
|
import { clientTileViews, type ClientTileViews } from '../shardfile/clientViews';
|
|
98
100
|
import type { ClientSkin } from '../shardfile/clientSkins';
|
|
99
|
-
import { setParkedMatricesFrozen, setWarmUpHeld } from '@wildshard/engine/render/precompile';
|
|
101
|
+
import { exteriorLightingState, setParkedMatricesFrozen, setWarmUpHeld } from '@wildshard/engine/render/precompile';
|
|
100
102
|
import { setBuildHeldTimed } from '@wildshard/engine/core/heldTiming';
|
|
101
103
|
import { setBuildUrgent } from '@wildshard/engine/core/framePacing';
|
|
102
104
|
import { NeighbourLife, type NeighbourLifeCell } from './neighbourLife';
|
|
@@ -114,6 +116,7 @@ import { readCompiledGridStrips } from '../../../shared/game/grid/compiledStrips
|
|
|
114
116
|
import { startRoadGrain } from './roadGrainPreparation';
|
|
115
117
|
import { startRoadSigns } from './roadSignPreparation';
|
|
116
118
|
import { RoadMapShare } from './roadResources';
|
|
119
|
+
import { prepareRoadSurfaceMaps } from './roadCompressedSurfaces';
|
|
117
120
|
import { clientPreparationBatch } from '../shardfile/preparationTiming';
|
|
118
121
|
|
|
119
122
|
import { admittedRuntimeProduct } from '../shardfile/runtimeProduct';
|
|
@@ -162,6 +165,8 @@ export interface GridSessionHost {
|
|
|
162
165
|
/** Presentation-only short range while an actual crossing waits at its
|
|
163
166
|
* in-world screen. Disabled in the same frame the crossing settles. */
|
|
164
167
|
readonly heldFrame?: { enabled: boolean };
|
|
168
|
+
/** ZE8: a gate's count reached 0 for this walled cell (ZE10 opens the loading screen and makes it the home) */
|
|
169
|
+
readonly enterZone?: (instance: string) => void;
|
|
165
170
|
/** Register once per fixed step (the page's one fixed step; never a second loop). */
|
|
166
171
|
readonly onFixed: (fn: (dt: number) => void) => void;
|
|
167
172
|
/** SF19a's one frame: the camera, composer and grade effects, and the page's late phase (absent: never built) */
|
|
@@ -205,6 +210,8 @@ export interface GridSessionState {
|
|
|
205
210
|
readonly seams: SeamLookState;
|
|
206
211
|
/** G85's soft walls: how many edges are closed */
|
|
207
212
|
readonly softWalls: SoftWallState;
|
|
213
|
+
/** ZE8: the buffer the feet stand in and its count (null: none), and the card's text while it shows */
|
|
214
|
+
readonly gate: { readonly cell: string | null; readonly count: number; readonly card: string | null };
|
|
208
215
|
/** G78's border shimmer and G119's save panel (status null: no panel up) */
|
|
209
216
|
readonly shimmer: BorderShimmerState;
|
|
210
217
|
/** G555: the cell whose step-by-step loading screen is open (its entry or re-entry waits), or null */
|
|
@@ -371,11 +378,19 @@ export class GridSession {
|
|
|
371
378
|
private readonly life: NeighbourLife;
|
|
372
379
|
/** Late frames the page loop has run; `stepRingsUntil` steps the rings only while it has not. */
|
|
373
380
|
private lateFrames = 0;
|
|
381
|
+
/** A ring prelink asked before the page drew its first frame: the page's warm-up skips it then (`warmSceneRoots`), so it
|
|
382
|
+
* runs again once the loop has drawn (ZE2d: the home's boot prelink was lost, and the road linked its home-lit variants
|
|
383
|
+
* on the first walk back in). */
|
|
384
|
+
private prelinkOwed = false;
|
|
374
385
|
private readonly admitNeighbour: ((cell: GridCell, required?: boolean) => Promise<void>) | undefined;
|
|
375
386
|
private readonly admitNeighbourRender: ((cell: GridCell) => Promise<boolean>) | undefined;
|
|
376
387
|
/** G222 playtest #7: each neighbour's declared doors and gates, shown exactly when its region has them standing */
|
|
377
388
|
private readonly panels: NeighbourPanels;
|
|
378
389
|
private readonly softWalls: { readonly step: () => void; readonly state: () => SoftWallState };
|
|
390
|
+
/** ZE8: the gate count and its card */
|
|
391
|
+
private readonly gate = new GateCount();
|
|
392
|
+
private gateState: GateCountState = { cell: null, count: 5, fire: null };
|
|
393
|
+
private readonly gateCard: GateCard | null;
|
|
379
394
|
/** G342 / G385: the near-placeholder tier, shipped for everyone: the four nearest cells draw their near view */
|
|
380
395
|
private readonly near: NearPlaceholders;
|
|
381
396
|
private readonly shimmer: { readonly step: () => void; readonly state: () => BorderShimmerState };
|
|
@@ -506,8 +521,11 @@ export class GridSession {
|
|
|
506
521
|
(url, signal) => fetch(url, { signal }), pause, 'outer');
|
|
507
522
|
return compiledOuter?.strips ?? generatePlatformSliced(source.cells, source.empty, pause, OUTER_RING_STRETCH_MS, await seamPlans(), (x, z) => !ring(x, z)); // T10: built in play after controls, short stretches beside the frame
|
|
508
523
|
};
|
|
524
|
+
const maps = new RoadMapShare();
|
|
525
|
+
await waitFor('Grid road surfaces', prepareRoadSurfaceMaps(admission, maps), 'worker');
|
|
526
|
+
if (roadScope.disposed || roadScope.disposing) throw new Error('Grid session left during surface preparation');
|
|
509
527
|
const roadInput = { strips, home, pitch: assembly.pitch, layout, scene: host.scene,
|
|
510
|
-
scope: roadScope, camera: () => host.frame?.camera, plans, admission, tileBacking, maps
|
|
528
|
+
scope: roadScope, camera: () => host.frame?.camera, plans, admission, tileBacking, maps,
|
|
511
529
|
...(grain === undefined ? {} : { grain: grain.get }), ...(signs === undefined ? {} : { signs: signs.get }) };
|
|
512
530
|
const pause = async (): Promise<void> => { await construction.check(); };
|
|
513
531
|
// Spawn heap (T10): no closure here may capture `compiled`. Every closure of this scope shares one context, and the
|
|
@@ -675,16 +693,15 @@ export class GridSession {
|
|
|
675
693
|
// tiles) stays drawn from inside it: the neighbours are the grid's horizon (G321 part 4's fade beyond the cell is gone)
|
|
676
694
|
// SF17b's per-view road budget (§3.2, G101): what the view camera draws of the road system, and what stays resident
|
|
677
695
|
this.roadBudget = { view: () => { const camera = host.frame?.camera; return camera === undefined ? null : roadViewCost(this.roadRoots, camera, this.roadPlans); }, resident: () => roadResident(this.roadRoots, this.roadPlans) };
|
|
678
|
-
// G85: a closed neighbour edge shows as a cyan hex shimmer
|
|
696
|
+
// G85: a closed neighbour edge shows as a cyan hex shimmer; ZE5 (J352): every cell but the home is walled, and its wall shows
|
|
697
|
+
// from wherever it is seen, so the cell behind it reads as there to enter
|
|
679
698
|
this.constructorTiming?.('road');
|
|
680
699
|
this.softWalls = installSoftWallLook({ scene: host.scene, scope: host.scope, time: () => app.clock.now,
|
|
681
|
-
edges: this.
|
|
700
|
+
edges: walledCells(this.assembly, home).flatMap((cell) => zoneWallEdges(cell, home).map((edge) => {
|
|
682
701
|
const look = { instance: cell.instance, x: edge.x, z: edge.z, axis: edge.axis, halfLength: edge.halfLength };
|
|
683
702
|
return cell.edgeLook === undefined ? look : Object.assign(look, { height: cell.edgeLook.height });
|
|
684
703
|
})),
|
|
685
|
-
|
|
686
|
-
ports: { closed: (id) => this.live === null || !this.live.live.ready(id),
|
|
687
|
-
feet: () => { const at = this.world(); return { x: at.x - home.origin.x, z: at.z - home.origin.z }; } } });
|
|
704
|
+
ports: { closed: (id) => this.live === null || !this.live.live.ready(id) } });
|
|
688
705
|
setParkedMatricesFrozen(true); // G580 T2: a hidden parked world skips matrix updates during its warm-up
|
|
689
706
|
host.scope.onDispose(() => { if (host.heldFrame !== undefined) host.heldFrame.enabled = false; setWarmUpHeld(false); setParkedMatricesFrozen(false); setBuildHeldTimed(false); setBuildUrgent(false); });
|
|
690
707
|
// G78: a shimmer line at every shard border on its real ground; G119: SAVING… / SAVE FAILED, RETRY while a crossing waits
|
|
@@ -700,6 +717,7 @@ export class GridSession {
|
|
|
700
717
|
return status;
|
|
701
718
|
},
|
|
702
719
|
text: (shown) => (shown === 'saving' ? GAME_STRINGS.grid.saving : GAME_STRINGS.grid.saveFailed) } });
|
|
720
|
+
this.gateCard = typeof document === 'undefined' ? null : new GateCard(host.scope);
|
|
703
721
|
this.constructorTiming?.('presentation');
|
|
704
722
|
const nativeOrigin = { origin: { x: 0, z: 0 } };
|
|
705
723
|
if (preparedRoad?.collidersInstalled !== true) for (const { mesh } of this.strips) installStripCollider(host.physics, mesh, host.scope);
|
|
@@ -707,7 +725,7 @@ export class GridSession {
|
|
|
707
725
|
withOwner(host.scope, () => installVoidFloor(host.physics, this.assembly.cells, this.assembly.pitch, false));
|
|
708
726
|
// The normal world stage owns the home's sockets; this scope adds only rebased neighbours.
|
|
709
727
|
installEntrySockets(host.physics, host.scope, this.neighbours.map((cell) => ({ x: cell.origin.x - nativeOrigin.origin.x, z: cell.origin.z - nativeOrigin.origin.z })));
|
|
710
|
-
this.walls = new ReadinessWalls(host.physics, [...this.
|
|
728
|
+
this.walls = new ReadinessWalls(host.physics, [...walledCells(this.assembly, home).flatMap((cell) => zoneWallEdges(cell, nativeOrigin)), ...rimEdges(this.assembly, nativeOrigin)], host.scope);
|
|
711
729
|
// a cell's PMREM of a new cube height fading in (drawnEnvironment.ts): the road's views take its variants before it lights
|
|
712
730
|
// them (G639 desktop: Pine's 1024 and Nalati's 512 ring / road variants linked on the first road frame beside each)
|
|
713
731
|
host.scope.onDispose(onPageEnvironment(() => { this.prelinkViews(); }));
|
|
@@ -834,7 +852,7 @@ export class GridSession {
|
|
|
834
852
|
};
|
|
835
853
|
// the one late system (play.ts binds every onLate to game.grid.frame): the ring tiles' static-matrix checks run in it too
|
|
836
854
|
let ringStep: (() => void) | undefined;
|
|
837
|
-
host.frame?.onLate((dt) => { this.lateFrames++; this.viewStep(); this.life.late(dt); this.panels.late(); bands(); frame?.frame(); ringStep?.(); });
|
|
855
|
+
host.frame?.onLate((dt) => { this.lateFrames++; if (this.prelinkOwed && this.lateFrames > 2) { this.prelinkOwed = false; this.prelinkViews(); } this.viewStep(); this.life.late(dt); this.panels.late(); bands(); frame?.frame(); ringStep?.(); });
|
|
838
856
|
const tiles = neighbourTiles(host.scope, async (tile) => { await host.prepareTile?.(tile); },
|
|
839
857
|
(tile, retiredRoots) => { this.tileGhosts.retired(tile.key, retiredRoots); }, host.frame === undefined ? undefined : step => { ringStep = step; }),
|
|
840
858
|
tileCost = clientRingCatalogue(tiles.instances);
|
|
@@ -894,6 +912,9 @@ export class GridSession {
|
|
|
894
912
|
}),
|
|
895
913
|
// the live cell alone, for a sampler that must not build the whole readout four times a second (state() allocates it)
|
|
896
914
|
current: () => (this.live === null ? null : this.live.live.current()),
|
|
915
|
+
// ZE2d: the road's prelink on demand, and the exterior lighting the page scene declares, for the road-lag proof
|
|
916
|
+
prelink: () => { this.prelinkViews(); },
|
|
917
|
+
exterior: () => exteriorLightingState(host.scene),
|
|
897
918
|
}));
|
|
898
919
|
this.constructorTiming?.('streaming');
|
|
899
920
|
}
|
|
@@ -1027,7 +1048,7 @@ export class GridSession {
|
|
|
1027
1048
|
await prepare(cell.instance, owner, start);
|
|
1028
1049
|
} catch (error) { owner.dispose(); throw error; }
|
|
1029
1050
|
} }),
|
|
1030
|
-
neighbourEdges: (cell, origin) =>
|
|
1051
|
+
neighbourEdges: (cell, origin) => zoneWallEdges(cell, { origin }), rimEdges: (origin) => rimEdges(this.assembly, { origin }) }, page);
|
|
1031
1052
|
return this.live;
|
|
1032
1053
|
}
|
|
1033
1054
|
|
|
@@ -1039,6 +1060,7 @@ export class GridSession {
|
|
|
1039
1060
|
private prelinkViews(): void {
|
|
1040
1061
|
const prepare = this.host.prepareView, scope = this.host.scope;
|
|
1041
1062
|
if ((prepare === undefined && this.host.prepareViews === undefined) || scope.disposed || scope.disposing) return;
|
|
1063
|
+
if (this.lateFrames <= 2) this.prelinkOwed = true;
|
|
1042
1064
|
prelinkGridViews(scope, [...this.viewRoots.values(), ...this.roadRoots], prepare, this.host.prepareViews);
|
|
1043
1065
|
// the resident cells' sky domes too, under these lights (each layer was prepared under the lights it was built in)
|
|
1044
1066
|
const skies = this.host.prepareSkyLayers;
|
|
@@ -1078,6 +1100,7 @@ export class GridSession {
|
|
|
1078
1100
|
if (this.assembly.approaching(distance, 400 + Math.min(speed, 60) * 4)) void this.admitNeighbour?.(cell).catch(() => undefined);
|
|
1079
1101
|
}
|
|
1080
1102
|
this.softWalls.step();
|
|
1103
|
+
this.stepGate(at);
|
|
1081
1104
|
if (view) this.viewStep();
|
|
1082
1105
|
const inside = this.assembly.at(at.x, at.z), active = this.live === null ? this.home.instance : this.live.live.current();
|
|
1083
1106
|
// GC2: online, prediction on the rim of a cell the server still walls (C5) is not a departure
|
|
@@ -1088,6 +1111,22 @@ export class GridSession {
|
|
|
1088
1111
|
else if (presence.kind === 'enter') gridCells.enter({ instance: presence.instance, slug: presence.slug });
|
|
1089
1112
|
}
|
|
1090
1113
|
|
|
1114
|
+
/** ZE8: the count while the feet stand in a walled cell's buffer; at 0 that cell's zone entry, once. */
|
|
1115
|
+
private stepGate(at: { x: number; z: number }): void {
|
|
1116
|
+
const buffer = bufferAt(this.assembly.cells, this.home, at);
|
|
1117
|
+
this.gateState = this.gate.step(buffer?.instance ?? null, diagnosticNow());
|
|
1118
|
+
if (this.gateState.fire !== null) this.host.enterZone?.(this.gateState.fire);
|
|
1119
|
+
}
|
|
1120
|
+
private shardName(instance: string): string { const slug = this.assembly.cell(instance).slug; return this.names.get(slug) ?? slug; }
|
|
1121
|
+
private drawGate(at: { x: number; z: number }): void {
|
|
1122
|
+
const card = this.gateCard, { cell } = this.gateState;
|
|
1123
|
+
if (card === null) return;
|
|
1124
|
+
if (cell === null) { card.hide(); return; }
|
|
1125
|
+
const origin = this.assembly.cell(cell).origin, home = this.home.origin;
|
|
1126
|
+
card.show({ centre: { x: origin.x - home.x, z: origin.z - home.z }, feet: { x: at.x - home.x, z: at.z - home.z }, name: this.shardName(cell), count: this.gateState.count },
|
|
1127
|
+
this.host.frame?.camera, innerWidth, innerHeight);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1091
1130
|
/** Tile streaming T5.3 (G775): the entered cell's resident L0 tiles (key j * 8 + i) and its origin from the home cell,
|
|
1092
1131
|
* for the Developer minimap overlay. */
|
|
1093
1132
|
private overlayState: { readonly at: number; readonly state: ReturnType<GridSession['tileOverlayState']> } | null = null;
|
|
@@ -1127,6 +1166,7 @@ export class GridSession {
|
|
|
1127
1166
|
for (const cell of this.neighbours) if (this.placeholderBlocksTiles(cell.instance)) this.rings.retireRefinement(cell.instance);
|
|
1128
1167
|
if (this.host.heldFrame !== undefined) this.host.heldFrame.enabled = false;
|
|
1129
1168
|
this.shimmer.step();
|
|
1169
|
+
this.drawGate(at);
|
|
1130
1170
|
const active = this.live === null ? this.home.instance : this.live.live.current();
|
|
1131
1171
|
const eye = this.host.eye?.();
|
|
1132
1172
|
if (this.host.backgroundReady?.() !== false) this.near.update(eye === undefined || !Number.isFinite(eye.x) || !Number.isFinite(eye.z) ? at : { x: at.x + eye.x, z: at.z + eye.z }, active);
|
|
@@ -1194,7 +1234,7 @@ export class GridSession {
|
|
|
1194
1234
|
pitch: this.assembly.pitch,
|
|
1195
1235
|
home: this.home.instance, inside: gridCells.cell?.instance ?? null, feet: { x: Math.round(at.x * 100) / 100, z: Math.round(at.z * 100) / 100 },
|
|
1196
1236
|
cells: this.assembly.cells.map((cell) => { const d = drawn(cell.instance); return { instance: cell.instance, slug: cell.slug, cell: cell.cell, shows: shows(cell.instance, d), drawn: d }; }),
|
|
1197
|
-
strips: this.strips.length, road: this.road, seams: this.seams, softWalls: this.softWalls.state(), shimmer: this.shimmer.state(), cellLoading: null, cellStage: null, cellStep: null, hybrid: this.live?.hybridState() ?? null, ringsReady: this.rings.ready(), ringsWait: { cells: this.rings.waiting(), far: this.rings.farPlan(), preparation: this.farPreparation(), waits: { count: pending.length, oldest: pending.map(({ label, kind, ageMs }) => ({ label, kind, ageMs })).sort((a, b) => b.ageMs - a.ageMs).slice(0, 16) } },
|
|
1237
|
+
strips: this.strips.length, road: this.road, seams: this.seams, softWalls: this.softWalls.state(), gate: { cell: this.gateState.cell, count: this.gateState.count, card: this.gateCard?.text ?? null }, shimmer: this.shimmer.state(), cellLoading: null, cellStage: null, cellStep: null, hybrid: this.live?.hybridState() ?? null, ringsReady: this.rings.ready(), ringsWait: { cells: this.rings.waiting(), far: this.rings.farPlan(), preparation: this.farPreparation(), waits: { count: pending.length, oldest: pending.map(({ label, kind, ageMs }) => ({ label, kind, ageMs })).sort((a, b) => b.ageMs - a.ageMs).slice(0, 16) } },
|
|
1198
1238
|
residentMB: Math.round(cost.accounted / 1e4) / 100, playingMB: Math.round(cost.playing / 1e4) / 100, envelopeMB: Math.round(this.allocator.envelope() / 1e4) / 100,
|
|
1199
1239
|
accountedBytes: cost.accounted,
|
|
1200
1240
|
rings: { frame: stats.frame, far: stats.resident.far, l1: stats.resident.l1, l0: stats.resident.l0, refused: stats.refused, inFlight: stats.inFlight, queued: stats.queued,
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* GC12 (Jake, 2026-11-13 ~22:50 Cancún, board A): the wall shows only when a player meets a closed edge. A closed wall is drawn
|
|
11
11
|
* while the traveller's feet stand within `MEET_METRES` of it, so a warm crossing (or a wall seen from across the cell) never
|
|
12
12
|
* shows it; the readiness wall itself still holds at every closed edge.
|
|
13
|
+
*
|
|
14
|
+
* ZE5 (J352, Jake 2026-11-15 ~11:02 Cancún: "the wall needs to be this see-through wall like we have right now [...] Like we want
|
|
15
|
+
* people to kind of be enticed to kind of enter and go in"): the zone walls round every cell but the home take this look, and
|
|
16
|
+
* the session passes no `feet`, so a wall shows from wherever it is seen. Past 70 m it eases to a faint line rather than going,
|
|
17
|
+
* so the walls read from across the road while the cell behind stays in view.
|
|
13
18
|
*/
|
|
14
19
|
import { AdditiveBlending, BufferAttribute, BufferGeometry, Color, DoubleSide, DynamicDrawUsage, Group, Mesh, type Object3D, ShaderMaterial } from 'three';
|
|
15
20
|
import type { LookScope } from '../../../shared/game/grid/roadLayout';
|
|
@@ -69,7 +74,7 @@ float hexEdge(vec2 p) {
|
|
|
69
74
|
void main() {
|
|
70
75
|
if (vClosed < 0.5) discard;
|
|
71
76
|
float d = length(vWorld.xz - cameraPosition.xz);
|
|
72
|
-
float near = 1.0 - smoothstep(25.0, 70.0, d);
|
|
77
|
+
float near = mix(0.3, 1.0, 1.0 - smoothstep(25.0, 70.0, d)) * (1.0 - smoothstep(600.0, 1400.0, d));
|
|
73
78
|
if (near <= 0.0) discard;
|
|
74
79
|
float e = hexEdge(vUv);
|
|
75
80
|
float line = 1.0 - smoothstep(0.0, 0.06, e);
|
|
@@ -263,6 +263,9 @@ export class ClientScriptViews {
|
|
|
263
263
|
ports.scope.onDispose(() => { this.dispose(); });
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
/** ZE3a: draw the particles or not (a frozen neighbour's are hidden: their pool's first draw linked its program on the road). */
|
|
267
|
+
show(visible: boolean): void { if (this.pool !== null) this.pool.points.visible = visible; }
|
|
268
|
+
|
|
266
269
|
/** Put every composed view back to the base it had before `apply` (run before the views write their own pose). */
|
|
267
270
|
restore(): void {
|
|
268
271
|
for (const p of this.posed) {
|
|
@@ -4,6 +4,7 @@ import { ownedSave } from '../../../shared/game/saves';
|
|
|
4
4
|
import type { GridSession as DeclarationGridSession } from '../grid/session';
|
|
5
5
|
import { exitSessionToTitle } from './exitToTitle';
|
|
6
6
|
import { initialHomeMetadataRequired } from '../grid/homeMetadata';
|
|
7
|
+
import { enterZone } from '../grid/pageEntry';
|
|
7
8
|
import { timeClientPreparation } from '../shardfile/preparationTiming';
|
|
8
9
|
import type { Physics } from '@wildshard/engine/physics/Physics';
|
|
9
10
|
import type { Audio } from '@wildshard/engine/audio/Audio';
|
|
@@ -176,6 +177,8 @@ async function buildPlay(ctx: Awaited<ReturnType<typeof loadoutStage>>) : Promis
|
|
|
176
177
|
},
|
|
177
178
|
prepareSkyLayers: () => game.warmSkyLayers(),
|
|
178
179
|
...(ctx.session.residency === undefined ? {} : { residency: ctx.session.residency }),
|
|
180
|
+
// ZE10 (J352): a gate's count reached 0: the full loading screen, and that cell becomes the home
|
|
181
|
+
enterZone: (instance) => { enterZone(instance); },
|
|
179
182
|
onFixed: (fn) => { game.onFixed('post', fn, 'game.grid.session'); },
|
|
180
183
|
frame: { prepareDisplay: pass => game.preparePostPass(pass), scene: game.rootScene, camera: game.camera, composer: () => game.composer, post: () => game.post, sunDir: () => game.sky.sunDir, cinematic: () => game.regionCinematic(), slices: () => game.depthSlices,
|
|
181
184
|
// G321: the frame blends the camera's field of view by owner; the shadow cascades follow it
|
|
@@ -54,6 +54,9 @@ export interface PageResidencyBoot {
|
|
|
54
54
|
*/
|
|
55
55
|
/** GC13: the page's playing envelope: the phone tier's 1.0 GB (G65), else the shared caps' */
|
|
56
56
|
export function pagePlayingBytes(tier: Tier = TIER): number { return tier === 'phone' ? PHONE_PLAYING_BYTES : CONTENT_CAPS.playing; }
|
|
57
|
+
/** GC13: the page's loading envelope. A phone has no headroom past G65's 1.0 GB (two worlds on the road peaked at 1.28 GB), so a
|
|
58
|
+
* world is never built beside the one being left: that one goes first. Else the shared caps' loading figure. */
|
|
59
|
+
export function pageLoadingBytes(tier: Tier = TIER): number { return tier === 'phone' ? PHONE_PLAYING_BYTES : CONTENT_CAPS.loading; }
|
|
57
60
|
|
|
58
61
|
export function preparePageResidency(manifest: Pick<ShardManifest, 'slug' | 'shardfile' | 'runtimeCost'>, configuredSlug?: string, memory: MemoryAdmission = new MemoryAdmission(() => MEMORY_GATES.reportOnly || isDev())): PageResidencyBoot {
|
|
59
62
|
const mode = bootPageMode(configuredSlug ?? manifest.slug);
|
|
@@ -61,7 +64,7 @@ export function preparePageResidency(manifest: Pick<ShardManifest, 'slug' | 'sha
|
|
|
61
64
|
if (mode !== 'grid' && (!measuredHome || manifest.runtimeCost === undefined)) return { mode, instance: null, memory };
|
|
62
65
|
const instance = mode === 'grid' ? pageGridInstance() : manifest.slug;
|
|
63
66
|
if (instance === null) throw new Error('Grid residency requires the consumed home instance');
|
|
64
|
-
const residency = new PageResidency(new ResidencyAllocator({ memory, playing: pagePlayingBytes() }));
|
|
67
|
+
const residency = new PageResidency(new ResidencyAllocator({ memory, playing: pagePlayingBytes(), loading: pageLoadingBytes() }));
|
|
65
68
|
try {
|
|
66
69
|
if (measuredHome) {
|
|
67
70
|
if (manifest.runtimeCost === undefined) throw new Error('Grid runtime home requires reviewed memory measurements before bootstrap');
|
|
@@ -104,7 +107,7 @@ function clientSource(admitted: AdmittedProduct, options: ProductOptions, bindin
|
|
|
104
107
|
const sections = outputDescriptor(source)?.sections;
|
|
105
108
|
if (sections !== undefined) prepareClientModuleGroups(source, sections);
|
|
106
109
|
const ownedBindings = { ...bindings,
|
|
107
|
-
...(bindings.allocator === undefined && bindings.residency === undefined && options.memory !== undefined ? { allocator: new ResidencyAllocator({ memory: options.memory, playing: pagePlayingBytes() }) } : {}),
|
|
110
|
+
...(bindings.allocator === undefined && bindings.residency === undefined && options.memory !== undefined ? { allocator: new ResidencyAllocator({ memory: options.memory, playing: pagePlayingBytes(), loading: pageLoadingBytes() }) } : {}),
|
|
108
111
|
...(options.firstParty ? {} : { instance: admitted.instance ?? '' }) };
|
|
109
112
|
const residency = clientResidency(source, ownedBindings);
|
|
110
113
|
const assets = new ClientAssets(source, admitted.assets, options);
|
|
@@ -140,7 +140,7 @@ const onlineLeaving: OnlineLeaving = {
|
|
|
140
140
|
settle: () => { void (async () => { (await import('@wildshard/engine/boot/browserChunkRecovery')).settleRefusedBuild(); })(); },
|
|
141
141
|
};
|
|
142
142
|
interface OnlineModule { readonly startOnline: (config: BuildWorld & { keep: ReleaseKeep; leaving: OnlineLeaving; loaded: string; build: string; identity: (name?: string) => NetIdentity; grid?: { readonly cell: string; readonly cells: readonly string[]; readonly placed: (cell: string, at: { readonly x: number; readonly y: number; readonly z: number; readonly yaw: number }) => void; readonly reenter: (cell: string) => void; readonly goto?: boolean } }) => Promise<Shell> }
|
|
143
|
-
interface Shell { readonly redials?: true; devColliders?: (name: string, boxes: readonly DevBox[]) => void; pause: () => void; hold: (on: boolean) => void; bossGod: () => void; raise: (flag: string) => void; join: (id: string, x: number, y: number, z: number) => { readonly client: NetClient; readonly move: (x: number, y: number, z: number) => void }; readonly client: NetClient; readonly booted: Promise<{ readonly restored: boolean }>; place: (x: number, y: number, z: number, yaw: number) => void; hardHits: (by: number) => void; ready: () => void; leave?: () => Promise<void>; save: () => Promise<{ readonly tick: number; readonly ok: boolean }>; probe: () => Promise<{ readonly tickMs: number }>; dispose: () => void }
|
|
143
|
+
interface Shell { readonly redials?: true; devColliders?: (name: string, boxes: readonly DevBox[]) => void; pause: () => void; hold: (on: boolean) => void; bossGod: () => void; still: () => void; raise: (flag: string) => void; join: (id: string, x: number, y: number, z: number) => { readonly client: NetClient; readonly move: (x: number, y: number, z: number) => void }; readonly client: NetClient; readonly booted: Promise<{ readonly restored: boolean }>; place: (x: number, y: number, z: number, yaw: number) => void; hardHits: (by: number) => void; ready: () => void; leave?: () => Promise<void>; save: () => Promise<{ readonly tick: number; readonly ok: boolean }>; probe: () => Promise<{ readonly tickMs: number }>; dispose: () => void }
|
|
144
144
|
|
|
145
145
|
const SAVE_EVERY_MS = 30_000;
|
|
146
146
|
/** How long the card waits for the server's first rows, and how often it looks. A server that has booted says them in a tick. */
|
|
@@ -188,7 +188,7 @@ function inScene(object: Object3D): boolean {
|
|
|
188
188
|
for (let at: Object3D | null = object; at !== null; at = at.parent) { if (!at.visible) return false; if (at instanceof Scene) return true; }
|
|
189
189
|
return false;
|
|
190
190
|
}
|
|
191
|
-
declare global { interface Window { __onlinePlayers?: () => OtherPlayers['shown']; __workerClientFights?: () => readonly WorkerClientFight[]; __workerClientHits?: (by: number) => void; __workerClientTravel?: (to: ShardSlug) => void;__workerClientSky?: (name: string) => void; __workerClientTime?: (pick: OptionValue<'time'>) => void; __workerClientRow?: (name: string) => number | undefined; __workerClientFlag?: (flag: string) => void; __workerClientDevColliders?: (name: string, boxes: readonly DevBox[]) => void; __workerClientRows?: (kind: string) => readonly { readonly x: number; readonly y: number; readonly z: number }[]; __workerClientGate?: (flag: string) => boolean; __workerClientBot?: (id: string, x: number, y: number, z: number) => { readonly move: (x: number, y: number, z: number) => void; readonly press: (id: string) => void; readonly end: () => void }; __workerClient?: () => WorkerClientReport; __workerClientSave?: () => Promise<void> } }
|
|
191
|
+
declare global { interface Window { __onlinePlayers?: () => OtherPlayers['shown']; __workerClientFights?: () => readonly WorkerClientFight[]; __workerClientHits?: (by: number) => void; __workerClientStill?: () => void; __workerClientTravel?: (to: ShardSlug) => void;__workerClientSky?: (name: string) => void; __workerClientTime?: (pick: OptionValue<'time'>) => void; __workerClientRow?: (name: string) => number | undefined; __workerClientFlag?: (flag: string) => void; __workerClientDevColliders?: (name: string, boxes: readonly DevBox[]) => void; __workerClientRows?: (kind: string) => readonly { readonly x: number; readonly y: number; readonly z: number }[]; __workerClientGate?: (flag: string) => boolean; __workerClientBot?: (id: string, x: number, y: number, z: number) => { readonly move: (x: number, y: number, z: number) => void; readonly press: (id: string) => void; readonly end: () => void }; __workerClient?: () => WorkerClientReport; __workerClientSave?: () => Promise<void> } }
|
|
192
192
|
|
|
193
193
|
/** The page's pose inputs, as acts short enough to go. */
|
|
194
194
|
function poseActs(names: ReadonlySet<string>): readonly string[] {
|
|
@@ -605,6 +605,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
605
605
|
window.__workerClient = () => ({ ...report });
|
|
606
606
|
window.__onlinePlayers = () => others?.shown ?? [];
|
|
607
607
|
window.__workerClientHits = by => { shell.hardHits(by); };
|
|
608
|
+
window.__workerClientStill = () => { shell.still(); };
|
|
608
609
|
window.__workerClientFlag = flag => { shell.raise(flag); };
|
|
609
610
|
// SHARD-SOURCE AP5: the dev hook's `swapColliders` reaches the in-page server here (DEVSERVER only: the define folds it away)
|
|
610
611
|
if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__) window.__workerClientDevColliders = (name, boxes) => { shell.devColliders?.(name, boxes); };
|
|
@@ -13,12 +13,44 @@ import { runtimeProduct } from './runtimeProduct';
|
|
|
13
13
|
import { SharedTileBuilds, type TileContent } from './tileContent';
|
|
14
14
|
import type { ControlRefinement } from './controlRefinement';
|
|
15
15
|
import { tilesSettling } from './tileDriver';
|
|
16
|
+
import { TIER_CONFIG } from '@wildshard/engine/core/tier';
|
|
17
|
+
import { cullSlabRanges, spatialSlabRanges, type SlabRanges } from './slabRanges';
|
|
16
18
|
|
|
17
19
|
type WholeLibrary = Extract<WorldScenesSection['libraries'][number], { kind: 'whole' }>;
|
|
18
20
|
type SlabTile = WorldSceneSlabLibrary['tiles'][number];
|
|
19
21
|
/** the bake's tag on each slab mesh (`sharddev/bake/slabs.ts`): its key, tile and place in its file */
|
|
20
22
|
const SlabTag = v.object({ key: v.string(), tile: v.number(), chunk: v.number() });
|
|
21
23
|
const EMPTY: ReadonlySet<number> = new Set();
|
|
24
|
+
/** NB8: each phone chunk geometry's leaf tree (`slabRanges.ts`): built on a read in play before its first upload; a read
|
|
25
|
+
* under the loader's settle (Nine's whole resident bank, ~0.2 s at CPU x4 on NB1's readyFrame) waits in LATE and is
|
|
26
|
+
* built after the settle, a few chunks a work slice, its reordered index uploaded again */
|
|
27
|
+
const RANGES = new WeakMap<BufferGeometry, SlabRanges>();
|
|
28
|
+
const LATE = new WeakSet<BufferGeometry>();
|
|
29
|
+
const waiting: { readonly part: InstancedMesh; readonly geometry: BufferGeometry; readonly scope: Scope }[] = [];
|
|
30
|
+
let draining = false;
|
|
31
|
+
function slabRuns(part: InstancedMesh, geometry: BufferGeometry, scope: Scope): void {
|
|
32
|
+
const ranges = RANGES.get(geometry);
|
|
33
|
+
if (ranges !== undefined) { cullSlabRanges(part, ranges); return; }
|
|
34
|
+
if (!LATE.has(geometry)) return;
|
|
35
|
+
waiting.push({ part, geometry, scope });
|
|
36
|
+
if (!draining) { draining = true; void drainLate().finally(() => { draining = false; }); }
|
|
37
|
+
}
|
|
38
|
+
async function drainLate(): Promise<void> {
|
|
39
|
+
while (tilesSettling()) await new Promise<void>(resolve => { pageScope.timeout(250, resolve); });
|
|
40
|
+
const slice = workSlice();
|
|
41
|
+
for (let entry = waiting.shift(); entry !== undefined; entry = waiting.shift()) {
|
|
42
|
+
const { part, geometry, scope } = entry;
|
|
43
|
+
if (scope.disposed || scope.disposing) continue;
|
|
44
|
+
let ranges = RANGES.get(geometry);
|
|
45
|
+
if (ranges === undefined && LATE.has(geometry)) {
|
|
46
|
+
LATE.delete(geometry);
|
|
47
|
+
const built = spatialSlabRanges(geometry);
|
|
48
|
+
if (built !== null) { RANGES.set(geometry, built); ranges = built; }
|
|
49
|
+
}
|
|
50
|
+
if (ranges !== undefined) cullSlabRanges(part, ranges);
|
|
51
|
+
if (slice.due()) await slice.yield();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
22
54
|
|
|
23
55
|
function slabMesh(node: Object3D): node is Mesh { return node instanceof Mesh; }
|
|
24
56
|
function materialList(mesh: Mesh): Material[] { return Array.isArray(mesh.material) ? mesh.material : [mesh.material]; }
|
|
@@ -59,6 +91,10 @@ async function readSlabChunks(owner: Scope, product: ShardProduct, tile: number,
|
|
|
59
91
|
const row = file.chunks[index];
|
|
60
92
|
if (row === undefined || tag.chunk !== index || tag.tile !== tile || tag.key !== row.key) throw new Error('Slab chunk differs from its row');
|
|
61
93
|
const geometry = nativeWholeGeometry(mesh, 'take');
|
|
94
|
+
if (TIER_CONFIG.slabRanges) {
|
|
95
|
+
if (tilesSettling()) LATE.add(geometry);
|
|
96
|
+
else { const ranges = spatialSlabRanges(geometry); if (ranges !== null) RANGES.set(geometry, ranges); }
|
|
97
|
+
}
|
|
62
98
|
const [x0, y0, z0, x1, y1, z1] = row.box, [sx, sy, sz, radius] = row.sphere;
|
|
63
99
|
geometry.boundingBox = new Box3(new Vector3(x0, y0, z0), new Vector3(x1, y1, z1));
|
|
64
100
|
geometry.boundingSphere = new Sphere(new Vector3(sx, sy, sz), radius);
|
|
@@ -236,6 +272,7 @@ export class SlabLibrary {
|
|
|
236
272
|
part.name = `${mesh.name}:slab:${String(tile)}:${String(index)}`; part.matrixAutoUpdate = false;
|
|
237
273
|
part.castShadow = key.castShadow; part.receiveShadow = key.receiveShadow; part.renderOrder = key.renderOrder;
|
|
238
274
|
part.layers.mask = key.layers; part.frustumCulled = key.frustumCulled;
|
|
275
|
+
if (key.frustumCulled) slabRuns(part, geometry, scope);
|
|
239
276
|
drawn.push(part); parts.push({ part, anchor: mesh, scope });
|
|
240
277
|
}
|
|
241
278
|
// All keys share one publication cursor. A CPU-budget yield alone can
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { BufferAttribute, type BufferGeometry, type Camera, Frustum, Matrix4, type Object3D, WebGLCoordinateSystem } from 'three';
|
|
2
|
+
import { drawNeutral } from '@wildshard/engine/render/drawNeutral';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* NINE-DRAGON-BENCHMAX NB8: a slab chunk draws only the run of its triangles the camera can see. A resident cell's slab
|
|
6
|
+
* chunk (`sharddev/bake/slabs.ts`) is up to 4 MB of one key in source order, so its bounds span the fragment (Nine's
|
|
7
|
+
* kit chunks reach 190 m) and the object's frustum test keeps nearly every chunk: the phone's spawn view drew 37 of 49
|
|
8
|
+
* chunks, 0.56 M triangles. Splitting chunks in the bake does not pay (NB9: more draws, the spawn view keeps its
|
|
9
|
+
* triangles); ordering each chunk's triangles along a k-d tree of their centroids, then drawing the one contiguous run
|
|
10
|
+
* from its first to its last leaf whose box meets the frustum, cuts triangles with no new draw, no extension, no new
|
|
11
|
+
* program and no change to the shard's bytes. The index is reordered before its first upload; vertices are untouched.
|
|
12
|
+
*/
|
|
13
|
+
export interface SlabRanges {
|
|
14
|
+
/** per node: box min xyz, max xyz in the geometry's own frame */
|
|
15
|
+
readonly boxes: Float32Array;
|
|
16
|
+
/** per node, the root first: left child, right child (-1 for a leaf), first triangle, end triangle */
|
|
17
|
+
readonly nodes: Int32Array;
|
|
18
|
+
readonly triangles: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** triangles per leaf: a leaf's box test costs ~6 plane checks, and 256 triangles of a wall kit is a few metres */
|
|
22
|
+
export const SLAB_LEAF_TRIANGLES = 256;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reorder `geometry`'s index along a k-d tree of its triangles' centroids (each node split at the middle of its longest
|
|
26
|
+
* extent, to leaves of at most `leaf` triangles), before upload, and return that tree; null when the chunk is one leaf
|
|
27
|
+
* (nothing below the object's own test) or has no index or positions. Each level is one linear partition pass.
|
|
28
|
+
*/
|
|
29
|
+
export function spatialSlabRanges(geometry: BufferGeometry, leaf: number = SLAB_LEAF_TRIANGLES): SlabRanges | null {
|
|
30
|
+
const index = geometry.index, position = geometry.getAttribute('position');
|
|
31
|
+
if (index === null || position === undefined || index.count % 3 !== 0) return null;
|
|
32
|
+
const triangles = index.count / 3;
|
|
33
|
+
if (triangles <= leaf) return null;
|
|
34
|
+
const source = index.array, corners = new Uint32Array(source);
|
|
35
|
+
// the bake's positions are plain float32 xyz; any other layout is read through the attribute
|
|
36
|
+
const plain = position instanceof BufferAttribute && position.itemSize === 3 && !position.normalized && position.array instanceof Float32Array;
|
|
37
|
+
const xyz = plain ? position.array : new Float32Array(position.count * 3);
|
|
38
|
+
if (!plain) for (let v = 0; v < position.count; v++) { xyz[v * 3] = position.getX(v); xyz[v * 3 + 1] = position.getY(v); xyz[v * 3 + 2] = position.getZ(v); }
|
|
39
|
+
// centroids (times three) and triangle ids, permuted together so every pass reads front to back
|
|
40
|
+
const cx = new Float32Array(triangles), cy = new Float32Array(triangles), cz = new Float32Array(triangles), order = new Uint32Array(triangles);
|
|
41
|
+
for (let t = 0; t < triangles; t++) {
|
|
42
|
+
const a = (corners[t * 3] ?? 0) * 3, b = (corners[t * 3 + 1] ?? 0) * 3, c = (corners[t * 3 + 2] ?? 0) * 3;
|
|
43
|
+
cx[t] = (xyz[a] ?? 0) + (xyz[b] ?? 0) + (xyz[c] ?? 0); cy[t] = (xyz[a + 1] ?? 0) + (xyz[b + 1] ?? 0) + (xyz[c + 1] ?? 0); cz[t] = (xyz[a + 2] ?? 0) + (xyz[b + 2] ?? 0) + (xyz[c + 2] ?? 0);
|
|
44
|
+
order[t] = t;
|
|
45
|
+
}
|
|
46
|
+
const rows: number[] = [];
|
|
47
|
+
// top-down: a node's row is [left, right, first triangle, end triangle]; the root is node 0, children follow it
|
|
48
|
+
const build = (lo: number, hi: number): number => {
|
|
49
|
+
const node = rows.length / 4; rows.push(-1, -1, lo, hi);
|
|
50
|
+
if (hi - lo <= leaf) return node;
|
|
51
|
+
let x0 = Infinity, y0 = Infinity, z0 = Infinity, x1 = -Infinity, y1 = -Infinity, z1 = -Infinity;
|
|
52
|
+
for (let i = lo; i < hi; i++) {
|
|
53
|
+
const x = cx[i] ?? 0, y = cy[i] ?? 0, z = cz[i] ?? 0;
|
|
54
|
+
if (x < x0) x0 = x; if (y < y0) y0 = y; if (z < z0) z0 = z; if (x > x1) x1 = x; if (y > y1) y1 = y; if (z > z1) z1 = z;
|
|
55
|
+
}
|
|
56
|
+
const ex = x1 - x0, ey = y1 - y0, ez = z1 - z0, key = ex >= ey && ex >= ez ? cx : ey >= ez ? cy : cz;
|
|
57
|
+
const cut = key === cx ? (x0 + x1) / 2 : key === cy ? (y0 + y1) / 2 : (z0 + z1) / 2;
|
|
58
|
+
let i = lo, j = hi - 1;
|
|
59
|
+
while (i <= j) {
|
|
60
|
+
if ((key[i] ?? 0) < cut) { i++; continue; }
|
|
61
|
+
// swap row i with row j and look at the new row i again
|
|
62
|
+
let t: number;
|
|
63
|
+
t = cx[i] ?? 0; cx[i] = cx[j] ?? 0; cx[j] = t; t = cy[i] ?? 0; cy[i] = cy[j] ?? 0; cy[j] = t;
|
|
64
|
+
t = cz[i] ?? 0; cz[i] = cz[j] ?? 0; cz[j] = t; t = order[i] ?? 0; order[i] = order[j] ?? 0; order[j] = t; j--;
|
|
65
|
+
}
|
|
66
|
+
// every centroid on one side of the middle (all equal along the axis): split the run in half as it stands
|
|
67
|
+
const mid = i === lo || i === hi ? (lo + hi) >> 1 : i;
|
|
68
|
+
const left = build(lo, mid), right = build(mid, hi);
|
|
69
|
+
rows[node * 4] = left; rows[node * 4 + 1] = right;
|
|
70
|
+
return node;
|
|
71
|
+
};
|
|
72
|
+
build(0, triangles);
|
|
73
|
+
// the index in its new order, then each leaf's box read front to back, then every parent's (children follow parents)
|
|
74
|
+
for (let t = 0; t < triangles; t++) {
|
|
75
|
+
const from = (order[t] ?? 0) * 3;
|
|
76
|
+
source[t * 3] = corners[from] ?? 0; source[t * 3 + 1] = corners[from + 1] ?? 0; source[t * 3 + 2] = corners[from + 2] ?? 0;
|
|
77
|
+
}
|
|
78
|
+
const nodes = Int32Array.from(rows), count = nodes.length / 4, boxes = new Float32Array(count * 6);
|
|
79
|
+
for (let node = count - 1; node >= 0; node--) {
|
|
80
|
+
const left = nodes[node * 4] ?? -1, right = nodes[node * 4 + 1] ?? -1;
|
|
81
|
+
if (left >= 0) {
|
|
82
|
+
for (let k = 0; k < 3; k++) {
|
|
83
|
+
boxes[node * 6 + k] = Math.min(boxes[left * 6 + k] ?? 0, boxes[right * 6 + k] ?? 0);
|
|
84
|
+
boxes[node * 6 + 3 + k] = Math.max(boxes[left * 6 + 3 + k] ?? 0, boxes[right * 6 + 3 + k] ?? 0);
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
let bx0 = Infinity, by0 = Infinity, bz0 = Infinity, bx1 = -Infinity, by1 = -Infinity, bz1 = -Infinity;
|
|
89
|
+
for (let c = (nodes[node * 4 + 2] ?? 0) * 3, end = (nodes[node * 4 + 3] ?? 0) * 3; c < end; c++) {
|
|
90
|
+
const v = (source[c] ?? 0) * 3, x = xyz[v] ?? 0, y = xyz[v + 1] ?? 0, z = xyz[v + 2] ?? 0;
|
|
91
|
+
if (x < bx0) bx0 = x; if (y < by0) by0 = y; if (z < bz0) bz0 = z; if (x > bx1) bx1 = x; if (y > by1) by1 = y; if (z > bz1) bz1 = z;
|
|
92
|
+
}
|
|
93
|
+
boxes[node * 6] = bx0; boxes[node * 6 + 1] = by0; boxes[node * 6 + 2] = bz0; boxes[node * 6 + 3] = bx1; boxes[node * 6 + 4] = by1; boxes[node * 6 + 5] = bz1;
|
|
94
|
+
}
|
|
95
|
+
index.needsUpdate = true;
|
|
96
|
+
return { boxes, nodes, triangles };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const frustum = new Frustum(), clip = new Matrix4();
|
|
100
|
+
function visible(boxes: Float32Array, node: number): boolean {
|
|
101
|
+
for (const plane of frustum.planes) {
|
|
102
|
+
const { x, y, z } = plane.normal, at = node * 6;
|
|
103
|
+
// the box corner furthest along the plane's normal
|
|
104
|
+
const px = x > 0 ? boxes[at + 3] ?? 0 : boxes[at] ?? 0, py = y > 0 ? boxes[at + 4] ?? 0 : boxes[at + 1] ?? 0, pz = z > 0 ? boxes[at + 5] ?? 0 : boxes[at + 2] ?? 0;
|
|
105
|
+
if (x * px + y * py + z * pz + plane.constant < 0) return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
/** the first visible leaf's first triangle under `node`, or -1 */
|
|
110
|
+
function first(ranges: SlabRanges, node: number): number {
|
|
111
|
+
if (!visible(ranges.boxes, node)) return -1;
|
|
112
|
+
const left = ranges.nodes[node * 4] ?? -1;
|
|
113
|
+
if (left < 0) return ranges.nodes[node * 4 + 2] ?? 0;
|
|
114
|
+
const found = first(ranges, left);
|
|
115
|
+
return found >= 0 ? found : first(ranges, ranges.nodes[node * 4 + 1] ?? 0);
|
|
116
|
+
}
|
|
117
|
+
/** the last visible leaf's end triangle under `node`, or -1 */
|
|
118
|
+
function last(ranges: SlabRanges, node: number): number {
|
|
119
|
+
if (!visible(ranges.boxes, node)) return -1;
|
|
120
|
+
const right = ranges.nodes[node * 4 + 1] ?? -1;
|
|
121
|
+
if (right < 0) return ranges.nodes[node * 4 + 3] ?? 0;
|
|
122
|
+
const found = last(ranges, right);
|
|
123
|
+
return found >= 0 ? found : last(ranges, ranges.nodes[node * 4] ?? 0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The triangle run `[start, end)` of `ranges` that `camera` can see of an object drawn with `world`; when no leaf is in
|
|
127
|
+
* view, the first leaf alone, so a parked warm still issues a real draw and builds its pipeline. */
|
|
128
|
+
export function visibleSlabRun(ranges: SlabRanges, world: Matrix4, camera: Camera): readonly [number, number] {
|
|
129
|
+
clip.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse).multiply(world);
|
|
130
|
+
frustum.setFromProjectionMatrix(clip, WebGLCoordinateSystem, camera.reversedDepth);
|
|
131
|
+
const start = first(ranges, 0);
|
|
132
|
+
if (start < 0) { let node = 0; while ((ranges.nodes[node * 4] ?? -1) >= 0) node = ranges.nodes[node * 4] ?? 0; return [ranges.nodes[node * 4 + 2] ?? 0, ranges.nodes[node * 4 + 3] ?? 0]; }
|
|
133
|
+
return [start, Math.max(start, last(ranges, 0))];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Draw `part` (whose geometry `ranges` was built on) as its visible run for each camera that renders it; the full
|
|
137
|
+
* range is restored after every draw, so shadow passes, warms, raycasts and bounds read the whole chunk. */
|
|
138
|
+
export function cullSlabRanges(part: Object3D & { geometry: BufferGeometry }, ranges: SlabRanges): void {
|
|
139
|
+
const geometry = part.geometry, { start, count } = geometry.drawRange;
|
|
140
|
+
part.onBeforeRender = drawNeutral((_renderer: unknown, _scene: unknown, camera: Camera): void => {
|
|
141
|
+
const [from, to] = visibleSlabRun(ranges, part.matrixWorld, camera);
|
|
142
|
+
geometry.setDrawRange(from * 3, (to - from) * 3);
|
|
143
|
+
});
|
|
144
|
+
part.onAfterRender = drawNeutral((): void => { geometry.setDrawRange(start, count); });
|
|
145
|
+
}
|
|
@@ -80,7 +80,7 @@ export interface OnlineShell {
|
|
|
80
80
|
progress: () => LinkProgress;
|
|
81
81
|
dialNow: () => void;
|
|
82
82
|
why: () => LinkCause;
|
|
83
|
-
pause: () => void; resume: () => void; hold: (on: boolean) => void; bossGod: () => void; hardHits: (by: number) => void;
|
|
83
|
+
pause: () => void; resume: () => void; hold: (on: boolean) => void; bossGod: () => void; still: () => void; hardHits: (by: number) => void;
|
|
84
84
|
place: (x: number, y: number, z: number, yaw: number) => void; raise: (flag: string) => void;
|
|
85
85
|
/** QA row 16: the player chose to go (the menu's exit, another world). The body leaves now, not after J114's hold.
|
|
86
86
|
* Resolves once the door has closed the link; a page waits for it at most `atMostLeaveWait`. */
|
|
@@ -156,7 +156,7 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
|
|
|
156
156
|
const tickOf = (): number => client.latest?.tick ?? 0, idle = (): void => undefined;
|
|
157
157
|
return { client, voice, redials: true, booted, ready: () => { loaded = true; unseated?.control('ready'); unseated = null; },
|
|
158
158
|
visible: hiddenMs => { redial.check(hiddenMs); }, retry: () => { redial.retry(); }, progress: () => redial.progress, why: () => redial.why, dialNow: () => { redial.dialNow(); },
|
|
159
|
-
pause: idle, resume: idle, hold: idle, bossGod: idle, hardHits: idle, place: idle, raise: idle,
|
|
159
|
+
pause: idle, resume: idle, hold: idle, bossGod: idle, still: idle, hardHits: idle, place: idle, raise: idle,
|
|
160
160
|
// The door hears a quit on any link of this build: seated, still admitted, or handed a held body back. A link that is down (a redial's
|
|
161
161
|
// wait) gets a fresh one to say it on, so a held body goes too. No redial follows: the page is going.
|
|
162
162
|
// FL27: a door that heard the quit closes plainly. A link it closed `stalled` was dropped before the quit reached it (it went out
|
|
@@ -11,7 +11,7 @@ import { saveDocuments } from '@wildshard/engine/saves/indexed';
|
|
|
11
11
|
import type { SaveStorage } from '@wildshard/engine/saves/store';
|
|
12
12
|
import { ServerMessageSchema, ShellMessageSchema, type ProbedRow, type ServerMessage, type ShellMessage } from '@wildshard/format/standaloneControl';
|
|
13
13
|
import { answerHeldReads, type HeldRead } from '../../../shared/host/standalone/heldReads';
|
|
14
|
-
import type { HarnessFlag, HarnessGod, HarnessHits, HarnessJoin, HarnessMove, HarnessPlace } from '../../../shared/host/standalone/harnessPlace';
|
|
14
|
+
import type { HarnessFlag, HarnessGod, HarnessHits, HarnessJoin, HarnessMove, HarnessPlace, HarnessStill } from '../../../shared/host/standalone/harnessPlace';
|
|
15
15
|
import type { DevBox, DevCollidersMessage, DevGround, DevGroundMessage } from '@wildshard/engine/game/devColliders';
|
|
16
16
|
import { isDevRestart, type DevGameplay, type DevPlace, type DevRestarted, type DevRestartMessage } from '@wildshard/engine/game/devGameplay';
|
|
17
17
|
import type { ServerWorkerStart } from '../../../server/host/standalone/serverRuntime';
|
|
@@ -70,6 +70,8 @@ export interface StandaloneShell {
|
|
|
70
70
|
hold: (on: boolean) => void;
|
|
71
71
|
/** A Developer's `?bossGod`, for the server that lands a fight's blows. */
|
|
72
72
|
bossGod: () => void;
|
|
73
|
+
/** A golden camera's spectator: every creature in the player's world holds where it is. */
|
|
74
|
+
still: () => void;
|
|
73
75
|
/** A harness's word that one of this player's flags is up. */
|
|
74
76
|
raise: (flag: string) => void;
|
|
75
77
|
/** A proof's second client, a real one on its own link: it stands at this point in this cell, and `move` puts its body elsewhere. */
|
|
@@ -173,6 +175,7 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
|
|
|
173
175
|
place: (x, y, z, yaw) => { harness?.postMessage({ x, y, z, yaw } satisfies HarnessPlace, []); },
|
|
174
176
|
hardHits: by => { harness?.postMessage({ hits: by } satisfies HarnessHits, []); },
|
|
175
177
|
bossGod: () => { harness?.postMessage({ god: true } satisfies HarnessGod, []); },
|
|
178
|
+
still: () => { harness?.postMessage({ still: true } satisfies HarnessStill, []); },
|
|
176
179
|
raise: flag => { harness?.postMessage({ flag } satisfies HarnessFlag, []); },
|
|
177
180
|
devColliders: (name, boxes) => { if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__) harness?.postMessage({ wildshardDevColliders: name, boxes } satisfies DevCollidersMessage, []); },
|
|
178
181
|
devRestart,
|