mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read vessel, CCTV and FIRMS billboard state from the app's mirror
The three layers now add their billboards through addBillboard and write the mirrored fields through setBillboard, so selection, cards, queries, focus, view thinning and the FIRMS horizon cull read what was pushed from the app instead of from Cesium. Vessels and FIRMS state their sprites' own sizes (32 px ship artwork, the glow canvas at twice the core size), which the mirror needs. A vessel helper, iconPosition, replaces the repeated mirror-or-visual position lookups, and the vessel visibility pass writes show only when it changes, as CCTV and FIRMS already did. A billboard never given a position now has none in the mirror rather than the origin.
This commit is contained in:
1 parent
bb91688a62
commit
6639c4bb80
23 files changed
+152
-97
No files matched your search
@@ -39,6 +39,7 @@ import {
|
||||
presentSelectedVessel,
|
||||
subscribeSelectedVessel,
|
||||
} from '../hudReadouts.js';
|
||||
import { mirrorBillboard, setBillboard } from './billboardMirror.js';
|
||||
|
||||
test('open feed with vessels is healthy (null)', () => {
|
||||
assert.equal(deriveAisFeedError({ status: 'open', lastMessageAt: 1, error: null }, 42), null);
|
||||
@@ -659,12 +660,12 @@ test('vessel focus wire animates alpha with deadband and restores after tracking
|
||||
let writes = 0;
|
||||
const makeColor = (alpha) => ({ alpha, withAlpha: (next) => makeColor(next) });
|
||||
let color = makeColor(1);
|
||||
const billboard = {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
get color() { return color; },
|
||||
set color(next) { writes += 1; color = next; },
|
||||
};
|
||||
});
|
||||
const records = [{ position: billboard.position, billboard }];
|
||||
const target = {
|
||||
screenRect: { left: 40, top: 40, right: 60, bottom: 60 },
|
||||
@@ -713,12 +714,12 @@ test('vessel focus wire animates alpha with deadband and restores after tracking
|
||||
|
||||
test('vessel focus wire performs no alpha writes when nothing has been tracked', () => {
|
||||
let writes = 0;
|
||||
const billboard = {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
show: true,
|
||||
get color() { return { alpha: 1 }; },
|
||||
set color(_next) { writes += 1; },
|
||||
};
|
||||
});
|
||||
const result = applyVesselFocusDeemphasis({
|
||||
records: [{ position: billboard.position, billboard }],
|
||||
target: null,
|
||||
@@ -737,11 +738,11 @@ test('vessel focus wire performs no alpha writes when nothing has been tracked',
|
||||
|
||||
test('vessel focus wire restores a hidden sprite before releasing the active pass', () => {
|
||||
const makeColor = (alpha) => ({ alpha, withAlpha: (next) => makeColor(next) });
|
||||
const billboard = {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
color: makeColor(1),
|
||||
};
|
||||
});
|
||||
const records = [{ billboard }];
|
||||
const target = {
|
||||
screenRect: { left: 40, top: 40, right: 60, bottom: 60 },
|
||||
@@ -771,7 +772,7 @@ test('vessel focus wire restores a hidden sprite before releasing the active pas
|
||||
assert.equal(dimmed.activeCount, 1);
|
||||
assert.equal(billboard.color.alpha, params.dimFloor);
|
||||
|
||||
billboard.show = false;
|
||||
setBillboard(billboard, 'show', false);
|
||||
const releaseStart = pass(params.attackMs, null, dimmed.activeCount);
|
||||
const restored = pass(params.attackMs + params.releaseMs, null, releaseStart.activeCount);
|
||||
assert.equal(restored.ran, true);
|
||||
@@ -1350,9 +1351,11 @@ test('buildVesselCard: unnamed vessels title as MMSI; long names truncate', () =
|
||||
});
|
||||
|
||||
test('buildVesselCard: anchors to the billboard position when present', () => {
|
||||
const rendered = { x: 9, y: 9, z: 9 };
|
||||
const card = buildVesselCard(makeRecord({ billboard: { position: rendered } }));
|
||||
assert.equal(card.position, rendered);
|
||||
const rendered = new Cesium.Cartesian3(9, 9, 9);
|
||||
const card = buildVesselCard(
|
||||
makeRecord({ billboard: mirrorBillboard({ position: rendered }) }),
|
||||
);
|
||||
assert.deepEqual(card.position, rendered);
|
||||
});
|
||||
|
||||
test('buildVesselCard: tanker types carry the amber accent', () => {
|
||||
@@ -1742,11 +1745,12 @@ test('vessel selection passes the opaque source reference to optional history',
|
||||
|
||||
test('vessel focus wire skips hidden sprites at rest while a target is tracked', () => {
|
||||
const makeColor = (alpha) => ({ alpha, withAlpha: (next) => makeColor(next) });
|
||||
const sprite = (show) => ({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show,
|
||||
color: makeColor(1),
|
||||
});
|
||||
const sprite = (show) =>
|
||||
mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show,
|
||||
color: makeColor(1),
|
||||
});
|
||||
const visible = sprite(true);
|
||||
const hidden = Array.from({ length: 50 }, () => sprite(false));
|
||||
const records = [visible, ...hidden].map((billboard) => ({
|
||||
|
||||
@@ -31,12 +31,10 @@ const DEFAULTS = Object.freeze({
|
||||
/** Cesium copies positions and scalers on write; the mirror keeps its own copy too. */
|
||||
function copyInto(record, field, value) {
|
||||
if (field === 'position') {
|
||||
// Cesium keeps its old position when handed none; so does the mirror.
|
||||
if (!value && record.position) return;
|
||||
record.position = Cesium.Cartesian3.clone(
|
||||
value ?? Cesium.Cartesian3.ZERO,
|
||||
record.position,
|
||||
);
|
||||
// Cesium keeps its old position when handed none; so does the mirror. A
|
||||
// billboard never given one has none here (Cesium would report the origin).
|
||||
if (!value) return;
|
||||
record.position = Cesium.Cartesian3.clone(value, record.position);
|
||||
} else if (field === 'scaleByDistance') {
|
||||
record.scaleByDistance = value
|
||||
? Cesium.NearFarScalar.clone(value, record.scaleByDistance)
|
||||
@@ -97,7 +95,7 @@ export function setBillboard(billboard, field, value) {
|
||||
* The app's copy of a billboard's mirrored fields, or null when it has none (or
|
||||
* there is no billboard).
|
||||
* @param {Object|null|undefined} billboard
|
||||
* @returns {{ show: boolean, position: Cesium.Cartesian3, scale: number,
|
||||
* @returns {{ show: boolean, position?: Cesium.Cartesian3, scale: number,
|
||||
* rotation: number, width?: number, height?: number,
|
||||
* scaleByDistance?: Cesium.NearFarScalar }|null}
|
||||
*/
|
||||
|
||||
@@ -62,7 +62,7 @@ test('a billboard the app did not add can be mirrored from its fields', () => {
|
||||
const bb = mirrorBillboard({ show: false, scale: 2 });
|
||||
assert.equal(billboardState(bb).show, false);
|
||||
assert.equal(billboardState(bb).scale, 2);
|
||||
assert.ok(Cesium.Cartesian3.equals(billboardState(bb).position, Cesium.Cartesian3.ZERO));
|
||||
assert.equal(billboardState(bb).position, undefined, 'none was pushed');
|
||||
assert.equal(billboardState(null), null);
|
||||
assert.equal(mirrorBillboard(null), null);
|
||||
});
|
||||
|
||||
@@ -79,6 +79,7 @@ import {
|
||||
IDLE_CAMERA_COLOR,
|
||||
LIVE_CAMERA_COLOR,
|
||||
} from '../layers/cctv/policy.js';
|
||||
import { mirrorBillboard } from './billboardMirror.js';
|
||||
|
||||
const ASPECT = 16 / 9;
|
||||
const toRad = (deg) => (deg * Math.PI) / 180;
|
||||
@@ -355,7 +356,7 @@ test('default COVERAGE refresh materializes the active and visible camera frustu
|
||||
test('camera icons are violet for video feeds, cyan for stills, amber when active', () => {
|
||||
const record = (id, feedType) => ({
|
||||
camera: { ...UNCLAMPED_CAMERA, id, feedType, groundElevationM: 0 },
|
||||
billboard: {},
|
||||
billboard: mirrorBillboard({}),
|
||||
coverageEntities: [],
|
||||
projection: null,
|
||||
});
|
||||
@@ -682,7 +683,7 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
|
||||
camera: { id: 'a' },
|
||||
activationDone: true,
|
||||
probeClampRangeM: 105,
|
||||
billboard: { color: 'keep-color', scale: 1.25 },
|
||||
billboard: mirrorBillboard({ color: 'keep-color', scale: 1.25 }),
|
||||
coverageEntities: [{ show: true }, { show: true }],
|
||||
projection: { planeEntity: { show: true } },
|
||||
viewshedPrimitive: viewshedA,
|
||||
@@ -691,7 +692,7 @@ test('CCTV disable hide sweep hides record visuals and destroys viewsheds withou
|
||||
camera: { id: 'b' },
|
||||
activationDone: true,
|
||||
probeClampRangeM: 146,
|
||||
billboard: { color: 'keep-color', scale: 1 },
|
||||
billboard: mirrorBillboard({ color: 'keep-color', scale: 1 }),
|
||||
projection: null,
|
||||
viewshedPrimitive: viewshedB,
|
||||
},
|
||||
|
||||
@@ -10,6 +10,7 @@ import cctvLayer, {
|
||||
_viewRecordIdsForTest,
|
||||
refreshHorizonCulling,
|
||||
} from './cctv.js';
|
||||
import { mirrorBillboard } from './billboardMirror.js';
|
||||
|
||||
const WIDTH = 800;
|
||||
const HEIGHT = 600;
|
||||
@@ -40,7 +41,7 @@ function recordsAt(
|
||||
mountHeightM: 8,
|
||||
},
|
||||
position,
|
||||
billboard: { position, show: true },
|
||||
billboard: mirrorBillboard({ position, show: true }),
|
||||
coverageEntities: [],
|
||||
projection: null,
|
||||
};
|
||||
@@ -59,7 +60,11 @@ function viewerAt(heightM, screenByPosition, shiftX = 0) {
|
||||
scene: {
|
||||
canvas: { clientWidth: WIDTH, clientHeight: HEIGHT },
|
||||
cartesianToCanvasCoordinates: (position) => {
|
||||
const screen = screenByPosition.get(position);
|
||||
// The mirror holds its own copy of each position, so match by value.
|
||||
const key = [...screenByPosition.keys()].find((candidate) =>
|
||||
Cesium.Cartesian3.equals(candidate, position),
|
||||
);
|
||||
const screen = screenByPosition.get(key);
|
||||
return screen && { x: screen.x + shiftX, y: screen.y };
|
||||
},
|
||||
},
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from './groundFloor.js';
|
||||
import { unregisterSpriteCollection } from './spriteOrder.js';
|
||||
import { isOverlayPointVisible, normalizeOverlayEntry } from '../overlays/worldOverlay.js';
|
||||
import { mirrorBillboard } from './billboardMirror.js';
|
||||
|
||||
const AUSTIN = { lon: -97.7, lat: 30.2 };
|
||||
/** Antipode of Austin — as far behind the limb as a point on Earth can be. */
|
||||
@@ -34,13 +35,13 @@ const LIMB_DLON = 41.87;
|
||||
* the pass does not dirty the collection's vertex buffer needlessly.
|
||||
*/
|
||||
function billboard(position, show = true) {
|
||||
return {
|
||||
return mirrorBillboard({
|
||||
position,
|
||||
_show: show,
|
||||
writes: 0,
|
||||
get show() { return this._show; },
|
||||
set show(value) { this._show = value; this.writes += 1; },
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Cesium BillboardCollection-shaped stub. */
|
||||
|
||||
@@ -4,6 +4,7 @@ import { applyVesselFocusDeemphasis } from './aisLiveVessels.js';
|
||||
import { applyCctvFocusDeemphasis } from './cctv.js';
|
||||
import { applySatellitePointFocusDeemphasis } from './satellites.js';
|
||||
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
|
||||
import { mirrorBillboard } from './billboardMirror.js';
|
||||
|
||||
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
||||
const target = {
|
||||
@@ -51,14 +52,14 @@ function assertResumeGate(name, makePass) {
|
||||
}
|
||||
|
||||
assertResumeGate('vessel', () => {
|
||||
const billboard = {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
width: 32,
|
||||
height: 32,
|
||||
scale: 1,
|
||||
color: color(),
|
||||
};
|
||||
});
|
||||
return {
|
||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
||||
applyVesselFocusDeemphasis({
|
||||
@@ -76,14 +77,14 @@ assertResumeGate('vessel', () => {
|
||||
});
|
||||
|
||||
assertResumeGate('CCTV', () => {
|
||||
const billboard = {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
width: 24,
|
||||
height: 24,
|
||||
scale: 1,
|
||||
color: color(),
|
||||
};
|
||||
});
|
||||
const record = { camera: { id: 'cam-1' }, billboard };
|
||||
return {
|
||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
||||
|
||||
Reference in new issue
Block a user