mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Task 11a. The military flights logic no longer imports Cesium: it draws
through the shared aircraft renderer (src/layers/aircraft/render/cesium.js)
with the military's parameters in src/layers/military/render/cesium.js
(sprite-order slot 'military', jet.glb's 180° nose offset), registered for
'cesium' in the renderer registry and created at init(viewer, {engine}).
The same pure move as flights in 10a:
- Fleet: the BillboardCollection and its sprite-order slot (enable keeps
restoreSpriteOrder, as before); sprites stay Billboard handles.
- Models: fleet/tracked/preload glTF loads (asynchronous:false, MIX tint at
MODEL_COLOR_BLEND_AMOUNT, IR boost as `unlit` → the UNLIT CustomShader),
the model collection, setPose. The per-class specs keep their own nose
offset: setPose takes an optional offsetDeg (default the layer's), on
both aircraft renderers (same arithmetic, test added).
- Tracked: the ENU billboard Entity with its position/colour/rotation
callbacks (#FFD166, transparent amber once the model owns the visual),
viewFrom, followed through viewer.trackedEntity + the one exact tracked
frame; refocusTrackedById through follow.refocus.
- Trail: the entity trail and the floored live head segment.
- View: camera/scene reads, frame number, frustum and horizon tests,
render requests, frame events.
- Clicks and Escape go through the engine's selection dispatcher (the
ScreenSpaceEventHandler and keydown listener are gone); the cross-layer
untrack watches the renderer's follow. Same rules: cockpit clicks are
inert, the tracked visual/model is a no-op, another layer's pick is not
empty space, an unowned pick is.
- Colours are engine-neutral Rgba (MIL_ICON_COLOR #FFB800,
TRACKED_ICON_COLOR #FFD166, AMBER_TRANSPARENT), NearFarScalar →
nearFarScale; Cesium math → src/geo.
- check-import-directions: src/layers/military/ joins the rendered layers
(cesium only in render/cesium*.js).
- The military registry and the flights' duplicate suppression are
untouched.
Source-text tests updated with the moved code, same meaning:
- militaryAwareness.test: military's hasContact guard reads fleet.visible().
- trackingClickGesture.test: the military gesture rules are the
dispatcher's (selection gesture before select, click classifier before
the empty-space clear), military answers the empty click with a
user-origin clear — the same assertion flights already had.
- ownership.test: the services fixture names selection and renderer; the
app-composed services build the layer's Cesium renderer.
- renderers.test: flights and military have extracted Cesium renderers.
New tests: the military logic over a plain-data renderer and a fake engine
(amber fleet, click-select, #FFD166 tracked glyph, no-op on the tracked
visual, empty-click and Escape release, the keyboard left on destroy); the
plain-data renderer moved to src/testSupport for both aircraft layers;
setPose with a per-model offset.
W1 replay vs 7c7422e2 (the 10a reference run): every layer's counts, known
objects, screen points, tracking pose after 2 s, requests and the
city/global/orbit shots (sha256) identical. qa-military-names (it checks
the installations layer): the same verdict as 7c7422e2 (the zoom-markers
assertion fails on both). Main chunk 2,890,763 B (−2.9 KB).
220 lines
7.7 KiB
JavaScript
220 lines
7.7 KiB
JavaScript
// The flights logic draws only through its renderer (phase 3 Task 10a): with
|
|
// a renderer that is plain data (no Cesium), the layer builds its fleet,
|
|
// selects a contact on a click through the engine's selection dispatcher,
|
|
// tracks and follows it, and releases it on an empty click. This is the seam
|
|
// the Navara renderer (Task 10b) plugs into.
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import * as geo from '../../geo/index.js';
|
|
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
|
|
import { createApplicationFlights } from '../../app/layers/flights.js';
|
|
import { defaultSurface } from '../../data/surfaceServices.js';
|
|
import * as militaryRegistry from '../../data/militaryRegistry.js';
|
|
import { openSkySnapshot } from '../../sources/live/aircraft.js';
|
|
import { missingAircraftRendererMembers } from '../aircraft/render/contract.js';
|
|
import { Rgba } from '../shared/color.js';
|
|
import { recordingAircraftRenderer as recordingRenderer } from '../../testSupport/aircraftRecordingRenderer.mjs';
|
|
|
|
globalThis.window ||= {};
|
|
globalThis.window.dispatchEvent ||= () => true;
|
|
globalThis.window.addEventListener ||= () => {};
|
|
globalThis.window.removeEventListener ||= () => {};
|
|
globalThis.CustomEvent ||= class CustomEvent extends Event {
|
|
constructor(type, init) {
|
|
super(type);
|
|
this.detail = init?.detail;
|
|
}
|
|
};
|
|
globalThis.document ||= {
|
|
body: { classList: { contains: () => false } },
|
|
addEventListener() {},
|
|
removeEventListener() {},
|
|
};
|
|
|
|
function snapshotOf(ids) {
|
|
const nowSec = Math.floor(Date.now() / 1000);
|
|
return openSkySnapshot({
|
|
time: nowSec,
|
|
states: ids.map((id, index) => [
|
|
id,
|
|
`TST${index} `,
|
|
'United States',
|
|
nowSec,
|
|
nowSec,
|
|
-97.6 + index * 0.1,
|
|
30.3,
|
|
10_668,
|
|
false,
|
|
250,
|
|
95,
|
|
5,
|
|
null,
|
|
10_700,
|
|
null,
|
|
null,
|
|
null,
|
|
5,
|
|
]),
|
|
});
|
|
}
|
|
|
|
test('the flights logic draws, selects and follows only through its renderer', async () => {
|
|
const engine = createFakeEngine();
|
|
let renderer = null;
|
|
const layer = createApplicationFlights({
|
|
surface: defaultSurface,
|
|
source: {
|
|
label: 'Fixture aircraft',
|
|
getSnapshot: async () => snapshotOf(['abc123', 'def456']),
|
|
},
|
|
militaryRegistry,
|
|
renderer: {
|
|
create: ({ viewer, engine: given }) => {
|
|
assert.equal(viewer, null, 'no viewer on an engine without one');
|
|
renderer = recordingRenderer(given);
|
|
return renderer;
|
|
},
|
|
},
|
|
});
|
|
layer.init(null, { engine });
|
|
assert.deepEqual(missingAircraftRendererMembers(renderer), []);
|
|
layer.enable();
|
|
try {
|
|
await layer.update(null);
|
|
assert.equal(renderer.sprites.size, 2, 'one sprite per contact');
|
|
const [sprite] = renderer.sprites;
|
|
assert.ok(sprite.color instanceof Rgba, 'colours are engine-neutral');
|
|
assert.equal(sprite.id, 'abc123');
|
|
assert.equal(layer.getAllPositions().length, 2);
|
|
|
|
// A click on a contact: the engine's pick, through the dispatcher.
|
|
engine.fake.script('pick', () => ({ id: 'def456' }));
|
|
engine.fake.script('drillPick', () => [{ id: 'def456' }]);
|
|
const click = () => {
|
|
engine.fake.input('down', { position: { x: 10, y: 10 } });
|
|
engine.fake.input('up', { position: { x: 10, y: 10 } });
|
|
engine.fake.input('click', { position: { x: 10, y: 10 } });
|
|
};
|
|
click();
|
|
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
|
|
assert.deepEqual(
|
|
renderer.calls.filter(
|
|
([name]) => name.startsWith('tracked') || name.startsWith('follow'),
|
|
),
|
|
[
|
|
['tracked.create', 'tracked-1'],
|
|
['follow.start', 'tracked-1'],
|
|
],
|
|
);
|
|
|
|
// Clicking the tracked visual itself is a no-op.
|
|
engine.fake.script('pick', () => ({ id: 'tracked-1' }));
|
|
engine.fake.script('drillPick', () => [{ id: 'tracked-1' }]);
|
|
click();
|
|
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
|
|
|
|
// Empty space releases the follow and removes the tracked visual.
|
|
engine.fake.script('pick', () => undefined);
|
|
engine.fake.script('drillPick', () => []);
|
|
click();
|
|
assert.equal(layer.getTrackedInfo(), null);
|
|
assert.ok(
|
|
renderer.calls.some(([name]) => name === 'follow.release') &&
|
|
renderer.calls.some(
|
|
([name, id]) => name === 'tracked.remove' && id === 'tracked-1',
|
|
),
|
|
);
|
|
} finally {
|
|
layer.disable();
|
|
layer.destroy(null);
|
|
}
|
|
assert.ok(renderer.calls.some(([name]) => name === 'destroy'));
|
|
});
|
|
|
|
test('the flights logic draws and follows on the Navara renderer (fake engine)', async () => {
|
|
const { createAircraftNavaraRenderer, aircraftAtlasLayout } =
|
|
await import('../aircraft/render/navara.js');
|
|
const layout = aircraftAtlasLayout();
|
|
const engine = createFakeEngine();
|
|
let renderer = null;
|
|
const layer = createApplicationFlights({
|
|
surface: defaultSurface,
|
|
source: {
|
|
label: 'Fixture aircraft',
|
|
getSnapshot: async () => snapshotOf(['abc123', 'def456']),
|
|
},
|
|
militaryRegistry,
|
|
renderer: {
|
|
create: ({ engine: given }) =>
|
|
(renderer = createAircraftNavaraRenderer({
|
|
engine: given,
|
|
layerId: 'flights',
|
|
order: 8,
|
|
headingOffsetDeg: 180,
|
|
drawAtlas: async () => ({
|
|
canvas: { width: layout.width, height: layout.height },
|
|
cells: layout.cells,
|
|
}),
|
|
})),
|
|
},
|
|
});
|
|
layer.init(null, { engine });
|
|
layer.enable();
|
|
try {
|
|
await renderer.whenReady();
|
|
await layer.update(null);
|
|
await Promise.resolve();
|
|
const sprites = engine.movers
|
|
.list()
|
|
.filter(({ id }) => id.startsWith('flights-sprites'));
|
|
assert.equal(sprites.length, 1);
|
|
assert.equal(sprites[0].count, 2);
|
|
const { store } = engine.fake.moverSet(sprites[0].id);
|
|
assert.deepEqual([...store.pickIds.slice(0, 2)].sort(), [
|
|
'abc123',
|
|
'def456',
|
|
]);
|
|
// What it draws, as the QA probe reads it (the same on every engine).
|
|
const drawn = layer.qaDrawn();
|
|
assert.deepEqual(drawn.map((row) => row.id).sort(), ['abc123', 'def456']);
|
|
assert.ok(drawn.every((row) => row.show && row.image.startsWith('data:')));
|
|
// A click on a contact selects it; the engine follows with its label.
|
|
engine.fake.script('pick', () => ({ id: 'def456' }));
|
|
engine.fake.script('drillPick', () => [{ id: 'def456' }]);
|
|
engine.fake.input('down', { position: { x: 10, y: 10 } });
|
|
engine.fake.input('up', { position: { x: 10, y: 10 } });
|
|
engine.fake.input('click', { position: { x: 10, y: 10 } });
|
|
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
|
|
const following = engine.camera.following();
|
|
assert.equal(following?.label?.id, 'flights:def456');
|
|
engine.fake.frame();
|
|
const tracked = engine.movers
|
|
.list()
|
|
.find(({ id }) => id.startsWith('flights-tracked'));
|
|
assert.equal(tracked.count, 1);
|
|
assert.equal(layer.getAllPositions().length, 2);
|
|
// A camera command ends the engine's follow; the contact stays selected
|
|
// (as on Cesium after a search flight), and tracking it again follows.
|
|
engine.camera.setView({
|
|
destination: geo.cartesian3.fromDegrees(-97.7, 30.2, 50_000),
|
|
});
|
|
assert.equal(engine.camera.following(), null);
|
|
assert.equal(layer.getTrackedInfo()?.icao24, 'def456');
|
|
assert.equal(layer.trackById('def456', { origin: 'voice' }), true);
|
|
assert.equal(engine.camera.following()?.label?.id, 'flights:def456');
|
|
assert.equal(layer.stopTracking(), true);
|
|
assert.equal(engine.camera.following(), null);
|
|
assert.equal(
|
|
engine.movers.list().find(({ id }) => id.startsWith('flights-tracked'))
|
|
.count,
|
|
0,
|
|
);
|
|
} finally {
|
|
layer.disable();
|
|
layer.destroy(null);
|
|
}
|
|
assert.equal(engine.movers.list().length, 0, 'no mover set left behind');
|
|
engine.destroy();
|
|
});
|