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

+75 -101
View File
@@ -27,7 +27,6 @@ import {
} from './policy.js';
import { roundHeadingDegrees } from '../../data/headingDegrees.js';
import { entityRecord, readEntityRecord } from '../../data/entityRecords.js';
import { billboardState, setBillboard } from '../../data/billboardMirror.js';
export function createTracking({
flightState,
@@ -65,9 +64,9 @@ export function createTracking({
}
function _publishTrackedSelection(icao24, origin = 'programmatic') {
const bb = flightState._billboards.get(icao24);
const position = parts.icons._iconPosition(icao24);
const info = flightState.records.data.get(icao24);
if (!billboardState(bb)?.position || !info) return false;
if (!position || !info) return false;
if (flightState._trackedEntity)
entityRecord(flightState._trackedEntity).selectionOrigin = origin;
_emitAwarenessEvent('gev:awareness-subject-selected', {
@@ -78,7 +77,7 @@ export function createTracking({
// a callsign-less contact reached Context as its raw hex even once adsbdb
// had supplied a registration. Identity below stays `icao24`.
label: parts.queries._contactLabel(icao24, info),
position: Cesium.Cartesian3.clone(billboardState(bb).position),
position,
origin,
});
selectTrackedSubjectContext(_contextSubjectMetadata(icao24));
@@ -163,9 +162,12 @@ export function createTracking({
}
const previous = flightState._cockpitNearContacts;
const distancesSquared = [];
for (const [icao24, bb] of flightState._billboards) {
const position = billboardState(bb)?.position;
if (icao24 === flightState._trackedIcao || !position) continue;
const icons = flightState._icons;
const tau = parts.icons._displayTau();
for (let row = 0; row < icons.count; row++) {
const icao24 = icons.idAt(row);
if (icao24 === flightState._trackedIcao) continue;
const position = icons.position(row, tau, flightState._scratchCockpitPos);
distancesSquared.push([
icao24,
Cesium.Cartesian3.distanceSquared(
@@ -181,13 +183,10 @@ export function createTracking({
parts.rendering._modelKeepDistM(),
);
flightState._cockpitNearContacts = next;
let presentationChanged = false;
for (const [icao24, bb] of flightState._billboards) {
if (previous.has(icao24) === next.has(icao24)) continue;
parts.rendering._applyFleetBillboardPresentation(icao24, bb);
presentationChanged = true;
}
if (presentationChanged) flightState._lastCamPoseSig = '';
for (const icao24 of previous)
if (!next.has(icao24)) parts.icons._applyIconPresentation(icao24);
for (const icao24 of next)
if (!previous.has(icao24)) parts.icons._applyIconPresentation(icao24);
}
/** Switch all current and future ambient contacts between silhouettes and cockpit pips. */
@@ -205,9 +204,9 @@ export function createTracking({
if (flightState._modelCollection) flightState._modelCollection.show = true;
flightState._trail?.setVisible(!next);
if (flightState._trailHeadEntity) flightState._trailHeadEntity.show = !next;
for (const [icao24, bb] of flightState._billboards)
parts.rendering._applyFleetBillboardPresentation(icao24, bb);
flightState._lastCamPoseSig = '';
const icons = flightState._icons;
for (let row = 0; row < (icons?.count ?? 0); row++)
parts.icons._applyIconPresentation(icons.idAt(row));
flightState._lastFleetTickMs = 0;
}
@@ -319,8 +318,7 @@ export function createTracking({
if (!flightState._trackedIcao || !flightState._viewer) return;
const pos =
parts.motion._trackedDisplayCached() ||
billboardState(flightState._billboards.get(flightState._trackedIcao))
?.position;
parts.icons._iconPosition(flightState._trackedIcao);
if (!pos) return;
const projected = screenProjectedRotation(
flightState._viewer.scene,
@@ -639,30 +637,9 @@ export function createTracking({
const clearedIcao = flightState._trackedIcao;
clearFocusTarget('flights', clearedIcao);
// Restore the original billboard appearance. The rotation is re-seeded from
// the tracked entity's last rendered rotation and a rotation pass is forced
// (_lastCamPoseSig below): the fleet billboard otherwise reappears with the
// STALE screen rotation it had when tracking began — up to a full
// ROTATION_REFRESH_MS of a wrong (possibly reversed) nose on release.
if (flightState._billboards.has(flightState._trackedIcao)) {
const bb = flightState._billboards.get(flightState._trackedIcao);
setBillboard(bb, 'show', true);
setBillboard(bb, 'width', 20);
setBillboard(bb, 'height', 20);
// Ground/military-aware restore (a plane untracked while taxiing must come
// back muted-gray at ground scale, not white at full scale).
bb.color = parts.rendering._fleetBillboardColor(flightState._trackedIcao);
setBillboard(
bb,
'scale',
parts.rendering._fleetBillboardScale(
flightState._trackedIcao,
flightState.records.data.get(flightState._trackedIcao)?.klass,
),
);
setBillboard(bb, 'rotation', flightState._lastTrackedRotation);
}
flightState._lastCamPoseSig = ''; // force a fleet rotation pass on the next tick
// The nose the icon continues from (the shared _displayCourse entry), so
// release never flips it.
const trackedCourseDeg = flightState._displayCourse.get(clearedIcao);
// Stop tracking and remove the entity. skipViewerUntrack: when ANOTHER layer just grabbed the
// follow-camera, we tear down our own state but must NOT clear viewer.trackedEntity (the new owner
@@ -679,10 +656,14 @@ export function createTracking({
parts.rendering._releaseTrackedModel();
_resetTrackedSelectionState(); // the zoom band + load-failure budget belong to the selection we just dropped
flightState._trackedIcao = null;
parts.rendering._applyFleetBillboardPresentation(
clearedIcao,
flightState._billboards.get(clearedIcao),
);
// Hand the contact back to its icon only now: settling floors a grounded
// contact, and while it still read as tracked its tracked model owned the
// visual, so the floor would have stepped aside.
if (flightState._icons?.has(clearedIcao)) {
flightState._icons.setShown(flightState._icons.row(clearedIcao), true);
parts.icons._settleIcon(clearedIcao, { fromCourseDeg: trackedCourseDeg });
}
parts.icons._applyIconPresentation(clearedIcao);
clearTrackedSubjectContext('flights');
_emitAwarenessEvent('gev:awareness-subject-cleared', {
layerId: 'flights',
@@ -730,10 +711,7 @@ export function createTracking({
pending.generation !== flightState._trackingIntentGeneration
)
return false;
if (
!flightState._billboardCollection?.show ||
!flightState._billboards.has(pending.id)
)
if (!flightState._icons?.show || !flightState._icons.has(pending.id))
return false;
flightState._pendingTrackingRestore = null;
_trackFlight(pending.id, { origin: pending.origin });
@@ -837,42 +815,42 @@ export function createTracking({
// an already-loaded model would otherwise linger with the billboard hidden.
if (flightState._models.has(id) || flightState._modelPending.has(id))
parts.rendering._releaseModel(id);
const bb = flightState._billboards.get(id);
if (bb && id !== flightState._trackedIcao) setBillboard(bb, 'show', true); // horizon cull re-asserts next tick
const row = flightState._icons?.row(id) ?? -1;
if (row >= 0 && id !== flightState._trackedIcao)
flightState._icons.setShown(row, true);
if (id === flightState._trackedIcao) {
parts.rendering._releaseTrackedModel();
_syncTracked2dRotation();
}
}
const bb = flightState._billboards.get(id);
if (bb) parts.rendering._applyFleetBillboardPresentation(id, bb);
parts.icons._applyIconPresentation(id);
if (id === flightState._trackedIcao) {
_syncTrackedBillboardImage();
_updateTrackedLabelModel(id);
}
flightState._viewer?.scene?.requestRender?.();
return flightState._billboards.has(id) || id === flightState._trackedIcao;
return flightState._icons?.has(id) || id === flightState._trackedIcao;
}
/** Re-image every converted contact this layer owns (IR style flip). */
function _refreshTr3bForStyle() {
for (const id of tr3bConvertedIds()) {
if (flightState._billboards.has(id) || id === flightState._trackedIcao)
if (flightState._icons?.has(id) || id === flightState._trackedIcao)
_refreshTr3bContact(id);
}
}
/** Plausibility check anchored to the plane's billboard position (coarse is
/** Plausibility check anchored to the plane's icon position (coarse is
* fine here — this gates a LABEL, and it must not touch the tracked frame
* cache). Missing data → true (never hide what we can't judge). */
function _routeIsPlausible(icao24, route) {
const info = flightState.records.data.get(icao24);
const bb = flightState._billboards.get(icao24);
if (!info || !bb || !billboardState(bb).position) return true;
const position = parts.icons._iconPosition(icao24);
if (!info || !position) return true;
const carto = Cesium.Cartographic.fromCartesian(
billboardState(bb).position,
position,
Cesium.Ellipsoid.WGS84,
flightState._scratchCarto,
);
@@ -907,29 +885,42 @@ export function createTracking({
function _trackFlight(icao24, { origin = 'programmatic' } = {}) {
_clearTracking(false, { origin }); // switching planes — the new follow-camera takes over
const bb = flightState._billboards.get(icao24);
const icons = flightState._icons;
const row = icons?.row(icao24) ?? -1;
const info = flightState.records.data.get(icao24);
if (!bb || !info) return;
if (row < 0 || !info) return;
// The tracked limiter continues from the nose the icon was drawn with, and
// the entity starts with the rotation the icon had on screen.
const tau = parts.icons._displayTau();
const iconPosition = icons.position(row, tau);
flightState._displayCourse.set(icao24, icons.course(row, tau));
flightState._trackedIcao = icao24;
_resetTrackedSelectionState(); // fresh selection: enter at the ENTER ceiling, full load-retry budget
flightState._cachedDRFrame = -1;
flightState._lastTrackedRotation = billboardState(bb).rotation || 0;
flightState._lastTrackedRotation =
screenProjectedRotation(
flightState._viewer.scene,
iconPosition,
icons.course(row, tau),
0,
) ?? 0;
// Drop any fleet 3D model for this aircraft — the tracked entity now owns its visual (its
// own billboard + model graphic), and the fleet tick skips the tracked icao, so a leftover
// fleet model would be orphaned + double-rendered.
parts.rendering._releaseModel(icao24);
// Hide the billboard — the tracked entity replaces it visually
setBillboard(bb, 'show', false);
// Hide the icon — the tracked entity replaces it visually
icons.setShown(row, false);
// Helper: smoothed, per-frame-cached tracked position (see _trackedDisplayPosition —
// one computation shared by the position/alignedAxis/rotation/trail-head callbacks,
// with discontinuity reconciliation). Falls back to the last billboard position when
// with discontinuity reconciliation). Falls back to the icon's position when
// the aircraft has no fix.
const getTrackedPosition = () =>
parts.motion._trackedDisplayPosition(icao24) ||
billboardState(bb).position;
parts.icons._iconPosition(icao24) ||
iconPosition;
// Dead-reckoning position property — smooth continuous motion between API updates.
const positionProperty = new Cesium.CallbackProperty(() => {
@@ -1106,23 +1097,19 @@ export function createTracking({
*/
function _onMilitaryActiveChange(active) {
if (!flightState._viewer || !flightState._billboardCollection) return;
const icons = flightState._icons;
if (!flightState._viewer || !icons) return;
if (active) {
for (const [icao24, bb] of flightState._billboards) {
if (!isMilitaryIcao(icao24) || icao24 === flightState._trackedIcao)
continue;
flightState._billboardCollection.remove(bb);
flightState._billboards.delete(icao24);
parts.rendering._releaseModel(icao24); // military-suppression: drop any 3D model too
flightState.records.data.delete(icao24);
flightState._cullPositions.delete(icao24);
flightState._positionHistory.delete(icao24);
flightState._displayCourse.delete(icao24);
flightState._groundSnap.forget(icao24);
flightState.records.missingPolls.delete(icao24);
const suppressed = [];
for (let row = 0; row < icons.count; row++) {
const icao24 = icons.idAt(row);
if (isMilitaryIcao(icao24) && icao24 !== flightState._trackedIcao)
suppressed.push(icao24);
}
flightState.feed._count = flightState._billboards.size;
} else if (flightState._billboardCollection.show) {
// Military-suppression: drop each duplicate with any 3D model too.
for (const icao24 of suppressed) parts.icons._forgetContact(icao24);
flightState.feed._count = icons.count;
} else if (icons.show) {
// Fire-and-forget refresh; only while the layer is actually enabled.
void flightsLayer.update(flightState._viewer);
}
@@ -1212,25 +1199,12 @@ export function createTracking({
return;
}
// For BillboardCollection picks, the billboard may be at picked.primitive or picked.id
const billboard = picked.primitive;
if (
billboard &&
billboard.id &&
flightState._billboards.has(billboard.id)
) {
// Icon picks carry the icao on picked.id; models carry it on the primitive.
const pickedIcao =
typeof picked.id === 'string' ? picked.id : picked.primitive?.id;
if (pickedIcao && flightState._icons?.has(pickedIcao)) {
_cancelPendingTrackingRestore();
_trackFlight(billboard.id, { origin: 'user' });
return;
}
// Some CesiumJS versions surface the id as a string on picked.id instead
if (
picked.id &&
typeof picked.id === 'string' &&
flightState._billboards.has(picked.id)
) {
_cancelPendingTrackingRestore();
_trackFlight(picked.id, { origin: 'user' });
_trackFlight(pickedIcao, { origin: 'user' });
return;
}
}