Merge remote-tracking branch 'origin/main' into flights/course-from-fixes

# Conflicts:
#	docs/CURRENT-STATE.md
#	scripts/package-boundaries.json
This commit is contained in:
Sameh Khamis committed 2026-11-15 11:26:28 -08:00
commit d49552af57
14 files changed
+429 -22

No files matched your search

+5 -4
View File
@@ -1,6 +1,8 @@
import * as Cesium from 'cesium';
import { createFrameWait } from '../time/frameWait.js';
const MAX_FRAME_ATTEMPTS = 120;
/** Drawn time (ms) to wait for the tracked entity's first position. */
const MAX_POSITION_WAIT_MS = 2_000;
const MIN_TRACKED_RANGE_M = 150;
const ZOOM_INERTIA_STATES = new WeakMap();
@@ -154,7 +156,7 @@ export function clampTrackedCameraPosition(
*/
export function applyTrackedCameraFrame(viewer, entity, viewFrom) {
if (!viewer || !entity || !viewFrom) return;
let attempts = 0;
const positionWait = createFrameWait(MAX_POSITION_WAIT_MS);
const trackedTransform = new Cesium.Matrix4();
const trackedPosition = new Cesium.Cartesian3();
const resolvedViewFrom = new Cesium.Cartesian3();
@@ -184,7 +186,6 @@ export function applyTrackedCameraFrame(viewer, entity, viewFrom) {
stop();
return;
}
attempts += framed ? 0 : 1;
// Prefer the display cache exposed by the flight layer. Calling the
// CallbackProperty from preUpdate can advance dead reckoning again while
// Cesium's billboard/label still holds the prior visualizer sample. At a
@@ -198,7 +199,7 @@ export function applyTrackedCameraFrame(viewer, entity, viewFrom) {
trackedPosition,
);
if (!position) {
if (attempts >= MAX_FRAME_ATTEMPTS) stop();
if (positionWait.tick()) stop();
return;
}
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(
+11 -8
View File
@@ -33,6 +33,7 @@
*/
import * as Cesium from 'cesium';
import { registerPickOwner } from './pickRegistry.js';
import { createFrameWait } from '../time/frameWait.js';
// Round 6: trail ENTITIES are pickable (the old Primitive had
// allowPicking:false). A trail hugs its aircraft, so an unclaimed pick would
@@ -58,9 +59,9 @@ const MIN_SEGMENT_DISTANCE_SQ = 0.01;
const NO_POSITIONS = Object.freeze([]);
/** @constant {number} Points per chunk; adjacent chunks share one point. */
export const CHUNK_POINTS = 128;
/** @constant {number} Visible frames a frozen chunk's stand-in waits for its
* static geometry before it is dropped anyway. */
const STAND_IN_MAX_FRAMES = 600;
/** @constant {number} Drawn time (ms) a frozen chunk's stand-in waits for its
* static geometry while the trail is shown before it is dropped anyway. */
const STAND_IN_MAX_MS = 10_000;
/**
* Create an always-visible polyline trail bound to a viewer.
@@ -80,7 +81,7 @@ export function createTrail(viewer, { color, width = 2.5 }) {
const depthFailMaterial = baseColor.withAlpha(TRAIL_OCCLUDED_ALPHA);
let destroyed = false;
let visible = true;
/** @type {{positions: Cesium.Cartesian3[], entity: Cesium.Entity, standIn: boolean, frames: number}[]} */
/** @type {{positions: Cesium.Cartesian3[], entity: Cesium.Entity, standIn: boolean, wait: {tick: () => boolean, pause: () => void}}[]} */
let frozen = [];
/** Newest chunk of the newest segment: the only part that changes. */
let tail = NO_POSITIONS;
@@ -152,9 +153,11 @@ export function createTrail(viewer, { color, width = 2.5 }) {
function staticReady(chunk) {
const display = viewer.dataSourceDisplay;
if (typeof display?.getBoundingSphere !== 'function') return true;
if (!visible) return false;
chunk.frames += 1;
if (chunk.frames > STAND_IN_MAX_FRAMES) return true;
if (!visible) {
chunk.wait.pause();
return false;
}
if (chunk.wait.tick()) return true;
try {
return (
display.getBoundingSphere(chunk.entity, false, scratchSphere) ===
@@ -262,7 +265,7 @@ export function createTrail(viewer, { color, width = 2.5 }) {
positions,
entity: addEntity(positions),
standIn: true,
frames: 0,
wait: createFrameWait(STAND_IN_MAX_MS),
});
i = end;
}
+35
View File
@@ -287,3 +287,38 @@ test('replacing the newest point and removing points inside the trail draws exac
for (const run of drawnRuns(viewer))
for (let i = 1; i < run.length; i++) assert.equal(next.get(run[i - 1]), run[i]);
});
test('a stand-in is dropped after ten seconds of drawn time, whatever the frame rate', () => {
const viewer = fakeViewer();
const trail = createTrail(viewer, { color: '#ffffff' });
const realNow = performance.now;
let clock = 1_000;
performance.now = () => clock;
try {
trail.setPositions(line(CHUNK_POINTS + 5));
// 2,000 frames at 240 Hz is about 8.3 s: still waiting for the geometry.
for (let i = 0; i < 2_000; i++) {
viewer.frame();
clock += 1000 / 240;
}
assert.equal(trail._chunksForTest().frozen[0].standIn, true);
// Hidden time does not count toward the wait.
trail.setVisible(false);
clock += 60_000;
viewer.frame();
trail.setVisible(true);
viewer.frame();
assert.equal(trail._chunksForTest().frozen[0].standIn, true);
// A background tab draws nothing: a long gap adds at most one frame step.
clock += 60_000;
viewer.frame();
assert.equal(trail._chunksForTest().frozen[0].standIn, true);
for (let i = 0; i < 480 && trail._chunksForTest().frozen[0].standIn; i++) {
clock += 1000 / 240;
viewer.frame();
}
assert.equal(trail._chunksForTest().frozen[0].standIn, false);
} finally {
performance.now = realNow;
}
});