mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 03:32:19 +00:00
Start the application through the contract, not on the Cesium viewer
The application scene takes a renderer plugin and no longer refuses one without a Cesium viewer. It loads the default (Cesium) plugin only when it is given none, so a page on the stub never loads Cesium. - Every layer and tool is handed the application's own scene object (createSceneHost): the container and isDestroyed(), bound to the renderer, the same on Cesium and the stub. - What only Cesium needs at startup is done in its plugin's create: the free-look height limit, and keyboard access to its credits' expand link (creditKeyboard.js moves into the adapter). - What a plugin may hand the application beside the contract goes through provideApplicationHooks, each hook optional: Cesium's map engine, stale command trimming, inline panel rendering, viewerDrawsEntity, the zoom-out guard, and the viewer QA scripts read from window.__godsEyeView. - The map stacks, and the photoreal base the scene loads, switch through the renderer's own map engine (mapEngineFor), else its globe port (globeEngine.js). The Cesium engine takes the scene object and changes the viewer behind it.
This commit is contained in:
1 parent
a72d4c3b1f
commit
6daf63d90c
24 files changed
+825
-241
No files matched your search
@@ -3,6 +3,8 @@ import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { CONTRACT_VERSION, checkRendererShape } from '../contract/index.js';
|
||||
import { rendererOf } from '../rendererOf.js';
|
||||
import { applicationHooksOf } from '../applicationHooks.js';
|
||||
import { cesiumMapEngine } from './mapEngine.js';
|
||||
import {
|
||||
ReadonlySet,
|
||||
cesiumRenderer,
|
||||
@@ -55,12 +57,19 @@ function fakeViewer(log, { failDestroy = false } = {}) {
|
||||
moveEnd: fakeEvent(listeners),
|
||||
},
|
||||
primitives: { add() {}, remove() {} },
|
||||
// The free-look height limit writes the camera controller's look.
|
||||
screenSpaceCameraController: {
|
||||
enableLook: true,
|
||||
minimumTrackBallHeight: 7_500_000,
|
||||
},
|
||||
requestRender() {},
|
||||
preUpdate: fakeEvent(listeners),
|
||||
postUpdate: fakeEvent(listeners),
|
||||
preRender: fakeEvent(listeners),
|
||||
postRender: fakeEvent(listeners),
|
||||
},
|
||||
camera: { positionCartographic: { height: 20_000_000 } },
|
||||
entities: { contains: (entity) => entity?.own === true },
|
||||
canvas: {
|
||||
tag: 'canvas',
|
||||
// Cesium's input handler binds the canvas's events.
|
||||
@@ -128,6 +137,23 @@ test('the plugin wraps the viewer it is given, behind the accessor only', async
|
||||
assert.equal(cesiumViewerOf(renderer).canvas, renderer.canvas);
|
||||
assert.equal(rendererOf(viewer), renderer, 'the viewer finds its renderer');
|
||||
|
||||
assert.equal(
|
||||
viewer.scene.screenSpaceCameraController.enableLook,
|
||||
false,
|
||||
'free look is limited to low heights from the start',
|
||||
);
|
||||
const hooks = applicationHooksOf(renderer);
|
||||
assert.equal(hooks.mapEngine, cesiumMapEngine, 'the map stacks use Cesium');
|
||||
assert.equal(hooks.qaHandles.viewer, viewer, 'QA scripts read the viewer');
|
||||
assert.equal(hooks.viewerDrawsEntity({ own: true }), true);
|
||||
assert.equal(hooks.viewerDrawsEntity({}), false);
|
||||
for (const name of [
|
||||
'trimStaleCommands',
|
||||
'keepPanelRendering',
|
||||
'installZoomOutGuard',
|
||||
])
|
||||
assert.equal(typeof hooks[name], 'function', name);
|
||||
|
||||
assert.ok(viewer.listeners.size > 0, 'the ports follow the frame phases');
|
||||
assert.equal(typeof renderer.draw.icons, 'function');
|
||||
assert.ok(renderer.capabilities.has('models'), 'draw.models is declared');
|
||||
@@ -136,6 +162,11 @@ test('the plugin wraps the viewer it is given, behind the accessor only', async
|
||||
renderer.destroy();
|
||||
assert.equal(viewer.listeners.size, 0, 'and stop on destroy');
|
||||
assert.equal(rendererOf(viewer), null, 'and lets go of the viewer');
|
||||
assert.equal(
|
||||
viewer.scene.screenSpaceCameraController.enableLook,
|
||||
true,
|
||||
'and gives free look back',
|
||||
);
|
||||
assert.deepEqual(log, ['resize', 'destroy']);
|
||||
assert.deepEqual(doc.children, [], 'credits leave with the renderer');
|
||||
renderer.destroy();
|
||||
@@ -273,48 +304,4 @@ test('only renderers this plugin made reach a Cesium viewer', () => {
|
||||
assert.equal(cesiumViewerOf({}), null);
|
||||
});
|
||||
|
||||
test('the application refuses a renderer it cannot run on, and destroys it', async (t) => {
|
||||
const { createApplicationScene } = await import('../../app/scene.js');
|
||||
const { createApplicationRequestServices } =
|
||||
await import('../../services/requests.js');
|
||||
const destroyed = [];
|
||||
const deferred = [];
|
||||
const plugin = {
|
||||
id: 'other',
|
||||
async create(options) {
|
||||
assert.ok(options.signal, 'the scene passes its signal');
|
||||
return {
|
||||
id: 'other',
|
||||
destroy: () => {
|
||||
destroyed.push('other');
|
||||
throw new Error('and it fails to go');
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
const saved = { document: globalThis.document, window: globalThis.window };
|
||||
globalThis.document = fakeDocument();
|
||||
globalThis.window = new EventTarget();
|
||||
const warn = console.warn;
|
||||
console.warn = () => {};
|
||||
t.after(() => {
|
||||
for (const fn of deferred.reverse()) fn();
|
||||
console.warn = warn;
|
||||
globalThis.document = saved.document;
|
||||
globalThis.window = saved.window;
|
||||
});
|
||||
await assert.rejects(
|
||||
createApplicationScene({
|
||||
renderer: plugin,
|
||||
requestServices: createApplicationRequestServices(),
|
||||
loaderStatus: { textContent: '' },
|
||||
signal: new AbortController().signal,
|
||||
defer: (fn) => deferred.push(fn),
|
||||
}),
|
||||
/renderer cannot run the application yet/,
|
||||
'the refusal is not hidden by the failed destroy',
|
||||
);
|
||||
assert.deepEqual(destroyed, ['other']);
|
||||
});
|
||||
|
||||
const EXPECTED_MISSING = [];
|
||||
Reference in new issue
Block a user