Merge origin/main: shipwrecks, news, transit fronts, signal-lost trails and uncredited photos on the renderer's ports

Upstream's layers and changes are carried onto the ports, with no Cesium
outside src/render and no reach into the viewer:

- Shipwrecks draw as one icon set, clicked through the input dispatcher.
- News draws through draw sets, the camera port and the input dispatcher;
  its beacons pulse each frame through the frame port.
- The scene occlusion probe moves into src/render/cesium and reaches
  detection through a new application hook, createOcclusionProbe; its
  private Cesium reads go through internals.js.
- Flight and military trails, the stale and SIGNAL LOST cue, coasting and
  following the world clock run on the draw and frame ports. GPU icons
  follow the scene clock while the world clock is followed, and fade when
  stale. A report that holds is not planned again every tick.
- Vessels are keyed by their record id.

The stub boot now enables military, shipwrecks and news as well.
This commit is contained in:
Sameh Khamis committed 2026-11-10 20:03:28 -08:00
commit a755f63638
331 files changed
+40654 -1666

No files matched your search

+139 -16
View File
@@ -15,6 +15,16 @@
* The history changes at poll cadence (~15-60 s) plus once on backfill; the
* head may change every frame. Either is rebuilt alone, under the same pick
* id, without rebuilding the other.
*
* A history with breaks (`setSegments`) draws each segment separately and
* nothing between them. Every segment is cut into lines of up to
* CHUNK_POINTS points; adjacent lines share their boundary point, so the
* trail has no seam. A line is identified by its position objects, so it is
* never rewritten by an update that keeps those points: appends, a backfill
* prepended ahead of it, or the oldest points dropping off the front (which
* rewrites only the first line). Only the newest line of the newest segment
* changes as the trail grows, and the draw port lets lines that stop
* changing settle into static geometry.
*/
import { cssColor } from '../render/color.js';
import { findDraw } from '../render/rendererOf.js';
@@ -43,6 +53,8 @@ const HEAD_ALPHA = 0.9;
const HEAD_OCCLUDED_ALPHA = 0.45;
/** @constant {number} Squared distance (m^2) below which consecutive points are merged. */
const MIN_SEGMENT_DISTANCE_SQ = 0.01;
/** @constant {number} Points per history line; adjacent lines share one point. */
export const CHUNK_POINTS = 128;
/** `css` (any CSS colour) at `alpha`, as a renderer colour. */
function colorAt(css, alpha) {
@@ -69,14 +81,38 @@ function trailPositions(given) {
return positions.length >= 2 ? positions : [];
}
/** `trailPositions`, keeping the given position objects (a line's identity). */
function keptPositions(given) {
const positions = [];
for (const position of Array.isArray(given) ? given : []) {
if (!position) continue;
const last = positions[positions.length - 1];
if (last && distanceSq(last, position) < MIN_SEGMENT_DISTANCE_SQ) continue;
positions.push(position);
}
return positions.length >= 2 ? positions : [];
}
const plain = ({ x, y, z }) => ({ x, y, z });
/** Whether `chunk` holds exactly the same position objects as `seg` from `start`. */
function sameRun(chunk, seg, start) {
const positions = chunk.positions;
if (start + positions.length > seg.length) return false;
for (let k = 0; k < positions.length; k++)
if (positions[k] !== seg[start + k]) return false;
return true;
}
/**
* Create an always-visible polyline trail bound to a viewer.
* @param {object} viewer - Viewer whose renderer draws the trail.
* @param {object} options - Trail options.
* @param {string} options.color - CSS colour of the trail.
* @param {number} [options.width=2.5] - Line width in pixels.
* @returns {{setPositions: function(Array<{x: number, y: number, z: number}>): void, setHead: function(Array<{x: number, y: number, z: number}>|null): void, setVisible: function(boolean): void, clear: function(): void, destroy: function(): void}}
* Trail handle: setPositions replaces the history, setHead the live head
* @returns {{setPositions: function(Array<{x: number, y: number, z: number}>): void, setSegments: function(Array<Array<{x: number, y: number, z: number}>>): void, setHead: function(Array<{x: number, y: number, z: number}>|null): void, setVisible: function(boolean): void, clear: function(): void, destroy: function(): void}}
* Trail handle: setPositions replaces the history with one line,
* setSegments with one per segment, setHead the live head
* (null or fewer than 2 positions: none), setVisible temporarily hides
* both without discarding them, clear empties both, and destroy removes
* the trail permanently.
@@ -93,6 +129,10 @@ export function createTrail(viewer, { color, width = 2.5 }) {
const drawn = new Map();
/** The head given while the trail is hidden, drawn once it shows. */
let pendingHead = null;
/** History lines before the newest one, oldest first: each line's id and
* the position objects it was drawn from, which never change. */
let chunks = [];
let chunkSeq = 0;
function ensureSet() {
if (set || destroyed || !viewer || viewer.isDestroyed?.()) return set;
@@ -118,7 +158,13 @@ export function createTrail(viewer, { color, width = 2.5 }) {
lines.upsert([hidden]);
return;
}
const item = {
const item = lineItem(id, positions, alpha, occludedAlpha, mode);
drawn.set(id, { key, item });
lines.upsert([item]);
}
function lineItem(id, positions, alpha, occludedAlpha, mode = 'geodesic') {
return {
id,
positions,
widthPx: width,
@@ -128,8 +174,77 @@ export function createTrail(viewer, { color, width = 2.5 }) {
// mesh renders dimmed — it must never disappear into the ground.
depthFail: { kind: 'solid', color: colorAt(color, occludedAlpha) },
};
drawn.set(id, { key, item });
lines.upsert([item]);
}
/**
* Cut the history's segments into lines, keeping every line whose points
* are still drawn in the same order. New lines end where a kept one
* begins, so dropping the oldest point rewrites only the first line. The
* newest line of the newest segment is the body line, the one that grows.
* @param {Array<Array<{x: number, y: number, z: number}>>} list
*/
function setSegments(list) {
if (destroyed || !viewer || viewer.isDestroyed?.()) return;
const lines = ensureSet();
if (!lines) return;
const segments = (Array.isArray(list) ? list : [])
.map(keptPositions)
.filter((positions) => positions.length >= 2);
const byStart = new Map();
for (const chunk of chunks) byStart.set(chunk.positions[0], chunk);
const kept = new Set();
const reusable = (seg, j) => {
const chunk = byStart.get(seg[j]);
return chunk && !kept.has(chunk) && sameRun(chunk, seg, j) ? chunk : null;
};
const next = [];
const added = [];
let tail = [];
segments.forEach((seg, s) => {
const newest = s === segments.length - 1;
let i = 0;
while (i < seg.length - 1) {
const existing = reusable(seg, i);
if (existing) {
kept.add(existing);
next.push(existing);
i += existing.positions.length - 1;
continue;
}
if (newest && seg.length - i <= CHUNK_POINTS) {
tail = seg.slice(i);
break;
}
let end = Math.min(seg.length - 1, i + CHUNK_POINTS - 1);
for (let j = i + 1; j < end; j++) {
if (reusable(seg, j)) {
end = j;
break;
}
}
const positions = seg.slice(i, end + 1);
const chunk = { id: `${bodyId}:${++chunkSeq}`, positions };
next.push(chunk);
added.push(
lineItem(
chunk.id,
positions.map(plain),
TRAIL_ALPHA,
TRAIL_OCCLUDED_ALPHA,
),
);
i = end;
}
});
const gone = chunks.filter((chunk) => !kept.has(chunk));
chunks = next;
if (gone.length) lines.remove(gone.map((chunk) => chunk.id));
if (added.length) lines.upsert(added);
// Round 8 (owner: UAL1104's Pacific trail "cutting through the
// globe"): straight 3D chords between sparse trans-oceanic
// waypoints tunnel through the planet; a geodesic line follows the
// curved surface (heights interpolated) instead.
draw(bodyId, tail.map(plain), TRAIL_ALPHA, TRAIL_OCCLUDED_ALPHA);
}
/**
@@ -163,18 +278,19 @@ export function createTrail(viewer, { color, width = 2.5 }) {
* ECEF positions, oldest -> newest.
*/
setPositions(cartesians) {
// Round 8 (owner: UAL1104's Pacific trail "cutting through the
// globe"): straight 3D chords between sparse trans-oceanic
// waypoints tunnel through the planet; a geodesic line follows the
// curved surface (heights interpolated) instead.
draw(
bodyId,
trailPositions(cartesians),
TRAIL_ALPHA,
TRAIL_OCCLUDED_ALPHA,
);
setSegments([cartesians]);
},
/**
* Replace the trail geometry with chronological segments (oldest
* first), nothing drawn between them. A segment with fewer than 2
* distinct positions draws nothing. Pass the same position objects on
* every update: a line whose points are unchanged is never rewritten.
* @param {Array<Array<{x: number, y: number, z: number}>>} list
* Segments, each oldest -> newest.
*/
setSegments,
setHead,
/** Temporarily hide/show the trail without discarding accumulated history. */
@@ -187,8 +303,14 @@ export function createTrail(viewer, { color, width = 2.5 }) {
/** Empty the trail, keeping its set (cheap re-arm). */
clear() {
pendingHead = null;
if (!destroyed && set && !viewer?.isDestroyed?.() && drawn.size) {
if (
!destroyed &&
set &&
!viewer?.isDestroyed?.() &&
(drawn.size || chunks.length)
) {
drawn.clear();
chunks = [];
set.clear();
}
},
@@ -203,6 +325,7 @@ export function createTrail(viewer, { color, width = 2.5 }) {
}
set = null;
drawn.clear();
chunks = [];
},
};
}