feat: the boards stop being three products
The owner asked twice why there are still three separate boards. The honest answer, and what this round executes: **it feels like three boards, but not because the scale jumps 20x — because the three packs draw three different Californias, and the loudest difference is that the mountains are four times taller on one of them.** **THE 20x HORIZONTAL SCALE JUMP IS INVISIBLE**, and measuring that collapsed the cost of this whole round. `World.project` is a uniform scale in x/z with no vertical term, and a uniform scale leaves a perspective image identical — so a camera carried across the seam on matched true-metre offsets draws a pixel-identical horizontal frame. 1,919 -> 94 m/unit costs nothing to look at. Rescaling was never the problem. A boot card, a tab strip and a 4.17x vertical deflation were. **THE PAUSE WAS MOSTLY FAKE.** A switch covered the screen for 1,715 ms but only 608 ms blocked the main thread; the page drew 46 of 69 frames with nothing to show, because the outgoing board had already been disposed. `mountCity` now retains it: the incoming board builds BEHIND a live, interactive picture, and `stage.setScene` fires only on completion. Measured across all six directions, three runs each — boot card yes -> **no**, opaque cover 726-1,415 ms -> **0**, blank frames 21-46 -> **exactly 1**, wall clock down 12-29%, blocked main thread down 15-47%. A return to a board already seen links **zero** shader programs and blocks **zero** milliseconds: 298-312 ms of camera flight where it was ~1,600 ms behind a card. Disposal had been throwing away the shader cache too — linkProgram ran 38, 59, 78, 109, 127 across five mounts and never reused one. **The transition is a fog dip, not a crossfade**, through the `setAerialFog` seam built last round. Every both-boards-live crossfade breaks a budget — ca+sf is 2,640,307 triangles against bay-area's 2,600,000 cap — and a fade never lands inside the harness's sample window, which is the "a cap you do not measure is a cap you do not have" failure this repo already argues against. The dip costs zero triangles and zero draw calls, and it hides the 4.17x deflation, the 4,025 m projection disagreement and the vanishing 2 km freeway symbols at once, because all three happen at maximum obscuration. It is also diegetic: a descent through haze. The first dip was wrong and the photograph caught it: collapsing to 6% of board SPAN turned the whole night frame into one flat field — the exact "turns the map off" failure the risk list named. Re-anchored to 70% of camera STAND-OFF, so the coastline survives and only the relief melts. **One ladder, one places list.** 26 authored chapters become 24 rungs sorted descending by STAND-OFF, not altitude — by altitude they interleave badly and altitude cannot tell a low oblique from a high plan. The three-board tab strip is off by default; the left column is now one scrolling list of all 24 rungs under three region headings that does not change when the board does. Only which row is lit changes. Label collisions are resolved in the ladder and never in a pack, so the 29 index-aimed capture guards are untouched. The minimap stops turning through 90 degrees between boards: every board is pinned to a rectangle with California's proportions. **SF and SoCal are not regressed**, and that was the acceptance that mattered: 95.9-98.8% of board pixels are delta-0 against a baseline hash-verified identical to what the live site serves, and every one of the 34-70 surviving pixels per frame is an aircraft or a hull. **A real defect found only by photograph:** `minimap.setMarkers()` had zero call sites. Every marker on every board was gone — the LA studio's door dot, the Bay Area's eight company markers — dropped when the minimap went per-board. Typecheck, tests, budgets and the console were all green with that bug in. Also fixed: two capture presets that lied. `look.mjs`'s `glyph-la` and `glyph-sf` claimed California chapter closeups and returned SoCal and Bay Area frames, because they aimed by chapter index and the indices had moved. Aiming is now by identity, with a guard test. NOT SHIPPED, DELIBERATELY: the pack merge. At Bay density it is 34.04M triangles, 13x the highest budget — dead, not a trade. At SoCal density it is 1.99M and fits today, and the price is San Francisco rendering at 164 m lots instead of 40 m, i.e. SF looking the way SoCal looks now. SF and SoCal carry every marketing still on the site. That is the owner's decision and it is worthless as an argument and decisive as a photograph, so it ships as a measurement artifact with a side-by-side still and is wired into nothing. The four data reconciliations that would make one world honest — one exaggeration rule, roads in metres, one projection centre, one coastline convention — are behind TERA_RECONCILE, default OFF. Tests 1,570 -> 1,651, server 295. All ten budget cells pass, no cap raised. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1837,9 +1837,28 @@ export const CALIFORNIA_CITY: City = {
|
||||
{ name: "San Francisco", lat: 37.7749, lng: -122.4194, height: 720, footprint: 0.026, shape: "tower", color: 0x9fb2c2, label: true },
|
||||
],
|
||||
bridges: [],
|
||||
/**
|
||||
* The two corridors, authored twice: once as the symbol this board draws and
|
||||
* once as the road it actually is.
|
||||
*
|
||||
* `width` is 1 and 1.06 scene units, which at 1,919 m to the unit is 1,919 m
|
||||
* and 2,034 m of asphalt — wider, by a factor of two, than the widest thing in
|
||||
* downtown Los Angeles, and the most prominent marks on the state board. That
|
||||
* was a deliberate choice and it is defensible on its own terms: a 47 m
|
||||
* freeway on a board 554 units across is a fortieth of a unit and would not
|
||||
* exist at all. It is not defensible at the seam, where the same road is
|
||||
* 43–55 m on Southern California and 23–30 m on the Bay Area, because a 2 km
|
||||
* ribbon becoming a 30 m line is a change of drawing convention rather than an
|
||||
* LOD transition.
|
||||
*
|
||||
* `widthM` is US-101 and I-5 as they are on the ground — six lanes plus
|
||||
* shoulders through the Salinas Valley, eight through the San Joaquin — and it
|
||||
* is read by `cities/reconcile.ts` and by nothing else. The engine draws
|
||||
* `width`, always.
|
||||
*/
|
||||
roads: [
|
||||
{ path: CALIFORNIA_US_101, width: 1, kind: "freeway" },
|
||||
{ path: CALIFORNIA_I_5, width: 1.06, kind: "freeway" },
|
||||
{ path: CALIFORNIA_US_101, width: 1, widthM: 44, kind: "freeway" },
|
||||
{ path: CALIFORNIA_I_5, width: 1.06, widthM: 47, kind: "freeway" },
|
||||
],
|
||||
chapters: [
|
||||
{
|
||||
|
||||
@@ -0,0 +1,461 @@
|
||||
/**
|
||||
* One California, from three packs — behind a flag, so both answers can be
|
||||
* photographed and the owner can choose between them.
|
||||
*
|
||||
* ## The complaint this exists for
|
||||
*
|
||||
* The three boards feel like three boards, and the measured reason is *not*
|
||||
* that the horizontal scale jumps 20× at the seam. `World.project` is a uniform
|
||||
* scale in x/z with no vertical term, and a uniform scale leaves a perspective
|
||||
* image identical: a camera carried across the seam on matched true-metre
|
||||
* offsets draws a pixel-identical horizontal frame. 1,919 → 94 m per unit costs
|
||||
* nothing to look at.
|
||||
*
|
||||
* What is visible is that **the three packs draw three different Californias**,
|
||||
* and every one of those differences is a number in a data file:
|
||||
*
|
||||
* | | california | sf | socal | spread |
|
||||
* | --- | --- | --- | --- | --- |
|
||||
* | `verticalExaggeration` | 15 | 3.6 | 3.4 | 4.41× at a matched pose |
|
||||
* | freeway width, true metres | 1,919–2,034 | 23–30 | 43–55 | 88× |
|
||||
* | longitude squashed by cos | 37.30° | 37.77° | 33.82° | up to ~4 km of drift |
|
||||
* | `coastFalloff` | 0.0250° | 0.0018° | 0.0045° | 14× in metres |
|
||||
* | palette stops declared | 11 | 0 | 11 (different) | — |
|
||||
*
|
||||
* So this module is four rules, each replacing one column of that table with a
|
||||
* single authored constant plus facts the pack already states. It reads as data
|
||||
* because it *is* data: nothing here is an engine change, and the whole of the
|
||||
* blast radius in `world.ts` is that the constructor asks for a reconciled pack
|
||||
* and reads `lngScale` off it.
|
||||
*
|
||||
* ## The flag, and why it defaults off
|
||||
*
|
||||
* San Francisco and Southern California carry every marketing still on
|
||||
* lumbridgecorp.com. A reconciliation that leaves a board *worse* is a bad trade
|
||||
* however good the argument for it, and the only instrument that can tell is a
|
||||
* photograph. So: `?reconcile=1` in the browser, `setReconcile()` from a node
|
||||
* script, **off** everywhere else, and each of the four rules can be turned on
|
||||
* alone — `?reconcile=exaggeration,roads` — so a rule that loses its photograph
|
||||
* is reverted rather than argued for.
|
||||
*
|
||||
* With the flag off `reconciledCity` returns the pack it was handed, by
|
||||
* identity. Not a copy with the same numbers in it: the same object. That is
|
||||
* what makes "no pixel moves with the flag off" a fact about the code rather
|
||||
* than a claim about a diff.
|
||||
*
|
||||
* ## Why the reconciliation rewrites the pack rather than the engine
|
||||
*
|
||||
* `World` posts `this.city` to the terrain worker as a structured clone, and the
|
||||
* worker builds a second `World` from it. A flag read from `location.search` is
|
||||
* not visible in there — a worker's `location` is the worker script's URL — so a
|
||||
* reconciliation that lived in the engine would produce a *reconciled* board on
|
||||
* the main thread standing on an *unreconciled* heightfield. Rewriting the pack
|
||||
* puts the answer in the thing that crosses the wire. `reconciled: true` on the
|
||||
* way out is what makes the second pass in the worker a no-op, and the rule
|
||||
* idempotent.
|
||||
*/
|
||||
|
||||
import type { City, Road, ScenePalette } from "../engine/types.ts";
|
||||
|
||||
// ---- The flag --------------------------------------------------------------
|
||||
|
||||
/** The four rules, each independently switchable. */
|
||||
export type Rule = "exaggeration" | "roads" | "ground" | "projection";
|
||||
|
||||
export const RULES: readonly Rule[] = ["exaggeration", "roads", "ground", "projection"];
|
||||
|
||||
/**
|
||||
* Set from a node script; wins over the query string.
|
||||
*
|
||||
* `null` hands the decision back to the URL, which is what a test wants in its
|
||||
* teardown. Deliberately not memoised: a test that flips the flag between two
|
||||
* assertions must see two answers.
|
||||
*/
|
||||
let forced: ReadonlySet<Rule> | null = null;
|
||||
|
||||
export function setReconcile(rules: boolean | readonly Rule[] | null): void {
|
||||
if (rules === null) forced = null;
|
||||
else if (rules === true) forced = new Set(RULES);
|
||||
else if (rules === false) forced = new Set();
|
||||
else forced = new Set(rules);
|
||||
}
|
||||
|
||||
function parse(value: string | null): ReadonlySet<Rule> {
|
||||
if (value === null || value === "" || value === "0" || value === "false") return new Set();
|
||||
if (value === "1" || value === "true" || value === "all") return new Set(RULES);
|
||||
const wanted = value.split(/[,+\s]+/).filter((part) => part !== "");
|
||||
return new Set(RULES.filter((rule) => wanted.some((part) => rule.startsWith(part))));
|
||||
}
|
||||
|
||||
/** Which rules are on right now. */
|
||||
export function activeRules(): ReadonlySet<Rule> {
|
||||
if (forced !== null) return forced;
|
||||
const search = (globalThis as { location?: { search?: string } }).location?.search;
|
||||
if (search === undefined) return new Set();
|
||||
return parse(new URLSearchParams(search).get("reconcile"));
|
||||
}
|
||||
|
||||
export function reconcileEnabled(rule?: Rule): boolean {
|
||||
const on = activeRules();
|
||||
return rule === undefined ? on.size > 0 : on.has(rule);
|
||||
}
|
||||
|
||||
// ---- The four authored constants -------------------------------------------
|
||||
|
||||
/**
|
||||
* Relief in the frame: peak scene units over board span, the rule
|
||||
* ARCHITECTURE §12.1 already argues and already tuned California against.
|
||||
*
|
||||
* §12.1 moved California from 13 to 15 precisely to hold this number while the
|
||||
* board grew, and recorded that 15 "puts this board on Southern California's
|
||||
* number exactly, which is the calibration that matters — the two are meant to
|
||||
* read as the same landscape at two zooms". This constant is that number, taken
|
||||
* off California so the board the photograph tuned does not move at all:
|
||||
*
|
||||
* | board | today | one rule | relief today | relief reconciled |
|
||||
* | --- | --- | --- | --- | --- |
|
||||
* | california | 15 | 15.00 | 7.24% | 7.24% |
|
||||
* | socal | 3.4 | 3.41 | 6.92% | 7.24% |
|
||||
* | sf | 3.6 | 5.78 | 4.51% | 7.24% |
|
||||
*
|
||||
* **So the rule's verdict is that San Francisco is the board that is wrong**,
|
||||
* by 1.6×, and the other two were already on one number. That is a real claim
|
||||
* about a board that carries most of this product's imagery, which is exactly
|
||||
* why it is behind a flag with a photograph attached.
|
||||
*
|
||||
* What the rule does **not** do is remove the deflation at the seam, and that
|
||||
* is worth stating because it is easy to assume otherwise. Apparent relief at a
|
||||
* *matched* pose — same true-metre stand-off on both boards — is proportional
|
||||
* to the exaggeration itself, not to relief-in-frame, so the 4.17× step from
|
||||
* California to the Bay Area becomes 2.60× and the 4.41× step to Southern
|
||||
* California becomes 4.22×. Making it 1.0× would mean one exaggeration on every
|
||||
* board, which flattens the state to 1.7% of its own frame. Relief-in-frame and
|
||||
* matched-pose relief are the same quantity only when two boards have the same
|
||||
* span, and these do not.
|
||||
*/
|
||||
export const RELIEF_IN_FRAME = 0.0724;
|
||||
|
||||
/**
|
||||
* The narrowest a road may be drawn, as a fraction of the board's span.
|
||||
*
|
||||
* Measured rather than chosen. The two metro packs' narrowest roads sit at
|
||||
* 0.00019940 (San Francisco, a 19 m residential street) and 0.00020356
|
||||
* (Southern California, a 31 m boulevard) of their own board spans — two packs
|
||||
* authored a year apart agreeing to within 2% about how thin a line may get
|
||||
* before it stops being a line. The floor is set just under the tighter of the
|
||||
* two, so **neither metro board moves**, and California's freeways fall onto it.
|
||||
*
|
||||
* California's US-101 and I-5 are authored 1 and 1.06 scene units wide, which at
|
||||
* 1,919 m to the unit is 1,919 m and 2,034 m — black ribbons wider than the
|
||||
* cities they join, and the most prominent marks on the state board. Read as
|
||||
* true metres instead (44 m and 47 m, `Road.widthM`) they are 0.023 units and
|
||||
* would vanish, so the floor is what draws them: 0.110 units, or 212 m. A 9.1×
|
||||
* narrowing, and a symbol at the same fraction of its board that the Bay Area
|
||||
* already draws a side street at.
|
||||
*/
|
||||
export const LEGIBLE_SPAN_FRACTION = 0.000199;
|
||||
|
||||
/**
|
||||
* The coastal ramp, in coarse ground cells.
|
||||
*
|
||||
* `coastFalloff` exists for one mechanical reason: the terrain grid is clipped
|
||||
* to land, so its rim is stair-stepped at cell size, and the ramp takes every
|
||||
* height to zero across that rim so the steps land flat on the shore plate and
|
||||
* disappear (`terrain.ts` header). The size of the thing being hidden is the
|
||||
* **coarse** cell — the fine cell only exists inside a focus region, and coasts
|
||||
* run outside them — so the ramp is a multiple of that and of nothing else.
|
||||
*
|
||||
* 0.8 is California's own ratio, and it reproduces its authored 0.025° to
|
||||
* within 0.2%. The metro packs both come out slightly wider than they are
|
||||
* today: San Francisco 0.0018° → 0.0032° (200 m → 360 m) and Southern
|
||||
* California 0.0045° → 0.0058° (500 m → 641 m), which is the direction that
|
||||
* *removes* stair-stepping rather than adding it.
|
||||
*/
|
||||
export const COAST_RAMP_CELLS = 0.8;
|
||||
|
||||
/**
|
||||
* The one latitude every board squashes longitude by.
|
||||
*
|
||||
* `World.lngScale` is `latScale × cos(centre.lat)`, and each pack uses its own
|
||||
* centre — 37.30°, 37.77°, 33.82°. In true metres a degree of longitude is then
|
||||
* 88,551 m on California and 92,484 m on Southern California, so the two boards
|
||||
* disagree about where Riverside is by 3,435 m and about their shared north-east
|
||||
* corner by 4,025 m. At a 109 km stand-off that is about 3% of the frame — a
|
||||
* visible sideways slide in any transition that shows both boards at once.
|
||||
*
|
||||
* 37.3° is California's centre: the state board is the root of every descent and
|
||||
* the only board whose rectangle is a place rather than a crop. The price is
|
||||
* local aspect, and it is small and one-directional — Southern California draws
|
||||
* 4.25% narrower in x than a projection taken at its own latitude would, San
|
||||
* Francisco 0.64% wider — against a registration error that goes to zero by
|
||||
* construction.
|
||||
*/
|
||||
export const REFERENCE_LAT = 37.3;
|
||||
|
||||
/**
|
||||
* The palette anchors: one dry inland-southern end, one cool coastal-northern
|
||||
* end, mixed by where the board is.
|
||||
*
|
||||
* The south anchor is California's authored palette, unchanged, so the state
|
||||
* board renders exactly as it does today. The north anchor is the engine's
|
||||
* `DEFAULT_PALETTE` — which is to say San Francisco's, since it declares no
|
||||
* override — plus an `alpine` stop it never needed.
|
||||
*
|
||||
* **The two authored palettes are not on one line and no rule can put them
|
||||
* there.** Southern California's `flats` is 0xa9a291; the point 76.8% of the way
|
||||
* from the default to California's 0xb49b57 is 0xaf9b65. Its green channel is
|
||||
* *below* both anchors, so it is off the family in a direction a one-parameter
|
||||
* mix cannot reach. Something had to move, and the choice made here is that
|
||||
* California — the board §12 tuned against a photograph, and the board whose
|
||||
* desert Southern California is drawing a corner of — is the one that does not.
|
||||
* This is the riskiest of the four rules for that reason.
|
||||
*/
|
||||
const SOUTH_ANCHOR: ScenePalette = {
|
||||
skyTop: 0x7da6c9,
|
||||
skyHorizon: 0xe9d8bb,
|
||||
sea: 0x3c6d8b,
|
||||
lake: 0x4a7d93,
|
||||
shore: 0xc4b184,
|
||||
sand: 0xceba8c,
|
||||
flats: 0xb49b57,
|
||||
upland: 0x9d8a63,
|
||||
alpine: 0xb9b3a4,
|
||||
park: 0x76854e,
|
||||
parkHigh: 0x3d5739,
|
||||
};
|
||||
|
||||
/**
|
||||
* `terrain.ts`'s `DEFAULT_PALETTE`, copied rather than imported, plus an
|
||||
* `alpine` stop it never needed.
|
||||
*
|
||||
* Copied because `world.ts` reaches this module and `terrain.worker.ts` reaches
|
||||
* `world.ts`: importing `terrain.ts` here would drag three.js into the
|
||||
* heightfield worker, which is a worker that exists precisely so that half a
|
||||
* million samples of noise cost the page nothing. `reconcile.test.ts` asserts
|
||||
* the ten stops still agree, so the copy cannot drift silently.
|
||||
*/
|
||||
const NORTH_ANCHOR: ScenePalette = {
|
||||
skyTop: 0x8fb8d8,
|
||||
skyHorizon: 0xd9e6ee,
|
||||
sea: 0x4a7a99,
|
||||
lake: 0x527f9c,
|
||||
shore: 0xa8a495,
|
||||
sand: 0xc4b79b,
|
||||
flats: 0x9d9c93,
|
||||
upland: 0x8f9084,
|
||||
park: 0x6f8a5c,
|
||||
parkHigh: 0x5d7a4c,
|
||||
alpine: 0xa6a8a2,
|
||||
};
|
||||
|
||||
/** Metres above sea level at which `terrain.ts` starts painting `alpine`. */
|
||||
const ALPINE_FROM = 1_900;
|
||||
|
||||
// ---- The rules -------------------------------------------------------------
|
||||
|
||||
/** Scene units across the board, the larger of the two axes. See §12.1. */
|
||||
function spanUnits(city: City, lngScale: number): number {
|
||||
const lat = (city.bounds.maxLat - city.bounds.minLat) * city.latScale;
|
||||
const lng = (city.bounds.maxLng - city.bounds.minLng) * lngScale;
|
||||
return Math.max(lat, lng);
|
||||
}
|
||||
|
||||
function lngScaleOf(city: City, on: ReadonlySet<Rule>): number {
|
||||
const lat = on.has("projection") ? REFERENCE_LAT : city.center.lat;
|
||||
return city.latScale * Math.cos((lat * Math.PI) / 180);
|
||||
}
|
||||
|
||||
/**
|
||||
* The tallest ground the pack can produce, in metres, by the same blend
|
||||
* `World.elevationAt` uses — tallest hill plus 35% of the rest — evaluated at
|
||||
* every hill's own summit.
|
||||
*
|
||||
* A property of the pack and not of the field, which is what lets the
|
||||
* exaggeration be derived at construction time. The heightfield's true maximum
|
||||
* is 2.7–8.1% higher because the roughness multiplier peaks at 1.18 somewhere
|
||||
* near a summit; that bias is in the same direction on all three boards and
|
||||
* divides out of a ratio, and the alternative — half a million samples of
|
||||
* four-octave noise before the first triangle — is the cost this whole engine is
|
||||
* arranged around avoiding.
|
||||
*
|
||||
* O(hills²): 469² on California, and 7 ms. Only ever run with the flag on.
|
||||
*/
|
||||
export function blendedPeakMetres(city: City): number {
|
||||
const squash = Math.cos((city.center.lat * Math.PI) / 180);
|
||||
let best = 0;
|
||||
for (const at of city.hills) {
|
||||
let peak = 0;
|
||||
let total = 0;
|
||||
for (const hill of city.hills) {
|
||||
const dLat = at.lat - hill.lat;
|
||||
const dLng = (at.lng - hill.lng) * squash;
|
||||
const d = Math.hypot(dLat, dLng) / hill.radius;
|
||||
if (d >= 1) continue;
|
||||
const f = (1 - d * d) ** 2;
|
||||
const h = hill.elevation * f;
|
||||
total += h;
|
||||
if (h > peak) peak = h;
|
||||
}
|
||||
const here = peak === 0 ? 0 : peak + (total - peak) * 0.35;
|
||||
if (here > best) best = here;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** (a) One relief-in-frame constant instead of three unrelated exaggerations. */
|
||||
export function reconciledExaggeration(city: City, lngScale = lngScaleOf(city, new Set())): number {
|
||||
const metresPerUnit = 111_320 / city.latScale;
|
||||
const peak = blendedPeakMetres(city);
|
||||
if (peak <= 0) return city.verticalExaggeration;
|
||||
return (RELIEF_IN_FRAME * spanUnits(city, lngScale) * metresPerUnit) / peak;
|
||||
}
|
||||
|
||||
/**
|
||||
* (b) A road's width in true metres, floored at the narrowest legible fraction
|
||||
* of the board.
|
||||
*
|
||||
* `widthM` is the pack's own statement of what the road really is; a pack that
|
||||
* does not declare one is read as having authored true metres already, which
|
||||
* both metro packs did.
|
||||
*/
|
||||
export function reconciledRoadWidth(city: City, road: Road, lngScale?: number): number {
|
||||
const metresPerUnit = 111_320 / city.latScale;
|
||||
const trueMetres = road.widthM ?? road.width * metresPerUnit;
|
||||
const floor = LEGIBLE_SPAN_FRACTION * spanUnits(city, lngScale ?? lngScaleOf(city, new Set()));
|
||||
return Math.max(trueMetres / metresPerUnit, floor);
|
||||
}
|
||||
|
||||
/** (c) The coastal ramp as a multiple of the coarse ground cell. */
|
||||
export function reconciledCoastFalloff(city: City): number {
|
||||
return COAST_RAMP_CELLS * city.cellLat * (city.coarseFactor ?? 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* (c) One palette, mixed by how far south and how far inland the board reaches.
|
||||
*
|
||||
* The two terms are the two things that separate a golden Central Valley from a
|
||||
* grey-green Bay Area, and both are already in `bounds`: 37.5°N to 33.0°N for
|
||||
* the southern term, and the coast at -122.0° to the Colorado at -114.0° for the
|
||||
* inland one. California lands on 1.00 and gets its own palette back exactly;
|
||||
* Southern California on 0.77; San Francisco on 0.05, which is the engine
|
||||
* default it already renders with.
|
||||
*/
|
||||
export function reconciledPaletteMix(city: City): number {
|
||||
const south = (37.5 - city.bounds.minLat) / (37.5 - 33.0);
|
||||
const inland = (city.bounds.maxLng + 122.0) / 8.0;
|
||||
return Math.min(1, Math.max(0, 0.5 * south + 0.5 * inland));
|
||||
}
|
||||
|
||||
const CHANNELS = ["skyTop", "skyHorizon", "sea", "lake", "shore", "sand", "flats", "upland", "park", "parkHigh"] as const;
|
||||
|
||||
function mixChannel(a: number, b: number, t: number): number {
|
||||
const r = Math.round((((a >> 16) & 0xff) * (1 - t) + ((b >> 16) & 0xff) * t));
|
||||
const g = Math.round((((a >> 8) & 0xff) * (1 - t) + ((b >> 8) & 0xff) * t));
|
||||
const bl = Math.round(((a & 0xff) * (1 - t) + (b & 0xff) * t));
|
||||
return (r << 16) | (g << 8) | bl;
|
||||
}
|
||||
|
||||
export function reconciledPalette(city: City): ScenePalette {
|
||||
const t = reconciledPaletteMix(city);
|
||||
const out = {} as ScenePalette;
|
||||
for (const key of CHANNELS) out[key] = mixChannel(NORTH_ANCHOR[key], SOUTH_ANCHOR[key], t);
|
||||
// A board gets the alpine stop when it has ground above the snow line, which
|
||||
// is the fact `alpine` is about. San Francisco's tallest is 1,186 m and does
|
||||
// not; the other two do. Today that is authored, one pack at a time.
|
||||
if (blendedPeakMetres(city) > ALPINE_FROM) {
|
||||
out.alpine = mixChannel(NORTH_ANCHOR.alpine ?? 0, SOUTH_ANCHOR.alpine ?? 0, t);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---- Putting it back into a pack -------------------------------------------
|
||||
|
||||
const cache = new WeakMap<City, Map<string, City>>();
|
||||
|
||||
/**
|
||||
* The pack the engine should actually draw.
|
||||
*
|
||||
* Returns the argument **by identity** when nothing is on, and the same object
|
||||
* for the same pack and the same rule set when something is, so a `World` and
|
||||
* the `World` its worker rebuilds agree without either of them knowing about the
|
||||
* other.
|
||||
*/
|
||||
export function reconciledCity(city: City): City {
|
||||
if (city.reconciled === true) return city;
|
||||
const on = activeRules();
|
||||
if (on.size === 0) return city;
|
||||
|
||||
const key = RULES.filter((rule) => on.has(rule)).join(",");
|
||||
let byRules = cache.get(city);
|
||||
if (byRules === undefined) cache.set(city, (byRules = new Map()));
|
||||
const hit = byRules.get(key);
|
||||
if (hit !== undefined) return hit;
|
||||
|
||||
const lngScale = lngScaleOf(city, on);
|
||||
const next: City = { ...city, reconciled: true };
|
||||
if (on.has("projection")) next.lngScale = lngScale;
|
||||
if (on.has("exaggeration")) next.verticalExaggeration = reconciledExaggeration(city, lngScale);
|
||||
if (on.has("roads")) {
|
||||
next.roads = city.roads.map((road) => ({
|
||||
...road,
|
||||
width: reconciledRoadWidth(city, road, lngScale),
|
||||
}));
|
||||
}
|
||||
if (on.has("ground")) {
|
||||
next.coastFalloff = reconciledCoastFalloff(city);
|
||||
next.palette = reconciledPalette(city);
|
||||
}
|
||||
byRules.set(key, next);
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the reconciliation did to a pack, for a script that wants to print it.
|
||||
*
|
||||
* Here rather than in the script so the numbers a report quotes and the numbers
|
||||
* the engine draws come from one place.
|
||||
*/
|
||||
export interface Reconciliation {
|
||||
id: string;
|
||||
spanUnits: number;
|
||||
peakMetres: number;
|
||||
exaggeration: { before: number; after: number };
|
||||
reliefInFrame: { before: number; after: number };
|
||||
roadMetres: { before: [number, number]; after: [number, number] };
|
||||
coastFalloff: { before: number; after: number };
|
||||
lngMetresPerDegree: { before: number; after: number };
|
||||
paletteMix: number;
|
||||
}
|
||||
|
||||
export function describe(city: City): Reconciliation {
|
||||
const metresPerUnit = 111_320 / city.latScale;
|
||||
const before = lngScaleOf(city, new Set());
|
||||
const after = lngScaleOf(city, new Set(RULES));
|
||||
const peak = blendedPeakMetres(city);
|
||||
const spanBefore = spanUnits(city, before);
|
||||
const spanAfter = spanUnits(city, after);
|
||||
const exAfter = reconciledExaggeration(city, after);
|
||||
const widths = (pack: City, scale: number, use: boolean): [number, number] => {
|
||||
const metres = pack.roads.map((road) =>
|
||||
use ? reconciledRoadWidth(pack, road, scale) * metresPerUnit : road.width * metresPerUnit,
|
||||
);
|
||||
return [Math.min(...metres), Math.max(...metres)];
|
||||
};
|
||||
return {
|
||||
id: city.id,
|
||||
spanUnits: spanAfter,
|
||||
peakMetres: peak,
|
||||
exaggeration: { before: city.verticalExaggeration, after: exAfter },
|
||||
reliefInFrame: {
|
||||
before: ((peak / metresPerUnit) * city.verticalExaggeration) / spanBefore,
|
||||
after: ((peak / metresPerUnit) * exAfter) / spanAfter,
|
||||
},
|
||||
roadMetres: { before: widths(city, before, false), after: widths(city, after, true) },
|
||||
coastFalloff: { before: city.coastFalloff, after: reconciledCoastFalloff(city) },
|
||||
lngMetresPerDegree: {
|
||||
before: (before / city.latScale) * 111_320,
|
||||
after: (after / city.latScale) * 111_320,
|
||||
},
|
||||
paletteMix: reconciledPaletteMix(city),
|
||||
};
|
||||
}
|
||||
@@ -520,6 +520,150 @@ export interface AerialFog {
|
||||
far: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* How long the board takes to disappear into its own haze, and how long the next
|
||||
* one takes to come out of it. Seconds.
|
||||
*
|
||||
* ## Why a fog dip is the transition, and a crossfade is not
|
||||
*
|
||||
* Two independent reasons, either one sufficient.
|
||||
*
|
||||
* **A crossfade cannot be afforded.** Every both-boards-live pairing breaks a
|
||||
* desktop triangle cap: California + the Bay Area is 2,640,307 against a cap of
|
||||
* 2,600,000; California + the Southland is 1,805,344 against 1,700,000; the two
|
||||
* metros together are 3,694,949 against everything. Rendering only the outgoing
|
||||
* board's terrain still breaks the California direction (586,535 against
|
||||
* 440,000). And `scripts/performance-budget.mjs` samples eight seconds after a
|
||||
* three-second warm-up, so a 0.8 s fade never lands inside the window — shipping
|
||||
* one would create exactly the cap-you-do-not-measure this repo argues against.
|
||||
*
|
||||
* **A crossfade should not be wanted.** The three packs draw three different
|
||||
* Californias, and a true dissolve at a matched pose puts the two loudest
|
||||
* differences on screen simultaneously and in register: terrain and buildings
|
||||
* deflate 4.17x across the California-to-Bay seam and 4.41x into the Southland,
|
||||
* because `verticalExaggeration` is 15 / 3.6 / 3.4; and the Southland slides up
|
||||
* to 4,025 m sideways, because `World.lngScale` squashes longitude by the cosine
|
||||
* of each pack's *own* centre latitude. A dissolve does not hide a 4.2x
|
||||
* deflation, it stages it. A dip to haze hides the deflation, the slide and
|
||||
* California's 1,919 m-wide freeway symbols all at once, because all three
|
||||
* happen at maximum obscuration — and it costs zero triangles, zero draw calls
|
||||
* and no render target, because `SceneHandle.setAerialFog` already exists and
|
||||
* `main.ts` already drives it on every controls `change`.
|
||||
*
|
||||
* Out is shorter than in on purpose: leaving is an instruction the visitor just
|
||||
* gave and wants obeyed, arriving is a picture they are being shown.
|
||||
*/
|
||||
export const FOG_DIP_OUT_SECONDS = 0.3;
|
||||
export const FOG_DIP_IN_SECONDS = 0.5;
|
||||
|
||||
/**
|
||||
* The fog pair that hides a board, in that board's own scene units.
|
||||
*
|
||||
* `near: 0` and a far plane at a small fraction of the board's span puts every
|
||||
* fragment past the far plane, which `fog_fragment` resolves to the fog colour
|
||||
* outright — a flat field of the horizon's own colour, which is what the sky
|
||||
* dome behind it is already painted with, so the two meet without a seam.
|
||||
*
|
||||
* The far plane is not zero, and the reason is the night. The night fog colour
|
||||
* lands around #16203a and `atmosphere.ts` has already had to floor the night
|
||||
* ground rig once to stop a fog plane behind the camera turning the whole map
|
||||
* off. A collapse that leaves a few per cent of the board's span in front of the
|
||||
* camera keeps the nearest relief faintly readable through the haze, so the dip
|
||||
* reads as weather rather than as a power cut.
|
||||
*/
|
||||
/**
|
||||
* How deep the dip goes, as a fraction of how far the camera is standing back.
|
||||
*
|
||||
* ## It is measured against the camera, not against the board, and that is a fix
|
||||
*
|
||||
* The first version collapsed the far plane to 6% of the board's span. It hid
|
||||
* everything, which was the intent, and at night it hid everything *uniformly*:
|
||||
* photographed at 04:35Z the whole frame was one flat field of #16203a with no
|
||||
* relief, no coastline and no horizon in it. That is the failure
|
||||
* `atmosphere.ts` already had to floor the night ground rig once for — a dip
|
||||
* that turns the map off rather than putting weather on it — and it reads as a
|
||||
* wipe rather than as a descent through haze.
|
||||
*
|
||||
* Against the camera it behaves. `fog_fragment` is linear between the two
|
||||
* planes, so a far plane at 70% of the stand-off leaves the *near* limb of the
|
||||
* board at roughly 85% obscuration and everything at or beyond the orbit target
|
||||
* at 100%: the land keeps a faint shape while the relief — which is what the
|
||||
* seam actually changes, by 4.17x — goes completely. Losing the mountains and
|
||||
* keeping the coastline is the right thing to lose, because the coastline is the
|
||||
* half that is continuous across the seam.
|
||||
*
|
||||
* It also scales itself. The same fraction is a plan view of a state and a
|
||||
* street-level oblique, with no per-board number to keep in step.
|
||||
*/
|
||||
export const FOG_DIP_REACH_FRACTION = 0.7;
|
||||
|
||||
/**
|
||||
* The near plane sits a quarter of the way in rather than on the camera, and
|
||||
* that is arithmetic rather than taste.
|
||||
*
|
||||
* `dipFog` interpolates in ratios, and a ratio cannot reach zero from a positive
|
||||
* start — so a collapsed `near` of exactly 0 has to be lerped linearly while
|
||||
* `far` is lerped geometrically, and the two cross partway through: measured on
|
||||
* the Bay Area's clear pair, the near plane overtakes the far plane at about the
|
||||
* midpoint of the dip and `scene.fog` is then a pair that draws nothing
|
||||
* coherent. Keeping both distances positive and proportional keeps the whole
|
||||
* dip on one curve, and `near < far` for every value of `t` falls out of the
|
||||
* arithmetic instead of needing a guard.
|
||||
*/
|
||||
const FOG_DIP_NEAR_FRACTION = 0.25;
|
||||
|
||||
/**
|
||||
* The fog pair that hides a board, in that board's own scene units.
|
||||
*
|
||||
* `reachUnits` is how far the camera is standing back from what it is looking
|
||||
* at, in **scene units of the board being hidden** — the fog planes are scene
|
||||
* distances, and California's unit is twenty times the Bay Area's, so one shared
|
||||
* pair would leave one board unfogged and wash the other out completely.
|
||||
*
|
||||
* The caller floors it against the board's own span, because a camera that has
|
||||
* been dragged onto its target has a stand-off near zero and a fog pair of
|
||||
* (0, 0) draws nothing at all.
|
||||
*/
|
||||
export function collapsedFog(reachUnits: number): AerialFog {
|
||||
const far = Math.max(1e-3, reachUnits * FOG_DIP_REACH_FRACTION);
|
||||
return { near: far * FOG_DIP_NEAR_FRACTION, far };
|
||||
}
|
||||
|
||||
/**
|
||||
* One step of a dip, as a pure function of how far through it is.
|
||||
*
|
||||
* **Not a third source of fog.** Both endpoints are pairs `Atmosphere` authored
|
||||
* — the live aerial perspective at one end, `collapsedFog` at the other — so
|
||||
* CONTRACT §4's single direction is intact: this interpolates between two of
|
||||
* this module's own answers and cannot invent a colour, a sun or a sky. It is
|
||||
* here rather than in `main.ts` for that reason, and because it is the only part
|
||||
* of the transition worth testing without a GPU.
|
||||
*
|
||||
* Geometric rather than linear, because fog distances are perceived in ratios:
|
||||
* a far plane stepping 3,900 -> 2,000 -> 1,000 -> 500 units looks like an even
|
||||
* fade, and 3,900 -> 2,925 -> 1,950 -> 975 looks like nothing at all followed by
|
||||
* a slam. `t` is clamped, so a caller that overshoots its own clock lands on the
|
||||
* endpoint rather than past it.
|
||||
*/
|
||||
export function dipFog(from: AerialFog, to: AerialFog, t: number): AerialFog {
|
||||
// `NaN` is a caller whose clock went wrong, and the honest answer to that is
|
||||
// the pair it started from rather than a fog of `NaN`, which three writes
|
||||
// straight into a uniform and renders as an untextured void.
|
||||
const clamped = Number.isFinite(t) ? t : 0;
|
||||
// The endpoints are returned rather than computed. `a * (b / a) ** 1` is not
|
||||
// `b` in floating point, and a transition that settles a rounding error away
|
||||
// from the pair `Atmosphere` authored leaves the board very slightly wrong for
|
||||
// as long as nothing else recomputes the fog.
|
||||
if (clamped <= 0) return { near: from.near, far: from.far };
|
||||
if (clamped >= 1) return { near: to.near, far: to.far };
|
||||
const u = clamped * clamped * (3 - 2 * clamped);
|
||||
const ratio = (a: number, b: number): number => {
|
||||
if (a <= 0 || b <= 0) return a + (b - a) * u;
|
||||
return a * Math.pow(b / a, u);
|
||||
};
|
||||
return { near: ratio(from.near, to.near), far: ratio(from.far, to.far) };
|
||||
}
|
||||
|
||||
export interface Atmosphere {
|
||||
/**
|
||||
* The rig this observation implies. Pure; the caller applies the result.
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Which boards stay in memory, and which one gets thrown away first.
|
||||
*
|
||||
* ## Why a cache at all
|
||||
*
|
||||
* Because most of a board switch was never work. Measured on this box against
|
||||
* `dist@bcac6aa` with a real GPU: switching to the Bay Area covers the screen
|
||||
* with the opaque boot card for 1,711 ms, the Southland for 1,079 and California
|
||||
* for 997 — but only 604 / 372 / 222 ms of that **blocks the main thread**, and
|
||||
* the page draws 68 / 45 / 49 frames inside the gap. Sixty-five to seventy-eight
|
||||
* per cent of every pause is a live, animating page with nothing to draw,
|
||||
* because `mountCity` disposed the outgoing board before the incoming one
|
||||
* existed. Keeping it turns a full-screen modal into a live picture that
|
||||
* freezes for a fraction of a second, and it costs no triangles: `Stage`
|
||||
* retains and pauses by contract, `tick()` renders only the current scene, and a
|
||||
* paused board is zero draw calls.
|
||||
*
|
||||
* It also recovers the shader cache, which disposal was throwing away. `three`
|
||||
* refcounts programs per material and deletes at zero, so disposing a board's
|
||||
* materials deletes its programs: `linkProgram` ran 38, 59, 78, 109 and 127
|
||||
* times across five mounts and never once reused, and a second visit to the Bay
|
||||
* Area was only 115 ms faster than the first. Retained, a return costs nothing.
|
||||
*
|
||||
* ## Why two deep is enough
|
||||
*
|
||||
* The `sf` and `socal` bounds do not intersect (37.18–38.03 N against
|
||||
* 33.28–34.36 N) and California contains both, so the set of boards that can
|
||||
* describe any one camera position is always `{california}` or
|
||||
* `{california, one metro}` — never three. Measured GPU vertex and index bytes
|
||||
* are california 5.86 MB, sf 14.12 and socal 8.06, plus heightfields of 0.49,
|
||||
* 3.06 and 0.77; California and the worst metro resident together is about
|
||||
* 40 MB, and all three about 60. `deviceProfile().handheld` changes only the
|
||||
* pixel ratio and the shadow map, so a phone carries the same resident geometry
|
||||
* as a laptop against a much smaller WebGL budget — hence two on a handheld and
|
||||
* three on a desktop, and `residentCapacity` is the one place that says so.
|
||||
*
|
||||
* ## What this module deliberately does not know
|
||||
*
|
||||
* What a board *is*. It holds an opaque payload, so the record bundling the
|
||||
* sixteen per-board variables `main.ts` used to tear down can stay in `main.ts`
|
||||
* where its types live, and this file stays a pure, testable eviction policy
|
||||
* with no DOM, no WebGL and no `three` import. The caller disposes what it is
|
||||
* handed back; nothing here frees anything, for the same reason `Stage` does not
|
||||
* (CONTRACT.md §1).
|
||||
*/
|
||||
|
||||
/**
|
||||
* How many boards may be resident at once, including the pinned one.
|
||||
*
|
||||
* Three on a desktop is every board this build has, which is what makes the
|
||||
* SoCal-to-Bay-Area rebuild disappear as well as the return to California. Two
|
||||
* on a handheld is California plus whichever metro is on screen, which is the
|
||||
* provably sufficient set above.
|
||||
*/
|
||||
export function residentCapacity(handheld: boolean): number {
|
||||
return handheld ? 2 : 3;
|
||||
}
|
||||
|
||||
export interface BoardCacheOptions {
|
||||
/**
|
||||
* Board ids that are never evicted.
|
||||
*
|
||||
* California, in practice: it is the cheapest board (5.86 MB) and the root of
|
||||
* every descent, so it is the one most likely to be asked for again and the
|
||||
* one that costs least to keep.
|
||||
*/
|
||||
pinned?: readonly string[];
|
||||
/** Resident boards, including pinned ones. See `residentCapacity`. */
|
||||
capacity: number;
|
||||
}
|
||||
|
||||
export interface BoardCache<T> {
|
||||
get(id: string): T | null;
|
||||
has(id: string): boolean;
|
||||
/** Every resident id, least-recently-shown first. */
|
||||
ids(): readonly string[];
|
||||
size(): number;
|
||||
/**
|
||||
* Store a board and mark it the most recently shown.
|
||||
*
|
||||
* Returns whatever had to be evicted to stay inside `capacity` — the caller's
|
||||
* job to dispose, and it must not forget `environmentRig.release(scene)`: the
|
||||
* rig's ledger is a strong reference, and a board left in it is the whole
|
||||
* scene graph retained.
|
||||
*/
|
||||
put(id: string, value: T): readonly T[];
|
||||
/** Mark an already-resident board as the most recently shown. */
|
||||
touch(id: string): void;
|
||||
/** Take one out without evicting anything else. */
|
||||
remove(id: string): T | null;
|
||||
/** Take everything out, most-recently-shown last. */
|
||||
drain(): readonly T[];
|
||||
}
|
||||
|
||||
export function createBoardCache<T>(options: BoardCacheOptions): BoardCache<T> {
|
||||
const pinned = new Set(options.pinned ?? []);
|
||||
const capacity = Math.max(1, Math.floor(options.capacity));
|
||||
/**
|
||||
* Insertion order is recency order.
|
||||
*
|
||||
* A `Map` iterates in insertion order and `delete` + `set` is how a key is
|
||||
* moved to the end of it, so the least recently shown board is simply the
|
||||
* first key the iterator yields. That is the whole LRU and it needs no
|
||||
* timestamps — which matters, because a timestamp would have to come from a
|
||||
* clock, and this module has no business reading one.
|
||||
*/
|
||||
const entries = new Map<string, T>();
|
||||
|
||||
function evictable(protectedId: string | null): string | null {
|
||||
for (const id of entries.keys()) {
|
||||
if (pinned.has(id)) continue;
|
||||
if (id === protectedId) continue;
|
||||
return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
get: (id) => entries.get(id) ?? null,
|
||||
has: (id) => entries.has(id),
|
||||
ids: () => [...entries.keys()],
|
||||
size: () => entries.size,
|
||||
|
||||
put(id, value) {
|
||||
const evicted: T[] = [];
|
||||
// Replacing an id in place is not an eviction and must not free the
|
||||
// incoming board — the common shape of that mistake is a rebuild racing a
|
||||
// switch, which the caller's `AbortController` already prevents, and this
|
||||
// is the second line of defence.
|
||||
const previous = entries.get(id);
|
||||
if (previous !== undefined && previous !== value) evicted.push(previous);
|
||||
entries.delete(id);
|
||||
entries.set(id, value);
|
||||
|
||||
while (entries.size > capacity) {
|
||||
const victim = evictable(id);
|
||||
// Nothing left that may be freed: every remaining board is pinned or is
|
||||
// the one being shown. Over capacity is the correct outcome — a pin is a
|
||||
// statement that the board matters more than the ceiling does.
|
||||
if (victim === null) break;
|
||||
const record = entries.get(victim);
|
||||
entries.delete(victim);
|
||||
if (record !== undefined) evicted.push(record);
|
||||
}
|
||||
return evicted;
|
||||
},
|
||||
|
||||
touch(id) {
|
||||
const value = entries.get(id);
|
||||
if (value === undefined) return;
|
||||
entries.delete(id);
|
||||
entries.set(id, value);
|
||||
},
|
||||
|
||||
remove(id) {
|
||||
const value = entries.get(id);
|
||||
if (value === undefined) return null;
|
||||
entries.delete(id);
|
||||
return value;
|
||||
},
|
||||
|
||||
drain() {
|
||||
const all = [...entries.values()];
|
||||
entries.clear();
|
||||
return all;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,433 @@
|
||||
/**
|
||||
* One ladder over three boards: every authored chapter as a rung, ordered by
|
||||
* how far the camera stands off.
|
||||
*
|
||||
* ## Why this file exists
|
||||
*
|
||||
* The product ships three city packs and, until this module, the interface said
|
||||
* so out loud: a strip of three tabs naming three *modes*, each swapping a
|
||||
* different list of chapters underneath it. That is the single most direct way
|
||||
* to tell a visitor they are looking at three products rather than one place.
|
||||
* The boards themselves are not the problem — measured, the 20x horizontal
|
||||
* scale jump between California and the Bay Area is *invisible*, because
|
||||
* `World.project` is a uniform scale in x/z with no vertical term and a uniform
|
||||
* scale leaves a perspective image identical. What announces three boards is the
|
||||
* chrome around them, and this is the data that lets the chrome stop.
|
||||
*
|
||||
* ## Stand-off, and not altitude
|
||||
*
|
||||
* The rungs are ordered by `cameraStandoffMetres` — the true-metre distance from
|
||||
* the camera to what it is looking at — and that choice is measured rather than
|
||||
* aesthetic. Sorted by *altitude* the three boards interleave badly: SoCal's
|
||||
* Orange County chapter sits 5.97 km up and the Bay Area's Peninsula 3.93 km,
|
||||
* both of them inside California's own range, and an altitude cannot tell a low
|
||||
* oblique from a high plan. Sorted by stand-off they separate cleanly —
|
||||
* California bottoms out at 242 km, the Southland's whole-board pose is 108.8 km
|
||||
* and the Bay Area's is 71.2 km. Stand-off is what decides how much earth is in
|
||||
* frame, which is what decides which board can fill it.
|
||||
*
|
||||
* Both numbers are read straight off the authored `focus` block and are
|
||||
* therefore facts about the *pack*, not about the runtime: `standoffM` is
|
||||
* `hypot(distance, height) x metresPerUnit` and `altitudeM` is
|
||||
* `height x metresPerUnit / verticalExaggeration`, which is exactly what
|
||||
* `SceneHandle.cameraStandoffMetres()` and `cameraAltitudeMetres()` report once
|
||||
* the camera has arrived. Deriving them here rather than measuring them at
|
||||
* runtime is what keeps this module pure and the ladder stable across a resize.
|
||||
* (`chapterFraming` scales a pose on a narrow window; that is a framing
|
||||
* correction for a phone, not a change to what the chapter *is*.)
|
||||
*
|
||||
* ## What this module is not allowed to do
|
||||
*
|
||||
* **It never edits a pack.** Twenty-nine capture guards in `scripts/brand-assets`
|
||||
* aim at `#chapters .chapter` by index and assert the button's `shortLabel`, so
|
||||
* a pack whose chapter order or short labels moved would silently re-shoot every
|
||||
* still on lumbridgecorp.com. Two rungs currently read "Whole Board" and two read
|
||||
* "The Valley"; both collisions are resolved *here*, in `LADDER_LABELS`, and the
|
||||
* packs keep the strings the guards assert on. The ladder is a new **view** over
|
||||
* the same data, never a replacement for it.
|
||||
*
|
||||
* **It holds the handover table, and `City` does not.** `handoverStandoffM` is a
|
||||
* fact about how the *ladder* hands one board to the next, and putting it on the
|
||||
* `City` type would widen a pack — a file that must stay pure, reviewable data —
|
||||
* for the benefit of one consumer. It lives in `HANDOVER_STANDOFF_M` below, next
|
||||
* to the argument for its value.
|
||||
*/
|
||||
|
||||
import type { Chapter, City } from "./types.ts";
|
||||
|
||||
/** The three regions a rung can belong to, and the order they descend in. */
|
||||
export type LadderRegion = "state" | "southland" | "bay";
|
||||
|
||||
/** The heading the places list prints above each region's rungs. */
|
||||
export const REGION_LABELS: Readonly<Record<LadderRegion, string>> = Object.freeze({
|
||||
state: "The state",
|
||||
southland: "The Southland",
|
||||
bay: "The Bay",
|
||||
});
|
||||
|
||||
/** Which region a board id belongs to. */
|
||||
export const BOARD_REGION: Readonly<Record<string, LadderRegion>> = Object.freeze({
|
||||
california: "state",
|
||||
socal: "southland",
|
||||
sf: "bay",
|
||||
});
|
||||
|
||||
/**
|
||||
* The stand-off, in true metres, below which a board is willing to take the
|
||||
* camera from the one above it. Authored, and deliberately not derived.
|
||||
*
|
||||
* The natural derived rule — hand over only once the incoming board's bounds
|
||||
* cover the frame — computes a maximum stand-off of 31.6 km for a target at
|
||||
* downtown San Francisco with a 63.1 degree horizontal field of view, because
|
||||
* the board's west edge is only 19.4 km away. The Bay Area's own whole-board
|
||||
* chapter stands off 71.2 km, and the shipped marketing still for it shows the
|
||||
* board's northern land edge across the top of the frame. So the derived rule
|
||||
* would refuse the board at its own opening pose. One authored number per pack
|
||||
* is honest, is one line, and is checkable against a photograph.
|
||||
*
|
||||
* California is absent: it is the root of every descent and hands over to
|
||||
* nothing. `handoverStandoff` returns `Infinity` for it, which reads correctly
|
||||
* in the comparison below without a special case.
|
||||
*/
|
||||
export const HANDOVER_STANDOFF_M: Readonly<Record<string, number>> = Object.freeze({
|
||||
sf: 71_200,
|
||||
socal: 108_800,
|
||||
});
|
||||
|
||||
export function handoverStandoff(boardId: string): number {
|
||||
return HANDOVER_STANDOFF_M[boardId] ?? Number.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* The labels the ladder uses where a pack's own would collide.
|
||||
*
|
||||
* Keyed `board:chapter`. Four entries, and every one of them exists because two
|
||||
* packs independently chose the same words for two different places: both metro
|
||||
* packs open on a chapter labelled "Whole Board", and both call a chapter "The
|
||||
* Valley" — the San Fernando one and the silicon one. A list that merges the
|
||||
* three packs has to say which is which, and it has to say it without touching
|
||||
* `shortLabel`, which the capture guards assert on.
|
||||
*/
|
||||
const LADDER_LABELS: Readonly<Record<string, string>> = Object.freeze({
|
||||
"socal:all": "The Southland",
|
||||
"sf:all": "The Bay Area",
|
||||
// Its pack label is also "The Bay Area", which the whole-board rung above has
|
||||
// just taken. Its short label is unique and is the better name anyway: this is
|
||||
// the wide plan of the water, not the board.
|
||||
"sf:bay-area": "The Bay",
|
||||
});
|
||||
|
||||
/**
|
||||
* A chapter on the California board that is a **door** rather than a camera
|
||||
* pose, and the rung it folds onto.
|
||||
*
|
||||
* `main.ts` matches these two ids against `CALIFORNIA_DESTINATIONS` and calls
|
||||
* `switchCity()` instead of `flyTo()`, so their `focus` blocks are dead for the
|
||||
* camera and live only as dots on the plan. As rungs they would be duplicates:
|
||||
* two entries at 88.4 km of stand-off called "LA" and "SF" sitting between the
|
||||
* Southland's whole-board rung and the Bay Area's, which are the two places they
|
||||
* go. So they fold on, and the ladder is 24 rungs rather than 26.
|
||||
*/
|
||||
const FOLDED_DOORS: Readonly<Record<string, string>> = Object.freeze({
|
||||
"california:los-angeles": "socal:all",
|
||||
"california:san-francisco": "sf:all",
|
||||
});
|
||||
|
||||
/** One rung: a place you can be, and how far back you stand to see it. */
|
||||
export interface LadderRung {
|
||||
/** `board:chapter`. Unique across the ladder; the ladder's own identity. */
|
||||
key: string;
|
||||
/** The chapter id **on its own board**, unchanged from the pack. */
|
||||
id: string;
|
||||
board: string;
|
||||
region: LadderRegion;
|
||||
/** Unique across the ladder. See `LADDER_LABELS`. */
|
||||
label: string;
|
||||
/** The pack's own short label, untouched — the string the capture guards assert. */
|
||||
shortLabel: string;
|
||||
/** The pack's own chapter number, untouched. */
|
||||
number: string;
|
||||
description: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
rotation: number;
|
||||
/** True metres from the camera to the target at this chapter's authored pose. */
|
||||
standoffM: number;
|
||||
/** True metres of air under the camera, vertical exaggeration divided out. */
|
||||
altitudeM: number;
|
||||
/**
|
||||
* The California door chapter that folded onto this rung, if one did. Kept so
|
||||
* the places list can say a rung is reachable from the state board, and so a
|
||||
* click on it from California takes the authored door rather than inventing a
|
||||
* second route.
|
||||
*/
|
||||
doorFrom?: { board: string; id: string };
|
||||
}
|
||||
|
||||
/** What `buildLadder` needs from a board. A `City` satisfies it. */
|
||||
export interface LadderBoard {
|
||||
id: string;
|
||||
city: Pick<City, "chapters" | "latScale" | "verticalExaggeration">;
|
||||
}
|
||||
|
||||
/** Metres per scene unit, horizontally. The same arithmetic `World` does. */
|
||||
function metresPerUnit(latScale: number): number {
|
||||
return 111_320 / latScale;
|
||||
}
|
||||
|
||||
export function chapterStandoffMetres(chapter: Chapter, latScale: number): number {
|
||||
return Math.hypot(chapter.focus.distance, chapter.focus.height) * metresPerUnit(latScale);
|
||||
}
|
||||
|
||||
export function chapterAltitudeMetres(
|
||||
chapter: Chapter,
|
||||
latScale: number,
|
||||
verticalExaggeration: number,
|
||||
): number {
|
||||
return (chapter.focus.height * metresPerUnit(latScale)) / verticalExaggeration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Every authored chapter of every board, as one array sorted **descending by
|
||||
* stand-off**, with the two California doors folded onto the metro rungs they
|
||||
* open.
|
||||
*
|
||||
* This is the ordered array the brief asks for and it is the coordinate the
|
||||
* handover rule reads. It is *not* the order the places list prints — see
|
||||
* `placesRows`, which groups it, and the note there for why a global sort
|
||||
* produces nine headings for three regions.
|
||||
*/
|
||||
export function buildLadder(boards: readonly LadderBoard[]): readonly LadderRung[] {
|
||||
const rungs: LadderRung[] = [];
|
||||
const doors: { key: string; onto: string }[] = [];
|
||||
|
||||
for (const board of boards) {
|
||||
const region = BOARD_REGION[board.id] ?? "state";
|
||||
for (const chapter of board.city.chapters) {
|
||||
const key = `${board.id}:${chapter.id}`;
|
||||
const onto = FOLDED_DOORS[key];
|
||||
if (onto !== undefined) {
|
||||
doors.push({ key, onto });
|
||||
continue;
|
||||
}
|
||||
rungs.push({
|
||||
key,
|
||||
id: chapter.id,
|
||||
board: board.id,
|
||||
region,
|
||||
label: LADDER_LABELS[key] ?? chapter.label,
|
||||
shortLabel: chapter.shortLabel,
|
||||
number: chapter.number,
|
||||
description: chapter.description,
|
||||
lat: chapter.focus.lat,
|
||||
lng: chapter.focus.lng,
|
||||
rotation: chapter.focus.rotation,
|
||||
standoffM: chapterStandoffMetres(chapter, board.city.latScale),
|
||||
altitudeM: chapterAltitudeMetres(
|
||||
chapter,
|
||||
board.city.latScale,
|
||||
board.city.verticalExaggeration,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const door of doors) {
|
||||
const rung = rungs.find((candidate) => candidate.key === door.onto);
|
||||
if (!rung) continue;
|
||||
const [board = "", id = ""] = door.key.split(":");
|
||||
rung.doorFrom = { board, id };
|
||||
}
|
||||
|
||||
// Descending, and ties broken by key so the array is a pure function of the
|
||||
// packs. Two rungs at an identical stand-off is not hypothetical — the two
|
||||
// folded California doors shared one before they folded.
|
||||
rungs.sort((a, b) => b.standoffM - a.standoffM || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
||||
return rungs;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ladder as the places list prints it: grouped by region, groups ordered by
|
||||
* their own top rung, rungs inside a group still descending by stand-off.
|
||||
*
|
||||
* ## Why the printed list is grouped and the array is not
|
||||
*
|
||||
* Because a globally interleaved order is unreadable. Sorted purely by stand-off
|
||||
* the twenty-four rungs alternate Southland, Bay, Southland, Bay eleven times —
|
||||
* 108.8 km Southland, 71.2 km Bay, 38.6 Southland, 30.1 Southland, 30.0 Bay,
|
||||
* 28.8 Southland, 26.3 Bay — so a list that printed a heading whenever the
|
||||
* region changed would print **nine headings for three regions**. That is
|
||||
* noise, and it argues for three boards more loudly than the tab strip it
|
||||
* replaces.
|
||||
*
|
||||
* Grouping keeps one ordering rule — stand-off, everywhere — and gives the three
|
||||
* headings the brief asks for. The groups themselves are ordered by their top
|
||||
* rung, so the page still reads top to bottom as a descent: the state from
|
||||
* 1,551 km down to 242, the Southland from 108.8 km down to 9.1, the Bay from
|
||||
* 71.2 km down to 3.9.
|
||||
*/
|
||||
export function placesRows(ladder: readonly LadderRung[]): readonly LadderRung[] {
|
||||
const regions: LadderRegion[] = ["state", "southland", "bay"];
|
||||
const top = new Map<LadderRegion, number>();
|
||||
for (const rung of ladder) {
|
||||
const seen = top.get(rung.region);
|
||||
if (seen === undefined || rung.standoffM > seen) top.set(rung.region, rung.standoffM);
|
||||
}
|
||||
const ordered = regions
|
||||
.filter((region) => top.has(region))
|
||||
.sort((a, b) => (top.get(b) ?? 0) - (top.get(a) ?? 0));
|
||||
const rows: LadderRung[] = [];
|
||||
for (const region of ordered) {
|
||||
for (const rung of ladder) if (rung.region === region) rows.push(rung);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which rung the camera is standing on, for the highlight that makes the list
|
||||
* an altimeter rather than a menu.
|
||||
*
|
||||
* Two rules, in this order, and the order is the whole design:
|
||||
*
|
||||
* 1. **If the camera is where a chapter put it, that chapter wins.** Within
|
||||
* `PARKED_TOLERANCE` of its authored stand-off, the rung you clicked stays
|
||||
* lit even when a neighbour's number is arithmetically nearer. Four of the
|
||||
* Bay Area's rungs sit inside 12% of each other (Marin 21.5 km, Silicon
|
||||
* Valley 20.7, San Jose 19.6, the East Bay 19.2), and a highlight that
|
||||
* hopped between them the instant you arrived would read as a bug.
|
||||
* 2. **Otherwise the nearest stand-off on the resident board wins**, in log
|
||||
* space, because the ladder spans four orders of magnitude and a linear
|
||||
* "nearest" would pin everything below 20 km onto one rung.
|
||||
*
|
||||
* `currentId` is the resident board's own current chapter — `SceneHandle.current()`
|
||||
* — and `null` is a legitimate answer: a camera dragged out past the top rung of
|
||||
* a board is not standing on any of them.
|
||||
*/
|
||||
const PARKED_TOLERANCE = 0.18;
|
||||
|
||||
export function activeRung(
|
||||
ladder: readonly LadderRung[],
|
||||
boardId: string,
|
||||
standoffM: number,
|
||||
currentId: string | null,
|
||||
): LadderRung | null {
|
||||
const onBoard = ladder.filter((rung) => rung.board === boardId);
|
||||
if (onBoard.length === 0) return null;
|
||||
|
||||
if (currentId !== null) {
|
||||
const parked = onBoard.find((rung) => rung.id === currentId);
|
||||
if (parked && Math.abs(standoffM - parked.standoffM) <= parked.standoffM * PARKED_TOLERANCE) {
|
||||
return parked;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Number.isFinite(standoffM) || standoffM <= 0) {
|
||||
return onBoard.find((rung) => rung.id === currentId) ?? null;
|
||||
}
|
||||
|
||||
let best: LadderRung | null = null;
|
||||
let bestDistance = Number.POSITIVE_INFINITY;
|
||||
for (const rung of onBoard) {
|
||||
if (rung.standoffM <= 0) continue;
|
||||
const distance = Math.abs(Math.log(standoffM) - Math.log(rung.standoffM));
|
||||
if (distance < bestDistance) {
|
||||
bestDistance = distance;
|
||||
best = rung;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the camera should be handed from one board to another, and to which.
|
||||
*
|
||||
* Pure, and it is the whole of the free-camera board rule. Three inputs and no
|
||||
* state beyond what the caller passes back in:
|
||||
*
|
||||
* - `standoffM` — the live `cameraStandoffMetres()`, already true metres and
|
||||
* already free of both scale and exaggeration.
|
||||
* - `target` — where the orbit is pointed, in lat/lng. A board is only a
|
||||
* candidate if it contains this.
|
||||
* - `current` — the resident board, so the answer can be "stay".
|
||||
*
|
||||
* ## The hysteresis band, and why it is not optional
|
||||
*
|
||||
* A camera parked exactly on a threshold and nudged by a wheel notch would tear
|
||||
* down and rebuild a board on every notch. Promotion happens below
|
||||
* `handover x PROMOTE`, demotion above `handover x DEMOTE`, and the gap between
|
||||
* them is dead air where the answer is always "stay". `dragging` is the second
|
||||
* guard: `OrbitControls` fires `change` on every damped frame of a drag, and a
|
||||
* board swap in the middle of one takes the pointer away from the thing it is
|
||||
* holding.
|
||||
*
|
||||
* ## It has to be allowed to say no
|
||||
*
|
||||
* The two metro boards cover 25,884 km² of California's 989,000 — about 55% of
|
||||
* the population and 2.6% of the area. Two wheel notches down from the state
|
||||
* pose over Fresno lands on 806 m lots and 2 km-wide freeway symbols with
|
||||
* nothing finer to hand over to, and the honest answer there is to stay on
|
||||
* California and let the descent look coarse. `null` is that answer and it is
|
||||
* the common case.
|
||||
*/
|
||||
export const PROMOTE = 0.9;
|
||||
export const DEMOTE = 1.15;
|
||||
|
||||
export interface HandoverBoard {
|
||||
id: string;
|
||||
bounds: { minLat: number; maxLat: number; minLng: number; maxLng: number };
|
||||
/** Metres per scene unit. The finest board wins a tie of candidates. */
|
||||
metresPerUnit: number;
|
||||
}
|
||||
|
||||
export interface HandoverQuery {
|
||||
boards: readonly HandoverBoard[];
|
||||
current: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
standoffM: number;
|
||||
dragging?: boolean;
|
||||
}
|
||||
|
||||
export function handover(query: HandoverQuery): string | null {
|
||||
if (query.dragging === true) return null;
|
||||
if (!Number.isFinite(query.standoffM) || query.standoffM <= 0) return null;
|
||||
|
||||
const contains = (board: HandoverBoard): boolean =>
|
||||
query.lat >= board.bounds.minLat &&
|
||||
query.lat <= board.bounds.maxLat &&
|
||||
query.lng >= board.bounds.minLng &&
|
||||
query.lng <= board.bounds.maxLng;
|
||||
|
||||
const currentBoard = query.boards.find((board) => board.id === query.current);
|
||||
|
||||
// Demote first: a camera that has climbed above this board's own handover
|
||||
// ceiling belongs to whatever contains it at a coarser scale, and asking about
|
||||
// promotion from a board you have already left is how an oscillation starts.
|
||||
if (currentBoard !== undefined) {
|
||||
const ceiling = handoverStandoff(currentBoard.id);
|
||||
if (Number.isFinite(ceiling) && query.standoffM > ceiling * DEMOTE) {
|
||||
const coarser = query.boards
|
||||
.filter(
|
||||
(board) =>
|
||||
board.id !== query.current &&
|
||||
contains(board) &&
|
||||
board.metresPerUnit > currentBoard.metresPerUnit,
|
||||
)
|
||||
.sort((a, b) => a.metresPerUnit - b.metresPerUnit)[0];
|
||||
return coarser?.id ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
const candidates = query.boards.filter(
|
||||
(board) =>
|
||||
board.id !== query.current &&
|
||||
contains(board) &&
|
||||
(currentBoard === undefined || board.metresPerUnit < currentBoard.metresPerUnit) &&
|
||||
query.standoffM < handoverStandoff(board.id) * PROMOTE,
|
||||
);
|
||||
if (candidates.length === 0) return null;
|
||||
// Finest wins. `sf` and `socal` bounds do not intersect and California
|
||||
// contains both, so the candidate set here is never larger than one — but the
|
||||
// rule is written for the general case rather than for today's three packs.
|
||||
return candidates.sort((a, b) => a.metresPerUnit - b.metresPerUnit)[0]?.id ?? null;
|
||||
}
|
||||
+51
-10
@@ -21,11 +21,19 @@
|
||||
* engine already paid for:
|
||||
*
|
||||
* - **Nothing here knows how big a board is.** Every coordinate is derived
|
||||
* from `city.bounds` through the same `World` the scene uses. `scene.ts`
|
||||
* from one rectangle — `MinimapOptions.frame`, which defaults to
|
||||
* `city.bounds` — through the same `World` the scene uses. `scene.ts`
|
||||
* documents what the alternative cost: camera limits tuned for San
|
||||
* Francisco's 230-unit board silently became a property of the engine, and
|
||||
* the Bay Area's 1003 units could not be framed at all. A minimap with a
|
||||
* hardcoded extent would fail the same way and look like a rendering bug.
|
||||
*
|
||||
* **Amended.** The rule used to say `city.bounds` outright, and that was
|
||||
* exactly right while a board was one framing and exactly wrong once a board
|
||||
* became a rung of a ladder — a plan that changes shape when the world has
|
||||
* not is the loudest "you are somewhere else now" signal on the screen. So
|
||||
* the rectangle is now the caller's to choose and the derivation is
|
||||
* unchanged. See `MinimapOptions.frame`.
|
||||
* - **`tick()` runs inside the stage's frame loop**, so it allocates nothing
|
||||
* and tessellates nothing in the steady state. The map itself — coastline,
|
||||
* relief, roads — is rasterised once into an offscreen surface and blitted;
|
||||
@@ -73,6 +81,34 @@ export interface MinimapOptions {
|
||||
/** The live orbit controls. `controls.target` is the crosshair. */
|
||||
controls: OrbitControls;
|
||||
markerPalette?: MarkerPalette;
|
||||
/**
|
||||
* The geographic rectangle the plan **draws**, which is no longer the same
|
||||
* thing as the board's own bounds. Defaults to `city.bounds`.
|
||||
*
|
||||
* ## Why this exists, against this file's own first rule
|
||||
*
|
||||
* The header above states the rule "nothing here knows how big a board is —
|
||||
* every coordinate is derived from `city.bounds`", and that rule is exactly
|
||||
* right while a board is *one framing* and exactly wrong once a board is a
|
||||
* rung of a ladder. Both metro rectangles are arbitrary crops: the Bay Area's
|
||||
* is 0.85 by 0.89 degrees and the Southland's is 1.08 by 1.66, so the plan
|
||||
* came out square on one board and landscape on the other while the world
|
||||
* underneath had not changed at all. A plan that changes **shape** when the
|
||||
* world does not is the loudest "you are somewhere else now" signal on the
|
||||
* screen, and it fires in the same frame the fog dip is trying to hide the
|
||||
* change.
|
||||
*
|
||||
* The rule this replaces it with is narrower rather than looser: the plan is
|
||||
* still derived entirely from a rectangle handed to it, and it still knows
|
||||
* nothing about *which* board it is drawing. It has simply stopped assuming
|
||||
* that rectangle is the board's own.
|
||||
*
|
||||
* The frame must **contain** `city.bounds`, or the board runs off its own
|
||||
* plan. Nothing here enforces that, because a frame that deliberately crops is
|
||||
* a legitimate thing to want and a runtime assertion would be a second
|
||||
* opinion about a caller's intent.
|
||||
*/
|
||||
frame?: { minLat: number; maxLat: number; minLng: number; maxLng: number };
|
||||
/** Fires when the user clicks, drags or commits a keyboard seek. */
|
||||
onSeek?(lat: number, lng: number): void;
|
||||
/** Fires on hover, and once with `null` when the pointer leaves. */
|
||||
@@ -183,18 +219,23 @@ export function createMinimap(options: MinimapOptions): Minimap {
|
||||
// ---- The board ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The board in scene units, from the city's own bounds. `projectZ` negates
|
||||
* latitude — north is `-z` — so the northern edge is the *smaller* z and the
|
||||
* corners have to be taken in that order or the map comes out upside down.
|
||||
* The drawn rectangle in scene units. `projectZ` negates latitude — north is
|
||||
* `-z` — so the northern edge is the *smaller* z and the corners have to be
|
||||
* taken in that order or the map comes out upside down.
|
||||
*
|
||||
* `frame`, not `city.bounds`: see `MinimapOptions.frame`. Everything below
|
||||
* this line is unchanged, because everything below this line was already
|
||||
* written against these six numbers rather than against a board.
|
||||
*/
|
||||
const [westX, northZ] = world.project(city.bounds.maxLat, city.bounds.minLng);
|
||||
const [eastX, southZ] = world.project(city.bounds.minLat, city.bounds.maxLng);
|
||||
const frame = options.frame ?? city.bounds;
|
||||
const [westX, northZ] = world.project(frame.maxLat, frame.minLng);
|
||||
const [eastX, southZ] = world.project(frame.minLat, frame.maxLng);
|
||||
const boardW = eastX - westX;
|
||||
const boardH = southZ - northZ;
|
||||
const boardSpan = Math.max(boardW, boardH);
|
||||
|
||||
const latSpan = city.bounds.maxLat - city.bounds.minLat;
|
||||
const lngSpan = city.bounds.maxLng - city.bounds.minLng;
|
||||
const latSpan = frame.maxLat - frame.minLat;
|
||||
const lngSpan = frame.maxLng - frame.minLng;
|
||||
|
||||
// Layout, in device pixels. Everything is recomputed by `layout()`.
|
||||
let dpr = 1;
|
||||
@@ -401,9 +442,9 @@ export function createMinimap(options: MinimapOptions): Minimap {
|
||||
|
||||
const elevation = new Float32Array(shadeCols * shadeRows);
|
||||
for (let j = 0; j < shadeRows; j++) {
|
||||
const lat = city.bounds.maxLat - ((j + 0.5) / shadeRows) * latSpan;
|
||||
const lat = frame.maxLat - ((j + 0.5) / shadeRows) * latSpan;
|
||||
for (let i = 0; i < shadeCols; i++) {
|
||||
const lng = city.bounds.minLng + ((i + 0.5) / shadeCols) * lngSpan;
|
||||
const lng = frame.minLng + ((i + 0.5) / shadeCols) * lngSpan;
|
||||
elevation[j * shadeCols + i] = world.elevationSampled(lat, lng);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-1
@@ -442,6 +442,23 @@ export interface SceneOptions {
|
||||
* parked on the stage defeats that.
|
||||
*/
|
||||
signal?: AbortSignal;
|
||||
/**
|
||||
* Put this scene on the stage when it is finished. Defaults to **true**.
|
||||
*
|
||||
* Construction used to imply presentation: the last statement before the
|
||||
* handle was returned was `stage.setScene(stageScene)`, which was correct for
|
||||
* as long as a board was built only when there was nothing else to look at.
|
||||
* It is not correct once a board is built *behind* the one on screen — which
|
||||
* is the whole of what makes a switch stop being a full-screen card — because
|
||||
* the swap has to happen after the fog has closed over the outgoing board,
|
||||
* not the instant the incoming one has geometry.
|
||||
*
|
||||
* Opt-out rather than removed, so the default stays the thing every existing
|
||||
* caller and every test already expects, and so "build it but do not show me
|
||||
* yet" has to be asked for out loud. The caller that asks then owns the
|
||||
* `stage.setScene(handle.stageScene)` that presents it.
|
||||
*/
|
||||
present?: boolean;
|
||||
}
|
||||
|
||||
export interface SceneHandle {
|
||||
@@ -1309,7 +1326,9 @@ export async function createScene(
|
||||
});
|
||||
},
|
||||
};
|
||||
stage.setScene(stageScene);
|
||||
// Construction implies presentation only while nobody says otherwise. See
|
||||
// `SceneOptions.present` for why that stopped being unconditional.
|
||||
if (options.present !== false) stage.setScene(stageScene);
|
||||
|
||||
return {
|
||||
world,
|
||||
|
||||
@@ -86,7 +86,25 @@ export interface Bridge {
|
||||
|
||||
export interface Road {
|
||||
path: LatLng[];
|
||||
/**
|
||||
* Half-width to either side of the centreline, in **scene units** — which is
|
||||
* to say, at whatever this board's metres-per-unit happens to be.
|
||||
*
|
||||
* Both metro packs authored roughly true widths here: 19–32 m on the Bay Area
|
||||
* and 31–55 m on Southern California. The state board did not, and could not
|
||||
* sensibly — a 40 m freeway is 0.02 units on a board 554 units across — so its
|
||||
* two corridors are authored as 1,919 m and 2,034 m **symbols**, which is why
|
||||
* they draw as ribbons wider than the cities they join.
|
||||
*/
|
||||
width: number;
|
||||
/**
|
||||
* What the road really is, in metres, for a pack whose `width` is a symbol.
|
||||
*
|
||||
* Read by `cities/reconcile.ts` and by nothing else: the engine draws `width`,
|
||||
* always. A pack that omits this is taken to have authored true metres in
|
||||
* `width` already, which both metro packs did.
|
||||
*/
|
||||
widthM?: number;
|
||||
kind: "street" | "freeway";
|
||||
}
|
||||
|
||||
@@ -471,6 +489,19 @@ export interface City {
|
||||
*/
|
||||
latScale: number;
|
||||
|
||||
/**
|
||||
* Degrees to scene units for longitude, when the derivation above is not what
|
||||
* the board wants.
|
||||
*
|
||||
* Absent on every authored pack, and present on a pack that
|
||||
* `cities/reconcile.ts` has rewritten: three boards each squashing longitude
|
||||
* by the cosine of their own centre latitude disagree about where a place is
|
||||
* by up to 4 km, and the reconciliation puts all three on one reference
|
||||
* latitude. Optional rather than required so that "a city pack is a data file
|
||||
* anybody can review" keeps meaning what it meant.
|
||||
*/
|
||||
lngScale?: number;
|
||||
|
||||
/**
|
||||
* How much taller than life the vertical is. Terrain and buildings share it,
|
||||
* so they stay honest relative to each other.
|
||||
@@ -513,6 +544,16 @@ export interface City {
|
||||
|
||||
/** Palette overrides; every field is optional. */
|
||||
palette?: Partial<ScenePalette>;
|
||||
|
||||
/**
|
||||
* Set by `cities/reconcile.ts` on a pack it has already rewritten.
|
||||
*
|
||||
* `World` posts its pack to the terrain worker as a structured clone and the
|
||||
* worker builds a second `World` from it. This is what makes that second pass
|
||||
* a no-op instead of a second reconciliation of an already-reconciled board.
|
||||
* Never authored by hand.
|
||||
*/
|
||||
reconciled?: true;
|
||||
}
|
||||
|
||||
export interface ScenePalette {
|
||||
|
||||
+21
-4
@@ -33,6 +33,7 @@
|
||||
* here, still exact, and are what the Worker itself uses.
|
||||
*/
|
||||
|
||||
import { reconciledCity } from "../cities/reconcile.ts";
|
||||
import type { City, LatLng } from "./types.ts";
|
||||
|
||||
/** The lattice, and the three arrays sampled off it. */
|
||||
@@ -100,11 +101,27 @@ export class World {
|
||||
private state: Field | null = null;
|
||||
private pending: Promise<boolean> | null = null;
|
||||
|
||||
/**
|
||||
* The pack is asked to reconcile itself before anything is derived from it.
|
||||
*
|
||||
* With `TERA_RECONCILE` off — the default, and every deploy — `reconciledCity`
|
||||
* returns the argument by identity and the three lines below compute exactly
|
||||
* what they always computed. With it on the pack comes back with one relief
|
||||
* rule, one road convention, one coastal ramp and one reference latitude, and
|
||||
* this constructor does not need to know which: it is data, and the whole of
|
||||
* the engine's involvement is reading `lngScale` off the pack when the pack
|
||||
* has an opinion. See `cities/reconcile.ts`.
|
||||
*/
|
||||
constructor(city: City) {
|
||||
this.city = city;
|
||||
this.lngScale = city.latScale * Math.cos((city.center.lat * Math.PI) / 180);
|
||||
this.metresPerUnit = 111_320 / city.latScale;
|
||||
this.lngSquash = Math.cos((city.center.lat * Math.PI) / 180);
|
||||
this.city = reconciledCity(city);
|
||||
this.lngScale =
|
||||
this.city.lngScale ?? this.city.latScale * Math.cos((this.city.center.lat * Math.PI) / 180);
|
||||
this.metresPerUnit = 111_320 / this.city.latScale;
|
||||
// Not `cos(centre.lat)` any more but the same number whenever `lngScale` is
|
||||
// derived from it, and the *right* number when it is not: a hill is a circle
|
||||
// in scene space only if the squash used to measure its radius is the squash
|
||||
// the projection uses. Reconciling one without the other draws ellipses.
|
||||
this.lngSquash = this.lngScale / this.city.latScale;
|
||||
}
|
||||
|
||||
// ---- Projection ---------------------------------------------------------
|
||||
|
||||
+960
-218
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* The board cache: what stays in memory, and what gets thrown away first.
|
||||
*
|
||||
* This is the eviction policy behind the thing the owner actually feels. A board
|
||||
* switch used to cover the screen with an opaque card for 1,711 / 1,079 / 997 ms
|
||||
* while only 604 / 372 / 222 ms of it blocked the main thread — so two thirds of
|
||||
* every pause was a live page with nothing to draw, because `mountCity` disposed
|
||||
* the outgoing board before the incoming one existed. Keeping it is the fix, and
|
||||
* keeping it means deciding what may be kept.
|
||||
*
|
||||
* The properties worth a test are the ones whose failure is silent. An eviction
|
||||
* that frees the board on screen is a black canvas. An eviction that frees a
|
||||
* board and forgets to hand it back is a leak of a whole scene graph, because
|
||||
* `environmentRig`'s ledger is a strong reference and only the caller can call
|
||||
* `release`. A `put` that quietly drops an existing record is the same leak with
|
||||
* a different cause. None of those throw.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { createBoardCache, residentCapacity } from "../engine/boards.ts";
|
||||
|
||||
interface Board {
|
||||
id: string;
|
||||
}
|
||||
|
||||
const board = (id: string): Board => ({ id });
|
||||
|
||||
describe("resident capacity is a property of the device and nothing else", () => {
|
||||
it("keeps every board on a desktop and two on a handheld", () => {
|
||||
// Three is every board this build has, which is what makes the
|
||||
// Southland-to-Bay rebuild disappear as well as the return to California.
|
||||
assert.equal(residentCapacity(false), 3);
|
||||
// `deviceProfile()` changes only the pixel ratio and the shadow map, so a
|
||||
// phone carries exactly the same resident geometry as a laptop against a
|
||||
// much smaller WebGL budget. Two is California plus whichever metro is on
|
||||
// screen — provably enough, because the two metro rectangles do not
|
||||
// intersect and California contains both.
|
||||
assert.equal(residentCapacity(true), 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the cache keeps what it is told to keep", () => {
|
||||
it("returns a stored board without rebuilding anything", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 3 });
|
||||
const sf = board("sf");
|
||||
assert.deepEqual(cache.put("sf", sf), []);
|
||||
assert.equal(cache.get("sf"), sf);
|
||||
assert.equal(cache.has("sf"), true);
|
||||
assert.equal(cache.get("socal"), null);
|
||||
assert.equal(cache.size(), 1);
|
||||
});
|
||||
|
||||
it("never evicts a pinned board, even past its ceiling", () => {
|
||||
// California is pinned because it is the cheapest board (5.86 MB of GPU
|
||||
// buffers against the Bay Area's 14.12) and is the root of every descent.
|
||||
const cache = createBoardCache<Board>({ capacity: 2, pinned: ["california"] });
|
||||
cache.put("california", board("california"));
|
||||
cache.put("sf", board("sf"));
|
||||
const evicted = cache.put("socal", board("socal"));
|
||||
assert.deepEqual(evicted.map((b) => b.id), ["sf"]);
|
||||
assert.equal(cache.has("california"), true);
|
||||
assert.equal(cache.has("socal"), true);
|
||||
});
|
||||
|
||||
it("evicts the least recently shown, not the least recently built", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 2 });
|
||||
cache.put("california", board("california"));
|
||||
cache.put("sf", board("sf"));
|
||||
// Going back to California makes the Bay Area the stale one.
|
||||
cache.touch("california");
|
||||
const evicted = cache.put("socal", board("socal"));
|
||||
assert.deepEqual(evicted.map((b) => b.id), ["sf"]);
|
||||
assert.deepEqual(cache.ids(), ["california", "socal"]);
|
||||
});
|
||||
|
||||
it("never evicts the board being put in", () => {
|
||||
// The failure this rules out is a black canvas: the incoming board is the
|
||||
// one about to go on the stage, and a capacity of one would otherwise make
|
||||
// it its own victim.
|
||||
const cache = createBoardCache<Board>({ capacity: 1 });
|
||||
cache.put("california", board("california"));
|
||||
const sf = board("sf");
|
||||
const evicted = cache.put("sf", sf);
|
||||
assert.deepEqual(evicted.map((b) => b.id), ["california"]);
|
||||
assert.equal(cache.get("sf"), sf);
|
||||
});
|
||||
|
||||
it("hands back everything it drops, exactly once", () => {
|
||||
// `environmentRig.release(scene)` and `SceneHandle.dispose()` are the
|
||||
// caller's to run, and it can only run them on a record it is given. A
|
||||
// dropped record that is never returned is the whole scene graph retained.
|
||||
const cache = createBoardCache<Board>({ capacity: 2 });
|
||||
const dropped: string[] = [];
|
||||
for (const id of ["a", "b", "c", "d", "e"]) {
|
||||
for (const victim of cache.put(id, board(id))) dropped.push(victim.id);
|
||||
}
|
||||
assert.deepEqual(dropped, ["a", "b", "c"]);
|
||||
assert.deepEqual(cache.ids(), ["d", "e"]);
|
||||
});
|
||||
|
||||
it("hands back a record it is replacing in place", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 3 });
|
||||
const first = board("sf");
|
||||
const second = board("sf");
|
||||
cache.put("sf", first);
|
||||
assert.deepEqual(cache.put("sf", second), [first]);
|
||||
assert.equal(cache.get("sf"), second);
|
||||
assert.equal(cache.size(), 1);
|
||||
});
|
||||
|
||||
it("does not report a board as evicted when it is put back unchanged", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 3 });
|
||||
const sf = board("sf");
|
||||
cache.put("sf", sf);
|
||||
assert.deepEqual(cache.put("sf", sf), []);
|
||||
assert.equal(cache.get("sf"), sf);
|
||||
});
|
||||
|
||||
it("takes one out on request and leaves the rest alone", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 3 });
|
||||
const sf = board("sf");
|
||||
cache.put("california", board("california"));
|
||||
cache.put("sf", sf);
|
||||
assert.equal(cache.remove("sf"), sf);
|
||||
assert.equal(cache.remove("sf"), null);
|
||||
assert.deepEqual(cache.ids(), ["california"]);
|
||||
});
|
||||
|
||||
it("drains everything, including the pinned board", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 3, pinned: ["california"] });
|
||||
cache.put("california", board("california"));
|
||||
cache.put("sf", board("sf"));
|
||||
assert.deepEqual(cache.drain().map((b) => b.id), ["california", "sf"]);
|
||||
assert.equal(cache.size(), 0);
|
||||
});
|
||||
|
||||
it("treats a capacity below one as one rather than throwing", () => {
|
||||
const cache = createBoardCache<Board>({ capacity: 0 });
|
||||
const sf = board("sf");
|
||||
assert.deepEqual(cache.put("sf", sf), []);
|
||||
assert.equal(cache.get("sf"), sf);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the two-deep case the product actually runs", () => {
|
||||
it("never makes the board on screen the victim, whatever the order", () => {
|
||||
/*
|
||||
* The bug this is here for was live and is the worst shape retention can
|
||||
* fail in. With a ceiling of two and California pinned, inserting the
|
||||
* *incoming* board while the outgoing one was still on the stage left the
|
||||
* outgoing board as the only legal victim — so a Bay-to-Southland switch on
|
||||
* a phone disposed the picture the visitor was looking at, blanked the
|
||||
* canvas, and only then swapped. `main.ts` fixes it by writing the cache
|
||||
* after `stage.setScene`, which makes the least-recently-*shown* board the
|
||||
* victim; this asserts the property the cache itself guarantees, which is
|
||||
* that the id being put is never evicted.
|
||||
*/
|
||||
const cache = createBoardCache<Board>({
|
||||
capacity: residentCapacity(true),
|
||||
pinned: ["california"],
|
||||
});
|
||||
cache.put("california", board("california"));
|
||||
const sf = board("sf");
|
||||
cache.put("sf", sf);
|
||||
|
||||
// The order `main.ts` now uses: the incoming board is shown first, so it is
|
||||
// the id being put and the outgoing one is the stale entry.
|
||||
const socal = board("socal");
|
||||
const evicted = cache.put("socal", socal);
|
||||
assert.deepEqual(evicted, [sf], "the board that has just been hidden is the victim");
|
||||
assert.equal(cache.get("socal"), socal, "and the one on screen is still resident");
|
||||
});
|
||||
|
||||
it("rebuilds nothing on a Bay -> Southland -> Bay round trip on a handheld", () => {
|
||||
// California pinned, one metro slot. Coming back to the Bay Area rebuilds
|
||||
// it — that is the honest cost of two-deep on a phone — but coming back to
|
||||
// California, which is the root of every descent, never does.
|
||||
const cache = createBoardCache<Board>({
|
||||
capacity: residentCapacity(true),
|
||||
pinned: ["california"],
|
||||
});
|
||||
const california = board("california");
|
||||
cache.put("california", california);
|
||||
|
||||
cache.put("sf", board("sf"));
|
||||
const droppedForSocal = cache.put("socal", board("socal"));
|
||||
assert.deepEqual(droppedForSocal.map((b) => b.id), ["sf"]);
|
||||
|
||||
// Back to California: resident, so nothing is built and nothing is dropped.
|
||||
assert.equal(cache.get("california"), california);
|
||||
cache.touch("california");
|
||||
assert.equal(cache.has("socal"), true);
|
||||
});
|
||||
|
||||
it("rebuilds nothing at all on a desktop, in any order", () => {
|
||||
const cache = createBoardCache<Board>({
|
||||
capacity: residentCapacity(false),
|
||||
pinned: ["california"],
|
||||
});
|
||||
const records = new Map<string, Board>();
|
||||
let rebuilt = 0;
|
||||
const visit = (id: string) => {
|
||||
if (cache.has(id)) {
|
||||
cache.touch(id);
|
||||
return;
|
||||
}
|
||||
rebuilt++;
|
||||
const record = board(id);
|
||||
records.set(id, record);
|
||||
assert.deepEqual(cache.put(id, record), []);
|
||||
};
|
||||
for (const id of ["california", "sf", "socal", "california", "sf", "socal", "sf"]) visit(id);
|
||||
assert.equal(rebuilt, 3, "three boards exist, so three builds and no more");
|
||||
for (const [id, record] of records) assert.equal(cache.get(id), record);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* The chapter strip is a public interface, and this is the fast half of the
|
||||
* check that says so.
|
||||
*
|
||||
* `scripts/check-chapter-identity.mjs` is the whole contract: it boots the built
|
||||
* bundle under every `?city=` and compares the rendered `#chapters` strip —
|
||||
* `data-view`, `data-view-index`, the printed number and the short label —
|
||||
* against `scripts/fixtures/chapter-identity.json`. That takes a browser and
|
||||
* about a minute. This file re-states the part of the same fixture that lives in
|
||||
* the packs, so a reorder fails in `npm test` in a second, and so the negative
|
||||
* case can be *watched failing*: a guard nobody has seen fail is not a guard.
|
||||
*
|
||||
* ## What is actually being protected
|
||||
*
|
||||
* Twenty-six aims in `scripts/brand-assets/{shots,films,capture}.mjs` point a
|
||||
* camera at `#chapters .chapter[N]` — a **position** — and assert the short
|
||||
* label they find there; 21 of them at a board a `?city=` reaches. Every one is
|
||||
* a still, a film or the Open Graph card on lumbridgecorp.com. The
|
||||
* label assertion was added after a share card shipped for a fortnight showing
|
||||
* a chase camera on a freeway under the headline "Cities from above", and it is
|
||||
* a good guard with two holes:
|
||||
*
|
||||
* - Short labels are not unique across boards. "Whole Board" is chapter 01 of
|
||||
* both metro boards and "The Valley" is a different valley on each of them, so
|
||||
* a reorder that preserves labels passes every one of them and shoots the wrong place.
|
||||
* - `?city=` falls back to the first board rather than failing, so a board that
|
||||
* lost its id serves California to a shot aimed at SoCal without an error.
|
||||
*
|
||||
* Identity here therefore means `(board, chapter id, position)` together, never
|
||||
* a label and never a position on its own.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import CALIFORNIA_CITY from "../cities/california.ts";
|
||||
import SAN_FRANCISCO_CITY from "../cities/sf.ts";
|
||||
import SOCAL_CITY from "../cities/socal.ts";
|
||||
import type { Chapter } from "../engine/types.ts";
|
||||
import { chromeState } from "../ui/chromeState.ts";
|
||||
import type { ChromeInputs } from "../ui/chromeState.ts";
|
||||
|
||||
interface FixtureChapter {
|
||||
index: number;
|
||||
dataView: string;
|
||||
dataViewIndex: string;
|
||||
number: string;
|
||||
shortLabel: string;
|
||||
}
|
||||
interface Fixture {
|
||||
takenAt: string;
|
||||
boards: Record<string, { activeBoard: string; chapters: FixtureChapter[] }>;
|
||||
}
|
||||
|
||||
const fixture = JSON.parse(
|
||||
readFileSync(new URL("../../scripts/fixtures/chapter-identity.json", import.meta.url), "utf8"),
|
||||
) as Fixture;
|
||||
|
||||
/** `?city=` value to the pack it selects — the same table `main.ts` holds. */
|
||||
const BOARDS: readonly (readonly [string, { chapters: Chapter[] }])[] = [
|
||||
["california", CALIFORNIA_CITY],
|
||||
["sf", SAN_FRANCISCO_CITY],
|
||||
["socal", SOCAL_CITY],
|
||||
];
|
||||
|
||||
/**
|
||||
* Every way this list of chapters differs from the one the imagery was aimed at.
|
||||
*
|
||||
* A list of sentences rather than an assertion, so that the negative test can
|
||||
* call the same function on a deliberately broken list and check that it
|
||||
* *reports* rather than that it *throws*. The two callers below are the whole
|
||||
* point: one proves the packs are still what the fixture says, the other proves
|
||||
* this function can tell when they are not.
|
||||
*/
|
||||
function drift(boardId: string, chapters: readonly Chapter[]): string[] {
|
||||
const expected = fixture.boards[boardId];
|
||||
if (expected === undefined) return [`?city=${boardId}: not in the fixture`];
|
||||
const problems: string[] = [];
|
||||
if (expected.chapters.length !== chapters.length) {
|
||||
problems.push(
|
||||
`?city=${boardId}: ${chapters.length} chapters, the fixture has ${expected.chapters.length}`,
|
||||
);
|
||||
}
|
||||
for (let i = 0; i < Math.min(expected.chapters.length, chapters.length); i += 1) {
|
||||
const want = expected.chapters[i];
|
||||
const got = chapters[i];
|
||||
if (want === undefined || got === undefined) continue;
|
||||
// `data-view` is the chapter's id, and `data-view-index` is its position in
|
||||
// the rendered list — `mount.ts` writes both from the same array. Checking
|
||||
// them here is checking that the DOM identity and the pack identity are the
|
||||
// same fact, which is what lets a browser-free test stand in for the DOM one.
|
||||
if (got.id !== want.dataView) problems.push(`${boardId}[${i}] id ${got.id} ≠ ${want.dataView}`);
|
||||
if (String(i) !== want.dataViewIndex) {
|
||||
problems.push(`${boardId}[${i}] position ${i} ≠ ${want.dataViewIndex}`);
|
||||
}
|
||||
if (got.number !== want.number) {
|
||||
problems.push(`${boardId}[${i}] number ${got.number} ≠ ${want.number}`);
|
||||
}
|
||||
if (got.shortLabel !== want.shortLabel) {
|
||||
problems.push(`${boardId}[${i}] label "${got.shortLabel}" ≠ "${want.shortLabel}"`);
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
function inputs(overrides: Partial<ChromeInputs> = {}): ChromeInputs {
|
||||
return {
|
||||
mode: "overview",
|
||||
available: ["overview"],
|
||||
access: { tier: "anon", signInUrl: "/login.html", subject: null },
|
||||
inside: false,
|
||||
officeDepth: null,
|
||||
viewport: { width: 1440, height: 900, coarsePointer: false },
|
||||
feeds: { markers: false, weather: false, flights: false },
|
||||
degraded: [],
|
||||
devices: [],
|
||||
firstVisit: false,
|
||||
panelOpen: true,
|
||||
planOpen: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("chapter identity", () => {
|
||||
it("matches the fixture the marketing imagery was aimed at", () => {
|
||||
const problems = BOARDS.flatMap(([id, city]) => drift(id, city.chapters));
|
||||
assert.deepEqual(
|
||||
problems,
|
||||
[],
|
||||
`The chapter strip moved. Every line below is a capture aim in ` +
|
||||
`scripts/brand-assets/** that now points somewhere else:\n ${problems.join("\n ")}`,
|
||||
);
|
||||
});
|
||||
|
||||
it("is 26 rungs over three boards, which is the number the ladder has to carry", () => {
|
||||
// Not a style assertion: the ladder work re-expresses these 26 as one
|
||||
// ordered descent, and 24 of them are camera poses — `los-angeles` and
|
||||
// `san-francisco` on the state board are doors that call `switchCity`
|
||||
// rather than `flyTo`, which is why two capture presets that claimed to be
|
||||
// California closeups were in fact photographs of the metro boards.
|
||||
assert.equal(CALIFORNIA_CITY.chapters.length, 6);
|
||||
assert.equal(SAN_FRANCISCO_CITY.chapters.length, 12);
|
||||
assert.equal(SOCAL_CITY.chapters.length, 8);
|
||||
assert.equal(
|
||||
BOARDS.reduce((total, [, city]) => total + city.chapters.length, 0),
|
||||
26,
|
||||
);
|
||||
});
|
||||
|
||||
it("puts the pack's id and short label straight onto the button", () => {
|
||||
// The DOM contract, stated where it can be checked without a browser:
|
||||
// `chromeState` maps a chapter to a row `id`/`label`, and `mount.ts` writes
|
||||
// that `id` into `data-view` and the row's position into `data-view-index`.
|
||||
// If this mapping ever stops being the identity function, the fixture above
|
||||
// stops standing in for the DOM and `check-chapter-identity.mjs` becomes the
|
||||
// only real guard.
|
||||
for (const [boardId, city] of BOARDS) {
|
||||
const state = chromeState(
|
||||
inputs({ views: city.chapters, activeViewId: city.chapters[0]?.id ?? null }),
|
||||
);
|
||||
assert.deepEqual(
|
||||
state.views.map((view) => view.id),
|
||||
city.chapters.map((chapter) => chapter.id),
|
||||
`${boardId}: row ids are not the pack's chapter ids`,
|
||||
);
|
||||
assert.deepEqual(
|
||||
state.views.map((view) => view.label),
|
||||
city.chapters.map((chapter) => chapter.shortLabel),
|
||||
`${boardId}: row labels are not the pack's short labels`,
|
||||
);
|
||||
assert.deepEqual(
|
||||
state.views.map((view) => view.number),
|
||||
city.chapters.map((chapter) => chapter.number),
|
||||
`${boardId}: printed numbers are not the pack's numbers`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("cannot be guarded by short label alone, because labels collide across boards", () => {
|
||||
// This is the reason the index-and-label aims are not enough, stated
|
||||
// as a fact about the data rather than as an opinion. If this assertion ever
|
||||
// fails because the labels became unique, the aims are still aimed by
|
||||
// position and this file still has to exist — but the failure mode gets
|
||||
// quieter, which is worth knowing about.
|
||||
const labels = BOARDS.flatMap(([, city]) => city.chapters.map((chapter) => chapter.shortLabel));
|
||||
const collisions = labels.filter((label, i) => labels.indexOf(label) !== i);
|
||||
assert.deepEqual([...new Set(collisions)].sort(), ["The Valley", "Whole Board"]);
|
||||
});
|
||||
|
||||
describe("the guard itself", () => {
|
||||
// A guard nobody has watched fail is not a guard. Each of these breaks the
|
||||
// list in one of the three ways a ladder rewrite realistically breaks it,
|
||||
// and asserts that `drift` says so.
|
||||
|
||||
it("fails when two chapters are swapped, even though every label survives", () => {
|
||||
const swapped = [...SAN_FRANCISCO_CITY.chapters];
|
||||
const [a, b] = [swapped[2], swapped[3]];
|
||||
assert.ok(a !== undefined && b !== undefined);
|
||||
swapped[2] = b;
|
||||
swapped[3] = a;
|
||||
const problems = drift("sf", swapped);
|
||||
assert.ok(problems.length > 0, "a reorder went unnoticed");
|
||||
assert.ok(
|
||||
problems.some((line) => line.includes("sf[2] id")),
|
||||
`expected a complaint about sf[2], got:\n ${problems.join("\n ")}`,
|
||||
);
|
||||
});
|
||||
|
||||
it("fails when a chapter is inserted, which shifts every index after it", () => {
|
||||
const inserted: Chapter[] = [...SOCAL_CITY.chapters];
|
||||
const first = inserted[0];
|
||||
assert.ok(first !== undefined);
|
||||
inserted.splice(1, 0, { ...first, id: "san-diego", shortLabel: "San Diego", number: "99" });
|
||||
const problems = drift("socal", inserted);
|
||||
assert.ok(problems.length > 0, "an insertion went unnoticed");
|
||||
assert.ok(
|
||||
problems.some((line) => line.includes("9 chapters")),
|
||||
`expected a complaint about the count, got:\n ${problems.join("\n ")}`,
|
||||
);
|
||||
});
|
||||
|
||||
it("fails when a chapter keeps its place and changes its id", () => {
|
||||
// The ladder rewrite's most likely shape: same 26 rungs, renamed to a
|
||||
// single sequence. `data-view` is what a re-pointed harness would key on,
|
||||
// so a silent rename is the one drift that would otherwise look like
|
||||
// nothing at all.
|
||||
const renamed = CALIFORNIA_CITY.chapters.map((chapter, i) =>
|
||||
i === 1 ? { ...chapter, id: "rung-02" } : chapter,
|
||||
);
|
||||
const problems = drift("california", renamed);
|
||||
assert.deepEqual(problems, ["california[1] id rung-02 ≠ la-sf-us-101"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* The fog dip: the transition that is not a crossfade.
|
||||
*
|
||||
* Two boards cannot be drawn at once and that is a measured fact rather than an
|
||||
* engine limit. Against the caps in `scripts/performance-budgets.json`,
|
||||
* California + the Bay Area is 2,640,307 triangles against a cap of 2,600,000,
|
||||
* California + the Southland is 1,805,344 against 1,700,000, and the two metros
|
||||
* together are 3,694,949 against everything; rendering only the outgoing board's
|
||||
* terrain still breaks the California direction at 586,535 against 440,000. And
|
||||
* `performance-budget.mjs` samples eight seconds after a three-second warm-up,
|
||||
* so a sub-second fade never lands inside the window — a transition whose cost
|
||||
* the gate cannot see is the exact failure this repo argues against.
|
||||
*
|
||||
* So the transition is a collapse of the outgoing board's own aerial fog, a
|
||||
* swap, and a lift of the incoming board's. Zero extra triangles, zero extra
|
||||
* draw calls, no render target — and it is also the *right* transition, because
|
||||
* a true dissolve at a matched pose would put the seam's 4.17x vertical
|
||||
* deflation and its up-to-4,025 m registration slide on screen simultaneously
|
||||
* and in register.
|
||||
*
|
||||
* What is testable without a GPU is the arithmetic, and the arithmetic is where
|
||||
* the two failures live: a dip that does not actually reach either endpoint, and
|
||||
* a dip whose collapsed pair is shared between boards whose scene units differ
|
||||
* by a factor of twenty.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import {
|
||||
collapsedFog,
|
||||
dipFog,
|
||||
FOG_DIP_IN_SECONDS,
|
||||
FOG_DIP_OUT_SECONDS,
|
||||
FOG_DIP_REACH_FRACTION,
|
||||
type AerialFog,
|
||||
} from "../engine/atmosphere.ts";
|
||||
|
||||
/** A clear-day pair of the shape `Atmosphere.aerial` returns for the Bay Area. */
|
||||
const CLEAR: AerialFog = { near: 1_150, far: 3_900 };
|
||||
|
||||
describe("the collapsed pair is measured against the camera, not the board", () => {
|
||||
it("scales with how far back the camera is standing", () => {
|
||||
// Fog planes are scene distances and California's unit is twenty times the
|
||||
// Bay Area's, so one shared pair would leave one board unfogged and wash the
|
||||
// other out completely.
|
||||
const wide = collapsedFog(808);
|
||||
const close = collapsedFog(41);
|
||||
assert.ok(wide.far > close.far);
|
||||
assert.equal(wide.far, 808 * FOG_DIP_REACH_FRACTION);
|
||||
assert.equal(close.far, 41 * FOG_DIP_REACH_FRACTION);
|
||||
});
|
||||
|
||||
it("leaves the near limb of the board faintly readable and everything else gone", () => {
|
||||
// The failure this replaced: a far plane at 6% of the board's span put every
|
||||
// fragment past it, and the night board photographed as one flat field of
|
||||
// #16203a with no coastline in it. `fog_fragment` is linear between the
|
||||
// planes, so a far plane at 70% of the stand-off means the fragment nearest
|
||||
// the camera — roughly half a board-span nearer than the target — is heavily
|
||||
// hazed rather than erased.
|
||||
const standoff = 808;
|
||||
const fog = collapsedFog(standoff);
|
||||
const nearest = standoff - 554 / 2;
|
||||
const factor = (nearest - fog.near) / (fog.far - fog.near);
|
||||
assert.ok(factor > 0.8, `the near limb is hidden (${factor})`);
|
||||
assert.ok(factor < 1, `but it is not erased (${factor})`);
|
||||
// Everything at or past what the camera is pointed at is gone outright.
|
||||
assert.ok((standoff - fog.near) / (fog.far - fog.near) >= 1);
|
||||
});
|
||||
|
||||
it("closes to just in front of the camera, and not onto it", () => {
|
||||
const fog = collapsedFog(808);
|
||||
assert.ok(fog.near > 0, "a positive near plane is what keeps the whole dip on one curve");
|
||||
assert.ok(fog.near < fog.far);
|
||||
});
|
||||
|
||||
it("refuses to produce a degenerate pair for a degenerate reach", () => {
|
||||
for (const reach of [0, -1]) {
|
||||
const fog = collapsedFog(reach);
|
||||
assert.ok(fog.far > 0, `reach ${reach} still yields a usable far plane`);
|
||||
assert.ok(Number.isFinite(fog.far));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("a dip reaches both ends and nothing beyond them", () => {
|
||||
const hidden = collapsedFog(808);
|
||||
|
||||
it("is exactly the start at zero and exactly the end at one", () => {
|
||||
assert.deepEqual(dipFog(CLEAR, hidden, 0), CLEAR);
|
||||
assert.deepEqual(dipFog(CLEAR, hidden, 1), hidden);
|
||||
// The lift is the same call with the endpoints swapped, which is why there
|
||||
// is one function and not two.
|
||||
assert.deepEqual(dipFog(hidden, CLEAR, 0), hidden);
|
||||
assert.deepEqual(dipFog(hidden, CLEAR, 1), CLEAR);
|
||||
});
|
||||
|
||||
it("clamps rather than overshooting a caller's clock", () => {
|
||||
assert.deepEqual(dipFog(CLEAR, hidden, 1.4), hidden);
|
||||
assert.deepEqual(dipFog(CLEAR, hidden, -0.2), CLEAR);
|
||||
assert.deepEqual(dipFog(CLEAR, hidden, Number.NaN), CLEAR);
|
||||
});
|
||||
|
||||
it("closes monotonically, and never leaves the board briefly clearer", () => {
|
||||
// A fog that opened even slightly partway through the collapse would be a
|
||||
// flash of the outgoing board at exactly the moment the swap is meant to be
|
||||
// invisible.
|
||||
let previous = Number.POSITIVE_INFINITY;
|
||||
for (let t = 0; t <= 1.0001; t += 0.02) {
|
||||
const far = dipFog(CLEAR, hidden, t).far;
|
||||
assert.ok(far <= previous + 1e-9, `far grew at t=${t}: ${far} after ${previous}`);
|
||||
previous = far;
|
||||
}
|
||||
});
|
||||
|
||||
it("fades in ratios rather than in metres", () => {
|
||||
// Fog distance is perceived logarithmically. A linear ramp spends the first
|
||||
// half of the dip doing almost nothing visible and the second half slamming
|
||||
// shut. The ease is symmetric, so halfway through the dip the far plane is
|
||||
// exactly the *geometric* mean of the two ends — which is the statement that
|
||||
// this is a ratio fade and not a distance fade.
|
||||
const mid = dipFog(CLEAR, hidden, 0.5).far;
|
||||
assert.ok(
|
||||
Math.abs(mid - Math.sqrt(CLEAR.far * hidden.far)) < 1e-9,
|
||||
`midpoint ${mid} is not the geometric mean of ${CLEAR.far} and ${hidden.far}`,
|
||||
);
|
||||
assert.ok(mid < (CLEAR.far + hidden.far) / 2, "and it is below the arithmetic mean");
|
||||
assert.ok(mid > hidden.far, "and it has not arrived early either");
|
||||
});
|
||||
|
||||
it("keeps the pair coherent at every step", () => {
|
||||
// The failure this catches is real and was found by writing it: a linear
|
||||
// near plane against a geometric far plane crosses over partway through the
|
||||
// dip, and `scene.fog` with `near > far` draws nothing coherent.
|
||||
for (let t = 0; t <= 1.0001; t += 0.1) {
|
||||
const fog = dipFog(CLEAR, hidden, t);
|
||||
assert.ok(Number.isFinite(fog.near), `near is finite at t=${t}`);
|
||||
assert.ok(Number.isFinite(fog.far), `far is finite at t=${t}`);
|
||||
assert.ok(fog.near >= 0);
|
||||
assert.ok(fog.far >= fog.near, "a far plane inside the near plane draws nothing");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the two halves are timed differently on purpose", () => {
|
||||
it("leaves faster than it arrives", () => {
|
||||
// Leaving is an instruction the visitor just gave and wants obeyed; arriving
|
||||
// is a picture they are being shown.
|
||||
assert.ok(FOG_DIP_OUT_SECONDS < FOG_DIP_IN_SECONDS);
|
||||
});
|
||||
|
||||
it("fits inside the pause it is hiding", () => {
|
||||
// The whole transition is 0.8 s. The switch it covers was measured at
|
||||
// 997-1,711 ms of opaque card, of which 222-604 ms blocked the main thread —
|
||||
// so the dip is on the order of the thing it replaces rather than an
|
||||
// addition to it.
|
||||
assert.ok(FOG_DIP_OUT_SECONDS + FOG_DIP_IN_SECONDS <= 1.0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
* The ladder: one descent over three boards, and the rule that hands the camera
|
||||
* from one to the next.
|
||||
*
|
||||
* Two things are being protected here and only one of them is the arithmetic.
|
||||
*
|
||||
* The first is **containment**. The ladder is a new view over the packs, never a
|
||||
* replacement for them: twenty-nine capture guards in `scripts/brand-assets` aim
|
||||
* at `#chapters .chapter` by index and assert the button's short label, and every
|
||||
* still on lumbridgecorp.com is shot that way. So this file asserts that no rung
|
||||
* carries a short label, a number or an id the pack did not, and that the packs'
|
||||
* own chapter arrays are untouched — a ladder that could only be built by editing
|
||||
* a pack is a ladder that re-shoots the marketing site.
|
||||
*
|
||||
* The second is **oscillation**. `handover` is shipped pure and tested here
|
||||
* before it is ever allowed to fire on a wheel notch, because a camera parked at
|
||||
* a threshold without a hysteresis band tears down and rebuilds a board on every
|
||||
* event, and that is not a bug you find by reading the function.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import {
|
||||
activeRung,
|
||||
BOARD_REGION,
|
||||
buildLadder,
|
||||
chapterAltitudeMetres,
|
||||
chapterStandoffMetres,
|
||||
DEMOTE,
|
||||
handover,
|
||||
handoverStandoff,
|
||||
PROMOTE,
|
||||
placesRows,
|
||||
REGION_LABELS,
|
||||
type HandoverBoard,
|
||||
} from "../engine/ladder.ts";
|
||||
import CALIFORNIA from "../cities/california.ts";
|
||||
import SAN_FRANCISCO from "../cities/sf.ts";
|
||||
import SOCAL from "../cities/socal.ts";
|
||||
|
||||
const PACKS = [
|
||||
{ id: "california", city: CALIFORNIA },
|
||||
{ id: "sf", city: SAN_FRANCISCO },
|
||||
{ id: "socal", city: SOCAL },
|
||||
];
|
||||
|
||||
const LADDER = buildLadder(PACKS);
|
||||
|
||||
/** The three boards as `handover` sees them. Metres per unit is `World`'s own arithmetic. */
|
||||
const BOARDS: HandoverBoard[] = PACKS.map((pack) => ({
|
||||
id: pack.id,
|
||||
bounds: pack.city.bounds,
|
||||
metresPerUnit: 111_320 / pack.city.latScale,
|
||||
}));
|
||||
|
||||
describe("the ladder is built from the packs and changes none of them", () => {
|
||||
it("folds the two California doors and keeps every other chapter", () => {
|
||||
const authored =
|
||||
CALIFORNIA.chapters.length + SAN_FRANCISCO.chapters.length + SOCAL.chapters.length;
|
||||
assert.equal(authored, 26, "the three packs author twenty-six chapters between them");
|
||||
assert.equal(LADDER.length, 24, "the two California doors fold onto the metro rungs");
|
||||
|
||||
// The doors are gone as rungs of their own and present as an origin on the
|
||||
// two rungs they open. They are not camera poses — `main.ts` matches them
|
||||
// against `CALIFORNIA_DESTINATIONS` and calls `switchCity` — so a rung for
|
||||
// each would be a duplicate of the board it opens.
|
||||
assert.equal(LADDER.some((rung) => rung.key === "california:los-angeles"), false);
|
||||
assert.equal(LADDER.some((rung) => rung.key === "california:san-francisco"), false);
|
||||
const southland = LADDER.find((rung) => rung.key === "socal:all");
|
||||
const bay = LADDER.find((rung) => rung.key === "sf:all");
|
||||
assert.deepEqual(southland?.doorFrom, { board: "california", id: "los-angeles" });
|
||||
assert.deepEqual(bay?.doorFrom, { board: "california", id: "san-francisco" });
|
||||
});
|
||||
|
||||
it("carries the packs' own ids, numbers and short labels unchanged", () => {
|
||||
for (const pack of PACKS) {
|
||||
for (const chapter of pack.city.chapters) {
|
||||
const rung = LADDER.find((candidate) => candidate.key === `${pack.id}:${chapter.id}`);
|
||||
// The two folded doors are the only chapters without a rung.
|
||||
if (rung === undefined) {
|
||||
assert.ok(
|
||||
chapter.id === "los-angeles" || chapter.id === "san-francisco",
|
||||
`${pack.id}:${chapter.id} has no rung and is not a door`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
assert.equal(rung.id, chapter.id);
|
||||
assert.equal(rung.number, chapter.number);
|
||||
assert.equal(rung.shortLabel, chapter.shortLabel);
|
||||
assert.equal(rung.description, chapter.description);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("resolves the label collisions in the ladder rather than in a pack", () => {
|
||||
// Both metro packs open on a chapter labelled "The Whole Board", and both
|
||||
// call a chapter "The Valley". Renaming either in its pack would move a
|
||||
// string twenty-nine index-aimed capture guards assert on.
|
||||
const labels = LADDER.map((rung) => rung.label);
|
||||
assert.equal(new Set(labels).size, labels.length, `duplicate ladder label in ${labels}`);
|
||||
assert.equal(SAN_FRANCISCO.chapters[0]?.shortLabel, "Whole Board");
|
||||
assert.equal(SOCAL.chapters[0]?.shortLabel, "Whole Board");
|
||||
assert.equal(LADDER.find((r) => r.key === "socal:all")?.label, "The Southland");
|
||||
assert.equal(LADDER.find((r) => r.key === "sf:all")?.label, "The Bay Area");
|
||||
});
|
||||
|
||||
it("puts every rung under a region that has a heading", () => {
|
||||
for (const rung of LADDER) {
|
||||
assert.equal(rung.region, BOARD_REGION[rung.board]);
|
||||
assert.equal(typeof REGION_LABELS[rung.region], "string");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("stand-off, and not altitude, is the ladder's coordinate", () => {
|
||||
it("sorts strictly descending by stand-off", () => {
|
||||
for (let i = 1; i < LADDER.length; i++) {
|
||||
const above = LADDER[i - 1];
|
||||
const below = LADDER[i];
|
||||
assert.ok(above && below);
|
||||
assert.ok(
|
||||
above.standoffM >= below.standoffM,
|
||||
`${above.key} (${above.standoffM}) sorts above ${below.key} (${below.standoffM})`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("separates the three boards by stand-off and interleaves them by altitude", () => {
|
||||
const on = (board: string) => LADDER.filter((rung) => rung.board === board);
|
||||
const california = on("california");
|
||||
const socal = on("socal");
|
||||
const sf = on("sf");
|
||||
|
||||
// The measured claim the coordinate choice rests on: by stand-off the three
|
||||
// boards form three clean bands.
|
||||
const lowestCalifornia = Math.min(...california.map((r) => r.standoffM));
|
||||
const highestSocal = Math.max(...socal.map((r) => r.standoffM));
|
||||
const highestSf = Math.max(...sf.map((r) => r.standoffM));
|
||||
assert.ok(lowestCalifornia > highestSocal, "California bottoms out above the Southland");
|
||||
assert.ok(highestSocal > highestSf, "the Southland's whole board stands off further than the Bay's");
|
||||
assert.ok(Math.round(lowestCalifornia / 1000) === 242, `California bottoms at 242 km, got ${lowestCalifornia}`);
|
||||
assert.ok(Math.round(highestSocal / 1000) === 109, `the Southland tops at 108.8 km, got ${highestSocal}`);
|
||||
assert.ok(Math.round(highestSf / 1000) === 71, `the Bay tops at 71.2 km, got ${highestSf}`);
|
||||
|
||||
// And by altitude they do not: a SoCal chapter sits inside California's range.
|
||||
const californiaAltitudes = california.map((r) => r.altitudeM);
|
||||
const lowestCaliforniaAltitude = Math.min(...californiaAltitudes);
|
||||
const highestCaliforniaAltitude = Math.max(...californiaAltitudes);
|
||||
const interleaved = [...socal, ...sf].filter(
|
||||
(rung) =>
|
||||
rung.altitudeM > lowestCaliforniaAltitude && rung.altitudeM < highestCaliforniaAltitude,
|
||||
);
|
||||
assert.ok(
|
||||
interleaved.length > 0,
|
||||
"an altitude ladder would interleave the boards; that is why stand-off is the coordinate",
|
||||
);
|
||||
});
|
||||
|
||||
it("derives both numbers from the authored focus block alone", () => {
|
||||
const chapter = SAN_FRANCISCO.chapters[0];
|
||||
assert.ok(chapter);
|
||||
const expectedStandoff =
|
||||
Math.hypot(chapter.focus.distance, chapter.focus.height) * (111_320 / SAN_FRANCISCO.latScale);
|
||||
assert.equal(chapterStandoffMetres(chapter, SAN_FRANCISCO.latScale), expectedStandoff);
|
||||
// The vertical exaggeration divides back out, exactly as
|
||||
// `SceneHandle.cameraAltitudeMetres` does through `World.unitsToMetres`.
|
||||
assert.equal(
|
||||
chapterAltitudeMetres(chapter, SAN_FRANCISCO.latScale, SAN_FRANCISCO.verticalExaggeration),
|
||||
(chapter.focus.height * (111_320 / SAN_FRANCISCO.latScale)) /
|
||||
SAN_FRANCISCO.verticalExaggeration,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("the printed list groups what the array interleaves", () => {
|
||||
const rows = placesRows(LADDER);
|
||||
|
||||
it("holds exactly the same rungs", () => {
|
||||
assert.equal(rows.length, LADDER.length);
|
||||
assert.deepEqual(
|
||||
[...rows].map((r) => r.key).sort(),
|
||||
[...LADDER].map((r) => r.key).sort(),
|
||||
);
|
||||
});
|
||||
|
||||
it("prints three region runs rather than nine", () => {
|
||||
const runs: string[] = [];
|
||||
for (const rung of rows) if (runs[runs.length - 1] !== rung.region) runs.push(rung.region);
|
||||
assert.deepEqual(runs, ["state", "southland", "bay"]);
|
||||
|
||||
// The thing grouping exists to avoid: a globally sorted list changes region
|
||||
// far more often than it has regions.
|
||||
const interleavedRuns: string[] = [];
|
||||
for (const rung of LADDER) {
|
||||
if (interleavedRuns[interleavedRuns.length - 1] !== rung.region) {
|
||||
interleavedRuns.push(rung.region);
|
||||
}
|
||||
}
|
||||
assert.ok(
|
||||
interleavedRuns.length > 5,
|
||||
`a global sort changes region ${interleavedRuns.length} times; grouping is why the list is readable`,
|
||||
);
|
||||
});
|
||||
|
||||
it("still descends inside every group", () => {
|
||||
for (let i = 1; i < rows.length; i++) {
|
||||
const above = rows[i - 1];
|
||||
const below = rows[i];
|
||||
assert.ok(above && below);
|
||||
if (above.region !== below.region) continue;
|
||||
assert.ok(above.standoffM >= below.standoffM, `${above.key} then ${below.key}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("the lit rung is an altimeter, not a menu", () => {
|
||||
it("keeps the rung you flew to lit when the camera is on its pose", () => {
|
||||
const soma = LADDER.find((rung) => rung.key === "sf:soma");
|
||||
assert.ok(soma);
|
||||
assert.equal(activeRung(LADDER, "sf", soma.standoffM, "soma")?.key, "sf:soma");
|
||||
});
|
||||
|
||||
it("does not hop between the four Bay rungs that sit inside 12% of each other", () => {
|
||||
const eastBay = LADDER.find((rung) => rung.key === "sf:east-bay");
|
||||
const sanJose = LADDER.find((rung) => rung.key === "sf:south-bay");
|
||||
assert.ok(eastBay && sanJose);
|
||||
assert.ok(
|
||||
Math.abs(eastBay.standoffM - sanJose.standoffM) / sanJose.standoffM < 0.12,
|
||||
"these two are the near-collision the tolerance exists for",
|
||||
);
|
||||
// Parked on the East Bay's own pose, the East Bay stays lit even though San
|
||||
// Jose's number is only two per cent away.
|
||||
assert.equal(activeRung(LADDER, "sf", eastBay.standoffM, "east-bay")?.key, "sf:east-bay");
|
||||
});
|
||||
|
||||
it("follows the camera once it has left that pose", () => {
|
||||
const whole = LADDER.find((rung) => rung.key === "sf:all");
|
||||
const missionBay = LADDER.find((rung) => rung.key === "sf:mission-bay");
|
||||
assert.ok(whole && missionBay);
|
||||
// Still nominally "on" the whole-board chapter, but flown down to street
|
||||
// level: the list has to say where the camera is.
|
||||
assert.equal(activeRung(LADDER, "sf", missionBay.standoffM, "all")?.key, "sf:mission-bay");
|
||||
});
|
||||
|
||||
it("only ever lights a rung on the resident board", () => {
|
||||
for (const standoff of [3_000, 30_000, 300_000, 3_000_000]) {
|
||||
assert.equal(activeRung(LADDER, "socal", standoff, null)?.board, "socal");
|
||||
}
|
||||
});
|
||||
|
||||
it("answers null for a board with no rungs", () => {
|
||||
assert.equal(activeRung(LADDER, "paris", 10_000, null), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("handover does not oscillate", () => {
|
||||
/** Downtown San Francisco: inside the sf rectangle, inside California's. */
|
||||
const SF_TARGET = { lat: 37.7749, lng: -122.4194 };
|
||||
/** Downtown Los Angeles: inside the socal rectangle, inside California's. */
|
||||
const LA_TARGET = { lat: 34.05, lng: -118.24 };
|
||||
/** Fresno: inside California and inside neither metro. */
|
||||
const FRESNO = { lat: 36.74, lng: -119.78 };
|
||||
|
||||
const query = (over: {
|
||||
current: string;
|
||||
standoffM: number;
|
||||
lat: number;
|
||||
lng: number;
|
||||
dragging?: boolean;
|
||||
}) => handover({ boards: BOARDS, ...over });
|
||||
|
||||
it("promotes below the authored threshold and stays put above it", () => {
|
||||
const sf = handoverStandoff("sf");
|
||||
assert.equal(sf, 71_200);
|
||||
assert.equal(
|
||||
query({ current: "california", standoffM: sf * PROMOTE * 0.99, ...SF_TARGET }),
|
||||
"sf",
|
||||
);
|
||||
assert.equal(query({ current: "california", standoffM: sf * PROMOTE * 1.01, ...SF_TARGET }), null);
|
||||
});
|
||||
|
||||
it("promotes at most once and demotes at most once over a full sweep", () => {
|
||||
const sf = handoverStandoff("sf");
|
||||
let current = "california";
|
||||
let promotions = 0;
|
||||
let demotions = 0;
|
||||
|
||||
const step = (standoffM: number) => {
|
||||
const next = query({ current, standoffM, ...SF_TARGET });
|
||||
if (next === null) return;
|
||||
if (next === "sf") promotions++;
|
||||
else demotions++;
|
||||
current = next;
|
||||
};
|
||||
|
||||
// Down through the threshold in one per cent steps, and back up again.
|
||||
for (let f = 1.4; f >= 0.5; f -= 0.01) step(sf * f);
|
||||
assert.equal(current, "sf", "the sweep down ends on the finer board");
|
||||
for (let f = 0.5; f <= 1.4; f += 0.01) step(sf * f);
|
||||
|
||||
assert.equal(promotions, 1, "one promotion over the whole sweep");
|
||||
assert.equal(demotions, 1, "one demotion over the whole sweep");
|
||||
assert.equal(current, "california", "the sweep up ends back on the state");
|
||||
});
|
||||
|
||||
it("has a dead band between the promote and demote thresholds", () => {
|
||||
const sf = handoverStandoff("sf");
|
||||
// Inside the band, neither direction fires, from either side of it.
|
||||
for (const f of [PROMOTE + 0.01, 1.0, DEMOTE - 0.01]) {
|
||||
assert.equal(query({ current: "california", standoffM: sf * f, ...SF_TARGET }), null);
|
||||
assert.equal(query({ current: "sf", standoffM: sf * f, ...SF_TARGET }), null);
|
||||
}
|
||||
});
|
||||
|
||||
it("never fires while a drag is in flight", () => {
|
||||
const sf = handoverStandoff("sf");
|
||||
assert.equal(
|
||||
query({ current: "california", standoffM: sf * 0.2, dragging: true, ...SF_TARGET }),
|
||||
null,
|
||||
);
|
||||
assert.equal(
|
||||
query({ current: "sf", standoffM: sf * 10, dragging: true, ...SF_TARGET }),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
it("refuses to promote where there is no finer board — 97.4% of the state", () => {
|
||||
for (const standoffM of [200_000, 60_000, 20_000, 4_000]) {
|
||||
assert.equal(query({ current: "california", standoffM, ...FRESNO }), null);
|
||||
}
|
||||
});
|
||||
|
||||
it("promotes into the Southland over Los Angeles and never into the Bay", () => {
|
||||
assert.equal(
|
||||
query({ current: "california", standoffM: handoverStandoff("socal") * 0.5, ...LA_TARGET }),
|
||||
"socal",
|
||||
);
|
||||
// The two metro rectangles do not intersect, so the candidate set is never
|
||||
// larger than one — the assertion is that the *other* one is not a candidate.
|
||||
assert.equal(query({ current: "sf", standoffM: 10_000, ...LA_TARGET }), null);
|
||||
});
|
||||
|
||||
it("demotes to California and never straight into the other metro", () => {
|
||||
assert.equal(
|
||||
query({ current: "sf", standoffM: handoverStandoff("sf") * DEMOTE * 1.01, ...SF_TARGET }),
|
||||
"california",
|
||||
);
|
||||
assert.equal(handoverStandoff("california"), Number.POSITIVE_INFINITY);
|
||||
// California hands over to nothing, so no stand-off demotes off it.
|
||||
assert.equal(query({ current: "california", standoffM: 5_000_000, ...SF_TARGET }), null);
|
||||
});
|
||||
|
||||
it("refuses a nonsense stand-off rather than guessing", () => {
|
||||
for (const standoffM of [0, -1, Number.NaN, Number.POSITIVE_INFINITY]) {
|
||||
assert.equal(query({ current: "california", standoffM, ...SF_TARGET }), null);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Three packs, one place: do the boards agree about where a thing is?
|
||||
*
|
||||
* `World.lngScale` is `latScale × cos(centre.lat)`, and each pack takes the
|
||||
* cosine at its **own** centre — 37.30°, 37.77°, 33.82°. A degree of longitude
|
||||
* is then worth 88,552 m on the state board and 92,484 m on Southern
|
||||
* California, so the two boards put the same coordinate in two different places
|
||||
* and the gap grows with distance from the anchor. At a 109 km stand-off the
|
||||
* worst of it is about 3% of the frame: a visible sideways slide in any
|
||||
* transition that shows both boards at once, and a permanent disagreement about
|
||||
* where Riverside is.
|
||||
*
|
||||
* The numbers below are measured on these packs, not quoted from a brief.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { afterEach, describe, it } from "node:test";
|
||||
import CALIFORNIA from "../cities/california.ts";
|
||||
import { REFERENCE_LAT, setReconcile } from "../cities/reconcile.ts";
|
||||
import SF from "../cities/sf.ts";
|
||||
import SOCAL from "../cities/socal.ts";
|
||||
import { World } from "../engine/world.ts";
|
||||
|
||||
/** Downtown Los Angeles: inside both southern boards, so a fair shared origin. */
|
||||
const ANCHOR: [number, number] = [34.05, -118.24];
|
||||
|
||||
const PLACES: [string, number, number][] = [
|
||||
["the shared north-east corner", 34.36, -117.22],
|
||||
["Riverside", 33.98, -117.37],
|
||||
["the south-west corner", 33.28, -118.88],
|
||||
];
|
||||
|
||||
/** Where a board puts a place, in true metres from the anchor. */
|
||||
function offset(world: World, lat: number, lng: number): [number, number] {
|
||||
const [x0, z0] = world.project(...ANCHOR);
|
||||
const [x1, z1] = world.project(lat, lng);
|
||||
return [(x1 - x0) * world.metresPerUnit, (z1 - z0) * world.metresPerUnit];
|
||||
}
|
||||
|
||||
function disagreement(a: World, b: World, lat: number, lng: number): number {
|
||||
const [ax, az] = offset(a, lat, lng);
|
||||
const [bx, bz] = offset(b, lat, lng);
|
||||
return Math.hypot(ax - bx, az - bz);
|
||||
}
|
||||
|
||||
afterEach(() => setReconcile(null));
|
||||
|
||||
describe("projection", () => {
|
||||
it("disagrees by kilometres today", () => {
|
||||
setReconcile(false);
|
||||
const california = new World(CALIFORNIA);
|
||||
const socal = new World(SOCAL);
|
||||
const worst = Math.max(...PLACES.map(([, lat, lng]) => disagreement(california, socal, lat, lng)));
|
||||
assert.ok(worst > 3_500, `expected kilometres of drift, measured ${worst.toFixed(0)} m`);
|
||||
assert.ok(worst < 4_200, `measured ${worst.toFixed(0)} m — the packs moved, re-read this test`);
|
||||
});
|
||||
|
||||
it("agrees within 50 m once every board squashes longitude the same way", () => {
|
||||
setReconcile(["projection"]);
|
||||
const worlds = [CALIFORNIA, SF, SOCAL].map((pack) => new World(pack));
|
||||
for (const [name, lat, lng] of PLACES) {
|
||||
for (const a of worlds) {
|
||||
for (const b of worlds) {
|
||||
const gap = disagreement(a, b, lat, lng);
|
||||
assert.ok(gap < 50, `${name}: ${a.city.id} vs ${b.city.id} is ${gap.toFixed(0)} m apart`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("puts every board on the one reference latitude", () => {
|
||||
setReconcile(["projection"]);
|
||||
for (const pack of [CALIFORNIA, SF, SOCAL]) {
|
||||
const world = new World(pack);
|
||||
const expected = pack.latScale * Math.cos((REFERENCE_LAT * Math.PI) / 180);
|
||||
assert.ok(Math.abs(world.lngScale - expected) < 1e-9, pack.id);
|
||||
// And the hill squash follows it, or hills stop being circles in scene
|
||||
// space on the two boards whose own latitude is not the reference.
|
||||
assert.ok(Math.abs(world.lngSquash - world.lngScale / pack.latScale) < 1e-15, pack.id);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The price, stated so it cannot be discovered later. Southern California is
|
||||
* projected at 37.3° rather than at its own 33.82°, so it draws narrower in x
|
||||
* than a projection taken at its own latitude would — measured, 4.25% — and
|
||||
* San Francisco 0.64% wider. That is the trade: local aspect, for
|
||||
* registration that is exact by construction.
|
||||
*/
|
||||
it("costs Southern California 4.25% of its width and San Francisco 0.64%", () => {
|
||||
setReconcile(["projection"]);
|
||||
const shrink = (pack: typeof SOCAL): number => {
|
||||
const before = pack.latScale * Math.cos((pack.center.lat * Math.PI) / 180);
|
||||
return new World(pack).lngScale / before - 1;
|
||||
};
|
||||
assert.ok(Math.abs(shrink(SOCAL) + 0.0425) < 0.0005, String(shrink(SOCAL)));
|
||||
assert.ok(Math.abs(shrink(SF) - 0.0064) < 0.0005, String(shrink(SF)));
|
||||
assert.equal(shrink(CALIFORNIA), 0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
* The reconciliation, and the one property that protects the live site: with
|
||||
* the flag off, nothing anywhere is different.
|
||||
*
|
||||
* "Byte-identical with the flag off" is asserted here rather than only in a
|
||||
* photograph because a photograph proves it for one frame of one board on one
|
||||
* afternoon, and this proves it for the object the engine reads. `reconciledCity`
|
||||
* returning its argument **by identity** is the strongest form of that claim
|
||||
* available: not a copy that happens to carry the same numbers, the same object.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { afterEach, describe, it } from "node:test";
|
||||
import CALIFORNIA from "../cities/california.ts";
|
||||
import {
|
||||
COAST_RAMP_CELLS,
|
||||
RELIEF_IN_FRAME,
|
||||
blendedPeakMetres,
|
||||
describe as describeReconciliation,
|
||||
reconciledCity,
|
||||
reconciledCoastFalloff,
|
||||
reconciledExaggeration,
|
||||
reconciledPalette,
|
||||
reconciledPaletteMix,
|
||||
setReconcile,
|
||||
} from "../cities/reconcile.ts";
|
||||
import SF from "../cities/sf.ts";
|
||||
import SOCAL from "../cities/socal.ts";
|
||||
import { DEFAULT_PALETTE } from "../engine/terrain.ts";
|
||||
import { World } from "../engine/world.ts";
|
||||
|
||||
const PACKS = [CALIFORNIA, SF, SOCAL];
|
||||
|
||||
afterEach(() => setReconcile(null));
|
||||
|
||||
describe("reconcile — the flag off", () => {
|
||||
it("hands every pack back by identity", () => {
|
||||
setReconcile(false);
|
||||
for (const pack of PACKS) assert.equal(reconciledCity(pack), pack);
|
||||
});
|
||||
|
||||
it("leaves the World's derived scalars exactly where they were", () => {
|
||||
setReconcile(false);
|
||||
for (const pack of PACKS) {
|
||||
const world = new World(pack);
|
||||
assert.equal(world.city, pack);
|
||||
assert.equal(world.lngScale, pack.latScale * Math.cos((pack.center.lat * Math.PI) / 180));
|
||||
assert.equal(world.lngSquash, world.lngScale / pack.latScale);
|
||||
assert.equal(world.metresPerUnit, 111_320 / pack.latScale);
|
||||
assert.equal(world.city.verticalExaggeration, pack.verticalExaggeration);
|
||||
assert.equal(world.city.coastFalloff, pack.coastFalloff);
|
||||
assert.deepEqual(
|
||||
world.city.roads.map((road) => road.width),
|
||||
pack.roads.map((road) => road.width),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* `lngSquash` stopped being `cos(centre.lat)` and became `lngScale/latScale`,
|
||||
* which is the same number for every authored pack and the right one for a
|
||||
* reconciled one. This is the assertion that the "same number" half is true —
|
||||
* it is what every hill on every shipped board stands on.
|
||||
*/
|
||||
it("computes the same hill squash the old expression did", () => {
|
||||
setReconcile(false);
|
||||
for (const pack of PACKS) {
|
||||
const world = new World(pack);
|
||||
const old = Math.cos((pack.center.lat * Math.PI) / 180);
|
||||
assert.ok(Math.abs(world.lngSquash - old) < 1e-15, `${pack.id}: ${world.lngSquash} vs ${old}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconcile — one relief rule", () => {
|
||||
/**
|
||||
* The whole claim of rule (a), as one number per board.
|
||||
*
|
||||
* Relief in the frame is peak scene units over board span — ARCHITECTURE
|
||||
* §12.1's rule, and the one it moved California from 13 to 15 to hold. Today
|
||||
* the three boards read 7.24%, 4.51% and 6.92%; the rule puts all three on
|
||||
* `RELIEF_IN_FRAME`.
|
||||
*/
|
||||
it("puts all three boards on one relief-in-frame number", () => {
|
||||
setReconcile(["exaggeration", "projection"]);
|
||||
const relief = PACKS.map((pack) => {
|
||||
const world = new World(pack);
|
||||
const span = Math.max(
|
||||
(pack.bounds.maxLat - pack.bounds.minLat) * pack.latScale,
|
||||
(pack.bounds.maxLng - pack.bounds.minLng) * world.lngScale,
|
||||
);
|
||||
return world.metres(blendedPeakMetres(pack)) / span;
|
||||
});
|
||||
for (const value of relief) assert.ok(Math.abs(value - RELIEF_IN_FRAME) < 1e-6, String(value));
|
||||
});
|
||||
|
||||
/**
|
||||
* The board ARCHITECTURE §12.1 tuned against a photograph does not move, and
|
||||
* that is not a coincidence: `RELIEF_IN_FRAME` is California's own number,
|
||||
* rounded to three significant figures. The 0.1% here is that rounding.
|
||||
*/
|
||||
it("leaves California where the photograph put it", () => {
|
||||
assert.ok(Math.abs(reconciledExaggeration(CALIFORNIA) - 15) < 0.015);
|
||||
});
|
||||
|
||||
/**
|
||||
* The honest limit of rule (a), asserted so nobody assumes otherwise.
|
||||
*
|
||||
* Apparent relief at a *matched* pose — the same true-metre stand-off on both
|
||||
* boards, which is what the seam actually is — is proportional to the
|
||||
* exaggeration itself and not to relief-in-frame. The rule takes the Bay Area
|
||||
* direction from 4.17× to 2.60× and leaves the Southern California direction
|
||||
* at 4.4×, because those two boards were already on one number. Only a single
|
||||
* exaggeration everywhere would make it 1.0×, and that flattens the state to
|
||||
* 1.7% of its own frame.
|
||||
*/
|
||||
it("narrows the seam step without closing it", () => {
|
||||
setReconcile(["exaggeration", "projection"]);
|
||||
const ex = (pack: typeof CALIFORNIA): number => new World(pack).city.verticalExaggeration;
|
||||
assert.ok(ex(CALIFORNIA) / ex(SF) < 4.167, "the Bay Area direction must improve");
|
||||
assert.ok(Math.abs(ex(CALIFORNIA) / ex(SF) - 2.6) < 0.1);
|
||||
assert.ok(Math.abs(ex(CALIFORNIA) / ex(SOCAL) - 4.41) < 0.1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconcile — one ground convention", () => {
|
||||
it("makes the coastal ramp a fixed multiple of the coarse cell", () => {
|
||||
for (const pack of PACKS) {
|
||||
const cell = pack.cellLat * (pack.coarseFactor ?? 1);
|
||||
assert.ok(Math.abs(reconciledCoastFalloff(pack) / cell - COAST_RAMP_CELLS) < 1e-12);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* The rule is California's own ratio, so the state board's 0.025° comes back
|
||||
* out of it to within 0.2%. That is what makes it a rule found rather than a
|
||||
* rule invented.
|
||||
*/
|
||||
it("reproduces California's authored falloff", () => {
|
||||
assert.ok(Math.abs(reconciledCoastFalloff(CALIFORNIA) / CALIFORNIA.coastFalloff - 1) < 0.002);
|
||||
});
|
||||
|
||||
it("only ever widens the metro ramps, which is the direction that hides steps", () => {
|
||||
for (const pack of [SF, SOCAL]) assert.ok(reconciledCoastFalloff(pack) > pack.coastFalloff);
|
||||
});
|
||||
|
||||
/** The north anchor is `DEFAULT_PALETTE`, copied. This is the copy not drifting. */
|
||||
it("keeps its copy of DEFAULT_PALETTE honest", () => {
|
||||
setReconcile(["ground"]);
|
||||
const north = reconciledPalette({ ...SF, bounds: { ...SF.bounds, minLat: 90, maxLng: -122 } });
|
||||
for (const [key, value] of Object.entries(DEFAULT_PALETTE)) {
|
||||
assert.equal(north[key as keyof typeof north], value, key);
|
||||
}
|
||||
});
|
||||
|
||||
it("gives California its own palette back, exactly", () => {
|
||||
const mixed = reconciledPalette(CALIFORNIA);
|
||||
assert.equal(reconciledPaletteMix(CALIFORNIA), 1);
|
||||
for (const [key, value] of Object.entries(CALIFORNIA.palette ?? {})) {
|
||||
assert.equal(mixed[key as keyof typeof mixed], value, key);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* `alpine` is a fact about the board, not a taste: it is the colour of ground
|
||||
* above the snow line, so a board with no ground up there does not get one.
|
||||
* San Francisco's tallest is 1,186 m against a 1,900 m threshold.
|
||||
*/
|
||||
it("hands out the alpine stop only to a board that reaches the snow line", () => {
|
||||
assert.equal(reconciledPalette(SF).alpine, undefined);
|
||||
assert.ok(reconciledPalette(SOCAL).alpine !== undefined);
|
||||
assert.ok(reconciledPalette(CALIFORNIA).alpine !== undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe("reconcile — the mechanics", () => {
|
||||
it("is idempotent, which is what the terrain worker's second pass depends on", () => {
|
||||
setReconcile(true);
|
||||
for (const pack of PACKS) {
|
||||
const once = reconciledCity(pack);
|
||||
const clone = JSON.parse(JSON.stringify(once)) as typeof once;
|
||||
assert.equal(reconciledCity(once), once);
|
||||
assert.equal(reconciledCity(clone), clone);
|
||||
assert.equal(clone.reconciled, true);
|
||||
}
|
||||
});
|
||||
|
||||
it("returns one object per pack and rule set, so a rebuild agrees with itself", () => {
|
||||
setReconcile(["roads"]);
|
||||
const roads = reconciledCity(SF);
|
||||
assert.equal(reconciledCity(SF), roads);
|
||||
setReconcile(["roads", "ground"]);
|
||||
assert.notEqual(reconciledCity(SF), roads);
|
||||
setReconcile(["roads"]);
|
||||
assert.equal(reconciledCity(SF), roads);
|
||||
});
|
||||
|
||||
it("turns each rule on alone", () => {
|
||||
setReconcile(["roads"]);
|
||||
const roadsOnly = reconciledCity(CALIFORNIA);
|
||||
assert.equal(roadsOnly.verticalExaggeration, CALIFORNIA.verticalExaggeration);
|
||||
assert.equal(roadsOnly.coastFalloff, CALIFORNIA.coastFalloff);
|
||||
assert.equal(roadsOnly.lngScale, undefined);
|
||||
assert.notEqual(roadsOnly.roads[0]?.width, CALIFORNIA.roads[0]?.width);
|
||||
|
||||
setReconcile(["exaggeration"]);
|
||||
const reliefOnly = reconciledCity(SF);
|
||||
assert.notEqual(reliefOnly.verticalExaggeration, SF.verticalExaggeration);
|
||||
assert.deepEqual(
|
||||
reliefOnly.roads.map((r) => r.width),
|
||||
SF.roads.map((r) => r.width),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports what it did", () => {
|
||||
const report = describeReconciliation(SOCAL);
|
||||
assert.equal(report.id, "socal");
|
||||
assert.ok(report.lngMetresPerDegree.before > report.lngMetresPerDegree.after);
|
||||
assert.ok(report.roadMetres.after[0] > 30 && report.roadMetres.after[1] < 56);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* A road is a road on every board, or it is a symbol on one of them.
|
||||
*
|
||||
* Measured on these packs: San Francisco's roads are 19–32 m wide and Southern
|
||||
* California's 31–55 m, which is what those roads are. California's US-101 and
|
||||
* I-5 are **1,919 m and 2,034 m** — wider than the cities they join, and the
|
||||
* most prominent marks on the state board. At the seam one has to become the
|
||||
* other, and a 2 km ribbon turning into a 30 m line is a change of drawing
|
||||
* convention rather than an LOD transition.
|
||||
*
|
||||
* Rule (b) reads every width as true metres and floors it at the narrowest
|
||||
* fraction of a board span the two metro packs already agree on. The floor is
|
||||
* the interesting part: it was measured off the shipped packs rather than
|
||||
* chosen, and it is what makes "the metro boards do not move" a property of the
|
||||
* rule rather than a coincidence to be checked.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { afterEach, describe, it } from "node:test";
|
||||
import CALIFORNIA from "../cities/california.ts";
|
||||
import { LEGIBLE_SPAN_FRACTION, reconciledRoadWidth, setReconcile } from "../cities/reconcile.ts";
|
||||
import SF from "../cities/sf.ts";
|
||||
import SOCAL from "../cities/socal.ts";
|
||||
import type { City } from "../engine/types.ts";
|
||||
import { World } from "../engine/world.ts";
|
||||
|
||||
const metresPerUnit = (city: City): number => 111_320 / city.latScale;
|
||||
|
||||
/** Every road on a board, in true metres, as the engine will draw it. */
|
||||
function drawn(city: City): number[] {
|
||||
const world = new World(city);
|
||||
return world.city.roads.map((road) => road.width * world.metresPerUnit);
|
||||
}
|
||||
|
||||
afterEach(() => setReconcile(null));
|
||||
|
||||
describe("road width", () => {
|
||||
it("is a symbol two kilometres wide on the state board today", () => {
|
||||
setReconcile(false);
|
||||
const widths = drawn(CALIFORNIA);
|
||||
assert.deepEqual(widths.map(Math.round), [1919, 2034]);
|
||||
});
|
||||
|
||||
it("leaves both metro boards untouched, to the digit", () => {
|
||||
setReconcile(false);
|
||||
const before = { sf: drawn(SF), socal: drawn(SOCAL) };
|
||||
setReconcile(["roads"]);
|
||||
assert.deepEqual(drawn(SF), before.sf);
|
||||
assert.deepEqual(drawn(SOCAL), before.socal);
|
||||
});
|
||||
|
||||
/**
|
||||
* Why the floor is 0.000199 and not a round number: the two metro packs,
|
||||
* authored separately, put their narrowest road at 0.00019940 and 0.00020356
|
||||
* of their own span. Two authors agreeing to within 2% about how thin a line
|
||||
* may get is the measurement the constant is taken from, and the floor sits
|
||||
* just under the tighter of the two so that neither board moves.
|
||||
*/
|
||||
it("sits just under the narrowest road either metro pack authored", () => {
|
||||
for (const pack of [SF, SOCAL]) {
|
||||
const world = new World(pack);
|
||||
const span = Math.max(
|
||||
(pack.bounds.maxLat - pack.bounds.minLat) * pack.latScale,
|
||||
(pack.bounds.maxLng - pack.bounds.minLng) * world.lngScale,
|
||||
);
|
||||
const narrowest = Math.min(...pack.roads.map((road) => road.width)) / span;
|
||||
assert.ok(narrowest > LEGIBLE_SPAN_FRACTION, `${pack.id}: ${narrowest}`);
|
||||
assert.ok(narrowest < LEGIBLE_SPAN_FRACTION * 1.05, `${pack.id}: ${narrowest}`);
|
||||
}
|
||||
});
|
||||
|
||||
it("collapses California's freeways by 9x, onto the floor", () => {
|
||||
setReconcile(["roads"]);
|
||||
const widths = drawn(CALIFORNIA);
|
||||
for (const metres of widths) {
|
||||
assert.ok(metres > 200 && metres < 220, `${metres} m`);
|
||||
}
|
||||
assert.ok(1919 / (widths[0] as number) > 9);
|
||||
});
|
||||
|
||||
/**
|
||||
* The floor is a floor, not a width: a road wider in true metres than the
|
||||
* floor keeps its own width. Nothing on the shipped boards exercises this —
|
||||
* every metro road clears the floor and both California roads fall onto it —
|
||||
* so it is asserted directly rather than left to be discovered by a pack that
|
||||
* one day authors a 400 m causeway on a small board.
|
||||
*/
|
||||
it("is a floor and not a width", () => {
|
||||
const wide = { ...CALIFORNIA.roads[0], widthM: 400_000 } as (typeof CALIFORNIA.roads)[number];
|
||||
const units = reconciledRoadWidth(CALIFORNIA, wide);
|
||||
assert.ok(Math.abs(units * metresPerUnit(CALIFORNIA) - 400_000) < 1);
|
||||
});
|
||||
|
||||
it("reads an undeclared width as true metres already", () => {
|
||||
const street = SF.roads.find((road) => road.kind === "street");
|
||||
assert.ok(street !== undefined && street.widthM === undefined);
|
||||
assert.ok(Math.abs(reconciledRoadWidth(SF, street) - street.width) < 1e-9);
|
||||
});
|
||||
});
|
||||
+135
-4
@@ -43,7 +43,7 @@ import type { DeviceDeclaration } from "../devices/types.ts";
|
||||
import type { ControlMode } from "../play/controlMode.ts";
|
||||
import { formatAircraftDetail, formatPlayHud } from "./hud.ts";
|
||||
import type { AircraftDetailInput, AircraftDetailView, PlayHudView, PlayTelemetry } from "./hud.ts";
|
||||
import { railHints } from "./shortcuts.ts";
|
||||
import { railHints, railLabel } from "./shortcuts.ts";
|
||||
import { BREAKPOINT } from "./tokens.ts";
|
||||
|
||||
// ---- Inputs ---------------------------------------------------------------
|
||||
@@ -122,6 +122,32 @@ export interface ChromeView {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* One rung of the places list: a chapter on some board, named so it can be told
|
||||
* apart from the chapters on the other two.
|
||||
*
|
||||
* A separate shape from `ChromeView` on purpose. A view is a row in the *current*
|
||||
* board's tour and is addressed by its position in that list — which is the one
|
||||
* thing about a chapter this round may not move, because the capture guards aim
|
||||
* that way. A place is addressed by `key`, carries the board it is on, and is
|
||||
* ordered by how far the camera stands back. Two different identities, two
|
||||
* types, and no chance of one silently standing in for the other.
|
||||
*/
|
||||
export interface ChromePlace {
|
||||
/** `board:chapter`. Unique across the whole ladder. */
|
||||
key: string;
|
||||
/** The chapter id on its own board. */
|
||||
id: string;
|
||||
board: string;
|
||||
/** The heading this rung sits under: a region, never a board. */
|
||||
region: string;
|
||||
/** Unique across the ladder — the two "Whole Board" rungs are named here. */
|
||||
label: string;
|
||||
/** True metres from the camera to the target at this rung's authored pose. */
|
||||
standoffM: number;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the detail card is showing.
|
||||
*
|
||||
@@ -196,6 +222,20 @@ export interface ChromeInputs {
|
||||
presenceVisible?: boolean;
|
||||
/** The board strip's entries: cities outside a building, offices inside one. */
|
||||
boards?: readonly ChromeBoardTab[];
|
||||
/**
|
||||
* Whether the board strip is *drawn*. The list above is built either way.
|
||||
*
|
||||
* The two are separate because the strip has a second reader: the harnesses
|
||||
* reach a board with `document.querySelector('[data-board=…]').click()`, and a
|
||||
* DOM click does not care whether an element is displayed. Emptying the list
|
||||
* would take the control away from them as well as from the visitor; hiding it
|
||||
* takes it away from the visitor only, which is what this round is for.
|
||||
*/
|
||||
boardsVisible?: boolean;
|
||||
/** The ladder, in the order the column prints it. Empty hides the section. */
|
||||
places?: readonly ChromePlace[];
|
||||
/** The rung the camera is standing on, by `key`. */
|
||||
activePlaceKey?: string | null;
|
||||
/** The chapter list: city chapters outside, authored viewpoints inside. */
|
||||
views?: readonly ChromeView[];
|
||||
activeViewId?: string | null;
|
||||
@@ -255,6 +295,28 @@ export interface ChromeViewRow {
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface ChromePlaceRow {
|
||||
key: string;
|
||||
id: string;
|
||||
board: string;
|
||||
label: string;
|
||||
active: boolean;
|
||||
/** The region heading to print **above** this row, or `null` to print none. */
|
||||
region: string | null;
|
||||
/**
|
||||
* The digit key that reaches this rung, or `null` past the ninth.
|
||||
*
|
||||
* The number **is** the key, which is why it stops at nine rather than
|
||||
* counting to twenty-four: a printed ordinal that no keystroke matches is a
|
||||
* label pretending to be an affordance. The chapter list gets away with
|
||||
* numbering everything because a pack's numbers are authored captions; the
|
||||
* ladder's are not.
|
||||
*/
|
||||
key9: string | null;
|
||||
/** "1,551 km" / "3.9 km". Formatted here so the applier has no decisions left. */
|
||||
standoff: string;
|
||||
}
|
||||
|
||||
/** The detail card, resolved. `null` when nothing is picked. */
|
||||
export type ChromeDetailView =
|
||||
| { kind: "text"; text: string }
|
||||
@@ -307,8 +369,12 @@ export interface ChromeState {
|
||||
* consistent frame of chrome.
|
||||
*/
|
||||
deviceDeclarations: readonly DeviceDeclaration[];
|
||||
/** Whether the board strip is worth drawing at all. See `ChromeInputs.boards`. */
|
||||
boardsVisible: boolean;
|
||||
chaptersVisible: boolean;
|
||||
views: readonly ChromeViewRow[];
|
||||
placesVisible: boolean;
|
||||
places: readonly ChromePlaceRow[];
|
||||
blurbVisible: boolean;
|
||||
blurbText: string;
|
||||
|
||||
@@ -478,6 +544,21 @@ export function seedPlanOpen(_width: number): boolean {
|
||||
|
||||
// ---- The function ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A stand-off as a person reads it, from 3.9 km to 1,551 km.
|
||||
*
|
||||
* Kilometres everywhere, because the ladder spans four orders of magnitude and
|
||||
* switching units partway down a column of numbers turns a scale into a puzzle.
|
||||
* One decimal below 10 km, where the difference between 3.9 and 4.3 is two
|
||||
* different neighbourhoods; none above it, where it is noise.
|
||||
*/
|
||||
function formatStandoff(metres: number): string {
|
||||
if (!Number.isFinite(metres) || metres <= 0) return "";
|
||||
const km = metres / 1000;
|
||||
if (km < 10) return `${km.toFixed(1)} km`;
|
||||
return `${Math.round(km).toLocaleString("en-US")} km`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the whole interface for one instant. Pure, total, and cheap enough to
|
||||
* call on every frame if the caller wants to.
|
||||
@@ -578,8 +659,10 @@ export function chromeState(inputs: ChromeInputs): ChromeState {
|
||||
keys: entry.keys,
|
||||
// `rail`, not `meaning`: the sheet gets the sentence, the rail gets the
|
||||
// glance. See the field's note in `shortcuts.ts` for what reusing the
|
||||
// sentence here actually looked like on screen.
|
||||
label: entry.rail ?? entry.meaning,
|
||||
// sentence here actually looked like on screen. `railLabel` is what makes
|
||||
// the digits read "Places" on a board and "Viewpoints" in a room without
|
||||
// binding the same nine keys twice.
|
||||
label: railLabel(entry, inside),
|
||||
}));
|
||||
|
||||
// ---- The honesty line ---------------------------------------------------
|
||||
@@ -654,7 +737,45 @@ export function chromeState(inputs: ChromeInputs): ChromeState {
|
||||
label: view.shortLabel,
|
||||
active: view.id === inputs.activeViewId,
|
||||
}));
|
||||
|
||||
/**
|
||||
* The ladder, with a heading printed only where the region actually changes.
|
||||
*
|
||||
* The caller hands these over already ordered — grouping is a fact about the
|
||||
* ladder and lives in `engine/ladder.ts`, next to the measurement that says a
|
||||
* globally interleaved list would print nine headings for three regions. All
|
||||
* this does is decide which rows carry one.
|
||||
*/
|
||||
const placesInput = inputs.places ?? [];
|
||||
let lastRegion: string | null = null;
|
||||
const places: readonly ChromePlaceRow[] = placesInput.map((place, i) => {
|
||||
const region = place.region === lastRegion ? null : place.region;
|
||||
lastRegion = place.region;
|
||||
return {
|
||||
key: place.key,
|
||||
id: place.id,
|
||||
board: place.board,
|
||||
label: place.label,
|
||||
active: place.key === inputs.activePlaceKey,
|
||||
region,
|
||||
key9: i < 9 ? String(i + 1) : null,
|
||||
standoff: formatStandoff(place.standoffM),
|
||||
};
|
||||
});
|
||||
|
||||
const activeView = (inputs.views ?? []).find((view) => view.id === inputs.activeViewId);
|
||||
/**
|
||||
* The sentence under the list, and it stays pinned to the **chapter** rather
|
||||
* than to the lit rung.
|
||||
*
|
||||
* They are usually the same sentence and deliberately not always. The lit rung
|
||||
* is an altimeter — it follows the camera, so dragging away from a chapter
|
||||
* moves it — and the blurb is a caption for the thing somebody *chose*.
|
||||
* `scripts/brand-assets/shots.mjs` depends on exactly that: several shots pick
|
||||
* a chapter so that "the blurb left in the panel is a caption inside the
|
||||
* frame", and then aim the camera somewhere else through the plan view. A
|
||||
* blurb that followed the camera would silently recaption those stills.
|
||||
*/
|
||||
const blurbText = activeView?.description ?? "";
|
||||
|
||||
const detailInput = inputs.detail ?? null;
|
||||
@@ -744,8 +865,18 @@ export function chromeState(inputs: ChromeInputs): ChromeState {
|
||||
inputs.devices.length === 1 ? "Studio hardware →" : `Studio hardware · ${inputs.devices.length} →`,
|
||||
deviceDeclarations: inputs.devices,
|
||||
|
||||
chaptersVisible: views.length > 0,
|
||||
boardsVisible: boards.length > 0 && (inputs.boardsVisible ?? true),
|
||||
/**
|
||||
* Outside a building the chapter list stays in the document and out of
|
||||
* sight: the places list is the same journey said better, and the guards
|
||||
* that reach `#chapters .chapter` do it with a DOM `.click()`, which works
|
||||
* on a `hidden` element. Inside one it is the viewpoint list and is the
|
||||
* control.
|
||||
*/
|
||||
chaptersVisible: views.length > 0 && (inside || places.length === 0),
|
||||
views,
|
||||
placesVisible: !inside && places.length > 0,
|
||||
places,
|
||||
// On a phone the panel is a bottom sheet with a thumb-sized list in it; a
|
||||
// paragraph of description under that list pushes the door off the screen.
|
||||
blurbVisible: !phone && blurbText !== "",
|
||||
|
||||
+103
@@ -62,6 +62,15 @@ import type { ShortcutSheetHandles } from "./shortcuts.ts";
|
||||
export interface ChromeHandlers {
|
||||
onSelectBoard?(id: string): void;
|
||||
onSelectView?(id: string, index: number): void;
|
||||
/**
|
||||
* A rung of the places list, by its ladder key.
|
||||
*
|
||||
* By key and not by index, unlike `onSelectView` — a place is addressed by
|
||||
* identity because it may be on a board that is not the one on screen, and
|
||||
* because the list it lives in is ordered by stand-off rather than by the
|
||||
* order a pack happened to author its chapters in.
|
||||
*/
|
||||
onSelectPlace?(key: string): void;
|
||||
onEnter?(): void;
|
||||
onWalk?(): void;
|
||||
onFly?(): void;
|
||||
@@ -183,7 +192,12 @@ export function mountChrome(
|
||||
const officeInvite = find("office-invite");
|
||||
const officeNote = find("office-note");
|
||||
const chapterNav = find("chapters");
|
||||
const chapterSection = find("chapters-section");
|
||||
const boardSection = find("boards-section");
|
||||
const placeNav = find("places");
|
||||
const placeSection = find("places-section");
|
||||
const blurb = find("blurb");
|
||||
const blurbSection = find("blurb-section");
|
||||
|
||||
const tier = find("tier");
|
||||
const tierLabel = find("tier-label");
|
||||
@@ -225,6 +239,9 @@ export function mountChrome(
|
||||
let latest: ChromeState | null = null;
|
||||
let boardSignature = "";
|
||||
let viewSignature = "";
|
||||
let placeSignature = "";
|
||||
/** The rung that was last scrolled into view, so a steady camera does not scroll. */
|
||||
let scrolledPlaceKey = "";
|
||||
let deviceSignature = "";
|
||||
/**
|
||||
* Four more signatures, for the four rebuilds that are not lists of buttons.
|
||||
@@ -307,6 +324,13 @@ export function mountChrome(
|
||||
if (id !== null && id !== undefined && index >= 0) handlers.onSelectView?.(id, index);
|
||||
});
|
||||
|
||||
on(placeNav, "click", (event) => {
|
||||
const target = event.target;
|
||||
if (!(target !== null && typeof target === "object" && "closest" in target)) return;
|
||||
const key = (target as Element).closest("[data-place]")?.getAttribute("data-place");
|
||||
if (key !== null && key !== undefined) handlers.onSelectPlace?.(key);
|
||||
});
|
||||
|
||||
// ---- The touch action pad ----------------------------------------------
|
||||
//
|
||||
// Held buttons are bound on the pointer rather than on click, because a click
|
||||
@@ -517,6 +541,84 @@ export function mountChrome(
|
||||
setHidden(officeNote, !state.officeNoteVisible);
|
||||
setText(officeNote, state.officeNoteText);
|
||||
|
||||
setHidden(boardSection, !state.boardsVisible);
|
||||
|
||||
/**
|
||||
* The places list, rebuilt only when a row's identity or its highlight moves.
|
||||
*
|
||||
* The highlight is in the signature deliberately: it is what makes the list
|
||||
* an altimeter, and it changes as the camera descends rather than only when
|
||||
* somebody clicks. Everything else about a row is a pure function of the
|
||||
* ladder, which is built once at module load, so in the steady state this
|
||||
* comparison is a string equality and nothing else.
|
||||
*/
|
||||
setHidden(placeSection, !state.placesVisible);
|
||||
const nextPlaceSignature = state.places
|
||||
.map((place) => `${place.key}:${place.region ?? ""}:${place.key9 ?? ""}:${place.active}`)
|
||||
.join("|");
|
||||
if (placeNav !== null && nextPlaceSignature !== placeSignature) {
|
||||
placeSignature = nextPlaceSignature;
|
||||
const rows: Node[] = [];
|
||||
for (const place of state.places) {
|
||||
if (place.region !== null) {
|
||||
const heading = doc.createElement("p");
|
||||
heading.className = "places__region";
|
||||
heading.textContent = place.region;
|
||||
rows.push(heading);
|
||||
}
|
||||
const button = doc.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "place";
|
||||
// Two attributes, because the two questions are different: which rung
|
||||
// this is, and which board it would take you to. The second is what lets
|
||||
// a stylesheet or a test tell a cross-board rung from a local one
|
||||
// without parsing the first.
|
||||
button.setAttribute("data-place", place.key);
|
||||
button.setAttribute("data-place-board", place.board);
|
||||
button.setAttribute("aria-pressed", String(place.active));
|
||||
const name = doc.createElement("span");
|
||||
name.className = "place__name";
|
||||
name.textContent = place.label;
|
||||
const standoff = doc.createElement("span");
|
||||
standoff.className = "place__standoff";
|
||||
standoff.textContent = place.standoff;
|
||||
if (place.key9 !== null) {
|
||||
const key = doc.createElement("span");
|
||||
key.className = "num";
|
||||
key.textContent = place.key9;
|
||||
button.append(key);
|
||||
}
|
||||
button.append(name, standoff);
|
||||
rows.push(button);
|
||||
}
|
||||
placeNav.replaceChildren(...rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep the lit rung in view as the camera descends.
|
||||
*
|
||||
* Guarded on the key rather than run every apply, because `scrollIntoView`
|
||||
* on an element that is already in view still costs a layout — and this
|
||||
* runs from a once-a-second poll. `block: "nearest"` scrolls the list and
|
||||
* never the page: the panel is a column on a desktop and a bottom sheet on
|
||||
* a phone, and a rung dragging the whole document sideways is the failure
|
||||
* that arrangement is most prone to.
|
||||
*/
|
||||
const litPlace = state.places.find((place) => place.active) ?? null;
|
||||
if (placeNav !== null && litPlace !== null && litPlace.key !== scrolledPlaceKey) {
|
||||
scrolledPlaceKey = litPlace.key;
|
||||
// Walked rather than selected. A `[data-place="…"]` selector would need
|
||||
// `CSS.escape` for a key that is caller-supplied text, and `CSS` is a
|
||||
// browser global this module's tests do not have — the whole point of the
|
||||
// `FakeElement` harness in `ui/mount.test.ts` is that this file runs
|
||||
// without a DOM. Twenty-four children is a walk nobody can measure.
|
||||
const row = [...placeNav.children].find(
|
||||
(child) => child.getAttribute?.("data-place") === litPlace.key,
|
||||
);
|
||||
(row as HTMLElement | undefined)?.scrollIntoView?.({ block: "nearest" });
|
||||
}
|
||||
|
||||
setHidden(chapterSection, !state.chaptersVisible);
|
||||
setHidden(chapterNav, !state.chaptersVisible);
|
||||
const nextViewSignature = state.views
|
||||
.map((view) => `${view.id}:${view.number}:${view.label}:${view.active}`)
|
||||
@@ -541,6 +643,7 @@ export function mountChrome(
|
||||
}),
|
||||
);
|
||||
}
|
||||
setHidden(blurbSection, !state.blurbVisible);
|
||||
setHidden(blurb, !state.blurbVisible);
|
||||
setText(blurb, state.blurbText);
|
||||
|
||||
|
||||
+41
-5
@@ -110,6 +110,17 @@ export interface Shortcut {
|
||||
* `railHints` only ever picks from a fixed set of ids.
|
||||
*/
|
||||
rail?: string;
|
||||
/**
|
||||
* The rail word to use **inside a studio**, when the same binding means
|
||||
* something else there. Falls back to `rail`.
|
||||
*
|
||||
* One key, one row in the `?` sheet, two true glances. `ui/shortcuts.test.ts`
|
||||
* asserts that no key is bound to two different meanings — it is the check
|
||||
* that caught `G` being both the crow's glide and godmode's drawer — so a
|
||||
* second entry for the digits is not available and would be wrong anyway:
|
||||
* `1`-`9` is one binding whose list changes with where you are standing.
|
||||
*/
|
||||
railOffice?: string;
|
||||
section: ShortcutSection;
|
||||
scope: ShortcutScope;
|
||||
/**
|
||||
@@ -251,19 +262,38 @@ export const KEYMAP: readonly Shortcut[] = [
|
||||
{
|
||||
id: "board",
|
||||
keys: ["[", "]"],
|
||||
meaning: "Previous / next board — California, the Bay Area, Southern California",
|
||||
/*
|
||||
* It used to read "Previous / next board — California, the Bay Area,
|
||||
* Southern California", which stopped being a true sentence the moment
|
||||
* boards stopped being modes. There is one list now and it descends: the
|
||||
* state at 1,551 km of stand-off down to a street in Mission Bay at 3.9,
|
||||
* with the Southland and the Bay in between. Stepping it crosses from one
|
||||
* board to the next wherever the list does, which is the whole point.
|
||||
*/
|
||||
meaning: "Up / down the list of places — the state, the Southland, the Bay",
|
||||
section: "world",
|
||||
scope: "city",
|
||||
onScreen: "the board tabs in the left column",
|
||||
onScreen: "the Places list in the left column",
|
||||
},
|
||||
{
|
||||
id: "chapters",
|
||||
keys: ["1", "…", "9"],
|
||||
meaning: "Fly to a chapter of the tour, or to a viewpoint inside a studio",
|
||||
rail: "Chapters",
|
||||
meaning: "Fly to one of the first nine places, or to a viewpoint inside a studio",
|
||||
rail: "Places",
|
||||
/*
|
||||
* One binding, two true words.
|
||||
*
|
||||
* A second KEYMAP entry was the obvious way to say "Viewpoints" in a room
|
||||
* and `ui/shortcuts.test.ts` refused it, correctly: it asserts that no key
|
||||
* is bound to two different meanings, which is the check that caught `G`
|
||||
* being both the crow's glide and godmode's drawer. The keys here are the
|
||||
* *same* binding said in two places, so the row stays one row and only the
|
||||
* rail's glance changes.
|
||||
*/
|
||||
railOffice: "Viewpoints",
|
||||
section: "world",
|
||||
scope: "always",
|
||||
onScreen: "the numbered list in the left column",
|
||||
onScreen: "the numbered rows at the top of the Places list",
|
||||
},
|
||||
|
||||
// ---- The view -----------------------------------------------------------
|
||||
@@ -543,6 +573,12 @@ export function shortcutRows(inputs: ShortcutSheetInputs): readonly ShortcutRow[
|
||||
* at most two hints and they are about the mode you are actually in; everything
|
||||
* else is one press of `?` away.
|
||||
*/
|
||||
/** The word the rail prints for a shortcut, given where the viewer is standing. */
|
||||
export function railLabel(entry: Shortcut, inside: boolean): string {
|
||||
if (inside && entry.railOffice !== undefined) return entry.railOffice;
|
||||
return entry.rail ?? entry.meaning;
|
||||
}
|
||||
|
||||
export function railHints(mode: ControlMode, coarsePointer: boolean): readonly Shortcut[] {
|
||||
if (coarsePointer) return [];
|
||||
const wanted: readonly string[] =
|
||||
|
||||
Reference in New Issue
Block a user