mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Let a host application place live contacts
createApplicationCatalog takes an optional placement provider. Its layer(kind) hands Flights, Military Flights, AIS Vessels, Transit and Rail a place(id, wallMs), and optionally observe(id, fix) and forget(id). While live, each layer tells it every fix it accepts and draws a contact where it places it: position, height (the layer's own when none is given), course and speed. A null answer, a provider that throws, a kind it leaves out, or no provider at all keeps the layer's own motion unchanged, and following the world clock the layers never ask it. A transit vehicle or train it holds still lets the render loop idle and is asked again each second; vessels ask for frames only while it places one, and stop when the layer turns off. Tests show the layers draw and reconcile exactly as before without a provider and with one that places nothing, draw where a provider places them, and idle while it holds them still.
This commit is contained in:
1 parent
e53cfef1d1
commit
6f830a2e70
46 files changed
+1417
-34
No files matched your search
@@ -2,6 +2,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createVesselLayer } from './index.js';
|
||||
import { VISIBILITY_UPDATE_MS } from './policy.js';
|
||||
import { layerPlacement } from '../../data/placementProvider.js';
|
||||
|
||||
// Vessels move only when a poll lands, so the layer must let the scene idle:
|
||||
// it asks for frames for forced passes and one trailing frame after the camera
|
||||
@@ -9,7 +10,7 @@ import { VISIBILITY_UPDATE_MS } from './policy.js';
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
function setup() {
|
||||
function setup({ placement = null } = {}) {
|
||||
let clock = 10_000;
|
||||
const requests = [];
|
||||
const holds = new Set();
|
||||
@@ -46,6 +47,7 @@ function setup() {
|
||||
releaseContinuousRender: (id) => holds.delete(id),
|
||||
governorRequestRender: (reason) => requests.push(reason),
|
||||
},
|
||||
...(placement ? { placement: layerPlacement(placement, 'vessels') } : {}),
|
||||
},
|
||||
});
|
||||
const camera = {
|
||||
@@ -136,3 +138,61 @@ test('destroy cancels a pending trailing frame', (t) => {
|
||||
advance(VISIBILITY_UPDATE_MS);
|
||||
assert.deepEqual(requests, []);
|
||||
});
|
||||
|
||||
test('a placement that places nothing asks for no frames; one that places a drawn vessel moves it in place', (t) => {
|
||||
let mono = 0;
|
||||
t.mock.method(performance, 'now', () => mono);
|
||||
const originalDocument = globalThis.document;
|
||||
globalThis.document = { getElementById: () => null };
|
||||
t.after(() => {
|
||||
if (originalDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = originalDocument;
|
||||
});
|
||||
let spot = null;
|
||||
const { layer, camera, requests, timers, advance } = setup({
|
||||
placement: { layer: () => ({ place: () => spot }) },
|
||||
});
|
||||
const record = {
|
||||
mmsi: '111',
|
||||
lat: 51.93,
|
||||
lon: 4.05,
|
||||
billboard: { show: true, position: null },
|
||||
};
|
||||
layer.testing._setVesselStateForTest({
|
||||
viewer: { camera, scene: {} },
|
||||
records: [record],
|
||||
});
|
||||
const visual = layer.testing._prepareVesselVisualForTest(record);
|
||||
const position = visual.position;
|
||||
const before = { ...position };
|
||||
|
||||
// Nothing placed: no frame is asked for, and the vessel stays put.
|
||||
for (let i = 0; i < 8; i += 1) {
|
||||
mono += 250;
|
||||
layer.testing._runPlacementPassForTest();
|
||||
advance(250);
|
||||
}
|
||||
assert.equal(timers.size, 0);
|
||||
assert.deepEqual(requests, []);
|
||||
assert.deepEqual({ ...visual.position }, before);
|
||||
|
||||
// Placed: moved in place, no new positions, and a frame asked for.
|
||||
spot = { lat: 51.94, lon: 4.05 };
|
||||
mono += 250;
|
||||
layer.testing._runPlacementPassForTest();
|
||||
assert.equal(visual.position, position, 'written in place');
|
||||
assert.notDeepEqual({ ...visual.position }, before);
|
||||
assert.equal(record.billboard.position, position);
|
||||
assert.equal(timers.size, 1);
|
||||
advance(1_000);
|
||||
assert.deepEqual(requests, ['ais-vessels-placement']);
|
||||
|
||||
// Turning the layer off drops the pending frame.
|
||||
mono += 250;
|
||||
layer.testing._runPlacementPassForTest();
|
||||
assert.equal(timers.size, 1);
|
||||
layer.destroy();
|
||||
assert.equal(timers.size, 0);
|
||||
advance(1_000);
|
||||
assert.deepEqual(requests, ['ais-vessels-placement']);
|
||||
});
|
||||
Reference in new issue
Block a user