Move only the anchor's height when the floor height arrives

- The first height that replaces the entry frame's now moves only the
  anchor's height. The anchor keeps its place and its eased lift, so the
  camera no longer jumps to a corrected fix or steps back.
- A detail line is measured with the title's glyph widths. They are a
  little wide for its smaller type, so a long detail line is no longer
  clipped.
- The first aircraft update is checked in the existing test, and the copy
  is removed; test fixtures are simpler.
- Comments, the release note and CURRENT-STATE match the code.
This commit is contained in:
German Khokhlov committed 2026-11-19 00:26:57 +04:00
1 parent c190e662bc
commit 83081730c0
9 files changed
+176 -138

No files matched your search

+14 -8
View File
@@ -403,11 +403,18 @@ function updateSubject(nowMs) {
this.surfaceWaitStartedMs = 0;
this.surfaceAcquiring = false;
if (!held) {
// The first height to replace the entry frame's places the anchor
// anew: an inertial one would close on it only at the horizontal
// correction's rate.
if (this.subjectHeightFromEntry && heightM !== this.subjectHeightM)
this.cockpitAnchorValid = false;
// The first height to replace the entry frame's is the anchor's at once
// (an inertial anchor would close on it only at the horizontal
// correction's rate); where the anchor stands, it stays.
if (
this.subjectHeightFromEntry &&
this.cockpitAnchorValid &&
heightM !== this.subjectHeightM
) {
const anchor = toCartographicRadians(this.cockpitAnchor);
if (anchor)
this.cockpitAnchor = fromRadians(anchor.lon, anchor.lat, heightM);
}
this.subjectHeightFromEntry = false;
}
this.subjectHeightM = heightM;
@@ -472,9 +479,8 @@ function updateSubject(nowMs) {
* Aircraft pass none and look along the heading at the profile pitch.
*/
function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
// An update that sets the anchor stands it on the target with no step:
// the first one (the time before it, an entry or a floor wait, moved
// nothing), and a subject's whose height replaced its entry frame's.
// The update that first sets the anchor stands it on the target: the time
// before it (an entry, a floor wait) moved nothing, so it has no step.
const anchoring = !this.cockpitAnchorValid;
if (anchoring) {
this.cockpitAnchorValid = true;
+3 -36
View File
@@ -444,10 +444,10 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
latitude: 30.19,
longitude: -97.67,
onGround: false,
stale: true,
stale: false,
};
const { owner, views } = cockpitOver({ info, target });
// Held on the target while the feed is stale.
// The first update stands the anchor on the target.
owner.update();
let expected = cesiumCockpitEye(Cesium, {
target,
@@ -456,13 +456,12 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
dtSec: 0,
liftM: 0,
});
near(views[0].destination, expected.eye, 1e-6, 'stale eye');
near(views[0].destination, expected.eye, 1e-6, 'first eye');
near(views[0].orientation.direction, expected.forward, 1e-12, 'direction');
near(views[0].orientation.up, expected.up, 1e-12, 'up');
// Live: the anchor coasts 80 ms along the heading and is pulled toward
// where the layer now shows the aircraft.
info.stale = false;
const anchor = Cesium.Cartesian3.clone(expected.anchor);
const moved = Cesium.Cartesian3.fromDegrees(-97.6698, 30.1901, 1210);
owner.trackedFollow.position = () => moved;
@@ -495,38 +494,6 @@ test('Cockpit places the eye at its aircraft as the Cesium maths did', async ()
}
});
test("a live aircraft's first Cockpit update stands the anchor on it", async () => {
const Cesium = await import('cesium');
const env = environment();
try {
const target = Cesium.Cartesian3.fromDegrees(-97.67, 30.19, 1200);
const info = {
icao24: 'abc123',
layerId: 'flights',
track: 72,
velocityMps: 200,
latitude: 30.19,
longitude: -97.67,
onGround: false,
stale: false,
};
const { owner, views } = cockpitOver({ info, target });
// Entry was a while ago: the step would carry the anchor 20 m ahead.
owner.update();
const expected = cesiumCockpitEye(Cesium, {
target,
info: { ...info, stale: true },
heading: 72,
dtSec: 0,
liftM: 0,
});
near(views[0].destination, expected.eye, 1e-6, 'first live eye');
owner.dispose();
} finally {
env.restore();
}
});
test('a grounded Cockpit probes the mesh from the camera and keeps the eye above the floor', async () => {
const Cesium = await import('cesium');
const env = environment();
+2 -2
View File
@@ -56,8 +56,8 @@ export function pushCockpitSignal(
{ inPlace = false } = {},
) {
if (!title || !detail) return;
// JSON keeps the fields apart: joined with `|`, a title or detail holding a
// `|` read as another pair. An in-place row also changes with its tone alone.
// JSON, not a joined string, so a separator inside a title or detail cannot
// make two rows match. An in-place row also changes with its tone alone.
const signature = JSON.stringify([
title,
detail,
+92 -15
View File
@@ -219,22 +219,20 @@ function fixture(
showBriefPage() {},
startBriefRotation() {},
stopBriefRotation() {},
pushCockpitSignal(key, tone, title, detail) {
signals.push({ key, tone, title, detail });
},
dropCockpitSignal(key) {
dropped.push(key);
},
scheduleContextLayout() {},
updateLocalPosition() {},
maybeRefreshRegionalBrief() {},
showContextCard() {},
});
if (realSignals) {
// The real Live Signals rows, published, not the recorder above.
delete cockpit.pushCockpitSignal;
delete cockpit.dropCockpitSignal;
}
if (!realSignals)
Object.assign(cockpit, {
pushCockpitSignal(key, tone, title, detail) {
signals.push({ key, tone, title, detail });
},
dropCockpitSignal(key) {
dropped.push(key);
},
});
t.after(() => {
cockpit.stop();
app.unmount();
@@ -297,7 +295,7 @@ const lastRelease = (calls) => calls.findLast(([name]) => name === 'release');
/**
* Move `ride`'s subject east at `speedMps` from `startMs` (the manual clock's
* start) on an inertial anchor, its frame otherwise as it was with `extra`
* on top; returns where it is now (longitude).
* on top; returns a function giving its longitude now.
*/
function movingEast(ride, startMs, speedMps, extra = {}) {
const eastNow = () =>
@@ -1355,9 +1353,7 @@ test("a moving vessel's first bridge update after entry stands the anchor on its
assert.equal(cockpit.enter(), true);
clock.advance(1000);
cockpit.update();
const anchor = Cesium.Cartographic.fromCartesian(
Cesium.Cartesian3.clone(cockpit.cockpitAnchor),
);
const anchor = Cesium.Cartographic.fromCartesian(cockpit.cockpitAnchor);
const fix = cockpit.vesselFix;
const gapM = Cesium.Cartesian3.distance(
Cesium.Cartesian3.fromRadians(anchor.longitude, anchor.latitude, 0),
@@ -1564,3 +1560,84 @@ test('an inertial subject placed at its entry height stands on the floor once it
`1 s after the floor came the eye is at ${heightM.toFixed(2)} m, not ${floorM + 3.5} m`,
);
});
/** How far east of LON the camera's last shot is (m). */
const shotEastM = (shots) =>
(Cesium.Math.toDegrees(
Cesium.Cartographic.fromCartesian(shots.at(-1).destination).longitude,
) -
LON) *
M_PER_DEG_LON;
test('the first floor after an entry height moves an inertial anchor as a cold floor does', async (t) => {
// The provider corrects its subject 100 m east as the floor arrives.
const run = (warm) => {
const clock = manualClock(t, 10_000);
const ride = subjectProvider();
ride.subject.frame = {
...ride.subject.frame,
heightM: FLOOR_M,
speedMps: 0,
anchor: 'inertial',
groundClamp: false,
};
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
ride.subject.frame = { ...ride.subject.frame, heightM: null };
clock.advance(100);
cockpit.update();
const beforeM = shotEastM(shots);
ride.subject.frame = { ...ride.subject.frame, longitude: eastM(100) };
if (warm) setFloor(FLOOR_M + 0.1);
clock.advance(100);
cockpit.update();
const stepM = shotEastM(shots) - beforeM;
const heightM = shotHeight(shots);
cockpit.stop();
return { stepM, heightM };
};
const cold = run(false);
const warm = run(true);
assert.ok(
Math.abs(warm.stepM - cold.stepM) < 0.02,
`east step ${warm.stepM.toFixed(3)} m with the floor arriving, ${cold.stepM.toFixed(3)} m with it cold`,
);
assert.ok(Math.abs(warm.heightM - (FLOOR_M + 0.1 + 3.5)) < 0.02);
});
test('the first floor after an entry height never steps an inertial anchor back to a held fix', async (t) => {
const startMs = 10_000;
const clock = manualClock(t, startMs);
const ride = subjectProvider();
const base = {
...ride.subject.frame,
heightM: FLOOR_M,
speedMps: 30,
anchor: 'inertial',
groundClamp: false,
};
ride.subject.frame = base;
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
setFloor(undefined);
cockpit.syncEntry();
assert.equal(cockpit.enter(), true);
// Telemetry that gives a new fix once a second, 30 m on each time.
ride.subject.frame = () => ({
...base,
heightM: null,
longitude: eastM(30 * Math.floor((performance.now() - startMs) / 1000)),
});
for (let i = 0; i < 17; i += 1) {
clock.advance(100);
cockpit.update();
}
const beforeM = shotEastM(shots);
// The floor arrives 1 cm off the entry height, between two fixes.
setFloor(FLOOR_M + 0.01);
clock.advance(100);
cockpit.update();
const stepM = shotEastM(shots) - beforeM;
assert.ok(stepM > 0, `the eye stepped ${stepM.toFixed(2)} m east`);
});