mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Draw live AIS vessels from a GPU icon set
This commit is contained in:
1 parent
816002e3b9
commit
e0eb771217
20 files changed
+340
-318
No files matched your search
@@ -39,7 +39,7 @@ import {
|
||||
presentSelectedVessel,
|
||||
subscribeSelectedVessel,
|
||||
} from '../hudReadouts.js';
|
||||
import { mirrorBillboard, setBillboard } from './billboardMirror.js';
|
||||
import { createIconSet } from './iconSet.js';
|
||||
|
||||
test('open feed with vessels is healthy (null)', () => {
|
||||
assert.equal(deriveAisFeedError({ status: 'open', lastMessageAt: 1, error: null }, 42), null);
|
||||
@@ -656,17 +656,18 @@ test('disable and destroy make abort-ignoring AIS responses inert', async () =>
|
||||
}
|
||||
});
|
||||
|
||||
/** One vessel row in a fresh set, as the layer adds it, plus its record. */
|
||||
function focusFixture() {
|
||||
const icons = createIconSet();
|
||||
const row = icons.add('353136000', { layer: 'ais-live-vessels', id: '353136000' });
|
||||
icons.setSize(row, 32, 32);
|
||||
const record = { iconId: '353136000', position: { x: 1, y: 2, z: 3 }, visible: true };
|
||||
return { icons, records: [record], record, focus: () => icons.focus(icons.row('353136000')) };
|
||||
}
|
||||
|
||||
test('vessel focus wire animates alpha with deadband and restores after tracking ends', () => {
|
||||
let writes = 0;
|
||||
const makeColor = (alpha) => ({ alpha, withAlpha: (next) => makeColor(next) });
|
||||
let color = makeColor(1);
|
||||
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 { icons, records, focus } = focusFixture();
|
||||
const target = {
|
||||
screenRect: { left: 40, top: 40, right: 60, bottom: 60 },
|
||||
paddingPx: 0,
|
||||
@@ -686,6 +687,7 @@ test('vessel focus wire animates alpha with deadband and restores after tracking
|
||||
const apply = (nowMs, focusTarget) => {
|
||||
const result = applyVesselFocusDeemphasis({
|
||||
records,
|
||||
icons,
|
||||
target: focusTarget,
|
||||
previousActiveCount: activeCount,
|
||||
nowMs,
|
||||
@@ -694,34 +696,30 @@ test('vessel focus wire animates alpha with deadband and restores after tracking
|
||||
params,
|
||||
});
|
||||
activeCount = result.activeCount;
|
||||
writes += result.writes;
|
||||
return result;
|
||||
};
|
||||
|
||||
assert.equal(apply(0, target).writes, 0);
|
||||
assert.equal(apply(150, target).writes, 1);
|
||||
assert.ok(color.alpha > 0.25 && color.alpha < 1);
|
||||
assert.ok(focus() > 0.25 && focus() < 1);
|
||||
assert.equal(apply(150, target).writes, 0, 'same timestamp stays inside deadband');
|
||||
assert.equal(apply(300, target).writes, 1);
|
||||
assert.equal(color.alpha, 0.25);
|
||||
assert.equal(focus(), 0.25);
|
||||
assert.equal(apply(300, null).writes, 0, 'release starts continuously from the floor');
|
||||
assert.equal(apply(600, null).writes, 1);
|
||||
assert.ok(color.alpha > 0.25 && color.alpha < 1);
|
||||
assert.ok(focus() > 0.25 && focus() < 1);
|
||||
assert.equal(apply(900, null).writes, 1);
|
||||
assert.equal(color.alpha, 1);
|
||||
assert.equal(focus(), 1);
|
||||
assert.equal(apply(901, null).writes, 0, 'settled restoration causes no churn');
|
||||
assert.equal(writes, 4);
|
||||
});
|
||||
|
||||
test('vessel focus wire performs no alpha writes when nothing has been tracked', () => {
|
||||
let writes = 0;
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 0, y: 0, z: 0 },
|
||||
show: true,
|
||||
get color() { return { alpha: 1 }; },
|
||||
set color(_next) { writes += 1; },
|
||||
});
|
||||
const { icons, records, focus } = focusFixture();
|
||||
const result = applyVesselFocusDeemphasis({
|
||||
records: [{ position: billboard.position, billboard }],
|
||||
records,
|
||||
icons,
|
||||
target: null,
|
||||
nowMs: 100,
|
||||
screenPositionFor: () => ({ x: 50, y: 50 }),
|
||||
@@ -733,17 +731,11 @@ test('vessel focus wire performs no alpha writes when nothing has been tracked',
|
||||
activeCount: 0,
|
||||
ran: false,
|
||||
});
|
||||
assert.equal(writes, 0);
|
||||
assert.equal(focus(), 1);
|
||||
});
|
||||
|
||||
test('vessel focus wire restores a hidden sprite before releasing the active pass', () => {
|
||||
const makeColor = (alpha) => ({ alpha, withAlpha: (next) => makeColor(next) });
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
color: makeColor(1),
|
||||
});
|
||||
const records = [{ billboard }];
|
||||
const { icons, records, record, focus } = focusFixture();
|
||||
const target = {
|
||||
screenRect: { left: 40, top: 40, right: 60, bottom: 60 },
|
||||
paddingPx: 0,
|
||||
@@ -759,6 +751,7 @@ test('vessel focus wire restores a hidden sprite before releasing the active pas
|
||||
};
|
||||
const pass = (nowMs, focusTarget, previousActiveCount) => applyVesselFocusDeemphasis({
|
||||
records,
|
||||
icons,
|
||||
target: focusTarget,
|
||||
previousActiveCount,
|
||||
nowMs,
|
||||
@@ -770,15 +763,15 @@ test('vessel focus wire restores a hidden sprite before releasing the active pas
|
||||
pass(0, target, 0);
|
||||
const dimmed = pass(params.attackMs, target, 0);
|
||||
assert.equal(dimmed.activeCount, 1);
|
||||
assert.equal(billboard.color.alpha, params.dimFloor);
|
||||
assert.equal(focus(), params.dimFloor);
|
||||
|
||||
setBillboard(billboard, 'show', false);
|
||||
record.visible = false;
|
||||
const releaseStart = pass(params.attackMs, null, dimmed.activeCount);
|
||||
const restored = pass(params.attackMs + params.releaseMs, null, releaseStart.activeCount);
|
||||
assert.equal(restored.ran, true);
|
||||
assert.equal(restored.activeCount, 0);
|
||||
assert.equal(restored.writes, 1);
|
||||
assert.equal(billboard.color.alpha, 1);
|
||||
assert.equal(focus(), 1);
|
||||
});
|
||||
|
||||
// --- Selection gestures (FB-1) ---------------------------------------------
|
||||
@@ -847,7 +840,6 @@ function makeRecord(overrides = {}) {
|
||||
lastPositionUtc: '',
|
||||
missedRefreshes: 0,
|
||||
position: POS,
|
||||
billboard: null,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -1056,18 +1048,9 @@ test('vessel interaction wire: CCTV-owned pick preserves vessel selection', () =
|
||||
});
|
||||
|
||||
test('vessel interaction wire: own-layer unkeyed record pick does not deselect', () => {
|
||||
const harness = installWireHarness({ id: makeRecord({ mmsi: undefined }) });
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(aisLiveVesselsLayer.getSelectedInfo()?.mmsi, harness.record.mmsi);
|
||||
assert.equal(harness.trail.clearCalls, 0);
|
||||
} finally {
|
||||
harness.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('vessel interaction wire: own-shaped evicted record pick does not deselect', () => {
|
||||
const harness = installWireHarness({ id: makeRecord({ mmsi: '999999999' }) });
|
||||
const icons = createIconSet();
|
||||
icons.add('ais-unkeyed:1', { id: 'ais-unkeyed:1' });
|
||||
const harness = installWireHarness({ id: 'ais-unkeyed:1' }, { icons });
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(aisLiveVesselsLayer.getSelectedInfo()?.mmsi, harness.record.mmsi);
|
||||
@@ -1350,11 +1333,9 @@ test('buildVesselCard: unnamed vessels title as MMSI; long names truncate', () =
|
||||
assert.ok(long.title.length <= 26, `title too long: ${long.title.length}`);
|
||||
});
|
||||
|
||||
test('buildVesselCard: anchors to the billboard position when present', () => {
|
||||
test('buildVesselCard: anchors to the drawn position', () => {
|
||||
const rendered = new Cesium.Cartesian3(9, 9, 9);
|
||||
const card = buildVesselCard(
|
||||
makeRecord({ billboard: mirrorBillboard({ position: rendered }) }),
|
||||
);
|
||||
const card = buildVesselCard(makeRecord({ position: rendered }));
|
||||
assert.deepEqual(card.position, rendered);
|
||||
});
|
||||
|
||||
@@ -1452,7 +1433,6 @@ test('vessel real layer lifecycle publishes protected selection and leaves no st
|
||||
viewer: { scene: { canvas: { clientWidth: 1600, clientHeight: 900 } } },
|
||||
records: [record],
|
||||
selectedRecord: record,
|
||||
billboardCollection: { show: true, remove() {} },
|
||||
});
|
||||
try {
|
||||
_updateVesselCardsForTest([]);
|
||||
@@ -1535,7 +1515,7 @@ test('EGM96 N pins the field finding: Rotterdam sea sits ~45 m ABOVE the ellipso
|
||||
// camera, whether the camera was free or tracking something else. The layer
|
||||
// only announces the click — the UI owns the flight (src/worldFocus.js).
|
||||
test('vessel interaction wire: selecting a vessel by click requests a camera transfer', () => {
|
||||
const harness = installWireHarness({ id: makeRecord() }, { selectedRecord: null });
|
||||
const harness = installWireHarness({ id: makeRecord().mmsi }, { selectedRecord: null });
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(
|
||||
WORLD_FOCUS_REQUEST_EVENT,
|
||||
@@ -1744,19 +1724,13 @@ 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) =>
|
||||
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) => ({
|
||||
position: billboard.position,
|
||||
billboard,
|
||||
}));
|
||||
const icons = createIconSet();
|
||||
const records = Array.from({ length: 51 }, (_, i) => {
|
||||
const iconId = String(i);
|
||||
icons.setSize(icons.add(iconId, { id: iconId }), 32, 32);
|
||||
return { iconId, position: { x: 1, y: 2, z: 3 }, visible: i === 0 };
|
||||
});
|
||||
const focus = (record) => icons.focus(icons.row(record.iconId));
|
||||
const target = {
|
||||
screenRect: { left: 40, top: 40, right: 60, bottom: 60 },
|
||||
paddingPx: 0,
|
||||
@@ -1767,6 +1741,7 @@ test('vessel focus wire skips hidden sprites at rest while a target is tracked',
|
||||
const apply = (nowMs) =>
|
||||
applyVesselFocusDeemphasis({
|
||||
records,
|
||||
icons,
|
||||
target,
|
||||
nowMs,
|
||||
screenPositionFor: () => {
|
||||
@@ -1786,7 +1761,7 @@ test('vessel focus wire skips hidden sprites at rest while a target is tracked',
|
||||
// Only the on-screen sprite pays for projection and distance.
|
||||
assert.equal(projected, 2);
|
||||
assert.equal(measured, 2);
|
||||
assert.equal(visible.color.alpha, 0.25);
|
||||
assert.equal(focus(records[0]), 0.25);
|
||||
assert.equal(result.activeCount, 1);
|
||||
for (const billboard of hidden) assert.equal(billboard.color.alpha, 1);
|
||||
for (const record of records.slice(1)) assert.equal(focus(record), 1);
|
||||
});
|
||||
@@ -274,7 +274,7 @@ test('a click on neither sprite nor card clears without moving the camera', () =
|
||||
const SIBLING_PICKS = [
|
||||
['flights', 'a1b2c3', { id: 'a1b2c3' }],
|
||||
['flights', 'a1b2c3', { primitive: { id: 'a1b2c3' } }],
|
||||
['ais-live-vessels', '353136000', { id: { mmsi: '353136000', name: 'EVER GIVEN' } }],
|
||||
['ais-live-vessels', '353136000', { id: '353136000' }],
|
||||
['cctv', 'atx-cam-3', { id: { id: 'atx-cam-3', name: 'entity-like' } }],
|
||||
['satellites', '25544', { id: 25544 }],
|
||||
];
|
||||
|
||||
@@ -5,6 +5,7 @@ import { applyCctvFocusDeemphasis } from './cctv.js';
|
||||
import { applySatellitePointFocusDeemphasis } from './satellites.js';
|
||||
import { DEFAULT_FOCUS_DEEMPHASIS_PARAMS } from './focusDeemphasis.js';
|
||||
import { mirrorBillboard } from './billboardMirror.js';
|
||||
import { createIconSet } from './iconSet.js';
|
||||
|
||||
const params = { ...DEFAULT_FOCUS_DEEMPHASIS_PARAMS, paddingPx: 0 };
|
||||
const target = {
|
||||
@@ -52,18 +53,14 @@ function assertResumeGate(name, makePass) {
|
||||
}
|
||||
|
||||
assertResumeGate('vessel', () => {
|
||||
const billboard = mirrorBillboard({
|
||||
position: { x: 1, y: 2, z: 3 },
|
||||
show: true,
|
||||
width: 32,
|
||||
height: 32,
|
||||
scale: 1,
|
||||
color: color(),
|
||||
});
|
||||
const icons = createIconSet();
|
||||
icons.setSize(icons.add('353136000', { id: '353136000' }), 32, 32);
|
||||
const record = { iconId: '353136000', position: { x: 1, y: 2, z: 3 }, visible: true };
|
||||
return {
|
||||
pass: ({ nowMs, target: focusTarget, previousActiveCount }) => (
|
||||
applyVesselFocusDeemphasis({
|
||||
records: [{ billboard }],
|
||||
records: [record],
|
||||
icons,
|
||||
target: focusTarget,
|
||||
previousActiveCount,
|
||||
nowMs,
|
||||
@@ -72,7 +69,7 @@ assertResumeGate('vessel', () => {
|
||||
params,
|
||||
})
|
||||
),
|
||||
readAlpha: () => billboard.color.alpha,
|
||||
readAlpha: () => icons.focus(icons.row('353136000')),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ const MAX_SIZE_PX = 4096;
|
||||
function createAtlas() {
|
||||
const slotOfKey = new Map();
|
||||
const entries = [];
|
||||
const listeners = new Set();
|
||||
const atlas = {
|
||||
/** Bumped whenever the canvas or a slot rectangle changes. */
|
||||
version: 0,
|
||||
@@ -57,6 +58,17 @@ function createAtlas() {
|
||||
ready(slot) {
|
||||
return atlas.rects[slot * 4 + 2] > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Call `listener` after every repack, so the renderer, drawing on demand,
|
||||
* can ask for the frame that shows a newly loaded image.
|
||||
* @param {() => void} listener
|
||||
* @returns {() => void} Stops listening.
|
||||
*/
|
||||
onChange(listener) {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
};
|
||||
|
||||
function load(entry) {
|
||||
@@ -120,6 +132,7 @@ function createAtlas() {
|
||||
atlas.rects[o + 3] = (entry.y + entry.sizePx) / size;
|
||||
}
|
||||
atlas.version++;
|
||||
for (const listener of listeners) listener();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -208,13 +208,19 @@ const EARTH_BOUNDS = new Cesium.BoundingSphere(
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {{ set: object, renderTime: () => Cesium.JulianDate }} options `renderTime`
|
||||
* gives the instant to draw at (the layer's delayed clock).
|
||||
* @param {{ set: object, renderTime: () => Cesium.JulianDate,
|
||||
* requestRender?: () => void }} options `renderTime` gives the instant to draw
|
||||
* at (the layer's delayed clock). `requestRender` asks for a frame when the
|
||||
* atlas packs a newly loaded image, for a layer that does not render
|
||||
* continuously.
|
||||
*/
|
||||
export class IconSetPrimitive {
|
||||
constructor({ set, renderTime }) {
|
||||
constructor({ set, renderTime, requestRender }) {
|
||||
this.set = set;
|
||||
this.renderTime = renderTime;
|
||||
this._stopAtlasListener = requestRender
|
||||
? iconAtlas.onChange(requestRender)
|
||||
: null;
|
||||
this.show = true;
|
||||
this._tau = 0;
|
||||
this._generation = -1;
|
||||
@@ -571,6 +577,7 @@ export class IconSetPrimitive {
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this._stopAtlasListener?.();
|
||||
this._destroyBuffers();
|
||||
this._programs?.opaque.destroy();
|
||||
this._programs?.translucent.destroy();
|
||||
|
||||
@@ -19,11 +19,10 @@ const _owners = new Map();
|
||||
/**
|
||||
* Resolves a scene.pick() result to a String pick id for the ownership scan.
|
||||
*
|
||||
* Layers use heterogeneous pick ids: flights/military/bikeshare/CCTV use
|
||||
* strings, satellites use numeric NORAD catalog ids, live AIS vessels attach
|
||||
* the vessel record OBJECT (identity = its `mmsi`), and entity picks surface
|
||||
* the Cesium Entity (identity = its string `id`). Everything is coerced to a
|
||||
* String so predicates match against one canonical form.
|
||||
* Layers use heterogeneous pick ids: flights/military/vessels/bikeshare/CCTV
|
||||
* use strings, satellites use numeric NORAD catalog ids, and entity picks
|
||||
* surface the Cesium Entity (identity = its string `id`). Everything is
|
||||
* coerced to a String so predicates match against one canonical form.
|
||||
*
|
||||
* @param {object|null|undefined} picked - Result of `scene.pick()`.
|
||||
* @returns {string|null} Canonical pick id, or null when the pick carries none.
|
||||
@@ -33,9 +32,7 @@ export function resolvePickId(picked) {
|
||||
const unwrap = (id) => {
|
||||
if (id === null || id === undefined) return undefined;
|
||||
if (typeof id === 'object') {
|
||||
// AIS vessel record (id object with .mmsi) or Cesium Entity (.id string)
|
||||
if (typeof id.mmsi === 'string' || typeof id.mmsi === 'number')
|
||||
return id.mmsi;
|
||||
// A Cesium Entity (.id string)
|
||||
if (typeof id.id === 'string' || typeof id.id === 'number') return id.id;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -33,12 +33,6 @@ test('resolvePickId: numeric pick id (satellite NORAD numbers) → String', () =
|
||||
assert.equal(resolvePickId({ id: undefined, primitive: { id: 43013 } }), '43013');
|
||||
});
|
||||
|
||||
test('resolvePickId: AIS vessel record object → its mmsi', () => {
|
||||
const record = { mmsi: '367123450', name: 'EVER GIVEN', billboard: {} };
|
||||
assert.equal(resolvePickId({ id: record }), '367123450');
|
||||
assert.equal(resolvePickId({ primitive: { id: record } }), '367123450');
|
||||
});
|
||||
|
||||
test('resolvePickId: Cesium-Entity-like object → its string id', () => {
|
||||
const entity = { id: 'cctv-atx-cam-3-center', properties: {} };
|
||||
assert.equal(resolvePickId({ id: entity }), 'cctv-atx-cam-3-center');
|
||||
@@ -48,7 +42,7 @@ test('resolvePickId: unresolvable picks → null', () => {
|
||||
assert.equal(resolvePickId(null), null);
|
||||
assert.equal(resolvePickId(undefined), null);
|
||||
assert.equal(resolvePickId({}), null);
|
||||
assert.equal(resolvePickId({ id: {} }), null); // object with no mmsi/id
|
||||
assert.equal(resolvePickId({ id: {} }), null); // object with no id
|
||||
assert.equal(resolvePickId({ primitive: {} }), null);
|
||||
});
|
||||
|
||||
@@ -67,8 +61,8 @@ test('ownership: sibling layers recognize each other via String-coerced ids', ()
|
||||
try {
|
||||
// Flights asking about a satellite pick (raw numeric id → String upstream)
|
||||
assert.equal(isOwnedByOtherLayer('flights', resolvePickId({ id: 25544 })), true);
|
||||
// Flights asking about a vessel pick (record object → mmsi)
|
||||
assert.equal(isOwnedByOtherLayer('flights', resolvePickId({ id: { mmsi: '367123450' } })), true);
|
||||
// Flights asking about a vessel pick (an icon row id: the mmsi)
|
||||
assert.equal(isOwnedByOtherLayer('flights', resolvePickId({ id: '367123450' })), true);
|
||||
// A layer never owns its own pick via the sibling scan
|
||||
assert.equal(isOwnedByOtherLayer('satellites', '25544'), false);
|
||||
// Unknown ids belong to nobody
|
||||
@@ -147,7 +141,7 @@ test('touch contact pick expands only a surface miss, bounded to 8 hits in 14 CS
|
||||
test('touch contact pick returns the first registered sibling, never a caller-specific preference', (t) => {
|
||||
primaryPointer(t, true);
|
||||
contactOwners(t);
|
||||
for (const first of [{ id: 'military' }, { id: { mmsi: '123456789' } }]) {
|
||||
for (const first of [{ id: 'military' }, { id: '123456789' }]) {
|
||||
const scene = {
|
||||
pick: () => mapTile,
|
||||
drillPick: () => [mapTile, first, { id: 'civil' }],
|
||||
|
||||
Reference in new issue
Block a user