Draw military flights from the shared GPU icon set

The flights icon planning and presentation move into
`createAircraftIcons` (src/data/aircraftIconLayer.js), and the motion
regime both layers dead-reckon from into src/data/aircraftMotionRegime.js.
Flights keeps only its grounded-floor pass on top.

Military now draws every contact as a row of that icon set, like
flights: the billboards, the cull positions and the rotation-pass
signature go. Tracking hides the row and untracking re-plans it from
the tracked course. Queries read the drawn row position and judge the
horizon as the shader does. Snapshots that arrive before init or after
destroy are ignored, and per-contact lookups find no contact then
instead of throwing.

With about 120 live military contacts, preRender p95 drops from
0.7-0.8 ms to 0.2 ms on the same views. Render time and frame gaps are
unchanged or slightly lower.
This commit is contained in:
Sameh Khamis committed 2026-11-03 20:30:43 -08:00
1 parent fa3a3a3bca
commit b027bde6ad
33 files changed
+1256 -1376

No files matched your search

+22 -113
View File
@@ -2,9 +2,6 @@ import * as Cesium from 'cesium';
import {
COURSE_HOLD_SPEED_MPS,
lerpAngleDeg,
speedRamp,
courseBetweenCartesians,
staleCoastLimitSeconds,
arcOffsetEnu,
courseSlewCapDps,
limitCourseStep,
@@ -37,20 +34,15 @@ import {
} from './policy.js';
import { modelState } from '../../data/modelMirror.js';
import { readEntityRecord } from '../../data/entityRecords.js';
import {
aircraftMotionRegime,
createMotionRegime,
fixSpeedMps,
fixTrackDeg,
} from '../../data/aircraftMotionRegime.js';
/** A fix's own ground speed, else the record's. */
function fixSpeedMps(fix, info) {
return Number.isFinite(fix.velocity)
? fix.velocity
: (info && info.velocity) || 0;
}
/** A fix's own track, else the record's. */
function fixTrackDeg(fix, info) {
return Number.isFinite(fix.track)
? fix.track
: (info && info.true_track) || 0;
}
/** Where a flights record carries its reported speed and track. */
const RECORD_FIELDS = { speed: 'velocity', track: 'true_track' };
export function createMotion({
flightState,
@@ -80,22 +72,7 @@ export function createMotion({
// the local frame even when the existing Cartesian is mutated in place.
const fixFrames = new WeakMap();
/** `_motionRegime`'s reused result. */
const regime = {
kind: 'fix',
a: null,
b: null,
span: 0,
speed: 0,
trackFrom: 0,
trackTo: 0,
chordCourse: null,
blend: 0,
fix: null,
heading: 0,
turnRateDps: 0,
minDt: 0,
maxDt: 0,
};
const regime = createMotionRegime();
// Round 5: the old `_warmGroundedAircraftSurfaceCache` (global exact-5-decimal
// warm for every grounded contact on Earth) is GONE. Parked-aircraft GPS
@@ -221,86 +198,18 @@ export function createMotion({
/**
* Which motion a contact's history gives at `renderTime` — the one choice
* `_deadReckon` (CPU) and the icon planner (GPU segment) both draw from.
*
* - `between`: interpolate the bracketing pair `a`→`b`, no extrapolation
* error and no snap-back. The course of the DISPLAYED motion blends the
* time-interpolated reported track toward the chord by `blend`: the chord
* is only trustworthy when the segment covers real ground (at hover its
* direction is GPS jitter; on a slow tight turn it STEPS the whole
* per-segment turn at each boundary), and helicopters never use it
* (rotorcraft chords are noise-dominated at their typical speeds).
* - `fix`: extrapolate `fix` by the elapsed time clamped to [minDt, maxDt].
* Warm-up (renderTime predates ALL history: freshly seen or just tracked,
* before RENDER_DELAY_SEC of history exists) runs the OLDEST fix BACKWARD,
* preserving the 30s-behind invariant, so as history fills the icon glides
* FORWARD into interpolation with no freeze and no backward snap (holding
* the oldest fix froze the icon; extrapolating the newest to wall-clock
* made it jump back a poll interval when interpolation took over).
* Otherwise the newest fix coasts. OpenSky can still be receiving fresh
* contact messages for that aircraft; freezing 60 s after the position
* produced a stop → catch-up → stop cadence, so it coasts through the latest
* real contact plus a bounded grace, with an absolute cap so a stale cached
* feed cannot drift forever.
*
* The returned object is a reused scratch: read it before the next call.
* @param {Array<object>} history Non-empty, oldest first.
* @param {object|undefined} info The contact's record.
* @param {Cesium.JulianDate} renderTime
* `_deadReckon` (CPU) and the icon planner (GPU segment) both draw from
* (`aircraftMotionRegime`). The result is a reused scratch: read it before
* the next call.
*/
function _motionRegime(history, info, renderTime) {
for (let i = history.length - 1; i >= 1; i--) {
const a = history[i - 1];
const b = history[i];
if (
!Cesium.JulianDate.lessThanOrEquals(a.time, renderTime) ||
!Cesium.JulianDate.lessThanOrEquals(renderTime, b.time)
)
continue;
const span = Cesium.JulianDate.secondsDifference(b.time, a.time);
const chordLenM = Cesium.Cartesian3.distance(a.position, b.position);
const speed = span > 0 ? chordLenM / span : (info && info.velocity) || 0;
const fallbackTrack = (info && info.true_track) || 0;
const trackFrom = Number.isFinite(a.track) ? a.track : fallbackTrack;
const blend = info && info.klass === 'helicopter' ? 0 : speedRamp(speed);
regime.kind = 'between';
regime.a = a;
regime.b = b;
regime.span = span;
regime.speed = speed;
regime.trackFrom = trackFrom;
regime.trackTo = Number.isFinite(b.track) ? b.track : trackFrom;
regime.chordCourse =
blend > 0 ? courseBetweenCartesians(a.position, b.position) : null;
regime.blend = blend;
return regime;
}
const newest = history[history.length - 1];
const warming = Cesium.JulianDate.lessThan(renderTime, history[0].time);
regime.kind = 'fix';
regime.fix = warming ? history[0] : newest;
regime.speed = fixSpeedMps(regime.fix, info);
regime.heading = fixTrackDeg(regime.fix, info);
regime.turnRateDps = (info && info.turnRateDps) || 0;
regime.minDt = -60;
// A warm-up ends when real time reaches the oldest fix; a single fix keeps
// coasting forward on the same arc.
regime.maxDt =
warming && history.length > 1
? 0
: staleCoastLimitSeconds({
// `epochMs` is captured once when the poll is normalized. Avoid
// allocating a Date per aircraft on every 12 Hz fleet tick.
fixEpochMs: Number.isFinite(newest.epochMs)
? newest.epochMs
: Cesium.JulianDate.toDate(newest.time).getTime(),
lastContactEpochMs: info?.lastContactEpochMs,
// Permit one minute of contact grace but cap any cached-feed drift
// at five minutes. Source backoff is exposed separately as a STALE cue.
minimumSec: 60,
maximumSec: 300,
});
return regime;
return aircraftMotionRegime(
history,
info,
renderTime,
RECORD_FIELDS,
regime,
);
}
/**
@@ -315,8 +224,8 @@ export function createMotion({
*/
function _extrapolateFix(fix, info, dt, out, turnRateDps = 0) {
const speed = fixSpeedMps(fix, info);
const heading = fixTrackDeg(fix, info);
const speed = fixSpeedMps(fix, info, RECORD_FIELDS);
const heading = fixTrackDeg(fix, info, RECORD_FIELDS);
flightState._drSpeedMps = speed;
flightState._drCourseHold = speed < COURSE_HOLD_SPEED_MPS;
flightState._drExtrapolating = true;
@@ -533,7 +442,7 @@ export function createMotion({
* readout run in postRender at a LATER frameNumber, so calling _trackedDisplayPosition there would
* re-run the dead-reckon on a fresh sample and double-advance the reconciliation → the label jitters
* against the now-stable plane (the model's jitter fix, resurfacing in the labels). Returns null when
* there's no valid fix for the tracked aircraft, so callers fall back to the billboard position. */
* there's no valid fix for the tracked aircraft, so callers fall back to the icon position. */
function _trackedDisplayCached() {
return flightState._drReconcileValid &&