@wildshard/engine 0.1.18 → 0.1.20
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 +18 -0
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/package.json +19 -15
- 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 +33 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.mjs +4 -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 +31 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +83 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +2 -0
- 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.d.mts +1 -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 +18 -5
- package/scripts/docs-inputs-proof.mjs +6 -6
- 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 +284 -0
- package/scripts/grid-crossing-walk-proof.mjs +126 -17
- 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/land.mjs +2 -1
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +37 -12
- package/scripts/loading-flow/deskbench.mjs +276 -0
- package/scripts/loading-flow/stalls.d.mts +17 -3
- package/scripts/loading-flow/stalls.mjs +82 -3
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +61 -6
- 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/nightly-model.ts +9 -6
- package/scripts/offline-proof-rules.d.mts +2 -2
- package/scripts/offline-proof-rules.mjs +15 -4
- package/scripts/offline-proof.mjs +80 -13
- 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/parity/boot-smoke.mjs +13 -2
- package/scripts/pin-format.ts +5 -2
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins-reuse.d.mts +1 -0
- package/scripts/pins-reuse.mjs +22 -0
- 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/scratch-dir.mjs +95 -0
- package/scripts/scratch-sweep.mjs +182 -0
- 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.mjs +22 -4
- 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 +2 -14
- 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 +179 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +6 -2
- package/scripts/worker-client-play.mjs +6 -2
- package/scripts/worktree-reap.mjs +59 -13
- package/scripts/worktree.mjs +19 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +10 -2
- package/src/client/engine/anim/rigParser.ts +2 -2
- 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/texturePack.ts +2 -2
- package/src/client/engine/core/Game.ts +63 -19
- package/src/client/engine/core/gpuOnly.ts +10 -0
- package/src/client/engine/core/renderBudget.ts +134 -0
- package/src/client/engine/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 +68 -10
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +41 -11
- package/src/client/engine/render/dataLook.ts +219 -44
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +9 -1
- package/src/client/engine/render/families/registry.ts +11 -2
- package/src/client/engine/render/families/sceneSurface.ts +116 -0
- package/src/client/engine/render/look.ts +12 -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 +4 -2
- package/src/client/engine/render/tiers.ts +4 -1
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +24 -3
- 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/engine/world/declaredProps.ts +5 -1
- package/src/client/engine/world/skyRig.ts +4 -1
- package/src/client/engine/world/terrainTileView.ts +64 -23
- package/src/client/game/boot/audio.generated.ts +114 -114
- package/src/client/game/boot/bytes.generated.ts +118 -220
- 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 -5
- package/src/client/game/devScene/hook.ts +428 -0
- package/src/client/game/devScene/liveLook.ts +21 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +152 -19
- package/src/client/game/grid/liveSession.ts +53 -3
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/pageEntry.ts +12 -1
- package/src/client/game/grid/placedCells.ts +114 -12
- 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 +23 -10
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- 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/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 +32 -7
- 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 +9 -0
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +28 -8
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
- package/src/client/game/shardfile/clientViews.ts +36 -8
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +19 -7
- package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
- package/src/client/game/shardfile/groundMerge.ts +57 -5
- package/src/client/game/shardfile/hybrid.ts +2 -0
- 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/shardfile/slabLibrary.ts +115 -49
- package/src/client/game/shardfile/tileContent.ts +1 -1
- package/src/client/game/shardfile/tileDriver.ts +38 -11
- package/src/client/game/shardfile/wirePage.ts +7 -3
- package/src/client/game/shardfile/worldScenes.ts +17 -10
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/host/online/doctor.ts +22 -7
- package/src/client/host/online/doctorView.ts +2 -0
- package/src/client/host/online/linkScreens.ts +109 -5
- package/src/client/host/online/shell.ts +13 -4
- package/src/client/host/standalone/shell.ts +40 -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 +35 -7
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +87 -14
- 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 +18 -3
- 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 +22 -7
- 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 +112 -18
- package/src/server/host/dedicated/cellProtocol.ts +18 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +38 -11
- 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 +3 -2
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +135 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/workerTable.ts +32 -14
- package/src/server/host/dedicated/world.ts +65 -7
- 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 +57 -8
- package/src/server/host/standalone/serverProduct.ts +48 -16
- package/src/server/host/standalone/serverRuntime.ts +1 -1
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/engine/core/framePacing.ts +12 -1
- package/src/shared/engine/physics/terrainTiles.ts +20 -4
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +107 -0
- package/src/shared/game/devGameplay.ts +41 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/placementRows.ts +5 -2
- 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
|
@@ -4,18 +4,29 @@
|
|
|
4
4
|
// Shard Select card and `?chunk=<slug>` landed on the deck. The file is believed only under the API's placement key, as the box and
|
|
5
5
|
// SA35's preview bake believe it. A missing, late, unreadable or refused file keeps the build's grid: boot never waits past
|
|
6
6
|
// `PLACED_DEADLINE_MS` and never fails here. The bucket sends it `no-store`, the read asks `no-store`, and the service worker leaves
|
|
7
|
-
// `/releases/` to the network (sw.js `isContentRead`), so no
|
|
7
|
+
// `/releases/` to the network (sw.js `isContentRead`), so no cache serves an old file.
|
|
8
|
+
// OFFLINE OF20: the device keeps the last file it believed (its text, in OF0's `gridRoute` slot, beside the world's kept word), and
|
|
9
|
+
// the next page installs it at once, its signature checked again: offline, or on a link that hangs past the deadline, Shard Select
|
|
10
|
+
// still has the cells this device last saw. A fresh file read in time replaces it, from the build's own catalogue; a 404 drops it.
|
|
11
|
+
// PAGE-SIZE (time to the title): the device keep imports the saves slots (about 1.2 MB of chunks) only when it is read or written,
|
|
12
|
+
// never on the title's path: online it is read only once the fresh read is slow (`KEPT_AFTER_MS`) or fails, and written a while after.
|
|
8
13
|
import * as v from 'valibot';
|
|
9
14
|
import { Scope } from '@wildshard/engine/app/scope';
|
|
15
|
+
import type { Json, jsonSlot } from '@wildshard/engine/saves/slots';
|
|
10
16
|
import { GRID_RADIUS } from '@wildshard/format/contentBounds';
|
|
11
17
|
import { PLACEMENT_PUBLIC_KEY, PlacementSchema, SignedPlacementSchema, placementsURL, type PlacementFile } from '../../../shared/game/grid/placementRows';
|
|
12
18
|
import { installCatalogue, installedCatalogue, type CatalogueDocument } from '../../../shared/game/grid/catalogueSlot';
|
|
13
19
|
import { findTitleManifest, installTitleManifests, titleManifests } from '../shard/titleList';
|
|
14
20
|
import { catalogueCards } from './placedCards';
|
|
21
|
+
import { installPlacedContent, placedContent, type PlacedContent } from './placedContent';
|
|
15
22
|
import { parseGridCatalogue } from '../../../shared/game/grid/catalogue';
|
|
16
23
|
|
|
17
24
|
/** How long a page's boot waits for the file: GO4's 3 s, the world word's own deadline. A slower answer leaves the build's grid. */
|
|
18
25
|
export const PLACED_DEADLINE_MS = 3000;
|
|
26
|
+
/** OF20 with the title's time: an online page reads its kept file only once the fresh read has taken this long (or failed). */
|
|
27
|
+
export const KEPT_AFTER_MS = 600;
|
|
28
|
+
/** How long after the fresh file is believed the device keep writes it (its slots chunks load then, off the title's path). */
|
|
29
|
+
export const KEEP_WRITE_AFTER_MS = 5000;
|
|
19
30
|
|
|
20
31
|
type Cell = PlacementFile['cells'][number];
|
|
21
32
|
const hexBytes = (hex: string): Uint8Array<ArrayBuffer> => Uint8Array.from(hex.match(/../gu) ?? [], pair => Number.parseInt(pair, 16));
|
|
@@ -73,7 +84,33 @@ export function addPlacedCells(document: CatalogueDocument, file: PlacementFile,
|
|
|
73
84
|
|
|
74
85
|
/** What a page's read of its placement file did, for the console and the tests: `carded` names the added slugs whose card came
|
|
75
86
|
* from the API's catalogue (SA46). */
|
|
76
|
-
export type PlacedRead = { readonly added: readonly Cell[]; readonly left: readonly string[]; readonly serial: number; readonly carded: readonly string[]
|
|
87
|
+
export type PlacedRead = { readonly added: readonly Cell[]; readonly left: readonly string[]; readonly serial: number; readonly carded: readonly string[];
|
|
88
|
+
/** OF20: the device's kept file, because the fresh one did not come (why) */ readonly cached?: string } | { readonly kept: string };
|
|
89
|
+
/** OF20: the last placement file this device believed, by its address. */
|
|
90
|
+
export interface PlacedKeep {
|
|
91
|
+
readonly read: (url: string) => string | null | Promise<string | null>;
|
|
92
|
+
readonly write: (url: string, text: string | null) => void | Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/** OF20: in OF0's device slot `gridRoute` (oneWayIn.ts `deviceRouteMemory`), as `placed: { url, text }`: one store for the world's
|
|
95
|
+
* last word and its last layout. The slots module is imported on the first read or write, never with this file (PAGE-SIZE: it is
|
|
96
|
+
* about 1.2 MB of chunks the title would wait for). */
|
|
97
|
+
export function devicePlacedKeep(): PlacedKeep {
|
|
98
|
+
const slot = async (): Promise<ReturnType<typeof jsonSlot>> =>
|
|
99
|
+
(await import('@wildshard/engine/saves/slots')).jsonSlot('gridRoute', 'device');
|
|
100
|
+
const row = async (): Promise<Record<string, Json>> => { const value = (await slot()).read(); return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {}; };
|
|
101
|
+
return {
|
|
102
|
+
read: async url => {
|
|
103
|
+
try {
|
|
104
|
+
const placed = (await row())['placed'];
|
|
105
|
+
return typeof placed === 'object' && placed !== null && !Array.isArray(placed) && placed['url'] === url && typeof placed['text'] === 'string' ? placed['text'] : null;
|
|
106
|
+
} catch { return null; }
|
|
107
|
+
},
|
|
108
|
+
write: async (url, text) => {
|
|
109
|
+
try { const { placed: _old, ...rest } = await row(); (await slot()).write(text === null ? rest : { ...rest, placed: { url, text } }); }
|
|
110
|
+
catch { /* a device that keeps nothing reads the network only, as before */ }
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
77
114
|
export interface PlacedPorts {
|
|
78
115
|
readonly fetch?: typeof fetch;
|
|
79
116
|
readonly publicKey?: string;
|
|
@@ -88,7 +125,22 @@ export interface PlacedPorts {
|
|
|
88
125
|
readonly api?: string;
|
|
89
126
|
/** The catalogue lookups' own deadline (`placedCards.ts` `CARD_DEADLINE_MS`). */
|
|
90
127
|
readonly cardDeadlineMs?: number;
|
|
128
|
+
/** SA48: a carded slug's content from the cook (`placedContent.ts`), by the hash its cell names; default: this page's build's index in
|
|
129
|
+
* the store at the placement file's origin. A slug with none stays out. */
|
|
130
|
+
readonly content?: (slug: string, hash: string | undefined, signal: AbortSignal) => Promise<PlacedContent | undefined>;
|
|
131
|
+
/** OF20: where the last believed file is kept (default: the device, `devicePlacedKeep`) */
|
|
132
|
+
readonly keep?: PlacedKeep;
|
|
133
|
+
/** An online page reads its kept file once the fresh read has taken this long (default `KEPT_AFTER_MS`); offline at once. */
|
|
134
|
+
readonly keptAfterMs?: number;
|
|
135
|
+
/** The fresh file is kept this long after it is believed (default `KEEP_WRITE_AFTER_MS`; the default keep only). */
|
|
136
|
+
readonly keepWriteAfterMs?: number;
|
|
91
137
|
}
|
|
138
|
+
/** The cook's content for a placed slug, from the store the placement file is in, for this page's build under its own validator. */
|
|
139
|
+
const cookContent = (url: string, read: typeof fetch): NonNullable<PlacedPorts['content']> => (slug, hash, signal) => {
|
|
140
|
+
const build: unknown = Reflect.get(globalThis, '__WS_BUILD_ID__'), validator: unknown = Reflect.get(globalThis, '__WS_SHARDFILE_VALIDATOR__');
|
|
141
|
+
return hash === undefined || typeof build !== 'string' ? Promise.resolve(undefined)
|
|
142
|
+
: placedContent(slug, hash, { fetch: read, signal, packs: new URL('/', url).href, build, validator: typeof validator === 'string' ? validator : null });
|
|
143
|
+
};
|
|
92
144
|
/** After every row's `order`, so a carded shard is last in the deck. */
|
|
93
145
|
const nextOrder = (rows: readonly { readonly order?: number }[]): number => rows.reduce((top, row) => Math.max(top, row.order ?? 0), rows.length) + 1;
|
|
94
146
|
/** Read the file at `url` and install the build's catalogue with its cells. Never throws: anything but a believed file keeps the build's
|
|
@@ -102,28 +154,78 @@ export async function learnPlacedCells(url: string, ports: PlacedPorts = {}): Pr
|
|
|
102
154
|
const abort = new AbortController(), stop = (): void => { abort.abort(); };
|
|
103
155
|
scope.timeout(ports.deadlineMs ?? PLACED_DEADLINE_MS, stop);
|
|
104
156
|
if (ports.signal?.aborted === true) stop(); else if (ports.signal !== undefined) scope.listen(ports.signal, 'abort', stop);
|
|
105
|
-
const response = await (ports.fetch ?? fetch)(url, { cache: 'no-store', credentials: 'omit', redirect: 'error', signal: abort.signal });
|
|
106
|
-
if (response.status === 404) return { kept: 'no placement file (404): nothing placed on this channel' };
|
|
107
|
-
if (!response.ok) return { kept: `placement file ${String(response.status)}` };
|
|
108
|
-
const file = await readSignedPlacement(await response.text(), ports.publicKey);
|
|
109
157
|
const channel = /\/releases\/(staging|production)-placements\.json$/u.exec(new URL(url).pathname)?.[1];
|
|
110
|
-
|
|
158
|
+
const believe = async (text: string): Promise<PlacementFile> => {
|
|
159
|
+
const read = await readSignedPlacement(text, ports.publicKey);
|
|
160
|
+
if (channel !== undefined && read.channel !== channel) throw new Error(`a ${read.channel} placement file at the ${channel} address`);
|
|
161
|
+
return read;
|
|
162
|
+
};
|
|
111
163
|
const known = ports.known ?? (slug => findTitleManifest(slug) !== undefined);
|
|
112
164
|
// the page's own deadline, read afresh after each wait: once it fires the boot has gone on
|
|
113
165
|
const wentOn = (): boolean => ports.signal?.aborted === true;
|
|
166
|
+
// OF20: the kept file, so a page whose read never comes still has the layout this device last saw. Offline it is read at once;
|
|
167
|
+
// online only once the fresh read is slow or fails, so the title never waits for the keep's chunks (PAGE-SIZE). A fresh file
|
|
168
|
+
// installed first wins: the kept one never replaces it.
|
|
169
|
+
const keep = ports.keep ?? devicePlacedKeep();
|
|
170
|
+
let cached: { readonly added: readonly Cell[]; readonly left: readonly string[]; readonly serial: number } | undefined, fresh = false;
|
|
171
|
+
let keptRead: Promise<void> | undefined;
|
|
172
|
+
const readKept = (): Promise<void> => (keptRead ??= (async () => {
|
|
173
|
+
const held = await keep.read(url);
|
|
174
|
+
if (held === null || fresh) return;
|
|
175
|
+
try {
|
|
176
|
+
const file = await believe(held), kept = addPlacedCells(document, file, known);
|
|
177
|
+
if (!fresh && !wentOn() && kept.added.length > 0) { installCatalogue(kept.document); cached = { added: kept.added, left: kept.left, serial: file.serial }; }
|
|
178
|
+
} catch { await keep.write(url, null); } // a kept file this build no longer believes is dropped
|
|
179
|
+
})().catch(() => undefined));
|
|
180
|
+
if (typeof navigator !== 'undefined' && !navigator.onLine) void readKept();
|
|
181
|
+
else scope.timeout(ports.keptAfterMs ?? KEPT_AFTER_MS, () => { void readKept(); });
|
|
182
|
+
const fallBack = async (why: string): Promise<PlacedRead> => {
|
|
183
|
+
await readKept();
|
|
184
|
+
return cached === undefined ? { kept: why } : { ...cached, carded: [], cached: why };
|
|
185
|
+
};
|
|
186
|
+
let response: Response;
|
|
187
|
+
try { response = await (ports.fetch ?? fetch)(url, { cache: 'no-store', credentials: 'omit', redirect: 'error', signal: abort.signal }); }
|
|
188
|
+
catch (error) { return await fallBack(error instanceof Error ? error.message : String(error)); }
|
|
189
|
+
if (response.status === 404) {
|
|
190
|
+
// nothing placed on this channel now: the kept cells leave too
|
|
191
|
+
fresh = true;
|
|
192
|
+
await keep.write(url, null);
|
|
193
|
+
if (cached !== undefined && !wentOn()) installCatalogue(document);
|
|
194
|
+
return { kept: 'no placement file (404): nothing placed on this channel' };
|
|
195
|
+
}
|
|
196
|
+
if (!response.ok) return await fallBack(`placement file ${String(response.status)}`);
|
|
197
|
+
let text: string, file: PlacementFile;
|
|
198
|
+
try { text = await response.text(); file = await believe(text); }
|
|
199
|
+
catch (error) { return await fallBack(error instanceof Error ? error.message : String(error)); }
|
|
114
200
|
const placed = addPlacedCells(document, file, known);
|
|
115
|
-
|
|
116
|
-
if (
|
|
201
|
+
// only a file that places cleanly is kept; the device keep writes it a while later, off the title's path
|
|
202
|
+
if (ports.keep === undefined) {
|
|
203
|
+
const believed = text, later = new Scope('grid.placed-keep');
|
|
204
|
+
later.timeout(ports.keepWriteAfterMs ?? KEEP_WRITE_AFTER_MS, () => { void keep.write(url, believed); later.dispose(); });
|
|
205
|
+
}
|
|
206
|
+
else await keep.write(url, text);
|
|
207
|
+
if (wentOn()) return await fallBack('the page went on before the placement file was read');
|
|
208
|
+
fresh = true;
|
|
209
|
+
// from the build's own catalogue, so the fresh file replaces the kept one's cells
|
|
210
|
+
if (placed.added.length > 0 || cached !== undefined) installCatalogue(placed.document);
|
|
117
211
|
// SA46: a cell the box would open whose slug this build has no card for (an upload after the build) is carded from its catalogue
|
|
118
212
|
// entry, after the build's own cells are in, so a slow or absent API costs them nothing; a slug it does not card stays out
|
|
119
213
|
const unknown = addPlacedCells(placed.document, file).added.map(cell => cell.slug);
|
|
120
214
|
const built = { added: placed.added, left: placed.left, serial: file.serial, carded: [] };
|
|
121
215
|
if (unknown.length === 0) return built;
|
|
122
|
-
|
|
123
|
-
|
|
216
|
+
// SA48: its content from the cook beside its card, so ENTER WORLD loads it; a card with no content would only fail at the door
|
|
217
|
+
const hashes = new Map(file.cells.map(cell => [cell.slug, cell.hash])), content = ports.content ?? cookContent(url, ports.fetch ?? fetch);
|
|
218
|
+
const [cards, contents] = await Promise.all([
|
|
219
|
+
catalogueCards(unknown, { fetch: ports.fetch ?? fetch, signal: abort.signal, order: nextOrder(titleManifests()), ...(ports.api === undefined ? {} : { api: ports.api }),
|
|
220
|
+
...(ports.cardDeadlineMs === undefined ? {} : { deadlineMs: ports.cardDeadlineMs }) }),
|
|
221
|
+
Promise.all(unknown.map(slug => content(slug, hashes.get(slug), abort.signal).catch(() => undefined))),
|
|
222
|
+
]);
|
|
223
|
+
const cooked = new Map<string, PlacedContent>();
|
|
224
|
+
unknown.forEach((slug, n) => { const found = contents[n]; if (found !== undefined) cooked.set(slug, found); });
|
|
124
225
|
if (cards.length === 0 || wentOn()) return built;
|
|
125
|
-
const carded = new Set(cards.map(row => row.slug)), more = addPlacedCells(placed.document, file, slug => carded.has(slug));
|
|
226
|
+
const carded = new Set(cards.filter(row => cooked.has(row.slug)).map(row => row.slug)), more = addPlacedCells(placed.document, file, slug => carded.has(slug));
|
|
126
227
|
const opened = new Set(more.added.map(cell => cell.slug)), rows = cards.filter(row => opened.has(row.slug));
|
|
228
|
+
for (const slug of opened) { const found = cooked.get(slug); if (found !== undefined) installPlacedContent(found); }
|
|
127
229
|
if (more.added.length > 0) installCatalogue(more.document);
|
|
128
230
|
if (rows.length > 0) installTitleManifests([...titleManifests(), ...rows]);
|
|
129
231
|
return { added: [...placed.added, ...more.added], left: more.left, serial: file.serial, carded: rows.map(row => row.slug) };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// SHARD-AUTHORING SA48 (meta SHARD-AUTHORING-PLAN): the content of a shard the API placed after this page was built. SA46 cards it, but
|
|
2
|
+
// entering reads its client product from the build's spawn rows, which no build has for a new author's upload. The cook does (MMO-SERVER
|
|
3
|
+
// MS2.4): for this build and the bytes the signed placement file names (`hash`, SA47 (1)) it writes `index/<build>/<hash>.json` beside
|
|
4
|
+
// its manifests, parts and header in the packs store. This reads that index and each manifest it names, and gives the rows a bake's
|
|
5
|
+
// `addCookedShards` would have written (the entry and whole-level addresses, the store as their home, whether it recorded programs),
|
|
6
|
+
// with the page's admission row for its header (`productVerdict`'s, believed only under this page's own validator revision). Any
|
|
7
|
+
// failure (no index yet, a 404, junk, another build's or slug's index, another validator) gives nothing, and the slug stays out.
|
|
8
|
+
import * as v from 'valibot';
|
|
9
|
+
import { bareSlug } from '../../../shared/game/grid/catalogueSlot';
|
|
10
|
+
import { readSpawnManifest, readSpawnManifestAddress, type SpawnManifestAddress } from '../../../shared/game/shardfile/spawnManifest';
|
|
11
|
+
import { cookIndexPath } from '../../../shared/game/shardfile/serverPack';
|
|
12
|
+
import { installPlacedSpawn, type PlacedSpawn } from '../boot/placedSpawn';
|
|
13
|
+
|
|
14
|
+
/** An index is a few KB; a manifest is at most `readSpawnManifestAddress`'s 2 MB. */
|
|
15
|
+
const INDEX_BYTES = 256 * 1024, MANIFEST_BYTES = 2_000_000;
|
|
16
|
+
const size = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
|
|
17
|
+
const hex = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
|
|
18
|
+
const ManifestRow = v.object({ url: v.pipe(v.string(), v.regex(/^\/assets\/spawn\/[a-z0-9_-]+-(?:entry|whole)-(?:phone|desktop)-[a-f0-9]{16}\.json$/u)),
|
|
19
|
+
tier: v.picklist(['phone', 'desktop']), set: v.picklist(['entry', 'whole']), files: size, totalBytes: size, wireBytes: size });
|
|
20
|
+
const IndexSchema = v.object({ version: v.literal(1), build: v.string(), slug: v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u)), hash: hex, header: v.string(),
|
|
21
|
+
manifests: v.pipe(v.array(ManifestRow), v.maxLength(8)), keys: v.pipe(v.array(v.string()), v.maxLength(100_000)), loose: v.string(),
|
|
22
|
+
verdict: v.optional(v.looseObject({ revision: hex, sourceHash: v.string(), indexHash: hex, residentBytes: v.pipe(v.number(), v.safeInteger(), v.minValue(1)),
|
|
23
|
+
postCost: v.looseObject({}), worst: v.optional(v.unknown()) })) });
|
|
24
|
+
|
|
25
|
+
/** What a placed slug needs to enter: its spawn rows and its header's admission row. */
|
|
26
|
+
export interface PlacedContent { readonly spawn: PlacedSpawn; readonly verdict: Readonly<Record<string, unknown>> | null }
|
|
27
|
+
export interface PlacedContentPorts {
|
|
28
|
+
readonly fetch: typeof fetch;
|
|
29
|
+
readonly signal: AbortSignal;
|
|
30
|
+
/** The store's root: the placement file's origin (`https://packs.wildshard.io/`), where the cook writes. */
|
|
31
|
+
readonly packs: string;
|
|
32
|
+
/** This page's build (`__BUILD_ID__`), the cook's folder. */
|
|
33
|
+
readonly build: string;
|
|
34
|
+
/** This page's validator revision (`__WS_SHARDFILE_VALIDATOR__`); null on a page with none (the dev server), which admits by no row. */
|
|
35
|
+
readonly validator: string | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function bounded(response: Response, cap: number): Promise<Uint8Array<ArrayBuffer>> {
|
|
39
|
+
if (!response.ok) { await response.body?.cancel(); throw new Error(`HTTP ${String(response.status)}`); }
|
|
40
|
+
const body = new Uint8Array(await response.arrayBuffer());
|
|
41
|
+
if (body.byteLength > cap) throw new Error('Too large');
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
const decode = (bytes: Uint8Array): unknown => JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
|
|
45
|
+
|
|
46
|
+
/** The cook's content for `slug` at `hash`, or undefined for anything but this build's index of these bytes. Never throws. */
|
|
47
|
+
export async function placedContent(slug: string, hash: string, ports: PlacedContentPorts): Promise<PlacedContent | undefined> {
|
|
48
|
+
try {
|
|
49
|
+
if (!/^[a-f0-9]{64}$/u.test(hash) || !/^[\w.-]{1,64}$/u.test(ports.build) || !ports.packs.endsWith('/')) return undefined;
|
|
50
|
+
const read = ports.fetch, at = (path: string): string => new URL(path.replace(/^\//u, ''), ports.packs).href;
|
|
51
|
+
// past the CDN's cached 404 (a query of its own, as the box reads it, SA47): an index missing now may be written a minute later
|
|
52
|
+
// (to the minute, so the edge still takes a busy page's repeats)
|
|
53
|
+
const indexAt = `${at(cookIndexPath(ports.build, hash))}?t=${String(Math.floor(Date.now() / 60_000))}`;
|
|
54
|
+
const index = v.parse(IndexSchema, decode(await bounded(await read(indexAt, { cache: 'no-store', credentials: 'omit', redirect: 'error', signal: ports.signal }), INDEX_BYTES)));
|
|
55
|
+
const product = index.slug;
|
|
56
|
+
if (index.build !== ports.build || index.hash !== hash || product !== bareSlug(slug) || index.header !== `shardfiles/${product}/shard.json`
|
|
57
|
+
|| index.loose !== `loose/${hash}/`) return undefined;
|
|
58
|
+
// a page that checks admission admits only a header its own validator's revision passed; a page with none asks nothing
|
|
59
|
+
if (ports.validator !== null && index.verdict?.revision !== ports.validator) return undefined;
|
|
60
|
+
// each manifest's own length is its address's (`readSpawnManifestAddress`); it is content-named, so this read is the download's
|
|
61
|
+
const addresses = await Promise.all(index.manifests.map(async row => {
|
|
62
|
+
const body = await bounded(await read(at(row.url), { credentials: 'omit', redirect: 'error', signal: ports.signal }), MANIFEST_BYTES);
|
|
63
|
+
const manifest = readSpawnManifest(decode(body));
|
|
64
|
+
if (manifest.shard !== product || manifest.tier !== row.tier || manifest.files.length !== row.files || manifest.totalBytes !== row.totalBytes) throw new Error(`${row.url} is not its row`);
|
|
65
|
+
return { row, address: readSpawnManifestAddress({ url: row.url, bytes: body.byteLength, totalBytes: row.totalBytes, files: row.files, wireBytes: row.wireBytes }) };
|
|
66
|
+
}));
|
|
67
|
+
const pick = (set: 'entry' | 'whole'): Partial<Record<'phone' | 'desktop', SpawnManifestAddress>> =>
|
|
68
|
+
Object.fromEntries(addresses.filter(({ row }) => row.set === set).map(({ row, address }) => [row.tier, address]));
|
|
69
|
+
const entry = pick('entry');
|
|
70
|
+
if (entry.phone === undefined || entry.desktop === undefined) return undefined;
|
|
71
|
+
const verdict = index.verdict === undefined ? null : { ...index.verdict, path: `/${index.header}` };
|
|
72
|
+
return { spawn: { slug: product, entry, whole: pick('whole'), base: ports.packs, loose: at(index.loose),
|
|
73
|
+
programs: index.keys.includes(`${index.loose}programs/${product}.json`) }, verdict };
|
|
74
|
+
} catch { return undefined; }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Make a placed slug's content this page's: its spawn rows for the download, and its admission row beside the build's own. */
|
|
78
|
+
export function installPlacedContent(content: PlacedContent): void {
|
|
79
|
+
installPlacedSpawn(content.spawn);
|
|
80
|
+
const verdicts: unknown = Reflect.get(globalThis, '__WS_SHARDFILE_VERDICTS__');
|
|
81
|
+
if (content.verdict === null || !Array.isArray(verdicts)) return;
|
|
82
|
+
// one row a path: a later learn of another upload replaces this page's earlier one (the build's own paths are never placed slugs)
|
|
83
|
+
const at = verdicts.findIndex((row: unknown) => typeof row === 'object' && row !== null && Reflect.get(row, 'path') === content.verdict?.['path']);
|
|
84
|
+
if (at === -1) verdicts.push(content.verdict); else verdicts.splice(at, 1, content.verdict);
|
|
85
|
+
}
|
|
@@ -25,6 +25,7 @@ import type { OfflineDownloadEnd } from '@wildshard/engine/ui/offlineDownload';
|
|
|
25
25
|
import { hasCachedAsset, cacheAsset } from '../shardfile/assetCache';
|
|
26
26
|
import { builtIndexHash, builtIndexHashes } from '@wildshard/format/builtIndexes';
|
|
27
27
|
import { readPrefetchIndex } from './prefetchIndex';
|
|
28
|
+
import { markPackMissing, packGone, packMissing } from '../../../shared/game/shardfile/packReads';
|
|
28
29
|
import type { GridAssembly } from '../../../shared/game/grid/assembly';
|
|
29
30
|
import {TIER, MOBILE_DEVICE, type Tier} from '@wildshard/engine/core/tier';
|
|
30
31
|
import { prefetchRing } from './titleOrder';
|
|
@@ -181,7 +182,14 @@ class GridPrefetch {
|
|
|
181
182
|
}
|
|
182
183
|
for (const pack of index.packs ?? []) {
|
|
183
184
|
const members = byPack.get(pack.hash);
|
|
184
|
-
if (members
|
|
185
|
+
if (members === undefined || this.status.reason !== null) continue;
|
|
186
|
+
// PZ7: a pack that is not published (or fails) leaves its members to their loose URLs
|
|
187
|
+
if (packMissing(pack)) { loose.push(...members); continue; }
|
|
188
|
+
try { await this.pack(pack, members, base, { holds, keepAsset }, quota); }
|
|
189
|
+
catch (error: unknown) {
|
|
190
|
+
if (!packGone(error)) throw error; // an abort, or a pack refused for its bytes
|
|
191
|
+
markPackMissing(pack, error); loose.push(...members);
|
|
192
|
+
}
|
|
185
193
|
}
|
|
186
194
|
rows.splice(0, rows.length, ...loose);
|
|
187
195
|
let next = 0;
|
|
@@ -10,6 +10,22 @@ export class ApproachInputsDeferredError extends Error {
|
|
|
10
10
|
constructor() { super('Product input residency admission deferred'); this.name = 'ApproachInputsDeferredError'; }
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
/** GC6: reads in flight for a world's input read-back, and for a cancellable approach's. */
|
|
14
|
+
export const INPUT_READS = 16, APPROACH_INPUT_READS = 12;
|
|
15
|
+
/** Run `read` over `refs` with at most `width` in flight; the first failure stops new reads, waits for those in flight and
|
|
16
|
+
* throws. `active` is checked before each new read (it throws on cancellation). */
|
|
17
|
+
export async function readWindow(refs: readonly string[], width: number, active: () => void, read: (ref: string) => Promise<void>): Promise<void> {
|
|
18
|
+
let next = 0, failure: { readonly error: unknown } | undefined;
|
|
19
|
+
const lane = async (): Promise<void> => {
|
|
20
|
+
while (failure === undefined && next < refs.length) {
|
|
21
|
+
const ref = refs[next++]; if (ref === undefined) return;
|
|
22
|
+
try { active(); await read(ref); } catch (error) { failure ??= { error }; }
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
await Promise.all(Array.from({ length: Math.min(width, refs.length) }, lane));
|
|
26
|
+
if (failure !== undefined) throw failure.error;
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
/** One admitted grid product's transient inputs, shared by overlapping preparations, never by finished promises. */
|
|
14
30
|
export class ProductInputs {
|
|
15
31
|
readonly reader: ClientAssets;
|
|
@@ -72,16 +88,13 @@ export class ProductInputs {
|
|
|
72
88
|
const bytes = missing.reduce((sum, ref) => sum + (source.files.find(file => file.hash === ref)?.compressed ?? source.requires.commonsWire[ref.replace(/^commons:/u, '')] ?? 0), 0);
|
|
73
89
|
const lease = this.reserve(bytes, signal !== undefined), loaded = new Map<string, Uint8Array>();
|
|
74
90
|
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
loaded.set(ref, result.value);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
91
|
+
// GC9: a cell's world reads its inputs back from the cache before it builds (Pine: about 1,500 files); one at a time
|
|
92
|
+
// that read was most of the build behind a moving player's loading wall.
|
|
93
|
+
// GC6 (QA 11-14 row 6): each read is a cache round trip that waits on drawn frames, so it is latency-bound, not
|
|
94
|
+
// byte-bound: Nalati's ~860 inputs in lockstep batches of four took 20 s of its world's 30 s at Jake's 2992x1434@2.
|
|
95
|
+
// A sliding window keeps INPUT_READS (a cancellable approach APPROACH_INPUT_READS) in flight; the bytes held are
|
|
96
|
+
// the same (all of them are kept, and the lease above already charges them).
|
|
97
|
+
await readWindow(missing, signal === undefined ? INPUT_READS : APPROACH_INPUT_READS, active, async ref => { loaded.set(ref, await this.reader.read(ref)); });
|
|
85
98
|
active();
|
|
86
99
|
for (const [ref, value] of loaded) this.assets.set(ref, value);
|
|
87
100
|
this.claims.push({ refs: new Set(missing), bytes, lease });
|
|
@@ -4,6 +4,9 @@ import { ApproachInputsDeferredError } from './productInputs';
|
|
|
4
4
|
import { productResidentBytesSteps } from '../shardfile/productCost';
|
|
5
5
|
import { workSlice } from '@wildshard/engine/core/workSlice';
|
|
6
6
|
|
|
7
|
+
/** A required product read the shared budget refused for now (not a broken product). */
|
|
8
|
+
export const PRODUCT_DEFERRED = 'Product residency admission deferred';
|
|
9
|
+
|
|
7
10
|
/** A caller holds the product while any admitted source or immutable transport bytes are still in use. */
|
|
8
11
|
export interface ProductLease<T> { readonly value: T; release: () => void }
|
|
9
12
|
interface Entry<T> { promise: Promise<T>; claim: ResidencyLease | undefined; bytes: number; users: number; settled: boolean; failed: boolean; optional: boolean }
|
|
@@ -37,7 +40,7 @@ export class ProductLeases<T> {
|
|
|
37
40
|
const request = { id: `product:${this.owner}:${key}`, category: 'product' as const, owner: this.owner,
|
|
38
41
|
bytes: fresh.bytes, distance: 0, needed: true, evictSync: () => { this.entries.delete(key); fresh.claim = undefined; } };
|
|
39
42
|
const claim = fresh.optional ? this.allocator.reserveIfFits(request) : this.allocator.reserve(request);
|
|
40
|
-
if (claim === null) { if (fresh.optional) throw new ApproachInputsDeferredError(); throw new Error(
|
|
43
|
+
if (claim === null) { if (fresh.optional) throw new ApproachInputsDeferredError(); throw new Error(PRODUCT_DEFERRED); } fresh.claim = claim;
|
|
41
44
|
}, bytes => {
|
|
42
45
|
if (this.closed) return; // A decoder completing after page disposal has no live claim to reduce.
|
|
43
46
|
if (fresh.claim === undefined) throw new Error('Transport release needs a product claim');
|
|
@@ -27,7 +27,7 @@ import * as v from 'valibot';
|
|
|
27
27
|
import { GridAdmissionPriority } from './admissionPriority';
|
|
28
28
|
import { timeClientPreparation } from '../shardfile/preparationTiming';
|
|
29
29
|
import { readCheckedOutputIndex } from '../../../shared/game/shardfile/outputIndexChecks';
|
|
30
|
-
import { packReads, type PackReads } from '../../../shared/game/shardfile/packReads';
|
|
30
|
+
import { packOrLoose, packReads, type PackReads } from '../../../shared/game/shardfile/packReads';
|
|
31
31
|
|
|
32
32
|
const edgeRows = v.strictObject({ edge: EdgeProfilesSchema, entryways: EntrywaysSchema });
|
|
33
33
|
const farRow = v.looseObject({ far: v.nullable(v.looseObject({ decoded: v.number(), gpu: v.number() })) });
|
|
@@ -82,7 +82,9 @@ async function readGridProductFile(at: GridProductIndex, path: string, hash: str
|
|
|
82
82
|
if(native!==undefined)return native(address,size,undefined,hash);
|
|
83
83
|
const held = await options.cache?.asset(base, hash) ?? await options.cachedResponse?.(address, hash, size);
|
|
84
84
|
if ((held === null || held === undefined) && options.offline) throw new Error(`Missing cached grid product file ${path}`);
|
|
85
|
-
const
|
|
85
|
+
const loose = async (): Promise<Uint8Array> => boundedResponse(await options.fetch(address), size);
|
|
86
|
+
// PZ7: a pack that is not published (or fails) falls back to the file's own URL
|
|
87
|
+
const bytes = held ?? (at.packed.has(hash) ? await packOrLoose(() => at.packed.read(hash), loose) : await loose());
|
|
86
88
|
if (bytes.length !== size || await options.hash(bytes) !== hash) throw new Error(`Grid product file ${path} hash or size mismatch`);
|
|
87
89
|
if (held === null || held === undefined) {
|
|
88
90
|
const cache = options.cache;
|
|
@@ -343,8 +345,10 @@ export function gridShardfileProduct(slug: string, owner: GridProductOwner, mode
|
|
|
343
345
|
const input = options.firstPartyRead===undefined
|
|
344
346
|
? await readIndexBytes(await boundedResponse(await options.fetch(url.href), limits.sourceBytes), options)
|
|
345
347
|
: await readProductDescriptor(options,url);
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
+
// GC9: the runtime-only wires released below are never read here (Pine's read fetched and hashed ~1,500 files twice)
|
|
349
|
+
const admitted = await timeClientPreparation(slug, 'product.read', () => admitProduct(input, { ...options, reserve, deferred: source => neighbourProductFilesPaced(source, options.pause) }));
|
|
350
|
+
// GC9: the files admission left unread stay selected inputs (approach and tile admissions read them back by name)
|
|
351
|
+
const selectedInputs = [...admitted.assets.keys(), ...admitted.unread ?? []];
|
|
348
352
|
// admission already refused a stack past the budget on its own; the cost is what placement sums per adjacent pair
|
|
349
353
|
gridPostCosts(owner.allocator).record(slug, productPostCost(admitted.source, (hash) => admitted.assets.get(hash)));
|
|
350
354
|
const preparation: { inputs?: ProductInputs } = {};
|
|
@@ -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');
|