Load the default renderer as the page starts, and follow through the camera port in tests

- The standalone page starts loading the default renderer as it starts
  (loadDefaultRenderer), so Cesium arrives beside the page's own setup,
  not after it; the scene takes a plugin or a promise of one.
- Where a follow target's layer has no display position yet, the followed
  position is the target's own position at the frame port's scene time.
- The globe engine's photoreal base that fails to come back is off again
  and the globe shown; a later switch tries again. The draped-imagery host
  asks the map engine whether the globe is shown where the renderer cannot
  say. The scene resizes the renderer with its container.
- Cockpit and voice tests follow through the camera port (followEntity),
  not by setting the viewer's tracked entity; the fake frame port has a
  scene time.
This commit is contained in:
Sameh Khamis committed 2026-11-10 17:44:29 -08:00
1 parent 6daf63d90c
commit ae4fbb5053
21 files changed
+328 -87

No files matched your search

+17 -11
View File
@@ -11,7 +11,11 @@ import { useCockpitStore } from './stores/cockpit.js';
import CockpitView from './views/CockpitView.vue';
import ContextView from './views/ContextView.vue';
import * as Cesium from 'cesium';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import {
bindFakeCesiumCamera,
followEntity,
followedEntity,
} from '../testSupport/fakeCameraPort.mjs';
import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
import { vesselCockpitInfo } from '../layers/vessels/cockpitSubject.js';
import { VesselRecords } from '../layers/vessels/records.js';
@@ -109,7 +113,10 @@ function sceneQuery(viewer, ports) {
return Number.isFinite(height) ? height : null;
},
sampleHeight(points, { mostDetailed = false } = {}) {
if (!mostDetailed || typeof scene().sampleHeightMostDetailed !== 'function')
if (
!mostDetailed ||
typeof scene().sampleHeightMostDetailed !== 'function'
)
return Promise.resolve(points.map(() => null));
// Answered as soon as the scene's read lands, as the adapter does.
return scene()
@@ -156,7 +163,6 @@ function fixture(
// Each placed camera: where it is and where it looks.
const shots = [];
const viewer = {
trackedEntity: undefined,
clock: { currentTime: null },
camera: {
cancelFlight() {},
@@ -415,10 +421,10 @@ test('tracking an aircraft from the bridge ends it without refocusing the vessel
const { cockpit, viewer, vessels, aircraft } = fixture(t);
cockpit.enter();
await settle();
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
cockpit.update();
assert.equal(cockpit.active, false);
assert.equal(viewer.trackedEntity, aircraft, 'the aircraft keeps tracking');
assert.equal(followedEntity(viewer), aircraft, 'the aircraft keeps tracking');
assert.equal(aircraft.show, true, 'the aircraft was never adopted');
assert.deepEqual(vessels.calls, [
['subject', RECORD.mmsi],
@@ -432,7 +438,7 @@ test('following a satellite or a site from the bridge ends it too', async (t) =>
await settle();
// A satellite's or an installation's follow carrier has no position of
// its own (the camera reads the follow target's).
viewer.trackedEntity = { id: 'satellites:25544', noradId: 25544 };
followEntity(viewer, { id: 'satellites:25544', noradId: 25544 });
cockpit.update();
assert.equal(cockpit.active, false);
assert.deepEqual(vessels.calls.at(-1), ['subject', null]);
@@ -473,7 +479,7 @@ test("turning off the ridden aircraft's layer ends the cockpit", async (t) => {
const { cockpit, viewer, aircraft, disableFlights } = fixture(t, {
aircraftInfo,
});
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
assert.equal(cockpit.enter({ kind: 'aircraft' }), true);
await settle();
cockpit.update();
@@ -876,7 +882,7 @@ test('arrows do nothing new in an aircraft cockpit', async (t) => {
const { cockpit, viewer, aircraft, shots, store } = fixture(t, {
aircraftInfo,
});
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
assert.equal(cockpit.enter({ kind: 'aircraft' }), true);
await settle();
assert.equal(cockpit.subjectKind, 'aircraft');
@@ -926,7 +932,7 @@ test('C neither enters nor leaves an aircraft cockpit', async (t) => {
onGround: false,
};
const { cockpit, viewer, aircraft } = fixture(t, { aircraftInfo });
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
const outside = press(cockpit, 'c');
await settle();
assert.equal(cockpit.active, false, 'C does not enter');
@@ -1562,7 +1568,7 @@ test('a followed aircraft keeps its own double-click hit area', async (t) => {
onGround: false,
};
const { cockpit, viewer, aircraft } = fixture(t, { aircraftInfo });
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
heightSensitiveProjection(viewer);
// Drawn at (400, -2700) as the press begins, at (600, -2700) by the
// double-click: a click there is not on the aircraft.
@@ -1588,7 +1594,7 @@ test("a ship's double-click memory does not carry over to an aircraft followed s
// The press finds the ship at (400, 300).
cockpit.onScenePointerDown(1000);
// Within the memory, an aircraft is followed, drawn elsewhere.
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
heightSensitiveProjection(viewer, { x: 900 });
assert.equal(cockpit.onSceneDoubleClick({ x: 400, y: 300 }, 1250), false);
assert.equal(cockpit.active, false);
+18 -11
View File
@@ -4,6 +4,7 @@ import { CockpitViewController } from './cockpitController.js';
import { withEntityRecord } from '../data/entityRecords.js';
import { fakeInput } from '../input/testDoubles.mjs';
import { bindRenderer } from '../render/rendererOf.js';
import { entityFollowTarget, followedOf } from '../data/followed.js';
import {
cockpitAnchorCorrectionStep,
cockpitGroundSafeHeight,
@@ -37,18 +38,30 @@ function environment() {
preUpdate: event,
screenSpaceCameraController: { enableInputs: true },
},
trackedEntityChanged: event,
entities: { contains: () => false },
};
// What the camera follows, as a layer's follow sets it.
const camera = {
followed: null,
follow(target) {
camera.followed = target;
},
on: (name, fn) =>
name === 'followChanged' ? event.addEventListener(fn) : () => {},
};
// The renderer's frame port: Cockpit moves the camera on its preUpdate.
bindRenderer(viewer, {
camera,
frame: {
on: (phase, fn) =>
phase === 'preUpdate' ? event.addEventListener(fn) : () => {},
},
});
/** Follow a holder of an entity record, as a layer's follow does. */
const follow = (holder) =>
camera.follow(holder ? entityFollowTarget(holder, {}) : null);
return {
viewer,
follow,
callbacks,
restore() {
Object.assign(globalThis, original);
@@ -96,7 +109,7 @@ test('disposing an active Cockpit releases the supplied render owner without ret
env.viewer.scene.screenSpaceCameraController.enableInputs,
true,
);
assert.equal(env.viewer.trackedEntity, undefined);
assert.equal(followedOf(env.viewer), null);
assert.equal(owner.active, false);
} finally {
env.restore();
@@ -122,15 +135,9 @@ test('aircraft identity is read from the supplied layer instances', () => {
militaryFlightsLayer: { getTrackedInfo: () => military },
},
});
env.viewer.trackedEntity = withEntityRecord(
{},
{ trackedId: 'military:def456' },
);
env.follow(withEntityRecord({}, { trackedId: 'military:def456' }));
assert.deepEqual(owner.readAircraftInfo(), military);
env.viewer.trackedEntity = withEntityRecord(
{},
{ trackedId: 'flights:abc123' },
);
env.follow(withEntityRecord({}, { trackedId: 'flights:abc123' }));
assert.deepEqual(owner.readAircraftInfo(), civilian);
owner.dispose();
} finally {
+14 -5
View File
@@ -11,6 +11,7 @@ import {
FAKE_EVENT_TYPES,
} from '../input/testDoubles.mjs';
import { bindRenderer } from '../render/rendererOf.js';
import { entityFollowTarget } from '../data/followed.js';
import { createCesiumInput } from '../render/cesium/input.js';
import { routeSceneDoubleClick, onSceneDoubleClick } from './cockpitInput.js';
import { inputFor } from '../input/dispatcher.js';
@@ -27,13 +28,21 @@ function harness(t, { stock = null } = {}) {
const project = () => ({ x: 100, y: 100 });
// With `stock`, the renderer's own input port takes the viewer's stock
// double-click follow and runs it as the app's does; else the fake input.
const input = stock ? cesiumInput(viewer, stock, project) : fakeInput(viewer);
if (!stock) bindRenderer(viewer, { query: { project } });
// The camera port follows the aircraft, as the flights layer's follow does.
const camera = { followed: null, on: () => () => {} };
const input = stock
? cesiumInput(viewer, stock, project, camera)
: fakeInput(viewer);
if (!stock) bindRenderer(viewer, { query: { project }, camera });
const entity = {
id: 'flights:abc',
position: { getValue: () => ({ x: 1, y: 2, z: 3 }) },
};
viewer.trackedEntity = entity;
camera.followed = entityFollowTarget(entity, {
position: () => entity.position.getValue(),
frame: 'enu',
viewFrom: { x: 0, y: -1000, z: 500 },
});
const controller = {
viewer,
active: false,
@@ -69,7 +78,7 @@ function harness(t, { stock = null } = {}) {
/** The Cesium renderer's input port over a fake handler, with `follow` as
* the viewer's stock double-click follow. */
function cesiumInput(viewer, follow, project) {
function cesiumInput(viewer, follow, project, camera) {
const stock = new FakeScreenSpaceEventHandler();
stock.setInputAction(follow, FAKE_EVENT_TYPES.LEFT_DOUBLE_CLICK);
viewer.screenSpaceEventHandler = stock;
@@ -87,7 +96,7 @@ function cesiumInput(viewer, follow, project) {
},
document: null,
});
bindRenderer(viewer, { input: made.port, query });
bindRenderer(viewer, { input: made.port, query, camera });
const T = FAKE_EVENT_TYPES;
const fire = (type) => (position) => handler.fire(type, { position });
return {
+8 -4
View File
@@ -10,7 +10,10 @@ import { createPinia } from 'pinia';
import { createApp, defineComponent, h, nextTick } from 'vue';
import { DataLayerManager } from '../data/manager.js';
import { withEntityRecord } from '../data/entityRecords.js';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import {
bindFakeCesiumCamera,
followEntity,
} from '../testSupport/fakeCameraPort.mjs';
import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
import { createDependencies } from '../layers/awareness/dependencies.js';
import { CockpitCoordinator } from './cockpitCoordinator.js';
@@ -90,7 +93,6 @@ function fixture(
entities.add(entity);
const listeners = () => ({ addEventListener: () => () => {} });
const viewer = {
trackedEntity: tracked ? entity : undefined,
clock: { currentTime: null },
camera: { cancelFlight() {}, frustum: { fov: 1, aspectRatio: 1 } },
entities: { contains: (candidate) => entities.has(candidate) },
@@ -102,6 +104,7 @@ function fixture(
};
// The Cockpit reads frames, the camera and what it follows through ports.
bindFakeCesiumCamera(viewer, fakeScenePorts(viewer));
if (tracked) followEntity(viewer, entity);
const context = { mode: contextMode, changing };
const coordinator = new CockpitCoordinator({
viewer,
@@ -175,8 +178,9 @@ function fixture(
/** Track another aircraft, as Contacts navigation does mid-session. */
const retrack = (subject) => {
tracked = subject;
viewer.trackedEntity = entityFor(subject);
entities.add(viewer.trackedEntity);
const next = entityFor(subject);
entities.add(next);
followEntity(viewer, next);
};
const $ = (selector) => document.querySelector(selector);
return { $, coordinator, cockpit, store, layers, disable, retrack, pinia };
+9 -8
View File
@@ -12,7 +12,11 @@ import assert from 'node:assert/strict';
import { createPinia } from 'pinia';
import { createApp, defineComponent, h, nextTick } from 'vue';
import * as Cesium from 'cesium';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import {
bindFakeCesiumCamera,
followEntity,
followedEntity,
} from '../testSupport/fakeCameraPort.mjs';
import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
import {
FAKE_EVENT_TYPES,
@@ -210,7 +214,7 @@ function satellitesLayer(viewer) {
if (!positions.has(id)) return false;
layer.calls.push(['track', id]);
layer.tracked = id;
viewer.trackedEntity = { position: { getValue: () => layer.position(id) } };
followEntity(viewer, { position: { getValue: () => layer.position(id) } });
return true;
},
setCockpitSubject(noradId) {
@@ -243,7 +247,6 @@ function fixture(t, { reducedMotion = false } = {}) {
const shots = [];
const picks = new Map();
const viewer = {
trackedEntity: undefined,
clock: { currentTime: null },
camera: {
frustum: { fov: 1, aspectRatio: ASPECT },
@@ -273,9 +276,7 @@ function fixture(t, { reducedMotion = false } = {}) {
handler.stockDouble = ({ position }) => {
handler.stockDoubleClicks += 1;
const picked = picks.get(`${position.x},${position.y}`);
viewer.trackedEntity = picked
? { position: { getValue: () => null } }
: undefined;
followEntity(viewer, picked ? { position: { getValue: () => null } } : null);
};
// The viewer's stock handler holds them, so the scene's input has them to
// hold off.
@@ -639,7 +640,7 @@ test('a double-click on a site focuses it and keeps the orbital view', async (t)
const { cockpit, viewer, handler } = scene;
scene.doubleClick(SITES.alpha.at);
assert.equal(handler.stockDoubleClicks, 0, 'Cesium does not track the site');
assert.equal(viewer.trackedEntity, undefined);
assert.equal(followedEntity(viewer), undefined);
scene.frame();
assert.equal(cockpit.active, true, 'still in orbit');
assert.equal(cockpit.orbital.focus.key, SITES.alpha.id);
@@ -725,7 +726,7 @@ test('a satellite row rides it, staying in orbit; RETURN goes back', async (t) =
assert.equal(newTrack.length, 1);
assert.ok(newTrack[0].timestamp > firstTrack.timestamp, 'the new ride’s own time');
assert.deepEqual(satellites.calls.slice(-2), [['track', 49260], ['subject', 49260]]);
assert.equal(viewer.trackedEntity, undefined, 'the Cockpit keeps the camera');
assert.equal(followedEntity(viewer), undefined, 'the Cockpit keeps the camera');
assert.equal(cockpit.subjectId, 49260);
assert.equal(cockpit.orbital.focus, null, 'the focus is reset');
assert.equal(modeEvents.at(-1)?.active, true);
+12 -9
View File
@@ -24,7 +24,11 @@ import {
} from '../cockpitOrbital.js';
import { vesselCockpitInfo } from '../layers/vessels/cockpitSubject.js';
import { claimPointer, releasePointer } from '../data/inputOwnership.js';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import {
bindFakeCesiumCamera,
followEntity,
followedEntity,
} from '../testSupport/fakeCameraPort.mjs';
import { fakeScenePorts } from '../testSupport/fakeCesiumScene.mjs';
import { fakeInput } from '../input/testDoubles.mjs';
@@ -97,7 +101,7 @@ function stockEventHandler(viewer) {
};
actions.set(DOUBLE_CLICK, () => {
handler.stockCalls += 1;
viewer.trackedEntity = undefined;
followEntity(viewer, null);
});
return handler;
}
@@ -141,7 +145,6 @@ function fixture(
gevTrackedId: aircraftInfo ? `flights:${aircraftInfo.icao24}` : '',
};
const viewer = {
trackedEntity: undefined,
clock: { currentTime: null },
camera: {
// Cesium's frustum: `fov` the wider angle, `fovy` the vertical one.
@@ -409,7 +412,7 @@ test('entering takes the camera and shows only the orbital HUD', async (t) => {
assert.equal(cockpit.subjectKind, 'satellite');
assert.equal(cockpit.subjectId, ISS.noradId);
assert.deepEqual(satellites.calls, [['subject', ISS.noradId]]);
assert.equal(viewer.trackedEntity, undefined);
assert.equal(followedEntity(viewer), undefined);
assert.equal(viewer.scene.screenSpaceCameraController.enableInputs, false);
assert.ok(document.body.classList.contains('cockpit-mode'));
assert.ok(document.body.classList.contains('cockpit-orbit'));
@@ -759,11 +762,11 @@ test('losing the satellite ends the view without refocusing it', async (t) => {
test('tracking an aircraft from orbit ends the view and keeps that tracking', async (t) => {
const { cockpit, viewer, satellites, aircraft, clock } = await orbitAt(t);
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
clock.advance(16);
cockpit.update();
assert.equal(cockpit.active, false);
assert.equal(viewer.trackedEntity, aircraft);
assert.equal(followedEntity(viewer), aircraft);
assert.ok(!satellites.calls.some(([call]) => call === 'refocus'));
});
@@ -785,7 +788,7 @@ test('+ and − mean nothing new in an aircraft cockpit or on a bridge', async (
onGround: false,
};
const air = fixture(t, { satellite: null, aircraftInfo });
air.viewer.trackedEntity = air.aircraft;
followEntity(air.viewer, air.aircraft);
assert.equal(air.cockpit.enter({ kind: 'aircraft' }), true);
for (const key of ['+', '=', '-', '_'])
assert.equal(press(air.cockpit, key).defaultPrevented, false, key);
@@ -934,7 +937,7 @@ test('a double-click on the followed aircraft model enters instead of untracking
};
const scene = fixture(t, { aircraftInfo });
const { viewer, aircraft, store } = scene;
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
// The model is a primitive, not an Entity: Cesium's own double-click
// would untrack it.
doubleClickNearSatellite(scene, 0);
@@ -1058,7 +1061,7 @@ test('a tracked aircraft takes entry before a tracked satellite', async (t) => {
onGround: false,
};
const { cockpit, viewer, aircraft, store } = fixture(t, { aircraftInfo });
viewer.trackedEntity = aircraft;
followEntity(viewer, aircraft);
cockpit.syncEntry();
assert.equal(store.presence.entryKind, 'aircraft');
});
+5 -2
View File
@@ -10,7 +10,10 @@ import { CockpitViewController } from './cockpitController.js';
import { useCockpitStore } from './stores/cockpit.js';
import CockpitView from './views/CockpitView.vue';
import ContextView from './views/ContextView.vue';
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
import {
bindFakeCesiumCamera,
followEntity,
} from '../testSupport/fakeCameraPort.mjs';
const INFO = Object.freeze({
icao24: 'abc123',
@@ -43,7 +46,6 @@ function fixture(t) {
const listeners = () => ({ addEventListener: () => () => {} });
const entity = { position: {}, show: true };
const viewer = {
trackedEntity: entity,
camera: { cancelFlight() {} },
entities: { contains: (candidate) => candidate === entity },
scene: {
@@ -53,6 +55,7 @@ function fixture(t) {
trackedEntityChanged: listeners(),
};
bindFakeCesiumCamera(viewer, { frame: { on: () => () => {} } });
followEntity(viewer, entity);
const cockpit = new CockpitViewController(viewer, {
services: {
flightsLayer: { getTrackedInfo: () => INFO, refreshTr3b() {} },