From a72c0ba2371ff558b578547f6a1f7c8291d44c4c Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Wed, 18 Nov 2026 14:32:45 +0400 Subject: [PATCH] Fix tone-only signal changes, the first anchor step, row order and emoji widths - A provider's Live Signals row now changes when only its tone does; fields are compared one by one instead of through a joined signature. - The frame that first sets an inertial subject's anchor puts it on the subject, so the view no longer jumps ahead after waiting for the floor. - The subject HUD drops vanished rows before it adds new ones, so TRACK ACQUIRED and a steady warning keep their place. - Progress labels give astral-plane glyphs such as emoji at least main's width, so they are not clipped. --- .../1787-cockpit-subject-camera-hud.md | 13 ++- docs/CURRENT-STATE.md | 9 +- src/cockpitProgress.js | 18 ++- src/cockpitProgress.test.mjs | 19 +++ src/ui/cockpitCamera.js | 7 +- src/ui/cockpitInstruments.js | 17 ++- src/ui/cockpitSignals.js | 10 +- src/ui/cockpitSubjectView.test.mjs | 109 ++++++++++++++++++ 8 files changed, 171 insertions(+), 31 deletions(-) diff --git a/changelog.d/1787-cockpit-subject-camera-hud.md b/changelog.d/1787-cockpit-subject-camera-hud.md index 96eb5d6fb5..0e860b64f4 100644 --- a/changelog.d/1787-cockpit-subject-camera-hud.md +++ b/changelog.d/1787-cockpit-subject-camera-hud.md @@ -1,8 +1,9 @@ - Keep an application's Cockpit subject steady: a height its entry frame gave holds while the floor is still cold, so the view no longer ends; the camera - keeps up when the browser draws few frames (at 5 a second it fell 700 m - behind a 30 m/s subject in a minute); a provider's Live Signals rows change - where they stand, so a changing ETA no longer pushes a steady warning off - the list; progress labels give CJK, kana and Hangul names the width they - need; and labels, entry face and look keep the words checked at - registration when a later read fails (German, @gekh, #1787). + keeps up when the browser draws few frames (at 5 a second, one updated every + frame fell 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; and labels, entry face and look keep the + words checked at registration when a later read fails (German, @gekh, #1787). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 67d063bd73..ff6762f4c5 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -2754,17 +2754,20 @@ exact, since an inertial anchor runs on at the frame's speed); `cameraIntervalMs 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 +second late would, and the update that first places the camera (after entry or +a floor wait) stands its anchor on the subject. 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 (each changes where it -stands, so a changing ETA never pushes a steady warning off the list), a veil that darkens the +stands, its tone included, so a changing ETA never pushes a steady warning off +the list; 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 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, a full-width CJK, kana or Hangul glyph given about 1 em). Core translates none of the provider's text: a host +labels never overlap and get about 1 em for each full-width CJK, kana or Hangul +glyph and a little more for an emoji or other astral glyph). 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 diff --git a/src/cockpitProgress.js b/src/cockpitProgress.js index 0d9f38920e..c8114d3e84 100644 --- a/src/cockpitProgress.js +++ b/src/cockpitProgress.js @@ -30,27 +30,25 @@ const TONE_RANK = Object.freeze([ const stronger = (a, b) => TONE_RANK.indexOf(b) > TONE_RANK.indexOf(a) ? b : a; -/** - * Full-width glyphs (CJK ideographs and punctuation, kana, Hangul, full-width - * forms), each about 1 em wide. - */ +/** Full-width glyphs (CJK, kana, Hangul, full-width forms): about 1 em each. */ const WIDE_GLYPH = /[ᄀ-ᅟ⺀-〾ぁ-㏿㐀-䶿一-鿿ꥠ-꥿가-힣豈-﫿︰-﹏＀-⦆¢-₩\u{20000}-\u{3fffd}]/u; -/** One line's width in the label's 10 px type, 0.06 em apart (px). */ +/** + * One line's width (px) in `.cockpit-progress-label` type (cockpitSubject.css: + * 10 px, 0.06 em spacing): 10.6 px a full-width glyph and 6.4 px each UTF-16 + * unit of any other, so an emoji or other astral glyph gets 12.8 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; + else narrow += glyph.length; 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. - */ +/** A label's width estimate (px): its longer line and 8 px of padding. */ export function estimateProgressLabelPx(label) { return Math.max(lineWidthPx(label?.text), lineWidthPx(label?.detail)) + 8; } diff --git a/src/cockpitProgress.test.mjs b/src/cockpitProgress.test.mjs index 5d5885cd2c..e05f3fe0ff 100644 --- a/src/cockpitProgress.test.mjs +++ b/src/cockpitProgress.test.mjs @@ -159,3 +159,22 @@ test('a CJK stop name gets the width its full-width glyphs need', () => { assert.equal(estimateProgressLabelPx({ text: 'CENTRAL' }), 7 * 6.4 + 8); assert.equal(estimateProgressLabelPx({ text: 'カタカナ' }), 4 * 6.4 + 8); }); + +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`, + ); + } +}); diff --git a/src/ui/cockpitCamera.js b/src/ui/cockpitCamera.js index e6eeb1ea57..feb7734798 100644 --- a/src/ui/cockpitCamera.js +++ b/src/ui/cockpitCamera.js @@ -459,7 +459,10 @@ 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) { + // The update that first sets the anchor stands it on the target: the time + // before it (an entry, a floor wait) moved nothing, so it has no step. + const anchoring = !this.cockpitAnchorValid; + if (anchoring) { this.cockpitAnchor = clone(target); this.cockpitAnchorValid = true; this.subjectLiftM = null; @@ -485,7 +488,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. diff --git a/src/ui/cockpitInstruments.js b/src/ui/cockpitInstruments.js index d64890bd8d..cf3cea895d 100644 --- a/src/ui/cockpitInstruments.js +++ b/src/ui/cockpitInstruments.js @@ -256,24 +256,23 @@ function updateSubjectHud(info, nowMs, forceContext) { this.updateLocalPosition(info); this.maybeRefreshRegionalBrief(info); this.showContextCard(false); - const keys = new Set(); + 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; // 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); + for (const signal of hud.signals) this.pushCockpitSignal( - key, + `subject:${signal.id}`, SUBJECT_SIGNAL_TONES[signal.tone] ?? 'info', signal.title, signal.detail || signal.title, null, { inPlace: true }, ); - } - for (const key of this.subjectSignalKeys ?? []) - if (!keys.has(key)) this.dropCockpitSignal(key); - this.subjectSignalKeys = keys; } } diff --git a/src/ui/cockpitSignals.js b/src/ui/cockpitSignals.js index 14e8cca528..abfcfd12fa 100644 --- a/src/ui/cockpitSignals.js +++ b/src/ui/cockpitSignals.js @@ -54,7 +54,15 @@ export function pushCockpitSignal( { inPlace = false } = {}, ) { if (!title || !detail) return; - const signature = `${title}|${detail}|${target?.layerId || ''}|${target?.id || ''}`; + // Each field on its own, so no title and detail 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 || inPlace diff --git a/src/ui/cockpitSubjectView.test.mjs b/src/ui/cockpitSubjectView.test.mjs index 6c0fe249d4..92a7a9b2eb 100644 --- a/src/ui/cockpitSubjectView.test.mjs +++ b/src/ui/cockpitSubjectView.test.mjs @@ -625,6 +625,55 @@ 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 mPerDegLon = 111_320 * Math.cos(Cesium.Math.toRadians(LAT)); + const eastOf = () => + LON + (SPEED_MPS * (performance.now() - startMs)) / 1000 / mPerDegLon; + const ride = subjectProvider({ cameraIntervalMs: intervalMs }); + const base = ride.subject.frame; + ride.subject.frame = () => ({ + ...base, + heightM: null, + longitude: eastOf(), + 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); + cockpit.update(); + const shot = Cesium.Cartographic.fromCartesian(shots[before].destination); + const leadM = + (Cesium.Math.toDegrees(shot.longitude) - eastOf()) * mPerDegLon; + 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); const ride = subjectProvider(); @@ -1373,3 +1422,63 @@ test('a signal still listed stays in Live Signals while another one changes', as ['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 } = fixture(t, { providers: [ride] }); + delete cockpit.pushCockpitSignal; + delete cockpit.dropCockpitSignal; + const hudWith = (tone) => ({ + ...HUD, + signals: [ + { id: 'doors', tone, title: 'DOORS', detail: 'door fault, car 2' }, + ], + }); + const doorsTone = () => + cockpit.signalItems.find((row) => row.key === 'subject:doors').tone; + 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] }); + delete cockpit.pushCockpitSignal; + delete cockpit.dropCockpitSignal; + 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(', ')}`, + ); +});