mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Fly the remaining flights through the camera port, on any viewer
The embed view, the celestial-ring focus, the ground-guard lift, the Bhote Koshi approach and orbit, launch selection and replay flights, and the cockpit's view and takeover now drive the renderer's camera port. The contract gains a sineInOut easing, pinned by a conformance trace. A viewer with no renderer bound, such as one a caller of a public export brings, now gets a camera port too, as it already got an input port: cameraOf builds one over the viewer's own Cesium camera and keeps it for the viewer's life, until a renderer is bound. The Cesium adapter provides the factory as it loads; code that reaches Cesium takes cameraOf from the adapter so the factory comes with it, and findCamera answers null where a missing camera is not an error (HUD, share link, world focus, Recent Imagery's ZOOM IN). A test walks every package export and fails one that can reach the bridge without loading the factory. A destroyed viewer gets no camera and lets go of a built one, and the application renderer stays bound until its viewer is destroyed.
This commit is contained in:
1 parent
c5b716b107
commit
1d4e4ebe90
44 files changed
+1167
-344
No files matched your search
@@ -3,6 +3,7 @@
|
||||
// Arrival framing is computed before the destination's tiles exist, so it
|
||||
// works from a predicted ground height. The guard measures the real surface
|
||||
// after arrival and lifts the eye; these tests pin when it acts.
|
||||
import { bindFakeCesiumCamera } from './testSupport/fakeCameraPort.mjs';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
@@ -49,8 +50,12 @@ test('the clearance frames a subject without turning into an overflight', () =>
|
||||
|
||||
function fakeViewer({ cameraHeightM, surfaceM }) {
|
||||
const flights = [];
|
||||
const position = Cesium.Cartographic.fromDegrees(-97.7603, 30.3141, cameraHeightM);
|
||||
return {
|
||||
const position = Cesium.Cartographic.fromDegrees(
|
||||
-97.7603,
|
||||
30.3141,
|
||||
cameraHeightM,
|
||||
);
|
||||
return bindFakeCesiumCamera({
|
||||
flights,
|
||||
scene: {
|
||||
canvas: null,
|
||||
@@ -71,7 +76,7 @@ function fakeViewer({ cameraHeightM, surfaceM }) {
|
||||
this._currentFlight = {};
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
test('the guard lifts a buried arrival once the surface answers', async () => {
|
||||
@@ -111,7 +116,11 @@ test('the guard waits for streaming tiles and yields to a newer arrival', async
|
||||
|
||||
test('the guard leaves a clear view untouched', async () => {
|
||||
const viewer = fakeViewer({ cameraHeightM: 400, surfaceM: 171 });
|
||||
guardCameraAboveGround(viewer, { lat: 30.3125, lon: -97.765 }, { intervalMs: 1 });
|
||||
guardCameraAboveGround(
|
||||
viewer,
|
||||
{ lat: 30.3125, lon: -97.765 },
|
||||
{ intervalMs: 1 },
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
assert.equal(viewer.flights.length, 0);
|
||||
});
|
||||
@@ -142,27 +151,58 @@ function handoffFixture(t) {
|
||||
const originalFly = viewer.camera.flyTo;
|
||||
const navigation = new NavigationController({
|
||||
viewer,
|
||||
tracking: Object.fromEntries(['flightsLayer', 'militaryFlightsLayer',
|
||||
'satellitesLayer', 'aisLiveVesselsLayer', 'militaryAwarenessLayer',
|
||||
'rocketLaunchesLayer'].map((key) => [key, {}])),
|
||||
cancelOrientation() {}, clearLocation() {}, cancelShareSelection() {},
|
||||
getDataManager() {}, interruptCameraMotion() {}, stopOrbit() {},
|
||||
isCockpitActive: () => false, showToast() {},
|
||||
tracking: Object.fromEntries(
|
||||
[
|
||||
'flightsLayer',
|
||||
'militaryFlightsLayer',
|
||||
'satellitesLayer',
|
||||
'aisLiveVesselsLayer',
|
||||
'militaryAwarenessLayer',
|
||||
'rocketLaunchesLayer',
|
||||
].map((key) => [key, {}]),
|
||||
),
|
||||
cancelOrientation() {},
|
||||
clearLocation() {},
|
||||
cancelShareSelection() {},
|
||||
getDataManager() {},
|
||||
interruptCameraMotion() {},
|
||||
stopOrbit() {},
|
||||
isCockpitActive: () => false,
|
||||
showToast() {},
|
||||
});
|
||||
guardCameraAboveGround(viewer, { lat: 30.3, lon: -97.7 });
|
||||
return { viewer, navigation, originalFly };
|
||||
}
|
||||
|
||||
for (const handoff of ['Director', 'tracking', 'follow', 'keyboard', 'UI',
|
||||
'flyTo', 'flyToBoundingSphere', 'setView', 'layer-disable', 'layer-destroy', 'app-stop']) {
|
||||
for (const handoff of [
|
||||
'Director',
|
||||
'tracking',
|
||||
'follow',
|
||||
'keyboard',
|
||||
'UI',
|
||||
'flyTo',
|
||||
'flyToBoundingSphere',
|
||||
'setView',
|
||||
'layer-disable',
|
||||
'layer-destroy',
|
||||
'app-stop',
|
||||
]) {
|
||||
test(`arrival guard relinquishes and removes hooks on ${handoff}`, async (t) => {
|
||||
const { viewer, navigation, originalFly } = handoffFixture(t);
|
||||
const methods = ['flyTo', 'flyToBoundingSphere', 'setView', 'lookAt', 'cancelFlight']
|
||||
.map((name) => viewer.camera[name]);
|
||||
const methods = [
|
||||
'flyTo',
|
||||
'flyToBoundingSphere',
|
||||
'setView',
|
||||
'lookAt',
|
||||
'cancelFlight',
|
||||
].map((name) => viewer.camera[name]);
|
||||
if (handoff === 'Director') {
|
||||
SceneDirector.prototype._claimCameraOwnership.call({
|
||||
viewer, styleManager: { runImmediateNavigation: (noun, fn) =>
|
||||
navigation._runExplicitNavigation(noun, fn) },
|
||||
viewer,
|
||||
styleManager: {
|
||||
runImmediateNavigation: (noun, fn) =>
|
||||
navigation._runExplicitNavigation(noun, fn),
|
||||
},
|
||||
});
|
||||
} else if (handoff === 'tracking') {
|
||||
viewer.trackedEntityChanged.raiseEvent({ id: 'contact' });
|
||||
@@ -173,19 +213,31 @@ for (const handoff of ['Director', 'tracking', 'follow', 'keyboard', 'UI',
|
||||
} else if (handoff === 'app-stop') navigation.stop();
|
||||
else if (handoff.startsWith('layer-')) {
|
||||
const lifecycle = new LayerLifecycle(viewer);
|
||||
lifecycle.register({ id: 'test', init() {}, enable() {}, disable() {}, destroy() {} });
|
||||
lifecycle.register({
|
||||
id: 'test',
|
||||
init() {},
|
||||
enable() {},
|
||||
disable() {},
|
||||
destroy() {},
|
||||
});
|
||||
await lifecycle.setEnabled('test', true);
|
||||
if (handoff === 'layer-disable') await lifecycle.setEnabled('test', false);
|
||||
if (handoff === 'layer-disable')
|
||||
await lifecycle.setEnabled('test', false);
|
||||
else await lifecycle.destroyLayer('test');
|
||||
} else viewer.camera[handoff]({});
|
||||
// A direct flyTo is itself one recorded flight; the guard adds none.
|
||||
const priorFlights = viewer.flights.length;
|
||||
t.mock.timers.tick(10000);
|
||||
assert.equal(viewer.flights.length, priorFlights, 'the old probe cannot fly');
|
||||
assert.equal(
|
||||
viewer.flights.length,
|
||||
priorFlights,
|
||||
'the old probe cannot fly',
|
||||
);
|
||||
assert.equal(viewer.camera.flyTo, originalFly);
|
||||
assert.deepEqual(
|
||||
['flyTo', 'flyToBoundingSphere', 'setView', 'lookAt', 'cancelFlight']
|
||||
.map((name) => viewer.camera[name]),
|
||||
['flyTo', 'flyToBoundingSphere', 'setView', 'lookAt', 'cancelFlight'].map(
|
||||
(name) => viewer.camera[name],
|
||||
),
|
||||
methods,
|
||||
'the guard never replaces camera methods',
|
||||
);
|
||||
@@ -196,7 +248,11 @@ for (const handoff of ['Director', 'tracking', 'follow', 'keyboard', 'UI',
|
||||
|
||||
test('the guard yields to a camera moved without any camera method', async () => {
|
||||
const viewer = fakeViewer({ cameraHeightM: 172, surfaceM: 171 });
|
||||
guardCameraAboveGround(viewer, { lat: 30.3125, lon: -97.765 }, { intervalMs: 5 });
|
||||
guardCameraAboveGround(
|
||||
viewer,
|
||||
{ lat: 30.3125, lon: -97.765 },
|
||||
{ intervalMs: 5 },
|
||||
);
|
||||
// A cockpit or follow frame writes the pose directly.
|
||||
viewer.camera.directionWC = new Cesium.Cartesian3(1, 0, 0);
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
@@ -205,20 +261,30 @@ test('the guard yields to a camera moved without any camera method', async () =>
|
||||
|
||||
test('Cesium lifting a buried eye straight up is not another owner', async () => {
|
||||
const viewer = fakeViewer({ cameraHeightM: 104, surfaceM: 171 });
|
||||
guardCameraAboveGround(viewer, { lat: 30.3125, lon: -97.765 }, { intervalMs: 5 });
|
||||
guardCameraAboveGround(
|
||||
viewer,
|
||||
{ lat: 30.3125, lon: -97.765 },
|
||||
{ intervalMs: 5 },
|
||||
);
|
||||
// Terrain collision raises the eye to just above the loaded ground.
|
||||
const raised = Cesium.Cartographic.fromDegrees(-97.7603, 30.3141, 172);
|
||||
viewer.camera.positionCartographic = raised;
|
||||
viewer.camera.positionWC = Cesium.Cartographic.toCartesian(raised);
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
assert.equal(viewer.flights.length, 1, 'the guard still lifts the eye');
|
||||
const lifted = Cesium.Cartographic.fromCartesian(viewer.flights[0].destination);
|
||||
const lifted = Cesium.Cartographic.fromCartesian(
|
||||
viewer.flights[0].destination,
|
||||
);
|
||||
assert.ok(Math.abs(lifted.height - (171 + MIN_EYE_CLEARANCE_M)) < 0.5);
|
||||
});
|
||||
|
||||
test('another owner lowering the eye is not corrected', async () => {
|
||||
const viewer = fakeViewer({ cameraHeightM: 172, surfaceM: 171 });
|
||||
guardCameraAboveGround(viewer, { lat: 30.3125, lon: -97.765 }, { intervalMs: 5 });
|
||||
guardCameraAboveGround(
|
||||
viewer,
|
||||
{ lat: 30.3125, lon: -97.765 },
|
||||
{ intervalMs: 5 },
|
||||
);
|
||||
const lowered = Cesium.Cartographic.fromDegrees(-97.7603, 30.3141, 150);
|
||||
viewer.camera.positionCartographic = lowered;
|
||||
viewer.camera.positionWC = Cesium.Cartographic.toCartesian(lowered);
|
||||
|
||||
Reference in new issue
Block a user