mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
feat(transit): live public-transit vehicles from open GTFS-Realtime feeds (#587)
Supersedes #218 by @spcpza, ported onto the current component layout with fixes from review. Verified before merge: format, package boundaries, unit suite, build, and the browser tracking suite; a browser harness for the change where one applies; adversarial review applied. Contributor: @spcpza. His original commit is the base of this branch, and his own re-port onto main (2026-09-15, `5b69011`) was consulted while finishing the height work. That port reads every vehicle's surface from the app's shared ground-floor system (`cachedGroundFloor` / `warmGroundFloor` / `GROUND_FLOOR_LIFT_M`) rather than sampling the scene per layer, keeps a vehicle hidden until its cell answers, warms a bounded batch per poll on a timer instead of per frame, and renders at the ellipsoid above the altitude gate. That is the sounder primitive — one floor system for the app, with the rooftop-versus-street question already settled against a datum-correct DEM prior — and this branch's height work was rebuilt on it, replacing a bespoke cell cache, ground prior and rooftop rule written here. Credit for that direction is his. Future work (not in this PR), both written up in docs/CURRENT-STATE.md: - Readable route names. The realtime feeds carry only `route_id`; `route_short_name` / `route_long_name` live in each operator's static GTFS `routes.txt`, and headsigns in `trips.txt`. Doing it properly wants a server-side metadata loader beside the transit proxy with fixed registered static sources, bounded indexes built once and persisted, a slow conditional refresh, and a versioned route dictionary the browser caches. Shipped here: ids are never rewritten, and a cut one carries an ellipsis instead of reading as a typo. - Below-ground rendering. Subway vehicles are drawn on the surface directly above themselves, because the feeds carry no depth and a train nobody can see is not worth drawing; the card says so plainly. Real treatment wants OSM tunnel geometry per city and a ghosted sprite tethered to the surface. The owner recorded it and left it. Round four and after (2026-09-15). The owner tested round three under FLIR and NVG, and then asked for the design to be taken further: elegant in performance, beautiful on camera, trails with a cache for public transport, Cesium-native, and a core other moving layers can adopt. Codex Astra reviewed the plan (it confirmed the speed fault: a glide started from the drawn position at receipt time but spanned the gap between report times, so with MBTA reporting every ~10 s against a 15 s poll every second glide ran at 1.5x; it rejected a queued-segment patch), then wrote the design, then implemented it in commit-sized passes with adversarial review between them and real-browser harness runs by the integrator. What this PR now contains beyond the contributor's original port: - Delayed playback in a contact-agnostic core (`src/data/contactPlayback.js`): each vehicle keeps a typed, bounded fix history and a display clock that runs at one second per second through it, a feed-derived lag behind real time, holding at its newest fix rather than extrapolating and never sprinting to catch up. Marker, course, motion word, card and trail all read the same displayed sample. The clock has an explicit time-offset and seek API so a rewind is a later feature, not a rewrite; flights and vessels are untouched. - A selected-vehicle trail (`src/data/contactTrailRenderer.js`, `src/layers/transit/trails.js`): the retained history drawn with batched Cesium primitives, clipped at display time so the head is exactly the sprite, faded by age, in the mode colour (white under sensor presets), on the same surface path as the marker. - Bounded proxy-side history (`server/providers/transitHistory.js`): fifteen minutes and at most 128 fixes per vehicle with hard byte ceilings, MBTA only for now (opt-in per feed), served by a small endpoint that never fetches upstream, so a selected trail survives a browser reload while the server keeps running. - Scene work bounded to what is visible and moving, an occluder, cached DETECT candidates, holds on the render loop only while something visible moves. - Sensor presets: white-hot haloed sprites under NVG/FLIR/noir (black-hot inverts), saturated mode colours under CRT, per-mode bracket tiers in every theme, the selected card keeping its mode colour. - A discriminating browser harness (`scripts/qa-transit.mjs`) that samples postRender frames, reads the real card anchor, and measures fleet budgets at 800 and 3,000 vehicles. Not built, recorded as follow-ups: curated route display names (lowest priority per the owner), fleet-wide tails, route snapping, a rewind UI, adoption of the playback core by flights and vessels. Verified at merge (2026-09-15 morning): unit suite 3,896 passing, build clean, format and boundary gates clean, tracking regression 109/109, browser harness keyless 200 pass / 0 fail (13 sensor checks unexercised because the live view offered fewer than six isolated sprites; every judged sprite passed), keyed on Google 3D tiles 198 pass with the per-frame allocation gate as the only failure. Follow-ups recorded: the keyed build's playback sampler still allocates per frame (CPU and frame time stay within budget; the 3,000-vehicle metro view sits at a 27.6 ms frame interval against a 25 ms budget), the shared detection overlay's per-paint allocation, friendlier route names, fleet-wide tails, a rewind UI, and adopting the playback core for vessels and flights. Co-authored-by: spcpza <[email protected]>
This commit is contained in:
1 parent
1ad565c8af
commit
76c20be277
78 files changed
+19842
-186
No files matched your search
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @file Preset-aware transit sprite styling — pure lookup tables mapping the
|
||||
* active post-FX style to a sprite treatment the shaders cannot destroy, and
|
||||
* the detection tier that carries each mode's colour above them.
|
||||
*
|
||||
* Why: transit sprites are in-scene billboards, so they pass THROUGH the
|
||||
* post-FX chain. NVG and FLIR reduce the scene to luminance, and the mode
|
||||
* palette's luma is middling — a green bus, a red metro and an amber tram all
|
||||
* collapse to the same dim grey, on a road NVG's auto-gain has pushed to
|
||||
* white. The owner's Boston test: "you can barely see these guys".
|
||||
*
|
||||
* Encoding per profile, the traffic-dot precedent applied to a glyph:
|
||||
* - `mono` (surveillance/NVG, thermal/FLIR, noir, cockpit nvg/thermal): the
|
||||
* sprite is WHITE — the hottest end of grayscale FLIR and of the Ironbow
|
||||
* ramp, and the brightest phosphor under NVG — drawn larger, with a dark
|
||||
* halo sized in SCREEN pixels so it keeps local contrast on a bright road
|
||||
* through any luma mapping. Black-hot FLIR inverts it, deliberately: a
|
||||
* black sprite with a light ring is what a hot object looks like there.
|
||||
* - `crt` (retro): saturated per-mode colours that survive posterisation,
|
||||
* a size boost to out-shout the pixel grid, and a thinner halo.
|
||||
* - `normal` (normal/anime/snow/unknown): every lookup returns the shipped
|
||||
* value — mode colour, shipped size, hairline edge only.
|
||||
*
|
||||
* Brackets are a different matter. The detection canvas composites ABOVE the
|
||||
* post-FX chain, so a tier colour is literal screen RGB in every preset: the
|
||||
* brackets carry the mode colour the sprites can no longer encode, the way
|
||||
* traffic's brackets carry congestion. Tier colours per theme live in
|
||||
* `src/overlays/worldOverlayTokens.js`.
|
||||
*
|
||||
* Cesium-free so the tables are unit-testable; the layer maps them to Cesium
|
||||
* colours and billboard sizes at spawn and restyle time.
|
||||
*
|
||||
* @module data/transitPresetStyle
|
||||
*/
|
||||
|
||||
/** @const {Object<string,'mono'|'crt'>} Style name → non-normal profile. */
|
||||
const PROFILE_BY_STYLE = Object.freeze({
|
||||
surveillance: 'mono', // NVG — P43 phosphor × luma
|
||||
thermal: 'mono', // FLIR — grayscale/Ironbow × luma
|
||||
noir: 'mono', // full desaturation
|
||||
nvg: 'mono', // cockpit vision names its modes directly
|
||||
retro: 'crt', // CRT — hue survives, small glyphs don't
|
||||
});
|
||||
|
||||
/**
|
||||
* Per-profile sprite treatment. `rgba` is [r,g,b] 0–255 + alpha 0–1;
|
||||
* `scale` multiplies the shipped billboard size; `outlinePx` is the dark
|
||||
* halo's width in FINAL SCREEN PIXELS, which is the only unit that means
|
||||
* anything for a glyph rendered at eighteen pixels — the shipped 1.5-unit
|
||||
* hairline in a 96-unit box is 0.28 px on screen, and vanishes.
|
||||
*/
|
||||
const SPRITE_STYLE = Object.freeze({
|
||||
mono: Object.freeze({
|
||||
rgba: Object.freeze([255, 255, 255, 1]),
|
||||
scale: 1.5,
|
||||
outlinePx: 3,
|
||||
}),
|
||||
crt: Object.freeze({
|
||||
scale: 1.3,
|
||||
outlinePx: 1.25,
|
||||
rgbaByMode: Object.freeze({
|
||||
bus: Object.freeze([0, 255, 102, 1]),
|
||||
tram: Object.freeze([255, 179, 0, 1]),
|
||||
subway: Object.freeze([255, 59, 48, 1]),
|
||||
rail: Object.freeze([215, 139, 255, 1]),
|
||||
ferry: Object.freeze([58, 208, 255, 1]),
|
||||
unknown: Object.freeze([255, 255, 255, 1]),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
/** Modes with a bracket tier of their own. */
|
||||
const TIER_MODES = Object.freeze([
|
||||
'bus',
|
||||
'tram',
|
||||
'subway',
|
||||
'rail',
|
||||
'ferry',
|
||||
'unknown',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Classify a style name into a transit styling profile.
|
||||
* @param {string|null|undefined} styleName - Active style (e.g. 'thermal').
|
||||
* @returns {'normal'|'mono'|'crt'} Styling profile; unknown → 'normal'.
|
||||
*/
|
||||
export function transitStyleProfile(styleName) {
|
||||
return PROFILE_BY_STYLE[styleName] || 'normal';
|
||||
}
|
||||
|
||||
/**
|
||||
* Preset sprite colour, or null to keep the shipped mode colour.
|
||||
* @param {string|null|undefined} styleName
|
||||
* @param {string} mode Transit mode.
|
||||
* @returns {number[]|null} [r,g,b,a] with rgb 0–255, alpha 0–1, or null.
|
||||
*/
|
||||
export function presetSpriteRgba(styleName, mode) {
|
||||
const profile = transitStyleProfile(styleName);
|
||||
if (profile === 'mono') return SPRITE_STYLE.mono.rgba;
|
||||
if (profile === 'crt') {
|
||||
return (
|
||||
SPRITE_STYLE.crt.rgbaByMode[mode] || SPRITE_STYLE.crt.rgbaByMode.unknown
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplier a preset applies to the shipped billboard size.
|
||||
* @param {string|null|undefined} styleName
|
||||
* @returns {number} 1 under the normal profile.
|
||||
*/
|
||||
export function presetSpriteScale(styleName, selected = false) {
|
||||
if (transitStyleProfile(styleName) === 'mono')
|
||||
return selected ? 36 / 30 : 30 / 20;
|
||||
return SPRITE_STYLE[transitStyleProfile(styleName)]?.scale ?? 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dark-halo width in final screen pixels, or 0 for the shipped hairline only.
|
||||
* @param {string|null|undefined} styleName
|
||||
* @returns {number}
|
||||
*/
|
||||
export function presetSpriteOutlinePx(styleName, selected = false) {
|
||||
return (
|
||||
SPRITE_STYLE[transitStyleProfile(styleName)]?.outlinePx ??
|
||||
(selected ? 1.5 : 1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detection-overlay tier key for a transit mode. Every theme's `tiers`
|
||||
* table carries these six, so the bracket colour is per mode in every
|
||||
* preset. Unlike traffic, transit sets its tier keyless as well: the feeds
|
||||
* are keyless, and there is no separate keyless experience to keep
|
||||
* byte-identical.
|
||||
* @param {string} mode
|
||||
* @returns {string}
|
||||
*/
|
||||
export function transitModeTier(mode) {
|
||||
return `transit_${TIER_MODES.includes(mode) ? mode : 'unknown'}`;
|
||||
}
|
||||
|
||||
/** The tier keys this module can produce, for the tables that must carry them. */
|
||||
export const TRANSIT_TIER_KEYS = Object.freeze(
|
||||
TIER_MODES.map((mode) => `transit_${mode}`),
|
||||
);
|
||||
Reference in new issue
Block a user