mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Application extras come from the renderer plugin; framing, occlusion and panel drawing are contract ports
A renderer plugin may supply applicationHooks(renderer) for what only its renderer has (map engine, own credits, stale commands, QA handles). What every renderer should do moves onto the contract: controls.keepEarthFramed (behind the keepEarthFramed capability), query.occlusionTest (behind occlusionTest), and panel drawing, which keepPanelRendering now does through resize and frame.renderNow through the contract. renderNow throws when the frame fails to draw. The Cesium port installs its zoom-out guard through keepEarthFramed (a setView no longer cancels its turn) and answers occlusionTest with the scene's probe; the stub answers it with a horizon test.
This commit is contained in:
1 parent
a755f63638
commit
619c19ea67
40 files changed
+737
-323
No files matched your search
Vendored
+1
-16
@@ -11,13 +11,7 @@ import { t } from '../i18n/index.js';
|
||||
* picker, for a page that does not initialize the app's locale.
|
||||
*/
|
||||
export function createApplicationControls({
|
||||
scene: {
|
||||
viewer,
|
||||
mapStackController,
|
||||
operations,
|
||||
viewerDrawsEntity,
|
||||
installZoomOutGuard,
|
||||
},
|
||||
scene: { viewer, mapStackController, operations, viewerDrawsEntity },
|
||||
loaderStatus,
|
||||
Controls = StyleManager,
|
||||
services,
|
||||
@@ -49,15 +43,6 @@ export function createApplicationControls({
|
||||
defer(() => styleManager.orbitController.stop());
|
||||
defer(() => styleManager.hud.destroy());
|
||||
defer(() => styleManager.dispose());
|
||||
// The scene's renderer bounds the user's outward zooms (a scene whose
|
||||
// renderer has no such guard gives none).
|
||||
if (installZoomOutGuard)
|
||||
defer(
|
||||
installZoomOutGuard({
|
||||
subscribeCameraHandoff: (listener) =>
|
||||
styleManager.subscribeCameraHandoff?.(listener),
|
||||
}),
|
||||
);
|
||||
// The previous multi-canvas weather compositor remains disabled. Cockpit
|
||||
// clouds use a separate, capped low-resolution GPU pass that never attaches
|
||||
// Cesium fog or post-process stages and is fully stopped in map mode.
|
||||
|
||||
@@ -11,55 +11,7 @@ before(() => {
|
||||
});
|
||||
after(() => uninstallDom());
|
||||
|
||||
test("application controls install the scene's zoom-out guard and remove it on teardown", () => {
|
||||
const handoffs = new Set();
|
||||
class Controls {
|
||||
hasShareState = true;
|
||||
orbitController = { stop() {} };
|
||||
hud = { destroy() {} };
|
||||
dispose() {}
|
||||
subscribeCameraHandoff(listener) {
|
||||
handoffs.add(listener);
|
||||
return () => handoffs.delete(listener);
|
||||
}
|
||||
}
|
||||
const cleanups = [];
|
||||
// The guard the scene's renderer gives: installed once, with the controls'
|
||||
// camera handoff, and disposed with the application.
|
||||
const guard = { installs: 0, disposals: 0 };
|
||||
createApplicationControls({
|
||||
scene: {
|
||||
viewer: {},
|
||||
mapStackController: {},
|
||||
operations: {
|
||||
surface: { controlServices: {} },
|
||||
searchAndFlyTo() {},
|
||||
requests: { regional: {}, weather: {} },
|
||||
},
|
||||
installZoomOutGuard({ subscribeCameraHandoff }) {
|
||||
guard.installs += 1;
|
||||
const unsubscribe = subscribeCameraHandoff(() => {});
|
||||
return () => {
|
||||
guard.disposals += 1;
|
||||
unsubscribe();
|
||||
};
|
||||
},
|
||||
},
|
||||
loaderStatus: {},
|
||||
Controls,
|
||||
catalog: { get: (id) => ({ id }) },
|
||||
defer: (cleanup) => cleanups.push(cleanup),
|
||||
});
|
||||
|
||||
assert.equal(guard.installs, 1);
|
||||
assert.equal(handoffs.size, 1);
|
||||
|
||||
for (const cleanup of cleanups.reverse()) cleanup();
|
||||
assert.equal(guard.disposals, 1);
|
||||
assert.equal(handoffs.size, 0);
|
||||
});
|
||||
|
||||
test('a scene without a zoom-out guard starts its controls without one', () => {
|
||||
test('the application controls start and stop', () => {
|
||||
class Controls {
|
||||
hasShareState = true;
|
||||
orbitController = { stop() {} };
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ export function createApplicationData({
|
||||
const dataManager = new LayerLifecycle(viewer, {
|
||||
allowQaRegistration,
|
||||
// A panel's host may report it hidden while it is on screen; its layers
|
||||
// keep polling (see keepPanelRendering in render/cesium/panelRendering.js).
|
||||
// keep polling (see keepPanelRendering in app/panelRendering.js).
|
||||
visibilityTarget: panelAwareVisibility(document),
|
||||
getSourceAvailability: catalog?.getSourceAvailability,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @module app/panelRendering
|
||||
* @description Keeping the globe drawing in an inline panel whose host stops
|
||||
* animation frames (`src/app/embed.js`, embed mode), through the ports alone: the
|
||||
* application scene hands it to the embed views (`src/app/scene.js`).
|
||||
*/
|
||||
|
||||
// A panel keeps drawing at about this rate when its host stops animation
|
||||
// frames; see keepPanelRendering.
|
||||
const PANEL_FRAME_MS = 33;
|
||||
const MISSED_FRAMES_MS = 250;
|
||||
|
||||
/** A render error's details, including the plain objects workers report. */
|
||||
function describeError(error) {
|
||||
if (error instanceof Error)
|
||||
return `${error.name}: ${error.message}\n${error.stack}`;
|
||||
try {
|
||||
return JSON.stringify(error, Object.getOwnPropertyNames(error ?? {}));
|
||||
} catch {
|
||||
return String(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep `renderer` drawing in an inline panel. Some hosts report a panel on
|
||||
* screen as hidden, which stops the browser's animation frames and with them
|
||||
* the renderer's own loop; while frames stop arriving, draw from a timer
|
||||
* (`resize`, then `frame.renderNow()`). A frame that fails stops the timer,
|
||||
* its error reported in full. Returns a function that stops it.
|
||||
* @param {import('../render/contract/renderer').Renderer} renderer
|
||||
* @param {{windowRef?: Window, now?: () => number}} [options]
|
||||
* @returns {() => void}
|
||||
*/
|
||||
export function keepPanelRendering(
|
||||
renderer,
|
||||
{ windowRef = globalThis.window, now = () => performance.now() } = {},
|
||||
) {
|
||||
let lastFrame = now();
|
||||
let frameRequest = null;
|
||||
const onFrame = () => {
|
||||
lastFrame = now();
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
};
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
let failed = false;
|
||||
const timer = windowRef.setInterval(() => {
|
||||
if (failed || now() - lastFrame < MISSED_FRAMES_MS) return;
|
||||
try {
|
||||
renderer.resize();
|
||||
renderer.frame.renderNow();
|
||||
} catch (error) {
|
||||
// Report the error in full: workers report plain objects, which
|
||||
// would print as [object Object].
|
||||
failed = true;
|
||||
console.error(
|
||||
"[God's Eye View panel] render error:",
|
||||
describeError(error),
|
||||
);
|
||||
}
|
||||
}, PANEL_FRAME_MS);
|
||||
return () => {
|
||||
windowRef.clearInterval(timer);
|
||||
windowRef.cancelAnimationFrame(frameRequest);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { keepPanelRendering } from './panelRendering.js';
|
||||
|
||||
const windowWith = () => {
|
||||
const handles = { tick: null, frame: null };
|
||||
handles.windowRef = {
|
||||
requestAnimationFrame: (fn) => ((handles.frame = fn), 1),
|
||||
cancelAnimationFrame: () => (handles.frame = null),
|
||||
setInterval: (fn) => ((handles.tick = fn), 1),
|
||||
clearInterval: () => (handles.tick = null),
|
||||
};
|
||||
return handles;
|
||||
};
|
||||
|
||||
test('a panel keeps drawing from a timer while animation frames stop', () => {
|
||||
let clock = 0;
|
||||
const handles = windowWith();
|
||||
const drawn = [];
|
||||
const renderer = {
|
||||
resize: () => drawn.push('resize'),
|
||||
frame: { renderNow: () => drawn.push('render') },
|
||||
};
|
||||
const stop = keepPanelRendering(renderer, {
|
||||
windowRef: handles.windowRef,
|
||||
now: () => clock,
|
||||
});
|
||||
// Frames arrive: the render loop draws, so the timer does nothing.
|
||||
clock = 100;
|
||||
handles.frame();
|
||||
handles.tick();
|
||||
assert.deepEqual(drawn, []);
|
||||
// Frames stop, as in a panel its host reports hidden: the timer draws.
|
||||
clock = 400;
|
||||
handles.tick();
|
||||
assert.deepEqual(drawn, ['resize', 'render']);
|
||||
stop();
|
||||
assert.equal(handles.tick, null);
|
||||
assert.equal(handles.frame, null);
|
||||
});
|
||||
|
||||
test('a panel reports a failed frame in full and stops drawing', () => {
|
||||
const handles = windowWith();
|
||||
let renders = 0;
|
||||
const renderer = {
|
||||
resize() {},
|
||||
frame: {
|
||||
renderNow() {
|
||||
renders += 1;
|
||||
// Workers report plain objects.
|
||||
throw { name: 'RuntimeError', message: 'worker failed' };
|
||||
},
|
||||
},
|
||||
};
|
||||
const logged = [];
|
||||
const original = console.error;
|
||||
console.error = (...args) => logged.push(args.join(' '));
|
||||
try {
|
||||
let clock = 0;
|
||||
const stop = keepPanelRendering(renderer, {
|
||||
windowRef: handles.windowRef,
|
||||
now: () => clock,
|
||||
});
|
||||
clock = 1000;
|
||||
handles.tick();
|
||||
assert.match(logged[0], /render error: .*"message":"worker failed"/);
|
||||
handles.tick();
|
||||
assert.equal(renders, 1, 'no frame after the one that failed');
|
||||
stop();
|
||||
} finally {
|
||||
console.error = original;
|
||||
}
|
||||
});
|
||||
+26
-7
@@ -15,7 +15,11 @@ import { describeError } from './errors.js';
|
||||
import { worldClock, worldTimeFor } from '../time/worldClock.js';
|
||||
import { followWorldTime } from '../time/viewerClock.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
import { applicationHooksOf } from '../render/applicationHooks.js';
|
||||
import {
|
||||
applicationHooksOf,
|
||||
provideApplicationHooks,
|
||||
} from '../render/applicationHooks.js';
|
||||
import { keepPanelRendering } from './panelRendering.js';
|
||||
import { createSceneHost } from '../render/rendererOf.js';
|
||||
|
||||
let defaultLoad = null;
|
||||
@@ -95,7 +99,6 @@ export async function createApplicationScene({
|
||||
// bound to the renderer.
|
||||
const scene = createSceneHost(renderer, { container });
|
||||
const viewer = scene.host;
|
||||
const hooks = applicationHooksOf(renderer);
|
||||
// The governor keeps its holds on the renderer's frame port. The loop
|
||||
// draws every frame until the application's tools are up (they release
|
||||
// 'boot'), as it did before anything could hold it.
|
||||
@@ -112,6 +115,14 @@ export async function createApplicationScene({
|
||||
}
|
||||
}
|
||||
});
|
||||
// What the plugin hands the application beside the contract, each hook
|
||||
// optional (render/applicationHooks.js).
|
||||
if (typeof rendererPlugin.applicationHooks === 'function')
|
||||
provideApplicationHooks(
|
||||
renderer,
|
||||
rendererPlugin.applicationHooks(renderer),
|
||||
);
|
||||
const hooks = applicationHooksOf(renderer);
|
||||
// The renderer follows its container's size (`Renderer.resize`).
|
||||
if (typeof ResizeObserver === 'function' && container) {
|
||||
const resizes = new ResizeObserver(() => renderer.resize());
|
||||
@@ -126,6 +137,13 @@ export async function createApplicationScene({
|
||||
const { controls } = renderer.camera;
|
||||
if (!controls.zoomInputs.includes('ctrlWheel'))
|
||||
controls.zoomInputs = [...controls.zoomInputs, 'ctrlWheel'];
|
||||
// The user's outward zooms stop at a whole-Earth view, which stays framed.
|
||||
if (renderer.capabilities.has('keepEarthFramed')) {
|
||||
controls.keepEarthFramed = true;
|
||||
defer(() => {
|
||||
controls.keepEarthFramed = false;
|
||||
});
|
||||
}
|
||||
defer(
|
||||
followWorldTime(viewer, worldTimeFor('sky'), {
|
||||
subscribe: worldClock.subscribe,
|
||||
@@ -214,14 +232,15 @@ export async function createApplicationScene({
|
||||
mapStackController,
|
||||
operations,
|
||||
input,
|
||||
// Keeps the globe drawing in an inline panel whose host stops animation
|
||||
// frames (embed mode, src/app/embed.js); returns its disposer.
|
||||
keepPanelRendering: (options) => keepPanelRendering(renderer, options),
|
||||
// What the renderer's plugin hands the application beside the contract,
|
||||
// each optional: trims stale draw commands, keeps an inline panel
|
||||
// drawing, says whether an entity is the renderer's own, installs the
|
||||
// zoom-out guard, and what QA scripts read (render/applicationHooks.js).
|
||||
// each optional: trims stale draw commands, says whether an entity is
|
||||
// the renderer's own, and what QA scripts read
|
||||
// (render/applicationHooks.js).
|
||||
trimStaleCommands: hooks.trimStaleCommands,
|
||||
keepPanelRendering: hooks.keepPanelRendering,
|
||||
viewerDrawsEntity: hooks.viewerDrawsEntity,
|
||||
installZoomOutGuard: hooks.installZoomOutGuard,
|
||||
qaHandles: hooks.qaHandles,
|
||||
};
|
||||
}
|
||||
+41
-7
@@ -46,14 +46,15 @@ test('the scene runs on a renderer with only the required members', async (t) =>
|
||||
'isDestroyed',
|
||||
]);
|
||||
// No hooks: each is left out, not faked.
|
||||
for (const name of [
|
||||
'trimStaleCommands',
|
||||
'keepPanelRendering',
|
||||
'viewerDrawsEntity',
|
||||
'installZoomOutGuard',
|
||||
'qaHandles',
|
||||
])
|
||||
for (const name of ['trimStaleCommands', 'viewerDrawsEntity', 'qaHandles'])
|
||||
assert.equal(scene[name], undefined, name);
|
||||
// What the renderer does through its ports.
|
||||
assert.equal(typeof scene.keepPanelRendering, 'function');
|
||||
assert.equal(
|
||||
renderer.camera.controls.keepEarthFramed,
|
||||
undefined,
|
||||
'no framing on a renderer without it',
|
||||
);
|
||||
// Keyless, the map stack shows Esri on the globe through the globe port.
|
||||
assert.equal(scene.tileset, null);
|
||||
assert.equal(scene.mapStackController.getActiveId(), 'esri-imagery');
|
||||
@@ -91,6 +92,39 @@ test('the scene runs on a renderer with only the required members', async (t) =>
|
||||
assert.equal(document.getElementById('gev-credits'), null, 'credits gone');
|
||||
});
|
||||
|
||||
test('the scene keeps the Earth framed where the renderer can', async (t) => {
|
||||
const { renderer, deferred } = await startOnStub(t, {
|
||||
capabilities: ['keepEarthFramed'],
|
||||
});
|
||||
assert.equal(renderer.camera.controls.keepEarthFramed, true);
|
||||
const controls = renderer.camera.controls;
|
||||
for (const fn of deferred.splice(0).reverse()) await fn();
|
||||
assert.equal(controls.keepEarthFramed, false, 'and lets go on teardown');
|
||||
});
|
||||
|
||||
test("the scene takes a plugin's application hooks", async (t) => {
|
||||
const stub = createStubRendererPlugin({ capabilities: [] });
|
||||
const given = [];
|
||||
const handles = Object.freeze({ probe: 'qa' });
|
||||
const { scene } = await startOnStub(t, {
|
||||
renderer: {
|
||||
id: 'stub-with-hooks',
|
||||
create: (options) => stub.create(options),
|
||||
applicationHooks(made) {
|
||||
given.push(made);
|
||||
return { qaHandles: handles, ownCreditDisplay: true };
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.deepEqual(given, [scene.renderer], 'asked once, for the renderer');
|
||||
assert.equal(scene.qaHandles, handles, 'QA scripts read its handles');
|
||||
assert.equal(
|
||||
document.getElementById('gev-credits'),
|
||||
null,
|
||||
'its own display shows the credits',
|
||||
);
|
||||
});
|
||||
|
||||
test('with credentials, the photoreal base loads through the globe port', async (t) => {
|
||||
const { scene, renderer } = await startOnStub(t, {
|
||||
capabilities: ['photoreal', 'globeVisibility'],
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ export function createApplicationTools({
|
||||
// the loop, refresh the one DOM surface we gated, render a frame.
|
||||
const syncVisibilitySuspension = () => {
|
||||
// A panel's host may report it hidden while it is on screen; the panel
|
||||
// keeps drawing itself (see keepPanelRendering in render/cesium/panelRendering.js).
|
||||
// keeps drawing itself (see keepPanelRendering in app/panelRendering.js).
|
||||
const hidden = document.hidden && !isEmbeddedInline();
|
||||
renderer.frame.suspend(hidden);
|
||||
cockpitCloudEffects?.setSuspended?.(hidden);
|
||||
|
||||
Reference in new issue
Block a user