@wildshard/engine 0.1.22 → 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 +15 -0
- package/index.html +17 -4
- package/lint/engine-sides.json +9 -0
- package/lint/sim-players.json +2 -13
- package/package.json +36 -3
- package/scripts/apfs-clone.mjs +5 -2
- package/scripts/app-build/catalogue.ts +39 -8
- package/scripts/app-build/serviceWorker.ts +4 -1
- package/scripts/app-build/splitOutput.mjs +33 -11
- 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/ci-pack.mjs +3 -3
- package/scripts/engine-ci-shard.mjs +11 -0
- package/scripts/fight-page-census.mjs +131 -0
- package/scripts/goldens/board.py +44 -11
- package/scripts/goldens/capture.mjs +18 -6
- package/scripts/goldens/native-residency.d.mts +2 -0
- package/scripts/goldens/native-residency.mjs +31 -4
- package/scripts/grid-road-lag.mjs +209 -0
- package/scripts/keep-copy.mjs +172 -0
- package/scripts/land.d.mts +4 -1
- package/scripts/land.mjs +121 -9
- package/scripts/lane-live.mjs +136 -0
- package/scripts/leftovers-report.mjs +47 -0
- package/scripts/loading-card-proof.mjs +42 -9
- package/scripts/loading-flow/benchmax.mjs +59 -7
- package/scripts/loading-flow/stalls.d.mts +2 -0
- package/scripts/loading-flow/stalls.mjs +13 -0
- package/scripts/map-hash.mjs +1 -1
- package/scripts/mmo-bots.mjs +5 -3
- package/scripts/mmo-grid-proof.mjs +74 -0
- package/scripts/mmo-seat-proof.mjs +43 -0
- package/scripts/nightly-heads.ts +13 -13
- package/scripts/nightly-model.ts +26 -12
- package/scripts/nightly-tag.mjs +2 -4
- package/scripts/nightly.proof.ts +18 -5
- package/scripts/nightly.ts +13 -8
- package/scripts/no-astc-boot.mjs +77 -0
- 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/physics-route.json +6 -6
- package/scripts/pins-reuse.mjs +1 -0
- package/scripts/pins-staging.ts +54 -0
- package/scripts/pins.ts +5 -0
- package/scripts/ring3.proof.ts +71 -0
- package/scripts/ring3.ts +100 -0
- package/scripts/road-drive-proof.mjs +269 -0
- package/scripts/road-memory-probe.mjs +129 -0
- package/scripts/scratch-dir.mjs +33 -14
- package/scripts/scratch-sweep.mjs +15 -23
- package/scripts/server-release/github.mjs +59 -26
- package/scripts/server-release/items.d.mts +7 -0
- package/scripts/server-release/items.mjs +28 -0
- package/scripts/server-release/publish.mjs +24 -2
- package/scripts/server-release/sign.mjs +8 -4
- package/scripts/side-parity.mjs +1 -1
- package/scripts/test-products.json +1 -0
- package/scripts/test_prebuilt_output.py +3 -1
- package/scripts/tsconfig.json +2 -0
- 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/vitest-ci-files.ts +5 -1
- package/scripts/vps/rebuild.sh +3 -1
- package/scripts/vps/wildshard-config +106 -1
- package/scripts/warm-native-chrome.mjs +9 -3
- package/scripts/worker-client-fights.mjs +9 -3
- package/scripts/worktree-reap.mjs +36 -140
- package/scripts/worktree.mjs +92 -12
- package/scripts/zone-gate-proof.mjs +93 -0
- package/src/client/engine/audio/audioLog.ts +7 -2
- package/src/client/engine/boot/diagnostics.ts +69 -1
- package/src/client/engine/boot/sw.ts +3 -1
- package/src/client/engine/core/ktx2.ts +33 -10
- package/src/client/engine/core/ktx2Zstd.ts +2 -1
- package/src/client/engine/models/place.ts +7 -5
- package/src/client/engine/pwa/sw.js +83 -10
- package/src/client/engine/render/dataLook.ts +14 -7
- package/src/client/engine/render/lookLight.ts +64 -20
- package/src/client/engine/render/precompile.ts +6 -0
- package/src/client/engine/render/tiers.ts +9 -0
- package/src/client/engine/ui/Loading.ts +6 -8
- package/src/client/engine/ui/lookLightOption.ts +1 -1
- package/src/client/engine/ui/playerReload.ts +5 -5
- package/src/client/game/audio/cueDirector.ts +2 -1
- package/src/client/game/boot/bytes.generated.ts +4 -1
- package/src/client/game/boot/versions.generated.ts +8 -5
- package/src/client/game/boss/arenaRoom.ts +4 -3
- package/src/client/game/boss/roamingProjection.ts +1 -1
- package/src/client/game/devScene/hook.ts +1 -1
- package/src/client/game/devScene/liveLook.ts +1 -1
- package/src/client/game/grid/cellClip.ts +70 -6
- package/src/client/game/grid/dataCellKit.ts +9 -1
- 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/products.ts +21 -7
- 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 +58 -16
- package/src/client/game/grid/softWallLook.ts +6 -1
- package/src/client/game/plugin/ui.ts +3 -0
- package/src/client/game/population/signals.ts +1 -1
- package/src/client/game/quest/chapterDirector.ts +1 -0
- package/src/client/game/session/play.ts +3 -0
- package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
- package/src/client/game/shardfile/clientSource.ts +5 -2
- package/src/client/game/shardfile/clientWorker.ts +25 -8
- package/src/client/game/shardfile/look.ts +1 -1
- package/src/client/game/shardfile/runtimeProduct.ts +9 -5
- package/src/client/game/shardfile/slabLibrary.ts +37 -0
- package/src/client/game/shardfile/slabRanges.ts +145 -0
- package/src/client/game/shardfile/wirePage.ts +5 -2
- package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
- package/src/client/host/online/shell.ts +2 -2
- package/src/client/host/standalone/shell.ts +4 -1
- package/src/cook/game/cookWorker.ts +8 -5
- package/src/cook/game/tierTextures.ts +5 -3
- package/src/server/engine/net/simWorld.ts +3 -4
- package/src/server/game/grid/cellHome.ts +58 -0
- package/src/server/game/grid/simulation.ts +32 -8
- package/src/server/game/plugin/mover.ts +18 -14
- package/src/server/game/plugin/simulation.ts +2 -0
- package/src/server/game/shardfile/dataRespawn.ts +47 -0
- package/src/server/game/shardfile/declaredKitItems.ts +31 -7
- package/src/server/host/bake/headlessWorker.ts +3 -3
- package/src/server/host/dedicated/cellWorker.ts +4 -2
- package/src/server/host/dedicated/main.ts +7 -4
- package/src/server/host/dedicated/packReader.ts +15 -2
- package/src/server/host/dedicated/playerStore.ts +1 -1
- package/src/server/host/headlessRuntime.ts +11 -6
- package/src/server/host/standalone/cellWorld.ts +20 -6
- package/src/server/host/standalone/gridServer.ts +20 -6
- package/src/server/host/standalone/roadWorld.ts +36 -0
- package/src/server/host/standalone/serverHost.ts +2 -2
- package/src/shared/engine/entities/AnimalSim.ts +10 -0
- package/src/shared/engine/physics/gridBorders.ts +15 -1
- package/src/shared/engine/physics/transferWalls.ts +9 -4
- package/src/shared/engine/sim/snapshot.ts +5 -5
- 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/ledger.ts +13 -4
- package/src/shared/game/loot/platformCatalogue.ts +14 -0
- package/src/shared/game/quest/ledger.ts +3 -3
- package/src/shared/game/shardfile/items.ts +9 -1
- package/src/shared/game/strings.ts +2 -0
- package/src/shared/host/headlessJourney.ts +3 -3
- package/src/shared/host/headlessTape.ts +7 -6
- package/src/shared/host/releaseRows.ts +4 -1
- 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
|
@@ -179,24 +179,38 @@ export function gridShardfileFarBytes(slug: string): Promise<number | null> | nu
|
|
|
179
179
|
* GLB), look/look (the haze colour) and world/collision sections, and the far files, each hash-verified, without admitting
|
|
180
180
|
* the whole product first (its admission, ~8-20 s a product at 4x CPU, held every shardfile neighbour's far proxy and so the
|
|
181
181
|
* grid reveal's ringsReady). No residency claim: the far ring's own lease charges the proxy. Null when the slug has no
|
|
182
|
-
* shardfile or no mesh-collision world (its far proxy is the baked folder's)
|
|
182
|
+
* shardfile or no mesh-collision world (its far proxy is the baked folder's), unless `anyWorld` (no baked folder): then
|
|
183
|
+
* null only when the product's tiles carry no far row.
|
|
183
184
|
*/
|
|
184
|
-
export function readGridShardfileFar(slug: string): Promise<GridShardfileFar | null> {
|
|
185
|
+
export function readGridShardfileFar(slug: string, anyWorld = false): Promise<GridShardfileFar | null> {
|
|
185
186
|
const descriptor = findShard(slug)?.shardfile;
|
|
186
187
|
if (descriptor === undefined) return Promise.resolve(null);
|
|
187
188
|
const url = new URL(descriptor, location.href);
|
|
188
|
-
return readGridProductFar(url.href, slug, browserShardfileOptions(new URL('.', url).href, true));
|
|
189
|
+
return readGridProductFar(url.href, slug, browserShardfileOptions(new URL('.', url).href, true), anyWorld);
|
|
189
190
|
}
|
|
190
191
|
/** A shardfile far proxy's rows and a verified reader for its declared far files. */
|
|
191
192
|
export interface GridShardfileFar { readonly rows: ShardfileFarRows; readonly read: (ref: string) => Promise<Uint8Array> }
|
|
192
|
-
/** `readGridShardfileFar` for one product URL (null: no mesh-collision world, so its far proxy is the baked folder's).
|
|
193
|
-
|
|
193
|
+
/** `readGridShardfileFar` for one product URL (null: no mesh-collision world, unless `anyWorld`, so its far proxy is the baked folder's).
|
|
194
|
+
* `anyWorld`: the build baked no far folder for this slug, so any world's own far row is read (TEMPLATE-E2E: Brasscap rev 5
|
|
195
|
+
* has no mesh collision and no repo bake; null then only when its tiles carry no far row). */
|
|
196
|
+
export async function readGridProductFar(url: string, identity: string, options: ProductOptions, anyWorld = false): Promise<GridShardfileFar | null> {
|
|
194
197
|
const at = await readGridProductIndex(url, identity, options);
|
|
195
198
|
const collision = await readGridSection(at, 'world/collision');
|
|
196
|
-
|
|
199
|
+
const mesh = collision !== null && v.parse(farRows.collision, collision).meshCollision !== null;
|
|
200
|
+
if (!mesh && !anyWorld) return null;
|
|
197
201
|
const [tiles, props, look] = await Promise.all([readGridSection(at, 'world/tiles'), readGridSection(at, 'world/props'), readGridSection(at, 'look/look')]);
|
|
198
202
|
const fog = look === null ? null : v.parse(farRows.look, look).look.keys[0]?.fog.colour ?? null;
|
|
199
|
-
const
|
|
203
|
+
const far = tiles === null ? null : v.parse(farRows.tiles, tiles).far;
|
|
204
|
+
const declared = props === null ? null : v.parse(farRows.props, props).props?.far ?? null;
|
|
205
|
+
const isGlb = (ref: string): boolean => {
|
|
206
|
+
const hash = ref.replace(/^commons:/u, ''), commons = ref.startsWith('commons:');
|
|
207
|
+
return at.index.files.some(row => row.hash === hash && (row.commons === true) === commons && row.kind === 'glb');
|
|
208
|
+
};
|
|
209
|
+
// A mesh-collision world keeps its rows as they are. Any other world (a scene upload) has no props row naming its far GLB,
|
|
210
|
+
// so it is the first far file the index lists as a GLB; with none, its far proxy is the baked folder's after all.
|
|
211
|
+
const farRef = declared ?? (mesh || far === null ? null : far.files.find(isGlb) ?? null);
|
|
212
|
+
if (!mesh && (far === null || farRef === null)) return null;
|
|
213
|
+
const rows: ShardfileFarRows = { far, farRef, fog };
|
|
200
214
|
const read = (ref: string): Promise<Uint8Array> => {
|
|
201
215
|
const hash = ref.replace(/^commons:/u, ''), commons = ref.startsWith('commons:');
|
|
202
216
|
const file = at.index.files.find(row => row.hash === hash && (row.commons === true) === commons);
|
|
@@ -533,6 +533,11 @@ export function createRegionalWorldFoundation(ports: RegionalWorldPorts): (reque
|
|
|
533
533
|
const animals = frame.run(app, () => new RowBodies(new AnimalHerdView(scene, sky, { physics: host.physics }), app, host.physics));
|
|
534
534
|
await animals.build(ports.pause, frame);
|
|
535
535
|
if (left()) throw new Error('Regional world left while building creatures');
|
|
536
|
+
// ZE2d (DL24 on the grid): one hidden rig of every model a row can bring, parked in this region's scene, so its
|
|
537
|
+
// warm-up builds the programs its creatures draw with: the region's look patch and its own factory's bodies. The
|
|
538
|
+
// page's warm rigs sit outside the region (no `|look:`, another factory's hulls): Driftwood's glowing creature
|
|
539
|
+
// linked 149 to 198 ms on the first walk back in from the road, Pine's wildlife three programs
|
|
540
|
+
frame.run(app, () => { animals.stageWarmRigs(); });
|
|
536
541
|
return { animals, wearSkin: (equipment: EquipmentService, skin: SkinDef): void => {
|
|
537
542
|
const model = equipment.get(skin.weapon).model;
|
|
538
543
|
if (model instanceof Group) applySkin(model, skin, sky);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {type CompressedTexture, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, RGBA_ASTC_6x6_Format, SRGBColorSpace} from 'three';
|
|
2
|
+
import {TIER} from '@wildshard/engine/core/tier';
|
|
3
|
+
import {contentURL} from '@wildshard/engine/boot/contentBase';
|
|
4
|
+
import {nativeCompressedFormatSupported} from '@wildshard/engine/core/ktx2';
|
|
5
|
+
import {ROAD_GRAIN_PLANES} from './roadGrain';
|
|
6
|
+
import {PlatformRenderAdmissionError, type PlatformRenderAdmission} from './renderResidency';
|
|
7
|
+
import type {RoadMapShare} from './roadResources';
|
|
8
|
+
|
|
9
|
+
const KINDS = ['asphalt', 'junction'] as const;
|
|
10
|
+
const IDS = {asphalt: 'road.asphalt', junction: 'road.junctions'} as const;
|
|
11
|
+
/** Native ASTC must have sampled correctly at every mip; unsupported phones keep the procedural maps. */
|
|
12
|
+
export function compressedRoadSupport(tier: string, nativeSupported: boolean): boolean {
|
|
13
|
+
return tier === 'phone' && nativeSupported;
|
|
14
|
+
}
|
|
15
|
+
/** Exact ASTC 6x6 allocation, including the small padded levels at the end of the chain. */
|
|
16
|
+
export function roadSurfaceBytes(width: number, height: number): number {
|
|
17
|
+
let bytes = 0;
|
|
18
|
+
for (let w = width, h = height; ; w = Math.max(1, w >> 1), h = Math.max(1, h >> 1)) {
|
|
19
|
+
bytes += Math.ceil(w / 6) * Math.ceil(h / 6) * 16;
|
|
20
|
+
if (w === 1 && h === 1) return bytes;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
interface SurfaceLoader {
|
|
24
|
+
readonly supported?: boolean;
|
|
25
|
+
readonly read?: (url: string, signal: AbortSignal) => Promise<CompressedTexture>;
|
|
26
|
+
readonly upload?: (texture: CompressedTexture, current: () => boolean) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Admit the pair before loading, publish both atomically, and retain one counted owner across road halves. */
|
|
30
|
+
export async function prepareRoadSurfaceMaps(admission: PlatformRenderAdmission, maps: RoadMapShare, loader: SurfaceLoader = {}): Promise<boolean> {
|
|
31
|
+
if (!(loader.supported ?? compressedRoadSupport(TIER, nativeCompressedFormatSupported('SRGB8_ALPHA8_ASTC_6x6'))) || KINDS.some(kind => maps.has(IDS[kind]))) return false;
|
|
32
|
+
const gpuBytes = KINDS.reduce((bytes, kind) => bytes + roadSurfaceBytes(ROAD_GRAIN_PLANES[kind].width, ROAD_GRAIN_PLANES[kind].height), 0);
|
|
33
|
+
let owner;
|
|
34
|
+
try { owner = admission.allocate({id: 'road.surface-maps', jsBytes: gpuBytes, gpuBytes}, scope => scope); }
|
|
35
|
+
catch (error) { if (error instanceof PlatformRenderAdmissionError) return false; throw error; }
|
|
36
|
+
const textures = new Map<string, CompressedTexture>();
|
|
37
|
+
const controller = new AbortController(), loading = owner.child('surface-loading');
|
|
38
|
+
const retired = new Promise<false>(resolve => { owner.onDispose(() => { controller.abort(); resolve(false); }); });
|
|
39
|
+
loading.timeout(5000, () => { owner.dispose(); });
|
|
40
|
+
let shared = false;
|
|
41
|
+
owner.onDispose(() => { for (const [id, texture] of textures) { if (shared) maps.release(id, texture); else texture.dispose(); } });
|
|
42
|
+
const read = loader.read ?? (async (url: string, signal: AbortSignal) => (await import('@wildshard/engine/core/ktx2')).ktx2File(url, signal));
|
|
43
|
+
const upload = loader.upload ?? (async (texture: CompressedTexture, current: () => boolean): Promise<void> => {
|
|
44
|
+
await (await import('@wildshard/engine/core/ktx2')).prepareCompressedTexture(texture, undefined, current);
|
|
45
|
+
});
|
|
46
|
+
try {
|
|
47
|
+
const results = await Promise.race([retired, Promise.allSettled(KINDS.map(async kind => {
|
|
48
|
+
const texture = await read(contentURL(`/assets/grid-road/road-${kind}-phone.ktx2`), controller.signal);
|
|
49
|
+
if (owner.disposed || owner.disposing) { texture.dispose(); throw new Error('Road surface owner retired'); }
|
|
50
|
+
textures.set(IDS[kind], texture);
|
|
51
|
+
const image: unknown = texture.image, expected = ROAD_GRAIN_PLANES[kind];
|
|
52
|
+
if (texture.format !== RGBA_ASTC_6x6_Format || texture.colorSpace !== SRGBColorSpace || typeof image !== 'object' || image === null
|
|
53
|
+
|| Reflect.get(image, 'width') !== expected.width || Reflect.get(image, 'height') !== expected.height
|
|
54
|
+
|| texture.mipmaps.length !== 11 || texture.mipmaps.reduce((bytes, mip) => bytes + mip.data.byteLength, 0) !== roadSurfaceBytes(expected.width, expected.height)) {
|
|
55
|
+
throw new Error('Road surface texture differs from its admitted format');
|
|
56
|
+
}
|
|
57
|
+
if (kind === 'asphalt') { texture.wrapS = RepeatWrapping; texture.wrapT = RepeatWrapping; }
|
|
58
|
+
texture.anisotropy = 8; texture.minFilter = LinearMipmapLinearFilter; texture.magFilter = LinearFilter;
|
|
59
|
+
texture.needsUpdate = true;
|
|
60
|
+
await upload(texture, () => !owner.disposed && !owner.disposing);
|
|
61
|
+
}))]);
|
|
62
|
+
if (results === false || results.some(result => result.status === 'rejected') || owner.disposed || owner.disposing) { owner.dispose(); return false; }
|
|
63
|
+
for (const [id, texture] of textures) maps.hold(id, texture);
|
|
64
|
+
shared = true;
|
|
65
|
+
admission.shrink?.('road.surface-maps', gpuBytes);
|
|
66
|
+
return true;
|
|
67
|
+
} catch (error) { owner.dispose(); throw error; }
|
|
68
|
+
finally { loading.dispose(); }
|
|
69
|
+
}
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* The layout is `roadLayout.ts`; sign text comes from the catalogue's slugs through the shard registry.
|
|
9
9
|
*/
|
|
10
10
|
import {
|
|
11
|
-
BufferAttribute, BufferGeometry,
|
|
12
|
-
MeshLambertMaterial, NoColorSpace, type Object3D, Quaternion,
|
|
11
|
+
BufferAttribute, BufferGeometry, Color, DataTexture, Group, LinearFilter, LinearMipmapLinearFilter, Matrix4, Mesh,
|
|
12
|
+
MeshLambertMaterial, NoColorSpace, type Object3D, Quaternion, RGFormat, type Texture, UnsignedByteType, Vector3,
|
|
13
13
|
} from 'three';
|
|
14
14
|
import type { GridCell } from '../../../shared/game/grid/assembly';
|
|
15
|
-
import {
|
|
15
|
+
import type { RoadGrainSource } from './roadGrain';
|
|
16
|
+
import { junctionTextureSteps, roadTextureSteps, ROAD_PERIOD, WHITE } from './roadSurfaceMaps';
|
|
16
17
|
import { packRoadSignPixels } from './roadSignPixels';
|
|
17
18
|
import { paintRoadSignCanvas, roadSignPaintLayout, roadSignLineKey as lineKey, SIGN_LINE_W as LINE_W, SIGN_LINE_H as LINE_H, type RoadSignSource } from './roadSignPaint';
|
|
18
19
|
import { ownRoadMesh, type RoadMapShare } from './roadResources';
|
|
@@ -95,7 +96,7 @@ export class RoadOverlayLight {
|
|
|
95
96
|
export interface RoadLookState { readonly segments: number; readonly junctions: number; readonly roundabouts: number; readonly signs: number; readonly lights: number; readonly draws: number }
|
|
96
97
|
|
|
97
98
|
const LIFT = 0.02; // the overlay's height over the deck's road band (polygon offset does the rest)
|
|
98
|
-
const
|
|
99
|
+
const KERB = new Color(0x9a9c98), ISLAND = new Color(0x4f6a35), SIGN_GREEN = '#0d6b3c';
|
|
99
100
|
|
|
100
101
|
/** A tiny triangle builder: positions, normals, uvs, colours, one index buffer. */
|
|
101
102
|
class Mesher {
|
|
@@ -148,75 +149,6 @@ function canvas(w: number, h: number): { el: HTMLCanvasElement; g: CanvasRenderi
|
|
|
148
149
|
const g = el.getContext('2d'); if (g === null) throw new Error('No 2D canvas for the road look');
|
|
149
150
|
return { el, g };
|
|
150
151
|
}
|
|
151
|
-
function texture(el: HTMLCanvasElement, repeat: boolean): CanvasTexture {
|
|
152
|
-
const t = new CanvasTexture(el); t.colorSpace = SRGBColorSpace; t.anisotropy = 8; t.minFilter = LinearMipmapLinearFilter;
|
|
153
|
-
if (repeat) { t.wrapS = RepeatWrapping; t.wrapT = RepeatWrapping; }
|
|
154
|
-
return t;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** The road canvas: u [0, 0.5) the normal section, [0.5, 1) the turn-in section; v one 12 m period of dashes. */
|
|
158
|
-
const ROAD_PERIOD = 12;
|
|
159
|
-
function* roadTextureSteps(grain?: RoadGrainSource): Generator<void, CanvasTexture> {
|
|
160
|
-
const W = 1024, H = 512, { el, g } = canvas(W, H);
|
|
161
|
-
const plane = grain?.('asphalt');
|
|
162
|
-
if (plane === undefined) yield* roadGrainSteps(g, W, H, 1); else putRoadGrain(g, 'asphalt', plane);
|
|
163
|
-
const half = W / 2, px = (t: number, base: number): number => base + (t + ROAD_HALF) / (2 * ROAD_HALF) * half, pm = half / (2 * ROAD_HALF);
|
|
164
|
-
for (const base of [0, half]) {
|
|
165
|
-
const turnIn = base > 0;
|
|
166
|
-
// wheel paths: faint darker wear in each lane
|
|
167
|
-
g.fillStyle = 'rgba(20,22,26,0.07)';
|
|
168
|
-
for (const t of [-5.9, -4.3, -2.6, -1.0, 1.0, 2.6, 4.3, 5.9]) g.fillRect(px(t, base) - 0.45 * pm, 0, 0.9 * pm, H);
|
|
169
|
-
g.fillStyle = YELLOW; // the double yellow centre line (G80)
|
|
170
|
-
for (const t of [-0.17, 0.17]) g.fillRect(px(t, base) - 0.06 * pm, 0, 0.12 * pm, H);
|
|
171
|
-
g.fillStyle = WHITE; // lane dividers: 3 m dash in a 12 m period
|
|
172
|
-
for (const t of [-3.55, 3.55]) g.fillRect(px(t, base) - 0.06 * pm, 0, 0.12 * pm, H * 3 / ROAD_PERIOD);
|
|
173
|
-
for (const t of [-7.0, 7.0]) { // edge lines; at a turn-in, short dashes so the opening reads
|
|
174
|
-
if (!turnIn) g.fillRect(px(t, base) - 0.075 * pm, 0, 0.15 * pm, H);
|
|
175
|
-
else for (let k = 0; k < 6; k++) g.fillRect(px(t, base) - 0.075 * pm, k * H / 6, 0.15 * pm, H / 12);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return texture(el, true);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** The junction canvas: 62.5 m square; the roundabout's markings in the middle, plain asphalt in the corners. */
|
|
182
|
-
function* junctionTextureSteps(grain?: RoadGrainSource): Generator<void, CanvasTexture> {
|
|
183
|
-
const W = 1024, { el, g } = canvas(W, W), k = W / (2 * GAP_HALF);
|
|
184
|
-
const plane = grain?.('junction');
|
|
185
|
-
if (plane === undefined) yield* roadGrainSteps(g, W, W, 2); else putRoadGrain(g, 'junction', plane);
|
|
186
|
-
const P = (x: number, z: number): [number, number] => [(x + GAP_HALF) * k, (GAP_HALF - z) * k];
|
|
187
|
-
const arc = (r: number, a0: number, a1: number, width: number, colour: string, dash?: readonly [number, number]): void => {
|
|
188
|
-
g.strokeStyle = colour; g.lineWidth = width * k; g.setLineDash(dash === undefined ? [] : [dash[0] * k, dash[1] * k]);
|
|
189
|
-
const [cx, cy] = P(0, 0); g.beginPath(); g.arc(cx, cy, r * k, -a1, -a0); g.stroke(); g.setLineDash([]);
|
|
190
|
-
};
|
|
191
|
-
const open = Math.asin((ROAD_HALF + 0.3) / (RING_OUTER - 0.5));
|
|
192
|
-
for (let q = 0; q < 4; q++) arc(RING_OUTER - 0.5, q * Math.PI / 2 + open, (q + 1) * Math.PI / 2 - open, 0.15, WHITE); // outer edge line between the arms
|
|
193
|
-
arc(RING_ISLAND + 0.45, 0, Math.PI * 2, 0.15, WHITE); // inner edge line
|
|
194
|
-
arc((RING_ISLAND + RING_OUTER) / 2, 0, Math.PI * 2, 0.12, WHITE, [3, 3]); // the circulating lane divider
|
|
195
|
-
const sides: readonly { x: number; z: number }[] = [{ x: 1, z: 0 }, { x: 0, z: 1 }, { x: -1, z: 0 }, { x: 0, z: -1 }];
|
|
196
|
-
for (const d of sides) {
|
|
197
|
-
const rx = -d.z, rz = d.x; // the across unit
|
|
198
|
-
const line = (t: number, r0: number, r1: number, width: number, colour: string, dash = 0): void => {
|
|
199
|
-
g.fillStyle = colour;
|
|
200
|
-
for (let r = r0; r < r1; r += dash > 0 ? dash * 4 : r1 - r0) {
|
|
201
|
-
const e = Math.min(r1, r + (dash > 0 ? dash : r1 - r0)), [ax, ay] = P(d.x * r + rx * (t - width / 2), d.z * r + rz * (t - width / 2)), [bx, by] = P(d.x * e + rx * (t + width / 2), d.z * e + rz * (t + width / 2));
|
|
202
|
-
g.fillRect(Math.min(ax, bx), Math.min(ay, by), Math.abs(bx - ax), Math.abs(by - ay));
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
for (const t of [-0.17, 0.17]) line(t, RING_OUTER + 3, GAP_HALF, 0.12, YELLOW);
|
|
206
|
-
for (const t of [-3.55, 3.55]) line(t, RING_OUTER + 3, GAP_HALF, 0.12, WHITE, 3);
|
|
207
|
-
for (const t of [-7.0, 7.0]) line(t, RING_OUTER + 0.5, GAP_HALF, 0.15, WHITE);
|
|
208
|
-
// give way: the entry half is on the inbound traveller's right (three's mirrored frame: −across), dashed, a triangle per lane
|
|
209
|
-
const entry = -1;
|
|
210
|
-
for (let t = 0.4; t < 6.9; t += 0.9) line(entry * (t + 0.3), RING_OUTER + 0.9, RING_OUTER + 1.2, 0.6, WHITE);
|
|
211
|
-
for (const t of [1.8, 5.3]) {
|
|
212
|
-
const tip = RING_OUTER + 2.2, base = tip + 2.6, [ax, ay] = P(d.x * tip + rx * t * entry, d.z * tip + rz * t * entry);
|
|
213
|
-
const [bx, by] = P(d.x * base + rx * (t * entry + 0.7), d.z * base + rz * (t * entry + 0.7)), [cx, cy] = P(d.x * base + rx * (t * entry - 0.7), d.z * base + rz * (t * entry - 0.7));
|
|
214
|
-
g.strokeStyle = WHITE; g.lineWidth = 0.15 * k; g.beginPath(); g.moveTo(ax, ay); g.lineTo(bx, by); g.lineTo(cx, cy); g.closePath(); g.stroke();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return texture(el, false);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
152
|
/** The asphalt over every segment: three quads each (the middle one the turn-in section), UVs into the road canvas. */
|
|
221
153
|
function asphalt(layout: RoadLayout, home: GridCell): Mesher {
|
|
222
154
|
const m = new Mesher();
|
|
@@ -14,7 +14,7 @@ import type { RoadSignSource } from './roadSignPaint';
|
|
|
14
14
|
* before the deck's and the boulevard's claims and dropped after; the curtain's split arrays become its geometry without a
|
|
15
15
|
* copy (they are counted in `road.curtain`).
|
|
16
16
|
*/
|
|
17
|
-
import { Mesh, type Camera, type Object3D } from 'three';
|
|
17
|
+
import { DataArrayTexture, Mesh, type Camera, type Object3D } from 'three';
|
|
18
18
|
import { CONTENT_CAPS } from '@wildshard/engine/core/config';
|
|
19
19
|
import { ownRoadMesh, type RoadMapShare } from './roadResources';
|
|
20
20
|
import type { RoadTileBacking } from './roadTileBacking';
|
|
@@ -57,7 +57,7 @@ export interface PlatformRoadInput {
|
|
|
57
57
|
readonly within?: (x: number, z: number) => boolean;
|
|
58
58
|
/** build the void floor and its rail (default true; one build of a split road draws it) */
|
|
59
59
|
readonly voidFloor?: boolean;
|
|
60
|
-
/** PZ24: one asphalt and
|
|
60
|
+
/** PZ24: one asphalt, junction and deck-grain upload for every build of this road (a split road's halves pass the same share) */
|
|
61
61
|
readonly maps?: RoadMapShare;
|
|
62
62
|
}
|
|
63
63
|
/** The readouts and the roots the road budget measures. */
|
|
@@ -162,18 +162,23 @@ function* platformRoadSteps(input: PlatformRoadInput): Generator<void, PlatformR
|
|
|
162
162
|
const meshes: Mesh[] = [];
|
|
163
163
|
yield;
|
|
164
164
|
const deckBytes = yield* meshBytesSteps(parts.map(solidSource), SOLID_FLOATS, { pitch, ...(tileSize === undefined ? {} : { tileSize }), lod: ROAD_LOD }, true);
|
|
165
|
-
const
|
|
165
|
+
const maps = input.maps, grainId = 'road.deck-grain';
|
|
166
|
+
const grainBytes = maps?.has(grainId) === true ? { jsBytes: 0, gpuBytes: 0 } : gpuOnlyTextureBytes(GRAIN_SIZE, GRAIN_SIZE, GRAIN_LAYERS.length, 'data');
|
|
166
167
|
const deckAdmission = bytePlan('road.deck', deckBytes, grainBytes);
|
|
167
168
|
const builtDeck = yield* allocateRenderSteps(admission, deckAdmission, function* buildDeck(owner) {
|
|
168
169
|
yield;
|
|
169
|
-
const
|
|
170
|
+
const held = maps?.take(grainId);
|
|
171
|
+
if (held !== undefined && !(held instanceof DataArrayTexture)) throw new Error('Road deck grain must be an array texture');
|
|
172
|
+
const grain = held ?? grainArray({ gravel, stone, strata, riprap }), material = solidMaterial(grain);
|
|
173
|
+
if (maps !== undefined && held === undefined) maps.hold(grainId, grain);
|
|
170
174
|
yield;
|
|
171
175
|
const deck = new Mesh(yield* solidGeometrySteps(parts), material);
|
|
172
|
-
ownRoadMesh(owner, deck, [grain]);
|
|
176
|
+
ownRoadMesh(owner, deck, maps === undefined ? [grain] : []);
|
|
177
|
+
if (maps !== undefined) owner.onDispose(() => { maps.release(grainId, grain); });
|
|
173
178
|
deck.name = 'grid-deck'; deck.receiveShadow = true;
|
|
174
179
|
deck.castShadow = false; deck.matrixAutoUpdate = false; deck.updateMatrix();
|
|
175
180
|
yield* cullIntoSteps(culler, deck, ROAD_LOD); scene.add(deck); meshes.push(deck);
|
|
176
|
-
gpuOnlyRoad(deck, [grain]); // G144: admitted, its JS copies go on upload (the plan counts them gone)
|
|
181
|
+
gpuOnlyRoad(deck, held === undefined ? [grain] : []); // G144: admitted, its JS copies go on upload (the plan counts them gone)
|
|
177
182
|
return deck;
|
|
178
183
|
});
|
|
179
184
|
if (builtDeck === undefined) throw new Error('Road construction cancelled');
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** The unchanged procedural road painters, shared by runtime fallback and the reproducible phone bake. */
|
|
2
|
+
import {CanvasTexture, LinearMipmapLinearFilter, RepeatWrapping, SRGBColorSpace} from 'three';
|
|
3
|
+
import {GAP_HALF, RING_ISLAND, RING_OUTER, ROAD_HALF} from '../../../shared/game/grid/roadLayout';
|
|
4
|
+
import {putRoadGrain, roadGrainSteps, type RoadGrainSource} from './roadGrain';
|
|
5
|
+
|
|
6
|
+
export const WHITE = '#e9ebe6';
|
|
7
|
+
const YELLOW = '#e0b23a';
|
|
8
|
+
function canvas(w: number, h: number): {el: HTMLCanvasElement; g: CanvasRenderingContext2D} {
|
|
9
|
+
const el = document.createElement('canvas'); el.width = w; el.height = h;
|
|
10
|
+
const g = el.getContext('2d'); if (g === null) throw new Error('No 2D canvas for the road look');
|
|
11
|
+
return {el, g};
|
|
12
|
+
}
|
|
13
|
+
function texture(el: HTMLCanvasElement, repeat: boolean): CanvasTexture {
|
|
14
|
+
const t = new CanvasTexture(el); t.colorSpace = SRGBColorSpace; t.anisotropy = 8; t.minFilter = LinearMipmapLinearFilter;
|
|
15
|
+
if (repeat) { t.wrapS = RepeatWrapping; t.wrapT = RepeatWrapping; }
|
|
16
|
+
return t;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The road canvas: u [0, 0.5) the normal section, [0.5, 1) the turn-in section; v one 12 m period of dashes. */
|
|
20
|
+
export const ROAD_PERIOD = 12;
|
|
21
|
+
export function* roadTextureSteps(grain?: RoadGrainSource): Generator<void, CanvasTexture> {
|
|
22
|
+
const W = 1024, H = 512, { el, g } = canvas(W, H);
|
|
23
|
+
const plane = grain?.('asphalt');
|
|
24
|
+
if (plane === undefined) yield* roadGrainSteps(g, W, H, 1); else putRoadGrain(g, 'asphalt', plane);
|
|
25
|
+
const half = W / 2, px = (t: number, base: number): number => base + (t + ROAD_HALF) / (2 * ROAD_HALF) * half, pm = half / (2 * ROAD_HALF);
|
|
26
|
+
for (const base of [0, half]) {
|
|
27
|
+
const turnIn = base > 0;
|
|
28
|
+
// wheel paths: faint darker wear in each lane
|
|
29
|
+
g.fillStyle = 'rgba(20,22,26,0.07)';
|
|
30
|
+
for (const t of [-5.9, -4.3, -2.6, -1.0, 1.0, 2.6, 4.3, 5.9]) g.fillRect(px(t, base) - 0.45 * pm, 0, 0.9 * pm, H);
|
|
31
|
+
g.fillStyle = YELLOW; // the double yellow centre line (G80)
|
|
32
|
+
for (const t of [-0.17, 0.17]) g.fillRect(px(t, base) - 0.06 * pm, 0, 0.12 * pm, H);
|
|
33
|
+
g.fillStyle = WHITE; // lane dividers: 3 m dash in a 12 m period
|
|
34
|
+
for (const t of [-3.55, 3.55]) g.fillRect(px(t, base) - 0.06 * pm, 0, 0.12 * pm, H * 3 / ROAD_PERIOD);
|
|
35
|
+
for (const t of [-7.0, 7.0]) { // edge lines; at a turn-in, short dashes so the opening reads
|
|
36
|
+
if (!turnIn) g.fillRect(px(t, base) - 0.075 * pm, 0, 0.15 * pm, H);
|
|
37
|
+
else for (let k = 0; k < 6; k++) g.fillRect(px(t, base) - 0.075 * pm, k * H / 6, 0.15 * pm, H / 12);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return texture(el, true);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The junction canvas: 62.5 m square; the roundabout's markings in the middle, plain asphalt in the corners. */
|
|
44
|
+
export function* junctionTextureSteps(grain?: RoadGrainSource): Generator<void, CanvasTexture> {
|
|
45
|
+
const W = 1024, { el, g } = canvas(W, W), k = W / (2 * GAP_HALF);
|
|
46
|
+
const plane = grain?.('junction');
|
|
47
|
+
if (plane === undefined) yield* roadGrainSteps(g, W, W, 2); else putRoadGrain(g, 'junction', plane);
|
|
48
|
+
const P = (x: number, z: number): [number, number] => [(x + GAP_HALF) * k, (GAP_HALF - z) * k];
|
|
49
|
+
const arc = (r: number, a0: number, a1: number, width: number, colour: string, dash?: readonly [number, number]): void => {
|
|
50
|
+
g.strokeStyle = colour; g.lineWidth = width * k; g.setLineDash(dash === undefined ? [] : [dash[0] * k, dash[1] * k]);
|
|
51
|
+
const [cx, cy] = P(0, 0); g.beginPath(); g.arc(cx, cy, r * k, -a1, -a0); g.stroke(); g.setLineDash([]);
|
|
52
|
+
};
|
|
53
|
+
const open = Math.asin((ROAD_HALF + 0.3) / (RING_OUTER - 0.5));
|
|
54
|
+
for (let q = 0; q < 4; q++) arc(RING_OUTER - 0.5, q * Math.PI / 2 + open, (q + 1) * Math.PI / 2 - open, 0.15, WHITE); // outer edge line between the arms
|
|
55
|
+
arc(RING_ISLAND + 0.45, 0, Math.PI * 2, 0.15, WHITE); // inner edge line
|
|
56
|
+
arc((RING_ISLAND + RING_OUTER) / 2, 0, Math.PI * 2, 0.12, WHITE, [3, 3]); // the circulating lane divider
|
|
57
|
+
const sides: readonly { x: number; z: number }[] = [{ x: 1, z: 0 }, { x: 0, z: 1 }, { x: -1, z: 0 }, { x: 0, z: -1 }];
|
|
58
|
+
for (const d of sides) {
|
|
59
|
+
const rx = -d.z, rz = d.x; // the across unit
|
|
60
|
+
const line = (t: number, r0: number, r1: number, width: number, colour: string, dash = 0): void => {
|
|
61
|
+
g.fillStyle = colour;
|
|
62
|
+
for (let r = r0; r < r1; r += dash > 0 ? dash * 4 : r1 - r0) {
|
|
63
|
+
const e = Math.min(r1, r + (dash > 0 ? dash : r1 - r0)), [ax, ay] = P(d.x * r + rx * (t - width / 2), d.z * r + rz * (t - width / 2)), [bx, by] = P(d.x * e + rx * (t + width / 2), d.z * e + rz * (t + width / 2));
|
|
64
|
+
g.fillRect(Math.min(ax, bx), Math.min(ay, by), Math.abs(bx - ax), Math.abs(by - ay));
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
for (const t of [-0.17, 0.17]) line(t, RING_OUTER + 3, GAP_HALF, 0.12, YELLOW);
|
|
68
|
+
for (const t of [-3.55, 3.55]) line(t, RING_OUTER + 3, GAP_HALF, 0.12, WHITE, 3);
|
|
69
|
+
for (const t of [-7.0, 7.0]) line(t, RING_OUTER + 0.5, GAP_HALF, 0.15, WHITE);
|
|
70
|
+
// give way: the entry half is on the inbound traveller's right (three's mirrored frame: −across), dashed, a triangle per lane
|
|
71
|
+
const entry = -1;
|
|
72
|
+
for (let t = 0.4; t < 6.9; t += 0.9) line(entry * (t + 0.3), RING_OUTER + 0.9, RING_OUTER + 1.2, 0.6, WHITE);
|
|
73
|
+
for (const t of [1.8, 5.3]) {
|
|
74
|
+
const tip = RING_OUTER + 2.2, base = tip + 2.6, [ax, ay] = P(d.x * tip + rx * t * entry, d.z * tip + rz * t * entry);
|
|
75
|
+
const [bx, by] = P(d.x * base + rx * (t * entry + 0.7), d.z * base + rz * (t * entry + 0.7)), [cx, cy] = P(d.x * base + rx * (t * entry - 0.7), d.z * base + rz * (t * entry - 0.7));
|
|
76
|
+
g.strokeStyle = WHITE; g.lineWidth = 0.15 * k; g.beginPath(); g.moveTo(ax, ay); g.lineTo(bx, by); g.lineTo(cx, cy); g.closePath(); g.stroke();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return texture(el, false);
|
|
80
|
+
}
|
|
@@ -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';
|
|
@@ -157,11 +160,13 @@ export interface GridSessionHost {
|
|
|
157
160
|
readonly physics: Physics;
|
|
158
161
|
readonly scope: Scope;
|
|
159
162
|
readonly feet: () => { readonly x: number; readonly y: number; readonly z: number };
|
|
160
|
-
/**
|
|
163
|
+
/** Only home coverage can load before controls; every neighbour read waits for this boundary. */
|
|
161
164
|
readonly backgroundReady?: () => boolean;
|
|
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 */
|
|
@@ -248,7 +255,8 @@ function neighbourTiles(scope: Scope, prepare: (tile: PreparedRingTile) => Promi
|
|
|
248
255
|
async function loadFar(slug: string): Promise<{ prepared: FarPrepared; bytes: number }> {
|
|
249
256
|
// Pure authored projects have no repo bake: their proxy comes from their product's sections and far files (O26: read
|
|
250
257
|
// hash-verified on their own, not after admitting the whole product), instead of a nonexistent far.json
|
|
251
|
-
|
|
258
|
+
// a slug the build baked no far for (an upload with no mesh collision) reads its product's far row whatever its world
|
|
259
|
+
const shardfile = await readGridShardfileFar(slug, publicBytes()[`/assets/baked/${slug}/far.json`] === undefined);
|
|
252
260
|
if (shardfile !== null) return loadShardfileFar(shardfile.rows, shardfile.read);
|
|
253
261
|
const response = await fetch(versionedUrl(`/assets/baked/${slug}/far.json`));
|
|
254
262
|
if (!response.ok) throw new Error(`far.json ${slug}: ${String(response.status)}`);
|
|
@@ -370,11 +378,19 @@ export class GridSession {
|
|
|
370
378
|
private readonly life: NeighbourLife;
|
|
371
379
|
/** Late frames the page loop has run; `stepRingsUntil` steps the rings only while it has not. */
|
|
372
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;
|
|
373
385
|
private readonly admitNeighbour: ((cell: GridCell, required?: boolean) => Promise<void>) | undefined;
|
|
374
386
|
private readonly admitNeighbourRender: ((cell: GridCell) => Promise<boolean>) | undefined;
|
|
375
387
|
/** G222 playtest #7: each neighbour's declared doors and gates, shown exactly when its region has them standing */
|
|
376
388
|
private readonly panels: NeighbourPanels;
|
|
377
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;
|
|
378
394
|
/** G342 / G385: the near-placeholder tier, shipped for everyone: the four nearest cells draw their near view */
|
|
379
395
|
private readonly near: NearPlaceholders;
|
|
380
396
|
private readonly shimmer: { readonly step: () => void; readonly state: () => BorderShimmerState };
|
|
@@ -505,8 +521,11 @@ export class GridSession {
|
|
|
505
521
|
(url, signal) => fetch(url, { signal }), pause, 'outer');
|
|
506
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
|
|
507
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');
|
|
508
527
|
const roadInput = { strips, home, pitch: assembly.pitch, layout, scene: host.scene,
|
|
509
|
-
scope: roadScope, camera: () => host.frame?.camera, plans, admission, tileBacking, maps
|
|
528
|
+
scope: roadScope, camera: () => host.frame?.camera, plans, admission, tileBacking, maps,
|
|
510
529
|
...(grain === undefined ? {} : { grain: grain.get }), ...(signs === undefined ? {} : { signs: signs.get }) };
|
|
511
530
|
const pause = async (): Promise<void> => { await construction.check(); };
|
|
512
531
|
// Spawn heap (T10): no closure here may capture `compiled`. Every closure of this scope shares one context, and the
|
|
@@ -596,8 +615,9 @@ export class GridSession {
|
|
|
596
615
|
const home = this.home;
|
|
597
616
|
// the root world is neutral highway physics and the home an owned region like every cell, so every cell is a neighbour
|
|
598
617
|
this.neighbours = [...this.assembly.cells];
|
|
599
|
-
|
|
600
|
-
|
|
618
|
+
// NB12: the eight adjacent cells used to compete with home for downloads
|
|
619
|
+
// and GLTF decodes. The home's own coverage is the only boot exception.
|
|
620
|
+
const initialRing = new Set([home.instance]);
|
|
601
621
|
const backgroundReady = (): boolean => host.backgroundReady?.() !== false;
|
|
602
622
|
// ringsReady: the far ring charges each proxy its declared bytes before it loads, not the 1.6 MB cap, so placeholder
|
|
603
623
|
// charges never leave a visible cell out of the ring (12 visible proxies of 0.4-1.6 MB fit its 14.4 MB)
|
|
@@ -673,16 +693,15 @@ export class GridSession {
|
|
|
673
693
|
// tiles) stays drawn from inside it: the neighbours are the grid's horizon (G321 part 4's fade beyond the cell is gone)
|
|
674
694
|
// SF17b's per-view road budget (§3.2, G101): what the view camera draws of the road system, and what stays resident
|
|
675
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) };
|
|
676
|
-
// 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
|
|
677
698
|
this.constructorTiming?.('road');
|
|
678
699
|
this.softWalls = installSoftWallLook({ scene: host.scene, scope: host.scope, time: () => app.clock.now,
|
|
679
|
-
edges: this.
|
|
700
|
+
edges: walledCells(this.assembly, home).flatMap((cell) => zoneWallEdges(cell, home).map((edge) => {
|
|
680
701
|
const look = { instance: cell.instance, x: edge.x, z: edge.z, axis: edge.axis, halfLength: edge.halfLength };
|
|
681
702
|
return cell.edgeLook === undefined ? look : Object.assign(look, { height: cell.edgeLook.height });
|
|
682
703
|
})),
|
|
683
|
-
|
|
684
|
-
ports: { closed: (id) => this.live === null || !this.live.live.ready(id),
|
|
685
|
-
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) } });
|
|
686
705
|
setParkedMatricesFrozen(true); // G580 T2: a hidden parked world skips matrix updates during its warm-up
|
|
687
706
|
host.scope.onDispose(() => { if (host.heldFrame !== undefined) host.heldFrame.enabled = false; setWarmUpHeld(false); setParkedMatricesFrozen(false); setBuildHeldTimed(false); setBuildUrgent(false); });
|
|
688
707
|
// G78: a shimmer line at every shard border on its real ground; G119: SAVING… / SAVE FAILED, RETRY while a crossing waits
|
|
@@ -698,6 +717,7 @@ export class GridSession {
|
|
|
698
717
|
return status;
|
|
699
718
|
},
|
|
700
719
|
text: (shown) => (shown === 'saving' ? GAME_STRINGS.grid.saving : GAME_STRINGS.grid.saveFailed) } });
|
|
720
|
+
this.gateCard = typeof document === 'undefined' ? null : new GateCard(host.scope);
|
|
701
721
|
this.constructorTiming?.('presentation');
|
|
702
722
|
const nativeOrigin = { origin: { x: 0, z: 0 } };
|
|
703
723
|
if (preparedRoad?.collidersInstalled !== true) for (const { mesh } of this.strips) installStripCollider(host.physics, mesh, host.scope);
|
|
@@ -705,7 +725,7 @@ export class GridSession {
|
|
|
705
725
|
withOwner(host.scope, () => installVoidFloor(host.physics, this.assembly.cells, this.assembly.pitch, false));
|
|
706
726
|
// The normal world stage owns the home's sockets; this scope adds only rebased neighbours.
|
|
707
727
|
installEntrySockets(host.physics, host.scope, this.neighbours.map((cell) => ({ x: cell.origin.x - nativeOrigin.origin.x, z: cell.origin.z - nativeOrigin.origin.z })));
|
|
708
|
-
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);
|
|
709
729
|
// a cell's PMREM of a new cube height fading in (drawnEnvironment.ts): the road's views take its variants before it lights
|
|
710
730
|
// them (G639 desktop: Pine's 1024 and Nalati's 512 ring / road variants linked on the first road frame beside each)
|
|
711
731
|
host.scope.onDispose(onPageEnvironment(() => { this.prelinkViews(); }));
|
|
@@ -832,7 +852,7 @@ export class GridSession {
|
|
|
832
852
|
};
|
|
833
853
|
// the one late system (play.ts binds every onLate to game.grid.frame): the ring tiles' static-matrix checks run in it too
|
|
834
854
|
let ringStep: (() => void) | undefined;
|
|
835
|
-
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?.(); });
|
|
836
856
|
const tiles = neighbourTiles(host.scope, async (tile) => { await host.prepareTile?.(tile); },
|
|
837
857
|
(tile, retiredRoots) => { this.tileGhosts.retired(tile.key, retiredRoots); }, host.frame === undefined ? undefined : step => { ringStep = step; }),
|
|
838
858
|
tileCost = clientRingCatalogue(tiles.instances);
|
|
@@ -892,6 +912,9 @@ export class GridSession {
|
|
|
892
912
|
}),
|
|
893
913
|
// the live cell alone, for a sampler that must not build the whole readout four times a second (state() allocates it)
|
|
894
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),
|
|
895
918
|
}));
|
|
896
919
|
this.constructorTiming?.('streaming');
|
|
897
920
|
}
|
|
@@ -1025,7 +1048,7 @@ export class GridSession {
|
|
|
1025
1048
|
await prepare(cell.instance, owner, start);
|
|
1026
1049
|
} catch (error) { owner.dispose(); throw error; }
|
|
1027
1050
|
} }),
|
|
1028
|
-
neighbourEdges: (cell, origin) =>
|
|
1051
|
+
neighbourEdges: (cell, origin) => zoneWallEdges(cell, { origin }), rimEdges: (origin) => rimEdges(this.assembly, { origin }) }, page);
|
|
1029
1052
|
return this.live;
|
|
1030
1053
|
}
|
|
1031
1054
|
|
|
@@ -1037,6 +1060,7 @@ export class GridSession {
|
|
|
1037
1060
|
private prelinkViews(): void {
|
|
1038
1061
|
const prepare = this.host.prepareView, scope = this.host.scope;
|
|
1039
1062
|
if ((prepare === undefined && this.host.prepareViews === undefined) || scope.disposed || scope.disposing) return;
|
|
1063
|
+
if (this.lateFrames <= 2) this.prelinkOwed = true;
|
|
1040
1064
|
prelinkGridViews(scope, [...this.viewRoots.values(), ...this.roadRoots], prepare, this.host.prepareViews);
|
|
1041
1065
|
// the resident cells' sky domes too, under these lights (each layer was prepared under the lights it was built in)
|
|
1042
1066
|
const skies = this.host.prepareSkyLayers;
|
|
@@ -1076,6 +1100,7 @@ export class GridSession {
|
|
|
1076
1100
|
if (this.assembly.approaching(distance, 400 + Math.min(speed, 60) * 4)) void this.admitNeighbour?.(cell).catch(() => undefined);
|
|
1077
1101
|
}
|
|
1078
1102
|
this.softWalls.step();
|
|
1103
|
+
this.stepGate(at);
|
|
1079
1104
|
if (view) this.viewStep();
|
|
1080
1105
|
const inside = this.assembly.at(at.x, at.z), active = this.live === null ? this.home.instance : this.live.live.current();
|
|
1081
1106
|
// GC2: online, prediction on the rim of a cell the server still walls (C5) is not a departure
|
|
@@ -1086,6 +1111,22 @@ export class GridSession {
|
|
|
1086
1111
|
else if (presence.kind === 'enter') gridCells.enter({ instance: presence.instance, slug: presence.slug });
|
|
1087
1112
|
}
|
|
1088
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
|
+
|
|
1089
1130
|
/** Tile streaming T5.3 (G775): the entered cell's resident L0 tiles (key j * 8 + i) and its origin from the home cell,
|
|
1090
1131
|
* for the Developer minimap overlay. */
|
|
1091
1132
|
private overlayState: { readonly at: number; readonly state: ReturnType<GridSession['tileOverlayState']> } | null = null;
|
|
@@ -1125,6 +1166,7 @@ export class GridSession {
|
|
|
1125
1166
|
for (const cell of this.neighbours) if (this.placeholderBlocksTiles(cell.instance)) this.rings.retireRefinement(cell.instance);
|
|
1126
1167
|
if (this.host.heldFrame !== undefined) this.host.heldFrame.enabled = false;
|
|
1127
1168
|
this.shimmer.step();
|
|
1169
|
+
this.drawGate(at);
|
|
1128
1170
|
const active = this.live === null ? this.home.instance : this.live.live.current();
|
|
1129
1171
|
const eye = this.host.eye?.();
|
|
1130
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);
|
|
@@ -1192,7 +1234,7 @@ export class GridSession {
|
|
|
1192
1234
|
pitch: this.assembly.pitch,
|
|
1193
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 },
|
|
1194
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 }; }),
|
|
1195
|
-
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) } },
|
|
1196
1238
|
residentMB: Math.round(cost.accounted / 1e4) / 100, playingMB: Math.round(cost.playing / 1e4) / 100, envelopeMB: Math.round(this.allocator.envelope() / 1e4) / 100,
|
|
1197
1239
|
accountedBytes: cost.accounted,
|
|
1198
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);
|