mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Stop Navara's memory growth on engine switches, hide polygon zones reliably, and drop the Cesium camera rig
- Navara 0.2.1 never frees pick batch ids, and the mover banks rebuilt their instanced meshes on each attach, leaking about 260 KiB of WebAssembly memory per switch. A per-view pool hands released ids back out; the long soak now asserts native growth of at most 32 KiB per switch. - Navara 0.2.1 sometimes drops the first show:false update on a new vector layer, so a zone turned off right after a switch back stayed drawn. Polygon displays hide by deleting their layers and rebuild them when shown. - Camera verbs drive both engines through the globe contract; the Cesium viewer rig and the tests of states it can no longer reach are gone. - Flights and military tracking share src/layers/aircraft/tracking.js. - The geo import scenario reads movers only where the engine has them. - Add the Navara section to docs/CURRENT-STATE.md and a changelog fragment.
This commit is contained in:
1 parent
7abf74518f
commit
a6c64713ee
46 files changed
+2367
-2894
No files matched your search
@@ -0,0 +1,157 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { createTracking as createFlightsTracking } from '../flights/tracking.js';
|
||||
import { createTracking as createMilitaryTracking } from '../military/tracking.js';
|
||||
|
||||
// Both observed aircraft layers build their tracking from the shared aircraft
|
||||
// tracking; each must still reach it with its own identity and rules.
|
||||
const LAYERS = [
|
||||
{
|
||||
name: 'flights',
|
||||
createTracking: createFlightsTracking,
|
||||
layerId: 'flights',
|
||||
layerName: 'Live Flights',
|
||||
focusId: 'flights',
|
||||
floorsTrail: false,
|
||||
backfillLeadAltM: 10000,
|
||||
thinsBackfill: false,
|
||||
},
|
||||
{
|
||||
name: 'military',
|
||||
createTracking: createMilitaryTracking,
|
||||
layerId: 'military',
|
||||
layerName: 'Military Flights',
|
||||
focusId: 'militaryFlights',
|
||||
floorsTrail: true,
|
||||
backfillLeadAltM: 50,
|
||||
thinsBackfill: true,
|
||||
},
|
||||
];
|
||||
|
||||
const GROUND_M = 300;
|
||||
|
||||
function harness(layer, { groundM = null, track = [] } = {}) {
|
||||
const calls = { registered: [], focusCleared: [] };
|
||||
const flightState = {
|
||||
enabled: true,
|
||||
feed: {
|
||||
_lastSource: 'Fixture aircraft',
|
||||
_source: { getTrack: async () => ({ records: track }) },
|
||||
},
|
||||
records: { data: new Map(), missingPolls: new Map() },
|
||||
lifetime: new AbortController(),
|
||||
_billboards: new Map(),
|
||||
_trackedIcao: null,
|
||||
_trailPositions: [],
|
||||
_trailBackfillToken: 0,
|
||||
_renderer: {
|
||||
engine: {},
|
||||
follow: { onChanged: () => () => {} },
|
||||
},
|
||||
};
|
||||
const services = {
|
||||
context: {},
|
||||
aircraftPresentation: { tr3bTypeLabel: (id, type) => type },
|
||||
geoid: { ensureGeoidReady: async () => {}, geoidHeight: () => 0 },
|
||||
groundFloor: {
|
||||
resolveGroundFloorCellsBounded: async () => {},
|
||||
cachedGroundFloor: () => groundM,
|
||||
// The production floor rule: lift onto a known floor, else pass through.
|
||||
floorAltitudeM: (altM, floorM) => {
|
||||
const hasAlt = Number.isFinite(altM);
|
||||
const hasFloor = Number.isFinite(floorM);
|
||||
if (hasAlt && hasFloor) return Math.max(altM, floorM);
|
||||
if (hasAlt) return altM;
|
||||
if (hasFloor) return floorM;
|
||||
return null;
|
||||
},
|
||||
},
|
||||
focus: { clearFocusTarget: (id) => calls.focusCleared.push(id) },
|
||||
militaryRegistry: {},
|
||||
readout: {},
|
||||
selection: {
|
||||
selectionDispatcherFor: () => ({
|
||||
register: (id) => {
|
||||
calls.registered.push(id);
|
||||
return () => {};
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
const parts = {
|
||||
queries: {
|
||||
_describeFlight: () => ({ callsign: 'ABC1', track: 90 }),
|
||||
_contactLabel: () => 'ABC1',
|
||||
_toCleanText: (value) => value || '',
|
||||
_formatAltitude: () => '',
|
||||
},
|
||||
};
|
||||
const tracking = layer.createTracking({
|
||||
flightState,
|
||||
services,
|
||||
parts,
|
||||
layer: {},
|
||||
});
|
||||
return { tracking, flightState, calls };
|
||||
}
|
||||
|
||||
const heightOf = (position) => geo.cartographic.fromCartesian(position).height;
|
||||
|
||||
for (const layer of LAYERS) {
|
||||
test(`${layer.name} tracking publishes its own layer identity`, () => {
|
||||
const { tracking, calls } = harness(layer);
|
||||
const context = tracking._contextSubjectMetadata('abc123');
|
||||
assert.equal(context.layerId, layer.layerId);
|
||||
assert.equal(context.layerName, layer.layerName);
|
||||
// The route line is the civil layer's: military contexts carry none.
|
||||
assert.equal('route' in context.properties, layer.name === 'flights');
|
||||
tracking._installClickHandler();
|
||||
assert.deepEqual(calls.registered, [layer.layerId]);
|
||||
tracking._clearTracking();
|
||||
assert.deepEqual(calls.focusCleared, [layer.focusId]);
|
||||
});
|
||||
|
||||
test(`${layer.name} trail ${layer.floorsTrail ? 'lifts' : 'keeps'} a fix below the warm ground`, () => {
|
||||
const { tracking, flightState } = harness(layer, { groundM: GROUND_M });
|
||||
assert.equal('_trailFloorPosition' in tracking, layer.floorsTrail);
|
||||
tracking._appendTrailFix(geo.cartesian3.fromDegrees(-106.6, 35.05, 10));
|
||||
const height = heightOf(flightState._trailPositions[0]);
|
||||
assert.ok(
|
||||
Math.abs(height - (layer.floorsTrail ? GROUND_M : 10)) < 0.01,
|
||||
`trail height ${height}`,
|
||||
);
|
||||
});
|
||||
|
||||
test(`${layer.name} backfill places and thins history by its own rules`, async () => {
|
||||
const leading = harness(layer, {
|
||||
track: [{ observedAtMs: 1000, latitude: 35, longitude: -106 }],
|
||||
});
|
||||
leading.flightState._trackedIcao = 'abc123';
|
||||
await leading.tracking._backfillTrail('abc123', 0, Infinity);
|
||||
assert.equal(leading.flightState._trailPositions.length, 1);
|
||||
assert.ok(
|
||||
Math.abs(
|
||||
heightOf(leading.flightState._trailPositions[0]) -
|
||||
layer.backfillLeadAltM,
|
||||
) < 0.01,
|
||||
);
|
||||
|
||||
const long = harness(layer, {
|
||||
track: Array.from({ length: 1000 }, (_, index) => ({
|
||||
observedAtMs: 1000 + index * 1000,
|
||||
latitude: 35 + index * 0.001,
|
||||
longitude: -106,
|
||||
baroAltitudeM: 3000,
|
||||
})),
|
||||
});
|
||||
long.flightState._trackedIcao = 'abc123';
|
||||
await long.tracking._backfillTrail('abc123', 0, Infinity);
|
||||
// 1000 points into a 400-vertex trail: stride-thinned (every 3rd) or
|
||||
// only the newest 400 kept.
|
||||
assert.equal(
|
||||
long.flightState._trailPositions.length,
|
||||
layer.thinsBackfill ? 334 : 400,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user