@wildshard/engine 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +21 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/no-base64.mjs +3 -1
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/lint/shard-imports.mjs +6 -7
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +22 -23
- package/package.json +25 -16
- package/scripts/agent-sync.mjs +27 -8
- package/scripts/app-build/appCook.ts +8 -2
- package/scripts/app-build/catalogue.ts +10 -7
- package/scripts/app-build/gen.ts +22 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +35 -0
- package/scripts/app-build/previousDeploy.d.mts +2 -0
- package/scripts/app-build/previousDeploy.mjs +10 -1
- package/scripts/app-build/serviceWorker.ts +10 -3
- package/scripts/app-build/splitOutput.mjs +4 -2
- package/scripts/app-build/standaloneOutput.d.mts +1 -1
- package/scripts/app-build/standaloneOutput.mjs +5 -3
- package/scripts/app-build/titlePreloads.d.mts +8 -0
- package/scripts/app-build/titlePreloads.mjs +69 -0
- package/scripts/app-build/worldMapAtlas.ts +10 -6
- package/scripts/app-build-pipeline.mjs +34 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +81 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +3 -1
- package/scripts/check-models.mjs +2 -0
- package/scripts/check-paths.allow.json +0 -115
- package/scripts/check-paths.mjs +2 -2
- package/scripts/check-platform-ratchets.mjs +2 -3
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.d.mts +1 -1
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/ci-static.sh +1 -1
- package/scripts/committed-fast-checks.mjs +0 -2
- package/scripts/content-sw-proof.mjs +2 -1
- package/scripts/cook-worker.mjs +9 -3
- package/scripts/cook.mjs +20 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +4 -2
- package/scripts/devserver-client.mjs +25 -8
- package/scripts/docs-inputs-proof.mjs +6 -6
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/e7-voice-staging-proof.mjs +1 -1
- package/scripts/gate-related-tests.mjs +1 -1
- package/scripts/git-source-view.mjs +1 -1
- package/scripts/goldens/capture.mjs +17 -5
- package/scripts/grid-crossing-nightly.mjs +59 -0
- package/scripts/grid-crossing-qa.mjs +44 -0
- package/scripts/grid-crossing-ratchet.d.mts +6 -0
- package/scripts/grid-crossing-ratchet.mjs +52 -0
- package/scripts/grid-crossing-report.mjs +122 -0
- package/scripts/grid-crossing-stages.mjs +47 -0
- package/scripts/grid-crossing-tour.mjs +277 -0
- package/scripts/grid-crossing-walk-proof.mjs +136 -18
- package/scripts/host-ruler/roots.mjs +2 -2
- package/scripts/host-ruler.d.mts +91 -0
- package/scripts/host-ruler.mjs +565 -0
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +3 -1
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +213 -0
- package/scripts/mmo-bots.mjs +8 -2
- package/scripts/net-lag-proof.mjs +219 -0
- package/scripts/night-market-kit-budget.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +5 -3
- package/scripts/offline-proof-rules.mjs +34 -7
- package/scripts/offline-proof.mjs +88 -18
- package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
- package/scripts/page-release/content.d.mts +9 -1
- package/scripts/page-release/content.mjs +131 -17
- package/scripts/page-release/flow.mjs +36 -10
- package/scripts/page-release/stamp-content.mjs +24 -0
- package/scripts/page-release.mjs +28 -6
- package/scripts/page-size.mjs +2 -1
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +78 -0
- package/scripts/tile-bake-report.mjs +1 -1
- package/scripts/tile-bakes.mjs +1 -1
- package/scripts/title-assets.generated.json +2 -0
- package/scripts/tsconfig.json +1 -2
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +176 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +84 -24
- package/scripts/worker-client-play.mjs +7 -2
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/scripts/worktree-reap.mjs +5 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +47 -12
- package/src/client/engine/boot/bootCache.ts +2 -2
- package/src/client/engine/boot/bootTrace.ts +12 -4
- package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
- package/src/client/engine/boot/clearDownloads.ts +5 -2
- package/src/client/engine/boot/contentRead.ts +11 -0
- package/src/client/engine/boot/gpuFiles.ts +4 -2
- package/src/client/engine/boot/lastEnd.ts +99 -12
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/boot/texturePack.ts +2 -2
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +18 -0
- package/src/client/engine/core/bootstrap.ts +4 -1
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +29 -6
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +53 -14
- package/src/client/engine/render/dataLook.ts +152 -40
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +7 -1
- package/src/client/engine/render/look.ts +6 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +28 -4
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
- package/src/client/engine/ui/debugOptions.ts +1 -1
- package/src/client/engine/ui/lookLightOption.ts +10 -6
- package/src/client/engine/ui/namePrompt.ts +7 -0
- package/src/client/game/boot/audio.generated.ts +114 -216
- package/src/client/game/boot/bytes.generated.ts +118 -238
- package/src/client/game/boot/placedSpawn.ts +35 -0
- package/src/client/game/boot/spawnDownload.ts +25 -6
- package/src/client/game/boot/versions.generated.ts +7 -7
- package/src/client/game/devScene/hook.ts +291 -0
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +134 -12
- package/src/client/game/grid/liveSession.ts +47 -5
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +233 -0
- package/src/client/game/grid/placedContent.ts +85 -0
- package/src/client/game/grid/prefetch.ts +9 -1
- package/src/client/game/grid/productInputs.ts +3 -1
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadLook.ts +24 -15
- package/src/client/game/grid/roadLookPlatform.ts +4 -2
- package/src/client/game/grid/roadResources.ts +24 -0
- package/src/client/game/grid/roadSign.worker.ts +4 -3
- package/src/client/game/grid/roadSignPaint.ts +16 -5
- package/src/client/game/grid/roadSignPreparation.ts +4 -3
- package/src/client/game/grid/roadSignScale.ts +8 -0
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
- package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
- package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
- package/src/client/game/grid/roadTileWriter.ts +2 -1
- package/src/client/game/grid/screenReports.ts +39 -0
- package/src/client/game/grid/session.ts +29 -4
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/grid/softWallLook.ts +25 -8
- package/src/client/game/mainMenu.ts +6 -2
- package/src/client/game/plugin/context.ts +2 -1
- package/src/client/game/plugin/followedMovers.ts +7 -1
- package/src/client/game/quest/figures.ts +2 -0
- package/src/client/game/session/finish.ts +11 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +4 -1
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +21 -8
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/game/titleDeck.ts +4 -3
- package/src/client/host/online/doctor.ts +2 -0
- package/src/client/host/online/linkScreens.ts +30 -4
- package/src/client/host/online/shell.ts +14 -0
- package/src/client/host/standalone/shell.ts +4 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +67 -9
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +349 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/engine/ai/bossContenders.ts +27 -3
- package/src/server/engine/ai/phases.ts +1 -1
- package/src/server/engine/entities/creatureRefill.ts +9 -2
- package/src/server/engine/net/ledgerBook.ts +2 -0
- package/src/server/engine/net/room.ts +15 -0
- package/src/server/engine/sim/respawn.ts +8 -0
- package/src/server/game/boss/arenaRoomEntry.ts +5 -1
- package/src/server/game/boss/arenaRoomNative.ts +2 -0
- package/src/server/game/boss/native.ts +2 -1
- package/src/server/game/boss/nativeWake.ts +9 -5
- package/src/server/game/boss/openArenaNative.ts +2 -2
- package/src/server/game/boss/openArenaRoom.ts +3 -1
- package/src/server/game/grid/room.ts +44 -3
- package/src/server/game/grid/simulation.ts +23 -0
- package/src/server/game/population/mixedRoster.ts +11 -3
- package/src/server/game/population/nativeBake.ts +8 -3
- package/src/server/game/population/nativeReturns.ts +6 -3
- package/src/server/game/population/roster.ts +5 -3
- package/src/server/game/quest/eliteDrops.ts +15 -4
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +10 -6
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +98 -16
- package/src/server/host/dedicated/cellProtocol.ts +16 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +4 -19
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +126 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/workerTable.ts +15 -4
- package/src/server/host/dedicated/world.ts +95 -8
- package/src/server/host/headless.ts +1 -1
- package/src/server/host/headlessRuntime.ts +1 -1
- package/src/server/host/standalone/roadWorld.ts +15 -3
- package/src/server/host/standalone/serverHost.ts +4 -1
- package/src/server/host/standalone/serverProduct.ts +41 -11
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +47 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/catalogueSlot.ts +7 -0
- package/src/shared/game/grid/placementRows.ts +36 -0
- package/src/shared/game/plugin/bossRecord.ts +3 -2
- package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
- package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
- package/src/shared/game/shardfile/packReads.ts +28 -3
- package/src/shared/game/shardfile/serverPack.ts +9 -0
- package/src/shared/game/systems/looks/trampleField.ts +2 -0
- package/src/shared/host/formatJsonSchema.ts +2 -2
- package/src/tsconfig.json +1 -27
- package/lint/host-reviews.json +0 -14
- package/lint/listed-view-code.json +0 -13
- package/lint/platform-pending-users.json +0 -2520
- package/lint/platform-pending-users.md +0 -18
- package/scripts/cell-mem/metrics-preload.mjs +0 -65
- package/scripts/check-closed-components.d.mts +0 -7
- package/scripts/check-closed-components.mjs +0 -87
- package/scripts/g571-hosts.d.mts +0 -3
- package/scripts/g571-hosts.mjs +0 -54
- package/scripts/host-ruler/register-migrate.mjs +0 -242
- package/scripts/listed-view-code.d.mts +0 -7
- package/scripts/listed-view-code.mjs +0 -93
- package/scripts/look-loop/fit-lut.py +0 -142
- package/scripts/look-loop/palette-delta.py +0 -183
- package/scripts/look-loop/regions/driftwood-isle.json +0 -25
- package/scripts/look-loop/regions/far-reach.json +0 -225
- package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
- package/scripts/look-loop/regions/pine-hollow.json +0 -22
- package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
- package/scripts/platform-chargebacks.d.mts +0 -9
- package/scripts/platform-chargebacks.mjs +0 -135
- package/scripts/shard-component-spans.d.mts +0 -15
- package/scripts/shard-component-spans.mjs +0 -18
- package/scripts/shard-components.d.mts +0 -16
- package/scripts/shard-components.mjs +0 -363
- package/scripts/shard-platform-hosts.d.mts +0 -2
- package/scripts/shard-platform-hosts.mjs +0 -93
- package/scripts/shard-platform-sections.d.mts +0 -2
- package/scripts/shard-platform-sections.mjs +0 -9
- package/scripts/shard-platform.d.mts +0 -76
- package/scripts/shard-platform.mjs +0 -1072
- package/src/.oxfmtrc.json +0 -48
- package/src/scripts/ask-new.sh +0 -29
- package/src/scripts/asks.mjs +0 -142
- package/src/scripts/herdr-prompt.sh +0 -34
- package/src/scripts/herdr-question-open.sh +0 -67
- package/src/scripts/md-wrap.mjs +0 -229
- /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
- /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
- /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
|
@@ -42,6 +42,25 @@ function binGrid(pitch: number, tileSize?: number): { size: number; offset: numb
|
|
|
42
42
|
/** A cell edge's distance from its cell centre (the seam's outer row meets the shard's own ground there). */
|
|
43
43
|
const CELL_EDGE = CHUNK_HALF;
|
|
44
44
|
|
|
45
|
+
/** IOSMEM (WILDSHARD-GAME-8G): the clip's and bin sort's working lists, growing typed storage off the JS heap. As
|
|
46
|
+
* number[] they held ~40-90 bytes a triangle of short-lived heap through an install (hundreds of MB on Driftwood's road),
|
|
47
|
+
* which an iPhone counts against the page until it collects. */
|
|
48
|
+
class Grow<A extends Uint32Array | Float64Array> {
|
|
49
|
+
length = 0;
|
|
50
|
+
constructor(private array: A, private readonly make: (size: number) => A) {}
|
|
51
|
+
push(value: number): void {
|
|
52
|
+
if (this.length === this.array.length) { const next = this.make(Math.max(64, this.array.length * 2)); next.set(this.array); this.array = next; }
|
|
53
|
+
this.array[this.length++] = value;
|
|
54
|
+
}
|
|
55
|
+
/** The filled part; `exact` copies it out so a long-kept result never pins the spare capacity. */
|
|
56
|
+
view(exact = false): A {
|
|
57
|
+
if (!exact) return this.array.subarray(0, this.length) as A;
|
|
58
|
+
return (this.length === this.array.length ? this.array : this.array.slice(0, this.length)) as A;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const growU32 = (size: number): Grow<Uint32Array> => new Grow(new Uint32Array(size), (n) => new Uint32Array(n));
|
|
62
|
+
const growF64 = (size: number): Grow<Float64Array> => new Grow(new Float64Array(size), (n) => new Float64Array(n));
|
|
63
|
+
|
|
45
64
|
|
|
46
65
|
/** The same attribute interpolation and index order, yielding between bounded triangle/copy batches. */
|
|
47
66
|
export function* clipToBinsSteps(geometry: BufferGeometry, pitch: number, tileSize?: number): Generator<void> {
|
|
@@ -70,7 +89,7 @@ export function* clipToBinsSteps(geometry: BufferGeometry, pitch: number, tileSi
|
|
|
70
89
|
for (let n = 0; n < extra.length / stride; n++) { if (n % 256 === 0) yield; for (let c = 0; c < size; c++) array[(count + n) * size + c] = extra[n * stride + o + c] ?? 0; }
|
|
71
90
|
geometry.setAttribute(name, new BufferAttribute(array, size)); o += size;
|
|
72
91
|
}
|
|
73
|
-
geometry.setIndex(new BufferAttribute(
|
|
92
|
+
geometry.setIndex(new BufferAttribute(out.slice(), 1));
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
/**
|
|
@@ -78,8 +97,9 @@ export function* clipToBinsSteps(geometry: BufferGeometry, pitch: number, tileSi
|
|
|
78
97
|
* x then z, a new vertex interpolating all `stride` values linearly (position at `px`). A plan that reads only positions
|
|
79
98
|
* gets exactly the builder's positions, new vertices and triangles: every value interpolates on its own.
|
|
80
99
|
*/
|
|
81
|
-
function* clipCore(triangles: number, indexAt: (i: number) => number, count: number, stride: number, px: number, read: (n: number) => Float64Array, coordinate: (n: number, axis: number) => number, pitch: number, tileSize?: number, retain = true): Generator<void, { extra:
|
|
82
|
-
|
|
100
|
+
function* clipCore(triangles: number, indexAt: (i: number) => number, count: number, stride: number, px: number, read: (n: number) => Float64Array, coordinate: (n: number, axis: number) => number, pitch: number, tileSize?: number, retain = true): Generator<void, { extra: Float64Array; out: Uint32Array; added: number; corners: number }> {
|
|
101
|
+
// Most triangles fit one bin, so the index is about three corners a triangle; cut triangles grow it.
|
|
102
|
+
const { size: s, offset } = binGrid(pitch, tileSize), extra = growF64(retain ? stride * 64 : 0), out = growU32(retain ? triangles * 3 + 64 : 0);
|
|
83
103
|
let added = 0, corners = 0;
|
|
84
104
|
// Count-only admission needs no final index or copied interpolation channels.
|
|
85
105
|
// Polygon vertices still retain every value used by the original split.
|
|
@@ -107,7 +127,7 @@ function* clipCore(triangles: number, indexAt: (i: number) => number, count: num
|
|
|
107
127
|
// polygons or copying attributes; only an interior cut needs interpolation.
|
|
108
128
|
if (!crossesBin(coordinate(a, 0), coordinate(b, 0), coordinate(third, 0), s, offset)
|
|
109
129
|
&& !crossesBin(coordinate(a, 2), coordinate(b, 2), coordinate(third, 2), s, offset)) {
|
|
110
|
-
corners += 3; if (retain) out.push(a
|
|
130
|
+
corners += 3; if (retain) { out.push(a); out.push(b); out.push(third); } continue;
|
|
111
131
|
}
|
|
112
132
|
const tri: V[] = [a, b, third].map((n) => ({ n, v: read(n) }));
|
|
113
133
|
let polys: V[][] = [tri];
|
|
@@ -127,10 +147,10 @@ function* clipCore(triangles: number, indexAt: (i: number) => number, count: num
|
|
|
127
147
|
}
|
|
128
148
|
for (const poly of polys) for (let k = 1; k + 1 < poly.length; k++) {
|
|
129
149
|
corners += 3;
|
|
130
|
-
if (retain) out.push(poly[0]?.n ?? 0
|
|
150
|
+
if (retain) { out.push(poly[0]?.n ?? 0); out.push(poly[k]?.n ?? 0); out.push(poly[k + 1]?.n ?? 0); }
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
|
-
return { extra, out, added, corners };
|
|
153
|
+
return { extra: extra.view(), out: out.view(), added, corners };
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
|
|
@@ -147,26 +167,36 @@ export function* cullPlanSteps(geometry: BufferGeometry, pitch: number, lod: rea
|
|
|
147
167
|
if (index === null) throw new Error('A culled road mesh needs an index');
|
|
148
168
|
// each triangle's bin (`cullBin` of its centroid) as two numbers; a bin's string key, made once, orders the bins
|
|
149
169
|
const { size, offset } = binGrid(pitch, tileSize);
|
|
150
|
-
|
|
170
|
+
// Each triangle's bin id in one typed pass, then a counting sort keeps every bin's triangles in index order (IOSMEM:
|
|
171
|
+
// no number[] list per bin on the JS heap).
|
|
172
|
+
interface BinRow { readonly key: string; readonly x: number; readonly z: number; readonly id: number; count: number }
|
|
173
|
+
const triangles = index.count / 3, byBin = new Map<number, Map<number, BinRow>>(), binOf = new Uint32Array(triangles);
|
|
174
|
+
let binCount = 0;
|
|
151
175
|
for (let t = 0; t < triangles; t++) {
|
|
152
176
|
if (t % 256 === 0) yield;
|
|
153
177
|
let x = 0, z = 0;
|
|
154
178
|
for (let c = 0; c < 3; c++) { const n = index.getX(t * 3 + c); x += position.getX(n); z += position.getZ(n); }
|
|
155
179
|
const bx = Math.floor(x / 3 / size + offset), bz = Math.floor(z / 3 / size + offset);
|
|
156
180
|
let row = byBin.get(bx); if (row === undefined) { row = new Map(); byBin.set(bx, row); }
|
|
157
|
-
|
|
158
|
-
if (bin === undefined)
|
|
181
|
+
let bin = row.get(bz);
|
|
182
|
+
if (bin === undefined) { bin = { key: `${String(bx)},${String(bz)}`, x: bx, z: bz, id: binCount++, count: 0 }; row.set(bz, bin); }
|
|
183
|
+
bin.count++; binOf[t] = bin.id;
|
|
159
184
|
}
|
|
160
|
-
const
|
|
185
|
+
const firsts = new Uint32Array(binCount + 1), members = new Uint32Array(triangles);
|
|
186
|
+
for (const row of byBin.values()) for (const bin of row.values()) firsts[bin.id + 1] = bin.count;
|
|
187
|
+
for (let b = 0; b < binCount; b++) firsts[b + 1] = (firsts[b + 1] ?? 0) + (firsts[b] ?? 0);
|
|
188
|
+
{ const cursor = firsts.slice(0, binCount); for (let t = 0; t < triangles; t++) { if (t % 4096 === 0) yield; const b = binOf[t] ?? 0; members[cursor[b] ?? 0] = t; cursor[b] = (cursor[b] ?? 0) + 1; } }
|
|
189
|
+
const out = growU32(triangles * 3 + 64), bins: CullBin[] = [];
|
|
161
190
|
const clusters = lod.map((tier) => clusterer(geometry, pitch, tier.cell, tileSize));
|
|
162
|
-
const ordered:
|
|
191
|
+
const ordered: BinRow[] = [];
|
|
163
192
|
for (const row of byBin.values()) for (const bin of row.values()) ordered.push(bin);
|
|
164
193
|
ordered.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
165
194
|
// A shared indexed vertex contributes once per bin to both bounds scans.
|
|
166
195
|
// Keep triangle publication and LOD representative order unchanged.
|
|
167
196
|
const boundedIn = new Uint32Array(position.count);
|
|
168
197
|
let binId = 0;
|
|
169
|
-
for (const {
|
|
198
|
+
for (const { id, x: tileX, z: tileZ } of ordered) {
|
|
199
|
+
const list = members.subarray(firsts[id] ?? 0, firsts[id + 1] ?? 0);
|
|
170
200
|
const start = out.length, unique: number[] = [];
|
|
171
201
|
binId++;
|
|
172
202
|
let minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
@@ -198,13 +228,13 @@ export function* cullPlanSteps(geometry: BufferGeometry, pitch: number, lod: rea
|
|
|
198
228
|
if (i % 256 === 0) yield;
|
|
199
229
|
const t = list[i] ?? 0;
|
|
200
230
|
const a = cluster(index.getX(t * 3)), b = cluster(index.getX(t * 3 + 1)), c = cluster(index.getX(t * 3 + 2));
|
|
201
|
-
if (a !== b && b !== c && a !== c) out.push(a
|
|
231
|
+
if (a !== b && b !== c && a !== c) { out.push(a); out.push(b); out.push(c); }
|
|
202
232
|
}
|
|
203
233
|
levels.push({ start: from, count: out.length - from });
|
|
204
234
|
}
|
|
205
235
|
bins.push({ sphere, start, count, levels, ...(tileSize === undefined ? {} : { tile: { x: tileX, z: tileZ } }) });
|
|
206
236
|
}
|
|
207
|
-
return { source:
|
|
237
|
+
return { source: out.view(true), bins, lod: lod.map((tier) => tier.distance) };
|
|
208
238
|
}
|
|
209
239
|
|
|
210
240
|
/**
|
|
@@ -15,7 +15,8 @@ import type { GridCell } from '../../../shared/game/grid/assembly';
|
|
|
15
15
|
import { putRoadGrain, roadGrainSteps, type RoadGrainSource } from './roadGrain';
|
|
16
16
|
import { packRoadSignPixels } from './roadSignPixels';
|
|
17
17
|
import { paintRoadSignCanvas, roadSignPaintLayout, roadSignLineKey as lineKey, SIGN_LINE_W as LINE_W, SIGN_LINE_H as LINE_H, type RoadSignSource } from './roadSignPaint';
|
|
18
|
-
import { ownRoadMesh } from './roadResources';
|
|
18
|
+
import { ownRoadMesh, type RoadMapShare } from './roadResources';
|
|
19
|
+
import { roadSignScale } from './roadSignScale';
|
|
19
20
|
import { ROAD_SKY } from './frameModel';
|
|
20
21
|
import { coverageMaterial, coverageTable, gpuOnlyTextureBytes, uniformPart, type CoverageColours, type SolidPart } from './roadSolid';
|
|
21
22
|
import { bytePlan, cullIntoSteps, gpuOnlyRoad, meshBytesSteps, type CullSource, type RoadCuller } from './roadCull';
|
|
@@ -45,6 +46,8 @@ export interface RoadLookInput {
|
|
|
45
46
|
readonly overlayLight?: RoadOverlayLight;
|
|
46
47
|
/** Bind a source's shrink-only charge after its backing is durable. */
|
|
47
48
|
readonly retireGeometry?: (mesh: Mesh, id: string, retainedBytes: number) => void;
|
|
49
|
+
/** PZ24: the road system's shared asphalt and junction maps (absent: each build paints its own) */
|
|
50
|
+
readonly maps?: RoadMapShare;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
/**
|
|
@@ -370,20 +373,20 @@ const SIGN_BLUE_FROM_RED = 0.45;
|
|
|
370
373
|
const signCoverage = (): CoverageColours => ({ from: SIGN_GREEN, to: WHITE, blueFromRed: SIGN_BLUE_FROM_RED, sentinel: { v: GREY_V - 0.5, colour: SIGN_GREY } });
|
|
371
374
|
/** The atlas's layout, pure (its size and every uv), so the sign mesh and its byte plan never need the canvas. */
|
|
372
375
|
interface SignAtlasLayout {
|
|
373
|
-
readonly keys: readonly string[]; readonly lines: ReadonlyMap<string, SignLine>; readonly width: number; readonly height: number;
|
|
376
|
+
readonly keys: readonly string[]; readonly lines: ReadonlyMap<string, SignLine>; readonly width: number; readonly height: number; readonly scale: number;
|
|
374
377
|
readonly slot: (k: number) => [number, number];
|
|
375
378
|
readonly cell: (line: SignLine) => readonly [number, number, number, number];
|
|
376
379
|
readonly swatch: Readonly<Record<'green' | 'grey' | 'white', readonly [number, number]>>;
|
|
377
380
|
}
|
|
378
|
-
function signAtlasLayout(signs: readonly RoadSign[]): SignAtlasLayout {
|
|
379
|
-
const { keys, lines, width: W, height: H, slot } = roadSignPaintLayout(signs);
|
|
381
|
+
function signAtlasLayout(signs: readonly RoadSign[], scale: number): SignAtlasLayout {
|
|
382
|
+
const { keys, lines, width: W, height: H, slot } = roadSignPaintLayout(signs, scale), cellW = LINE_W * scale, cellH = LINE_H * scale;
|
|
380
383
|
const [sx, sy] = slot(keys.length); // swatches in the last cell
|
|
381
384
|
const uv = (px: number, py: number): readonly [number, number] => [px / W, 1 - py / H];
|
|
382
385
|
const index = new Map(keys.map((k, i) => [k, i]));
|
|
383
386
|
return {
|
|
384
|
-
keys, lines, width: W, height: H, slot,
|
|
385
|
-
cell: (line) => { const [x, y] = slot(index.get(lineKey(line)) ?? 0); return [x / W, 1 - (y +
|
|
386
|
-
swatch: { green: uv(sx + 32, sy +
|
|
387
|
+
keys, lines, width: W, height: H, scale, slot,
|
|
388
|
+
cell: (line) => { const [x, y] = slot(index.get(lineKey(line)) ?? 0); return [x / W, 1 - (y + cellH) / H, (x + cellW) / W, 1 - y / H]; },
|
|
389
|
+
swatch: { green: uv(sx + 32 * scale, sy + cellH / 2), grey: [0.5, GREY_V], white: uv(sx + 160 * scale, sy + cellH / 2) },
|
|
387
390
|
};
|
|
388
391
|
}
|
|
389
392
|
function signAtlasTexture(atlas: SignAtlasLayout, signs?: RoadSignSource): DataTexture {
|
|
@@ -433,6 +436,8 @@ interface TexturedSource {
|
|
|
433
436
|
readonly overlay: boolean;
|
|
434
437
|
/** GPU bytes per texel (4: an RGBA8 canvas; 2: the sign atlas's RG8 array) and what holds the texels until upload */
|
|
435
438
|
readonly texelBytes: number; readonly source: 'canvas' | 'data';
|
|
439
|
+
/** PZ24: its map depends on the grain only, so every build of one road system shares one upload */
|
|
440
|
+
readonly shared: boolean;
|
|
436
441
|
readonly material: (map: Texture) => MeshLambertMaterial;
|
|
437
442
|
}
|
|
438
443
|
// the map is the emissive map too, black until RoadOverlayLight lights it inside a cell (one program either way)
|
|
@@ -440,11 +445,11 @@ const overlayMaterial = (map: Texture): MeshLambertMaterial => new MeshLambertMa
|
|
|
440
445
|
/** A texture painted in one stretch, as a paint step. */
|
|
441
446
|
function* paintNow(paint: () => Texture): Generator<void, Texture> { yield; return paint(); }
|
|
442
447
|
function texturedSources(layout: RoadLayout, home: GridCell, grain?: RoadGrainSource, signs?: RoadSignSource): TexturedSource[] {
|
|
443
|
-
const atlas = signAtlasLayout(layout.signs);
|
|
448
|
+
const atlas = signAtlasLayout(layout.signs, roadSignScale());
|
|
444
449
|
return [
|
|
445
|
-
{ id: 'road.asphalt', name: 'grid-asphalt', mesher: asphalt(layout, home), width: 1024, height: 512, paint: () => roadTextureSteps(grain), overlay: true, texelBytes: 4, source: 'canvas', material: overlayMaterial },
|
|
446
|
-
{ id: 'road.junctions', name: 'grid-junctions', mesher: junctionAsphalt(layout, home), width: 1024, height: 1024, paint: () => junctionTextureSteps(grain), overlay: true, texelBytes: 4, source: 'canvas', material: overlayMaterial },
|
|
447
|
-
{ id: 'road.signs', name: 'grid-signs', mesher: signMesher(layout.signs, home, atlas), width: atlas.width, height: atlas.height, paint: () => paintNow(() => signAtlasTexture(atlas, signs)), overlay: false, texelBytes: 2, source: 'data', material: (map) => coverageMaterial(map, signCoverage(), 'g227-grid-sign-cover') },
|
|
450
|
+
{ id: 'road.asphalt', name: 'grid-asphalt', mesher: asphalt(layout, home), width: 1024, height: 512, paint: () => roadTextureSteps(grain), overlay: true, texelBytes: 4, source: 'canvas', shared: true, material: overlayMaterial },
|
|
451
|
+
{ id: 'road.junctions', name: 'grid-junctions', mesher: junctionAsphalt(layout, home), width: 1024, height: 1024, paint: () => junctionTextureSteps(grain), overlay: true, texelBytes: 4, source: 'canvas', shared: true, material: overlayMaterial },
|
|
452
|
+
{ id: 'road.signs', name: 'grid-signs', mesher: signMesher(layout.signs, home, atlas), width: atlas.width, height: atlas.height, paint: () => paintNow(() => signAtlasTexture(atlas, signs)), overlay: false, texelBytes: 2, source: 'data', shared: false, material: (map) => coverageMaterial(map, signCoverage(), 'g227-grid-sign-cover') },
|
|
448
453
|
];
|
|
449
454
|
}
|
|
450
455
|
|
|
@@ -461,22 +466,26 @@ export function* installRoadLookSteps(input: RoadLookInput): Generator<void, Roa
|
|
|
461
466
|
scene.add(group);
|
|
462
467
|
scope.onDispose(() => { group.removeFromParent(); });
|
|
463
468
|
for (const source of sources) {
|
|
469
|
+
const share = source.shared ? input.maps : undefined;
|
|
464
470
|
const build = function* build(owner: LookScope): Generator<void, Mesh> {
|
|
465
471
|
yield;
|
|
466
|
-
const map = yield* source.paint(), material = source.material(map);
|
|
472
|
+
const held = share?.take(source.id), map = held ?? (yield* source.paint()), material = source.material(map);
|
|
473
|
+
if (share !== undefined && held === undefined) share.hold(source.id, map);
|
|
467
474
|
const mesh = new Mesh(source.mesher.geometry(), material);
|
|
468
|
-
ownRoadMesh(owner, mesh, [map]);
|
|
475
|
+
ownRoadMesh(owner, mesh, share === undefined ? [map] : []);
|
|
476
|
+
if (share !== undefined) owner.onDispose(() => { share.release(source.id, map); });
|
|
469
477
|
mesh.name = source.name; if (source.overlay) { mesh.receiveShadow = true; input.overlayLight?.add(material, owner); }
|
|
470
478
|
mesh.castShadow = false; mesh.matrixAutoUpdate = false; mesh.updateMatrix();
|
|
471
479
|
if (cull !== undefined) yield* cullIntoSteps(cull, mesh); else hook?.(mesh);
|
|
472
480
|
group.add(mesh);
|
|
473
|
-
if (admission !== undefined) gpuOnlyRoad(mesh, [map]); // G144: admitted, its vertex arrays and canvas go on upload (nothing repaints it)
|
|
481
|
+
if (admission !== undefined) gpuOnlyRoad(mesh, held === undefined ? [map] : []); // G144: admitted, its vertex arrays and canvas go on upload (nothing repaints it)
|
|
474
482
|
return mesh;
|
|
475
483
|
};
|
|
476
484
|
if (admission === undefined) yield* build(scope);
|
|
477
485
|
else {
|
|
478
486
|
const bytes = yield* meshBytesSteps([mesherSource(source.mesher)], ROAD_FLOATS, cull === undefined ? undefined : { pitch: cull.pitch, ...(cull.tileSize === undefined ? {} : { tileSize: cull.tileSize }) }, true);
|
|
479
|
-
|
|
487
|
+
// a shared map another build of this road already holds costs this build nothing (PZ24)
|
|
488
|
+
const textures = share?.has(source.id) === true ? { jsBytes: 0, gpuBytes: 0 } : gpuOnlyTextureBytes(source.width, source.height, 1, source.source, source.texelBytes);
|
|
480
489
|
const plan = bytePlan(source.id, bytes, textures);
|
|
481
490
|
const mesh = yield* allocateRenderSteps(admission, plan, build);
|
|
482
491
|
if (mesh === undefined) throw new Error('Road construction cancelled');
|
|
@@ -16,7 +16,7 @@ import type { RoadSignSource } from './roadSignPaint';
|
|
|
16
16
|
*/
|
|
17
17
|
import { Mesh, type Camera, type Object3D } from 'three';
|
|
18
18
|
import { CONTENT_CAPS } from '@wildshard/engine/core/config';
|
|
19
|
-
import { ownRoadMesh } from './roadResources';
|
|
19
|
+
import { ownRoadMesh, type RoadMapShare } from './roadResources';
|
|
20
20
|
import type { RoadTileBacking } from './roadTileBacking';
|
|
21
21
|
import type { RoadGrainSource } from './roadGrain';
|
|
22
22
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
@@ -57,6 +57,8 @@ 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 one junction map for every build of this road (a split road's halves pass the same share) */
|
|
61
|
+
readonly maps?: RoadMapShare;
|
|
60
62
|
}
|
|
61
63
|
/** The readouts and the roots the road budget measures. */
|
|
62
64
|
export interface PlatformRoad {
|
|
@@ -152,7 +154,7 @@ function* platformRoadSteps(input: PlatformRoadInput): Generator<void, PlatformR
|
|
|
152
154
|
const overlayLight = new RoadOverlayLight();
|
|
153
155
|
const road = yield* installRoadLookSteps({ layout, home, scene, scope, solid, cull: culler, admission, overlayLight, retireGeometry,
|
|
154
156
|
...(input.grain === undefined ? {} : { grain: input.grain }),
|
|
155
|
-
...(input.signs === undefined ? {} : { signs: input.signs }) });
|
|
157
|
+
...(input.signs === undefined ? {} : { signs: input.signs }), ...(input.maps === undefined ? {} : { maps: input.maps }) });
|
|
156
158
|
const voidLook = input.voidFloor === false ? null : installVoidLook({ rail: layout.rail, edge: layout.edge, holes: layout.holes, home, scene, scope, solid, admission });
|
|
157
159
|
// this build's own boulevard group (a split road adds one per build)
|
|
158
160
|
let boulevard: Object3D | undefined;
|
|
@@ -13,3 +13,27 @@ export function ownRoadMesh(scope: LookScope, mesh: Mesh, textures: readonly Tex
|
|
|
13
13
|
scope.onDispose(() => { mesh.geometry.dispose(); });
|
|
14
14
|
scope.onDispose(() => { mesh.removeFromParent(); });
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* PZ24 (meta PAGE-SIZE): one upload of each road canvas that depends on the grain only (the asphalt and the junction), shared
|
|
19
|
+
* by every build of one road system: A1's ring-first halves painted and uploaded both twice, 8.4 MB of the iPhone profile's
|
|
20
|
+
* GPU texture on Driftwood. Each user takes a count; the last release disposes the texture, so a half retired before the
|
|
21
|
+
* other never pulls the map from under it.
|
|
22
|
+
*/
|
|
23
|
+
export class RoadMapShare {
|
|
24
|
+
private readonly held = new Map<string, { readonly texture: Texture; users: number }>();
|
|
25
|
+
/** a held map for `id`, counted for the caller, or undefined (paint it, then `hold` it) */
|
|
26
|
+
take(id: string): Texture | undefined {
|
|
27
|
+
const row = this.held.get(id); if (row === undefined) return undefined;
|
|
28
|
+
row.users++; return row.texture;
|
|
29
|
+
}
|
|
30
|
+
has(id: string): boolean { return this.held.has(id); }
|
|
31
|
+
/** the first user's freshly painted map, counted for it */
|
|
32
|
+
hold(id: string, texture: Texture): void { if (!this.held.has(id)) this.held.set(id, { texture, users: 1 }); }
|
|
33
|
+
release(id: string, texture: Texture): void {
|
|
34
|
+
const row = this.held.get(id);
|
|
35
|
+
if (row?.texture !== texture) { texture.dispose(); return; }
|
|
36
|
+
if (--row.users > 0) return;
|
|
37
|
+
this.held.delete(id); texture.dispose();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SignLine } from '../../../shared/game/grid/roadLayout';
|
|
2
|
-
import { paintRoadSignCanvas, roadSignPaintLayout } from './roadSignPaint';
|
|
2
|
+
import { paintRoadSignCanvas, roadSignPaintLayout, SIGN_SCALES } from './roadSignPaint';
|
|
3
3
|
import { packRoadSignPixels } from './roadSignPixels';
|
|
4
4
|
import { installWorkerBootTiming } from '@wildshard/engine/boot/workerTiming';
|
|
5
5
|
|
|
@@ -17,9 +17,10 @@ self.onmessage = (event: MessageEvent<unknown>): void => {
|
|
|
17
17
|
try {
|
|
18
18
|
const input = event.data;
|
|
19
19
|
if (typeof input !== 'object' || input === null) throw new Error('Invalid sign job');
|
|
20
|
-
const rows: unknown = Reflect.get(input, 'rows'), red: unknown = Reflect.get(input, 'red'), green: unknown = Reflect.get(input, 'green');
|
|
20
|
+
const rows: unknown = Reflect.get(input, 'rows'), red: unknown = Reflect.get(input, 'red'), green: unknown = Reflect.get(input, 'green'), scale: unknown = Reflect.get(input, 'scale') ?? 1;
|
|
21
21
|
if (!signLines(rows) || !(red instanceof Uint8Array) || !(green instanceof Uint8Array) || red.length !== 256 || green.length !== 256) throw new Error('Invalid sign planes');
|
|
22
|
-
|
|
22
|
+
if (typeof scale !== 'number' || !SIGN_SCALES.includes(scale)) throw new Error('Invalid sign scale');
|
|
23
|
+
const layout = roadSignPaintLayout(rows.map(line => ({ lines: [line] })), scale);
|
|
23
24
|
if (layout.width * layout.height > 16 * 1024 * 1024) throw new Error('Worker sign plane too large');
|
|
24
25
|
const context = new OffscreenCanvas(layout.width, layout.height).getContext('2d');
|
|
25
26
|
if (context === null) throw new Error('Worker sign has no 2D canvas');
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
import type { RoadSign, SignLine } from '../../../shared/game/grid/roadLayout';
|
|
2
2
|
|
|
3
3
|
export const SIGN_LINE_W = 512, SIGN_LINE_H = 64;
|
|
4
|
+
/** PZ24: the atlas's texel scales. 1 is the painted size; the phone tier's 0.5 holds a quarter of the texels (Driftwood's
|
|
5
|
+
* two halves' atlases were 28.8 MB of GPU texture at 1, 7.2 MB at 0.5): the same painting, drawn half size. */
|
|
6
|
+
export const SIGN_SCALES: readonly number[] = [1, 0.5];
|
|
4
7
|
export interface RoadSignPaintLayout {
|
|
5
|
-
readonly keys: readonly string[]; readonly lines: ReadonlyMap<string, SignLine>;
|
|
8
|
+
readonly keys: readonly string[]; readonly lines: ReadonlyMap<string, SignLine>;
|
|
9
|
+
/** texels; `slot` and the cell size are texels too (a line cell is `SIGN_LINE_W * scale` by `SIGN_LINE_H * scale`) */
|
|
10
|
+
readonly width: number; readonly height: number; readonly scale: number;
|
|
6
11
|
readonly slot: (index: number) => [number, number];
|
|
7
12
|
}
|
|
8
13
|
export type RoadSignSource = (layout: RoadSignPaintLayout) => Uint8Array<ArrayBuffer> | undefined;
|
|
9
14
|
export function roadSignLineKey(line: SignLine): string { return `${line.arrow}|${line.names.join(' · ')}|${line.metres === null ? '' : String(line.metres)}`; }
|
|
10
15
|
/** Original first-key ordering and last matching line, without canvas or renderer state. */
|
|
11
|
-
export function roadSignPaintLayout(signs: readonly Pick<RoadSign, 'lines'>[]): RoadSignPaintLayout {
|
|
16
|
+
export function roadSignPaintLayout(signs: readonly Pick<RoadSign, 'lines'>[], scale = 1): RoadSignPaintLayout {
|
|
17
|
+
if (!SIGN_SCALES.includes(scale)) throw new Error(`No road sign atlas scale ${String(scale)}`);
|
|
12
18
|
const keys = [...new Set(signs.flatMap(s => s.lines.map(roadSignLineKey)))], lines = new Map<string, SignLine>();
|
|
13
19
|
for (const sign of signs) for (const line of sign.lines) lines.set(roadSignLineKey(line), line);
|
|
14
|
-
const
|
|
15
|
-
|
|
20
|
+
const perRow = 1024 / SIGN_LINE_W, cellW = SIGN_LINE_W * scale, cellH = SIGN_LINE_H * scale;
|
|
21
|
+
const width = 1024 * scale, height = Math.ceil((keys.length + 1) / perRow) * cellH;
|
|
22
|
+
return { keys, lines, width, height, scale, slot: k => [(k % perRow) * cellW, Math.floor(k / perRow) * cellH] };
|
|
16
23
|
}
|
|
17
24
|
/** Exact original commands, font, coordinates and canvas state on either native 2D surface. */
|
|
18
25
|
export function paintRoadSignCanvas(g: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, atlas: RoadSignPaintLayout): void {
|
|
19
|
-
const { keys, lines,
|
|
26
|
+
const { keys, lines, width: W, height: H, scale } = atlas, LINE_W = SIGN_LINE_W, LINE_H = SIGN_LINE_H, WHITE = '#e9ebe6';
|
|
27
|
+
// the same commands in painted units at every scale (PZ24): only the transform shrinks them
|
|
28
|
+
const slot = (k: number): [number, number] => { const [x, y] = atlas.slot(k); return [x / scale, y / scale]; };
|
|
20
29
|
g.fillStyle = '#0d6b3c'; g.fillRect(0, 0, W, H);
|
|
30
|
+
g.save(); g.scale(scale, scale);
|
|
21
31
|
keys.forEach((key, k) => {
|
|
22
32
|
const line = lines.get(key); if (line === undefined) return;
|
|
23
33
|
const [x, y] = slot(k), mid = y + LINE_H / 2;
|
|
@@ -35,4 +45,5 @@ export function paintRoadSignCanvas(g: CanvasRenderingContext2D | OffscreenCanva
|
|
|
35
45
|
});
|
|
36
46
|
const [sx, sy] = slot(keys.length);
|
|
37
47
|
g.fillStyle = WHITE; g.fillRect(sx + 128, sy, 64, SIGN_LINE_H);
|
|
48
|
+
g.restore();
|
|
38
49
|
}
|
|
@@ -3,12 +3,13 @@ import type { ResidencyAllocator } from '../../../shared/game/grid/allocator';
|
|
|
3
3
|
import type { RoadSign } from '../../../shared/game/grid/roadLayout';
|
|
4
4
|
import { coverageTable } from './roadSolid';
|
|
5
5
|
import { roadSignPaintLayout, type RoadSignSource } from './roadSignPaint';
|
|
6
|
+
import { roadSignScale } from './roadSignScale';
|
|
6
7
|
|
|
7
8
|
export interface RoadSignPreparation { readonly ready: Promise<void>; readonly get: RoadSignSource; readonly release: () => void }
|
|
8
9
|
/** One road bank's scoped coverage; exact original main-thread painting remains the fallback. */
|
|
9
10
|
export function startRoadSigns(parent: Scope, allocator: ResidencyAllocator, home: string, signs: readonly RoadSign[], phase: 'initial' | 'outer' = 'initial'): RoadSignPreparation | undefined {
|
|
10
11
|
if (typeof Worker !== 'function' || typeof OffscreenCanvas !== 'function' || parent.disposed || parent.disposing) return undefined;
|
|
11
|
-
const layout = roadSignPaintLayout(signs), rows = [...layout.lines.values()], signature = JSON.stringify(rows), count = layout.width * layout.height;
|
|
12
|
+
const layout = roadSignPaintLayout(signs, roadSignScale()), rows = [...layout.lines.values()], signature = JSON.stringify(rows), count = layout.width * layout.height;
|
|
12
13
|
if (rows.length > 2048 || count > 16 * 1024 * 1024 || signature.length > 131072) return undefined;
|
|
13
14
|
// Canvas + RGBA readback + final RG8 + conversion lookup; duplicated job text is bounded too.
|
|
14
15
|
// T10: claimed at once: a stepped eviction here (6369cf2558, retired with the rest of it) kept the evicted world
|
|
@@ -38,8 +39,8 @@ export function startRoadSigns(parent: Scope, allocator: ResidencyAllocator, hom
|
|
|
38
39
|
listeners.push(scope.listen(worker, 'messageerror', () => { failed('transfer failed'); }));
|
|
39
40
|
deadline = scope.timeout(30_000, () => { failed('worker deadline'); });
|
|
40
41
|
const colours = { from: '#0d6b3c', to: '#e9ebe6', blueFromRed: 0.45, sentinel: { v: 1.5, colour: '#6f7378' } };
|
|
41
|
-
worker.postMessage({ rows, red: coverageTable(colours, 0), green: coverageTable(colours, 1) }, { transfer: [] });
|
|
42
|
+
worker.postMessage({ rows, scale: layout.scale, red: coverageTable(colours, 0), green: coverageTable(colours, 1) }, { transfer: [] });
|
|
42
43
|
} catch (error) { failed(error instanceof Error ? error.message : String(error)); }
|
|
43
|
-
return { ready, get: current => settled && current.width === layout.width && current.height === layout.height
|
|
44
|
+
return { ready, get: current => settled && current.width === layout.width && current.height === layout.height && current.scale === layout.scale
|
|
44
45
|
&& JSON.stringify([...current.lines.values()]) === signature ? plane : undefined, release: () => { scope.dispose(); } };
|
|
45
46
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TIER } from '@wildshard/engine/core/tier';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PZ24 (meta PAGE-SIZE): the road sign atlas's texel scale for this page's tier. The phone paints it half size: Driftwood's
|
|
5
|
+
* two road halves held 28.8 MB of sign atlas on the iPhone profile (1024x4096 and 1024x6464 RG8 with mips), a quarter of
|
|
6
|
+
* that at 0.5: a sign line is 256x32 texels across a 3.4 m board. The desktop keeps the painted size. Read at each build, so a tier change takes effect with the next road.
|
|
7
|
+
*/
|
|
8
|
+
export function roadSignScale(): number { return TIER === 'phone' ? 0.5 : 1; }
|
|
@@ -53,6 +53,18 @@ function archiveScratch(mesh: Mesh, indices: number): number {
|
|
|
53
53
|
const bytes = 4 * (indices * (stride + 8) + header) + 2 * (indices * (stride + 64) + header);
|
|
54
54
|
return Number.isSafeInteger(bytes) ? bytes : Infinity;
|
|
55
55
|
}
|
|
56
|
+
/** Retire a whole-road mesh once its tile pool (a child) draws instead; returns the geometry it drew, for disposal. It stays
|
|
57
|
+
* as the pool's parent but draws in no view (no camera's layers, shadow pass included). RP4: three links a program in
|
|
58
|
+
* `setProgram` before it reads the draw count, so the empty mesh linked a flat-shaded, position-less variant of each road
|
|
59
|
+
* material the first frame it drew (Driftwood's west edge, 3 links, 386 ms in Chromium) and again at every light-count move. */
|
|
60
|
+
export function retireWholeRoadMesh(mesh: Mesh): BufferGeometry {
|
|
61
|
+
const previous = mesh.geometry;
|
|
62
|
+
mesh.geometry = new BufferGeometry(); mesh.geometry.setDrawRange(0, 0);
|
|
63
|
+
mesh.onBeforeRender = () => { /* Original cull buffers are retired. */ };
|
|
64
|
+
mesh.layers.disableAll();
|
|
65
|
+
return previous;
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
export class RoadTileBacking {
|
|
57
69
|
private readonly sources = new Map<Mesh, Source>();
|
|
58
70
|
private readonly pending: PendingArchive[] = [];
|
|
@@ -284,9 +296,7 @@ export class RoadTileBacking {
|
|
|
284
296
|
// hidden. Geometry disposal precedes each corresponding lease shrink.
|
|
285
297
|
for (const source of this.sources.values()) if (source.pool !== null) source.pool.root.visible = true;
|
|
286
298
|
for (const source of this.sources.values()) {
|
|
287
|
-
const previous = source.mesh
|
|
288
|
-
source.mesh.geometry = new BufferGeometry(); source.mesh.geometry.setDrawRange(0, 0);
|
|
289
|
-
source.mesh.onBeforeRender = () => { /* Original cull buffers are retired. */ };
|
|
299
|
+
const previous = retireWholeRoadMesh(source.mesh);
|
|
290
300
|
this.culler.plans.delete(source.mesh); previous.dispose(); source.retire?.();
|
|
291
301
|
}
|
|
292
302
|
this.committed = true;
|
|
@@ -2,6 +2,7 @@ import { roadTileCache } from './roadTileArchive';
|
|
|
2
2
|
import { captureJobTiles } from './roadTileCaptureJob';
|
|
3
3
|
import type { CaptureJob } from './roadTileCaptureWorker';
|
|
4
4
|
import { installWorkerBootTiming } from '@wildshard/engine/boot/workerTiming';
|
|
5
|
+
import { setCacheChannel } from '@wildshard/engine/pwa/cacheNames';
|
|
5
6
|
|
|
6
7
|
installWorkerBootTiming('road-tile-capture');
|
|
7
8
|
|
|
@@ -10,5 +11,6 @@ async function answer(job: CaptureJob): Promise<void> {
|
|
|
10
11
|
try { self.postMessage({ id: job.id, ok: true, ...await captureJobTiles(job, roadTileCache(caches, job.origin)) }, { transfer: [] }); }
|
|
11
12
|
catch (error: unknown) { self.postMessage({ id: job.id, ok: false, error: error instanceof Error ? error.message : String(error) }, { transfer: [] }); }
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
// OF12: this worker has no document stamp; each job names the page's cache channel
|
|
15
|
+
self.onmessage = (event: MessageEvent<CaptureJob>): void => { setCacheChannel(Reflect.get(event.data, 'channel')); void answer(event.data); };
|
|
14
16
|
self.postMessage({ ready: true }, { transfer: [] });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pageCacheChannel } from '@wildshard/engine/pwa/cacheNames';
|
|
1
2
|
/** DL11: the road tile capture's worker, owned by the backing's scope. A source's compaction, coarse merge and
|
|
2
3
|
* archive writes run there on a copy of its arrays, so the page publishes (and uploads) the source at once and
|
|
3
4
|
* only the references come back. Until the worker says it is running, and whenever it cannot start, the backing
|
|
@@ -69,7 +70,7 @@ export class RoadTileCaptureWorker {
|
|
|
69
70
|
const worker = this.worker; if (!this.usable() || worker === undefined) return null;
|
|
70
71
|
return new Promise<CaptureResult>((resolve, reject) => {
|
|
71
72
|
this.waiting.set(job.id, { job, resolve, reject, refused });
|
|
72
|
-
worker.postMessage(job, { transfer: [] });
|
|
73
|
+
worker.postMessage({ ...job, channel: pageCacheChannel() }, { transfer: [] }); // OF12: the worker's cache channel
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
private message(reply: unknown): void {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assetCacheName, setCacheChannel } from '@wildshard/engine/pwa/cacheNames';
|
|
2
2
|
import { installWorkerBootTiming } from '@wildshard/engine/boot/workerTiming';
|
|
3
3
|
|
|
4
4
|
installWorkerBootTiming('road-tile-write');
|
|
@@ -11,10 +11,12 @@ self.onmessage = (event: MessageEvent<unknown>): void => {
|
|
|
11
11
|
if (typeof message !== 'object' || message === null) return;
|
|
12
12
|
const id: unknown = Reflect.get(message, 'id'), url: unknown = Reflect.get(message, 'url'), bytes: unknown = Reflect.get(message, 'bytes');
|
|
13
13
|
if (typeof id !== 'number' || typeof url !== 'string' || !(bytes instanceof Uint8Array) || !(bytes.buffer instanceof ArrayBuffer)) return;
|
|
14
|
+
// OF12: this worker has no document stamp; the page names its channel's cache
|
|
15
|
+
setCacheChannel(Reflect.get(message, 'channel'));
|
|
14
16
|
const body = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
15
17
|
void (async (): Promise<void> => {
|
|
16
18
|
try {
|
|
17
|
-
await (await caches.open(
|
|
19
|
+
await (await caches.open(assetCacheName())).put(url, new Response(body, {
|
|
18
20
|
headers: { 'content-type': 'application/octet-stream', 'content-length': String(body.length) },
|
|
19
21
|
}));
|
|
20
22
|
self.postMessage({ id, ok: true }, { transfer: [] });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pageCacheChannel } from '@wildshard/engine/pwa/cacheNames';
|
|
1
2
|
/** DL11: road archive writes go to one dedicated worker that owns the Cache
|
|
2
3
|
* Storage put; the page transfers each freshly encoded body instead of copying
|
|
3
4
|
* it. Reads, hashes and URLs are the original store's. Until the worker says it
|
|
@@ -61,7 +62,7 @@ export function roadTileWriter(scope: Scope, storage: Pick<CacheStorage, 'open'>
|
|
|
61
62
|
const id = next++;
|
|
62
63
|
return new Promise<boolean>(resolve => {
|
|
63
64
|
waiting.set(id, { hash, finish: resolve });
|
|
64
|
-
target.postMessage({ id, url: roadTileUrl(origin, hash), bytes }, { transfer: [bytes.buffer] });
|
|
65
|
+
target.postMessage({ id, url: roadTileUrl(origin, hash), bytes, channel: pageCacheChannel() }, { transfer: [bytes.buffer] });
|
|
65
66
|
});
|
|
66
67
|
} };
|
|
67
68
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { captureBrowserError } from '@wildshard/engine/telemetry/browserErrors';
|
|
2
|
+
import type { GridCrossingState } from '../../../shared/game/grid/crossing';
|
|
3
|
+
import type { CrossingSaveStatus } from './borderShimmer';
|
|
4
|
+
|
|
5
|
+
declare const __BUILD_ID__: string;
|
|
6
|
+
const buildId = (): string => { try { return __BUILD_ID__; } catch { return ''; } };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* SENTRY-TRIAGE S18: the grid's SAVE FAILED, RETRY at a border is a screen of a fault. The first time a session shows it, one
|
|
10
|
+
* report names the cell the crossing left and the one it aimed for; later failures in the same session stay quiet, so an
|
|
11
|
+
* offline player who keeps trying can't fill the screen outbox (8 kept) and push out an unsent error-modal.
|
|
12
|
+
*/
|
|
13
|
+
export function saveFailedReporter(slugOf: (instance: string | null) => string, capture: typeof captureBrowserError = captureBrowserError):
|
|
14
|
+
(status: CrossingSaveStatus, state: GridCrossingState | null | undefined) => void {
|
|
15
|
+
let reported = false;
|
|
16
|
+
return (status, state) => {
|
|
17
|
+
if (reported || status !== 'failed') return;
|
|
18
|
+
reported = true;
|
|
19
|
+
try {
|
|
20
|
+
capture(new Error(`a border crossing could not save (SAVE FAILED, RETRY): ${state?.issue ?? state?.phase ?? 'unknown'}`), {
|
|
21
|
+
system: 'grid', build: buildId(), shard: slugOf(state?.current ?? null), bootStage: 'playing', fatal: false, screen: 'save-failed',
|
|
22
|
+
diagnostic: { phase: state?.phase ?? null, target: slugOf(state?.target ?? null) } });
|
|
23
|
+
} catch { /* a report never holds the crossing */ }
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** S18: a neighbour that can't load shows UNAVAILABLE on Shard Select. One report per cell a session, at warning level. */
|
|
28
|
+
export function refusalReporter(capture: typeof captureBrowserError = captureBrowserError):
|
|
29
|
+
(instance: string, slug: string, refusal: string, error: unknown) => void {
|
|
30
|
+
const seen = new Set<string>();
|
|
31
|
+
return (instance, slug, refusal, error) => {
|
|
32
|
+
if (seen.has(instance)) return;
|
|
33
|
+
seen.add(instance);
|
|
34
|
+
try {
|
|
35
|
+
capture(error instanceof Error ? error : new Error(String(error)), { system: 'grid', build: buildId(), shard: slug, bootStage: 'playing',
|
|
36
|
+
fatal: false, screen: 'cell-unavailable', diagnostic: { refusal, cell: instance } });
|
|
37
|
+
} catch { /* a report never holds the refusal */ }
|
|
38
|
+
};
|
|
39
|
+
}
|