mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
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:
1 parent
fa3a3a3bca
commit
b027bde6ad
33 files changed
+1256
-1376
No files matched your search
@@ -3,6 +3,12 @@ import { TRACKED_ICON_COLOR } from '../layers/military/policy.js';
|
||||
import { createRendering as civilRendering } from '../layers/flights/rendering.js';
|
||||
import { createRendering as militaryRendering } from '../layers/military/rendering.js';
|
||||
import { createMilitarySnapshotRenderer } from '../layers/military/snapshotRenderer.js';
|
||||
import { createIcons as createMilitaryIcons } from '../layers/military/icons.js';
|
||||
import { createIconSet } from './iconSet.js';
|
||||
import {
|
||||
aircraftMotionRegime,
|
||||
createMotionRegime,
|
||||
} from './aircraftMotionRegime.js';
|
||||
import { aircraftEmergency } from './aircraftEmergency.js';
|
||||
// Source-to-voice provenance, status retention/clearing, contact-time contracts,
|
||||
// and civil/military billboard, Cockpit and model tint regressions.
|
||||
@@ -462,18 +468,16 @@ test('tint priorities cover normal, priority, emergency, tracking and Cockpit do
|
||||
}
|
||||
});
|
||||
|
||||
test('GERMAN: an existing untracked military billboard repaints each poll without alpha loss', () => {
|
||||
test('GERMAN: an existing untracked military icon repaints each poll without losing its fade', () => {
|
||||
const { flightState, rendering } = renderHarness(militaryRendering);
|
||||
const bb = {
|
||||
color: rendering._fleetBillboardColor('abc123').withAlpha(0.65),
|
||||
};
|
||||
Object.assign(flightState, {
|
||||
_billboards: new Map([['abc123', bb]]),
|
||||
_icons: createIconSet(),
|
||||
_models: new Map(),
|
||||
_positionHistory: new Map(),
|
||||
_cullPositions: new Map(),
|
||||
_displayCourse: new Map(),
|
||||
_groundSnap: { forget() {} },
|
||||
_cockpitContactMode: false,
|
||||
_cockpitNearContacts: new Set(),
|
||||
});
|
||||
const records = new MilitaryFlightRecords({
|
||||
geoidHeight: () => 0,
|
||||
@@ -481,18 +485,42 @@ test('GERMAN: an existing untracked military billboard repaints each poll withou
|
||||
floorAltitudeM: (value) => value,
|
||||
});
|
||||
flightState.records = records;
|
||||
const parts = {
|
||||
rendering: {
|
||||
...rendering,
|
||||
_iconKind: () => 'jet',
|
||||
_syncModelToClass() {},
|
||||
},
|
||||
motion: {
|
||||
_motionRegime: (history, info, renderTime) =>
|
||||
aircraftMotionRegime(
|
||||
history,
|
||||
info,
|
||||
renderTime,
|
||||
{ speed: 'speedMps', track: 'track' },
|
||||
createMotionRegime(),
|
||||
),
|
||||
},
|
||||
};
|
||||
const icons = createMilitaryIcons({
|
||||
flightState,
|
||||
services: { focus: { focusPassIsNeeded: () => false } },
|
||||
parts,
|
||||
});
|
||||
const row = flightState._icons.add('abc123', {
|
||||
layer: 'military',
|
||||
id: 'abc123',
|
||||
});
|
||||
// The focus fade the fleet tick composes lives in its own column.
|
||||
flightState._icons.setFocus(row, 0.65);
|
||||
const apply = createMilitarySnapshotRenderer({
|
||||
flightState,
|
||||
records,
|
||||
groundFloor: { warmGroundFloor() {}, cachedGroundFloor: () => null },
|
||||
meshFloor: { sampleMeshFloorCells() {} },
|
||||
militaryRegistry: { registerMilitaryIcaos() {} },
|
||||
rendering: {
|
||||
...rendering,
|
||||
_syncModelToClass() {},
|
||||
_applyFleetBillboardPresentation() {},
|
||||
},
|
||||
motion: {},
|
||||
rendering: parts.rendering,
|
||||
icons,
|
||||
tracking: {},
|
||||
queries: {},
|
||||
});
|
||||
@@ -518,7 +546,7 @@ test('GERMAN: an existing untracked military billboard repaints each poll withou
|
||||
{ observedAtMs: NOW_MS },
|
||||
);
|
||||
apply(snapshot, {});
|
||||
assert.equal(bb.color.green < 0.5, red);
|
||||
assert.equal(bb.color.alpha, 0.65);
|
||||
assert.equal(flightState._icons.color(row).green < 0.5, red);
|
||||
assert.ok(Math.abs(flightState._icons.focus(row) - 0.65) < 1e-6);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,443 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
COURSE_HOLD_SPEED_MPS,
|
||||
courseSlewCapDps,
|
||||
norm180,
|
||||
} from './motionModel.js';
|
||||
import {
|
||||
createIconSet,
|
||||
ICON_CULL_LIFT,
|
||||
ICON_RECEDES,
|
||||
ICON_ROTATES,
|
||||
} from './iconSet.js';
|
||||
import {
|
||||
segmentCourse,
|
||||
writeArcSegment,
|
||||
writeCourseGlide,
|
||||
writeHoldSegment,
|
||||
writeLerpSegment,
|
||||
} from './iconSegment.js';
|
||||
import { IconSetPrimitive } from './iconSetPrimitive.js';
|
||||
import { iconAtlas } from './iconAtlas.js';
|
||||
import {
|
||||
aircraftIcon,
|
||||
FLEET_ICON_PX,
|
||||
TRACKED_ICON_PX,
|
||||
} from './aircraftIcons.js';
|
||||
import { cockpitContactDotImage } from './cockpitContactDot.js';
|
||||
import { horizonOccluder } from './iconOrientation.js';
|
||||
|
||||
/** Raster size of the cockpit contact pip (cockpitContactDot.js draws 16 px). */
|
||||
const COCKPIT_DOT_PX = 16;
|
||||
/** Contacts drawn below this height (m) are judged for the horizon a little
|
||||
* above the ellipsoid (ICON_CULL_LIFT). */
|
||||
const CULL_LIFT_BELOW_M = 10;
|
||||
|
||||
/**
|
||||
* An aircraft layer's contacts as one icon set: each row's motion segment
|
||||
* mirrors the layer's dead reckoning for the delayed display time, so the GPU
|
||||
* moves every untracked contact between polls with no per-frame CPU pass.
|
||||
*
|
||||
* The layer's state supplies `_icons`, `_iconPrimitive`, `_scratchIconRenderTime`,
|
||||
* `_iconFocusActive`, `_positionHistory`, `_displayCourse`, `_groundSnap`,
|
||||
* `_models`, `_trackedIcao`, `_viewer`, `_cockpitContactMode`,
|
||||
* `_cockpitNearContacts` and `records` (`data`, `missingPolls`, `forget`).
|
||||
* `parts.motion._motionRegime` picks the motion; `parts.rendering` supplies
|
||||
* the icon kind, scale, colours and distance scalars, and `_releaseModel`.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {object} options.state The layer's mutable state.
|
||||
* @param {object} options.services The layer's services (`focus`).
|
||||
* @param {object} options.parts The layer's parts (`motion`, `rendering`).
|
||||
* @param {string} options.layerId Pick and focus owner id.
|
||||
* @param {number} options.renderDelaySec How far behind real time contacts draw.
|
||||
* @param {number} options.courseMaxDps The fleet's course slew cap.
|
||||
* @param {number} options.cockpitContactSizePx Cockpit far-contact pip size.
|
||||
* @param {(icao24: string) => boolean} [options.holdsPlan] True while something
|
||||
* else writes this row's segment (it is not planned).
|
||||
* @param {(icao24: string) => void} [options.beforeSettle] Runs before a row is
|
||||
* planned afresh.
|
||||
* @param {(icao24: string) => void} [options.afterSettle] Runs after it.
|
||||
* @param {(icao24: string) => void} [options.onForget] Drops the layer's own
|
||||
* per-contact state when a contact goes.
|
||||
*/
|
||||
export function createAircraftIcons({
|
||||
state,
|
||||
services,
|
||||
parts,
|
||||
layerId,
|
||||
renderDelaySec,
|
||||
courseMaxDps,
|
||||
cockpitContactSizePx,
|
||||
holdsPlan = () => false,
|
||||
beforeSettle = () => {},
|
||||
afterSettle = () => {},
|
||||
onForget = () => {},
|
||||
}) {
|
||||
const { focusPassIsNeeded } = services.focus;
|
||||
const scratchTime = new Cesium.JulianDate();
|
||||
const scratchPosition = new Cesium.Cartesian3();
|
||||
const scratchCull = new Cesium.Cartesian3();
|
||||
const scratchScaleByDistance = new Cesium.NearFarScalar();
|
||||
let normalScaleByDistance = null;
|
||||
let cockpitScaleByDistance = null;
|
||||
|
||||
/** The delayed instant every untracked contact is drawn at. */
|
||||
function _displayTime(result = scratchTime) {
|
||||
return Cesium.JulianDate.addSeconds(
|
||||
Cesium.JulianDate.now(result),
|
||||
-renderDelaySec,
|
||||
result,
|
||||
);
|
||||
}
|
||||
|
||||
function _displayTau() {
|
||||
return state._icons.seconds(_displayTime());
|
||||
}
|
||||
|
||||
/** Create the set and its primitive for one layer lifetime. */
|
||||
function _createIcons(viewer) {
|
||||
state._icons = createIconSet({ epoch: _displayTime() });
|
||||
state._iconPrimitive = new IconSetPrimitive({
|
||||
set: state._icons,
|
||||
renderTime: () => _displayTime(state._scratchIconRenderTime),
|
||||
});
|
||||
viewer.scene.primitives.add(state._iconPrimitive);
|
||||
return state._iconPrimitive;
|
||||
}
|
||||
|
||||
/** Where a contact is drawn right now, or null when it has no row. */
|
||||
function _iconPosition(icao24, result = new Cesium.Cartesian3()) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
return row < 0 ? null : set.position(row, _displayTau(), result);
|
||||
}
|
||||
|
||||
/** The nose direction a contact is drawn with right now. */
|
||||
function _iconCourse(icao24) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
return row < 0 ? null : set.course(row, _displayTau());
|
||||
}
|
||||
|
||||
/** Whether the layer draws this contact's icon (not tracked, not model-owned). */
|
||||
function _iconShown(icao24) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
return row >= 0 && set.shown(row);
|
||||
}
|
||||
|
||||
/** The camera's horizon test, or null when there is no placed camera. */
|
||||
function _occluder() {
|
||||
const camera = state._viewer?.camera;
|
||||
return camera?.positionWC ? horizonOccluder(camera) : null;
|
||||
}
|
||||
|
||||
/** Whether a drawn row at `position` clears the camera's horizon, judged
|
||||
* exactly as the icon shader judges it. No camera, no horizon. */
|
||||
function _aboveHorizon(row, position, occluder) {
|
||||
return (
|
||||
!occluder ||
|
||||
occluder.isPointVisible(
|
||||
state._icons.cullPoint(row, position, scratchCull),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the segment the layer's dead reckoning would follow from now on:
|
||||
* interpolation between the bracketing fixes, the warm-up arc back from the
|
||||
* oldest fix, or the coast arc past the newest. The displayed nose glides
|
||||
* from where it is onto the new course at the fleet's slew cap; a hovering
|
||||
* contact keeps its nose. The row expires when the regime would change.
|
||||
* @param {string} icao24
|
||||
* @param {{fromCourseDeg?: number|null}} [options] Nose to glide from when
|
||||
* the row's own segment is not what was on screen (tracking handoff).
|
||||
*/
|
||||
function _planIcon(icao24, { fromCourseDeg } = {}) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
if (row < 0 || holdsPlan(icao24)) return;
|
||||
const history = state._positionHistory.get(icao24);
|
||||
if (!history?.length) return;
|
||||
const info = state.records.data.get(icao24);
|
||||
const renderTime = _displayTime();
|
||||
const tau = set.seconds(renderTime);
|
||||
const seg = set.segments;
|
||||
const shownCourse =
|
||||
fromCourseDeg ??
|
||||
(set.expires(row) === -Infinity ? null : set.course(row, tau));
|
||||
|
||||
const regime = parts.motion._motionRegime(history, info, renderTime);
|
||||
let speed;
|
||||
let expiresAt = Infinity;
|
||||
if (regime.kind === 'between') {
|
||||
const { a, b, span, trackFrom, trackTo, chordCourse } = regime;
|
||||
speed = regime.speed;
|
||||
const blend = chordCourse == null ? 0 : regime.blend;
|
||||
if (span > 0) {
|
||||
writeLerpSegment(seg, row, {
|
||||
from: a.position,
|
||||
to: b.position,
|
||||
t0: set.seconds(a.time),
|
||||
t1: set.seconds(b.time),
|
||||
course0Deg:
|
||||
trackFrom + blend * norm180((chordCourse ?? 0) - trackFrom),
|
||||
courseSlopeDeg: norm180(trackTo - trackFrom) * (1 - blend),
|
||||
});
|
||||
} else {
|
||||
writeHoldSegment(
|
||||
seg,
|
||||
row,
|
||||
b.position,
|
||||
trackTo + blend * norm180((chordCourse ?? 0) - trackTo),
|
||||
);
|
||||
}
|
||||
expiresAt = set.seconds(b.time);
|
||||
} else {
|
||||
const { fix, heading } = regime;
|
||||
speed = regime.speed;
|
||||
const t0 = set.seconds(fix.time);
|
||||
if (speed === 0) {
|
||||
writeHoldSegment(seg, row, fix.position, heading);
|
||||
} else {
|
||||
writeArcSegment(seg, row, {
|
||||
fix: fix.position,
|
||||
t0,
|
||||
minDt: regime.minDt,
|
||||
maxDt: regime.maxDt,
|
||||
speedMps: speed,
|
||||
trackDeg: heading,
|
||||
turnRateDps: regime.turnRateDps,
|
||||
});
|
||||
}
|
||||
// A warm-up's arc ends at its fix; a coast's runs to its limit.
|
||||
if (regime.maxDt === 0) expiresAt = t0;
|
||||
}
|
||||
// Below hover speed the nose holds what is on screen (or, for a new row,
|
||||
// where this segment starts); above it, it glides on at the slew cap.
|
||||
const hold = speed < COURSE_HOLD_SPEED_MPS;
|
||||
if (hold || shownCourse != null) {
|
||||
writeCourseGlide(
|
||||
seg,
|
||||
row,
|
||||
shownCourse ?? segmentCourse(seg, row, tau),
|
||||
tau,
|
||||
hold ? 0 : courseSlewCapDps(speed, courseMaxDps),
|
||||
);
|
||||
}
|
||||
set.segmentWritten(row, expiresAt);
|
||||
}
|
||||
|
||||
/** Re-plan every row whose regime ended before `tau`. */
|
||||
function _replanExpired(tau) {
|
||||
const set = state._icons;
|
||||
const due = [];
|
||||
for (let row = 0; row < set.count; row++)
|
||||
if (set.expires(row) <= tau) due.push(set.idAt(row));
|
||||
for (const icao24 of due) _planIcon(icao24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance focus de-emphasis for every drawn row (and every row a fleet model
|
||||
* draws for, whose alpha reads it), only while a focus target exists or some
|
||||
* row is still relaxing back to full emphasis.
|
||||
*/
|
||||
function _focusIcons(tau, scene, camera, nowMs, target) {
|
||||
if (!focusPassIsNeeded(target, state._iconFocusActive)) return;
|
||||
const { advanceProjectedSpriteFocus, nearFarScalarValueAtDistance } =
|
||||
services.focus;
|
||||
const set = state._icons;
|
||||
let active = 0;
|
||||
for (let row = 0; row < set.count; row++) {
|
||||
if (!set.shown(row) && !state._models.has(set.idAt(row))) continue;
|
||||
const position = set.position(row, tau, scratchPosition);
|
||||
const distanceScale = nearFarScalarValueAtDistance(
|
||||
set.scaleByDistance(row, scratchScaleByDistance),
|
||||
Cesium.Cartesian3.distance(camera.positionWC, position),
|
||||
);
|
||||
const half = set.scale(row) * distanceScale * 0.5;
|
||||
const focus = advanceProjectedSpriteFocus(
|
||||
set.metaAt(row),
|
||||
position,
|
||||
scene,
|
||||
camera,
|
||||
nowMs,
|
||||
target,
|
||||
undefined,
|
||||
set.width(row) * half,
|
||||
set.height(row) * half,
|
||||
);
|
||||
set.setFocus(row, focus.factor);
|
||||
if (focus.active || focus.transitioning) active++;
|
||||
}
|
||||
state._iconFocusActive = active;
|
||||
}
|
||||
|
||||
/** Image, size, scale, tint and freshness for one row under the current
|
||||
* normal/cockpit contract. Motion and rotation stay with the segment. */
|
||||
function _applyIconPresentation(icao24) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
if (row < 0) return;
|
||||
const rendering = parts.rendering;
|
||||
const info = state.records.data.get(icao24);
|
||||
const tracked = icao24 === state._trackedIcao;
|
||||
const cockpitDot =
|
||||
state._cockpitContactMode &&
|
||||
!tracked &&
|
||||
!state._cockpitNearContacts.has(icao24);
|
||||
if (cockpitDot) {
|
||||
const dot = iconAtlas.slot(cockpitContactDotImage(), COCKPIT_DOT_PX);
|
||||
set.setImage(row, dot, dot);
|
||||
set.setSize(row, cockpitContactSizePx, cockpitContactSizePx);
|
||||
set.setScale(row, 1);
|
||||
cockpitScaleByDistance ??= rendering._cockpitBillboardScaleByDistance();
|
||||
set.setScaleByDistance(row, cockpitScaleByDistance);
|
||||
set.setColor(row, rendering._cockpitContactColor(icao24, info));
|
||||
set.setFlag(row, ICON_ROTATES, false);
|
||||
} else {
|
||||
set.setImage(
|
||||
row,
|
||||
iconAtlas.slot(
|
||||
aircraftIcon(rendering._iconKind(icao24, info?.klass)),
|
||||
FLEET_ICON_PX,
|
||||
),
|
||||
iconAtlas.slot(
|
||||
aircraftIcon(
|
||||
rendering._iconKind(icao24, info?.klass),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
TRACKED_ICON_PX,
|
||||
),
|
||||
);
|
||||
const size = tracked ? 24 : 20;
|
||||
set.setSize(row, size, size);
|
||||
set.setScale(row, rendering._fleetBillboardScale(icao24, info?.klass));
|
||||
normalScaleByDistance ??= rendering._normalBillboardScaleByDistance();
|
||||
set.setScaleByDistance(row, normalScaleByDistance);
|
||||
set.setColor(row, rendering._fleetBillboardColor(icao24, info));
|
||||
set.setFlag(row, ICON_ROTATES, true);
|
||||
}
|
||||
set.setFlag(row, ICON_RECEDES, true);
|
||||
set.setFlag(
|
||||
row,
|
||||
ICON_CULL_LIFT,
|
||||
Number.isFinite(info?.renderAltitudeM) &&
|
||||
info.renderAltitudeM < CULL_LIFT_BELOW_M,
|
||||
);
|
||||
set.setAlpha(row, state.records.missingPolls.get(icao24) ? 0.45 : 1);
|
||||
}
|
||||
|
||||
/** Add a row for a new contact, hidden while it is the tracked one. */
|
||||
function _addIcon(icao24) {
|
||||
const set = state._icons;
|
||||
const row = set.add(icao24, { layer: layerId, id: icao24 });
|
||||
_applyIconPresentation(icao24);
|
||||
_settleIcon(icao24);
|
||||
set.setShown(row, icao24 !== state._trackedIcao);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plan a row afresh, with the layer's own settle work on either side, and
|
||||
* let a dimmed row relax: one that sat out the focus pass (tracked) may come
|
||||
* back dimmed after the pass went idle, so it is counted to run the pass.
|
||||
* @param {string} icao24
|
||||
* @param {{fromCourseDeg?: number}} [options] The course on screen to glide from.
|
||||
*/
|
||||
function _settleIcon(icao24, options) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
if (row < 0) return;
|
||||
beforeSettle(icao24);
|
||||
if (set.focus(row) < 1) state._iconFocusActive += 1;
|
||||
_planIcon(icao24, options);
|
||||
afterSettle(icao24);
|
||||
}
|
||||
|
||||
/** Drop a contact and everything the layer keeps for it. */
|
||||
function _forgetContact(icao24) {
|
||||
state._icons?.remove(icao24);
|
||||
parts.rendering._releaseModel(icao24);
|
||||
state.records.forget(icao24);
|
||||
state._positionHistory.delete(icao24);
|
||||
state._displayCourse.delete(icao24);
|
||||
state._groundSnap.forget(icao24);
|
||||
onForget(icao24);
|
||||
}
|
||||
|
||||
/** Icon ids, so ray samples never land on an aircraft instead of the ground. */
|
||||
function _iconIds() {
|
||||
const set = state._icons;
|
||||
const ids = new Array(set?.count ?? 0);
|
||||
for (let row = 0; row < ids.length; row++) ids[row] = set.idAt(row);
|
||||
return ids;
|
||||
}
|
||||
|
||||
return {
|
||||
_displayTime,
|
||||
_displayTau,
|
||||
_createIcons,
|
||||
_iconPosition,
|
||||
_iconCourse,
|
||||
_iconShown,
|
||||
_occluder,
|
||||
_aboveHorizon,
|
||||
_planIcon,
|
||||
_settleIcon,
|
||||
_replanExpired,
|
||||
_focusIcons,
|
||||
_applyIconPresentation,
|
||||
_addIcon,
|
||||
_forgetContact,
|
||||
_iconIds,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Test seams over an aircraft layer's icon rows, shared by the flights and
|
||||
* military `testing` parts.
|
||||
* @param {object} state The layer state holding `_icons`.
|
||||
* @param {{icons: ReturnType<typeof createAircraftIcons>}} parts Read at call time.
|
||||
* @param {string} layerId
|
||||
*/
|
||||
export function aircraftIconTestSeams(state, parts, layerId) {
|
||||
/** Give a test contact an icon row held at `billboard.position`, shown as
|
||||
* `billboard.show` says (hidden by default while tracked). */
|
||||
function _seedIconForTest(icao24, billboard, tracked) {
|
||||
const set = state._icons;
|
||||
const row = set.add(icao24, { layer: layerId, id: icao24 });
|
||||
if (billboard?.position)
|
||||
writeHoldSegment(set.segments, row, billboard.position, 0);
|
||||
set.segmentWritten(row);
|
||||
set.setShown(row, billboard?.show ?? !tracked);
|
||||
return row;
|
||||
}
|
||||
|
||||
/** Where a contact's icon is drawn now and whether the layer shows it. */
|
||||
function _iconForTest(icao24) {
|
||||
const position = parts.icons._iconPosition(icao24);
|
||||
return position
|
||||
? {
|
||||
position,
|
||||
shown: parts.icons._iconShown(icao24),
|
||||
course: parts.icons._iconCourse(icao24),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
|
||||
/** Show or hide a contact's icon as a handoff would, or hold it somewhere. */
|
||||
function _setIconForTest(icao24, { shown, position } = {}) {
|
||||
const set = state._icons;
|
||||
const row = set?.row(icao24) ?? -1;
|
||||
if (row < 0) return;
|
||||
if (shown !== undefined) set.setShown(row, shown);
|
||||
if (position) {
|
||||
writeHoldSegment(set.segments, row, position, 0);
|
||||
set.segmentWritten(row);
|
||||
}
|
||||
}
|
||||
|
||||
return { _seedIconForTest, _iconForTest, _setIconForTest };
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
courseBetweenCartesians,
|
||||
speedRamp,
|
||||
staleCoastLimitSeconds,
|
||||
} from './motionModel.js';
|
||||
|
||||
/**
|
||||
* Which record fields carry an aircraft layer's reported ground speed (m/s)
|
||||
* and track (degrees clockwise from north).
|
||||
* @typedef {{speed: string, track: string}} AircraftRecordFields
|
||||
*/
|
||||
|
||||
/** A fix's own ground speed, else the record's. */
|
||||
export function fixSpeedMps(fix, info, fields) {
|
||||
return Number.isFinite(fix.velocity)
|
||||
? fix.velocity
|
||||
: (info && info[fields.speed]) || 0;
|
||||
}
|
||||
|
||||
/** A fix's own track, else the record's. */
|
||||
export function fixTrackDeg(fix, info, fields) {
|
||||
return Number.isFinite(fix.track)
|
||||
? fix.track
|
||||
: (info && info[fields.track]) || 0;
|
||||
}
|
||||
|
||||
/** A reusable result for `aircraftMotionRegime`. */
|
||||
export function createMotionRegime() {
|
||||
return {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Which motion an aircraft's history gives at `renderTime` — the one choice
|
||||
* the CPU dead reckoning 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 a poll interval of history exists) runs the OLDEST fix BACKWARD,
|
||||
* preserving the behind-real-time 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. A feed 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.
|
||||
*
|
||||
* @param {Array<object>} history Non-empty, oldest first.
|
||||
* @param {object|undefined} info The contact's record.
|
||||
* @param {Cesium.JulianDate} renderTime
|
||||
* @param {AircraftRecordFields} fields
|
||||
* @param {object} result From `createMotionRegime`; returned filled in.
|
||||
*/
|
||||
export function aircraftMotionRegime(
|
||||
history,
|
||||
info,
|
||||
renderTime,
|
||||
fields,
|
||||
result,
|
||||
) {
|
||||
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[fields.speed]) || 0;
|
||||
const fallbackTrack = (info && info[fields.track]) || 0;
|
||||
const trackFrom = Number.isFinite(a.track) ? a.track : fallbackTrack;
|
||||
const blend = info && info.klass === 'helicopter' ? 0 : speedRamp(speed);
|
||||
result.kind = 'between';
|
||||
result.a = a;
|
||||
result.b = b;
|
||||
result.span = span;
|
||||
result.speed = speed;
|
||||
result.trackFrom = trackFrom;
|
||||
result.trackTo = Number.isFinite(b.track) ? b.track : trackFrom;
|
||||
result.chordCourse =
|
||||
blend > 0 ? courseBetweenCartesians(a.position, b.position) : null;
|
||||
result.blend = blend;
|
||||
return result;
|
||||
}
|
||||
const newest = history[history.length - 1];
|
||||
const warming = Cesium.JulianDate.lessThan(renderTime, history[0].time);
|
||||
result.kind = 'fix';
|
||||
result.fix = warming ? history[0] : newest;
|
||||
result.speed = fixSpeedMps(result.fix, info, fields);
|
||||
result.heading = fixTrackDeg(result.fix, info, fields);
|
||||
result.turnRateDps = (info && info.turnRateDps) || 0;
|
||||
result.minDt = -60;
|
||||
// A warm-up ends when real time reaches the oldest fix; a single fix keeps
|
||||
// coasting forward on the same arc.
|
||||
result.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 result;
|
||||
}
|
||||
@@ -83,24 +83,24 @@ for (const layer of LAYERS) {
|
||||
test(`${layer.name}: near AIR state is independent from model admission`, () => {
|
||||
assert.match(source, /nextCockpitNearContacts\(/,
|
||||
'Cockpit derives a separate near-contact hysteresis set');
|
||||
assert.match(source, /isCockpitContact && !isCockpitNear[\s\S]*cockpitContactDotImage\(\)|!flightState\._cockpitNearContacts\.has\(icao24\);\s*if \(cockpitDot\) \{\s*const dot = iconAtlas\.slot\(cockpitContactDotImage\(\)/,
|
||||
assert.match(source, /!state\._cockpitNearContacts\.has\(icao24\);\s*if \(cockpitDot\) \{\s*const dot = iconAtlas\.slot\(cockpitContactDotImage\(\)/,
|
||||
'only out-of-range Cockpit contacts become dots');
|
||||
// `_iconKind` is identity for every unconverted contact (see
|
||||
// tr3bRegistry.test.mjs) — it only swaps the glyph for a contact the
|
||||
// operator explicitly converted into a TR-3B.
|
||||
assert.match(source, /bb\.image\s*=\s*aircraftIcon\(\s*_iconKind\(\s*icao24,\s*meta\?\.klass,?\s*\)(,\s*aircraftVisuals\.read\(bb\)\?\.iconLarge\s*\?\s*TRACKED_ICON_PX\s*:\s*undefined)?,?\s*\)|aircraftIcon\(\s*parts\.rendering\._iconKind\(icao24, info\?\.klass\),?\s*\)/,
|
||||
assert.match(source, /aircraftIcon\(\s*(?:parts\.)?rendering\._iconKind\(icao24, info\?\.klass\),?\s*\)/,
|
||||
'near contacts and model fallbacks retain the class-derived aircraft silhouette');
|
||||
assert.match(source, /setBillboard\(\s*bb,\s*'rotation',\s*0\s*\);|set\.setFlag\(row, ICON_ROTATES, false\);/,
|
||||
assert.match(source, /set\.setFlag\(row, ICON_ROTATES, false\);/,
|
||||
'far dots are reset to a rotation-free presentation');
|
||||
assert.match(source, /\(\s*!(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isCockpitNear,?\s*\)\s*&&\s*\(\s*doRotations\s*\|\|\s*revealed,?\s*\)|set\.setFlag\(row, ICON_ROTATES, true\);/,
|
||||
assert.match(source, /set\.setFlag\(row, ICON_ROTATES, true\);/,
|
||||
'near 2D silhouettes continue to receive projected course');
|
||||
assert.match(source, /if\s*\(\s*billboardState\(bb\)\.show,?\s*\)\s*setBillboard\(\s*bb,\s*'show',\s*false\s*\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders|icons\.setShown\(row, false\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders/,
|
||||
'the gap-proof billboard-to-model handoff remains intact');
|
||||
assert.match(source, /icons\.setShown\(row, false\);\s*\/\/\s*hand\s*off\s*ONLY\s*once\s*the\s*model\s*renders/,
|
||||
'the gap-proof icon-to-model handoff remains intact');
|
||||
});
|
||||
|
||||
test(`${layer.name}: Cockpit exit clears near state before restoring map presentation`, () => {
|
||||
const setMode = /^([ \t]*)function _setCockpitContactMode\b[\s\S]*?\n\1\}/m.exec(source)?.[0];
|
||||
assert.match(setMode, /else\s*(?:flightState\.)?_cockpitNearContacts\s*=\s*new\s*Set\(\s*,?\s*\);/);
|
||||
assert.match(setMode, /for\s*\(\s*const\s*\[icao24,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*\)\s*(?:parts\.\w+\.)?_applyFleetBillboardPresentation\(\s*icao24,\s*bb,?\s*\);|for \(let row = 0; row < \(icons\?\.count \?\? 0\); row\+\+\)\s*parts\.icons\._applyIconPresentation\(icons\.idAt\(row\)\);/);
|
||||
assert.match(setMode, /for \(let row = 0; row < \(icons\?\.count \?\? 0\); row\+\+\)\s*parts\.icons\._applyIconPresentation\(icons\.idAt\(row\)\);/);
|
||||
});
|
||||
}
|
||||
@@ -1665,7 +1665,7 @@ test('hasContact declines while a layer is disabled, whatever its maps still hol
|
||||
[
|
||||
'militaryFlights',
|
||||
readLayerSource(new URL('./militaryFlights.js', import.meta.url)),
|
||||
/hasContact\(\s*icao24,?\s*\)\s*\{\s*\n\s*if\s*\(\s*!(?:flightState\.)?_billboardCollection\s*\|\|\s*!(?:flightState\.)?_billboardCollection\.show\s*\|\|\s*(?:flightState\.)?_billboards\.size\s*===\s*0,?\s*\)\s*return\s*null;/,
|
||||
/hasContact\(\s*icao24,?\s*\)\s*\{\s*\n\s*const icons = flightState\._icons;\s*\n\s*if\s*\(\s*!icons\s*\|\|\s*!icons\.show\s*\|\|\s*icons\.count\s*===\s*0,?\s*\)\s*return\s*null;/,
|
||||
],
|
||||
[
|
||||
'aisLiveVessels',
|
||||
|
||||
@@ -32,5 +32,7 @@ export const _driveFleetModelHandoffForTest =
|
||||
militaryFlightsLayer.testing._driveFleetModelHandoffForTest;
|
||||
export const _ensureFleetModelForTest =
|
||||
militaryFlightsLayer.testing._ensureFleetModelForTest;
|
||||
export const _iconForTest = militaryFlightsLayer.testing._iconForTest;
|
||||
export const _setIconForTest = militaryFlightsLayer.testing._setIconForTest;
|
||||
export const mapAnalystRecord = militaryFlightsLayer.mapAnalystRecord;
|
||||
export default militaryFlightsLayer;
|
||||
@@ -14,7 +14,10 @@ import flightsLayer, {
|
||||
_iconForTest,
|
||||
_setTrackedFlightRefreshStateForTest,
|
||||
} from './flights.js';
|
||||
import militaryFlightsLayer, { _setTrackedMilitaryRefreshStateForTest } from './militaryFlights.js';
|
||||
import militaryFlightsLayer, {
|
||||
_iconForTest as _militaryIconForTest,
|
||||
_setTrackedMilitaryRefreshStateForTest,
|
||||
} from './militaryFlights.js';
|
||||
|
||||
const ICAO = 'abc123';
|
||||
const OTHER = 'def456';
|
||||
@@ -66,7 +69,7 @@ const LAYERS = [
|
||||
name: 'military',
|
||||
layer: militaryFlightsLayer,
|
||||
visualCenterM: Cesium.Cartesian3.ZERO,
|
||||
spritePosition: () => contactBillboard(true).position,
|
||||
spritePosition: () => _militaryIconForTest(ICAO).position,
|
||||
seed({ billboardShow, models = [] }) {
|
||||
_setTrackedMilitaryRefreshStateForTest({
|
||||
icao24: ICAO,
|
||||
|
||||
@@ -232,8 +232,8 @@ test('both flight layers keep a converted contact 2D and visible (render invaria
|
||||
const source = readLayerSource(new URL(`./${name}`, import.meta.url));
|
||||
|
||||
// 1. The 3D model handoff is SUPPRESSED for a converted contact — there is
|
||||
// no TR-3B GLB, so the triangle billboard stays the visual.
|
||||
assert.match(source, /modelEligible\.has\(icao24\) && !isTr3b\(icao24\)|for \(const icao24 of modelEligible\) \{\s*if \(isTr3b\(icao24\)\) continue;/,
|
||||
// no TR-3B GLB, so the triangle icon stays the visual.
|
||||
assert.match(source, /for \(const icao24 of modelEligible\) \{\s*if \(isTr3b\(icao24\)\) continue;/,
|
||||
`${name}: fleet model handoff skips converted contacts`);
|
||||
// The tracked regime became default-on and camera-distance driven
|
||||
// (2026-08-19), so the suppression moved from a conjunct on
|
||||
@@ -242,11 +242,11 @@ test('both flight layers keep a converted contact 2D and visible (render invaria
|
||||
assert.match(source, /if\s*\(\s*!(?:flightState\.)?_trackedIcao\s*\|\|\s*(?:flightState\.)?_cockpitContactMode\s*\|\|\s*isTr3b\(\s*(?:flightState\.)?_trackedIcao,?\s*\),?\s*\)\s*\{/,
|
||||
`${name}: the standalone tracked model is suppressed for a converted contact`);
|
||||
|
||||
// 2. The billboard is never hidden by that suppression — it must keep
|
||||
// 2. The icon is never hidden by that suppression — it must keep
|
||||
// satisfying the getNearby/getDetectableObjects visibility guards, so a
|
||||
// converted contact still works in Contacts and Cockpit.
|
||||
assert.match(source, /if\s*\(\s*(bb|modelled)\s*&&\s*id\s*!==\s*(?:flightState\.)?_trackedIcao,?\s*\)\s*setBillboard\(\s*\1,\s*'show',\s*true,?\s*\);|if\s*\(\s*row >= 0\s*&&\s*id\s*!==\s*flightState\._trackedIcao\s*\)\s*flightState\._icons\.setShown\(row, true\);/,
|
||||
`${name}: converting restores the billboard the model handoff had hidden`);
|
||||
assert.match(source, /if\s*\(\s*row >= 0\s*&&\s*id\s*!==\s*flightState\._trackedIcao\s*\)\s*flightState\._icons\.setShown\(row, true\);/,
|
||||
`${name}: converting restores the icon the model handoff had hidden`);
|
||||
|
||||
// 3. Every aircraftIcon() CALL SITE routes through the kind resolver, so no
|
||||
// refresh path (poll reconciler, raster swap, presentation, tracked
|
||||
@@ -411,7 +411,7 @@ test('a converted contact never consumes a 3D model CAP SLOT', async () => {
|
||||
const source = readLayerSource(new URL(`./${name}`, import.meta.url));
|
||||
// Anchor on the MODEL-eligibility loop (keepDistSq), not the unrelated
|
||||
// ambient-enrichment candidate loop that also builds a `cand`.
|
||||
const loop = /const\s*cand\s*=\s*\[\];\s*\n\s*for\s*\((?:\s*const\s*\[icao,\s*bb\]\s*of\s*(?:flightState\.)?_billboards,?\s*|let row = 0; row < icons\.count; row\+\+)\)[\s\S]*?cand\.push\(\s*/.exec(source)?.[0];
|
||||
const loop = /const\s*cand\s*=\s*\[\];\s*\n\s*for\s*\(let row = 0; row < icons\.count; row\+\+\)[\s\S]*?cand\.push\(\s*/.exec(source)?.[0];
|
||||
assert.ok(loop, `${name}: the model-eligibility candidate loop is present`);
|
||||
assert.match(loop, /keepDistSq/, `${name}: matched the model-eligibility loop`);
|
||||
assert.match(loop, /if \(isTr3b\(icao\)\) continue;/,
|
||||
|
||||
@@ -44,6 +44,8 @@ import militaryFlightsLayer, {
|
||||
_trackedBillboardColorForTest as militaryTrackedBillboardColor,
|
||||
_driveFleetModelHandoffForTest as militaryDriveFleetModel,
|
||||
_ensureFleetModelForTest as militaryEnsureFleetModel,
|
||||
_iconForTest as militaryIcon,
|
||||
_setIconForTest as militarySetIcon,
|
||||
} from './militaryFlights.js';
|
||||
import { clearTr3bRegistry, setTr3b } from './tr3bRegistry.js';
|
||||
import { reportMeshFloorCell, _clearMeshFloorCellsForTest } from './groundFloor.js';
|
||||
@@ -188,21 +190,21 @@ function contactBillboard() {
|
||||
};
|
||||
}
|
||||
|
||||
/** A flights contact's icon row, read and written the way these tests read a
|
||||
/** A contact's icon row, read and written the way these tests read a
|
||||
* billboard: where it is drawn and whether the layer shows it. */
|
||||
function flightIconView(icao24) {
|
||||
function iconView(icao24, readIcon, setIcon) {
|
||||
return {
|
||||
get position() {
|
||||
return flightsIcon(icao24)?.position;
|
||||
return readIcon(icao24)?.position;
|
||||
},
|
||||
set position(position) {
|
||||
flightsSetIcon(icao24, { position });
|
||||
setIcon(icao24, { position });
|
||||
},
|
||||
get show() {
|
||||
return flightsIcon(icao24)?.shown === true;
|
||||
return readIcon(icao24)?.shown === true;
|
||||
},
|
||||
set show(shown) {
|
||||
flightsSetIcon(icao24, { shown });
|
||||
setIcon(icao24, { shown });
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -237,7 +239,7 @@ const LAYERS = [
|
||||
modelCollection,
|
||||
meta: { callsign: 'TEST123 ', altitude: 10_668, klass: 'airliner', onGround },
|
||||
});
|
||||
return flightIconView(icao24);
|
||||
return iconView(icao24, flightsIcon, flightsSetIcon);
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -262,7 +264,7 @@ const LAYERS = [
|
||||
modelCollection,
|
||||
meta: { callsign: 'TEST123 ', altitudeFt: 35_000, klass: 'fastjet', onGround },
|
||||
});
|
||||
return billboard;
|
||||
return iconView(icao24, militaryIcon, militarySetIcon);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user