mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
Stand an inertial subject on its floor once the floor arrives
- The first floor height that replaces the entry frame's height re-anchors the camera and resets the smoothed rise, so the subject stands on the floor within a second instead of hovering above it. - A provider's thenable gets one rejection handler; frame fields and eye are read once each. - A progress label's width counts the smaller detail line and full-width and astral glyphs. - Tests cover the first camera update of an aircraft and a vessel, a double-click on a selected vessel, a tone-only Live Signals change and a getter that throws on its second read; repeated cases share helpers. - Comments, the release note and CURRENT-STATE say which height the camera holds while it waits for the surface and how a Live Signals row keeps its time.
This commit is contained in:
1 parent
109bb0fd4f
commit
c190e662bc
13 files changed
+314
-211
No files matched your search
+16
-5
@@ -357,6 +357,7 @@ function updateSubject(nowMs) {
|
||||
}
|
||||
this.lastSubjectFrame = frame;
|
||||
let heightM = frame.heightM;
|
||||
let held = false;
|
||||
if (heightM === null) {
|
||||
this.services.warmGroundFloor?.([
|
||||
{ lat: frame.latitude, lon: frame.longitude },
|
||||
@@ -366,8 +367,10 @@ function updateSubject(nowMs) {
|
||||
frame.longitude,
|
||||
);
|
||||
// A frame with no height stands on the shared floor; while that is cold
|
||||
// it keeps the last height it had, the entry frame's included.
|
||||
heightM = Number.isFinite(floorM) ? floorM : this.subjectHeightM;
|
||||
// the eye keeps the last height it stood at (a frame's or the floor's),
|
||||
// at first the entry frame's.
|
||||
held = !Number.isFinite(floorM);
|
||||
heightM = held ? this.subjectHeightM : floorM;
|
||||
}
|
||||
if (!Number.isFinite(heightM)) {
|
||||
// Nothing to stand on yet, from the first frame: the camera stays where
|
||||
@@ -399,6 +402,14 @@ 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;
|
||||
this.subjectHeightFromEntry = false;
|
||||
}
|
||||
this.subjectHeightM = heightM;
|
||||
const target = fromDegrees(frame.longitude, frame.latitude, heightM);
|
||||
const dtSec = cockpitSubjectStepSec(nowMs - this.lastFrameMs, intervalMs);
|
||||
@@ -461,11 +472,11 @@ function updateSubject(nowMs) {
|
||||
* Aircraft pass none and look along the heading at the profile pitch.
|
||||
*/
|
||||
function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
|
||||
// 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.
|
||||
// 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.
|
||||
const anchoring = !this.cockpitAnchorValid;
|
||||
if (anchoring) {
|
||||
this.cockpitAnchor = clone(target);
|
||||
this.cockpitAnchorValid = true;
|
||||
this.subjectLiftM = null;
|
||||
}
|
||||
|
||||
@@ -194,11 +194,10 @@ export class CockpitViewController {
|
||||
this.surfaceWaitStartedMs = 0;
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
/**
|
||||
* The last height an application subject's frame gave, the entry frame's
|
||||
* included (m).
|
||||
*/
|
||||
/** The height an application subject's eye last stood at (m). */
|
||||
this.subjectHeightM = null;
|
||||
/** Whether `subjectHeightM` is still the one its entry frame gave. */
|
||||
this.subjectHeightFromEntry = false;
|
||||
/** The ground clamp's eased lift under that subject's eye (m). */
|
||||
this.subjectLiftM = null;
|
||||
/**
|
||||
|
||||
@@ -495,6 +495,38 @@ 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();
|
||||
|
||||
@@ -262,7 +262,6 @@ function updateSubjectHud(info, nowMs, forceContext) {
|
||||
for (const key of this.subjectSignalKeys ?? [])
|
||||
if (!keys.has(key)) this.dropCockpitSignal(key);
|
||||
this.subjectSignalKeys = keys;
|
||||
// The view's rows are its current signals, each changed in place.
|
||||
for (const signal of hud.signals)
|
||||
this.pushCockpitSignal(
|
||||
`subject:${signal.id}`,
|
||||
|
||||
@@ -43,8 +43,9 @@ export function publishCockpitSignals() {
|
||||
* Log a signal as the newest row, unless its key last said the same.
|
||||
* @param {{inPlace?: boolean}} [options] `inPlace`: a status row, such as a
|
||||
* provider's, that changes where it stands rather than log a new row, so a
|
||||
* changing ETA never pushes a steady warning off the list; it keeps the
|
||||
* time it first appeared, and comes back if newer rows pushed it off.
|
||||
* changing ETA never pushes a steady warning off the list; it keeps its
|
||||
* time while it stays listed, and one pushed off comes back as the newest
|
||||
* row.
|
||||
*/
|
||||
export function pushCockpitSignal(
|
||||
key,
|
||||
@@ -55,8 +56,8 @@ export function pushCockpitSignal(
|
||||
{ inPlace = false } = {},
|
||||
) {
|
||||
if (!title || !detail) return;
|
||||
// Each field on its own, so no title and detail read as another pair; an
|
||||
// in-place row also changes with its tone alone.
|
||||
// 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.
|
||||
const signature = JSON.stringify([
|
||||
title,
|
||||
detail,
|
||||
|
||||
@@ -127,7 +127,10 @@ function subjectProvider(overrides = {}) {
|
||||
return { definition, subject, calls };
|
||||
}
|
||||
|
||||
function fixture(t, { providers = [], vessel = null, layerOn = true } = {}) {
|
||||
function fixture(
|
||||
t,
|
||||
{ providers = [], vessel = null, layerOn = true, realSignals = false } = {},
|
||||
) {
|
||||
document.body.replaceChildren();
|
||||
const host = document.body.appendChild(document.createElement('div'));
|
||||
const pinia = createPinia();
|
||||
@@ -208,6 +211,7 @@ function fixture(t, { providers = [], vessel = null, layerOn = true } = {}) {
|
||||
instruments: (view) => store.publishInstruments(view),
|
||||
route: (view) => store.publishRoute(view),
|
||||
radar: (view) => store.publishRadar(view),
|
||||
signals: realSignals ? (view) => store.publishSignals(view) : undefined,
|
||||
},
|
||||
});
|
||||
Object.assign(cockpit, {
|
||||
@@ -226,6 +230,11 @@ function fixture(t, { providers = [], vessel = null, layerOn = true } = {}) {
|
||||
maybeRefreshRegionalBrief() {},
|
||||
showContextCard() {},
|
||||
});
|
||||
if (realSignals) {
|
||||
// The real Live Signals rows, published, not the recorder above.
|
||||
delete cockpit.pushCockpitSignal;
|
||||
delete cockpit.dropCockpitSignal;
|
||||
}
|
||||
t.after(() => {
|
||||
cockpit.stop();
|
||||
app.unmount();
|
||||
@@ -285,6 +294,25 @@ async function settle() {
|
||||
/** The provider's last release call. */
|
||||
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).
|
||||
*/
|
||||
function movingEast(ride, startMs, speedMps, extra = {}) {
|
||||
const eastNow = () =>
|
||||
eastM((speedMps * (performance.now() - startMs)) / 1000);
|
||||
const base = ride.subject.frame;
|
||||
ride.subject.frame = () => ({
|
||||
...base,
|
||||
longitude: eastNow(),
|
||||
speedMps,
|
||||
anchor: 'inertial',
|
||||
...extra,
|
||||
});
|
||||
return eastNow;
|
||||
}
|
||||
|
||||
/** The camera's height above the ellipsoid in its last shot (m). */
|
||||
const shotHeight = (shots) =>
|
||||
Cesium.Cartographic.fromCartesian(shots.at(-1).destination).height;
|
||||
@@ -614,16 +642,7 @@ test('an inertial subject drawn at 5 frames a second stays near its target', asy
|
||||
const startMs = 10_000;
|
||||
const clock = manualClock(t, startMs);
|
||||
const ride = subjectProvider();
|
||||
const SPEED_MPS = 30;
|
||||
const eastNow = () =>
|
||||
eastM((SPEED_MPS * (performance.now() - startMs)) / 1000);
|
||||
const base = ride.subject.frame;
|
||||
ride.subject.frame = () => ({
|
||||
...base,
|
||||
longitude: eastNow(),
|
||||
speedMps: SPEED_MPS,
|
||||
anchor: 'inertial',
|
||||
});
|
||||
const eastNow = movingEast(ride, startMs, 30);
|
||||
const { cockpit, shots } = fixture(t, { providers: [ride] });
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
@@ -639,53 +658,38 @@ test('an inertial subject drawn at 5 frames a second stays near its target', asy
|
||||
);
|
||||
});
|
||||
|
||||
for (const [intervalMs, waitMs] of [
|
||||
[0, 1000],
|
||||
[500, 2000],
|
||||
]) {
|
||||
test(`an inertial subject's first camera update after a ${waitMs} ms floor wait (interval ${intervalMs} ms) stands on it`, async (t) => {
|
||||
const startMs = 10_000;
|
||||
const clock = manualClock(t, startMs);
|
||||
const SPEED_MPS = 30;
|
||||
const eastNow = () =>
|
||||
eastM((SPEED_MPS * (performance.now() - startMs)) / 1000);
|
||||
const ride = subjectProvider({ cameraIntervalMs: intervalMs });
|
||||
const base = ride.subject.frame;
|
||||
ride.subject.frame = () => ({
|
||||
...base,
|
||||
heightM: null,
|
||||
longitude: eastNow(),
|
||||
speedMps: SPEED_MPS,
|
||||
anchor: 'inertial',
|
||||
eye: { ...base.eye, forwardM: 0 },
|
||||
});
|
||||
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
|
||||
setFloor(undefined);
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
const before = shots.length;
|
||||
const stepMs = intervalMs || 100;
|
||||
for (let waited = stepMs; waited < waitMs; waited += stepMs) {
|
||||
clock.advance(stepMs);
|
||||
cockpit.update();
|
||||
}
|
||||
assert.equal(
|
||||
shots.length,
|
||||
before,
|
||||
'no camera update while the floor is cold',
|
||||
);
|
||||
setFloor(FLOOR_M);
|
||||
clock.advance(stepMs);
|
||||
test("an inertial subject's first camera update after a floor wait longer than its step stands on it", async (t) => {
|
||||
const startMs = 10_000;
|
||||
const clock = manualClock(t, startMs);
|
||||
const intervalMs = 500;
|
||||
const ride = subjectProvider({ cameraIntervalMs: intervalMs });
|
||||
const eastNow = movingEast(ride, startMs, 30, { heightM: null });
|
||||
const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] });
|
||||
setFloor(undefined);
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
const before = shots.length;
|
||||
// 2 s cold: longer than the 1.5 s an update may step.
|
||||
for (let waited = intervalMs; waited < 2000; waited += intervalMs) {
|
||||
clock.advance(intervalMs);
|
||||
cockpit.update();
|
||||
const shot = Cesium.Cartographic.fromCartesian(shots[before].destination);
|
||||
const leadM =
|
||||
(Cesium.Math.toDegrees(shot.longitude) - eastNow()) * M_PER_DEG_LON;
|
||||
assert.ok(
|
||||
Math.abs(leadM) < 1,
|
||||
`the first camera update leads the subject by ${leadM.toFixed(2)} m`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
assert.equal(
|
||||
shots.length,
|
||||
before,
|
||||
'no camera update while the floor is cold',
|
||||
);
|
||||
setFloor(FLOOR_M);
|
||||
clock.advance(intervalMs);
|
||||
cockpit.update();
|
||||
const shot = Cesium.Cartographic.fromCartesian(shots[before].destination);
|
||||
const leadM =
|
||||
(Cesium.Math.toDegrees(shot.longitude) - eastNow()) * M_PER_DEG_LON;
|
||||
assert.ok(
|
||||
Math.abs(leadM) < 1,
|
||||
`the first camera update leads the subject by ${leadM.toFixed(2)} m`,
|
||||
);
|
||||
});
|
||||
|
||||
test('an exact anchor sits on the subject, wherever the frame moves it', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
@@ -1310,6 +1314,8 @@ test("a double-click on the selected vessel does not enter an application's subj
|
||||
everythingAt(t, 100, 100);
|
||||
cockpit.syncEntry();
|
||||
assert.equal(store.presence.entryKind, 'vessel');
|
||||
// The first press of the double-click notes where the vessel is drawn.
|
||||
cockpit.onScenePointerDown();
|
||||
// The application's subject is selected after the vessel: it takes entry.
|
||||
clock.advance(500);
|
||||
ride.subject.candidate = { id: 'a1', name: 'Example 12', selectedAt: 1 };
|
||||
@@ -1342,6 +1348,24 @@ test('the same double-click on the vessel alone enters its bridge', async (t) =>
|
||||
assert.equal(cockpit.subjectKind, 'vessel');
|
||||
});
|
||||
|
||||
test("a moving vessel's first bridge update after entry stands the anchor on its fix", async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const { cockpit } = fixture(t, { vessel: VESSEL });
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
clock.advance(1000);
|
||||
cockpit.update();
|
||||
const anchor = Cesium.Cartographic.fromCartesian(
|
||||
Cesium.Cartesian3.clone(cockpit.cockpitAnchor),
|
||||
);
|
||||
const fix = cockpit.vesselFix;
|
||||
const gapM = Cesium.Cartesian3.distance(
|
||||
Cesium.Cartesian3.fromRadians(anchor.longitude, anchor.latitude, 0),
|
||||
Cesium.Cartesian3.fromDegrees(fix.longitude, fix.latitude, 0),
|
||||
);
|
||||
assert.ok(gapM < 0.01, `the anchor is ${gapM.toFixed(2)} m from the fix`);
|
||||
});
|
||||
|
||||
test('a provider view with look turns with the arrow keys and words its readout', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
@@ -1390,10 +1414,7 @@ test('rows a HUD view no longer lists leave Live Signals', async (t) => {
|
||||
test('a signal still listed stays in Live Signals while another one changes', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
const { cockpit } = fixture(t, { providers: [ride] });
|
||||
// The real Live Signals rows, not the fixture's recorder.
|
||||
delete cockpit.pushCockpitSignal;
|
||||
delete cockpit.dropCockpitSignal;
|
||||
const { cockpit } = fixture(t, { providers: [ride], realSignals: true });
|
||||
// The ETA is logged first, so it stands below the warning.
|
||||
const hudWith = (minutes) => ({
|
||||
...HUD,
|
||||
@@ -1454,17 +1475,19 @@ test('a signal still listed stays in Live Signals while another one changes', as
|
||||
test('a Live Signals row whose tone alone changes takes the new tone', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
const { cockpit } = fixture(t, { providers: [ride] });
|
||||
delete cockpit.pushCockpitSignal;
|
||||
delete cockpit.dropCockpitSignal;
|
||||
const { cockpit, store } = fixture(t, {
|
||||
providers: [ride],
|
||||
realSignals: true,
|
||||
});
|
||||
const hudWith = (tone) => ({
|
||||
...HUD,
|
||||
signals: [
|
||||
{ id: 'doors', tone, title: 'DOORS', detail: 'door fault, car 2' },
|
||||
],
|
||||
});
|
||||
// The class of the row Live Signals shows.
|
||||
const doorsTone = () =>
|
||||
cockpit.signalItems.find((row) => row.key === 'subject:doors').tone;
|
||||
store.signals.find((row) => row.title === 'DOORS').className;
|
||||
ride.subject.hud = hudWith('normal');
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
@@ -1481,9 +1504,7 @@ test('a Live Signals row whose tone alone changes takes the new tone', async (t)
|
||||
test('rows a HUD view replaces leave before new ones push a listed one off', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
const { cockpit } = fixture(t, { providers: [ride] });
|
||||
delete cockpit.pushCockpitSignal;
|
||||
delete cockpit.dropCockpitSignal;
|
||||
const { cockpit } = fixture(t, { providers: [ride], realSignals: true });
|
||||
const row = (id, tone) => ({
|
||||
id,
|
||||
tone,
|
||||
@@ -1510,3 +1531,36 @@ test('rows a HUD view replaces leave before new ones push a listed one off', asy
|
||||
`rows right after the change: ${keys.join(', ')}`,
|
||||
);
|
||||
});
|
||||
|
||||
// An inertial subject placed at its entry frame's height while the floor was
|
||||
// cold stands on the floor as soon as it warms, as an exact anchor does.
|
||||
test('an inertial subject placed at its entry height stands on the floor once it warms', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
ride.subject.frame = {
|
||||
...ride.subject.frame,
|
||||
heightM: FLOOR_M,
|
||||
speedMps: 0,
|
||||
anchor: 'inertial',
|
||||
eye: { ...ride.subject.frame.eye, forwardM: 0 },
|
||||
};
|
||||
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();
|
||||
assert.ok(Math.abs(shotHeight(shots) - (FLOOR_M + 3.5)) < 0.01);
|
||||
const floorM = FLOOR_M - 100;
|
||||
setFloor(floorM);
|
||||
for (let i = 0; i < 10; i += 1) {
|
||||
clock.advance(100);
|
||||
cockpit.update();
|
||||
}
|
||||
const heightM = shotHeight(shots);
|
||||
assert.ok(
|
||||
Math.abs(heightM - (floorM + 3.5)) < 1,
|
||||
`1 s after the floor came the eye is at ${heightM.toFixed(2)} m, not ${floorM + 3.5} m`,
|
||||
);
|
||||
});
|
||||
@@ -516,9 +516,10 @@ function enterSubject(provider) {
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
this.cockpitAnchorValid = false;
|
||||
// A height the entry frame gave is where the eye stands until a later frame
|
||||
// or the warmed floor gives another.
|
||||
// The entry frame's height, if any, stands in for a cold floor
|
||||
// (updateSubject).
|
||||
this.subjectHeightM = frame.heightM;
|
||||
this.subjectHeightFromEntry = true;
|
||||
this.lookRestPitchDeg = provider.look?.restPitchDeg ?? null;
|
||||
this.resetLook({ immediate: true });
|
||||
this.active = true;
|
||||
|
||||
Reference in new issue
Block a user