mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c190e662bc | ||
|
|
109bb0fd4f | ||
|
|
a72c0ba237 | ||
|
|
c2f73cdc04 | ||
|
|
5cc217dd1c | ||
|
|
a2a61c506f |
No files matched your search
@@ -3,10 +3,11 @@
|
||||
heading and HUD (in the page's language, via `getLocale` and
|
||||
`onLocaleChange` from `./i18n`); the camera can follow it without the
|
||||
ground clamp, anchored exactly on it, and a generic HUD adds source rows, a
|
||||
banner, a veil (off under reduced motion) and a bottom progress line. The
|
||||
Rail and Transit layers expose read and hold APIs so a selected train or
|
||||
vehicle can be ridden, and `./layers/rail/paths` is exported; that export
|
||||
and the read APIs are experimental. `docs/APPLICATION.md` shows a minimal
|
||||
provider. GEV itself registers none, and entry to the built-in aircraft,
|
||||
satellite and vessel views is unchanged; a provider's subject takes entry
|
||||
when it was selected after them (Denis Groshev, @ZloyS, #1686).
|
||||
banner, a veil (its light streaks stand still under reduced motion) and a
|
||||
bottom progress line. The Rail and Transit layers expose read and hold APIs
|
||||
so a selected train or vehicle can be ridden, and `./layers/rail/paths` is
|
||||
exported; that export and the read APIs are experimental.
|
||||
`docs/APPLICATION.md` shows a minimal provider. GEV itself registers none,
|
||||
and entry to the built-in aircraft, satellite and vessel views is
|
||||
unchanged; a provider's subject takes entry when it was selected after them
|
||||
(Denis Groshev, @ZloyS, #1686).
|
||||
@@ -0,0 +1,10 @@
|
||||
- Keep an application's Cockpit subject steady. A subject whose entry frame
|
||||
gives a height stands there until a later frame or the floor under it gives
|
||||
another, so the view no longer ends while the floor loads. The camera keeps
|
||||
up when the browser draws few frames: at 5 frames a second it used to fall
|
||||
700 m behind a 30 m/s subject in a minute. A provider's Live Signals rows
|
||||
change where they stand, their tone included, and rows it drops leave
|
||||
before new ones come in, so a changing ETA or a replaced row no longer
|
||||
pushes a steady warning off the list. Progress labels give CJK, kana and
|
||||
Hangul names the width they need. Labels, entry face and look keep their
|
||||
last good words when a later read fails (German, @gekh, #1787).
|
||||
+3
-1
@@ -396,7 +396,9 @@ their `this`; one that throws or returns a promise is treated as having
|
||||
failed. What a method returns may carry getters: one that throws when read
|
||||
makes a candidate none, a frame malformed (the view ends) and a HUD view keep
|
||||
the last; a worded member (labels, entry face, look) that throws keeps its
|
||||
last good words.
|
||||
last good words. An entry face's `icon` is a Material Symbols name whose glyph
|
||||
the application's page must load (GEV's own `index.html` loads a subset, its
|
||||
`icon_names`); a glyph the page does not load renders as its name.
|
||||
|
||||
```js
|
||||
import { getLocale, onLocaleChange } from 'gods-eye-view/i18n';
|
||||
|
||||
+17
-8
@@ -2743,28 +2743,37 @@ first in that order decides alone: when its gate is shut there is no entry
|
||||
rather than the next subject's.
|
||||
|
||||
A frame places the eye `eye.upM` above `heightM` (the shared floor where the
|
||||
frame gives none, or where it last stood while that floor is cold; with
|
||||
neither, the camera stays where it is and the HUD reads ACQUIRING SURFACE for
|
||||
frame gives none, or, while that floor is cold, the last height the eye stood
|
||||
at, a frame's or the floor's, at first the entry frame's; with neither, the camera stays where it is and the HUD reads ACQUIRING SURFACE for
|
||||
at most `COCKPIT_GROUND_WAIT_TIMEOUT_MS`, after which the view ends and the
|
||||
subject is released: no height stands in for a floor never read), slews toward `headingDeg` at the provider's rate, and may
|
||||
turn off the floor clamps (`groundClamp: false`, for a subject inside a
|
||||
structure) or keep the anchor exactly on the subject (`anchor: 'exact'`, for a
|
||||
layer that already moves it smoothly; a frame with no `speedMps` is always
|
||||
exact, since an inertial anchor runs on at the frame's speed); `cameraIntervalMs: 0` updates the
|
||||
camera every rendered frame. A frame that is null, malformed or for another
|
||||
camera every rendered frame. Each update turns the view, eases its lift and
|
||||
moves an inertial anchor by the time since the last one, at most a second past
|
||||
the interval (`cockpitSubjectStepSec`); an exact anchor stands where the frame
|
||||
is. The first update after entry (after any floor wait) stands its anchor on
|
||||
the subject, as does the first to replace the entry frame's height with
|
||||
another. A frame that is null, malformed or for another
|
||||
subject ends the view (`restoreTracking: false`), as an aircraft tracked
|
||||
meanwhile and the provider's layer turning off do; the exit control asks the
|
||||
provider to restore its subject. The generic HUD shows the provider's kicker,
|
||||
title, meta line, speed with its unit and tag, readout cards, always-visible
|
||||
source rows, banner, route card and Live Signals rows, a veil that darkens the
|
||||
picture under the HUD (with passing light streaks, which stop under reduced
|
||||
motion), arrow-key look-around when the provider asks for it, and a progress
|
||||
source rows, banner, route card and Live Signals rows (each changes in place,
|
||||
its tone included, and keeps its time while it stays listed; one pushed off
|
||||
comes back as the newest row; rows the view no longer lists leave before new
|
||||
ones come in), a veil that darkens the
|
||||
picture under the HUD (with passing light streaks, which stand still under
|
||||
reduced motion), arrow-key look-around when the provider asks for it, and a progress
|
||||
line along the bottom edge (`src/cockpitProgress.js`: close ticks merge,
|
||||
labels never overlap). Core translates none of the provider's text: a host
|
||||
labels never overlap and are sized for CJK, kana and Hangul). Core translates none of the provider's text: a host
|
||||
words it for the page's language (`gods-eye-view/i18n`:
|
||||
`getLocale`, `onLocaleChange`). Its entry face, labels and look may be
|
||||
functions, read again when they are shown and on a change of language, as the
|
||||
HUD view is.
|
||||
HUD view is; a read that throws or is malformed keeps the last good words, at
|
||||
first those checked when the provider was registered.
|
||||
|
||||
The Rail layer offers a read API for such a view: `getSelectedTrain()` and
|
||||
`getCockpitSubject()` (a snapshot of the train: where it is along its line,
|
||||
|
||||
+7
-4
@@ -58,12 +58,15 @@ export function cockpitAnchorCorrectionStep(
|
||||
return Math.min(distanceM, eased, correctionRateMps * dt);
|
||||
}
|
||||
|
||||
/** How late past its interval an update may come and still count in full. */
|
||||
const COCKPIT_SUBJECT_LATE_SEC = 1;
|
||||
|
||||
/**
|
||||
* The seconds an application subject's camera update advances its heading
|
||||
* slew, ground lift and anchor by: the time since the last update, at most
|
||||
* its update interval plus 0.1 s. A subject updated every 500 ms then turns
|
||||
* and eases at its configured rates, while a long stall (a hidden tab) still
|
||||
* moves it no further than one late update would.
|
||||
* its interval plus COCKPIT_SUBJECT_LATE_SEC. A subject updated every 500 ms,
|
||||
* or a browser drawing 5 frames a second, then keeps up, while a long stall
|
||||
* (a hidden tab) counts as one late update.
|
||||
* @param {number} elapsedMs Time since the last camera update.
|
||||
* @param {number} intervalMs The subject's update interval (0: every frame).
|
||||
* @returns {number}
|
||||
@@ -75,7 +78,7 @@ export function cockpitSubjectStepSec(elapsedMs, intervalMs) {
|
||||
const intervalSec = Number.isFinite(intervalMs)
|
||||
? Math.max(0, intervalMs) / 1000
|
||||
: 0;
|
||||
return Math.min(intervalSec + 0.1, elapsedSec);
|
||||
return Math.min(intervalSec + COCKPIT_SUBJECT_LATE_SEC, elapsedSec);
|
||||
}
|
||||
|
||||
/** Return whether a throttled cockpit presentation update is due. */
|
||||
|
||||
@@ -73,12 +73,15 @@ test('an application subject steps by its interval, never by a long stall', () =
|
||||
assert.equal(cockpitSubjectStepSec(16, 0), 0.016);
|
||||
assert.equal(cockpitSubjectStepSec(500, 500), 0.5);
|
||||
assert.equal(cockpitSubjectStepSec(520, 500), 0.52);
|
||||
// A hidden tab's minutes count as one late update.
|
||||
assert.equal(cockpitSubjectStepSec(60_000, 500), 0.6);
|
||||
assert.equal(cockpitSubjectStepSec(60_000, 0), 0.1);
|
||||
// Slow frames (5 a second) count in full...
|
||||
assert.equal(cockpitSubjectStepSec(200, 50), 0.2);
|
||||
assert.equal(cockpitSubjectStepSec(1000, 0), 1);
|
||||
// ...and a hidden tab's minutes as one late update.
|
||||
assert.equal(cockpitSubjectStepSec(60_000, 500), 1.5);
|
||||
assert.equal(cockpitSubjectStepSec(60_000, 0), 1);
|
||||
assert.equal(cockpitSubjectStepSec(-5, 500), 0);
|
||||
assert.equal(cockpitSubjectStepSec(Number.NaN, 500), 0);
|
||||
assert.equal(cockpitSubjectStepSec(1000, Number.NaN), 0.1);
|
||||
assert.equal(cockpitSubjectStepSec(1000, Number.NaN), 1);
|
||||
});
|
||||
|
||||
test('cockpit camera clearance never falls below the rendered ground floor', () => {
|
||||
|
||||
+32
-5
@@ -30,13 +30,40 @@ const TONE_RANK = Object.freeze([
|
||||
const stronger = (a, b) =>
|
||||
TONE_RANK.indexOf(b) > TONE_RANK.indexOf(a) ? b : a;
|
||||
|
||||
/** A label's width estimate (px): its longer line in small capitals. */
|
||||
/** Full-width glyphs in the BMP: CJK, kana, Hangul, full-width forms. */
|
||||
const WIDE_GLYPHS =
|
||||
/[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA960-\uA97F\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFF60\uFFE0-\uFFE6]/g;
|
||||
|
||||
/** What a full-width glyph and any other UTF-16 unit take in a title (px). */
|
||||
const TITLE_PX = Object.freeze({ wide: 10.6, narrow: 6.4 });
|
||||
/** The same in a detail line (px). */
|
||||
const DETAIL_PX = Object.freeze({
|
||||
wide: 10 / 1.2 + 0.6,
|
||||
narrow: 5.8 / 1.2 + 0.6,
|
||||
});
|
||||
|
||||
/**
|
||||
* One line's width (px) in `.cockpit-progress-label` type (cockpitSubject.css:
|
||||
* 10 px, 0.06 em spacing) at the glyph widths `px`: about 1 em a full-width
|
||||
* glyph and 0.58 em each UTF-16 unit of any other, so an astral glyph (an
|
||||
* emoji, a CJK extension) counts as two and an emoji in the BMP (☕) as one,
|
||||
* narrower than it is drawn. The detail line's `<small>` is 1/1.2 the size;
|
||||
* the 0.6 px spacing it inherits is not scaled.
|
||||
*/
|
||||
function lineWidthPx(line, px) {
|
||||
const text = String(line ?? '');
|
||||
const wide = text.match(WIDE_GLYPHS)?.length ?? 0;
|
||||
return wide * px.wide + (text.length - wide) * px.narrow;
|
||||
}
|
||||
|
||||
/** A label's width estimate (px): its wider line and 8 px of padding. */
|
||||
export function estimateProgressLabelPx(label) {
|
||||
const longest = Math.max(
|
||||
String(label?.text ?? '').length,
|
||||
String(label?.detail ?? '').length,
|
||||
return (
|
||||
Math.max(
|
||||
lineWidthPx(label?.text, TITLE_PX),
|
||||
lineWidthPx(label?.detail, DETAIL_PX),
|
||||
) + 8
|
||||
);
|
||||
return longest * 6.4 + 8;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
// the travelled part.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { cockpitProgressLayout } from './cockpitProgress.js';
|
||||
import {
|
||||
cockpitProgressLayout,
|
||||
estimateProgressLabelPx,
|
||||
} from './cockpitProgress.js';
|
||||
|
||||
const tick = (at, label = null, tone = 'normal') => ({ at, tone, label });
|
||||
const label = (text, priority, align = 'center', detail = '') => ({
|
||||
@@ -142,3 +145,59 @@ test('a long run of calls still lays out, every one a tick or part of one', () =
|
||||
assert.ok(narrow.ticks.length < wide.ticks.length);
|
||||
assert.equal(wide.ticks.length, 60);
|
||||
});
|
||||
|
||||
test('a CJK stop name gets the width its full-width glyphs need', () => {
|
||||
const text = '中央駅前広場東口'; // 8 full-width glyphs
|
||||
// 10 px type, 0.06 em apart.
|
||||
const needPx = text.length * (10 + 0.6);
|
||||
const givenPx = estimateProgressLabelPx({ text, detail: '' });
|
||||
assert.ok(
|
||||
givenPx >= needPx,
|
||||
`${givenPx} px given, about ${needPx} px needed`,
|
||||
);
|
||||
// As many Latin letters are narrower; half-width katakana are as narrow.
|
||||
assert.ok(givenPx > estimateProgressLabelPx({ text: 'CENTRALS' }));
|
||||
assert.equal(
|
||||
estimateProgressLabelPx({ text: 'カタカナ' }),
|
||||
estimateProgressLabelPx({ text: 'KANA' }),
|
||||
);
|
||||
});
|
||||
|
||||
test('emoji and other astral glyphs in a progress label get at least 1 em each', () => {
|
||||
// About 1 em in 10 px type, 0.06 em apart.
|
||||
const emPx = 10 + 0.6;
|
||||
for (const [text, needPx] of [
|
||||
['🚉🚆🚇🚋', 4 * emPx],
|
||||
['🚆'.repeat(8), 8 * emPx],
|
||||
// Supplementary kana, outside the full-width ranges.
|
||||
['𛀁𛀂', 2 * emPx],
|
||||
// Mixed: four emoji, a space and two full-width glyphs.
|
||||
['🚆🚇🚌🚕 乗換', 4 * emPx + 6.4 + 2 * emPx],
|
||||
]) {
|
||||
const givenPx = estimateProgressLabelPx({ text, detail: '' });
|
||||
assert.ok(
|
||||
givenPx >= needPx + 8,
|
||||
`${text}: ${givenPx} px given, about ${needPx} px needed`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('a label is as wide as its wider line, its smaller detail line included', () => {
|
||||
// The detail line's <small> is 1/1.2 of 10 px; its 0.6 px spacing is not.
|
||||
const detailEmPx = 10 / 1.2 + 0.6;
|
||||
const detail = '中央駅前'; // 4 full-width glyphs
|
||||
const givenPx = estimateProgressLabelPx({ text: 'GATE', detail });
|
||||
assert.ok(
|
||||
givenPx > estimateProgressLabelPx({ text: 'GATE', detail: '' }),
|
||||
'the wider detail line widens the label',
|
||||
);
|
||||
assert.ok(
|
||||
givenPx >= detail.length * detailEmPx + 8,
|
||||
`${givenPx} px given, about ${detail.length * detailEmPx} px needed`,
|
||||
);
|
||||
// A line takes less room as the smaller detail than as the title.
|
||||
assert.ok(
|
||||
estimateProgressLabelPx({ text: 'A', detail: 'CENTRAL STATION' }) <
|
||||
estimateProgressLabelPx({ text: 'CENTRAL STATION', detail: '' }),
|
||||
);
|
||||
});
|
||||
@@ -117,20 +117,26 @@ function lookOf(raw) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Promises worded members gave, each one's rejection caught once. */
|
||||
const caughtWords = new WeakSet();
|
||||
|
||||
/**
|
||||
* A provider's worded member `key` as it reads now, normalized: the value,
|
||||
* or what the function it is returns when called on `provider` (so it can
|
||||
* follow the page's language); null when it is malformed or a read throws.
|
||||
* Reading the member, and reading what it gives, runs provider code too (a
|
||||
* getter), so both are guarded as the call is.
|
||||
* A worded member as `read()` gives it, normalized: called on `provider`
|
||||
* when it is a function (so it can follow the page's language); null when it
|
||||
* is malformed (a promise too) or provider code throws.
|
||||
*/
|
||||
function wordedNow(provider, key, normalize) {
|
||||
function worded(provider, read, normalize) {
|
||||
try {
|
||||
const value = provider[key];
|
||||
return (
|
||||
normalize(typeof value === 'function' ? value.call(provider) : value) ??
|
||||
null
|
||||
);
|
||||
const value = read();
|
||||
const words = typeof value === 'function' ? value.call(provider) : value;
|
||||
if (typeof words?.then === 'function') {
|
||||
if (!caughtWords.has(words)) {
|
||||
caughtWords.add(words);
|
||||
Promise.resolve(words).catch(() => {});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return normalize(words) ?? null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -146,7 +152,7 @@ function providerName(provider, order) {
|
||||
return `#${order}`;
|
||||
}
|
||||
|
||||
/** Why `provider` cannot be kept, or null. */
|
||||
/** Why `provider` cannot be kept, its worded members aside, or null. */
|
||||
function refusal(provider, kinds) {
|
||||
if (!isObject(provider)) return 'not an object';
|
||||
if (typeof provider.kind !== 'string' || !KIND_PATTERN.test(provider.kind))
|
||||
@@ -165,14 +171,25 @@ function refusal(provider, kinds) {
|
||||
typeof provider.isEntryAllowed !== 'function'
|
||||
)
|
||||
return 'isEntryAllowed is not a function';
|
||||
if (!wordedNow(provider, 'entryFace', faceOf)) return 'malformed entry face';
|
||||
if (!wordedNow(provider, 'labels', labelsOf))
|
||||
return 'labels need view, exit and exitText';
|
||||
if (provider.look != null && !wordedNow(provider, 'look', lookOf))
|
||||
return 'look needs an aheadLabel';
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A provider's worded members, each read once, to seed its copy (so one that
|
||||
* fails when read again cannot undo this check), or why one is malformed.
|
||||
* @returns {{face: object, labels: object, look: ?object}|string}
|
||||
*/
|
||||
function checkedWords(provider) {
|
||||
const face = worded(provider, () => provider.entryFace, faceOf);
|
||||
if (!face) return 'malformed entry face';
|
||||
const labels = worded(provider, () => provider.labels, labelsOf);
|
||||
if (!labels) return 'labels need view, exit and exitText';
|
||||
const lookValue = provider.look;
|
||||
if (lookValue == null) return { face, labels, look: null };
|
||||
const look = worded(provider, () => lookValue, lookOf);
|
||||
return look ? { face, labels, look } : 'look needs an aheadLabel';
|
||||
}
|
||||
|
||||
/**
|
||||
* The application's subject providers, checked once and frozen, in the order
|
||||
* entry asks them: ascending `priority`, ties in list order. Each has
|
||||
@@ -191,7 +208,8 @@ function refusal(provider, kinds) {
|
||||
* object: it is called on the provider again whenever they are shown and
|
||||
* when the page's language changes, so its words can follow it
|
||||
* (`./i18n`). A read that throws or is malformed keeps the last
|
||||
* good one; `look` is on or off and `restPitchDeg` fixed as first read;
|
||||
* good one; `look` is on or off and `restPitchDeg` fixed as read at
|
||||
* registration;
|
||||
* - `cameraIntervalMs` (optional): 0..1000, null for the Cockpit's default; 0
|
||||
* updates the camera every rendered frame;
|
||||
* - `headingSlewDps` (optional): how fast the view turns to a new heading,
|
||||
@@ -224,7 +242,11 @@ export function cockpitSubjectProviders(
|
||||
let copy = null;
|
||||
try {
|
||||
reason = refusal(provider, kinds);
|
||||
if (!reason) copy = keptProvider(provider, order);
|
||||
if (!reason) {
|
||||
const words = checkedWords(provider);
|
||||
if (typeof words === 'string') reason = words;
|
||||
else copy = keptProvider(provider, order, words);
|
||||
}
|
||||
} catch {
|
||||
reason = 'a member threw when read';
|
||||
}
|
||||
@@ -241,14 +263,13 @@ export function cockpitSubjectProviders(
|
||||
return Object.freeze(kept);
|
||||
}
|
||||
|
||||
/** The frozen copy the Cockpit keeps of a provider `refusal` passed. */
|
||||
function keptProvider(provider, order) {
|
||||
// Worded members are read again on each use (see above); the last good
|
||||
// read stands in for one that is malformed or throws.
|
||||
let face = wordedNow(provider, 'entryFace', faceOf);
|
||||
let labels = wordedNow(provider, 'labels', labelsOf);
|
||||
// On or off, and its rest pitch, as first read.
|
||||
let look = wordedNow(provider, 'look', lookOf);
|
||||
/**
|
||||
* The frozen copy the Cockpit keeps of a provider that passed `refusal`,
|
||||
* seeded with the worded members `checkedWords` read.
|
||||
*/
|
||||
function keptProvider(provider, order, words) {
|
||||
let { face, labels, look } = words;
|
||||
// Look stays on or off, at its rest pitch, as read at registration.
|
||||
const restPitchDeg = look?.restPitchDeg ?? 0;
|
||||
return Object.freeze({
|
||||
kind: provider.kind,
|
||||
@@ -256,16 +277,16 @@ function keptProvider(provider, order) {
|
||||
priority: finite(provider.priority) ? provider.priority : 0,
|
||||
order,
|
||||
get entryFace() {
|
||||
face = wordedNow(provider, 'entryFace', faceOf) ?? face;
|
||||
face = worded(provider, () => provider.entryFace, faceOf) ?? face;
|
||||
return face;
|
||||
},
|
||||
get labels() {
|
||||
labels = wordedNow(provider, 'labels', labelsOf) ?? labels;
|
||||
labels = worded(provider, () => provider.labels, labelsOf) ?? labels;
|
||||
return labels;
|
||||
},
|
||||
get look() {
|
||||
if (!look) return null;
|
||||
const now = wordedNow(provider, 'look', lookOf);
|
||||
const now = worded(provider, () => provider.look, lookOf);
|
||||
if (now)
|
||||
look = Object.freeze({ restPitchDeg, aheadLabel: now.aheadLabel });
|
||||
return look;
|
||||
@@ -335,11 +356,11 @@ function candidateOf(raw) {
|
||||
* a position that is not finite, an eye with no valid `upM` (0..1000), or a
|
||||
* read of it that throws (a getter runs provider code).
|
||||
* A `heightM` that is not finite or lies outside
|
||||
* COCKPIT_SUBJECT_MIN_HEIGHT_M..COCKPIT_SUBJECT_MAX_HEIGHT_M reads as null:
|
||||
* the eye then stands on the shared floor, or where it last stood while that
|
||||
* is cold. The anchor is `'inertial'` only when asked for and the frame
|
||||
* gives a speed; otherwise it is `'exact'`. An id is compared with `heldId`
|
||||
* trimmed, as `cockpitSubjectCandidate` trims it.
|
||||
* COCKPIT_SUBJECT_MIN_HEIGHT_M..COCKPIT_SUBJECT_MAX_HEIGHT_M reads as null,
|
||||
* for the eye to stand on the shared floor (ui/cockpitCamera.js). The anchor
|
||||
* is `'inertial'` by default for a frame with a valid speed, and `'exact'`
|
||||
* when asked for or with no speed. An id is compared with `heldId` trimmed,
|
||||
* as `cockpitSubjectCandidate` trims it.
|
||||
* @param {unknown} raw What `read()` returned.
|
||||
* @param {string} heldId The subject the view holds.
|
||||
* @returns {object|null} `{id, name, latitude, longitude, heightM, headingDeg,
|
||||
@@ -356,49 +377,57 @@ export function cockpitSubjectFrame(raw, heldId) {
|
||||
}
|
||||
|
||||
function frameOf(raw, heldId) {
|
||||
if (!isObject(raw) || typeof raw.id !== 'string' || raw.id.trim() !== heldId)
|
||||
return null;
|
||||
const latitude = raw.latitude;
|
||||
const longitude = raw.longitude;
|
||||
if (!isObject(raw)) return null;
|
||||
// Each field read once: a getter on the frame runs provider code.
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
latitude,
|
||||
longitude,
|
||||
heightM,
|
||||
headingDeg: rawHeadingDeg,
|
||||
courseDeg,
|
||||
speedMps: rawSpeedMps,
|
||||
stale,
|
||||
groundClamp,
|
||||
anchor,
|
||||
eye: rawEye,
|
||||
} = raw;
|
||||
if (typeof id !== 'string' || id.trim() !== heldId) return null;
|
||||
if (!finite(latitude) || !finite(longitude) || Math.abs(latitude) > 90)
|
||||
return null;
|
||||
const eye = isObject(raw.eye) ? raw.eye : null;
|
||||
if (!eye || !finite(eye.upM) || eye.upM < 0 || eye.upM > 1000) return null;
|
||||
if (!isObject(rawEye)) return null;
|
||||
const { upM, forwardM, pitchDeg, minClearanceM } = rawEye;
|
||||
if (!finite(upM) || upM < 0 || upM > 1000) return null;
|
||||
const heading = (value) =>
|
||||
finite(value) ? ((value % 360) + 360) % 360 : null;
|
||||
const headingDeg = heading(raw.headingDeg);
|
||||
const speedMps =
|
||||
finite(raw.speedMps) && raw.speedMps >= 0 ? raw.speedMps : null;
|
||||
const headingDeg = heading(rawHeadingDeg);
|
||||
const speedMps = finite(rawSpeedMps) && rawSpeedMps >= 0 ? rawSpeedMps : null;
|
||||
return {
|
||||
id: heldId,
|
||||
name: cockpitSubjectText(raw.name, 64) || cockpitSubjectText(heldId, 64),
|
||||
name: cockpitSubjectText(name, 64) || cockpitSubjectText(heldId, 64),
|
||||
latitude,
|
||||
longitude: ((((longitude + 180) % 360) + 360) % 360) - 180,
|
||||
heightM:
|
||||
finite(raw.heightM) &&
|
||||
raw.heightM >= COCKPIT_SUBJECT_MIN_HEIGHT_M &&
|
||||
raw.heightM <= COCKPIT_SUBJECT_MAX_HEIGHT_M
|
||||
? raw.heightM
|
||||
finite(heightM) &&
|
||||
heightM >= COCKPIT_SUBJECT_MIN_HEIGHT_M &&
|
||||
heightM <= COCKPIT_SUBJECT_MAX_HEIGHT_M
|
||||
? heightM
|
||||
: null,
|
||||
headingDeg,
|
||||
courseDeg: heading(raw.courseDeg) ?? headingDeg,
|
||||
courseDeg: heading(courseDeg) ?? headingDeg,
|
||||
speedMps,
|
||||
stale: raw.stale === true,
|
||||
groundClamp: raw.groundClamp !== false,
|
||||
stale: stale === true,
|
||||
groundClamp: groundClamp !== false,
|
||||
// An inertial anchor runs on at the frame's speed; with none it would
|
||||
// close on a moving subject at the correction's floor and fall behind.
|
||||
anchor: raw.anchor === 'exact' || speedMps === null ? 'exact' : 'inertial',
|
||||
anchor: anchor === 'exact' || speedMps === null ? 'exact' : 'inertial',
|
||||
eye: {
|
||||
upM: eye.upM,
|
||||
forwardM:
|
||||
finite(eye.forwardM) && Math.abs(eye.forwardM) <= 500
|
||||
? eye.forwardM
|
||||
: 0,
|
||||
pitchDeg: finite(eye.pitchDeg) ? clamp(eye.pitchDeg, -90, 90) : 0,
|
||||
upM,
|
||||
forwardM: finite(forwardM) && Math.abs(forwardM) <= 500 ? forwardM : 0,
|
||||
pitchDeg: finite(pitchDeg) ? clamp(pitchDeg, -90, 90) : 0,
|
||||
minClearanceM:
|
||||
finite(eye.minClearanceM) && eye.minClearanceM >= 0
|
||||
? eye.minClearanceM
|
||||
: 0,
|
||||
finite(minClearanceM) && minClearanceM >= 0 ? minClearanceM : 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -642,11 +642,15 @@ test('a provider whose getter throws is left out with one warning; the next is k
|
||||
]);
|
||||
});
|
||||
|
||||
test('a worded getter that starts throwing keeps the last good words', () => {
|
||||
let failing = false;
|
||||
const words = (value) => () => {
|
||||
if (failing) throw new Error('translations unavailable');
|
||||
return value;
|
||||
test('a worded getter that throws from its second read keeps the last good words', () => {
|
||||
// Registration reads each once: the second read is the first use.
|
||||
const once = (value) => {
|
||||
let read = false;
|
||||
return () => {
|
||||
if (read) throw new Error('translations unavailable');
|
||||
read = true;
|
||||
return value;
|
||||
};
|
||||
};
|
||||
const definition = provider();
|
||||
for (const [key, value] of Object.entries({
|
||||
@@ -654,22 +658,52 @@ test('a worded getter that starts throwing keeps the last good words', () => {
|
||||
entryFace: { icon: 'commute', label: 'RIDE' },
|
||||
look: { restPitchDeg: 10, aheadLabel: 'Look ahead' },
|
||||
}))
|
||||
Object.defineProperty(definition, key, { get: words(value) });
|
||||
Object.defineProperty(definition, key, { get: once(value) });
|
||||
const { kept, warnings } = keep([definition]);
|
||||
assert.deepEqual(warnings, []);
|
||||
const [ride] = kept;
|
||||
failing = true;
|
||||
assert.equal(ride.labels.view, 'Ride view');
|
||||
assert.equal(ride.entryFace.label, 'RIDE');
|
||||
assert.deepEqual(ride.look, { restPitchDeg: 10, aheadLabel: 'Look ahead' });
|
||||
// So does a worded object whose own member throws when read.
|
||||
failing = false;
|
||||
Object.defineProperty(definition, 'labels', {
|
||||
get: () => throwingGetter({ view: 'v', exit: 'e', exitText: 'x' }, 'view'),
|
||||
});
|
||||
assert.equal(ride.labels.view, 'Ride view');
|
||||
});
|
||||
|
||||
test('a worded member that returns a rejected promise keeps the last good words, the rejection caught', async () => {
|
||||
const definition = provider();
|
||||
const words = definition.labels;
|
||||
let reads = 0;
|
||||
definition.labels = () => {
|
||||
reads += 1;
|
||||
return reads === 1 ? words : Promise.reject(new Error('late words'));
|
||||
};
|
||||
const { kept, warnings } = keep([definition]);
|
||||
assert.deepEqual(warnings, []);
|
||||
assert.equal(kept[0].labels.view, words.view);
|
||||
// An unhandled rejection would fail this test once it surfaces.
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
});
|
||||
|
||||
test('a frame field read through a getter is read once', () => {
|
||||
const frame = { id: 'a1', latitude: 1, longitude: 2, eye: { upM: 3 } };
|
||||
const once = (value) => {
|
||||
let read = false;
|
||||
return () => {
|
||||
const answer = read ? undefined : value;
|
||||
read = true;
|
||||
return answer;
|
||||
};
|
||||
};
|
||||
Object.defineProperty(frame, 'heightM', { get: once(420) });
|
||||
Object.defineProperty(frame, 'speedMps', { get: once(12) });
|
||||
const normalized = cockpitSubjectFrame(frame, 'a1');
|
||||
assert.equal(normalized.heightM, 420);
|
||||
assert.equal(normalized.speedMps, 12);
|
||||
});
|
||||
|
||||
test('a candidate, frame or HUD view whose getter throws reads as null', () => {
|
||||
assert.equal(
|
||||
cockpitSubjectCandidate(throwingGetter({ name: 'Example' }, 'id')),
|
||||
|
||||
+25
-9
@@ -336,7 +336,7 @@ function updateVessel(nowMs) {
|
||||
* gives none) and slew toward its heading. A frame that is null, malformed or
|
||||
* for another subject ends the view, as an aircraft tracked meanwhile does.
|
||||
* The update runs on the provider's `cameraIntervalMs` (0: every frame), and
|
||||
* its rates advance by the time that interval spans (cockpitSubjectStepSec).
|
||||
* its rates advance by the time since the last update (cockpitSubjectStepSec).
|
||||
*/
|
||||
function updateSubject(nowMs) {
|
||||
const provider = this.subjectProvider;
|
||||
@@ -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 height it last stood at.
|
||||
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);
|
||||
@@ -411,7 +422,9 @@ function updateSubject(nowMs) {
|
||||
: slewHeading(
|
||||
this.heading ?? frame.headingDeg,
|
||||
frame.headingDeg,
|
||||
rate * dtSec,
|
||||
// At most half a turn, which reaches any heading: a huge rate times
|
||||
// the step must not overflow to Infinity and stop the turn.
|
||||
Math.min(rate * dtSec, 180),
|
||||
);
|
||||
}
|
||||
let look = null;
|
||||
@@ -459,8 +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) {
|
||||
if (!this.cockpitAnchorValid) {
|
||||
this.cockpitAnchor = clone(target);
|
||||
// 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.cockpitAnchorValid = true;
|
||||
this.subjectLiftM = null;
|
||||
}
|
||||
@@ -485,7 +501,7 @@ function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
|
||||
: 0;
|
||||
|
||||
const groundClamp = info.groundClamp !== false;
|
||||
if (info.stale || info.anchor === 'exact') {
|
||||
if (anchoring || info.stale || info.anchor === 'exact') {
|
||||
// A feed backoff has no authoritative velocity epoch to advance from.
|
||||
// Hold the cockpit on the exact layer-rendered position so the camera
|
||||
// cannot coast away while the icon correctly remains fixed.
|
||||
@@ -503,8 +519,8 @@ function placeCamera(target, info, nowMs, dtSec, profile, look = null) {
|
||||
);
|
||||
const correction = sub(target, this.cockpitAnchor);
|
||||
const correctionDistanceM = magnitude(correction);
|
||||
// An application subject's step is already bounded by its own update
|
||||
// interval (cockpitSubjectStepSec); the built-in views keep the 0.1 s.
|
||||
// An application subject's step is already bounded (cockpitSubjectStepSec);
|
||||
// the built-in views keep the 0.1 s.
|
||||
const correctionStepM = cockpitAnchorCorrectionStep(
|
||||
correctionDistanceM,
|
||||
speedMps,
|
||||
|
||||
@@ -194,8 +194,10 @@ export class CockpitViewController {
|
||||
this.surfaceWaitStartedMs = 0;
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
/** The height an application subject's frame last stood at (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;
|
||||
/**
|
||||
@@ -735,8 +737,16 @@ export class CockpitViewController {
|
||||
publishCockpitSignals() {
|
||||
return publishCockpitSignals.call(this);
|
||||
}
|
||||
pushCockpitSignal(key, tone, title, detail, target) {
|
||||
return pushCockpitSignal.call(this, key, tone, title, detail, target);
|
||||
pushCockpitSignal(key, tone, title, detail, target, options) {
|
||||
return pushCockpitSignal.call(
|
||||
this,
|
||||
key,
|
||||
tone,
|
||||
title,
|
||||
detail,
|
||||
target,
|
||||
options,
|
||||
);
|
||||
}
|
||||
dropCockpitSignal(key) {
|
||||
return dropCockpitSignal.call(this, key);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -256,20 +256,21 @@ function updateSubjectHud(info, nowMs, forceContext) {
|
||||
this.updateLocalPosition(info);
|
||||
this.maybeRefreshRegionalBrief(info);
|
||||
this.showContextCard(false);
|
||||
const keys = new Set();
|
||||
for (const signal of hud.signals) {
|
||||
const key = `subject:${signal.id}`;
|
||||
keys.add(key);
|
||||
this.pushCockpitSignal(
|
||||
key,
|
||||
SUBJECT_SIGNAL_TONES[signal.tone] ?? 'info',
|
||||
signal.title,
|
||||
signal.detail || signal.title,
|
||||
);
|
||||
}
|
||||
const keys = new Set(hud.signals.map(({ id }) => `subject:${id}`));
|
||||
// Rows the view no longer lists leave first, so new ones take their
|
||||
// places rather than push a listed one (or TRACK ACQUIRED) off.
|
||||
for (const key of this.subjectSignalKeys ?? [])
|
||||
if (!keys.has(key)) this.dropCockpitSignal(key);
|
||||
this.subjectSignalKeys = keys;
|
||||
for (const signal of hud.signals)
|
||||
this.pushCockpitSignal(
|
||||
`subject:${signal.id}`,
|
||||
SUBJECT_SIGNAL_TONES[signal.tone] ?? 'info',
|
||||
signal.title,
|
||||
signal.detail || signal.title,
|
||||
null,
|
||||
{ inPlace: true },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,17 +39,42 @@ export function publishCockpitSignals() {
|
||||
this.scheduleContextLayout();
|
||||
}
|
||||
|
||||
export function pushCockpitSignal(key, tone, title, detail, target = null) {
|
||||
/**
|
||||
* 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 its
|
||||
* time while it stays listed, and one pushed off comes back as the newest
|
||||
* row.
|
||||
*/
|
||||
export function pushCockpitSignal(
|
||||
key,
|
||||
tone,
|
||||
title,
|
||||
detail,
|
||||
target = null,
|
||||
{ inPlace = false } = {},
|
||||
) {
|
||||
if (!title || !detail) return;
|
||||
const signature = `${title}|${detail}|${target?.layerId || ''}|${target?.id || ''}`;
|
||||
if (this.signalSignatures.get(key) === signature) return;
|
||||
this.signalSignatures.set(key, signature);
|
||||
// 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,
|
||||
target?.layerId || '',
|
||||
target?.id || '',
|
||||
inPlace ? tone : '',
|
||||
]);
|
||||
// A locale change words the signal again where it stands.
|
||||
const shown = this.rewordingSignals
|
||||
? this.signalItems.find((item) => item.key === key)
|
||||
: null;
|
||||
const shown =
|
||||
this.rewordingSignals || inPlace
|
||||
? this.signalItems.find((item) => item.key === key)
|
||||
: null;
|
||||
if (this.signalSignatures.get(key) === signature && (!inPlace || shown))
|
||||
return;
|
||||
this.signalSignatures.set(key, signature);
|
||||
if (shown) {
|
||||
Object.assign(shown, { title, detail });
|
||||
Object.assign(shown, { tone, title, detail });
|
||||
this.publishCockpitSignals();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
|
||||
const LAT = 47;
|
||||
const LON = 8;
|
||||
const FLOOR_M = 400;
|
||||
/** Metres in a degree of longitude at LAT. */
|
||||
const M_PER_DEG_LON = 111_320 * Math.cos(Cesium.Math.toRadians(LAT));
|
||||
/** The longitude `m` metres east of LON. */
|
||||
const eastM = (m) => LON + m / M_PER_DEG_LON;
|
||||
|
||||
/** A HUD view model as a provider words it. */
|
||||
const HUD = Object.freeze({
|
||||
@@ -123,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();
|
||||
@@ -204,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, {
|
||||
@@ -222,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();
|
||||
@@ -281,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;
|
||||
@@ -560,7 +592,7 @@ test('a subject updated every 500 ms turns, eases and closes on its target at it
|
||||
ride.subject.frame = {
|
||||
...ride.subject.frame,
|
||||
headingDeg: 180,
|
||||
longitude: LON + 100 / (111_320 * Math.cos(Cesium.Math.toRadians(LAT))),
|
||||
longitude: eastM(100),
|
||||
};
|
||||
setFloor(FLOOR_M + 3.5);
|
||||
clock.advance(500);
|
||||
@@ -585,7 +617,78 @@ test('a subject updated every 500 ms turns, eases and closes on its target at it
|
||||
// A long stall (a hidden tab) moves it as one late update would.
|
||||
clock.advance(60_000);
|
||||
cockpit.update();
|
||||
assert.ok(Math.abs(cockpit.heading - 101) < 1e-6, 'at most 0.6 s');
|
||||
assert.ok(Math.abs(cockpit.heading - 110) < 1e-6, 'at most 1.5 s');
|
||||
});
|
||||
|
||||
test('a subject turning at the largest finite rate reaches its heading after a late update', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider({
|
||||
cameraIntervalMs: 500,
|
||||
headingSlewDps: Number.MAX_VALUE,
|
||||
});
|
||||
const { cockpit } = fixture(t, { providers: [ride] });
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
clock.advance(500);
|
||||
cockpit.update();
|
||||
ride.subject.frame = { ...ride.subject.frame, headingDeg: 180 };
|
||||
// A 1.5 s step: the rate times it overflows to Infinity.
|
||||
clock.advance(1500);
|
||||
cockpit.update();
|
||||
assert.equal(cockpit.heading, 180);
|
||||
});
|
||||
|
||||
test('an inertial subject drawn at 5 frames a second stays near its target', async (t) => {
|
||||
const startMs = 10_000;
|
||||
const clock = manualClock(t, startMs);
|
||||
const ride = subjectProvider();
|
||||
const eastNow = movingEast(ride, startMs, 30);
|
||||
const { cockpit, shots } = fixture(t, { providers: [ride] });
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
clock.advance(200);
|
||||
cockpit.update();
|
||||
}
|
||||
const target = Cesium.Cartesian3.fromDegrees(eastNow(), LAT, FLOOR_M + 3.5);
|
||||
const gapM = Cesium.Cartesian3.distance(shots.at(-1).destination, target);
|
||||
assert.ok(
|
||||
gapM < 50,
|
||||
`after 60 s the camera is ${gapM.toFixed(0)} m from the subject`,
|
||||
);
|
||||
});
|
||||
|
||||
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();
|
||||
}
|
||||
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) => {
|
||||
@@ -863,6 +966,47 @@ test('a floor that never comes ends the view after the bounded wait, releasing t
|
||||
assert.deepEqual(lastRelease(ride.calls), ['release', 'a1', false]);
|
||||
});
|
||||
|
||||
for (const entryHeightM of [0, FLOOR_M]) {
|
||||
test(`a height the entry frame gave (${entryHeightM} m) holds while later frames give none and the floor is cold`, async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
ride.subject.frame = { ...ride.subject.frame, heightM: entryHeightM };
|
||||
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 };
|
||||
const waitPastTimeout = () => {
|
||||
for (
|
||||
let elapsed = 0;
|
||||
elapsed < COCKPIT_GROUND_WAIT_TIMEOUT_MS + 1000;
|
||||
elapsed += 100
|
||||
) {
|
||||
clock.advance(100);
|
||||
cockpit.update();
|
||||
}
|
||||
};
|
||||
waitPastTimeout();
|
||||
assert.equal(
|
||||
cockpit.active,
|
||||
true,
|
||||
'the view keeps the height its entry frame gave',
|
||||
);
|
||||
assert.ok(shots.length > 0, 'the camera is placed');
|
||||
assert.ok(Math.abs(shotHeight(shots) - (entryHeightM + 3.5)) < 0.01);
|
||||
// A floor that comes takes over, and is kept once it is cold again.
|
||||
const floorM = FLOOR_M - 100;
|
||||
setFloor(floorM);
|
||||
clock.advance(100);
|
||||
cockpit.update();
|
||||
assert.ok(Math.abs(shotHeight(shots) - (floorM + 3.5)) < 0.01);
|
||||
setFloor(undefined);
|
||||
waitPastTimeout();
|
||||
assert.equal(cockpit.active, true);
|
||||
assert.ok(Math.abs(shotHeight(shots) - (floorM + 3.5)) < 0.01);
|
||||
});
|
||||
}
|
||||
|
||||
test('an asynchronous hold that lands after entry was refused is released again', async (t) => {
|
||||
let heldId = null;
|
||||
const releases = [];
|
||||
@@ -942,6 +1086,30 @@ test('a provider’s labels, entry face and look follow a change of language', a
|
||||
);
|
||||
});
|
||||
|
||||
test('a provider whose labels throw after registration enters with no HUD kicker', async (t) => {
|
||||
manualClock(t, 10_000);
|
||||
let read = false;
|
||||
const ride = subjectProvider({
|
||||
labels() {
|
||||
if (read) throw new Error('word bundle unloaded');
|
||||
read = true;
|
||||
return {
|
||||
view: 'Tram view',
|
||||
exit: 'Exit tram view',
|
||||
exitText: 'EXIT TRAM',
|
||||
kicker: 'TRAM 4',
|
||||
};
|
||||
},
|
||||
});
|
||||
ride.subject.hud = { title: 'Example 12' };
|
||||
const { $, cockpit } = fixture(t, { providers: [ride] });
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
await settle();
|
||||
// The kicker checked at registration stands in for the HUD view's.
|
||||
assert.equal($('.cockpit-kicker').textContent, 'TRAM 4');
|
||||
});
|
||||
|
||||
test('a read that throws ends the view once; a hud that throws keeps the last', async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
@@ -1122,26 +1290,80 @@ test('a subject first seen together with a built-in one comes after it', async (
|
||||
assert.equal(store.presence.entryKind, 'vessel');
|
||||
});
|
||||
|
||||
/**
|
||||
* Every world position projects to (x, y): the scene query port projects
|
||||
* through Cesium.SceneTransforms.
|
||||
*/
|
||||
function everythingAt(t, x, y) {
|
||||
t.mock.method(
|
||||
Cesium.SceneTransforms,
|
||||
'worldToWindowCoordinates',
|
||||
(_scene, _position, result = new Cesium.Cartesian2()) =>
|
||||
Object.assign(result, { x, y }),
|
||||
);
|
||||
}
|
||||
|
||||
test("a double-click on the selected vessel does not enter an application's subject", async (t) => {
|
||||
const clock = manualClock(t, 10_000);
|
||||
const ride = subjectProvider();
|
||||
ride.subject.candidate = null;
|
||||
const { cockpit, store, viewer } = fixture(t, {
|
||||
const { cockpit, store } = fixture(t, {
|
||||
providers: [ride],
|
||||
vessel: VESSEL,
|
||||
});
|
||||
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 };
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.resolveEntryKind(), 'example-kind');
|
||||
// Every world position lands under the pointer, the vessel's sprite too.
|
||||
viewer.scene.cartesianToCanvasCoordinates = (_position, result = {}) =>
|
||||
Object.assign(result, { x: 400, y: 300 });
|
||||
assert.equal(cockpit.onSceneDoubleClick({ x: 400, y: 300 }), false);
|
||||
assert.equal(store.presence.entryKind, 'example-kind');
|
||||
// The user double-clicks the vessel, still selected.
|
||||
assert.equal(cockpit.onSceneDoubleClick({ x: 100, y: 100 }), false);
|
||||
await settle();
|
||||
assert.notEqual(store.presence.active, true);
|
||||
assert.equal(
|
||||
cockpit.subjectProvider ?? null,
|
||||
null,
|
||||
'no provider view entered from a double-click on the vessel',
|
||||
);
|
||||
assert.equal(
|
||||
ride.calls.some(([name]) => name === 'hold'),
|
||||
false,
|
||||
'the provider subject was not held',
|
||||
);
|
||||
});
|
||||
|
||||
test('the same double-click on the vessel alone enters its bridge', async (t) => {
|
||||
manualClock(t, 10_000);
|
||||
const { cockpit, store } = fixture(t, { vessel: VESSEL });
|
||||
everythingAt(t, 100, 100);
|
||||
cockpit.syncEntry();
|
||||
assert.equal(store.presence.entryKind, 'vessel');
|
||||
assert.equal(cockpit.onSceneDoubleClick({ x: 100, y: 100 }), true);
|
||||
await settle();
|
||||
assert.equal(store.presence.active, true, 'the bridge is entered');
|
||||
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) => {
|
||||
@@ -1188,3 +1410,157 @@ test('rows a HUD view no longer lists leave Live Signals', async (t) => {
|
||||
cockpit.update();
|
||||
assert.ok(dropped.includes('subject:note'));
|
||||
});
|
||||
|
||||
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], realSignals: true });
|
||||
// The ETA is logged first, so it stands below the warning.
|
||||
const hudWith = (minutes) => ({
|
||||
...HUD,
|
||||
signals: [
|
||||
{ id: 'eta', title: 'NEXT', detail: `Central in ${minutes} min` },
|
||||
{
|
||||
id: 'doors',
|
||||
tone: 'warning',
|
||||
title: 'DOORS',
|
||||
detail: 'door fault, car 2',
|
||||
},
|
||||
],
|
||||
});
|
||||
const etaRow = () =>
|
||||
cockpit.signalItems.find((row) => row.key === 'subject:eta');
|
||||
ride.subject.hud = hudWith(10);
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
const keysAtEntry = cockpit.signalItems.map((row) => row.key);
|
||||
const etaFirstSeen = etaRow().timestamp;
|
||||
for (let minutes = 9; minutes >= 2; minutes -= 1) {
|
||||
ride.subject.hud = hudWith(minutes);
|
||||
clock.advance(1000);
|
||||
cockpit.update();
|
||||
}
|
||||
const keys = cockpit.signalItems.map((row) => row.key);
|
||||
// Each row keeps its place, and the ETA the time it first appeared.
|
||||
assert.deepEqual(keys, keysAtEntry);
|
||||
assert.equal(etaRow().timestamp, etaFirstSeen);
|
||||
assert.ok(
|
||||
keys.includes('subject:doors'),
|
||||
`the warning the HUD still lists is shown (rows: ${keys.join(', ')})`,
|
||||
);
|
||||
// The changing one is one row, worded as it reads now.
|
||||
const etas = cockpit.signalItems.filter((row) => row.key === 'subject:eta');
|
||||
assert.deepEqual(
|
||||
etas.map((row) => row.detail),
|
||||
['Central in 2 min'],
|
||||
);
|
||||
// Rows pushed off the list by newer ones come back while still listed.
|
||||
for (let i = 0; i < 5; i += 1)
|
||||
cockpit.pushCockpitSignal(`other-${i}`, 'info', 'OTHER', `row ${i}`);
|
||||
assert.equal(
|
||||
cockpit.signalItems.some((row) => row.key.startsWith('subject:')),
|
||||
false,
|
||||
);
|
||||
clock.advance(1000);
|
||||
cockpit.update();
|
||||
assert.deepEqual(
|
||||
cockpit.signalItems
|
||||
.map((row) => row.key)
|
||||
.filter((key) => key.startsWith('subject:'))
|
||||
.sort(),
|
||||
['subject:doors', 'subject:eta'],
|
||||
);
|
||||
});
|
||||
|
||||
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, 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 = () =>
|
||||
store.signals.find((row) => row.title === 'DOORS').className;
|
||||
ride.subject.hud = hudWith('normal');
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
const tones = [doorsTone()];
|
||||
for (const tone of ['warning', 'normal']) {
|
||||
ride.subject.hud = hudWith(tone);
|
||||
clock.advance(1000);
|
||||
cockpit.update();
|
||||
tones.push(doorsTone());
|
||||
}
|
||||
assert.deepEqual(tones, ['info', 'warning', 'info']);
|
||||
});
|
||||
|
||||
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], realSignals: true });
|
||||
const row = (id, tone) => ({
|
||||
id,
|
||||
tone,
|
||||
title: id.toUpperCase(),
|
||||
detail: `row ${id}`,
|
||||
});
|
||||
ride.subject.hud = {
|
||||
...HUD,
|
||||
signals: [row('w', 'warning'), row('a'), row('b'), row('c')],
|
||||
};
|
||||
cockpit.syncEntry();
|
||||
assert.equal(cockpit.enter(), true);
|
||||
assert.ok(cockpit.signalItems.some((item) => item.key === 'track'));
|
||||
ride.subject.hud = {
|
||||
...HUD,
|
||||
signals: [row('w', 'warning'), row('a'), row('d'), row('e')],
|
||||
};
|
||||
clock.advance(1000);
|
||||
cockpit.update();
|
||||
const keys = cockpit.signalItems.map((item) => item.key);
|
||||
assert.deepEqual(
|
||||
[...keys].sort(),
|
||||
['subject:a', 'subject:d', 'subject:e', 'subject:w', 'track'],
|
||||
`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,7 +516,10 @@ function enterSubject(provider) {
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
this.cockpitAnchorValid = false;
|
||||
this.subjectHeightM = null;
|
||||
// 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