Merge Core main into denis/gev-sensor-zoom

# Conflicts:
#	src/cockpitOrbital.test.mjs
This commit is contained in:
Sameh Khamis committed 2026-11-08 16:20:37 -08:00
commit 9a16fb8cbc
111 files changed
+4022 -207

No files matched your search

+4 -2
View File
@@ -32,7 +32,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
1,
Math.ceil(layerState._denseIds.length / DENSE_REFRESH_FRAMES),
);
const now = new Date();
const now = new Date(layerState.now());
for (let i = 0; i < perFrame; i++) {
if (layerState._denseCursor >= layerState._denseIds.length)
layerState._denseCursor = 0;
@@ -97,7 +97,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
const entries = parts.orbits.parseTLE(text);
const style = POINT_STYLES.dense;
const now = new Date();
const now = new Date(layerState.now());
let added = 0;
for (let start = 0; start < entries.length; start += DENSE_CREATE_CHUNK) {
@@ -172,6 +172,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
layerState._count = layerState._points.size;
layerState._catalogRevision++;
layerState.coverageChanged();
layerState._denseStatus = 'ready';
console.log(
`[Data:Satellites] Dense catalog: +${added} ${DENSE_GROUP_PATH} (points only)`,
@@ -247,6 +248,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
layerState._denseCursor = 0;
layerState._count = layerState._points.size;
layerState._catalogRevision++;
layerState.coverageChanged();
}
return {
_abortActiveUpdates,
+2
View File
@@ -326,6 +326,7 @@ test('a failed Starlink load hides the core catalog Starlink points again', asyn
_detectionObjects: new Map(),
_trackedNorad: null,
_activeUpdateControllers: new Set(),
coverageChanged() {},
};
const catalog = createCatalog({
state,
@@ -384,6 +385,7 @@ test('enabling the layer leaves a hidden Stations class without its ISS ring', a
[90001, other],
]),
_points: new Map(),
coverageChanged() {},
};
const { methods } = createLifecycle({
state,
+10 -2
View File
@@ -202,16 +202,24 @@ export function createCockpitSubject({ state: layerState, parts }) {
// The tracked primitive stays hidden: its entity draws the dot.
if (noradId !== tracked) _setPointShown(noradId, true);
}
// Re-applied every sync: a catalog rebuild replaces the point
// primitives, and the new ones arrive shown.
for (const noradId of companions) {
if (noradId === tracked || hiddenPoints.has(noradId)) continue;
if (noradId === tracked) continue;
hiddenPoints.add(noradId);
_setPointShown(noradId, false);
}
if (held) {
const trackedPoint = layerState._points.get(tracked);
if (trackedPoint) trackedPoint.show = false;
}
const hiddenPath = layerState._cockpitHiddenPath;
if (hiddenPath !== null && (!held || hiddenPath !== tracked)) {
const path = layerState._orbitPaths.get(hiddenPath);
if (path)
// The ISS's ring also follows its class (and its tracking).
if (path && hiddenPath === ISS_NORAD) parts.controls._syncIssOrbit();
else if (path)
path.primitive.show = parts.controls.satelliteVisualsVisible(
layerState._enabled,
layerState._params.showOrbits,
+45 -3
View File
@@ -154,7 +154,7 @@ async function fixture(t) {
await parts.lifecycle.methods.init(viewer);
await parts.ingestion.methods.update(viewer);
parts.lifecycle.methods.enable(viewer);
// GPS is TELECOM, hidden by default; these tests need its point on screen.
// GPS is TELECOM; these tests need its point on screen whatever the default.
parts.controls.methods.setParams({ classes: { telecom: true } });
Object.assign(console, { log, warn });
t.after(() => {
@@ -377,6 +377,38 @@ test('untracking a held subject gives its marks back', async (t) => {
assert.equal(f.state._points.get(ISS_NORAD).show, true);
});
test('a catalog refresh while held keeps the subject and its companions hidden', async (t) => {
const f = await fixture(t);
f.track(ISS_NORAD);
f.nextFrame();
f.methods.setCockpitSubject(ISS_NORAD);
const log = console.log;
console.log = () => {};
try {
await f.parts.ingestion.methods.update(f.viewer);
} finally {
console.log = log;
}
f.nextFrame();
assert.equal(f.state._points.get(COMPANION).show, false, 'companion');
assert.equal(f.state._points.get(ISS_NORAD).show, false, 'tracked point');
f.methods.setCockpitSubject(null);
assert.equal(f.state._points.get(COMPANION).show, true, 'given back');
});
test('untracking a held ISS leaves its ring hidden while Stations is off', async (t) => {
const f = await fixture(t);
f.track(ISS_NORAD);
f.nextFrame();
f.methods.setCockpitSubject(ISS_NORAD);
f.methods.setParams({ classes: 'itpd' });
f.nextFrame();
f.methods.stopTracking();
assert.equal(f.ring(ISS_NORAD).show, false);
f.methods.setParams({ classes: 'sitpd' });
assert.equal(f.ring(ISS_NORAD).show, true);
});
test('tracking without a Cockpit subject keeps its marks', async (t) => {
const f = await fixture(t);
f.track(GPS);
@@ -555,8 +587,18 @@ test('the ground track bearing comes from the SGP4 velocity, less the Earth turn
test('the subject says whether its class may be ridden', () => {
const fix = { latitude: 0, longitude: 0, altitude: 400_000 };
const subject = (satelliteClass) =>
satelliteCockpitInfo(1, { name: 'X', group: 'visual', satelliteClass }, fix);
satelliteCockpitInfo(
1,
{ name: 'X', group: 'visual', satelliteClass },
fix,
);
assert.equal(subject('debris').enterable, false);
for (const satelliteClass of ['stations', 'imaging', 'telecom', 'starlink', 'probes'])
for (const satelliteClass of [
'stations',
'imaging',
'telecom',
'starlink',
'probes',
])
assert.equal(subject(satelliteClass).enterable, true, satelliteClass);
});
+4 -1
View File
@@ -314,7 +314,10 @@ export function createControls({ state: layerState, services, parts, source }) {
if (noradId === null) return null;
const sat = layerState._catalog.get(noradId);
const pos = parts.orbits.propagatePosition(sat.satrec, new Date());
const pos = parts.orbits.propagatePosition(
sat.satrec,
new Date(layerState.now()),
);
if (!pos) return null;
return {
+2 -1
View File
@@ -294,7 +294,7 @@ export function createIngestion({
layerState._denseLoadToken++; // cancel any in-flight dense load against the old catalog
parts.labels._syncIssOverlay();
const now = new Date();
const now = new Date(layerState.now());
// Process all TLE entries in CATALOG_GROUPS order
const allEntries = [];
@@ -425,6 +425,7 @@ export function createIngestion({
// the rebuild must not block on that.
void parts.tracking._reconcileTrackedSubjectContext();
parts.tracking._applyPendingTrackingRestore();
layerState.coverageChanged();
} catch (e) {
if (updateSignal.aborted || e?.name === 'AbortError') {
throw new DOMException('Satellite update aborted', 'AbortError');
+2
View File
@@ -40,6 +40,8 @@ function ingestionFor(catalogText, { source: sourceExtras = {} } = {}) {
_params: { catalog: 'core', showOrbits: false },
_satcat: new Map(),
_ucs: null,
now: Date.now,
coverageChanged() {},
};
const parts = {
orbits: {
+24 -1
View File
@@ -1,5 +1,10 @@
import * as Cesium from 'cesium';
import { ISS_NORAD, ISS_OVERLAY_SOURCE_ID } from './policy.js';
import {
ISS_NORAD,
ISS_OVERLAY_SOURCE_ID,
SATELLITE_COVERAGE_MS,
} from './policy.js';
import { worldClock } from '../../time/worldClock.js';
export function createLifecycle({
state: layerState,
@@ -8,6 +13,20 @@ export function createLifecycle({
source,
}) {
const { clearFocusTarget } = services.focus;
// While on with a catalog, satellites can be shown at any time in reach of
// their element sets. Registered once; off, the layer has no time to show,
// and each step tells the clock once it has settled.
worldClock.register({
id: 'satellites',
coverage: () => {
if (!layerState._enabled || !layerState._catalog.size) return null;
const now = worldClock.wallNow();
return {
start: now - SATELLITE_COVERAGE_MS,
end: now + SATELLITE_COVERAGE_MS,
};
},
});
const { holdContinuousRender, releaseContinuousRender } = services.render;
const { registerPickOwner, unregisterPickOwner } = services.picking;
@@ -50,6 +69,7 @@ export function createLifecycle({
layerState._denseStatus = 'idle';
layerState._denseError = null;
layerState._catalogRevision++;
layerState.coverageChanged();
// Point primitives for satellite dots
layerState._pointCollection = new Cesium.PointPrimitiveCollection();
@@ -99,6 +119,7 @@ export function createLifecycle({
);
}
parts.tracking._applyPendingTrackingRestore();
layerState.coverageChanged();
},
disable(viewer) {
@@ -126,6 +147,7 @@ export function createLifecycle({
layerState._preRenderListener();
layerState._preRenderListener = null;
}
layerState.coverageChanged();
},
destroy(viewer) {
@@ -183,6 +205,7 @@ export function createLifecycle({
failedGroups: [],
};
layerState._viewer = null;
layerState.coverageChanged();
},
};
+3 -3
View File
@@ -197,7 +197,7 @@ export function createOrbits({ state: layerState, services, parts, source }) {
lonDeg,
minElevDeg = 10,
requireVisible = false,
fromMs = Date.now(),
fromMs = layerState.now(),
}) {
return getNextSatellitePass(ISS_NORAD, {
latDeg,
@@ -227,7 +227,7 @@ export function createOrbits({ state: layerState, services, parts, source }) {
lonDeg,
minElevDeg = 10,
requireVisible = false,
fromMs = Date.now(),
fromMs = layerState.now(),
},
) {
const id = Number(noradId);
@@ -331,7 +331,7 @@ export function createOrbits({ state: layerState, services, parts, source }) {
}
function orbitTrackFromRecord(name, satrec) {
const referenceDate = new Date();
const referenceDate = new Date(layerState.now());
const current = propagatePosition(satrec, referenceDate);
if (!current) return null;
return {
+9
View File
@@ -32,6 +32,15 @@ export const ORBIT_PATH_STEPS = 180;
// points per orbital path
export const POSITION_UPDATE_MS = 1000;
/** How far either side of now SGP4 on current element sets stays meaningful. */
export const SATELLITE_COVERAGE_MS = 14 * 24 * 3_600_000;
/**
* How far the world time may move from when an orbit ring was drawn before it
* is drawn again: the Earth's turn is followed exactly, but the orbit's plane
* drifts a few degrees a day.
*/
export const ORBIT_REBAKE_MS = 30 * 60_000;
// re-propagate every 1s (SGP4 is smooth at this rate)
export const RING_ROTATION_MS = 1000;
+1 -1
View File
@@ -82,7 +82,7 @@ export function createRecords({ state, parts }) {
const limit = Number.isFinite(maxCount)
? Math.max(1, Math.floor(maxCount))
: 2000;
const now = new Date();
const now = new Date(state.now());
const result = [];
const emit = (noradId, sat) => {
if (result.length >= limit) return false;
+19 -5
View File
@@ -1,6 +1,11 @@
import * as Cesium from 'cesium';
import { gstime } from 'satellite.js';
import { ISS_NORAD, POSITION_UPDATE_MS, RING_ROTATION_MS } from './policy.js';
import {
ISS_NORAD,
ORBIT_REBAKE_MS,
POSITION_UPDATE_MS,
RING_ROTATION_MS,
} from './policy.js';
export function createRendering({
state: layerState,
@@ -42,7 +47,7 @@ export function createRendering({
const sat = layerState._catalog.get(noradId);
if (!sat || !layerState._viewer) return;
const bakeDate = new Date();
const bakeDate = new Date(layerState.now());
const basePositions = parts.orbits.computeOrbitPath(sat.satrec, bakeDate);
if (basePositions.length < 2) return;
@@ -77,6 +82,8 @@ export function createRendering({
layerState._orbitPaths.set(noradId, {
primitive,
color: pathColor,
bakeMs: bakeDate.getTime(),
// Same Date object as computeOrbitPath's internal fixedGmst → identical
// GMST value (gstime is pure), so delta starts at exactly 0 and the
// initial identity modelMatrix is correct until the first ring tick.
@@ -120,8 +127,15 @@ export function createRendering({
function _updateOrbitPathRotations(nowDate) {
if (layerState._orbitPaths.size === 0) return;
for (const path of layerState._orbitPaths.values()) {
for (const [noradId, path] of [...layerState._orbitPaths]) {
if (!path.primitive) continue;
// The rotation keeps the ring under the dot for minutes; the plane
// itself precesses, so a world time moved far from the bake re-bakes.
if (Math.abs(nowDate.getTime() - path.bakeMs) > ORBIT_REBAKE_MS) {
_hideOrbitPath(noradId);
_showOrbitPath(noradId, path.color);
continue;
}
parts.orbits.orbitFrameModelMatrix(
path.gmstAtBake,
nowDate,
@@ -151,7 +165,7 @@ export function createRendering({
*/
function _propagateAll() {
const now = new Date();
const now = new Date(layerState.now());
let updated = 0;
for (const [noradId, sat] of layerState._catalog) {
@@ -223,7 +237,7 @@ export function createRendering({
layerState._params.showOrbits &&
now - layerState._lastRingRotation >= RING_ROTATION_MS
) {
_updateOrbitPathRotations(new Date(now));
_updateOrbitPathRotations(new Date(layerState.now()));
layerState._lastRingRotation = now;
}
}
+9
View File
@@ -1,5 +1,6 @@
import * as Cesium from 'cesium';
import { DEFAULT_SATELLITE_CLASSES } from './classes.js';
import { worldClock, worldTimeFor } from '../../time/worldClock.js';
export function createState({ services }) {
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
@@ -187,6 +188,14 @@ export function createState({ services }) {
state._cockpitHiddenDot = false;
/** The time satellites are propagated to, in epoch ms. */
state.now = worldTimeFor('satellites');
/** The catalog changed, so the time satellites can be shown at may have. */
state.coverageChanged = () => worldClock.coverageChanged();
// Scratch variables
state._scratchCartesian = new Cesium.Cartesian3();
+5 -2
View File
@@ -159,7 +159,7 @@ export function createTracking({ state: layerState, services, parts, source }) {
sat.satrec,
layerState._trackedFrameNowForTest
? new Date(layerState._trackedFrameNowForTest())
: new Date(),
: new Date(layerState.now()),
);
if (!pos) return layerState._trackedFrameGeo; // propagation hiccup — keep last good sample
layerState._trackedFrameGeo = pos;
@@ -440,7 +440,10 @@ export function createTracking({ state: layerState, services, parts, source }) {
// Comfortable tracking landing: ~726 km back for LEO (user-validated
// "slightly zoomed out" framing — no stutter, label reads cleanly), scaled
// up for MEO/GEO so the camera doesn't land on top of a high-orbit dot.
const initialPos = parts.orbits.propagatePosition(sat.satrec, new Date());
const initialPos = parts.orbits.propagatePosition(
sat.satrec,
new Date(layerState.now()),
);
const viewScale =
initialPos && initialPos.altitude > HIGH_ORBIT_ALTITUDE_M
? TRACK_VIEW_FROM_HIGH_SCALE