flights: grounded aircraft turn 3D as soon as the tiles settle

Tiles still streaming no longer count as a failed ground sample: they leave
the retry backoff alone and return the last measured ground, if any, so the
first tick after the tiles settle samples and hands the icon to the model.
This commit is contained in:
Sameh Khamis committed 2026-11-15 17:41:37 -08:00
1 parent cb3be34283
commit d232d9afe4
4 files changed
+108 -33

No files matched your search

+10 -20
View File
@@ -373,16 +373,12 @@ for (const fixture of LAYERS) {
assert.ok(model.show || billboard.show, 'the contact never has both visuals hidden');
assert.equal(sampleCalls, 0, 'cold tiles do not force sampleHeight');
now += 1000;
// Streaming tiles are not a miss, so they earn no retry backoff: the
// first frame after the tiles settle samples and hands over.
now += 100;
viewer.tileset.tilesLoaded = true;
ownsVisual = fixture.driveFleetModel({ icao24, position, course: 92 });
assert.equal(ownsVisual, false, 'the miss backoff remains in force before two seconds');
assert.equal(sampleCalls, 0, 'backoff prevents an early synchronous sample');
assert.ok(model.show || billboard.show, 'backoff still leaves a visible owner');
now += 1500;
ownsVisual = fixture.driveFleetModel({ icao24, position, course: 92 });
assert.equal(ownsVisual, true, 'the model takes over after a valid terrain sample');
assert.equal(ownsVisual, true, 'the model takes over on the first settled frame');
assert.equal(sampleCalls, 1, 'the settled terrain is sampled exactly once');
assert.equal(model.show, true);
assert.equal(billboard.show, false);
@@ -403,13 +399,13 @@ for (const fixture of LAYERS) {
// Taxi past the 50 m resample threshold while the tiles are gone. The old
// snap stops being the direct answer, but it is still a MEASUREMENT of
// ground this contact was standing on ~96 m ago, so it is held: hiding the
// model here would pop a taxiing aircraft from 3D to 2D for a whole retry
// backoff (2–30 s), which is the one thing the gate must not introduce.
// model here would pop a taxiing aircraft from 3D to 2D until the tiles
// return, which is the one thing the gate must not introduce.
const taxied = Cesium.Cartesian3.fromDegrees(-97.709, 30.21, -500);
ownsVisual = fixture.driveFleetModel({ icao24, position: taxied, course: 92 });
assert.equal(ownsVisual, true,
'a taxi-invalidated snap is HELD through the resample outage, not dropped');
assert.equal(model.show, true, 'no 3D→2D pop while the resample is backing off');
assert.equal(model.show, true, 'no 3D→2D pop while the resample waits for tiles');
assert.equal(billboard.show, false);
assert.equal(sampleCalls, 1, 'and the hold costs no extra synchronous sample');
const held = Cesium.Matrix4.getTranslation(model.modelMatrix, new Cesium.Cartesian3());
@@ -646,17 +642,11 @@ for (const fixture of LAYERS) {
1e-6,
), 'a hidden tracked model cannot steal the proximity position');
now += 1000;
// Streaming tiles earned no backoff, so the first settled turn samples.
now += 100;
viewer.tileset.tilesLoaded = true;
sampledHeight = 187.5;
fixture.driveTrackedModel();
assert.equal(sampleCalls, 0, 'the tracked path honors the same retry backoff before sampling');
assert.equal(model.show, false, 'retry backoff keeps the unplaced primitive hidden');
assert.equal(fixture.trackedBillboardColor().alpha, 1,
'retry backoff leaves the tracked billboard opaque');
now += 1500;
fixture.driveTrackedModel();
assert.equal(sampleCalls, 1, 'the first settled turn samples once');
assert.equal(model.show, false, 'terrain alone does not reveal an unready model');
assert.equal(fixture.trackedBillboardColor().alpha, 1,
@@ -683,7 +673,7 @@ for (const fixture of LAYERS) {
// Taxi past the resample threshold with the tiles gone: the tracked model
// holds its last measured floor rather than handing the operator's own
// selection back to a 2D glyph for a retry backoff.
// selection back to a 2D glyph until the tiles return.
billboard.position = Cesium.Cartesian3.fromDegrees(-97.709, 30.21, -500);
fixture.driveTrackedModel();
assert.equal(model.show, true,
+15 -7
View File
@@ -11,11 +11,16 @@
* Discipline (CCTV-B9b style): scene.sampleHeight forces a synchronous offscreen
* pick render, so it is NEVER called per frame. Each grounded modeled plane gets
* ONE successful sample, cached per icao; the cache stops answering directly when
* the plane moves >MOVE_INVALIDATE_M from the sampled spot (taxiing). Misses (tiles
* still streaming, OSM fallback with no tileset skin, sample outside loaded
* geometry) are a retry-later signal with per-icao exponential backoff. A
* per-window budget stops a freshly modeled airport cluster from firing dozens of
* pick renders in one fleet tick.
* the plane moves >MOVE_INVALIDATE_M from the sampled spot (taxiing). A sample
* that misses (OSM fallback with no tileset skin, sample outside loaded
* geometry) is a retry-later signal with per-icao exponential backoff. Tiles
* still streaming is not a miss: no sample was taken, so it earns no backoff
* and the plane asks again on the next tick, sampling as soon as the tiles
* settle. Counting it as a miss had every grounded plane in view back off to
* RETRY_MAX_MS while the camera moved, then wait out that backoff after the
* tiles had loaded, so models replaced icons late and in batches. A per-window
* budget stops a freshly modeled airport cluster from firing dozens of pick
* renders in one fleet tick.
*
* What a caller gets while a sample is outstanding depends on whether this
* contact has ever HAD one, and the difference is the difference between two
@@ -121,7 +126,7 @@ const HELD_SNAP_MAX_DRIFT_M = 250;
* alternative because it errs UPWARD and stays visible, where a buried model
* errs into the terrain and cannot be seen at all. */
const HELD_SNAP_CONTRADICTION_M = 5;
/** First retry delay after a miss / tiles-not-ready (ms); doubles per consecutive miss. */
/** First retry delay after a sample finds no ground (ms); doubles per consecutive miss. */
const RETRY_BASE_MS = 2000;
/** Backoff cap (ms) — on the OSM fallback (no tile skin) sampleHeight misses forever. */
const RETRY_MAX_MS = 30000;
@@ -345,7 +350,10 @@ export function createGroundSnap({ groundFloor }) {
entries.set(icao, next);
return heldSnapM(next, surfacePos);
};
if (!_tilesReady(viewer)) return miss();
// Tiles still streaming: no sample is taken, so no backoff is earned (as
// with the budget above). The next tick asks again, and the first one after
// the tiles settle samples.
if (!_tilesReady(viewer)) return heldSnapM(entry, surfacePos);
windowCount += 1;
let sampled;
try {
+82 -5
View File
@@ -13,13 +13,15 @@ const groundFloor = {
function makeViewer() {
const calls = { samples: 0 };
const tileset = { show: true, tilesLoaded: true };
const ground = { heightM: 1650 };
return {
calls,
ground,
scene: {
primitives: { length: 1, get: () => tileset },
sampleHeight() {
calls.samples += 1;
return 1650;
return ground.heightM;
},
globe: { getHeight: () => 1600 },
},
@@ -49,14 +51,89 @@ test('a retry backoff stamped before the clock stepped back does not wait for it
const viewer = makeViewer();
const tileset = viewer.scene.primitives.get(0);
const snap = createGroundSnap({ groundFloor });
// Tiles still streaming: a miss, backed off for 2 s.
tileset.tilesLoaded = false;
// A sample that finds no ground: a miss, backed off for 2 s.
viewer.ground.heightM = undefined;
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
tileset.tilesLoaded = true;
viewer.ground.heightM = 1650;
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
assert.equal(viewer.calls.samples, 0, 'the backoff holds');
assert.equal(viewer.calls.samples, 1, 'the backoff holds');
// The clock steps back an hour: the stamp is an hour off, past any backoff.
t.mock.timers.setTime(10_000_000 - 3_600_000);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), 1650);
assert.equal(viewer.calls.samples, 2);
});
test('tiles still streaming earn no backoff: the first tick after they settle samples', (t) => {
t.mock.timers.enable({ apis: ['Date'], now: 20_000_000 });
const viewer = makeViewer();
const tileset = viewer.scene.primitives.get(0);
const snap = createGroundSnap({ groundFloor });
// The camera moves for 40 s: tiles stream the whole time, and the aircraft
// asks on every tick.
tileset.tilesLoaded = false;
for (let ms = 0; ms <= 40_000; ms += 100) {
t.mock.timers.setTime(20_000_000 + ms);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
}
assert.equal(viewer.calls.samples, 0, 'nothing samples while tiles stream');
// The tiles settle: the very next tick samples, with no backoff to wait out.
tileset.tilesLoaded = true;
t.mock.timers.setTime(20_000_000 + 40_100);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), 1650);
assert.equal(viewer.calls.samples, 1);
});
test('a held measurement still answers while tiles stream', (t) => {
t.mock.timers.enable({ apis: ['Date'], now: 30_000_000 });
const viewer = makeViewer();
const tileset = viewer.scene.primitives.get(0);
const snap = createGroundSnap({ groundFloor });
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), 1650);
// Taxi 100 m: the snap is demoted to a held value and a resample is due,
// but the tiles are streaming. The held value answers.
tileset.tilesLoaded = false;
const taxied = Cesium.Cartesian3.fromDegrees(-104.6737, 39.857, 0);
assert.equal(snap.heightFor(viewer, 'a00001', taxied), 1650);
assert.equal(viewer.calls.samples, 1);
// Tiles settle: the resample runs at once and answers fresh.
viewer.ground.heightM = 1652;
tileset.tilesLoaded = true;
assert.equal(snap.heightFor(viewer, 'a00001', taxied), 1652);
assert.equal(viewer.calls.samples, 2);
});
test('a sample that finds no ground still backs off', (t) => {
t.mock.timers.enable({ apis: ['Date'], now: 40_000_000 });
const viewer = makeViewer();
const snap = createGroundSnap({ groundFloor });
viewer.ground.heightM = undefined;
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
t.mock.timers.setTime(40_000_000 + 1_000);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
assert.equal(viewer.calls.samples, 1, 'inside the 2 s backoff');
t.mock.timers.setTime(40_000_000 + 2_001);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
assert.equal(viewer.calls.samples, 2, 'retried once the backoff ended');
});
test('streaming tiles after a real miss leave its backoff as it was', (t) => {
t.mock.timers.enable({ apis: ['Date'], now: 50_000_000 });
const viewer = makeViewer();
const tileset = viewer.scene.primitives.get(0);
const snap = createGroundSnap({ groundFloor });
// One real miss: backed off for 2 s.
viewer.ground.heightM = undefined;
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
// Tiles stream on every tick of that backoff and past it.
tileset.tilesLoaded = false;
for (let ms = 100; ms <= 3_000; ms += 100) {
t.mock.timers.setTime(50_000_000 + ms);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), null);
}
// They settle 3 s in: still the first 2 s backoff, not a doubled 4 s one.
viewer.ground.heightM = 1650;
tileset.tilesLoaded = true;
t.mock.timers.setTime(50_000_000 + 3_100);
assert.equal(snap.heightFor(viewer, 'a00001', atDenverAirport), 1650);
assert.equal(viewer.calls.samples, 2);
});