@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
|
@@ -46,7 +46,7 @@ export async function leaseClientLibrary(source: Shardfile, assets: ReadonlyMap<
|
|
|
46
46
|
}
|
|
47
47
|
for (const hash of source.requires.commons) {
|
|
48
48
|
const bytes = assets.get(`commons:${hash}`) ?? await ports.read?.(`commons:${hash}`); if (bytes === undefined) throw new Error('Missing admitted commons residency');
|
|
49
|
-
const { assetCost, prepareAssetDecoders } = await import('@wildshard/format/
|
|
49
|
+
const { assetCost, prepareAssetDecoders } = await import('@wildshard/format/shardfileAssets');
|
|
50
50
|
await prepareAssetDecoders();
|
|
51
51
|
const cost = assetCost('commons', bytes);
|
|
52
52
|
claims.push({ id: `commons:${hash}`, category: 'commons', bytes: cost.decoded + cost.gpu, owner: 'platform', distance: 0, needed: true });
|
|
@@ -23,6 +23,7 @@ import { materialGraphIr } from '@wildshard/format/materials';
|
|
|
23
23
|
import { FAMILY_IDS } from '@wildshard/format/materialFamilies';
|
|
24
24
|
import { propMaterialSlots, propSlotUse, type PropMaterials, type PropTextureSlot } from '@wildshard/format/propMaterials';
|
|
25
25
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
26
|
+
import { sceneSurfaceChannels } from '@wildshard/engine/render/families/sceneSurface';
|
|
26
27
|
|
|
27
28
|
const WRAPS: Readonly<Record<number, Wrapping>> = { 33071: ClampToEdgeWrapping, 33648: MirroredRepeatWrapping, 10497: RepeatWrapping };
|
|
28
29
|
const MAG: Readonly<Record<number, MagnificationTextureFilter>> = { 9728: NearestFilter, 9729: LinearFilter };
|
|
@@ -90,7 +91,9 @@ export async function propSurfaces(materials: PropMaterials, ports: {
|
|
|
90
91
|
for (const [slot, value] of slots) { const param = params[slot]; if (param?.type !== 'texture' && slot === 'colour' && graphUsesMeshMap(graph)) continue; if (param?.type !== 'texture') throw new Error(`props material "${name}": graph ${row.id} has no texture param ${slot}`); params[slot] = { ...param, value: value.file }; }
|
|
91
92
|
material = ownedGraph(ports.compile({ family: 'graph', graph: { ...graph, params } }), `${row.id}:${name}`);
|
|
92
93
|
} else material = base(row.id);
|
|
93
|
-
|
|
94
|
+
// SHARD-SOURCE AP11, AP12: a card reads its corners and a swaying surface its sway from their GLB channels
|
|
95
|
+
const channels = sceneSurfaceChannels(entry);
|
|
96
|
+
resolved.set(name, { material, maps, ...(channels === null ? {} : { channels }) });
|
|
94
97
|
}
|
|
95
98
|
return (name) => {
|
|
96
99
|
const binding = resolved.get(name);
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* the optional `outline` hook (`clientMaterials().outline`): a graph that declares `stages.outline` draws its hull as each
|
|
7
7
|
* mesh's second draw (terrain tiles, fine prop tiles, library panels and models; the coarse L1 proxy keeps one draw).
|
|
8
8
|
*/
|
|
9
|
-
import { AdditiveBlending, Box3, BufferAttribute, BufferGeometry, Material, Mesh, StaticDrawUsage, type Object3D, type Texture } from 'three';
|
|
9
|
+
import { AdditiveBlending, Box3, BufferAttribute, BufferGeometry, Material, Mesh, ShaderMaterial, StaticDrawUsage, type Object3D, type Texture } from 'three';
|
|
10
10
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
11
|
+
import { installTerrainTile, isCoarse, maskTerrainTile } from '@wildshard/engine/world/terrainTileView';
|
|
12
|
+
import { decodeTerrainTile, type TerrainTileData } from '@wildshard/format/terrainTileBytes';
|
|
13
13
|
import { coarseTileMask } from '@wildshard/engine/world/coarseTileMask';
|
|
14
14
|
import { installDeclaredProps, type PropSurfaceBinding } from '@wildshard/engine/world/declaredProps';
|
|
15
15
|
import type { ClientWorldViews, ResidentTile } from './tileContent';
|
|
16
16
|
import type { GraphOutlineHook } from './clientGraphs';
|
|
17
|
-
import { groundMerge } from './groundMerge';
|
|
17
|
+
import { groundMerge, mergeView } from './groundMerge';
|
|
18
18
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
19
19
|
import { geometryBoundsSteps } from '@wildshard/engine/world/geometryBounds';
|
|
20
20
|
import { workSlice } from '@wildshard/engine/core/workSlice';
|
|
@@ -28,6 +28,21 @@ const FLAT = 0.01, FLOOR = 0.1;
|
|
|
28
28
|
const isGlow = (material: Material): boolean => material.userData['graphRawOutput'] === true && material.userData['graphMeshMap'] !== true;
|
|
29
29
|
|
|
30
30
|
function isMesh(object: Object3D): object is Mesh { return object instanceof Mesh; }
|
|
31
|
+
/**
|
|
32
|
+
* SHARD-SOURCE AP8: a fine tile mesh that may draw in its material's cross-tile merge: a plain drawn mesh (not instanced or
|
|
33
|
+
* skinned, no morphs, no groups, no hull under it) on one opaque built-in family material. Left out: see-through surfaces
|
|
34
|
+
* and cards (they sort or face the camera one by one), swaying ones (a phase per prop), graph shaders (they may read
|
|
35
|
+
* the mesh's own space) and mirrored meshes.
|
|
36
|
+
*/
|
|
37
|
+
function mergeable(mesh: Mesh): mesh is Mesh<BufferGeometry, Material> {
|
|
38
|
+
const material: unknown = mesh.material, geometry: unknown = mesh.geometry;
|
|
39
|
+
if (Object.getPrototypeOf(mesh) !== Mesh.prototype || !mesh.visible || mesh.children.length > 0 || !isMaterial(material) || !isGeometry(geometry)) return false;
|
|
40
|
+
if (material instanceof ShaderMaterial || material.transparent || material.userData['sceneAlpha'] === true || material.userData['sceneCard'] === true) return false;
|
|
41
|
+
if (geometry.groups.length > 0 || Object.keys(geometry.morphAttributes).length > 0 || !geometry.hasAttribute('position')) return false;
|
|
42
|
+
// a mirrored mesh (negative scale) would keep its triangles' order in the merge and turn inside out: three flips winding per object
|
|
43
|
+
mesh.updateWorldMatrix(true, false); if (mesh.matrixWorld.determinant() < 0) return false;
|
|
44
|
+
return Object.keys(geometry.attributes).every((name) => !name.startsWith('_') && !name.startsWith('ws'));
|
|
45
|
+
}
|
|
31
46
|
/** a fine tile has nothing under it to hide */
|
|
32
47
|
function noMask(excluded: ReadonlySet<number>): void { if (excluded.size > 0) throw new Error('shardfile views: only a coarse tile masks quadrants'); }
|
|
33
48
|
|
|
@@ -37,7 +52,8 @@ function noMask(excluded: ReadonlySet<number>): void { if (excluded.size > 0) th
|
|
|
37
52
|
* only attaches it. Terrain takes wire bytes or `TerrainTileData` already decoded off the main thread.
|
|
38
53
|
*/
|
|
39
54
|
export interface ClientTileViews {
|
|
40
|
-
|
|
55
|
+
/** `ground`: where fine tiles merge (AP8; absent: `root`); a ring passes its shared root, as for props */
|
|
56
|
+
terrain: (input: Uint8Array | TerrainTileData, root: Object3D, scope: Scope, shadow: boolean, ground?: Object3D) => ResidentTile;
|
|
41
57
|
/** `ground`: where a drawn splat ground's tiles merge (absent: `root`); a ring passes its shared root, as each tile's
|
|
42
58
|
* `root` is its own group */
|
|
43
59
|
props: (props: NonNullable<Shardfile['props']>, key: string, bytes: Uint8Array, root: Object3D, scope: Scope, additional?: ReadonlyMap<string, Uint8Array>, ground?: Object3D) => Promise<ResidentTile | null>;
|
|
@@ -60,7 +76,9 @@ interface ViewPorts { terrain: string | NonNullable<Shardfile['terrain']> | null
|
|
|
60
76
|
/** The terrain's shadow flags (`terrain.shadow`): a tile casts only when `cast` (and the shadow disc says so), receives only when `receive` (absent: both). */
|
|
61
77
|
terrainShadow?: NonNullable<Shardfile['terrain']>['shadow'] | undefined;
|
|
62
78
|
/** The tiles' draw order among the opaque surfaces (`terrain.order`, three's renderOrder; absent: TERRAIN_ORDER). */
|
|
63
|
-
terrainOrder?: number | undefined
|
|
79
|
+
terrainOrder?: number | undefined;
|
|
80
|
+
/** SHARD-SOURCE AP8: a fine tile's static props draw merged per material across tiles (`propMerge`; absent: true) */
|
|
81
|
+
mergeProps?: boolean }
|
|
64
82
|
|
|
65
83
|
/** G784: absent `terrain.order`, the ground draws before the opaque surfaces laid on it (a road, a yard, a path), so a
|
|
66
84
|
* surface at the ground's depth always wins its tie. At renderOrder 0 three broke those ties by material id: a world's
|
|
@@ -88,12 +106,16 @@ export function clientTileViews(ports: ViewPorts): ClientTileViews {
|
|
|
88
106
|
if (material === undefined) throw new Error('shardfile views: the terrain family has no resolved material');
|
|
89
107
|
const cast = ports.terrainShadow?.cast ?? true, receive = ports.terrainShadow?.receive ?? true;
|
|
90
108
|
return {
|
|
91
|
-
terrain: (input, root, scope, shadow) => {
|
|
109
|
+
terrain: (input, root, scope, shadow, groundRoot) => {
|
|
92
110
|
if (material === null) throw new Error('shardfile views: a terrain tile in a shard without terrain');
|
|
93
|
-
const
|
|
111
|
+
const data = input instanceof Uint8Array ? decodeTerrainTile(input) : input;
|
|
112
|
+
const mesh = installTerrainTile(data, { root, scope, material, shadow: cast && shadow, ...(ports.lattice === undefined ? {} : { lattice: ports.lattice }) });
|
|
94
113
|
if (!receive) mesh.receiveShadow = false;
|
|
95
114
|
mesh.renderOrder = ports.terrainOrder ?? TERRAIN_ORDER;
|
|
96
115
|
const hulls = ports.outline?.(mesh, material, scope) ?? [];
|
|
116
|
+
// AP8: a fine tile with no hull draws in the terrain's merge, one view draw a 250 m block; it still casts itself
|
|
117
|
+
// (the shadow pass only) while its shadow disc says so. A coarse tile keeps its own mesh for its quadrant mask.
|
|
118
|
+
if ((ports.mergeProps ?? true) && hulls.length === 0 && !isCoarse(data)) mergeView(groundRoot ?? root, mesh, material, scope);
|
|
97
119
|
// a coarse tile's mask moves its draw range; its hull (a shallow geometry copy) follows
|
|
98
120
|
const mask = (excluded: ReadonlySet<number>): void => { maskTerrainTile(mesh, excluded); for (const hull of hulls) hull.geometry.setDrawRange(mesh.geometry.drawRange.start, mesh.geometry.drawRange.count); };
|
|
99
121
|
return { mask, shadow: cast ? (enabled) => { mesh.castShadow = enabled; } : () => undefined };
|
|
@@ -171,6 +193,12 @@ export function clientTileViews(ports: ViewPorts): ClientTileViews {
|
|
|
171
193
|
for (const { mesh, box } of lit) {
|
|
172
194
|
if (box.max.y - box.min.y < FLAT && box.max.y <= floor + FLOOR) mesh.castShadow = false; else casters.push(mesh);
|
|
173
195
|
}
|
|
196
|
+
// AP8: a fine tile's plain static meshes join their material's merge under the shared root, so a view draws each
|
|
197
|
+
// material once a 250 m block, not once a tile; each still casts itself (the shadow pass only) as its disc says
|
|
198
|
+
if (row.lod === 0 && (ports.mergeProps ?? true)) {
|
|
199
|
+
const meshes: Mesh[] = []; root.traverse((object) => { if (isMesh(object)) meshes.push(object); });
|
|
200
|
+
for (const mesh of meshes) if (mergeable(mesh)) mergeView(parent, mesh, mesh.material, scope);
|
|
201
|
+
}
|
|
174
202
|
const shadow = (enabled: boolean): void => { for (const mesh of casters) mesh.castShadow = enabled; };
|
|
175
203
|
if (row.lod === 1) {
|
|
176
204
|
const apply = coarseTileMask(root, row.x, row.z, scope);
|
|
@@ -5,12 +5,17 @@
|
|
|
5
5
|
* a stream a ribbon through its points at their levels, the sea a cell-wide plane. The surface is `materials.get('water')`
|
|
6
6
|
* when the look declares one, else the default water surface (`defaultWaterMaterial`, LF1-3: a no-code shard has no client
|
|
7
7
|
* plan to draw a graph surface, so this is its pond); a graph surface that declares `stages.outline` draws its hull
|
|
8
|
-
* through `outline` (`clientMaterials().outline`).
|
|
8
|
+
* through `outline` (`clientMaterials().outline`). A pool that declares its `surface` (TEMPLATES-CLEANROOM M4.6) draws
|
|
9
|
+
* that instead: a planar mirror on the desktop tier (`reflectingWater.ts`), the default surface in its tint and Fresnel
|
|
10
|
+
* otherwise.
|
|
9
11
|
*/
|
|
10
12
|
import { BufferAttribute, BufferGeometry, CircleGeometry, Mesh, MeshStandardMaterial, PlaneGeometry, Shape, ShapeGeometry, Vector2, type Material, type Object3D } from 'three';
|
|
11
13
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
12
14
|
import { patchShader } from '@wildshard/engine/render/shaderPatches';
|
|
13
15
|
import type { ShardWater } from '@wildshard/format/water';
|
|
16
|
+
import type { PoolSurface } from '@wildshard/format/pool-surface';
|
|
17
|
+
import { TIER } from '@wildshard/engine/core/tier';
|
|
18
|
+
import { mirrorPool } from './reflectingWater';
|
|
14
19
|
import type { GraphOutlineHook } from './clientGraphs';
|
|
15
20
|
import type { ClientFeatureRow } from '@wildshard/format/clientPlan';
|
|
16
21
|
|
|
@@ -51,9 +56,9 @@ export function undrawnWater(water: ShardWater, features: readonly ClientFeature
|
|
|
51
56
|
* normal rippled from world position (faded with distance, so far water stays flat and does not shimmer), reflected
|
|
52
57
|
* into a sky made from the shard's own light (its fog colour at the horizon, its hemisphere's sky colour above, its key
|
|
53
58
|
* light's glint), Fresnel-weighted; the alpha rises with the Fresnel, so water looked into shows its bed. */
|
|
54
|
-
const
|
|
59
|
+
const waterGlsl = (base: string, power: string, ripple: string, alpha: boolean): string => `{
|
|
55
60
|
vec3 wsV = normalize(vViewPosition), wsUpV = normalize((viewMatrix * vec4(0.0, 1.0, 0.0, 0.0)).xyz);
|
|
56
|
-
vec2 wsP = vWsWaterWorld.xz;
|
|
61
|
+
vec2 wsP = vWsWaterWorld.xz * ${ripple};
|
|
57
62
|
float wsFade = 1.0 / (1.0 + length(vViewPosition) * 0.06);
|
|
58
63
|
vec2 wsSlope = vec2(sin(wsP.x * 1.7 + sin(wsP.y * 0.9) * 1.3) + 0.6 * sin(wsP.y * 2.3 + wsP.x * 0.6),
|
|
59
64
|
cos(wsP.y * 1.9 + sin(wsP.x * 1.1) * 1.2) + 0.5 * cos(wsP.x * 2.9 - wsP.y * 0.7)) * 0.045 * wsFade;
|
|
@@ -71,11 +76,13 @@ const DEFAULT_WATER_GLSL = `{
|
|
|
71
76
|
float wsSun = max(dot(wsR, directionalLights[ 0 ].direction), 0.0);
|
|
72
77
|
wsWaterSky += directionalLights[ 0 ].color * (pow(wsSun, 600.0) * 2.5 + pow(wsSun, 10.0) * 0.3);
|
|
73
78
|
#endif
|
|
74
|
-
float wsFres =
|
|
79
|
+
float wsFres = ${base} + (1.0 - ${base}) * pow(1.0 - clamp(dot(wsN, wsV), 0.0, 1.0), ${power});
|
|
75
80
|
outgoingLight = mix(outgoingLight, wsWaterSky, wsFres);
|
|
76
|
-
diffuseColor.a = mix(diffuseColor.a, 1.0, wsFres);
|
|
81
|
+
${alpha ? 'diffuseColor.a = mix(diffuseColor.a, 1.0, wsFres);' : ''}
|
|
77
82
|
}
|
|
78
83
|
`;
|
|
84
|
+
const DEFAULT_WATER_GLSL = waterGlsl('0.22', '3.0', '1.0', true);
|
|
85
|
+
const glslFloat = (n: number): string => n.toFixed(4);
|
|
79
86
|
|
|
80
87
|
/** The default water surface (LF1-3) for a declared body the look gives no `water` material: three's standard material
|
|
81
88
|
* (so the engine's fog, shadow and light patches apply as to any other) with a deep tint, a sky reflection and a Fresnel
|
|
@@ -94,15 +101,50 @@ export function defaultWaterMaterial(): MeshStandardMaterial {
|
|
|
94
101
|
return material;
|
|
95
102
|
}
|
|
96
103
|
|
|
104
|
+
/** M4.6: a declared surface's sky water (`reflect: 'sky'`, or `planar` on the phone tier): the default surface's program
|
|
105
|
+
* with the surface's opaque tint, Fresnel and ripple scale (its own program, keyed by those values). */
|
|
106
|
+
export function skyWaterMaterial(look: PoolSurface): MeshStandardMaterial {
|
|
107
|
+
const material = new MeshStandardMaterial({ roughness: 0.12, metalness: 0 });
|
|
108
|
+
material.color.setRGB(look.tint[0], look.tint[1], look.tint[2]);
|
|
109
|
+
material.name = 'water-sky';
|
|
110
|
+
const glsl = waterGlsl(glslFloat(look.fresnel[0]), glslFloat(look.fresnel[1]), glslFloat(Math.max(0.05, look.ripple.scale / 2)), false);
|
|
111
|
+
const key = `m46-sky-water-${glsl.length}-${look.fresnel.join('-')}-${String(look.ripple.scale)}`;
|
|
112
|
+
patchShader(material, key, 100, (shader): void => {
|
|
113
|
+
shader.vertexShader = shader.vertexShader
|
|
114
|
+
.replace('#include <common>', '#include <common>\nvarying vec3 vWsWaterWorld;')
|
|
115
|
+
.replace('#include <project_vertex>', '#include <project_vertex>\nvWsWaterWorld = (modelMatrix * vec4(transformed, 1.0)).xyz;');
|
|
116
|
+
shader.fragmentShader = shader.fragmentShader
|
|
117
|
+
.replace('#include <common>', '#include <common>\nvarying vec3 vWsWaterWorld;')
|
|
118
|
+
.replace('#include <opaque_fragment>', `${glsl}#include <opaque_fragment>`);
|
|
119
|
+
}, { key });
|
|
120
|
+
return material;
|
|
121
|
+
}
|
|
122
|
+
|
|
97
123
|
/** Draw every declared water body's surface under `root`; the scope takes the meshes, geometry and default material. */
|
|
98
|
-
export function installClientWater(water: ShardWater, ports: { root: Object3D; scope: Scope; materials?: ReadonlyMap<string, Material>; outline?: GraphOutlineHook }): readonly Mesh[] {
|
|
124
|
+
export function installClientWater(water: ShardWater, ports: { root: Object3D; scope: Scope; materials?: ReadonlyMap<string, Material>; outline?: GraphOutlineHook; frame?: (run: (dt: number) => void) => void }, tier: string = TIER): readonly Mesh[] {
|
|
99
125
|
if (water.length === 0) return [];
|
|
100
|
-
const
|
|
126
|
+
const declared = ports.materials?.get('water');
|
|
127
|
+
let fallback: Material | null = null;
|
|
128
|
+
const material = (): Material => declared ?? (fallback ??= ports.scope.own(defaultWaterMaterial()));
|
|
101
129
|
return water.map((body) => {
|
|
102
|
-
const
|
|
130
|
+
const look = body.kind === 'pool' ? body.surface : undefined;
|
|
131
|
+
if (body.kind === 'pool' && look !== undefined && declared === undefined) {
|
|
132
|
+
if (look.reflect === 'planar' && tier !== 'phone') {
|
|
133
|
+
const pool = mirrorPool(body.shape, body.level, look);
|
|
134
|
+
pool.mesh.name = `water:${body.id}`; pool.mesh.renderOrder = 1;
|
|
135
|
+
ports.root.add(pool.mesh); ports.scope.onDispose(() => { pool.mesh.removeFromParent(); pool.dispose(); });
|
|
136
|
+
ports.frame?.(pool.tick);
|
|
137
|
+
return pool.mesh;
|
|
138
|
+
}
|
|
139
|
+
const sky = ports.scope.own(skyWaterMaterial(look)), mesh = new Mesh(ports.scope.own(surface(body)), sky);
|
|
140
|
+
mesh.name = `water:${body.id}`; mesh.receiveShadow = true; mesh.castShadow = false; mesh.renderOrder = 1;
|
|
141
|
+
ports.root.add(mesh); ports.scope.onDispose(() => { mesh.removeFromParent(); });
|
|
142
|
+
return mesh;
|
|
143
|
+
}
|
|
144
|
+
const drawn = material(), mesh = new Mesh(ports.scope.own(surface(body)), drawn);
|
|
103
145
|
mesh.name = `water:${body.id}`; mesh.receiveShadow = true; mesh.castShadow = false; mesh.renderOrder = 1;
|
|
104
146
|
ports.root.add(mesh); ports.scope.onDispose(() => { mesh.removeFromParent(); });
|
|
105
|
-
ports.outline?.(mesh,
|
|
147
|
+
ports.outline?.(mesh, drawn, ports.scope);
|
|
106
148
|
return mesh;
|
|
107
149
|
});
|
|
108
150
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// P1-E5.3 I6 (J126), E6: every page runs the real Game and Player against the real server in its worker: the Player predicts and
|
|
2
2
|
// reconciles, and every creature is an interpolated row drawn by the real views.
|
|
3
3
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
4
|
+
import type { DevBox } from '@wildshard/engine/game/devColliders';
|
|
4
5
|
import type { LiveGridWire } from '../grid/liveSession';
|
|
5
6
|
import { chosenCell, gotoHosted, pageGoto } from '../../../shared/game/grid/pageMode';
|
|
6
7
|
import type { SystemSpec } from '@wildshard/engine/app/systems';
|
|
@@ -8,6 +9,7 @@ import type { Player } from '@wildshard/engine/player/Player';
|
|
|
8
9
|
import { Vector3, type Object3D } from 'three';
|
|
9
10
|
import { appIdentity } from '@wildshard/engine/app/identity';
|
|
10
11
|
import { bootMark, bootTask } from '@wildshard/engine/boot/timing';
|
|
12
|
+
import { SEAT_GRACE_MS, seatedInTime } from './seatGrace';
|
|
11
13
|
import { importPageSaves, openIndexedSaves, serverSaveDatabase, serverStopsForImport, type IndexedSaves } from '@wildshard/engine/saves/indexed';
|
|
12
14
|
import { saveEnvironment } from '@wildshard/engine/saves/environment';
|
|
13
15
|
import { jsonSlot } from '@wildshard/engine/saves/slots';
|
|
@@ -21,7 +23,7 @@ import type { NetClient } from '@wildshard/engine/net/client';
|
|
|
21
23
|
import type { NetCombatEvent } from '@wildshard/engine/net/messages';
|
|
22
24
|
import type { DeathCause } from '@wildshard/engine/combat/pipeline';
|
|
23
25
|
import { deviceIdentity, heldName, type NetIdentity } from '@wildshard/engine/net/identity';
|
|
24
|
-
import {
|
|
26
|
+
import { askNameToJoin } from '@wildshard/engine/ui/namePrompt';
|
|
25
27
|
import { NetPlayer, type NetWeapons } from '@wildshard/engine/net/netPlayer';
|
|
26
28
|
import type { PredictedRow } from '@wildshard/engine/net/predictionWorld';
|
|
27
29
|
import { ANIMAL_CLASS } from '@wildshard/engine/net/netSchemas';
|
|
@@ -127,7 +129,7 @@ function releaseKeep(): ReleaseKeep {
|
|
|
127
129
|
}
|
|
128
130
|
/** E7.2d: the page's seat in the one world, in a shell of the same shape. */
|
|
129
131
|
interface OnlineModule { readonly startOnline: (config: BuildWorld & { keep: ReleaseKeep; loaded: string; build: string; identity: (name?: string) => NetIdentity; grid?: { readonly cell: string; readonly cells: readonly string[]; readonly placed: (cell: string, at: { readonly x: number; readonly y: number; readonly z: number; readonly yaw: number }) => void; readonly reenter: (cell: string) => void; readonly goto?: boolean } }) => Promise<Shell> }
|
|
130
|
-
interface Shell { readonly redials?: true; pause: () => void; hold: (on: boolean) => void; bossGod: () => void; raise: (flag: string) => void; join: (id: string, x: number, y: number, z: number) => { readonly client: NetClient; readonly move: (x: number, y: number, z: number) => void }; readonly client: NetClient; readonly booted: Promise<{ readonly restored: boolean }>; place: (x: number, y: number, z: number, yaw: number) => void; hardHits: (by: number) => void; ready: () => void; leave?: () => Promise<void>; save: () => Promise<{ readonly tick: number; readonly ok: boolean }>; probe: () => Promise<{ readonly tickMs: number }>; dispose: () => void }
|
|
132
|
+
interface Shell { readonly redials?: true; devColliders?: (name: string, boxes: readonly DevBox[]) => void; pause: () => void; hold: (on: boolean) => void; bossGod: () => void; raise: (flag: string) => void; join: (id: string, x: number, y: number, z: number) => { readonly client: NetClient; readonly move: (x: number, y: number, z: number) => void }; readonly client: NetClient; readonly booted: Promise<{ readonly restored: boolean }>; place: (x: number, y: number, z: number, yaw: number) => void; hardHits: (by: number) => void; ready: () => void; leave?: () => Promise<void>; save: () => Promise<{ readonly tick: number; readonly ok: boolean }>; probe: () => Promise<{ readonly tickMs: number }>; dispose: () => void }
|
|
131
133
|
|
|
132
134
|
const SAVE_EVERY_MS = 30_000;
|
|
133
135
|
/** How long the card waits for the server's first rows, and how often it looks. A server that has booted says them in a tick. */
|
|
@@ -165,7 +167,7 @@ export interface WorkerClientReport {
|
|
|
165
167
|
}
|
|
166
168
|
/** A fight as a proof reads it: its row, where its body stands and the server's name for it. */
|
|
167
169
|
export type WorkerClientFight = EncounterRow & { readonly at: { readonly x: number; readonly y: number; readonly z: number } | null; readonly name: string | null };
|
|
168
|
-
declare global { interface Window { __onlinePlayers?: () => OtherPlayers['shown']; __workerClientFights?: () => readonly WorkerClientFight[]; __workerClientHits?: (by: number) => void; __workerClientTravel?: (to: ShardSlug) => void;__workerClientSky?: (name: string) => void; __workerClientTime?: (pick: OptionValue<'time'>) => void; __workerClientRow?: (name: string) => number | undefined; __workerClientFlag?: (flag: string) => void; __workerClientRows?: (kind: string) => readonly { readonly x: number; readonly y: number; readonly z: number }[]; __workerClientGate?: (flag: string) => boolean; __workerClientBot?: (id: string, x: number, y: number, z: number) => { readonly move: (x: number, y: number, z: number) => void; readonly press: (id: string) => void; readonly end: () => void }; __workerClient?: () => WorkerClientReport; __workerClientSave?: () => Promise<void> } }
|
|
170
|
+
declare global { interface Window { __onlinePlayers?: () => OtherPlayers['shown']; __workerClientFights?: () => readonly WorkerClientFight[]; __workerClientHits?: (by: number) => void; __workerClientTravel?: (to: ShardSlug) => void;__workerClientSky?: (name: string) => void; __workerClientTime?: (pick: OptionValue<'time'>) => void; __workerClientRow?: (name: string) => number | undefined; __workerClientFlag?: (flag: string) => void; __workerClientDevColliders?: (name: string, boxes: readonly DevBox[]) => void; __workerClientRows?: (kind: string) => readonly { readonly x: number; readonly y: number; readonly z: number }[]; __workerClientGate?: (flag: string) => boolean; __workerClientBot?: (id: string, x: number, y: number, z: number) => { readonly move: (x: number, y: number, z: number) => void; readonly press: (id: string) => void; readonly end: () => void }; __workerClient?: () => WorkerClientReport; __workerClientSave?: () => Promise<void> } }
|
|
169
171
|
|
|
170
172
|
/** The page's pose inputs, as acts short enough to go. */
|
|
171
173
|
function poseActs(names: ReadonlySet<string>): readonly string[] {
|
|
@@ -345,7 +347,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
345
347
|
const online = async (world: BuildWorld, storage: SaveStorage): Promise<Shell> => {
|
|
346
348
|
const { startOnline } = await onlineModule();
|
|
347
349
|
// MP2.4: a page that came in without the title's PLAY (a link, a reload) asks for the Name here, once per device, before it joins
|
|
348
|
-
const answered = await
|
|
350
|
+
const answered = await askNameToJoin(scope, { parent: document.body, doctor: () => { document.dispatchEvent(new CustomEvent('ws:doctor', { detail: 'join' })); } });
|
|
349
351
|
// a page that left while it asked never joins (Codex review): a cancelled load must not take the device's seat
|
|
350
352
|
if (!answered || scope.disposed) throw new Error('The page left before it joined the world');
|
|
351
353
|
const { grid } = ports, booted = grid?.booted;
|
|
@@ -451,13 +453,20 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
451
453
|
net.bindWeapons(ports.weapons, slotsOf(items));
|
|
452
454
|
const day = ports.day(); if (day !== null) wirePage.dayPassed(day);
|
|
453
455
|
});
|
|
454
|
-
|
|
456
|
+
// OF9: a world build (the online shell redials) opens the world without its seat once the grace is up; the shell keeps dialling,
|
|
457
|
+
// the link screens say why, and the seat, when it comes, places the player (GO5). A server in this page boots with it, as before.
|
|
458
|
+
const unseated = shell.redials === true
|
|
459
|
+
&& !await seatedInTime(shell.booted, SEAT_GRACE_MS, navigator.onLine, ms => new Promise<void>(resolve => { scope.timeout(ms, resolve); }));
|
|
460
|
+
const { restored } = unseated ? { restored: false } : await bootTask('server:await-booted', () => shell.booted);
|
|
461
|
+
// OF10: unseated, the page plays its own input for the predictor's ring, then holds until the seat
|
|
462
|
+
if (unseated) { bootMark('server:unseated'); net.playUnseated(); }
|
|
455
463
|
// E7.6: only a world has anyone else in it.
|
|
456
464
|
let others: OtherPlayers | null = null;
|
|
457
465
|
if (shell.redials === true) others = new (await import('@wildshard/engine/net/otherPlayers')).OtherPlayers(client, ports.scene, scope, player.position);
|
|
458
466
|
if (new URLSearchParams(location.search).has('bossGod')) shell.bossGod();
|
|
459
467
|
bootMark('server:ready-send'); shell.ready();
|
|
460
468
|
const started = diagnosticNow(), report: WorkerClientReport = { drawn: wirePage.drawn, frames: 0, framesPerSecond: 0, ticksPerSecond: 0, correctionsPerMinute: 0, corrections: 0, retired: {}, spawnMs: {}, missed: net.predictor.missed, misses: net.predictor.misses, worstOffset: 0, queue: 0, replaysPerFrame: 0, delayMs: 0, jitterMs: 0, interpHeld: 0, interpStarved: 0, mainMsP95: 0, workerTickMs: 0, rows: 0, attacks: 0, hits: 0, kills: 0, refused: 0, held: 0, dropped: 0, hp: 0, falls: 0, closed: null, x: 0, z: 0, cell: 0, serverX: 0, serverZ: 0, restored, savedTick: -1, savedOk: false, receipts: [], quests: {}, flags: [], paid: 0, fights: [], owned: {}, sky: null, day: null, clawed: false, own: null, movers: 0, posed: 0, sand: 0 };
|
|
469
|
+
if (unseated) void shell.booted.then(answer => { report.restored = answer.restored; bootMark('server:seated-late'); return undefined; }, () => undefined);
|
|
461
470
|
scope.onDispose(client.onLedger(receipt => { report.receipts.push(`${receipt.grant}:${receipt.name}`); }));
|
|
462
471
|
const contacts: NetCombatEvent[] = [];
|
|
463
472
|
scope.onDispose(client.onTravel(() => { contacts.length = 0; }));
|
|
@@ -572,6 +581,8 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
572
581
|
window.__onlinePlayers = () => others?.shown ?? [];
|
|
573
582
|
window.__workerClientHits = by => { shell.hardHits(by); };
|
|
574
583
|
window.__workerClientFlag = flag => { shell.raise(flag); };
|
|
584
|
+
// SHARD-SOURCE AP5: the dev hook's `swapColliders` reaches the in-page server here (DEVSERVER only: the define folds it away)
|
|
585
|
+
if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__) window.__workerClientDevColliders = (name, boxes) => { shell.devColliders?.(name, boxes); };
|
|
575
586
|
window.__workerClientTravel = to => { travel({ to, mode: 'enter' }); };
|
|
576
587
|
window.__workerClientSky = name => { wirePage.climate({ op: 'force', name, at: 0.1 }); };
|
|
577
588
|
window.__workerClientTime = pick => { saveSetting('time', pick); };
|
|
@@ -613,7 +624,8 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
613
624
|
const off = scope.capture('disposers', resolve);
|
|
614
625
|
scope.timeout(FIRST_ROWS_POLL_MS, () => { off(); resolve(); });
|
|
615
626
|
});
|
|
616
|
-
|
|
627
|
+
// OF9: an unseated page has no rows to wait for: the world opens now
|
|
628
|
+
const firstBy = unseated ? 0 : diagnosticNow() + FIRST_ROWS_MS;
|
|
617
629
|
while (client.latest === null && diagnosticNow() < firstBy && !scope.disposed && !scope.disposing) await poll();
|
|
618
630
|
if (scope.disposed || scope.disposing) return;
|
|
619
631
|
net.reconcile(false);
|
|
@@ -622,7 +634,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
|
|
|
622
634
|
if (ports.linkBodies === undefined) { bootMark('server:launch-complete'); return; }
|
|
623
635
|
bootMark('server:first-body-preparation-start');
|
|
624
636
|
let first = -1;
|
|
625
|
-
const until = diagnosticNow() + FIRST_ROWS_MS;
|
|
637
|
+
const until = unseated ? 0 : diagnosticNow() + FIRST_ROWS_MS;
|
|
626
638
|
while (diagnosticNow() < until) {
|
|
627
639
|
renderTick = client.present();
|
|
628
640
|
if (first === -1 && client.latest !== null) first = client.latest.tick;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
2
|
-
import { buildHeld, frameBudgetSpent, frameDue, presenting } from '@wildshard/engine/core/framePacing';
|
|
2
|
+
import { buildHeld, buildUrgent, frameBudgetSpent, frameDue, presenting } from '@wildshard/engine/core/framePacing';
|
|
3
3
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
4
4
|
import { buildYield, WORK_SLICE_MS } from '@wildshard/engine/core/workSlice';
|
|
5
5
|
|
|
@@ -26,6 +26,6 @@ export function constructionCheckpoint(owner: Scope): Promise<void> | undefined
|
|
|
26
26
|
return buildYield(owner).then(() => { requireOwner(owner); loadingAt = diagnosticNow(); return undefined; });
|
|
27
27
|
}
|
|
28
28
|
loadingAt = undefined;
|
|
29
|
-
if (live && (buildHeld() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS)) return undefined;
|
|
29
|
+
if (live && (buildHeld() || buildUrgent() || !frameDue()) && !frameBudgetSpent(WORK_SLICE_MS)) return undefined;
|
|
30
30
|
return buildYield(owner).then(() => { requireOwner(owner); return undefined; });
|
|
31
31
|
}
|
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
* tile's vertex colours, say, are left out when a fine tile has none). A merged mesh receives shadow and never casts (as
|
|
13
13
|
* the tiles), and leaves with its block's last member. Each tile keeps its transformed attributes and its kept triangles
|
|
14
14
|
* (refreshed when its transform, an attribute's version or its hidden quadrants change), so a rebuild is copies.
|
|
15
|
+
*
|
|
16
|
+
* SHARD-SOURCE AP8: static props and fine terrain tiles merge the same way (`propMerge`): one view mesh per material,
|
|
17
|
+
* receive flag and render order per 250 m block and vertex layout, normals and tangents turned with their positions, so a
|
|
18
|
+
* view draws a material once across tiles. The merged mesh never casts: a member that casts keeps casting itself from
|
|
19
|
+
* SHADOW_LAYER (the shadow pass only, `castShadow` still its tile's shadow disc), so each light's cascades cull it as before.
|
|
15
20
|
*/
|
|
16
|
-
import { Box3, BufferAttribute, BufferGeometry, InterleavedBufferAttribute, Matrix4, Mesh, Sphere, Vector3, type Material, type Object3D } from 'three';
|
|
21
|
+
import { Box3, BufferAttribute, BufferGeometry, InterleavedBufferAttribute, Matrix3, Matrix4, Mesh, Sphere, Vector3, type Material, type Object3D } from 'three';
|
|
17
22
|
import type { Scope } from '@wildshard/engine/app/scope';
|
|
23
|
+
import { SHADOW_LAYER } from '@wildshard/engine/core/shadowLayer';
|
|
18
24
|
|
|
19
25
|
const HALF = 250, COARSE = 125, BLOCK = 250;
|
|
20
26
|
/** an attribute's change count (an interleaved one counts on its buffer) */
|
|
@@ -36,11 +42,15 @@ interface Member {
|
|
|
36
42
|
}
|
|
37
43
|
interface Block { readonly members: Map<Mesh, Member>; merged: Mesh | null; queued: boolean }
|
|
38
44
|
|
|
45
|
+
/** How members group into blocks: `quadrant` 250 m blocks (a ground's channels are those every member has), `cell` the
|
|
46
|
+
* 500 m cell by vertex layout, `block` 250 m blocks by vertex layout (props: a member never loses a channel). */
|
|
47
|
+
export type MergeGrouping = 'quadrant' | 'cell' | 'block';
|
|
48
|
+
|
|
39
49
|
export class GroundMerge {
|
|
40
50
|
private readonly blocks = new Map<string, Block>();
|
|
41
51
|
/** `onRebuild`: each new merged mesh, before it draws (its shadow flags, render order or a terrain's mesh slot) */
|
|
42
|
-
constructor(private readonly parent: Object3D, private readonly material: Material, private readonly name: string, private readonly onRebuild?: (mesh: Mesh) => void, readonly grouping:
|
|
43
|
-
if (grouping !== 'quadrant' && grouping !== 'cell') throw new Error('Unknown ground merge grouping');
|
|
52
|
+
constructor(private readonly parent: Object3D, private readonly material: Material, private readonly name: string, private readonly onRebuild?: (mesh: Mesh) => void, readonly grouping: MergeGrouping = 'quadrant') {
|
|
53
|
+
if (grouping !== 'quadrant' && grouping !== 'cell' && grouping !== 'block') throw new Error('Unknown ground merge grouping');
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
/** The tile's ground `mesh` joins (hidden itself) until `scope` ends. Detached meshes are already parent-local;
|
|
@@ -100,7 +110,7 @@ export class GroundMerge {
|
|
|
100
110
|
const size = this.grouping === 'cell' ? HALF * 2 : BLOCK;
|
|
101
111
|
const cell = `${String(Math.floor((x + HALF) / size))},${String(Math.floor((z + HALF) / size))}`;
|
|
102
112
|
if (this.grouping === 'quadrant') return cell;
|
|
103
|
-
// A cell merge never drops a channel supplied by another
|
|
113
|
+
// A cell (or block) merge never drops a channel supplied by another member.
|
|
104
114
|
const layout = Object.entries(member.mesh.geometry.attributes).map(([name, attribute]) => `${name}:${String(attribute.itemSize)}:${String(attribute.normalized)}`).sort().join('|');
|
|
105
115
|
return `${cell}|${layout}`;
|
|
106
116
|
}
|
|
@@ -131,10 +141,13 @@ export class GroundMerge {
|
|
|
131
141
|
if (member.mesh.parent === null) toParent.copy(member.mesh.matrix);
|
|
132
142
|
else toParent.multiplyMatrices(parentInverse, member.mesh.matrixWorld);
|
|
133
143
|
const transform = toParent.elements.join(',');
|
|
144
|
+
// AP8: a prop's normals and tangents turn with it (a ground's channels copy as they are)
|
|
145
|
+
const turned = this.grouping === 'block' && !isTranslation(toParent), normalMatrix = turned ? new Matrix3().getNormalMatrix(toParent) : null;
|
|
134
146
|
const attributes = names.map(name => {
|
|
135
147
|
const attribute = geometry.getAttribute(name);
|
|
136
148
|
if (attribute.count !== position.count) throw new Error(`Ground merge member lacks ${name}`);
|
|
137
|
-
const
|
|
149
|
+
const directed = turned && (name === 'normal' || name === 'tangent') && attribute.itemSize >= 3;
|
|
150
|
+
const key = name === 'position' || directed ? transform : '', known = member.attributes.get(name);
|
|
138
151
|
if (known !== undefined && known.key === key && known.version === versionOf(attribute)) return known.values;
|
|
139
152
|
const size = attribute.itemSize, out = new Float32Array(attribute.count * size);
|
|
140
153
|
if (name === 'position') {
|
|
@@ -148,6 +161,14 @@ export class GroundMerge {
|
|
|
148
161
|
out[i * 3 + 1] = ((e[1] ?? 0) * x + (e[5] ?? 1) * y + (e[9] ?? 0) * z + (e[13] ?? 0)) * w;
|
|
149
162
|
out[i * 3 + 2] = ((e[2] ?? 0) * x + (e[6] ?? 0) * y + (e[10] ?? 1) * z + (e[14] ?? 0)) * w;
|
|
150
163
|
}
|
|
164
|
+
} else if (directed) {
|
|
165
|
+
const m = name === 'normal' ? normalMatrix : new Matrix3().setFromMatrix4(toParent), v = new Vector3();
|
|
166
|
+
if (m === null) throw new Error('Ground merge normal without its matrix');
|
|
167
|
+
for (let i = 0; i < attribute.count; i++) {
|
|
168
|
+
v.set(attribute.getComponent(i, 0), attribute.getComponent(i, 1), attribute.getComponent(i, 2)).applyMatrix3(m).normalize();
|
|
169
|
+
out[i * size] = v.x; out[i * size + 1] = v.y; out[i * size + 2] = v.z;
|
|
170
|
+
if (size === 4) out[i * size + 3] = attribute.getComponent(i, 3);
|
|
171
|
+
}
|
|
151
172
|
} else {
|
|
152
173
|
const plain = plainFloats(attribute);
|
|
153
174
|
if (plain === null) for (let i = 0; i < attribute.count; i++) for (let c = 0; c < size; c++) out[i * size + c] = attribute.getComponent(i, c);
|
|
@@ -220,6 +241,12 @@ export class GroundMerge {
|
|
|
220
241
|
}
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
/** a transform with no rotation or scale (its upper 3 x 3 the identity) */
|
|
245
|
+
function isTranslation(m: Matrix4): boolean {
|
|
246
|
+
const e = m.elements;
|
|
247
|
+
return e[0] === 1 && e[1] === 0 && e[2] === 0 && e[4] === 0 && e[5] === 1 && e[6] === 0 && e[8] === 0 && e[9] === 0 && e[10] === 1;
|
|
248
|
+
}
|
|
249
|
+
|
|
223
250
|
const merges = new WeakMap<Object3D, Map<Material, GroundMerge>>();
|
|
224
251
|
/** The one merge of `material` under `parent` (made on first use; each block empties itself as its last member leaves). */
|
|
225
252
|
export function groundMerge(parent: Object3D, material: Material, name: string, grouping: 'quadrant' | 'cell' = 'quadrant'): GroundMerge {
|
|
@@ -230,3 +257,28 @@ export function groundMerge(parent: Object3D, material: Material, name: string,
|
|
|
230
257
|
if (merge.grouping !== grouping) throw new Error('Ground merge grouping changed for its material');
|
|
231
258
|
return merge;
|
|
232
259
|
}
|
|
260
|
+
|
|
261
|
+
/** How a merged prop mesh draws: whether it receives shadow, and its render order (each its own merge). */
|
|
262
|
+
export interface PropDraw { readonly receive: boolean; readonly order: number }
|
|
263
|
+
const propMerges = new WeakMap<Object3D, Map<Material, Map<string, GroundMerge>>>();
|
|
264
|
+
/** SHARD-SOURCE AP8: the one static prop merge of `material` drawn as `draw` under `parent`: 250 m blocks by vertex layout. */
|
|
265
|
+
export function propMerge(parent: Object3D, material: Material, draw: PropDraw): GroundMerge {
|
|
266
|
+
let byMaterial = propMerges.get(parent);
|
|
267
|
+
if (byMaterial === undefined) { byMaterial = new Map(); propMerges.set(parent, byMaterial); }
|
|
268
|
+
let byDraw = byMaterial.get(material);
|
|
269
|
+
if (byDraw === undefined) { byDraw = new Map(); byMaterial.set(material, byDraw); }
|
|
270
|
+
const key = `${String(draw.receive)}|${String(draw.order)}`;
|
|
271
|
+
let merge = byDraw.get(key);
|
|
272
|
+
if (merge === undefined) {
|
|
273
|
+
merge = new GroundMerge(parent, material, 'props.merged', (mesh) => { mesh.castShadow = false; mesh.receiveShadow = draw.receive; mesh.renderOrder = draw.order; }, 'block');
|
|
274
|
+
byDraw.set(key, merge);
|
|
275
|
+
}
|
|
276
|
+
return merge;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** AP8: `mesh` joins its merge for the view; it keeps drawing only into the shadow maps (SHADOW_LAYER) while it may cast. */
|
|
280
|
+
export function mergeView(parent: Object3D, mesh: Mesh, material: Material, scope: Scope): void {
|
|
281
|
+
if (mesh.material !== material) throw new Error('Prop merge member draws another material');
|
|
282
|
+
propMerge(parent, material, { receive: mesh.receiveShadow, order: mesh.renderOrder }).add(mesh, scope);
|
|
283
|
+
mesh.visible = true; mesh.layers.set(SHADOW_LAYER);
|
|
284
|
+
}
|
|
@@ -399,6 +399,8 @@ export class HybridRuntimeSession {
|
|
|
399
399
|
timings(): { readonly current: Readonly<Pick<HybridHookTiming, 'instance' | 'hook' | 'start'>> | null; readonly completed: readonly HybridHookTiming[] } {
|
|
400
400
|
return { current: this.currentHook, completed: [...this.completedHooks] };
|
|
401
401
|
}
|
|
402
|
+
/** GC6: the cells whose entry is being prepared on the road (for the tour's trace) */
|
|
403
|
+
preparing(): readonly string[] { return [...this.installations.keys()]; }
|
|
402
404
|
/** Finish an actually requested entry before its frame transfer. Neighbours use inert prepare() only.
|
|
403
405
|
* A source must leave first; entered services and parent runtime slots publish only at enter(). */
|
|
404
406
|
prepareEntry(instance: string, signal?: AbortSignal): Promise<boolean> {
|
|
@@ -3,6 +3,7 @@ import type { LookStrategy } from '@wildshard/engine/render/look';
|
|
|
3
3
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
4
4
|
import { lookLightManifest } from '@wildshard/engine/render/lookLight';
|
|
5
5
|
import { lookLightOn } from '@wildshard/engine/ui/lookLightOption';
|
|
6
|
+
import { TIER } from '@wildshard/engine/core/tier';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A shardfile's file reference → its URL: products sit beside the page that embeds `shard.json` (the SDK build writes
|
|
@@ -17,7 +18,11 @@ export function shardfileFileUrl(ref: string): string { return `./${ref.replace(
|
|
|
17
18
|
export function shardfileLook(look: Shardfile['look'], assets?: ReadonlyMap<string, Uint8Array>, light: boolean = lookLightOn()): LookStrategy {
|
|
18
19
|
const lut = look.grade.lut === null ? null : assets?.get(look.grade.lut) ?? shardfileFileUrl(look.grade.lut);
|
|
19
20
|
if (assets !== undefined && look.grade.lut !== null && !assets.has(look.grade.lut)) throw new Error('Missing admitted look LUT');
|
|
20
|
-
const resolved = lookLightManifest(look, light);
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const resolved = lookLightManifest(look, light, TIER);
|
|
22
|
+
// B2: `grade.tone` is a grade choice, not a light setting: it holds on every tier, with or without the row (so do M4.7's
|
|
23
|
+
// exposure and vignette); the bloom radius rides the bloom, which the row and the tier gate
|
|
24
|
+
return dataLook({ day: look.day ?? DATA_LOOK_DAY, dayOverride: look.dayOverride, keys: look.keys, lut, neutral: look.grade.tone === 'neutral', aces: look.grade.tone === 'aces',
|
|
25
|
+
exposure: look.grade.exposure, vignette: look.grade.vignette ?? null, bloomRadius: resolved.bloom.radius, sky: look.sky?.graph ?? null,
|
|
26
|
+
light: { rim: resolved.rim, pools: resolved.pools, heightFogDensity: resolved.atmosphere.fogHeightDensity, lamps: resolved.lamps, bounce: resolved.bounce, environment: resolved.environment,
|
|
27
|
+
shadow: resolved.shadow, motes: resolved.motes } });
|
|
23
28
|
}
|
|
@@ -14,10 +14,10 @@ import { isOutputIndex } from '@wildshard/format/outputAddress';
|
|
|
14
14
|
import { builtIndexHash } from '@wildshard/format/builtIndexes';
|
|
15
15
|
|
|
16
16
|
import { acceptValidatedCost } from '@wildshard/format/deviceMemoryCost';
|
|
17
|
-
import {
|
|
17
|
+
import { assetCacheName } from '@wildshard/engine/pwa/cacheNames';
|
|
18
18
|
import { saves } from '@wildshard/engine/saves/runtime';
|
|
19
19
|
import { contentHash } from '../../../shared/game/shardfile/contentHash';
|
|
20
|
-
import { packReads } from '../../../shared/game/shardfile/packReads';
|
|
20
|
+
import { packOrLoose, packReads } from '../../../shared/game/shardfile/packReads';
|
|
21
21
|
import { productResourceRole } from '../../../shared/game/shardfile/resourceRole';
|
|
22
22
|
import { preflightProduct } from './productPreflight';
|
|
23
23
|
|
|
@@ -107,6 +107,10 @@ export interface ProductOptions {
|
|
|
107
107
|
memory?: MemoryAdmission;
|
|
108
108
|
/** Trusted residency owner reserves parsed source and immutable transport before any asset-cache read or owned copy. */
|
|
109
109
|
reserve?: (source: Shardfile) => void | Promise<void>;
|
|
110
|
+
/** GC9: files the trusted owner releases straight after admission (a grid neighbour's runtime-only wires, read back
|
|
111
|
+
* from cache or network by its inputs). A first-party read leaves them unread instead of fetching and dropping them;
|
|
112
|
+
* checked admission still reads every file. */
|
|
113
|
+
deferred?: (source: Shardfile) => Promise<readonly string[]>;
|
|
110
114
|
/** Trusted presentation observer; it does not participate in admission decisions. */
|
|
111
115
|
progress?: (progress: ProductProgress) => void;
|
|
112
116
|
/** Trusted presentation scheduling between complete checks; validation never skips work. */
|
|
@@ -144,6 +148,8 @@ export interface AdmittedProduct {
|
|
|
144
148
|
releasePreparedTransport?: (refs: Iterable<string>, reread?: 'cache-or-fetch') => Promise<readonly string[]>;
|
|
145
149
|
/** Complete verified offline storage after control, without retaining the distant files on the page. */
|
|
146
150
|
completeCache?: (scope: Scope) => Promise<void>;
|
|
151
|
+
/** GC9: selected files a first-party read left unread (`ProductOptions.deferred`): still this product's inputs, read back on demand. */
|
|
152
|
+
unread?: readonly string[];
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
// Construct outside admission's decoding context: the owner must not retain the temporary hash/transport maps.
|
|
@@ -388,7 +394,9 @@ async function readBuiltProduct(input:unknown,options:ProductOptions,read:NonNul
|
|
|
388
394
|
if(!isBuildValidatedOutput(source))throw new Error('First-party reader did not assemble its build output');
|
|
389
395
|
await options.reserve?.(source);
|
|
390
396
|
const selected=options.tier===undefined?source.files:await tierProductFilesPaced(source,options.tier,options.pause,options.splatTier);
|
|
391
|
-
const
|
|
397
|
+
const control=options.tier==='phone'?controlFiles(await playLibrarySourcePaced(source,options.pause),selected):selected;
|
|
398
|
+
const deferred=options.deferred===undefined?undefined:new Set(await options.deferred(source));
|
|
399
|
+
const initial=deferred===undefined?control:control.filter(file=>!deferred.has(file.hash));
|
|
392
400
|
const base=new URL('.',options.base).href,assets=new Map<string,Uint8Array>();
|
|
393
401
|
const refs=[...initial.map(file=>({ref:file.hash,bytes:file.compressed})),...source.requires.commons.map(hash=>({ref:`commons:${hash}`,bytes:source.requires.commonsWire[hash]??0}))];
|
|
394
402
|
const unique=new Map(refs.map(row=>[row.ref.replace(/^commons:/u,''),row]));
|
|
@@ -411,7 +419,21 @@ async function readBuiltProduct(input:unknown,options:ProductOptions,read:NonNul
|
|
|
411
419
|
wires.set(row.ref.replace(/^commons:/u,''),result.bytes);
|
|
412
420
|
}
|
|
413
421
|
for(const row of refs){const bytes=wires.get(row.ref.replace(/^commons:/u,''));if(bytes===undefined)throw new Error('Missing built file bytes');assets.set(row.ref,bytes);}
|
|
414
|
-
|
|
422
|
+
const unread=deferred===undefined?[]:control.filter(file=>deferred.has(file.hash));
|
|
423
|
+
// GC9: the files left unread are fetched once more in the background, low priority and unhashed, so the entry's own
|
|
424
|
+
// verified reads of them find the HTTP cache warm (Pine's scene libraries read them one by one at entry); only after a read
|
|
425
|
+
// that succeeded
|
|
426
|
+
const warm=options.backgroundFetch;
|
|
427
|
+
if(unread.length>0&&warm!==undefined)void warmTransport(unread.map(file=>outputBlobUrl(source,file.hash,base)),warm);
|
|
428
|
+
return {source,assets,cached:false,...(deferred===undefined?{}:{unread:unread.map(file=>file.hash)}),releaseTransport:transportRelease(source,assets,options),releasePreparedTransport:transportRelease(source,assets,options,true)};
|
|
429
|
+
}
|
|
430
|
+
/** GC9: fetch immutable product files into the HTTP cache, eight at a time, ignoring failures (a later verified read fetches again). */
|
|
431
|
+
async function warmTransport(urls:readonly string[],fetchLow:NonNullable<ProductOptions['backgroundFetch']>):Promise<void>{
|
|
432
|
+
let next=0;
|
|
433
|
+
const worker=async():Promise<void>=>{
|
|
434
|
+
while(next<urls.length){const url=urls[next++];if(url===undefined)return;try{await (await fetchLow(url)).arrayBuffer();}catch{/* the entry's verified read fetches it */}}
|
|
435
|
+
};
|
|
436
|
+
await Promise.all(Array.from({length:Math.min(8,urls.length)},worker));
|
|
415
437
|
}
|
|
416
438
|
/** Drain a bounded window before refusal or publication; cache operations keep their authored error order. */
|
|
417
439
|
async function cacheRows<T>(rows: readonly T[], batch: boolean, work: (row: T) => Promise<void>): Promise<void> {
|
|
@@ -565,8 +587,13 @@ async function admitProductWork(input: unknown, options: ProductOptions, trace?:
|
|
|
565
587
|
if (bytes === null || bytes === undefined) {
|
|
566
588
|
if (options.offline) throw new Error('Visited shardfile has an incomplete offline cache');
|
|
567
589
|
progress('assets', `Fetching ${role}`, url);
|
|
568
|
-
|
|
569
|
-
|
|
590
|
+
const loose = async (): Promise<Uint8Array> => boundedResponse(await options.fetch(url), cap, (size) => { bytesRead += size; progress('assets', `Reading ${role}`, url); });
|
|
591
|
+
// PZ7: a pack that is not published (or fails) falls back to the member's loose blob
|
|
592
|
+
if (inPack && packed !== undefined) {
|
|
593
|
+
let fromPack = true;
|
|
594
|
+
bytes = await waitFor(`Pack member · ${role}`, packOrLoose(() => packed.read(hash), () => { fromPack = false; return loose(); }), 'file', url);
|
|
595
|
+
if (fromPack) bytesRead += bytes.length;
|
|
596
|
+
} else bytes = await loose();
|
|
570
597
|
} else { bytesRead += bytes.length; progress('assets', `Cached ${role}`, url); }
|
|
571
598
|
if (bytes.length !== cap) throw new Error('Shardfile asset wire size differs from declaration');
|
|
572
599
|
progress('hash', `Verifying ${role}`, url);
|
|
@@ -686,7 +713,7 @@ async function admitProductWork(input: unknown, options: ProductOptions, trace?:
|
|
|
686
713
|
* browser reads use native fetch, without a page index, leases or worker. */
|
|
687
714
|
export function browserProductCache(storage: Pick<CacheStorage, 'open'>,
|
|
688
715
|
preparation: Pick<ProductOptions, 'pause' | 'parseJson'> = {}): ProductCache {
|
|
689
|
-
const open = () => storage.open(
|
|
716
|
+
const open = () => storage.open(assetCacheName());
|
|
690
717
|
const productUrl = (base: string) => new URL('__visited_shardfile__', base).href;
|
|
691
718
|
const assetUrl = (base: string, hash: string): string => {
|
|
692
719
|
if (!HASH.test(hash)) throw new Error('Invalid content hash');
|