mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
The layers that still had one Cesium and one Navara implementation, or
drew on Cesium only, now draw through engine.movers, engine.lines and
engine.camera on both engines, and application code holds the engine
instead of guessing it from a viewer.
- Aircraft family: flights, military and local ADS-B share one display
(src/layers/aircraft/render/display.js). The Cesium and Navara
renderers are gone. Where they differed, the display follows Cesium:
- attach and visibility tracking, live disableDepthTestDistance
changes, the tracked glyph's distance scale, model ids that change,
local ADS-B markers hidden until shown and its UAT ring as a point;
- the trail head's hidden alpha is 0.45, the contract's
depthFailAlpha scaled by the head's 0.9.
The tracked glyph stays over the fleet, as on Navara. The movers
contract reports readiness per model and reads model axes as the
glTF's own on every engine. Cesium's follow takes any native target
through a proxy entity in the ENU frame and mirrors its readout fields.
- Wildlife Sightings draws badges and the density glow as sprite sets
and its privacy cells as line outlines (no fill yet). It takes clicks
from engine.input and its card anchors to the engine's canvas and
camera, so the layer is in both engines' catalogs again and a switch
keeps the session's layer set.
- Cockpit: cockpitHost takes the engine only. The ridden aircraft is the
engine follow's target, hidden through its sprite; only the Cesium
Viewer's stock double-click is still routed around.
- About forty camera, navigation, share-link, HUD, voice, detection and
layer-lifecycle callers take the engine. isGlobeEngine and
engineFromViewer calls outside src/globe fall from 51 to 14.
The coupling baseline drops accordingly: layer renderer lines from
5239/12331 to 4546/11106 (Cesium/Navara), `viewer` lines from 2424 to
2209, Cesium-importing files from 69 to 66.
152 lines
5.1 KiB
JavaScript
152 lines
5.1 KiB
JavaScript
import test from 'node:test';
|
|
import { readFileSync } from 'node:fs';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
CESIUM_BUILTIN,
|
|
CESIUM_LAYER_RENDERERS,
|
|
rendererFor,
|
|
createLayerAvailability,
|
|
createRendererRegistry,
|
|
layerAvailableOn,
|
|
} from './renderers.js';
|
|
import { APPLICATION_LAYER_DIRECTORY } from './directory.js';
|
|
import { createFakeEngine } from '../../globe/testing/fakeEngine.js';
|
|
|
|
test('a registry knows which engine renders which layer', () => {
|
|
const registry = createRendererRegistry();
|
|
const made = [];
|
|
registry.register('navara', {
|
|
flights: (engine, options) => {
|
|
made.push([engine.kind, options]);
|
|
return { destroy() {} };
|
|
},
|
|
});
|
|
registry.register('cesium', {
|
|
flights: CESIUM_BUILTIN,
|
|
satellites: CESIUM_BUILTIN,
|
|
});
|
|
assert.equal(registry.layerAvailableOn('flights', 'navara'), true);
|
|
assert.equal(registry.layerAvailableOn('satellites', 'navara'), false);
|
|
assert.equal(registry.layerAvailableOn('satellites', 'cesium'), true);
|
|
assert.equal(registry.layerAvailableOn('flights', 'other'), false);
|
|
const renderer = registry.rendererFor(
|
|
'flights',
|
|
{ kind: 'navara' },
|
|
{ tint: 1 },
|
|
);
|
|
assert.ok(renderer);
|
|
assert.deepEqual(made, [['navara', { tint: 1 }]]);
|
|
// A Cesium layer that still renders itself has no separate renderer.
|
|
assert.equal(registry.rendererFor('flights', { kind: 'cesium' }), null);
|
|
assert.equal(registry.rendererFor('satellites', { kind: 'navara' }), null);
|
|
assert.deepEqual(registry.availableIds('cesium').sort(), [
|
|
'flights',
|
|
'satellites',
|
|
]);
|
|
assert.throws(() => registry.register('navara', { x: 42 }), TypeError);
|
|
assert.throws(
|
|
() => registry.register('navara', { flights: () => ({}) }),
|
|
/already/,
|
|
'one renderer per layer and engine',
|
|
);
|
|
});
|
|
|
|
test('the default registry: every layer on Cesium, none yet on Navara', () => {
|
|
for (const { id } of APPLICATION_LAYER_DIRECTORY) {
|
|
assert.equal(layerAvailableOn(id, 'cesium'), true, id);
|
|
assert.equal(layerAvailableOn(id, 'navara'), false, id);
|
|
}
|
|
});
|
|
|
|
test('the aircraft, vessels, satellites, launches and earthquakes have extracted Cesium renderers', () => {
|
|
assert.deepEqual(Object.keys(CESIUM_LAYER_RENDERERS), [
|
|
'earthquakes',
|
|
'air-quality',
|
|
'gnss-integrity',
|
|
'fire-perimeters',
|
|
'drone-airspace',
|
|
'osm-places',
|
|
'local-firms',
|
|
'rocket-launches',
|
|
'satellites',
|
|
'flights',
|
|
'military',
|
|
'local-adsb',
|
|
'ais-live-vessels',
|
|
]);
|
|
const vessels = rendererFor(
|
|
'ais-live-vessels',
|
|
{ kind: 'cesium' },
|
|
{
|
|
viewer: { scene: {}, camera: {} },
|
|
},
|
|
);
|
|
assert.equal(vessels.kind, 'cesium');
|
|
assert.equal(rendererFor('satellites', { kind: 'cesium' }).kind, 'cesium');
|
|
});
|
|
|
|
test('the aircraft family draws through one display, the same factory on every engine', async () => {
|
|
const displays = {
|
|
flights: ['flights', 'createFlightsDisplay'],
|
|
military: ['military', 'createMilitaryDisplay'],
|
|
'local-adsb': ['localAdsb', 'createLocalAdsbDisplay'],
|
|
};
|
|
// The Navara mode registers the same modules' factories.
|
|
const navaraMode = readFileSync(
|
|
new URL('../navaraMode.js', import.meta.url),
|
|
'utf8',
|
|
);
|
|
const drawAtlas = async () => ({ canvas: {}, cells: {} });
|
|
for (const [id, [directory, name]] of Object.entries(displays)) {
|
|
const factory = (
|
|
await import(`../../layers/${directory}/render/display.js`)
|
|
)[name];
|
|
assert.equal(CESIUM_LAYER_RENDERERS[id], factory, id);
|
|
assert.match(
|
|
navaraMode,
|
|
new RegExp(
|
|
`'?${id}'?: async \\(\\) =>\\s*\\(await import\\('[^']+/render/display\\.js'\\)\\)\\s*\\.${name}\\b`,
|
|
),
|
|
id,
|
|
);
|
|
for (const kind of ['cesium', 'navara']) {
|
|
const engine = createFakeEngine({ kind });
|
|
const display = factory(engine, { drawAtlas });
|
|
assert.equal(display.engine, engine, `${id} on ${kind}`);
|
|
display.destroy();
|
|
engine.destroy();
|
|
}
|
|
}
|
|
});
|
|
|
|
test('the layer availability API: engine, isAvailable, available, unavailable', () => {
|
|
const registry = createRendererRegistry();
|
|
registry.register('navara', { flights: () => ({}) });
|
|
const directory = [
|
|
{ id: 'flights', name: 'Live Flights' },
|
|
{ id: 'satellites', name: 'Satellites' },
|
|
];
|
|
const availability = createLayerAvailability('navara', {
|
|
registry,
|
|
directory,
|
|
});
|
|
assert.equal(availability.engine, 'navara');
|
|
assert.equal(availability.isAvailable('flights'), true);
|
|
assert.equal(availability.isAvailable('satellites'), false);
|
|
assert.equal(availability.isAvailable('unknown'), false);
|
|
assert.deepEqual(availability.available(), [
|
|
{ id: 'flights', name: 'Live Flights' },
|
|
]);
|
|
assert.deepEqual(availability.unavailable(), [
|
|
{ id: 'satellites', name: 'Satellites' },
|
|
]);
|
|
// Fresh copies: a caller cannot change the answer.
|
|
availability.unavailable().push({ id: 'x', name: 'x' });
|
|
assert.equal(availability.unavailable().length, 1);
|
|
assert.ok(Object.isFrozen(availability));
|
|
const cesium = createLayerAvailability('cesium');
|
|
assert.equal(cesium.unavailable().length, 0);
|
|
assert.equal(cesium.available().length, APPLICATION_LAYER_DIRECTORY.length);
|
|
assert.throws(() => createLayerAvailability('vulkan'), TypeError);
|
|
});
|