mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Embed views and the application shell leave the Cesium allow-list
The embed views fly through rendererOf's camera port with geo maths, and the panel render loop that keeps an inline panel drawing moves into the Cesium adapter (src/render/cesium/panelRendering.js); the application scene hands it to the embed views as `keepRendering`. The shell reaches the camera, effects and globe through rendererOf and loads no Cesium factories; whether Cockpit's aircraft is an entity of the viewer's own comes from the scene's `viewerDrawsEntity`, wired in through the controls. Callers handing the shell or the application tools a viewer of their own load ./render/cesium/unbound once, as the ports' unbound check now records.
This commit is contained in:
1 parent
e6d9ec0636
commit
26665e8390
16 files changed
+222
-185
No files matched your search
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @module render/cesium/panelRendering
|
||||
* @description Keeping the Cesium viewer drawing in an inline panel whose
|
||||
* host stops animation frames (`src/app/embed.js`, embed mode). 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 the globe drawing in an inline panel. Some hosts report a panel on
|
||||
* screen as hidden, which stops the browser's animation frames and with them
|
||||
* Cesium's render loop; while frames stop arriving, draw from a timer.
|
||||
* Returns a function that stops it.
|
||||
*/
|
||||
export function keepPanelRendering(
|
||||
viewer,
|
||||
{ windowRef = globalThis.window, now = () => performance.now() } = {},
|
||||
) {
|
||||
let lastFrame = now();
|
||||
let frameRequest = null;
|
||||
const onFrame = () => {
|
||||
lastFrame = now();
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
};
|
||||
frameRequest = windowRef.requestAnimationFrame(onFrame);
|
||||
// Cesium stops drawing after a render error, and so does the timer.
|
||||
// Report the error in full: workers report plain objects, which Cesium
|
||||
// prints as [object Object].
|
||||
let failed = false;
|
||||
const removeErrorListener = viewer.scene?.renderError?.addEventListener(
|
||||
(_scene, error) => {
|
||||
failed = true;
|
||||
console.error(
|
||||
"[God's Eye View panel] render error:",
|
||||
describeError(error),
|
||||
);
|
||||
},
|
||||
);
|
||||
const timer = windowRef.setInterval(() => {
|
||||
if (
|
||||
failed ||
|
||||
now() - lastFrame < MISSED_FRAMES_MS ||
|
||||
viewer.isDestroyed?.()
|
||||
)
|
||||
return;
|
||||
viewer.resize();
|
||||
viewer.render();
|
||||
}, PANEL_FRAME_MS);
|
||||
return () => {
|
||||
windowRef.clearInterval(timer);
|
||||
windowRef.cancelAnimationFrame(frameRequest);
|
||||
removeErrorListener?.();
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { keepPanelRendering } from './panelRendering.js';
|
||||
|
||||
test('a panel keeps drawing from a timer while animation frames stop', () => {
|
||||
let clock = 0;
|
||||
let tick = null;
|
||||
let frame = null;
|
||||
const windowRef = {
|
||||
requestAnimationFrame: (fn) => ((frame = fn), 1),
|
||||
cancelAnimationFrame: () => (frame = null),
|
||||
setInterval: (fn) => ((tick = fn), 1),
|
||||
clearInterval: () => (tick = null),
|
||||
};
|
||||
const drawn = [];
|
||||
const viewer = {
|
||||
resize: () => drawn.push('resize'),
|
||||
render: () => drawn.push('render'),
|
||||
};
|
||||
const stop = keepPanelRendering(viewer, { windowRef, now: () => clock });
|
||||
// Frames arrive: the render loop draws, so the timer does nothing.
|
||||
clock = 100;
|
||||
frame();
|
||||
tick();
|
||||
assert.deepEqual(drawn, []);
|
||||
// Frames stop, as in a panel its host reports hidden: the timer draws.
|
||||
clock = 400;
|
||||
tick();
|
||||
assert.deepEqual(drawn, ['resize', 'render']);
|
||||
stop();
|
||||
assert.equal(tick, null);
|
||||
assert.equal(frame, null);
|
||||
});
|
||||
|
||||
test('a panel reports a render error in full and stops drawing', () => {
|
||||
let listener = null;
|
||||
let tick = null;
|
||||
const windowRef = {
|
||||
requestAnimationFrame: () => 1,
|
||||
cancelAnimationFrame() {},
|
||||
setInterval: (fn) => ((tick = fn), 1),
|
||||
clearInterval() {},
|
||||
};
|
||||
const drawn = [];
|
||||
const viewer = {
|
||||
resize() {},
|
||||
render: () => drawn.push('render'),
|
||||
scene: {
|
||||
renderError: {
|
||||
addEventListener: (fn) => ((listener = fn), () => (listener = null)),
|
||||
},
|
||||
},
|
||||
};
|
||||
const logged = [];
|
||||
const original = console.error;
|
||||
console.error = (...args) => logged.push(args.join(' '));
|
||||
try {
|
||||
let clock = 0;
|
||||
const stop = keepPanelRendering(viewer, { windowRef, now: () => clock });
|
||||
listener(viewer.scene, { name: 'RuntimeError', message: 'worker failed' });
|
||||
assert.match(logged[0], /render error: .*"message":"worker failed"/);
|
||||
clock = 1000;
|
||||
tick();
|
||||
assert.deepEqual(drawn, []);
|
||||
stop();
|
||||
assert.equal(listener, null);
|
||||
} finally {
|
||||
console.error = original;
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1 @@
|
||||
[
|
||||
"dev/conformance/main.js",
|
||||
"src/app/embed.js",
|
||||
"src/app/scene.js",
|
||||
"src/data/geoImportPins.js",
|
||||
"src/ui/applicationShell.js"
|
||||
]
|
||||
["dev/conformance/main.js", "src/app/scene.js", "src/data/geoImportPins.js"]
|
||||
@@ -49,13 +49,11 @@ const UNBOUND = 'src/render/cesium/unbound.js';
|
||||
/**
|
||||
* Entries that take their Cesium code injected: the module named here is
|
||||
* GEV's Cesium side for them, and must load the factories. Given another, the
|
||||
* entry's flight finds no camera (`findCamera`) and does nothing. Visual
|
||||
* settings are given their viewer by the application shell, which loads
|
||||
* both factories; without it, their styles keep records and draw nothing.
|
||||
* entry's flight finds no camera (`findCamera`) and does nothing. None is
|
||||
* left: visual settings, once given their viewer by the application shell,
|
||||
* now leave the factories to their caller as the shell does.
|
||||
*/
|
||||
const INJECTED = {
|
||||
'./ui/visual-settings': 'src/ui/applicationShell.js',
|
||||
};
|
||||
const INJECTED = {};
|
||||
|
||||
/**
|
||||
* Modules whose use of the bridge holds up without the factory: with no
|
||||
@@ -141,6 +139,10 @@ const DRAW_FROM_CALLER = new Set([
|
||||
// eye and shade the globe through the ports alone.
|
||||
'./application/layers',
|
||||
'./standalone/catalog',
|
||||
// The application's tools (scene director, annotations, embed views):
|
||||
// they draw, fly and take clicks through the ports; only Import's pins
|
||||
// (`src/data/geoImportPins.js`, still on the Cesium list) drive Cesium.
|
||||
'./application/tools',
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -174,6 +176,16 @@ const CAMERA_FROM_CALLER = new Set([
|
||||
// It shows its source's credit through `findCredits`, and switches stacks
|
||||
// through the map engine that `./render/cesium/unbound` provides too.
|
||||
'./maps/controller',
|
||||
// The application shell and what assembles it: their controls fly, read
|
||||
// the eye, shade the globe and set styles through the ports alone; the
|
||||
// application's renderer is bound to its viewer, and a viewer of the
|
||||
// renderer bound gets its ports from `./render/cesium/unbound`.
|
||||
'./ui/shell',
|
||||
'./ui/composition',
|
||||
'./ui/hud',
|
||||
'./ui/visual-settings',
|
||||
'./application/controls',
|
||||
'./application/data',
|
||||
]);
|
||||
|
||||
const pkg = JSON.parse(readFileSync(path.join(root, 'package.json'), 'utf8'));
|
||||
@@ -343,8 +355,8 @@ function checkLookupFactory(
|
||||
);
|
||||
}
|
||||
|
||||
test('every public entry that reaches a findEffects caller loads the unbound effects factory', () => {
|
||||
checkLookupFactory('findEffects', EFFECTS_FACTORY);
|
||||
test('every public entry that reaches a findEffects caller loads the unbound effects factory, or its caller can', () => {
|
||||
checkLookupFactory('findEffects', EFFECTS_FACTORY, { fromCaller: true });
|
||||
});
|
||||
|
||||
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
|
||||
|
||||
Reference in new issue
Block a user