Move the flights and military layers onto the renderer ports

The flights and military layers now reach the renderer only through its
ports: motion, queries, state, tracking, enrichment, evidence and policy
read the camera pose, project through the query port, request and
suspend frames through the frame port, and key per-frame caches on the
frames drawn rather than the scene's frame number. Policy is plain data,
the enrichment view test is pose-based, and the tracked aircraft is an
icon in a draw-port set with a plain holder standing in for the entity
that Cockpit, the tracked card and share links read.

The mesh floor sampler can sample through the query port, excluding
named draw sets, and both layers use it that way. A pick of another
layer's tracked icon is never taken for one of a layer's own contacts.

Twelve layer files leave the Cesium allow-list.
This commit is contained in:
Sameh Khamis committed 2026-11-07 18:49:23 -08:00
1 parent 00a0a0dbc7
commit 23d56f8393
40 files changed
+1638 -908

No files matched your search

+190
View File
@@ -0,0 +1,190 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { bindFakeDraw } from '../testSupport/fakeDrawPort.mjs';
import {
createTrackedAircraftIcon,
isOtherTrackedIconSet,
trackedContactHolder,
} from './trackedAircraftIcon.js';
/** A viewer double with a fake draw port and a frame port whose preRender the test runs. */
function harness() {
const viewer = {};
const listeners = new Set();
const requests = [];
const frame = {
requestRender(reason) {
requests.push(reason);
},
on(phase, cb) {
assert.equal(phase, 'preRender');
listeners.add(cb);
return () => listeners.delete(cb);
},
};
const { draw } = bindFakeDraw(viewer, { frame });
const tick = () => {
for (const cb of [...listeners]) cb({});
};
return { viewer, draw, listeners, tick, requests };
}
const SPRITE = Object.freeze({
width: 28,
height: 28,
scale: 1.2,
scaleByDistance: { near: 1000, nearValue: 3, far: 8e6, farValue: 0.5 },
});
test('the tracked billboard is one icon re-posed each frame, and only when it changed', () => {
const { viewer, draw, listeners, tick, requests } = harness();
const icon = createTrackedAircraftIcon({
viewer: () => viewer,
setPrefix: 'flights',
});
assert.equal(icon.setId, null, 'no set before anything is shown');
let pos = { x: 1, y: 2, z: 3 };
let rotation = 0.5;
let color = [0, 1, 1, 1];
icon.show({
id: 'abc123',
image: 'data:image/svg+xml;base64,AAA',
sprite: SPRITE,
position: () => pos,
rotation: () => rotation,
color: () => color,
});
const set = draw.find('flights-tracked-icon:');
assert.ok(set, 'an icon set on the draw port');
assert.equal(set.kind, 'icons');
assert.equal(icon.setId, set.spec.id);
assert.equal(listeners.size, 1, 'drawn before each frame');
assert.equal(set.items.size, 0, 'nothing is drawn between frames');
assert.equal(requests.length, 1, 'a frame is asked for');
tick();
const item = set.items.get('abc123');
assert.deepEqual(item.pos, { x: 1, y: 2, z: 3 });
assert.notEqual(item.pos, pos, 'the position is copied');
assert.deepEqual(item.size, [28, 28]);
assert.equal(item.scale, 1.2);
assert.equal(item.scaleByDistance, SPRITE.scaleByDistance);
assert.equal(item.rotationMode, 'screen');
assert.equal(item.rotation, 0.5);
assert.deepEqual(item.color, [0, 1, 1, 1]);
assert.equal(item.disableDepthTest, Number.POSITIVE_INFINITY);
assert.equal(item.show, true);
const writes = set.writes;
color = [0, 1, 1, 1];
tick();
assert.equal(
set.writes,
writes,
'a frame that changes nothing writes nothing',
);
pos = { x: 4, y: 5, z: 6 };
rotation = 1;
color = [0, 1, 1, 0];
tick();
assert.equal(set.writes, writes + 1);
assert.deepEqual(set.items.get('abc123').pos, { x: 4, y: 5, z: 6 });
assert.equal(set.items.get('abc123').rotation, 1);
assert.deepEqual(set.items.get('abc123').color, [0, 1, 1, 0]);
icon.setImage('data:image/svg+xml;base64,BBB');
assert.equal(set.items.get('abc123').image, 'data:image/svg+xml;base64,AAA');
tick();
assert.equal(set.items.get('abc123').image, 'data:image/svg+xml;base64,BBB');
const holder = trackedContactHolder('flights:abc123', icon, () => pos);
assert.equal(holder.show, true);
assert.deepEqual(holder.position.getValue(), { x: 4, y: 5, z: 6 });
holder.show = false;
tick();
assert.equal(holder.show, false);
assert.equal(set.items.get('abc123').show, false, 'hidden while kept');
holder.show = true;
tick();
assert.equal(set.items.get('abc123').show, true);
pos = null;
tick();
assert.equal(set.items.get('abc123').show, false, 'no position hides it');
icon.hide();
assert.equal(set.items.size, 0);
assert.equal(listeners.size, 0, 'no frame work while hidden');
icon.setImage('ignored');
assert.equal(set.items.size, 0);
icon.dispose();
assert.equal(draw.sets.get(set.spec.id).disposed, true);
});
test('each layer lifetime gets its own set id, and showing again replaces the contact', () => {
const { viewer, draw, tick } = harness();
const a = createTrackedAircraftIcon({
viewer: () => viewer,
setPrefix: 'military',
});
const b = createTrackedAircraftIcon({
viewer: () => viewer,
setPrefix: 'military',
});
const target = (id) => ({
id,
image: 'img',
sprite: SPRITE,
position: () => ({ x: 1, y: 1, z: 1 }),
rotation: () => 0,
color: () => [1, 1, 1, 1],
});
a.show(target('one'));
b.show(target('two'));
tick();
assert.notEqual(a.setId, b.setId);
a.show(target('three'));
tick();
assert.deepEqual([...draw.set(a.setId).items.keys()], ['three']);
});
test('without a draw port nothing is drawn and nothing throws', () => {
const icon = createTrackedAircraftIcon({
viewer: () => null,
setPrefix: 'flights',
});
icon.show({
id: 'x',
image: 'img',
sprite: SPRITE,
position: () => ({ x: 0, y: 0, z: 1 }),
rotation: () => 0,
color: () => [1, 1, 1, 1],
});
icon.setVisible(false);
icon.hide();
icon.dispose();
assert.equal(icon.setId, null);
});
test("a layer tells another layer's tracked icon set from its own sets", () => {
assert.equal(
isOtherTrackedIconSet('flights-tracked-icon:3', 'military'),
true,
);
assert.equal(
isOtherTrackedIconSet('military-tracked-icon:1', 'flights'),
true,
);
assert.equal(
isOtherTrackedIconSet('military-tracked-icon:1', 'military'),
false,
);
assert.equal(isOtherTrackedIconSet('flights-icons:2', 'military'), false);
assert.equal(
isOtherTrackedIconSet('flights-tracked-model:2', 'military'),
false,
);
assert.equal(isOtherTrackedIconSet(undefined, 'military'), false);
});