Draw civil flights from an icon set moved on the GPU

Every flight is now a row in the layer's icon set. Its motion segment
follows the same regime `_deadReckon` picks (interpolate between fixes,
warm up backward from the oldest, coast forward from the newest), and
one shared `_motionRegime` makes that choice for both. The shader moves
every untracked contact between polls, so the 12 Hz fleet tick no
longer touches each billboard. It now only re-plans expired rows,
floors grounded contacts, advances focus while needed, and runs the 3D
model regime.

Grounded contacts the floor lifts are pinned to a hold at the floored
position. Their nose glides on the GPU. Contacts within 50 km re-floor
every tick, and farther ones take turns about once a second. Low
contacts are judged for the horizon at no lower than 12 m above the
ellipsoid, as before. Below hover speed a contact's nose holds. A row
whose fleet model is drawn keeps its focus updated, because the model
reads it. Untracking re-plans and re-floors the icon from the tracked
course.

On the same views with about 6,700 OpenSky flights, frame gaps at p95
drop from 28-40 ms to 17 ms, and the fleet tick from 16-37 ms to about
2 ms at most.
This commit is contained in:
Sameh Khamis committed 2026-11-03 19:40:39 -08:00
1 parent 37dd4058c1
commit fa3a3a3bca
33 files changed
+1598 -986

No files matched your search

+68 -91
View File
@@ -16,7 +16,6 @@ import {
FLEET_DR_INTERVAL_MS,
} from './policy.js';
import { emergencyBroadcastPhrase } from '../../data/aircraftEmergency.js';
import { billboardState, setBillboard } from '../../data/billboardMirror.js';
import { modelState } from '../../data/modelMirror.js';
export function createQueries({
@@ -99,7 +98,7 @@ export function createQueries({
* airframe itself and cannot go stale the way a leg can.
*
* This is a DISPLAY string only. Identity everywhere in this layer is `icao24`
* (the `_billboards`/`_flightData` key, the `sourceId` detection declutter hashes,
* (the `_icons`/`_flightData` key, the `sourceId` detection declutter hashes,
* the `id` that trackById/Context cohorts resolve) — never the label.
* @param {string} icao24 - ICAO 24-bit transponder address (the identity key).
* @param {Object|null|undefined} info - `_flightData` record for this aircraft.
@@ -134,10 +133,8 @@ export function createQueries({
// every visual consumer reads the floored per-frame cache instead (see
// `_trackedDisplayPosition`). If that ever changes, floor this path too.
const info = flightState.records.data.get(icao24);
const bb = flightState._billboards.get(icao24);
const basePos =
parts.motion._deadReckon(icao24) ||
(bb ? billboardState(bb).position : null);
parts.motion._deadReckon(icao24) || parts.icons._iconPosition(icao24);
if (!basePos) return null;
const displayed = displayedKinematics({
derivedSpeedMps: flightState._drSpeedMps,
@@ -334,14 +331,8 @@ export function createQueries({
if (!flightState._models3dEnabled) {
parts.rendering._releaseModels();
parts.tracking._syncTracked2dRotation();
// Restore fleet billboards (the horizon-cull pass re-asserts next tick), but NEVER the
// tracked plane's own fleet billboard — its tracked entity is the visual, so re-showing it
// here would double-image the tracked plane when 3D is turned off mid-track.
if (flightState._billboardCollection)
for (const [icao, bb] of flightState._billboards) {
if (icao !== flightState._trackedIcao)
setBillboard(bb, 'show', true);
}
// (Releasing the models handed each fleet contact back to its icon, never
// the tracked plane's own — its tracked entity is the visual.)
}
}
if (
@@ -424,42 +415,34 @@ export function createQueries({
* @returns {Array<{position: Cesium.Cartesian3, id: string, type: string, skipLabel: boolean}>}
*/
getDetectableObjects(options = {}) {
if (
!flightState._billboardCollection ||
!flightState._billboardCollection.show
)
return [];
// Compute a stride that evenly samples the billboard map.
const icons = flightState._icons;
if (!icons || !icons.show) return [];
// Compute a stride that evenly samples the icon rows.
// seed shifts the starting offset so successive calls can sample
// different aircraft without shuffling the underlying Map order.
// different aircraft without reordering the rows.
const maxCount = Number.isFinite(options.maxCount)
? Math.max(1, Math.floor(options.maxCount))
: flightState._billboards.size;
: icons.count;
const seed = Number.isFinite(options.seed) ? Math.floor(options.seed) : 0;
const stride = Math.max(
1,
Math.ceil(flightState._billboards.size / maxCount),
);
const stride = Math.max(1, Math.ceil(icons.count / maxCount));
const start = seed % stride;
const occluder = parts.icons._occluder();
const tau = parts.icons._displayTau();
const result = [];
let idx = 0;
for (const [icao24, bb] of flightState._billboards) {
const shouldTake = (idx - start) % stride === 0;
idx++;
if (!shouldTake) continue;
for (let row = start; row < icons.count; row += stride) {
const icao24 = icons.idAt(row);
if (
flightState._cockpitContactMode &&
icao24.toLowerCase() === flightState._cockpitSubjectId
)
continue;
const isTracked = icao24 === flightState._trackedIcao;
// Keep planes rendered as a 3D model (billboard hidden) so the detection box
// doesn't vanish on the 2D→3D handoff; bb.position stays current while hidden.
// Keep planes rendered as a 3D model (icon hidden) so the detection box
// doesn't vanish on the 2D→3D handoff.
const model = flightState._models.get(icao24) ?? null;
const modelOwnsVisual = parts.rendering._modelOwnsVisual(icao24, model);
if (!isTracked && !billboardState(bb).show && !modelOwnsVisual)
continue;
if (!isTracked && !icons.shown(row) && !modelOwnsVisual) continue;
const info = flightState.records.data.get(icao24);
let object = flightState._detectionObjects.get(icao24);
if (!object) {
@@ -467,21 +450,24 @@ export function createQueries({
sourceId: icao24,
type: 'AIR',
_weldPos: new Cesium.Cartesian3(),
_iconPos: new Cesium.Cartesian3(),
};
flightState._detectionObjects.set(icao24, object);
}
// WELD: anchor to whatever actually owns the visual. A model-owned contact is
// read straight off the translation the fleet tick already wrote into its
// modelMatrix, so bracket and label sit on the aircraft you can see instead of
// on the buried billboard position, which for a grounded plane is ~100 m below
// on the buried icon position, which for a grounded plane is ~100 m below
// and rises only as the coarse ground-floor cell warms. Zero extra sampling and
// no `_modelDisplayPosition` call from postRender. Sprite-owned contacts keep
// `bb.position` — sprite and bracket are co-located there, so association holds.
// no `_modelDisplayPosition` call from postRender. Icon-owned contacts keep
// the drawn icon position — icon and bracket are co-located there.
const spec = modelOwnsVisual
? parts.rendering._modelSpec(info?.klass)
: null;
const pos = isTracked
? parts.motion._trackedVisualCached() || billboardState(bb).position
? parts.motion._trackedVisualCached() ||
icons.position(row, tau, object._iconPos)
: modelOwnsVisual
? modelVisualAnchor(
modelState(model).modelMatrix,
@@ -491,8 +477,15 @@ export function createQueries({
: spec.scale,
object._weldPos || (object._weldPos = new Cesium.Cartesian3()),
)
: billboardState(bb).position;
if (!pos) continue;
: icons.position(row, tau, object._iconPos);
// An icon past the horizon is not drawn, so it is not detectable.
if (
!pos ||
(!isTracked &&
!modelOwnsVisual &&
!parts.icons._aboveHorizon(row, pos, occluder))
)
continue;
object.position = pos;
object.skipLabel = isTracked;
// Card text only — declutter/cohort identity is `object.sourceId` (icao24).
@@ -517,13 +510,9 @@ export function createQueries({
result.push(object);
if (result.length >= maxCount) break;
}
if (
flightState._detectionObjects.size >
flightState._billboards.size + 512
) {
if (flightState._detectionObjects.size > icons.count + 512) {
for (const icao24 of flightState._detectionObjects.keys()) {
if (!flightState._billboards.has(icao24))
flightState._detectionObjects.delete(icao24);
if (!icons.has(icao24)) flightState._detectionObjects.delete(icao24);
}
}
return result;
@@ -583,12 +572,11 @@ export function createQueries({
* @returns {Array<{id: string, icao24: string, callsign: string|null, position: Cesium.Cartesian3, distance: number, aircraftClass: string|null, altitudeM: number|null, velocityMps: number|null, track: number|null}>}
*/
getNearby(center, range, maxCount = 50, { includeHidden = false } = {}) {
if (
!center ||
!flightState._billboardCollection ||
!flightState._billboardCollection.show
)
return [];
const icons = flightState._icons;
if (!center || !icons || !icons.show) return [];
const occluder = parts.icons._occluder();
const tau = parts.icons._displayTau();
const scratch = flightState._scratchNearbyPos;
const limit = Number.isFinite(maxCount)
? Math.max(1, Math.floor(maxCount))
@@ -598,28 +586,30 @@ export function createQueries({
const nearby = [];
for (const [icao24, bb] of flightState._billboards) {
for (let row = 0; row < icons.count; row++) {
const icao24 = icons.idAt(row);
const isTracked = icao24 === flightState._trackedIcao;
// Keep planes rendered as a 3D model (billboard hidden) so proximity counts
// don't drop to zero on the 2D→3D handoff; bb.position stays current while hidden.
const trackedPos = isTracked
? parts.motion._trackedDisplayCached()
: null; // cached, no recompute (anti-jitter)
const drawn = trackedPos || icons.position(row, tau, scratch);
// Keep planes rendered as a 3D model (icon hidden) so proximity counts
// don't drop to zero on the 2D→3D handoff.
if (
!aircraftIncludedInNearby({
isTracked,
billboardShown: billboardState(bb).show,
billboardShown:
icons.shown(row) &&
parts.icons._aboveHorizon(row, drawn, occluder),
modelRendering: parts.rendering._modelOwnsVisual(icao24),
includeHidden,
})
)
continue;
const trackedPos = isTracked
? parts.motion._trackedDisplayCached()
: null; // cached, no recompute (anti-jitter)
const pos = trackedPos || billboardState(bb).position;
if (!pos) continue;
const distance = Cesium.Cartesian3.distance(center, pos);
const distance = Cesium.Cartesian3.distance(center, drawn);
if (distance > maxRange) continue;
const pos = trackedPos || Cesium.Cartesian3.clone(drawn);
const info = flightState.records.data.get(icao24);
const callsign = info?.callsign?.trim() || null;
@@ -651,8 +641,8 @@ export function createQueries({
/**
* Return id/label/position for up to maxCount currently rendered aircraft.
* Cheap snapshot for voice-tool framing — billboard positions only, no
* dead reckoning and no cloning.
* Cheap snapshot for voice-tool framing — drawn icon positions, no
* extra dead reckoning.
* @param {number} [maxCount=500] - Maximum number of entries to return.
* @returns {Array<{id: string, label: string, position: Cesium.Cartesian3, latitude: number, longitude: number, altitudeM: number}>}
*/
@@ -671,34 +661,25 @@ export function createQueries({
* holds no data and therefore cannot answer.
*/
hasContact(icao24) {
if (
!flightState._billboardCollection ||
!flightState._billboardCollection.show ||
flightState._billboards.size === 0
)
return null;
const icons = flightState._icons;
if (!icons || !icons.show || icons.count === 0) return null;
if (!icao24) return false;
const id = String(icao24).trim();
return (
flightState._billboards.has(id) ||
flightState._billboards.has(id.toLowerCase())
);
return icons.has(id) || icons.has(id.toLowerCase());
},
getAllPositions(maxCount = 500) {
if (
!flightState._billboardCollection ||
flightState._billboards.size === 0
)
return [];
const icons = flightState._icons;
if (!icons || icons.count === 0) return [];
const limit = Number.isFinite(maxCount)
? Math.max(1, Math.floor(maxCount))
: 500;
const tau = parts.icons._displayTau();
const result = [];
for (const [icao24, bb] of flightState._billboards) {
const pos = billboardState(bb).position;
if (!pos) continue;
for (let row = 0; row < icons.count; row++) {
const icao24 = icons.idAt(row);
const pos = icons.position(row, tau);
const carto = Cesium.Cartographic.fromCartesian(
pos,
Cesium.Ellipsoid.WGS84,
@@ -741,11 +722,7 @@ export function createQueries({
* @returns {Array<Object>} See mapAnalystRecord for the record shape.
*/
getAnalystRecords(maxCount = 2000) {
if (
!flightState._billboardCollection ||
!flightState._billboardCollection.show ||
flightState.records.data.size === 0
)
if (!flightState._icons?.show || flightState.records.data.size === 0)
return [];
const limit = Number.isFinite(maxCount)
? Math.max(1, Math.floor(maxCount))
@@ -773,8 +750,8 @@ export function createQueries({
trackById(icao24, { origin = 'programmatic' } = {}) {
if (!icao24) return false;
let id = String(icao24).trim();
if (!flightState._billboards.has(id)) id = id.toLowerCase();
if (!flightState._billboards.has(id)) return false;
if (!flightState._icons?.has(id)) id = id.toLowerCase();
if (!flightState._icons?.has(id)) return false;
if (parts.tracking._isExplicitTrackingOrigin(origin))
parts.tracking._cancelPendingTrackingRestore();
if (flightState._trackedIcao === id)
@@ -844,7 +821,7 @@ export function createQueries({
)
return false;
let id = String(icao24).trim();
if (!flightState._billboards.has(id)) id = id.toLowerCase();
if (!flightState._icons?.has(id)) id = id.toLowerCase();
if (
id !== flightState._trackedIcao ||
!flightState._viewer.entities?.contains?.(flightState._trackedEntity) ||