@wildshard/engine 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +14 -0
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/package.json +17 -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 +22 -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 +81 -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 +277 -0
- package/scripts/grid-crossing-walk-proof.mjs +124 -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/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +3 -1
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +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/offline-proof-rules.d.mts +2 -2
- package/scripts/offline-proof-rules.mjs +15 -4
- package/scripts/offline-proof.mjs +74 -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/pin-packs.ts +1 -1
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures.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 +0 -2
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +176 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +6 -2
- package/scripts/worker-client-play.mjs +6 -2
- package/scripts/worktree-reap.mjs +5 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +10 -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/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +29 -6
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +41 -11
- package/src/client/engine/render/dataLook.ts +152 -40
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +7 -1
- package/src/client/engine/render/look.ts +6 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/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/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 +291 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +112 -16
- package/src/client/game/grid/liveSession.ts +33 -2
- 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/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 +3 -1
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/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 +20 -4
- 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 +6 -0
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +4 -1
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +19 -7
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/host/online/doctor.ts +2 -0
- package/src/client/host/online/linkScreens.ts +30 -4
- package/src/client/host/standalone/shell.ts +4 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +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 +15 -4
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +10 -6
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +98 -16
- package/src/server/host/dedicated/cellProtocol.ts +16 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +16 -6
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +3 -2
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +126 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/workerTable.ts +15 -4
- 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 +4 -1
- package/src/server/host/standalone/serverProduct.ts +41 -11
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +47 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/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
|
@@ -8,8 +8,8 @@ import type { NetClient } from './client';
|
|
|
8
8
|
export type LinkState = 'live' | 'reconnecting' | 'resuming' | 'lost' | 'full' | 'ended';
|
|
9
9
|
/** Why a link is down, as far as a browser can tell (meta MMO-FAILURE-MODES-PLAN FM4): `silent` stopped carrying frames (a half-open
|
|
10
10
|
* socket), `closed` was closed with no word (1006, a reset), `restart` was closed by a restarting server, `hidden` went quiet while the
|
|
11
|
-
* page was out of view. It rides `onState`'s reason for `reconnecting` and `resuming`. */
|
|
12
|
-
export type LinkCause = 'silent' | 'closed' | 'restart' | 'hidden' | 'updating';
|
|
11
|
+
* page was out of view, `offline` is a device that says it has no network (FM4b mode 2). It rides `onState`'s reason for `reconnecting` and `resuming`. */
|
|
12
|
+
export type LinkCause = 'silent' | 'closed' | 'restart' | 'hidden' | 'updating' | 'offline';
|
|
13
13
|
/** Where the dial is, for a screen that shows it: dials so far, the wait to the next (null while one is out), and how long it's been down. */
|
|
14
14
|
export interface LinkProgress { readonly dials: number; readonly nextDialMs: number | null; readonly downMs: number }
|
|
15
15
|
|
|
@@ -51,7 +51,10 @@ export interface RedialOptions {
|
|
|
51
51
|
readonly onCut?: (reason: string) => void;
|
|
52
52
|
readonly now?: () => number;
|
|
53
53
|
readonly random?: () => number;
|
|
54
|
+
/** FM4b mode 2: does the device say it has a network? Default `navigator.onLine`; a browser with no answer counts as online. */
|
|
55
|
+
readonly online?: () => boolean;
|
|
54
56
|
}
|
|
57
|
+
const browserOnline = (): boolean => typeof navigator === 'undefined' || (navigator as { onLine?: boolean }).onLine !== false;
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
60
|
* E7.1: one client's link, kept up. It watches for frames, and a link that stops carrying them is closed and dialled again on a
|
|
@@ -62,6 +65,7 @@ export class Redial {
|
|
|
62
65
|
private readonly scope = new Scope('net.redial');
|
|
63
66
|
private readonly now: () => number;
|
|
64
67
|
private readonly random: () => number;
|
|
68
|
+
private readonly online: () => boolean;
|
|
65
69
|
private readonly offFrame: () => void;
|
|
66
70
|
private transport: Transport;
|
|
67
71
|
private offClose: () => void;
|
|
@@ -75,8 +79,10 @@ export class Redial {
|
|
|
75
79
|
private dialled: number | null = null;
|
|
76
80
|
private waitingForSeat = false;
|
|
77
81
|
private cause: LinkCause = 'closed';
|
|
82
|
+
/** When the device last said it went offline while the link was down; null while it has a network. */
|
|
83
|
+
private offlineAt: number | null = null;
|
|
78
84
|
constructor(options: RedialOptions) {
|
|
79
|
-
this.options = options; this.transport = options.transport; this.now = options.now ?? diagnosticNow; this.random = options.random ?? jitterFrom(this.now());
|
|
85
|
+
this.options = options; this.transport = options.transport; this.now = options.now ?? diagnosticNow; this.random = options.random ?? jitterFrom(this.now()); this.online = options.online ?? browserOnline;
|
|
80
86
|
this.offFrame = options.client.onFrame(() => { this.heard(); });
|
|
81
87
|
this.offClose = this.watchClose(options.transport);
|
|
82
88
|
this.scope.interval(WATCH_MS, () => { this.watch(); });
|
|
@@ -112,7 +118,7 @@ export class Redial {
|
|
|
112
118
|
private heard(): void {
|
|
113
119
|
const now = this.now(), wasDown = this.phase === 'down';
|
|
114
120
|
this.heardAt = now;
|
|
115
|
-
if (wasDown) { this.phase = 'up'; this.dialled = null; this.dials = 0; this.waitingForSeat = false; }
|
|
121
|
+
if (wasDown) { this.phase = 'up'; this.dialled = null; this.dials = 0; this.waitingForSeat = false; this.offlineAt = null; }
|
|
116
122
|
this.show('live');
|
|
117
123
|
}
|
|
118
124
|
private watch(): void {
|
|
@@ -120,18 +126,35 @@ export class Redial {
|
|
|
120
126
|
if (this.phase === 'up') {
|
|
121
127
|
if (this.heardAt === null) return;
|
|
122
128
|
const silent = now - this.heardAt;
|
|
123
|
-
if (silent >= STRIP_MS && this.state === 'live') this.because('silent');
|
|
129
|
+
if (silent >= STRIP_MS && this.state === 'live') this.because(this.online() ? 'silent' : 'offline');
|
|
124
130
|
if (silent >= DROP_MS) this.lose(now); else if (silent >= STRIP_MS) this.show('reconnecting');
|
|
125
131
|
} else if (this.phase === 'down') this.redial(now);
|
|
126
132
|
}
|
|
127
133
|
private redial(now: number): void {
|
|
128
134
|
if (this.waitingForSeat) { if (this.dialled === null && now >= this.dialAt) this.dial(now); else if (this.dialled !== null && now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
135
|
+
if (this.offline(now)) { if (this.dialled !== null && now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
129
136
|
const out = now - this.lostAt;
|
|
130
137
|
if (out >= GIVE_UP_MS) { this.stop(); this.show('lost'); return; }
|
|
131
138
|
if (out >= RESUMING_MS) this.show('resuming');
|
|
132
139
|
if (this.dialled !== null) { if (now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
133
140
|
if (now >= this.dialAt) this.dial(now);
|
|
134
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* FM4b mode 2: a device with no network is not dialled (each dial would only fail) and its give-up clock stands still, so a
|
|
144
|
+
* phone in a tunnel never reaches `lost` while it waits; the world's own hold on the seat (J114) is the server's and goes on.
|
|
145
|
+
* The network back: the clock goes on from where it stopped and the dial goes out at once. True while offline.
|
|
146
|
+
*/
|
|
147
|
+
private offline(now: number): boolean {
|
|
148
|
+
if (!this.online()) {
|
|
149
|
+
this.offlineAt ??= now;
|
|
150
|
+
this.because('offline');
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (this.offlineAt === null) return false;
|
|
154
|
+
this.lostAt += now - this.offlineAt; this.offlineAt = null; this.dialAt = now;
|
|
155
|
+
this.because('closed');
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
135
158
|
private dial(now: number): void {
|
|
136
159
|
const transport = this.options.dial();
|
|
137
160
|
this.offClose(); this.transport = transport; this.dialled = now; this.dials++;
|
|
@@ -154,7 +177,7 @@ export class Redial {
|
|
|
154
177
|
if (reason === 'retry' || cut) this.because('updating');
|
|
155
178
|
if (cut) this.options.onCut?.(reason);
|
|
156
179
|
if (reason === 'full') { this.phase = 'down'; this.waitingForSeat = true; this.dialled = null; this.dialAt = now + FULL_RETRY_MS; this.show('full'); return; }
|
|
157
|
-
if (this.phase === 'up') { if (this.cause !== 'updating') this.because(reason === 'restart' ? 'restart' : 'closed'); this.lose(now, false); }
|
|
180
|
+
if (this.phase === 'up') { if (this.cause !== 'updating') this.because(reason === 'restart' ? 'restart' : this.online() ? 'closed' : 'offline'); this.lose(now, false); }
|
|
158
181
|
else if (this.phase === 'down') { if (reason === 'restart') this.because('restart'); this.failedDial(now); }
|
|
159
182
|
}
|
|
160
183
|
/** The link is gone or no use: from now it is dialled, and a player's 35 s count from the last frame. */
|
|
@@ -1,2 +1,59 @@
|
|
|
1
|
-
/** MF1/MF4: immutable code, content and versioned metadata, keyed by exact absolute URL.
|
|
1
|
+
/** MF1/MF4: immutable code, content and versioned metadata, keyed by exact absolute URL. Production's name; the other
|
|
2
|
+
* channels' names carry the channel (`cacheName`). */
|
|
2
3
|
export const ASSET_CACHE_NAME = 'ws-assets-v1';
|
|
4
|
+
|
|
5
|
+
/** OFFLINE OF12 (J298, Jake 2026-11-12: "The preview build should have a different cache"): every Cache Storage name a
|
|
6
|
+
* build writes carries its channel, so preview and staging on one origin (a local proof, any later shared host) keep
|
|
7
|
+
* disjoint caches and neither's activate deletes the other's. One bundle serves every channel and the deploy stamps
|
|
8
|
+
* `__WS_WORLD__` into the document, so the channel is read at run time, as `homeIconChannel` (app-build/homeIcons.mjs)
|
|
9
|
+
* reads it: no world is preview, a world whose release file is production's is production, any other world is staging.
|
|
10
|
+
* Production keeps the names it always had (renaming them would cold-start every player's cache); preview and staging
|
|
11
|
+
* put the channel after `ws-` (`ws-preview-assets-v1`, `ws-staging-shell-v3-<build>`), so production's prefix tests
|
|
12
|
+
* (`ws-shell-`) never match another channel's caches. */
|
|
13
|
+
export type CacheChannel = 'production' | 'staging' | 'preview';
|
|
14
|
+
export const CACHE_CHANNELS: readonly CacheChannel[] = ['production', 'staging', 'preview'];
|
|
15
|
+
|
|
16
|
+
/** The channel of a build stamp (`__WS_WORLD__`, or undefined on a build with no world). */
|
|
17
|
+
export function cacheChannel(world: unknown): CacheChannel {
|
|
18
|
+
if (typeof world !== 'object' || world === null) return 'preview';
|
|
19
|
+
const release: unknown = Reflect.get(world, 'release');
|
|
20
|
+
return typeof release === 'string' && /\/releases\/production\.json(?:[?#]|$)/u.test(release) ? 'production' : 'staging';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One cache name for a channel: production's as given; another channel's with the channel after `ws-`. */
|
|
24
|
+
export function cacheName(base: string, channel: CacheChannel): string {
|
|
25
|
+
if (channel === 'production') return base;
|
|
26
|
+
return base.startsWith('ws-') ? `ws-${channel}-${base.slice(3)}` : `${base}-${channel}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Whether a Cache Storage name is this channel's own (production's are the `ws-` names no other channel prefixes). */
|
|
30
|
+
export function ownsCache(name: string, channel: CacheChannel): boolean {
|
|
31
|
+
if (channel !== 'production') return name.startsWith(`ws-${channel}-`);
|
|
32
|
+
return name.startsWith('ws-') && !CACHE_CHANNELS.some(other => other !== 'production' && name.startsWith(`ws-${other}-`));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A dedicated worker has no document stamp: the page that starts it hands it the channel (`setCacheChannel`). */
|
|
36
|
+
let given: CacheChannel | undefined;
|
|
37
|
+
export function setCacheChannel(channel: unknown): void {
|
|
38
|
+
if (typeof channel === 'string' && (CACHE_CHANNELS as readonly string[]).includes(channel)) given = channel as CacheChannel;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** This page's (or this worker's, once told) channel. */
|
|
42
|
+
export function pageCacheChannel(): CacheChannel {
|
|
43
|
+
return given ?? cacheChannel((globalThis as { __WS_WORLD__?: unknown }).__WS_WORLD__);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The cross-build asset cache of this page's channel. */
|
|
47
|
+
export function assetCacheName(): string { return cacheName(ASSET_CACHE_NAME, pageCacheChannel()); }
|
|
48
|
+
|
|
49
|
+
/** A production worker opens this empty cache, so another channel's worker on the same origin can tell production's
|
|
50
|
+
* caches (kept) from its own channel's from before OF12, which used production's names (deleted once, see `isForeign`). */
|
|
51
|
+
export const PRODUCTION_MARK = 'ws-production-mark';
|
|
52
|
+
|
|
53
|
+
/** Whether a cache belongs to another channel that is on this origin, which this channel must never delete. Production's
|
|
54
|
+
* names are another channel's only where a production worker has run (`productionHere`, its mark); elsewhere they are
|
|
55
|
+
* this origin's own caches from before the channel names, a one-time cold start's leftovers. */
|
|
56
|
+
export function isForeign(name: string, channel: CacheChannel, productionHere: boolean): boolean {
|
|
57
|
+
if (ownsCache(name, channel) || !name.startsWith('ws-')) return false;
|
|
58
|
+
return channel === 'production' || !ownsCache(name, 'production') || productionHere;
|
|
59
|
+
}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import { workerScope } from '../app/workerScope.js';
|
|
2
2
|
import { diagnosticNow } from '../../../shared/engine/core/clock';
|
|
3
|
+
import { cacheChannel, cacheName, ownsCache, PRODUCTION_MARK } from './cacheNames';
|
|
3
4
|
/* MF1: one URL cache, one build shell, and one previous generation of code.
|
|
4
5
|
* No fetched-body reconstruction, checksums, receipts, packs, retries or work timers. */
|
|
5
6
|
const BUILD = '__BUILD_ID__';
|
|
6
7
|
const DOCUMENT = '__DOCUMENT__';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
// PZ12 (J274): the page origin's COOP and COEP for the baked document (empty on a channel that is not isolated)
|
|
9
|
+
const DOCUMENT_HEADERS = (baked => baked.startsWith('{') ? JSON.parse(baked) : {})('__DOCUMENT_HEADERS__');
|
|
10
|
+
const ISOLATED = Object.keys(DOCUMENT_HEADERS).length > 0;
|
|
11
|
+
/** PZ12: a dedicated worker in an isolated page starts only if its own script carries COEP. A worker chunk whose name did
|
|
12
|
+
* not change across the switch is held here (or in the HTTP cache) with the headers it was first fetched with, so on an
|
|
13
|
+
* isolated channel every worker script this worker answers wears the document's headers. */
|
|
14
|
+
async function isolatedWorkerScript(pending) {
|
|
15
|
+
const response = await pending;
|
|
16
|
+
if (response.type === 'opaque' || response.type === 'opaqueredirect') return response;
|
|
17
|
+
const headers = new Headers(response.headers);
|
|
18
|
+
for (const [name, value] of Object.entries(DOCUMENT_HEADERS)) headers.set(name, value);
|
|
19
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
20
|
+
}
|
|
21
|
+
const answer = (event, request, pending) => { event.respondWith(ISOLATED && request.destination === 'worker' ? isolatedWorkerScript(pending) : pending); };
|
|
11
22
|
/** OFFLINE OF5 (J298): a world build (its document stamped with `__WS_WORLD__`; play, staging) never runs the in-page solo
|
|
12
23
|
* server, so it never precaches the solo server's code or its server book. Read at run time: a deploy stamps the document. */
|
|
13
24
|
const WORLD = /\bglobalThis\.__WS_WORLD__=/u.test(DOCUMENT);
|
|
25
|
+
/** OFFLINE OF12: every cache this worker opens carries its channel (cacheNames.ts), read from the same stamp, so preview and
|
|
26
|
+
* staging on one origin keep disjoint caches. Production's names are the ones it always had. */
|
|
27
|
+
const CHANNEL = cacheChannel((() => {
|
|
28
|
+
const stamp = /\bglobalThis\.__WS_WORLD__=(\{[^;]+\});/u.exec(DOCUMENT)?.[1];
|
|
29
|
+
try { return stamp === undefined ? undefined : JSON.parse(stamp); } catch { return {}; }
|
|
30
|
+
})());
|
|
31
|
+
const ASSETS = cacheName('__ASSET_CACHE__', CHANNEL);
|
|
32
|
+
const BOOKS = cacheName('ws-builds-v1', CHANNEL);
|
|
33
|
+
const SHELL_FAMILY = cacheName('ws-shell-', CHANNEL);
|
|
34
|
+
const SHELL_PREFIX = cacheName('ws-shell-v3-', CHANNEL);
|
|
35
|
+
const SHELL = `${SHELL_PREFIX}${BUILD}`;
|
|
14
36
|
const SOLO_ONLY = /\/standalone\/(?:serverWorker|serverRuntime)-[^/]+\.js$|\/assets\/spawn\/server-[^/]+\.json$/u;
|
|
15
37
|
const FILES = JSON.parse('__FILES__');
|
|
16
38
|
/** What this build precaches and records as its generation: its files, less the solo server's on a world build. */
|
|
@@ -37,7 +59,7 @@ const isHtml = response => /\btext\/html\b/i.test(response.headers.get('content-
|
|
|
37
59
|
const { base: CONTENT_BASE, files: CONTENT_FILES } = JSON.parse('__CONTENT__');
|
|
38
60
|
/** OF5: the server book on the content base is solo-only too (a URL there, its path under the base's folder). */
|
|
39
61
|
const CONTENT_PRECACHE = CONTENT_FILES.filter(href => !WORLD || !SOLO_ONLY.test(new URL(href).pathname));
|
|
40
|
-
const CONTENT_CACHE = 'ws-content-v1';
|
|
62
|
+
const CONTENT_CACHE = cacheName('ws-content-v1', CHANNEL);
|
|
41
63
|
const CONTENT_URL = CONTENT_BASE === '' ? undefined : new URL(CONTENT_BASE);
|
|
42
64
|
/** A base on the page's own origin (contentBase.ts allows one) owns its folder only; the rest of the origin is the page's. */
|
|
43
65
|
const SAME_ORIGIN_BASE = CONTENT_URL?.origin === self.location.origin;
|
|
@@ -114,6 +136,8 @@ workerScope.listen(self, 'install', event => {
|
|
|
114
136
|
]) : undefined;
|
|
115
137
|
event.waitUntil((async () => {
|
|
116
138
|
await routes;
|
|
139
|
+
// OF12: production marks the origin, so another channel's worker here keeps production's caches
|
|
140
|
+
if (CHANNEL === 'production') await caches.open(PRODUCTION_MARK);
|
|
117
141
|
const [assets, shell, books] = await Promise.all([store(ASSETS), store(SHELL), caches.open(BOOKS)]);
|
|
118
142
|
await importPrevious(assets, books);
|
|
119
143
|
const namedShell = SHELL_FILES.filter(path => immutable(new URL(abs(path))));
|
|
@@ -269,9 +293,15 @@ workerScope.listen(self, 'activate', event => {
|
|
|
269
293
|
await books.delete(key);
|
|
270
294
|
}
|
|
271
295
|
await carryNetworkFirst().catch(() => undefined);
|
|
296
|
+
// OF12: only this channel's older shells (and production's legacy caches) go. Another channel's worker on this origin
|
|
297
|
+
// also drops every cache under production's names (its own from before OF12, and the legacy ws-content-v0) on each
|
|
298
|
+
// activate, unless production runs here too; nothing on this channel writes them again, so in effect it happens once.
|
|
299
|
+
const productionHere = CHANNEL !== 'production' && await caches.has(PRODUCTION_MARK);
|
|
272
300
|
for (const name of await caches.keys()) {
|
|
273
|
-
if (name === SHELL) continue;
|
|
274
|
-
|
|
301
|
+
if (name === SHELL || name === PRODUCTION_MARK) continue;
|
|
302
|
+
const legacy = CHANNEL === 'production' && (name.startsWith('ws-static-') || name === 'ws-immutable');
|
|
303
|
+
if (name.startsWith(SHELL_FAMILY) || legacy) await caches.delete(name);
|
|
304
|
+
else if (CHANNEL !== 'production' && !productionHere && ownsCache(name, 'production')) await caches.delete(name);
|
|
275
305
|
}
|
|
276
306
|
})());
|
|
277
307
|
});
|
|
@@ -399,7 +429,7 @@ workerScope.listen(self, 'fetch', event => {
|
|
|
399
429
|
if (url.pathname === '/version.json' || url.pathname === '/sw.js' || url.pathname.startsWith('/api/')) return;
|
|
400
430
|
if (request.mode === 'navigate' || url.pathname === '/' || url.pathname === '/index.html') {
|
|
401
431
|
const received=diagnosticNow();
|
|
402
|
-
event.respondWith(new Response(DOCUMENT, { headers: { 'content-type': 'text/html;charset=utf-8', 'cache-control': 'no-store' } }));
|
|
432
|
+
event.respondWith(new Response(DOCUMENT, { headers: { ...DOCUMENT_HEADERS, 'content-type': 'text/html;charset=utf-8', 'cache-control': 'no-store' } }));
|
|
403
433
|
bootPublish(event,[{operation:'sw:navigation-handler-and-delivery',url:request.url,start:received,end:diagnosticNow(),result:'complete'}]);
|
|
404
434
|
return;
|
|
405
435
|
}
|
|
@@ -408,12 +438,12 @@ workerScope.listen(self, 'fetch', event => {
|
|
|
408
438
|
return;
|
|
409
439
|
}
|
|
410
440
|
if (immutable(url)) {
|
|
411
|
-
event
|
|
441
|
+
answer(event, request, cached(request, ASSETS, event));
|
|
412
442
|
return;
|
|
413
443
|
}
|
|
414
444
|
if (/^\/(?:assets|basis|fonts)\//.test(url.pathname) || url.pathname === '/manifest.webmanifest') {
|
|
415
|
-
event
|
|
416
|
-
} else if (NETWORK_FIRST.test(url.pathname)) event
|
|
445
|
+
answer(event, request, cached(request, SHELL, event));
|
|
446
|
+
} else if (NETWORK_FIRST.test(url.pathname)) answer(event, request, networkFirst(request, SHELL, event));
|
|
417
447
|
});
|
|
418
448
|
|
|
419
449
|
workerScope.listen(self, 'message', event => {
|
|
@@ -22,8 +22,11 @@ import { loadLookGraphCompiler } from './graphBackend';
|
|
|
22
22
|
import { EmissiveLook } from './families/emissive';
|
|
23
23
|
import { familyMaterial } from './families/registry';
|
|
24
24
|
import { ToonLook } from './families/toon';
|
|
25
|
-
import { LOOK_RIM_PATCH, lightPools, rimPatch } from './lookLight';
|
|
26
|
-
import
|
|
25
|
+
import { LOOK_RIM_PATCH, bounceLight, environmentScene, lampLights, lightPools, rimPatch } from './lookLight';
|
|
26
|
+
import { ExposureEffect, lampHalos, lookMotes, tickGlow } from './lookRender';
|
|
27
|
+
import type { LookMotes, LookShadow, LookVignette } from '@wildshard/format/look-render';
|
|
28
|
+
import type { LookBounce, LookEnvironment, LookLamp, LookPools, LookRim } from '@wildshard/format/look-light';
|
|
29
|
+
import { tierPmremGenerator } from './pmremSize';
|
|
27
30
|
|
|
28
31
|
type Rgb = readonly [number, number, number];
|
|
29
32
|
const mesh = (object: THREE.Object3D): object is THREE.Mesh => object instanceof THREE.Mesh;
|
|
@@ -59,7 +62,21 @@ export interface DataLookSpec {
|
|
|
59
62
|
* its light settings as they resolved at load (LF1-4, `render/lookLight.ts`): a rim patched into every lit material, the
|
|
60
63
|
* light pools' decal draw and the fog program's height density; absent: none of them
|
|
61
64
|
*/
|
|
62
|
-
readonly light?: {
|
|
65
|
+
readonly light?: {
|
|
66
|
+
readonly rim: LookRim | null; readonly pools: LookPools | null; readonly heightFogDensity: number;
|
|
67
|
+
/** B2: real lamps, a warm bounce and a sky-derived environment; absent or null: none */
|
|
68
|
+
readonly lamps?: readonly LookLamp[] | null; readonly bounce?: LookBounce | null; readonly environment?: LookEnvironment | null;
|
|
69
|
+
/** TEMPLATES-CLEANROOM M4: the sun's shadow look and glow motes; absent or null: the engine's shadows, no motes */
|
|
70
|
+
readonly shadow?: LookShadow | null; readonly motes?: LookMotes | null;
|
|
71
|
+
};
|
|
72
|
+
/** B2 (`look.grade.tone` neutral): the Neutral display curve in place of the engine's AgX */
|
|
73
|
+
readonly neutral?: boolean;
|
|
74
|
+
/** M4.7 (`look.grade.tone` aces): the ACES filmic curve in place of the engine's AgX */
|
|
75
|
+
readonly aces?: boolean;
|
|
76
|
+
/** M4.7: `look.grade.exposure` in stops ahead of the tone curve (absent or 0: none), its vignette and bloom radius */
|
|
77
|
+
readonly exposure?: number;
|
|
78
|
+
readonly vignette?: LookVignette | null;
|
|
79
|
+
readonly bloomRadius?: number | null;
|
|
63
80
|
}
|
|
64
81
|
|
|
65
82
|
/** A sampled look: plain numbers, blended between the two keys around a time of day. */
|
|
@@ -129,6 +146,63 @@ async function lutTexture(url: string | Uint8Array | null): Promise<LookupTextur
|
|
|
129
146
|
return lut;
|
|
130
147
|
}
|
|
131
148
|
|
|
149
|
+
const NEUTRAL_FRAGMENT = `
|
|
150
|
+
vec3 neutralCurve(vec3 color) {
|
|
151
|
+
const float startCompression = 0.8 - 0.04;
|
|
152
|
+
const float desaturation = 0.15;
|
|
153
|
+
float x = min(color.r, min(color.g, color.b));
|
|
154
|
+
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
|
|
155
|
+
color -= offset;
|
|
156
|
+
float peak = max(color.r, max(color.g, color.b));
|
|
157
|
+
if (peak < startCompression) return color;
|
|
158
|
+
float d = 1.0 - startCompression;
|
|
159
|
+
float newPeak = 1.0 - d * d / (peak + d - startCompression);
|
|
160
|
+
color *= newPeak / peak;
|
|
161
|
+
float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
|
|
162
|
+
return mix(color, vec3(newPeak), g);
|
|
163
|
+
}
|
|
164
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
165
|
+
outputColor = vec4(neutralCurve(inputColor.rgb), inputColor.a);
|
|
166
|
+
}
|
|
167
|
+
`;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The NEUTRAL tone curve (Khronos PBR Neutral, three's `NeutralToneMapping` at exposure 1) as a grid cell's display: the
|
|
171
|
+
* page's colour pass already holds a ToneMappingEffect, and a second one includes three's tone-mapping chunk twice
|
|
172
|
+
* ('toneMappingExposure' redefinition), so the merged pass would never compile; this is the same curve under its own name.
|
|
173
|
+
*/
|
|
174
|
+
export class NeutralToneEffect extends Effect {
|
|
175
|
+
constructor() { super('NeutralToneEffect', NEUTRAL_FRAGMENT, { blendFunction: BlendFunction.NORMAL }); }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const ACES_FRAGMENT = `
|
|
179
|
+
uniform float uExposure;
|
|
180
|
+
vec3 acesFit(vec3 v) { vec3 a = v * (v + 0.0245786) - 0.000090537; vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081; return a / b; }
|
|
181
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
182
|
+
const mat3 inputMat = mat3(vec3(0.59719, 0.07600, 0.02840), vec3(0.35458, 0.90834, 0.13383), vec3(0.04823, 0.01566, 0.83777));
|
|
183
|
+
const mat3 outputMat = mat3(vec3(1.60475, -0.10208, -0.00327), vec3(-0.53108, 1.10813, -0.07276), vec3(-0.07367, -0.00605, 1.07602));
|
|
184
|
+
vec3 color = outputMat * acesFit(inputMat * (inputColor.rgb * uExposure / 0.6));
|
|
185
|
+
outputColor = vec4(clamp(color, 0.0, 1.0), inputColor.a);
|
|
186
|
+
}
|
|
187
|
+
`;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* M4.7 (review MUST): the ACES filmic curve (three's `ACESFilmicToneMapping`) as a grid cell's display, with the look's
|
|
191
|
+
* exposure folded in, for the reason `NeutralToneEffect` exists: a cell never runs `compose`, so the page chain's tone
|
|
192
|
+
* mode and the spliced `ExposureEffect` never reach it.
|
|
193
|
+
*/
|
|
194
|
+
export class AcesToneEffect extends Effect {
|
|
195
|
+
constructor(stops: number) {
|
|
196
|
+
super('AcesToneEffect', ACES_FRAGMENT, { blendFunction: BlendFunction.NORMAL, uniforms: new Map([['uExposure', new THREE.Uniform(2 ** stops)]]) });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** a data look's grid-cell display: its own tone curve, when it names one (Neutral, or ACES with its exposure) */
|
|
201
|
+
function cellTone(spec: { readonly neutral?: boolean; readonly aces?: boolean; readonly exposure?: number }): { readonly cell: { readonly replaces: 'tone'; readonly build: () => { display: Effect } } } | Record<string, never> {
|
|
202
|
+
if (spec.aces === true) { const stops = spec.exposure ?? 0; return { cell: { replaces: 'tone', build: () => ({ display: new AcesToneEffect(stops) }) } }; }
|
|
203
|
+
return spec.neutral === true ? { cell: { replaces: 'tone', build: () => ({ display: new NeutralToneEffect() }) } } : {};
|
|
204
|
+
}
|
|
205
|
+
|
|
132
206
|
/**
|
|
133
207
|
* A level look from data: the engine's clean chain, the gradient dome, the engine fog, key light and ambient turned by
|
|
134
208
|
* the keys on the engine clock, and the LUT last in the grade. Nothing is patched into another material.
|
|
@@ -136,6 +210,8 @@ async function lutTexture(url: string | Uint8Array | null): Promise<LookupTextur
|
|
|
136
210
|
export function dataLook(spec: DataLookSpec): LookStrategy {
|
|
137
211
|
if (spec.keys.length === 0) throw new Error('[look] a data look needs at least one key');
|
|
138
212
|
const linear = spec.keys[0]?.fog.near !== undefined;
|
|
213
|
+
// the keys the frame samples: a `liveKeys` call (sharddev `watch`, through engine's dev hook) replaces them in place
|
|
214
|
+
let keys = spec.keys;
|
|
139
215
|
// the mist's GLSL is in the linear fog only when the look declares it (LF1-4): off, the shader text is as before
|
|
140
216
|
const mist = (spec.light?.heightFogDensity ?? 0) > 0;
|
|
141
217
|
const fog = { wsLookFogNear: new THREE.Uniform(0), wsLookFogFar: new THREE.Uniform(1), wsLookFogEnabled: new THREE.Uniform(0) };
|
|
@@ -163,11 +239,24 @@ ${mist ? `
|
|
|
163
239
|
#endif`);
|
|
164
240
|
shader.fragmentShader = `#ifdef USE_FOG\nuniform float wsLookFogNear; uniform float wsLookFogFar; uniform float wsLookFogEnabled;\n#endif\n${patched}`;
|
|
165
241
|
};
|
|
166
|
-
const owned: { dome: THREE.Mesh<THREE.SphereGeometry, THREE.ShaderMaterial> | null; lut: LookupTexture | null; pools: THREE.Object3D | null; rim: boolean
|
|
242
|
+
const owned: { dome: THREE.Mesh<THREE.SphereGeometry, THREE.ShaderMaterial> | null; lut: LookupTexture | null; pools: THREE.Object3D | null; rim: boolean;
|
|
243
|
+
lamps: ReturnType<typeof lampLights> | null; bounce: ReturnType<typeof bounceLight> | null; environment: THREE.WebGLRenderTarget | null;
|
|
244
|
+
glow: THREE.Object3D[] | null } = { dome: null, lut: null, pools: null, rim: false, lamps: null, bounce: null, environment: null, glow: null };
|
|
245
|
+
const shadow = spec.light?.shadow ?? null;
|
|
246
|
+
const bounceRow = spec.light?.bounce ?? null;
|
|
247
|
+
// the bounce exists from the backdrop on (it follows the clock's sun there); compose adds it to the scene
|
|
248
|
+
if (bounceRow !== null) owned.bounce = bounceLight(bounceRow);
|
|
167
249
|
return {
|
|
250
|
+
...cellTone(spec),
|
|
251
|
+
liveKeys: (next) => {
|
|
252
|
+
// a fog kind change (exponential to linear, or back) changes the fog patch's shader text: that needs a new look
|
|
253
|
+
if (next.length === 0 || next.some((key) => (key.fog.near !== undefined) !== linear)) return false;
|
|
254
|
+
keys = next;
|
|
255
|
+
return true;
|
|
256
|
+
},
|
|
168
257
|
// the sky builds before the composer: the level scope takes the dome and the LUT here
|
|
169
|
-
mode: 'extend', chain: 'clean', compose: ({ engineChain, scene, scope }) => {
|
|
170
|
-
const rim = spec.light?.rim ?? null, pools = spec.light?.pools ?? null;
|
|
258
|
+
mode: 'extend', chain: 'clean', compose: ({ engineChain, scene, scope, fx, renderer }) => {
|
|
259
|
+
const rim = spec.light?.rim ?? null, pools = spec.light?.pools ?? null, lamps = spec.light?.lamps ?? null;
|
|
171
260
|
if (rim !== null && !owned.rim) {
|
|
172
261
|
owned.rim = true; scope.onDispose(() => { owned.rim = false; });
|
|
173
262
|
// LF1-4: one rim patch over every lit material, present and later (its values are uniforms: one shader text)
|
|
@@ -187,6 +276,43 @@ ${mist ? `
|
|
|
187
276
|
owned.pools = decal;
|
|
188
277
|
scene.add(decal); scope.own(decal.geometry); scope.own(decal.material); scope.onDispose(() => { decal.removeFromParent(); decal.dispose(); if (owned.pools === decal) owned.pools = null; });
|
|
189
278
|
}
|
|
279
|
+
if (lamps !== null && owned.lamps === null) {
|
|
280
|
+
// B2: real lamps, once per look like the pools
|
|
281
|
+
const group = lampLights(lamps);
|
|
282
|
+
owned.lamps = group;
|
|
283
|
+
scene.add(group); scope.onDispose(() => { group.removeFromParent(); for (const light of group.children) if (light instanceof THREE.Light) light.dispose(); if (owned.lamps === group) owned.lamps = null; });
|
|
284
|
+
}
|
|
285
|
+
const motes = spec.light?.motes ?? null;
|
|
286
|
+
if (owned.glow === null && ((lamps?.some((lamp) => lamp.halo !== undefined) ?? false) || motes !== null)) {
|
|
287
|
+
// M4.8: the lamps' halos (one instanced draw) and the motes (one points draw), once per look like the lamps
|
|
288
|
+
const glow: (THREE.Mesh | THREE.Points)[] = [];
|
|
289
|
+
const halos = lamps === null ? null : lampHalos(lamps);
|
|
290
|
+
if (halos !== null) glow.push(halos);
|
|
291
|
+
if (motes !== null) glow.push(lookMotes(motes));
|
|
292
|
+
owned.glow = glow;
|
|
293
|
+
for (const draw of glow) { scene.add(draw); scope.own(draw.geometry); scope.own(draw.material as THREE.Material); }
|
|
294
|
+
scope.onDispose(() => { for (const draw of glow) { draw.removeFromParent(); if (draw instanceof THREE.InstancedMesh) draw.dispose(); } if (owned.glow === glow) owned.glow = null; });
|
|
295
|
+
}
|
|
296
|
+
const bounce = owned.bounce;
|
|
297
|
+
if (bounce !== null && bounce.light.parent !== scene) {
|
|
298
|
+
scene.add(bounce.light, bounce.light.target); scope.onDispose(() => { bounce.light.removeFromParent(); bounce.light.target.removeFromParent(); });
|
|
299
|
+
}
|
|
300
|
+
const envRow = spec.light?.environment ?? null;
|
|
301
|
+
if (envRow !== null && owned.environment === null && owned.dome !== null) {
|
|
302
|
+
// B2: sky-derived ambient, filtered once from the dome at the look's start (a clock that runs keeps this one). Built
|
|
303
|
+
// here, not in the backdrop: a grid cell runs only the backdrop and must not hold an unused cube (review MUST 2).
|
|
304
|
+
// The far plane clears the 600 m dome (fromScene's default 100 m clips it to black).
|
|
305
|
+
const made = environmentScene(owned.dome, envRow), pmrem = tierPmremGenerator(renderer);
|
|
306
|
+
let target: THREE.WebGLRenderTarget;
|
|
307
|
+
try { target = pmrem.fromScene(made.scene, 0.02, 0.1, 1000); } finally { pmrem.dispose(); made.dispose(); }
|
|
308
|
+
const before = { environment: scene.environment, intensity: scene.environmentIntensity };
|
|
309
|
+
owned.environment = target;
|
|
310
|
+
scene.environment = target.texture; scene.environmentIntensity = envRow.intensity;
|
|
311
|
+
scope.onDispose(() => {
|
|
312
|
+
if (scene.environment === target.texture) { scene.environment = before.environment; scene.environmentIntensity = before.intensity; }
|
|
313
|
+
target.dispose(); if (owned.environment === target) owned.environment = null;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
190
316
|
if (linear) {
|
|
191
317
|
setInheritedPatch(patchFog, { scope, chain: true });
|
|
192
318
|
const seen = new Set<THREE.Material>();
|
|
@@ -201,20 +327,34 @@ ${mist ? `
|
|
|
201
327
|
const { dome, lut } = owned;
|
|
202
328
|
if (dome !== null) { scope.own(dome.geometry); scope.own(dome.material); scope.onDispose(() => { dome.removeFromParent(); }); }
|
|
203
329
|
if (lut !== null) scope.own(lut);
|
|
204
|
-
|
|
330
|
+
const chain = engineChain('clean');
|
|
331
|
+
// B2: the Neutral curve keeps the look's saturated albedo saturated, where AgX would grey it (asked after the clean chain)
|
|
332
|
+
if (spec.neutral === true) fx.tone.mode = ToneMappingMode.NEUTRAL;
|
|
333
|
+
// M4.7: ACES, the look's own vignette and bloom spread, and its exposure ahead of the curve
|
|
334
|
+
if (spec.aces === true) fx.tone.mode = ToneMappingMode.ACES_FILMIC;
|
|
335
|
+
if (spec.vignette !== undefined && spec.vignette !== null) { fx.vignette.offset = spec.vignette.offset; fx.vignette.darkness = spec.vignette.darkness; }
|
|
336
|
+
if (spec.bloomRadius !== undefined && spec.bloomRadius !== null) fx.bloom.mipmapBlurPass.radius = spec.bloomRadius;
|
|
337
|
+
const stops = spec.exposure ?? 0, at = chain.indexOf(fx.tone);
|
|
338
|
+
if (stops !== 0 && at !== -1) { const exposure = new ExposureEffect(stops); scope.own(exposure); chain.splice(at, 0, exposure); }
|
|
339
|
+
return { chain };
|
|
205
340
|
},
|
|
206
341
|
// G992: no sun disc or corona over the gradient dome. A 1° disc read as a blurred speck with a halo ("half-assed moon
|
|
207
342
|
// or sun", Jake), and a crisp disc alone as a 3 px dot (art/open-plots/sun-disc-g992/board.jpg); the key light is unchanged.
|
|
208
343
|
sky: { clouds: false, planet: false, sun: { disc: false, halo: false } },
|
|
344
|
+
// M4.7: the look's shadow radius and normal bias (its strength is set on the cascades each frame, below)
|
|
345
|
+
...(shadow === null ? {} : { shadows: { rig: 'tier' as const, radius: shadow.radius, normalBias: shadow.normalBias } }),
|
|
209
346
|
backdrop: async ({ sky }) => {
|
|
210
347
|
const clock = dataLookClock(spec.day, spec.dayOverride), now = lookSample();
|
|
211
348
|
const { dome, zenith, horizon } = gradientDome();
|
|
212
349
|
owned.dome = dome;
|
|
213
|
-
|
|
350
|
+
const bounce = owned.bounce;
|
|
351
|
+
let targets: SkyBackdropTargets | null = null, flicker = 0;
|
|
214
352
|
const apply = (): void => {
|
|
215
|
-
sampleLook(
|
|
353
|
+
sampleLook(keys, clock.hour / 24, now);
|
|
216
354
|
zenith.copy(now.zenith); horizon.copy(now.horizon);
|
|
217
355
|
sky.setKeyLight(clock.sunDir, now.sun, now.sunIntensity);
|
|
356
|
+
bounce?.aim(clock.sunDir);
|
|
357
|
+
if (shadow !== null) for (const light of (sky.csm as { lights?: readonly THREE.DirectionalLight[] } | undefined)?.lights ?? []) light.shadow.intensity = shadow.intensity;
|
|
218
358
|
if (targets === null) return;
|
|
219
359
|
targets.hemi.color.copy(now.ambientSky); targets.hemi.groundColor.copy(now.ambientGround); targets.hemi.intensity = now.ambientIntensity;
|
|
220
360
|
fog.wsLookFogEnabled.value = targets.underwater() ? 0 : Number(linear);
|
|
@@ -227,12 +367,13 @@ ${mist ? `
|
|
|
227
367
|
targets.fogU.fogDistDensity.value = now.fogDensity; targets.fogU.fogHeightDensity.value = spec.light?.heightFogDensity ?? 0;
|
|
228
368
|
targets.fogU.fogSunColor.value.copy(now.sun);
|
|
229
369
|
};
|
|
230
|
-
sampleLook(
|
|
370
|
+
sampleLook(keys, clock.hour / 24, now);
|
|
231
371
|
zenith.copy(now.zenith); horizon.copy(now.horizon);
|
|
372
|
+
bounce?.aim(clock.sunDir);
|
|
232
373
|
owned.lut = await lutTexture(spec.lut);
|
|
233
374
|
return { clock, horizon: now.fog.clone(), lut: owned.lut, clouds: dome,
|
|
234
375
|
bind: (t) => { targets = t; apply(); },
|
|
235
|
-
update: (dt) => { clock.update(dt); apply(); },
|
|
376
|
+
update: (dt) => { clock.update(dt); apply(); flicker += dt; owned.lamps?.update?.(flicker); if (owned.glow !== null) tickGlow(owned.glow, flicker); },
|
|
236
377
|
rebuild: () => undefined, attachPost: () => undefined };
|
|
237
378
|
},
|
|
238
379
|
};
|
|
@@ -373,35 +514,6 @@ export function headingHaze(row: HeadingHazeRow, sun: LookVec3): (shader: Shader
|
|
|
373
514
|
};
|
|
374
515
|
}
|
|
375
516
|
|
|
376
|
-
const NEUTRAL_FRAGMENT = `
|
|
377
|
-
vec3 neutralCurve(vec3 color) {
|
|
378
|
-
const float startCompression = 0.8 - 0.04;
|
|
379
|
-
const float desaturation = 0.15;
|
|
380
|
-
float x = min(color.r, min(color.g, color.b));
|
|
381
|
-
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
|
|
382
|
-
color -= offset;
|
|
383
|
-
float peak = max(color.r, max(color.g, color.b));
|
|
384
|
-
if (peak < startCompression) return color;
|
|
385
|
-
float d = 1.0 - startCompression;
|
|
386
|
-
float newPeak = 1.0 - d * d / (peak + d - startCompression);
|
|
387
|
-
color *= newPeak / peak;
|
|
388
|
-
float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0);
|
|
389
|
-
return mix(color, vec3(newPeak), g);
|
|
390
|
-
}
|
|
391
|
-
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
392
|
-
outputColor = vec4(neutralCurve(inputColor.rgb), inputColor.a);
|
|
393
|
-
}
|
|
394
|
-
`;
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* The NEUTRAL tone curve (Khronos PBR Neutral, three's `NeutralToneMapping` at exposure 1) as a grid cell's display: the
|
|
398
|
-
* page's colour pass already holds a ToneMappingEffect, and a second one includes three's tone-mapping chunk twice
|
|
399
|
-
* ('toneMappingExposure' redefinition), so the merged pass would never compile; this is the same curve under its own name.
|
|
400
|
-
*/
|
|
401
|
-
export class NeutralToneEffect extends Effect {
|
|
402
|
-
constructor() { super('NeutralToneEffect', NEUTRAL_FRAGMENT, { blendFunction: BlendFunction.NORMAL }); }
|
|
403
|
-
}
|
|
404
|
-
|
|
405
517
|
/** A painted look's dome (its sky layer) and the heading strip its haze reads (null on a painted-strip sky). */
|
|
406
518
|
export interface PaintedSky { readonly dome: THREE.Mesh<THREE.BufferGeometry, THREE.Material>; readonly strip: THREE.Texture | null }
|
|
407
519
|
/** A painted look's dressing: the sky pieces that stand in the world (a sea of cloud, the sun's glow) and their tick. */
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PBR family's detail layer (meta TEMPLATES-CLEANROOM M4.11, `@wildshard/format/detail-layer`, J338's procedural
|
|
3
|
+
* route): the stone, slab, wood and moss texture a cleanroom paints on canvases, drawn by the shader from world position,
|
|
4
|
+
* so it costs no bytes and needs no UVs. Per pixel:
|
|
5
|
+
* - broad value-noise blotches swing the albedo by `mottle`, a fine speckle by `grain`;
|
|
6
|
+
* - the same pattern, read as a height in metres, tilts the shading normal by `relief` (screen-space bump, Mikkelsen's
|
|
7
|
+
* surface-gradient method, as three's bump map);
|
|
8
|
+
* - `moss` grows on up-facing faces where a second, coarser noise passes `1 - amount`.
|
|
9
|
+
* Every knob is a uniform over one shader text, so all detailed surfaces share one program. Identifiers carry a `famD`
|
|
10
|
+
* prefix. A surface takes a detail layer alone, not with a ground or measure layer (each owns the albedo).
|
|
11
|
+
*/
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
import { patchShader, PATCH_ORDER } from '../shaderPatches';
|
|
14
|
+
import type { PbrMaterialParams } from '@wildshard/format/materialFamilies';
|
|
15
|
+
|
|
16
|
+
/** a PBR surface's detail layer (`@wildshard/format/detail-layer`'s `DetailLayer`) */
|
|
17
|
+
type DetailLayer = NonNullable<PbrMaterialParams['detail']>;
|
|
18
|
+
|
|
19
|
+
/** the program-cache key of every PBR material with a detail layer */
|
|
20
|
+
export const DETAIL_PROGRAM_KEY = 'family.pbr.detail.v1';
|
|
21
|
+
/** the speckle's frequency over the blotches' */
|
|
22
|
+
const GRAIN_OCTAVE = 9;
|
|
23
|
+
/** the relief's height (m) per metre of pattern scale at `relief` 1 */
|
|
24
|
+
const RELIEF_HEIGHT = 0.12;
|
|
25
|
+
|
|
26
|
+
const VERT_PARS = 'varying vec3 vFamDPos;\nvarying vec3 vFamDN;';
|
|
27
|
+
const VERT_WORLD = /* glsl */`#include <worldpos_vertex>
|
|
28
|
+
vec4 famDW = vec4( transformed, 1.0 );
|
|
29
|
+
vec3 famDN = objectNormal;
|
|
30
|
+
#ifdef USE_INSTANCING
|
|
31
|
+
famDW = instanceMatrix * famDW;
|
|
32
|
+
famDN = mat3( instanceMatrix ) * famDN;
|
|
33
|
+
#endif
|
|
34
|
+
vFamDPos = ( modelMatrix * famDW ).xyz;
|
|
35
|
+
vFamDN = normalize( mat3( modelMatrix ) * famDN );`;
|
|
36
|
+
|
|
37
|
+
const FRAG_PARS = /* glsl */`
|
|
38
|
+
varying vec3 vFamDPos;
|
|
39
|
+
varying vec3 vFamDN;
|
|
40
|
+
uniform vec4 famDK; // 1 / scale (1/m), mottle, grain, relief height (m)
|
|
41
|
+
uniform vec4 famDMoss; // linear colour, amount (0 = none)
|
|
42
|
+
float famDHash( vec3 p ) { p = fract( p * 0.1031 ); p += dot( p, p.zyx + 31.32 ); return fract( ( p.x + p.y ) * p.z ); }
|
|
43
|
+
float famDNoise( vec3 p ) {
|
|
44
|
+
vec3 i = floor( p ), f = fract( p );
|
|
45
|
+
f = f * f * ( 3.0 - 2.0 * f );
|
|
46
|
+
float a = mix( famDHash( i ), famDHash( i + vec3( 1.0, 0.0, 0.0 ) ), f.x );
|
|
47
|
+
float b = mix( famDHash( i + vec3( 0.0, 1.0, 0.0 ) ), famDHash( i + vec3( 1.0, 1.0, 0.0 ) ), f.x );
|
|
48
|
+
float c = mix( famDHash( i + vec3( 0.0, 0.0, 1.0 ) ), famDHash( i + vec3( 1.0, 0.0, 1.0 ) ), f.x );
|
|
49
|
+
float d = mix( famDHash( i + vec3( 0.0, 1.0, 1.0 ) ), famDHash( i + vec3( 1.0, 1.0, 1.0 ) ), f.x );
|
|
50
|
+
return mix( mix( a, b, f.y ), mix( c, d, f.y ), f.z );
|
|
51
|
+
}
|
|
52
|
+
float famDFbm( vec3 p ) { return 0.5 * famDNoise( p ) + 0.3 * famDNoise( p * 2.03 + 11.0 ) + 0.2 * famDNoise( p * 4.01 + 23.0 ); }`;
|
|
53
|
+
|
|
54
|
+
const FRAG_COLOUR = /* glsl */`#include <color_fragment>
|
|
55
|
+
vec3 famDP = vFamDPos * famDK.x;
|
|
56
|
+
float famDM = famDFbm( famDP );
|
|
57
|
+
float famDG = famDNoise( famDP * ${GRAIN_OCTAVE.toFixed(1)} );
|
|
58
|
+
diffuseColor.rgb *= max( 0.0, 1.0 + ( famDM - 0.5 ) * 2.0 * famDK.y + ( famDG - 0.5 ) * famDK.z );
|
|
59
|
+
float famDMossK = 0.0;
|
|
60
|
+
if ( famDMoss.w > 0.0 ) {
|
|
61
|
+
float famDUp = smoothstep( 0.5, 0.85, normalize( vFamDN ).y );
|
|
62
|
+
famDMossK = famDUp * smoothstep( 1.0 - famDMoss.w, 1.0 - famDMoss.w + 0.2, famDFbm( famDP * 0.6 + 7.0 ) * 0.7 + famDM * 0.3 );
|
|
63
|
+
diffuseColor.rgb = mix( diffuseColor.rgb, famDMoss.rgb * ( 0.8 + 0.4 * famDG ), famDMossK );
|
|
64
|
+
}`;
|
|
65
|
+
|
|
66
|
+
const FRAG_NORMAL = /* glsl */`#include <normal_fragment_maps>
|
|
67
|
+
if ( famDK.w > 0.0 ) {
|
|
68
|
+
float famDH = ( famDM + ( famDG - 0.5 ) * 0.3 + famDMossK * 0.4 ) * famDK.w;
|
|
69
|
+
vec3 famDSx = dFdx( -vViewPosition ), famDSy = dFdy( -vViewPosition );
|
|
70
|
+
vec3 famDR1 = cross( famDSy, normal ), famDR2 = cross( normal, famDSx );
|
|
71
|
+
float famDDet = dot( famDSx, famDR1 ) * faceDirection;
|
|
72
|
+
vec3 famDGrad = sign( famDDet ) * ( dFdx( famDH ) * famDR1 + dFdy( famDH ) * famDR2 );
|
|
73
|
+
normal = normalize( abs( famDDet ) * normal - famDGrad );
|
|
74
|
+
}`;
|
|
75
|
+
|
|
76
|
+
/** Draw a detail layer on a PBR material (in place). */
|
|
77
|
+
export function applyDetail(m: THREE.MeshStandardMaterial, detail: DetailLayer): void {
|
|
78
|
+
const moss = detail.moss;
|
|
79
|
+
const mossColour = moss === undefined ? new THREE.Color(0, 0, 0) : new THREE.Color().setRGB(moss.colour[0], moss.colour[1], moss.colour[2], THREE.SRGBColorSpace);
|
|
80
|
+
const uniforms: Record<string, { value: unknown }> = {
|
|
81
|
+
famDK: { value: new THREE.Vector4(1 / detail.scale, detail.mottle, detail.grain, detail.relief * detail.scale * RELIEF_HEIGHT) },
|
|
82
|
+
famDMoss: { value: new THREE.Vector4(mossColour.r, mossColour.g, mossColour.b, moss?.amount ?? 0) },
|
|
83
|
+
};
|
|
84
|
+
patchShader(m, 'engine.family.detail', PATCH_ORDER.material, (shader) => {
|
|
85
|
+
Object.assign(shader.uniforms, uniforms);
|
|
86
|
+
shader.vertexShader = shader.vertexShader.replace('#include <common>', `#include <common>\n${VERT_PARS}`).replace('#include <worldpos_vertex>', VERT_WORLD);
|
|
87
|
+
shader.fragmentShader = shader.fragmentShader.replace('#include <common>', `#include <common>\n${FRAG_PARS}`).replace('#include <color_fragment>', FRAG_COLOUR).replace('#include <normal_fragment_maps>', FRAG_NORMAL);
|
|
88
|
+
}, { key: DETAIL_PROGRAM_KEY });
|
|
89
|
+
}
|