Merge main (87ab9d2b1, #1758 and the #1757 revert) into the renderer branch

Grounded aircraft turn 3D on the first settled frame: streaming tiles are not a miss. groundSnap's tests keep main's cases against the branch's query port; trackedModelForm.test.mjs (the branch's form of trackedModelRegime.test.mjs) takes main's edits.
This commit is contained in:
Sameh Khamis committed 2026-11-15 18:42:06 -08:00
commit 4b0958b9e8
5 files changed
+111 -56

No files matched your search

+10 -42
View File
@@ -542,30 +542,15 @@ for (const fixture of LAYERS) {
);
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',
'the model takes over on the first settled frame',
);
assert.equal(
sampleCalls,
@@ -610,8 +595,8 @@ 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,
@@ -626,7 +611,7 @@ for (const fixture of LAYERS) {
assert.equal(
model.show,
true,
'no 3D→2D pop while the resample is backing off',
'no 3D→2D pop while the resample waits for tiles',
);
assert.equal(billboard.show, false);
assert.equal(
@@ -987,28 +972,11 @@ for (const fixture of LAYERS) {
'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()[3],
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,
@@ -1063,7 +1031,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(
+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
@@ -124,7 +129,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;
@@ -327,7 +332,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;
const at = toLonLatH(pos);
const exclude = Array.isArray(exclusions?.sets)
+82 -6
View File
@@ -18,7 +18,8 @@ function makeViewer() {
const calls = { samples: 0 };
const tileset = { show: true, tilesLoaded: true };
const asked = [];
const viewer = { calls, tileset, asked, surfaceLoaded: true };
const ground = { heightM: 1650 };
const viewer = { calls, tileset, asked, ground, surfaceLoaded: true };
bindRenderer(viewer, {
globe: {
isSettled: (kind) =>
@@ -30,7 +31,7 @@ function makeViewer() {
sampleHeightNow(point, options) {
calls.samples += 1;
asked.push({ point, options });
return 1650;
return ground.heightM;
},
},
});
@@ -60,15 +61,35 @@ test('a retry backoff stamped before the clock stepped back does not wait for it
const viewer = makeViewer();
const { tileset } = viewer;
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;
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);
});
@@ -160,3 +181,58 @@ test('through the Cesium globe port, a streaming tileset the port did not load h
assert.equal(later.heightFor(viewer, 'a00001', atDenverAirport), 1650);
assert.equal(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;
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 = 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;
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);
});