Files
gods-eye-view/src/data/cameraArrival.test.mjs
T
German Khokhlov 16e63f4c50 refactor(camera): use the globe engine
The startup fly-in, orbit, world-target focus, the arrival ground guard,
arrival ownership, camera sensitivity claims, landmark/viewport/globe
flights and place search (with its view bias and near-view recovery) take
the globe engine. Callers that still hold a viewer (voice, layers until
phase 1c) reach the same engine through engineFromViewer, and arrival
ownership is keyed by the engine whichever one a caller names.

The ground guard yields on camera.commanded instead of patching the
viewer camera itself; on Cesium that event hooks the same command methods
and tracking changes, so direct Cesium callers still end it. Landmark
framing reads the frustum fov from the pose's fovy and aspectRatio.

Tests that built viewer doubles now run on the fake engine (or on the
Cesium engine over the same double), with the same expectations.
2026-10-15 19:47:43 +04:00

40 lines
1.4 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
import { registerViewerEngine } from '../globe/cesium/engineFromViewer.js';
import { cancelCameraArrival, ownCameraArrival } from './cameraArrival.js';
test('an arrival owned on the engine yields to a cancel through its viewer', () => {
const engine = createFakeEngine();
const viewer = {};
const unregister = registerViewerEngine(viewer, engine);
const cancelled = [];
// A correction releases its ownership when it stops, as the ground guard does.
const own = (key, name) => {
let release = () => {};
release = ownCameraArrival(key, () => {
cancelled.push(name);
release();
});
};
own(engine, 'engine-owned');
cancelCameraArrival(viewer);
own(viewer, 'viewer-owned');
cancelCameraArrival(engine);
assert.deepEqual(cancelled, ['engine-owned', 'viewer-owned']);
unregister();
});
test('a newer arrival replaces the older one and release is idempotent', () => {
const engine = createFakeEngine();
const seen = [];
const releaseOld = ownCameraArrival(engine, () => seen.push('old'));
ownCameraArrival(engine, () => seen.push('new'));
assert.deepEqual(seen, ['old']);
releaseOld();
cancelCameraArrival(engine);
assert.deepEqual(seen, ['old', 'new']);
cancelCameraArrival(null);
assert.deepEqual(seen, ['old', 'new']);
});