mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Replace Cesium monkey-patches with hooks and keep internals in one module
The arrival ground guard replaced camera.flyTo, flyToBoundingSphere,
setView, lookAt and cancelFlight with wrappers so a direct caller would stop
it. It now remembers the pose it started on and, before each retry, yields
if a flight is under way or the camera has moved across the ground, down or
around. A straight rise is not a move: Cesium's terrain collision lifts a
buried eye that way as tiles load, which is the case the guard exists for.
This also catches owners the wrappers missed (a pose written directly,
lookAtTransform), and no camera method is replaced.
Recent imagery and weather overwrote provider.requestImage (weather also
provider.credit) to ration tiles. They now state that policy as a hook with
withTileRequestHook(provider, { requestImage, credit }) from
src/render/cesium/tileRequests.js, which hands Cesium a provider delegating
to the original and leaves the original untouched.
Every private Cesium field the app reaches goes through a named helper in
src/render/cesium/internals.js: the main and offscreen pick views and their
command extents, a billboard's collection, a cluster's point collection,
the widget's render-loop latch, the WebGL context and the current camera
flight. internals.test.mjs fails when the installed Cesium stops declaring
one of them, and a source scan fails on private access anywhere else. The
cyber sonar's primitives.update wrap stays until the effects work.
Live (Austin, keyless globe): a buried eye is lifted to 253 m over a 133 m
surface; a setView or flyTo by another caller makes the guard yield; radar
loads its tiles through the hook. Documented in docs/APPLICATION.md and
docs/CURRENT-STATE.md.
This commit is contained in:
1 parent
9bdeffeca3
commit
18d6e3292d
18 files changed
+597
-125
No files matched your search
@@ -59,10 +59,17 @@ function fakeViewer({ cameraHeightM, surfaceM }) {
|
||||
},
|
||||
camera: {
|
||||
positionCartographic: position,
|
||||
positionWC: Cesium.Cartographic.toCartesian(position),
|
||||
directionWC: new Cesium.Cartesian3(0, 0, -1),
|
||||
upWC: new Cesium.Cartesian3(0, 1, 0),
|
||||
heading: 0.5,
|
||||
pitch: -0.55,
|
||||
roll: 0,
|
||||
flyTo: (options) => flights.push(options),
|
||||
// As Cesium does: a flight is under way until it completes.
|
||||
flyTo(options) {
|
||||
flights.push(options);
|
||||
this._currentFlight = {};
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -122,8 +129,16 @@ function handoffFixture(t) {
|
||||
viewer.trackedEntityChanged = new Cesium.Event();
|
||||
viewer.camera.cancelFlight = () => {};
|
||||
viewer.camera.lookAtTransform = () => {};
|
||||
viewer.camera.flyToBoundingSphere = () => {};
|
||||
viewer.camera.setView = () => {};
|
||||
viewer.camera.flyToBoundingSphere = function () {
|
||||
this._currentFlight = {};
|
||||
};
|
||||
viewer.camera.setView = function () {
|
||||
this.positionWC = Cesium.Cartesian3.add(
|
||||
this.positionWC,
|
||||
new Cesium.Cartesian3(0, 0, 50),
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
};
|
||||
const originalFly = viewer.camera.flyTo;
|
||||
const navigation = new NavigationController({
|
||||
viewer,
|
||||
@@ -142,6 +157,8 @@ 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]);
|
||||
if (handoff === 'Director') {
|
||||
SceneDirector.prototype._claimCameraOwnership.call({
|
||||
viewer, styleManager: { runImmediateNavigation: (noun, fn) =>
|
||||
@@ -161,11 +178,50 @@ for (const handoff of ['Director', 'tracking', 'follow', 'keyboard', 'UI',
|
||||
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.camera.flyTo, originalFly, 'direct-call hook is removed');
|
||||
assert.equal(viewer.camera.flyTo, originalFly);
|
||||
assert.deepEqual(
|
||||
['flyTo', 'flyToBoundingSphere', 'setView', 'lookAt', 'cancelFlight']
|
||||
.map((name) => viewer.camera[name]),
|
||||
methods,
|
||||
'the guard never replaces camera methods',
|
||||
);
|
||||
assert.equal(viewer.trackedEntityChanged.numberOfListeners, 0);
|
||||
navigation.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
// 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));
|
||||
assert.equal(viewer.flights.length, 0, 'the moved view is not corrected');
|
||||
});
|
||||
|
||||
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 });
|
||||
// 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);
|
||||
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 });
|
||||
const lowered = Cesium.Cartographic.fromDegrees(-97.7603, 30.3141, 150);
|
||||
viewer.camera.positionCartographic = lowered;
|
||||
viewer.camera.positionWC = Cesium.Cartographic.toCartesian(lowered);
|
||||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||||
assert.equal(viewer.flights.length, 0);
|
||||
});
|
||||
Reference in new issue
Block a user