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

+21 -29
View File
@@ -29,7 +29,7 @@ export function createLifecycle({
},
/**
* Initialize the layer: create the billboard collection, reset all state,
* Initialize the layer: create the icon set and its primitive, reset all state,
* and install the click-to-track handler.
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
*/
@@ -42,9 +42,7 @@ export function createLifecycle({
flightState.lifetime = new AbortController();
clearFocusTarget('militaryFlights');
flightState._viewer = viewer;
flightState._billboardCollection = new Cesium.BillboardCollection();
viewer.scene.primitives.add(flightState._billboardCollection);
registerSpriteCollection('military', flightState._billboardCollection);
registerSpriteCollection('military', parts.icons._createIcons(viewer));
flightState._modelCollection = new Cesium.PrimitiveCollection();
viewer.scene.primitives.add(flightState._modelCollection);
// Warm the glTF cache so the tracked plane's model instantiates instantly when first needed
@@ -69,11 +67,10 @@ export function createLifecycle({
}
})
.catch(() => {
/* tracked plane just stays a billboard a beat longer */
/* tracked plane just stays an icon a beat longer */
});
}
flightState._billboards = new Map();
flightState._cullPositions.clear();
flightState._iconFocusActive = 0;
flightState._detectionObjects = new Map();
flightState.records.data = new Map();
flightState._positionHistory = new Map();
@@ -105,7 +102,7 @@ export function createLifecycle({
restoreSpriteOrder(viewer);
console.log('[Data:Military] Initialized with billboard icons');
console.log('[Data:Military] Initialized with GPU icons');
},
/**
@@ -113,8 +110,7 @@ export function createLifecycle({
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
*/
enable(viewer) {
if (flightState._billboardCollection)
flightState._billboardCollection.show = true;
if (flightState._icons) flightState._icons.show = true;
holdContinuousRender('military'); // per-frame animator (perf wave 2)
if (flightState._modelCollection)
flightState._modelCollection.show = true;
@@ -135,13 +131,12 @@ export function createLifecycle({
});
}
parts.tracking._installClickHandler(viewer);
registerPickOwner('military', (pickedId) =>
flightState._billboards.has(pickedId),
registerPickOwner(
'military',
(pickedId) => flightState._icons?.has(pickedId) === true,
);
// The flights layer suppresses its military duplicates while we render them
setMilitaryLayerActive(true);
// Force a fresh rotation pass on the first tick after re-enable
flightState._lastCamPoseSig = '';
if (!flightState._preRenderRemove && viewer?.scene) {
flightState._preRenderRemove = viewer.scene.preRender.addEventListener(
parts.rendering._fleetTick,
@@ -154,14 +149,11 @@ export function createLifecycle({
);
}
if (!flightState._moveEndRemove && viewer?.camera) {
// Arrival polish (mirror of flights.js — see the comment there): a settled
// camera move forces a full rotation pass on the very next frame, because
// the pose-signature gate can eat the settle (final easing frames land
// inside one quantization bucket) and leave stale noses for up to
// ROTATION_REFRESH_MS. One extra pass per gesture — nothing per-frame.
// A settled camera move (voice fly-to, fast pan release) runs the fleet
// pass on the very next preRender rather than up to FLEET_DR_INTERVAL_MS
// later, so the model handoff and focus land with the camera.
flightState._moveEndRemove = viewer.camera.moveEnd.addEventListener(
() => {
flightState._lastCamPoseSig = '';
flightState._lastFleetTickMs = 0;
},
);
@@ -177,8 +169,7 @@ export function createLifecycle({
disable(viewer) {
parts.controller._abortActiveUpdates();
parts.tracking._cancelPendingTrackingRestore();
if (flightState._billboardCollection)
flightState._billboardCollection.show = false;
if (flightState._icons) flightState._icons.show = false;
releaseContinuousRender('military');
parts.rendering._releaseModels();
if (flightState._modelCollection)
@@ -214,8 +205,8 @@ export function createLifecycle({
},
/**
* Tear down the layer: clear tracking, remove handlers, remove the billboard
* collection from the scene, and release all state.
* Tear down the layer: clear tracking, remove handlers, remove the icon
* primitive from the scene, and release all state.
* @param {Cesium.Viewer} viewer - The Cesium viewer instance
*/
destroy(viewer) {
@@ -255,10 +246,12 @@ export function createLifecycle({
flightState._moveEndRemove = null;
}
parts.rendering._releaseModels();
if (flightState._billboardCollection) {
viewer.scene.primitives.remove(flightState._billboardCollection);
flightState._billboardCollection = null;
if (flightState._iconPrimitive) {
viewer.scene.primitives.remove(flightState._iconPrimitive); // removing destroys it
flightState._iconPrimitive = null;
}
flightState._icons?.clear();
flightState._icons = null;
if (flightState._modelCollection) {
viewer.scene.primitives.remove(flightState._modelCollection); // removing destroys it + its models
flightState._modelCollection = null;
@@ -275,8 +268,7 @@ export function createLifecycle({
flightState._preloadModel = null;
}
flightState._planeModelLoaded = false;
flightState._billboards.clear();
flightState._cullPositions.clear();
flightState._iconFocusActive = 0;
flightState._detectionObjects.clear();
flightState.records.data.clear();
flightState._positionHistory.clear();