From a2a61c506fe7ad7f0fd01d5c755d10d519081d00 Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Tue, 17 Nov 2026 19:34:32 +0400 Subject: [PATCH] Keep an application's Cockpit subject steady in the camera and HUD - A height the entry frame gave holds while later frames give none and the floor is still cold, so the view no longer waits and ends. - A subject's camera update advances by the time since the last one, up to its interval plus a second: at 5 frames a second an inertial subject no longer falls behind (700 m in a minute at 30 m/s), while a hidden tab still counts as one late update. - A provider's Live Signals rows change where they stand and come back after newer rows pushed them off, so a changing ETA no longer hides a steady warning; the built-in rows log as before. - Progress labels give full-width glyphs (CJK, kana, Hangul) about 1 em, so such stop names no longer overlap. - A provider's labels, entry face and look start from the words checked at registration, so one that fails on its next read keeps them. The double-click test on a selected vessel now projects through SceneTransforms, as the scene query port does, with a control that enters the bridge. --- docs/CURRENT-STATE.md | 17 ++- src/cockpitMath.js | 15 ++- src/cockpitMath.test.mjs | 11 +- src/cockpitProgress.js | 28 +++- src/cockpitProgress.test.mjs | 19 ++- src/cockpitSubjectProviders.js | 43 +++--- src/ui/cockpitCamera.js | 4 +- src/ui/cockpitController.js | 12 +- src/ui/cockpitInstruments.js | 4 + src/ui/cockpitSignals.js | 29 +++- src/ui/cockpitSubjectView.test.mjs | 201 ++++++++++++++++++++++++++-- src/ui/cockpitTrackingController.js | 4 +- 12 files changed, 329 insertions(+), 58 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 4a5d97da6e..67d063bd73 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2743,28 +2743,33 @@ 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 the last height it had, the entry frame's included, while +that floor is cold; 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, eases and moves the view by the +time since the last one, so it keeps up when the browser draws few frames; an +update more than a second past its interval (a hidden tab) moves it as one a +second late would. 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 +source rows, banner, route card and Live Signals rows (each changes where it +stands, so a changing ETA never pushes a steady warning off the list), 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 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, a full-width CJK, kana or Hangul glyph given about 1 em). 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, diff --git a/src/cockpitMath.js b/src/cockpitMath.js index 05a69904c7..45348a2f39 100644 --- a/src/cockpitMath.js +++ b/src/cockpitMath.js @@ -58,12 +58,19 @@ export function cockpitAnchorCorrectionStep( return Math.min(distanceM, eased, correctionRateMps * dt); } +/** + * How late past its interval a subject's camera update may come and still + * advance by all of it: a browser drawing a frame a second still keeps up. + */ +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 update interval plus a second. A subject updated every 500 ms, or a + * browser drawing 5 frames a second, then turns, eases and moves at its + * configured rates, while a long stall (a hidden tab) still moves it no + * further than one late update would. * @param {number} elapsedMs Time since the last camera update. * @param {number} intervalMs The subject's update interval (0: every frame). * @returns {number} @@ -75,7 +82,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. */ diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index 29c2654c6c..3892d510b0 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -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', () => { diff --git a/src/cockpitProgress.js b/src/cockpitProgress.js index 67a3be951c..0d9f38920e 100644 --- a/src/cockpitProgress.js +++ b/src/cockpitProgress.js @@ -30,13 +30,29 @@ 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 (CJK ideographs and punctuation, kana, Hangul, full-width + * forms), each about 1 em wide. + */ +const WIDE_GLYPH = + /[ᄀ-ᅟ⺀-〾ぁ-㏿㐀-䶿一-鿿ꥠ-꥿가-힣豈-﫿︰-﹏＀-⦆¢-₩\u{20000}-\u{3fffd}]/u; + +/** One line's width in the label's 10 px type, 0.06 em apart (px). */ +function lineWidthPx(line) { + let wide = 0; + let narrow = 0; + for (const glyph of String(line ?? '')) + if (WIDE_GLYPH.test(glyph)) wide += 1; + else narrow += 1; + return wide * 10.6 + narrow * 6.4; +} + +/** + * A label's width estimate (px): its longer line, a full-width glyph at + * 10.6 px and any other at 6.4 px. + */ export function estimateProgressLabelPx(label) { - const longest = Math.max( - String(label?.text ?? '').length, - String(label?.detail ?? '').length, - ); - return longest * 6.4 + 8; + return Math.max(lineWidthPx(label?.text), lineWidthPx(label?.detail)) + 8; } /** diff --git a/src/cockpitProgress.test.mjs b/src/cockpitProgress.test.mjs index f1bd9d819b..5d5885cd2c 100644 --- a/src/cockpitProgress.test.mjs +++ b/src/cockpitProgress.test.mjs @@ -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,17 @@ 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`, + ); + // Latin, and half-width katakana, keep the narrower estimate. + assert.equal(estimateProgressLabelPx({ text: 'CENTRAL' }), 7 * 6.4 + 8); + assert.equal(estimateProgressLabelPx({ text: 'カタカナ' }), 4 * 6.4 + 8); +}); diff --git a/src/cockpitSubjectProviders.js b/src/cockpitSubjectProviders.js index 88b91e62cb..bed39e6bca 100644 --- a/src/cockpitSubjectProviders.js +++ b/src/cockpitSubjectProviders.js @@ -146,8 +146,12 @@ function providerName(provider, order) { return `#${order}`; } -/** Why `provider` cannot be kept, or null. */ -function refusal(provider, kinds) { +/** + * Why `provider` cannot be kept, or null. Its worded members, read once here, + * go into `words` (`face`, `labels`, `look`) to seed its copy, so one that + * fails when read again cannot undo this check. + */ +function refusal(provider, kinds, words) { if (!isObject(provider)) return 'not an object'; if (typeof provider.kind !== 'string' || !KIND_PATTERN.test(provider.kind)) return 'malformed kind'; @@ -165,11 +169,14 @@ 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'; + words.face = wordedNow(provider, 'entryFace', faceOf); + if (!words.face) return 'malformed entry face'; + words.labels = wordedNow(provider, 'labels', labelsOf); + if (!words.labels) return 'labels need view, exit and exitText'; + if (provider.look != null) { + words.look = wordedNow(provider, 'look', lookOf); + if (!words.look) return 'look needs an aheadLabel'; + } return null; } @@ -222,9 +229,10 @@ export function cockpitSubjectProviders( (Array.isArray(list) ? list : []).forEach((provider, order) => { let reason; let copy = null; + const words = { face: null, labels: null, look: null }; try { - reason = refusal(provider, kinds); - if (!reason) copy = keptProvider(provider, order); + reason = refusal(provider, kinds, words); + if (!reason) copy = keptProvider(provider, order, words); } catch { reason = 'a member threw when read'; } @@ -241,14 +249,15 @@ export function cockpitSubjectProviders( return Object.freeze(kept); } -/** The frozen copy the Cockpit keeps of a provider `refusal` passed. */ -function keptProvider(provider, order) { +/** + * The frozen copy the Cockpit keeps of a provider `refusal` passed, seeded + * with the worded members it checked. + */ +function keptProvider(provider, order, words) { // 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); + let { face, labels, look } = words; // On or off, and its rest pitch, as first read. - let look = wordedNow(provider, 'look', lookOf); const restPitchDeg = look?.restPitchDeg ?? 0; return Object.freeze({ kind: provider.kind, @@ -337,9 +346,9 @@ function candidateOf(raw) { * 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. + * is cold. 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, diff --git a/src/ui/cockpitCamera.js b/src/ui/cockpitCamera.js index e93bdf41fb..e6eeb1ea57 100644 --- a/src/ui/cockpitCamera.js +++ b/src/ui/cockpitCamera.js @@ -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; @@ -366,7 +366,7 @@ 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. + // it keeps the last height it had, the entry frame's included. heightM = Number.isFinite(floorM) ? floorM : this.subjectHeightM; } if (!Number.isFinite(heightM)) { diff --git a/src/ui/cockpitController.js b/src/ui/cockpitController.js index 39881f5df4..00552532c7 100644 --- a/src/ui/cockpitController.js +++ b/src/ui/cockpitController.js @@ -735,8 +735,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); diff --git a/src/ui/cockpitInstruments.js b/src/ui/cockpitInstruments.js index 62cb0e6ec0..d64890bd8d 100644 --- a/src/ui/cockpitInstruments.js +++ b/src/ui/cockpitInstruments.js @@ -257,6 +257,8 @@ function updateSubjectHud(info, nowMs, forceContext) { this.maybeRefreshRegionalBrief(info); this.showContextCard(false); const keys = new Set(); + // The view's rows are its current signals: each changes where it stands, + // so a changing one (an ETA) never pushes a steady one off the list. for (const signal of hud.signals) { const key = `subject:${signal.id}`; keys.add(key); @@ -265,6 +267,8 @@ function updateSubjectHud(info, nowMs, forceContext) { SUBJECT_SIGNAL_TONES[signal.tone] ?? 'info', signal.title, signal.detail || signal.title, + null, + { inPlace: true }, ); } for (const key of this.subjectSignalKeys ?? []) diff --git a/src/ui/cockpitSignals.js b/src/ui/cockpitSignals.js index 54889a82d7..14e8cca528 100644 --- a/src/ui/cockpitSignals.js +++ b/src/ui/cockpitSignals.js @@ -39,17 +39,32 @@ 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, and + * comes back if newer rows pushed it off the list. + */ +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); // 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; } diff --git a/src/ui/cockpitSubjectView.test.mjs b/src/ui/cockpitSubjectView.test.mjs index 63fffb0630..6c0fe249d4 100644 --- a/src/ui/cockpitSubjectView.test.mjs +++ b/src/ui/cockpitSubjectView.test.mjs @@ -585,7 +585,44 @@ 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('an inertial subject drawn at 5 frames a second stays near its target', async (t) => { + const clock = manualClock(t, 10_000); + const ride = subjectProvider(); + const SPEED_MPS = 30; + const startMs = 10_000; + const eastOf = (ms) => + LON + + (SPEED_MPS * (ms - startMs)) / + 1000 / + (111_320 * Math.cos((LAT * Math.PI) / 180)); + let nowMs = startMs; + ride.subject.frame = () => ({ + ...subjectProvider().subject.frame, + longitude: eastOf(nowMs), + speedMps: SPEED_MPS, + anchor: 'inertial', + }); + 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); + nowMs += 200; + cockpit.update(); + } + const target = Cesium.Cartesian3.fromDegrees( + eastOf(nowMs), + 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 exact anchor sits on the subject, wherever the frame moves it', async (t) => { @@ -863,6 +900,32 @@ test('a floor that never comes ends the view after the bounded wait, releasing t assert.deepEqual(lastRelease(ride.calls), ['release', 'a1', false]); }); +test('a height the entry frame gave holds while later frames give none and the floor is cold', async (t) => { + const clock = manualClock(t, 10_000); + const ride = subjectProvider(); + const { cockpit, shots, setFloor } = fixture(t, { providers: [ride] }); + setFloor(undefined); + cockpit.syncEntry(); + // The entry frame stands at FLOOR_M (heightM 400). + assert.equal(cockpit.enter(), true); + ride.subject.frame = { ...ride.subject.frame, heightM: null }; + for ( + let elapsed = 0; + elapsed < COCKPIT_GROUND_WAIT_TIMEOUT_MS + 1000; + elapsed += 100 + ) { + clock.advance(100); + cockpit.update(); + } + 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) - (FLOOR_M + 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 +1005,41 @@ test('a provider’s labels, entry face and look follow a change of language', a ); }); +/** Labels that read well once, when the provider is checked, then throw. */ +const GOOD_LABELS = Object.freeze({ + view: 'Ride view', + exit: 'Exit ride view', + exitText: 'EXIT RIDE', + kicker: 'RIDE', +}); +const labelsOnce = () => { + let reads = 0; + return function labels() { + reads += 1; + if (reads > 1) throw new Error('word bundle unloaded'); + return GOOD_LABELS; + }; +}; + +test('labels that start throwing after the first read keep the first good words', () => { + const warned = []; + const [kept] = cockpitSubjectProviders( + [{ ...subjectProvider().definition, labels: labelsOnce() }], + { warn: (message) => warned.push(message) }, + ); + assert.ok(kept, 'the provider is kept'); + assert.deepEqual({ ...kept.labels }, GOOD_LABELS); +}); + +test('entering such a provider with no HUD kicker does not throw', async (t) => { + manualClock(t, 10_000); + const ride = subjectProvider({ labels: labelsOnce() }); + ride.subject.hud = { title: 'Example 12' }; + const { cockpit } = fixture(t, { providers: [ride] }); + cockpit.syncEntry(); + assert.doesNotThrow(() => cockpit.enter()); +}); + 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 +1220,57 @@ 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 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); }); test('a provider view with look turns with the arrow keys and words its readout', async (t) => { @@ -1188,3 +1317,59 @@ 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] }); + // The real Live Signals rows, not the fixture's recorder. + delete cockpit.pushCockpitSignal; + delete cockpit.dropCockpitSignal; + const hudWith = (minutes) => ({ + ...HUD, + signals: [ + { + id: 'doors', + tone: 'warning', + title: 'DOORS', + detail: 'door fault, car 2', + }, + { id: 'eta', title: 'NEXT', detail: `Central in ${minutes} min` }, + ], + }); + ride.subject.hud = hudWith(10); + cockpit.syncEntry(); + assert.equal(cockpit.enter(), true); + 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); + 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'], + ); +}); diff --git a/src/ui/cockpitTrackingController.js b/src/ui/cockpitTrackingController.js index 8e3868bb7d..314a8c1b38 100644 --- a/src/ui/cockpitTrackingController.js +++ b/src/ui/cockpitTrackingController.js @@ -516,7 +516,9 @@ function enterSubject(provider) { this.surfaceAcquiring = false; this.surfaceFallback = false; this.cockpitAnchorValid = false; - this.subjectHeightM = null; + // A height the entry frame gave is where the eye stands until a later frame + // or the warmed floor gives another. + this.subjectHeightM = frame.heightM; this.lookRestPitchDeg = provider.look?.restPitchDeg ?? null; this.resetLook({ immediate: true }); this.active = true;