mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Read the HUD and share-link camera through the renderer's camera port
The first camera-family slice. The camera port's events move into a shared module (render/camera/events.js) that the stub and the Cesium port both use: listener lists, delivery with errors reported, and the contract's per-listener `changed` measure. The Cesium port gains: - camera.on: `changed` measured per listener on every tick, where Cesium measures its single threshold (the counts match Cesium's own at each threshold); moveStart and moveEnd relayed from Cesium's camera; - camera.viewRectangle, in degrees (now in CESIUM_CHECKS); - lon and lat in pose, and NaN where Cesium has no cartographic position. Code that still holds the viewer reaches the renderer through rendererOf(viewer); the application renderer binds it on create and unbinds on destroy. The HUD reads its telemetry from the camera port and no longer imports Cesium (off the allow-list). The share link writes the hash from the pose. Its restore path stays on the viewer's camera for a later slice. Behaviour changes: - The share link listens to `changed` at its own 0.5 threshold, not at whatever global threshold layers had set, and also to moveEnd, so the hash always catches up with where the camera comes to rest. - The HUD's and share link's camera callbacks run from the port's single relay, ahead of other moveStart/moveEnd listeners, and a throw in one is reported to the renderer's error listeners instead of escaping from Cesium's render.
This commit is contained in:
1 parent
910185bfe0
commit
b5900b4178
28 files changed
+688
-243
No files matched your search
@@ -25,6 +25,8 @@ import { hudReadouts } from './testSupport/hudReadouts.mjs';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { registerHooks } from 'node:module';
|
||||
import { ensureGeoidReady } from './data/geoid.js';
|
||||
import { fakeCameraPort } from './testSupport/fakeCameraPort.mjs';
|
||||
import { toDegrees as deg } from './geo/index.js';
|
||||
|
||||
const MGRS_STUB_URL = 'gev-test-stub:mgrs';
|
||||
registerHooks({
|
||||
@@ -65,39 +67,29 @@ const SFO_ELLIPSOIDAL_M = -15;
|
||||
function installHudEnvironment() {
|
||||
const { elements, publish, view } = hudReadouts();
|
||||
const previousDocument = globalThis.document;
|
||||
const cameraListeners = {};
|
||||
const camera = fakeCameraPort({
|
||||
pose: {
|
||||
pitch: -Math.PI / 2,
|
||||
lat: deg((SFO.latDeg * Math.PI) / 180),
|
||||
lon: deg((SFO.lonDeg * Math.PI) / 180),
|
||||
height: SFO_ELLIPSOIDAL_M,
|
||||
},
|
||||
});
|
||||
globalThis.document = {
|
||||
getElementById: (id) => elements.get(id) ?? null,
|
||||
querySelectorAll: () => [],
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
};
|
||||
const viewer = {
|
||||
camera: {
|
||||
pitch: -Math.PI / 2,
|
||||
positionCartographic: {
|
||||
latitude: (SFO.latDeg * Math.PI) / 180,
|
||||
longitude: (SFO.lonDeg * Math.PI) / 180,
|
||||
height: SFO_ELLIPSOIDAL_M,
|
||||
},
|
||||
computeViewRectangle: () => undefined,
|
||||
moveStart: {
|
||||
addEventListener(listener) {
|
||||
cameraListeners.moveStart = listener;
|
||||
},
|
||||
removeEventListener() {},
|
||||
},
|
||||
moveEnd: {
|
||||
addEventListener(listener) {
|
||||
cameraListeners.moveEnd = listener;
|
||||
},
|
||||
removeEventListener() {},
|
||||
},
|
||||
},
|
||||
const viewer = {};
|
||||
const cameraListeners = {
|
||||
moveStart: () => camera.emit('moveStart'),
|
||||
moveEnd: () => camera.emit('moveEnd'),
|
||||
};
|
||||
return {
|
||||
elements,
|
||||
viewer,
|
||||
camera,
|
||||
publish,
|
||||
view,
|
||||
cameraListeners,
|
||||
@@ -204,7 +196,7 @@ test('a cold tick paints both readouts uncorrected, and resolving flips both in
|
||||
const env = installHudEnvironment();
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, publish: env.publish });
|
||||
const alt = () => env.elements.get('hud-alt').textContent;
|
||||
const summary = () => env.elements.get('hud-summary').textContent;
|
||||
|
||||
@@ -253,12 +245,14 @@ test('the corrected readouts are the MSL datum, not a coincidence of the SFO sig
|
||||
const env = installHudEnvironment();
|
||||
// London: N is +46 m, so the correction moves the readout DOWN. A sign flip
|
||||
// that happens to look right at SFO fails here.
|
||||
env.viewer.camera.positionCartographic.latitude = (51.5072 * Math.PI) / 180;
|
||||
env.viewer.camera.positionCartographic.longitude = (-0.1275 * Math.PI) / 180;
|
||||
env.viewer.camera.positionCartographic.height = 100;
|
||||
env.camera.setPose({
|
||||
lat: deg((51.5072 * Math.PI) / 180),
|
||||
lon: deg((-0.1275 * Math.PI) / 180),
|
||||
height: 100,
|
||||
});
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, publish: env.publish });
|
||||
hud._updateCameraData(); // cold: requests the grid, paints uncorrected
|
||||
assert.match(env.elements.get('hud-alt').textContent, /^ALT: 100m/);
|
||||
await ensureGeoidReady();
|
||||
@@ -293,7 +287,7 @@ test('a summary asked for one view is dropped once the camera moves', async () =
|
||||
};
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { summaryService, publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, summaryService, publish: env.publish });
|
||||
let place = 'Yellowstone';
|
||||
hud._summaryContext = async () => ({ placeLabels: [place] });
|
||||
const summary = () => env.elements.get('hud-summary').textContent;
|
||||
@@ -353,7 +347,7 @@ test('a request the camera leaves paints nothing: aborted, failed, or its contex
|
||||
};
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { summaryService, publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, summaryService, publish: env.publish });
|
||||
hud._summaryContext = async () => ({ placeLabels: ['Yellowstone'] });
|
||||
const element = env.elements.get('hud-summary');
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
@@ -415,7 +409,7 @@ test('a cancelled summary retries the same context but completed answers stay re
|
||||
};
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { summaryService, publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, summaryService, publish: env.publish });
|
||||
hud._summaryContext = async () => ({ placeLabels: ['San Francisco'] });
|
||||
hud._updateCameraData();
|
||||
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
||||
@@ -472,7 +466,7 @@ test('after a dropped or timed-out request the next tick asks again, and a move
|
||||
};
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { summaryService, publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, summaryService, publish: env.publish });
|
||||
// The same place before and after: a slow follow camera, a small pan.
|
||||
hud._summaryContext = async () => ({ placeLabels: ['Lisboa'] });
|
||||
const element = env.elements.get('hud-summary');
|
||||
@@ -537,7 +531,7 @@ test('a summary interrupted while typing can retry unchanged context', async (t)
|
||||
};
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { summaryService, publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, summaryService, publish: env.publish });
|
||||
hud._summaryContext = async () => ({ placeLabels: ['San Francisco'] });
|
||||
hud._updateCameraData();
|
||||
await hud._updateSummary(true);
|
||||
@@ -578,7 +572,7 @@ test('a retired Operator layout falls back to Tactical in the live HUD', () => {
|
||||
const env = installHudEnvironment();
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { publish: env.publish });
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, publish: env.publish });
|
||||
hud.setVariant('minimal');
|
||||
assert.equal(hud.getVariant(), 'minimal');
|
||||
hud.setVariant('operator');
|
||||
@@ -589,3 +583,39 @@ test('a retired Operator layout falls back to Tactical in the live HUD', () => {
|
||||
env.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('a camera with no position leaves the readouts as they were', () => {
|
||||
const env = installHudEnvironment();
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, publish: env.publish });
|
||||
hud._updateCameraData();
|
||||
const alt = env.elements.get('hud-alt').textContent;
|
||||
const metrics = hud._latestMetrics;
|
||||
env.camera.setPose({ lon: NaN, lat: NaN, height: NaN });
|
||||
hud._updateCameraData();
|
||||
assert.equal(env.elements.get('hud-alt').textContent, alt);
|
||||
assert.equal(hud._latestMetrics, metrics);
|
||||
assert.doesNotMatch(alt, /NaN/);
|
||||
} finally {
|
||||
hud?.destroy();
|
||||
env.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('the view window is measured from the camera’s rectangle in degrees', () => {
|
||||
const env = installHudEnvironment();
|
||||
let hud;
|
||||
try {
|
||||
hud = new IntelHUD(env.viewer, { camera: env.camera.port, publish: env.publish });
|
||||
assert.equal(hud._viewWindowKm(0), null, 'no rectangle, no window');
|
||||
env.camera.setViewRectangle({ west: -1, south: -0.5, east: 1, north: 0.5 });
|
||||
assert.deepEqual(hud._viewWindowKm(0), { widthKm: 222, heightKm: 111 });
|
||||
// Across the antimeridian: the short way round.
|
||||
env.camera.setViewRectangle({ west: 179, south: 0, east: -179, north: 1 });
|
||||
assert.equal(Math.round(hud._viewWindowKm(60).widthKm), 111);
|
||||
} finally {
|
||||
hud?.destroy();
|
||||
env.restore();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user