Merge main into german/vessel-callout-under-card

Resolve addPaintItem by keeping both the collision reset from main and the
queued-card frame stamp from this branch.
This commit is contained in:
German Khokhlov committed 2026-11-06 20:00:45 +04:00
commit 910e63a56a
218 files changed
+29736 -599

No files matched your search

+131 -72
View File
@@ -1,3 +1,5 @@
import { WORLD_OVERLAY_OCCLUDER_SELECTORS } from './worldOverlayChrome.js';
export { WORLD_OVERLAY_OCCLUDER_SELECTORS } from './worldOverlayChrome.js';
import * as Cesium from 'cesium';
import {
createCyberSonarSampler,
@@ -19,6 +21,7 @@ import {
measureOverlayEntry,
paintOverlayEntry,
placementVariants,
truncateOverlayTitle,
} from './worldOverlayDraw.js';
import { WORLD_OVERLAY_STYLE } from './worldOverlayTokens.js';
import { t } from '../i18n/index.js';
@@ -72,57 +75,6 @@ const PAINT_LANE_INDEX = new Map(
WORLD_OVERLAY_PAINT_LANES.map((lane, index) => [lane, index]),
);
/**
* Unified UI exclusion inventory. Selectors may match multiple elements; the
* service caches their rectangles and observes layout/visibility changes.
*
* These rectangles are a PLACEMENT policy, never a paint mask. Every element
* listed here composites ABOVE the overlay host — map chrome sits at z90–z1000
* and the cockpit HUD at z145, against this host's z5/z6 — so the browser
* already keeps overlay pixels off it and no canvas needs clipping. What the
* inventory buys is readability: a card placed under solid chrome is simply
* lost, so the solver PREFERS placements clear of it. When nothing is clear the
* entry still renders and the chrome covers it, exactly as it did before the
* host existed.
*
* The list therefore holds only chrome dense enough to swallow a card. The
* cockpit's thin translucent line art — rims, arcs, rails, tapes, toplines,
* readouts — is deliberately ABSENT under the owner's AR-HUD ruling:
* world-space overlay content renders beneath the cockpit's screen-space HUD,
* which paints over it by z-order. Those elements are also enormous (the
* altitude rim is keyhole-tall, the topline viewport-wide), and excluding them
* suppressed essentially the entire cockpit view. Only the two solid,
* backdrop-filled cockpit windows survive as exclusions.
*/
export const WORLD_OVERLAY_OCCLUDER_SELECTORS = Object.freeze([
'#title-bar',
'#style-indicator',
'#top-center-actions',
'#traffic-sync-chip',
'#cctv-sync-chip',
'#left-panel-stack',
'#right-context-rail',
'.weather-summary',
'#pp-toggles',
'#command-dock',
'#gev-voice-control',
'#cesium-credits',
'.hud-top-left',
'.hud-top-right',
'.hud-bottom-left',
'.hud-bottom-right',
'.hud-bottom-bar',
'#space-mission-panel',
'#space-mission-panel-host',
'#military-awareness-panel',
'#bhote-koshi-event-panel',
// Cockpit: solid backdrop-filled windows only (both bounded to
// `min(340px, 28vw)` wide and `min(42vh, 410px)` tall, both `hidden` until
// toggled). Every other cockpit selector was removed — see the block comment.
'#cockpit-context',
'#cockpit-signal-stream',
]);
/** @typedef {{x:number,y:number,w:number,h:number}} OverlayRect */
/**
* @typedef {object} WorldOverlayEntry
@@ -143,6 +95,8 @@ export const WORLD_OVERLAY_OCCLUDER_SELECTORS = Object.freeze([
* @property {number} [maxVisible=Infinity] Source ceiling within a shared domain.
* @property {boolean} [moving=false] Enables bounded interval re-solves.
* @property {number} [solveIntervalMs=125]
* @property {function(Set<string>):void} [onVisibilityChange] Painted entry ids,
* reported only on membership changes. The borrowed Set is read-only.
*/
/** @type {Cesium.Viewer|null} */
@@ -474,6 +428,11 @@ export function normalizeOverlayEntry(sourceId, entry) {
collisionGroup: String(
entry.collisionGroup || defaultCollisionGroup(variant),
),
// Optional lower-priority content must fit around the actual painted
// members of another domain, including its sticky positions and exit fades.
yieldToCollisionGroup: entry.yieldToCollisionGroup
? String(entry.yieldToCollisionGroup)
: null,
// Explicit field pick rather than `{ ...entry, variant }`: the lane
// resolver reads only these four, and a full spread re-invokes every
// accessor the source put on its entry (a throwing one would abort
@@ -596,12 +555,15 @@ export function normalizeOverlayEntry(sourceId, entry) {
metadata: entry.metadata ?? null,
thumbnailWidth: entry.thumbnailWidth,
thumbnailHeight: entry.thumbnailHeight,
thumbnailFit: entry.thumbnailFit === 'contain' ? 'contain' : null,
thumbnailFixedWidth: entry.thumbnailFixedWidth === true,
thumbnailPadX: entry.thumbnailPadX,
thumbnailPadTop: entry.thumbnailPadTop,
thumbnailPadBottom: entry.thumbnailPadBottom,
thumbnailTitleGap: entry.thumbnailTitleGap,
thumbnailTitleHeight: entry.thumbnailTitleHeight,
thumbnailTitleChars: entry.thumbnailTitleChars,
thumbnailTitleWordBoundary: entry.thumbnailTitleWordBoundary === true,
thumbnailBackground: entry.thumbnailBackground,
thumbnailTitleColor: entry.thumbnailTitleColor,
thumbnailTitleFont: entry.thumbnailTitleFont,
@@ -615,13 +577,21 @@ export function normalizeOverlayEntry(sourceId, entry) {
_overlayTrackDisplayText: '',
_overlayThumbnailTitle:
variant === 'thumbnail'
? String(entry.title ?? '')
.toUpperCase()
.slice(
0,
? entry.thumbnailTitleWordBoundary === true
? truncateOverlayTitle(
String(entry.title ?? '').toUpperCase(),
Math.max(0, Math.floor(Number(entry.thumbnailTitleChars) || 0)) ||
undefined,
Infinity,
)
: String(entry.title ?? '')
.toUpperCase()
.slice(
0,
Math.max(
0,
Math.floor(Number(entry.thumbnailTitleChars) || 0),
) || undefined,
)
: '',
};
normalized._overlayKey = entryKey(source, id);
@@ -718,6 +688,12 @@ function normalizeSourceOptions(options = {}, previous = {}) {
DEFAULT_MOVING_SOLVE_MS,
) || 0,
),
onVisibilityChange:
options.onVisibilityChange === undefined
? previous.onVisibilityChange || null
: typeof options.onVisibilityChange === 'function'
? options.onVisibilityChange
: null,
};
}
@@ -848,6 +824,7 @@ function getOrCreateSource(sourceId, options = {}) {
cohortLists: [],
cohortCount: 0,
demandByDomain: new Map(),
visibleIds: new Set(),
options: normalizeSourceOptions(options),
};
_sources.set(id, source);
@@ -1185,18 +1162,17 @@ export function isOverlayPointVisible(
*/
function overlayRectIntersectsAny(rect, exclusions, count = exclusions.length) {
for (let i = 0; i < count; i++) {
const other = exclusions[i];
if (
rect.x < other.x + other.w &&
rect.x + rect.w > other.x &&
rect.y < other.y + other.h &&
rect.y + rect.h > other.y
)
return true;
if (overlayRectsOverlap(rect, exclusions[i])) return true;
}
return false;
}
function overlayRectsOverlap(a, b) {
return (
a.x < b.x + b.w && a.x + a.w > b.x && a.y < b.y + b.h && a.y + a.h > b.y
);
}
/**
* Like `overlayRectIntersectsAny`, but only against exclusions that composite
* BELOW the host — the ones a placement may never overlap at any cost.
@@ -1208,14 +1184,7 @@ function overlayRectIntersectsAnyHard(
) {
for (let i = 0; i < count; i++) {
const other = exclusions[i];
if (!other.hard) continue;
if (
rect.x < other.x + other.w &&
rect.x + rect.w > other.x &&
rect.y < other.y + other.h &&
rect.y + rect.h > other.y
)
return true;
if (other.hard && overlayRectsOverlap(rect, other)) return true;
}
return false;
}
@@ -2281,6 +2250,7 @@ function addPaintItem(record, placement, temporalAlpha, selected) {
item.lane = paintLaneForOverlayEntry(record.entry);
item.zIndex = record.entry.zIndex;
item.key = record.key;
item.collisionHidden = false;
item.stamp = _frameStamp;
_paintQueue[_paintCount++] = item;
// Indexed by source and id rather than by `record.key`, so a lookup builds
@@ -2526,6 +2496,7 @@ function entryKeyholeAlpha(entry, placement, keyhole) {
}
function paintEntryItem(item, keyhole, sonar) {
if (item.collisionHidden) return;
const { record, placement } = item;
const entry = record.entry;
const keyholeAlpha = entryKeyholeAlpha(entry, placement, keyhole);
@@ -2576,6 +2547,90 @@ function paintEntryItem(item, keyhole, sonar) {
_paintedBySource[entry.source]++;
}
function compareYieldingPaintItems(a, b) {
const aYields = !!a.record.entry.yieldToCollisionGroup;
const bYields = !!b.record.entry.yieldToCollisionGroup;
return (
Number(aYields) - Number(bYields) ||
b.record.entry.priority - a.record.entry.priority ||
compareStableKeys(a.key, b.key)
);
}
/** Recheck yielding content every painted frame, even between camera solves.
* The arbiter's sticky/exit placements are intentionally retained for cards;
* labels can only use the remaining rectangles. All buffers are reused. */
function declutterYieldingEntries() {
let hasYielding = false;
for (let i = 0; i < _paintCount; i++)
if (_paintQueue[i].record.entry.yieldToCollisionGroup) {
hasYielding = true;
break;
}
if (!hasYielding) return;
sortPooledRange(_paintQueue, _paintCount, compareYieldingPaintItems);
for (let i = 0; i < _paintCount; i++) {
const item = _paintQueue[i];
const entry = item.record.entry;
if (!entry.yieldToCollisionGroup) continue;
const placements = item.record.placements;
let accepted = null;
// Try the arbiter's chosen corner first, then its other valid placements.
for (let p = -1; p < placements.length; p++) {
const placement = p < 0 ? item.placement : placements[p];
if (p >= 0 && placement === item.placement) continue;
let blocked = false;
for (let j = 0; j < i; j++) {
const other = _paintQueue[j];
if (other.collisionHidden) continue;
const group = other.record.entry.collisionGroup;
if (
(group === entry.collisionGroup ||
group === entry.yieldToCollisionGroup) &&
overlayRectsOverlap(placement.rect, other.placement.rect)
) {
blocked = true;
break;
}
}
if (!blocked) {
accepted = placement;
break;
}
}
if (accepted) item.placement = accepted;
else item.collisionHidden = true;
}
}
function syncPaintVisibility(painted = true) {
for (let s = 0; s < _sourceList.length; s++) {
const source = _sourceList[s];
const callback = source.options.onVisibilityChange;
if (!callback) continue;
const count = painted ? _paintedBySource[source.id] || 0 : 0;
let changed = count !== source.visibleIds.size;
if (!changed && painted) {
for (const id of source.visibleIds) {
if (
_paintRectByKey.get(entryKey(source.id, id))?.stamp !== _frameStamp
) {
changed = true;
break;
}
}
}
if (!changed) continue;
source.visibleIds.clear();
if (painted)
for (let i = 0; i < _paintRectCount; i++) {
const rect = _paintRectPool[i];
if (rect.sourceId === source.id) source.visibleIds.add(rect.entryId);
}
callback(source.visibleIds);
}
}
function paintFrame(keyhole) {
const started = nowMs();
const sonar = isCyberSonarActive()
@@ -2590,6 +2645,7 @@ function paintFrame(keyhole) {
clearCanvas(false, true);
_paintRectCount = 0;
_hitRectCount = 0;
declutterYieldingEntries();
sortPooledRange(_paintQueue, _paintCount, comparePaintItems);
// The shared canvas is not clipped either. Cards already avoid solid chrome
// by placement, and every occluder composites above this host in the DOM, so
@@ -2612,6 +2668,7 @@ function paintFrame(keyhole) {
_diagnostics.paintRectPoolSize = _paintRectPool.length;
_diagnostics.paintMs = nowMs() - started;
syncAccessibleActions();
syncPaintVisibility();
_canvasNeedsClear =
_paintRectCount > 0 || activeCustomPaintLaneCount(PAINT_TARGET_SHARED) > 0;
}
@@ -2668,6 +2725,7 @@ function drawWorldOverlay() {
_hitRectCount = 0;
syncAccessibleActions();
}
syncPaintVisibility(false);
return;
}
if (_resizeDirty) ensureCanvasSize();
@@ -2802,6 +2860,7 @@ export function destroyWorldOverlay() {
) {
delete window.__gevWorldOverlay;
}
syncPaintVisibility(false);
_sources.clear();
_sourceList.length = 0;
for (let i = 0; i < _customPaintLaneList.length; i++) {