mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +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
@@ -468,10 +468,13 @@ release listeners; pending action feedback is limited to its current owner.
|
|||||||
rendering, HUD and share operations. `src/standalone/controls.js` provides the running
|
rendering, HUD and share operations. `src/standalone/controls.js` provides the running
|
||||||
application's instances. The shell
|
application's instances. The shell
|
||||||
imports no standalone bootstrap or concrete live layer implementation.
|
imports no standalone bootstrap or concrete live layer implementation.
|
||||||
The celestial ring's precise ICRF rotation comes from the renderer
|
The shell reaches the renderer through its ports alone, and loads no
|
||||||
(`src/sky/icrf.js`): the application's renderer provides it; a shell given a
|
renderer: given a viewer with no renderer bound, load
|
||||||
viewer with no renderer bound gets it once `./render/cesium/unbound` has loaded, and
|
`./render/cesium/unbound` once first, which also provides the celestial
|
||||||
falls back to the TEME approximation until then.
|
ring's precise ICRF rotation (`src/sky/icrf.js`; until then the ring uses
|
||||||
|
the TEME approximation). Whether Cockpit's aircraft is an entity of the
|
||||||
|
viewer's own is the `viewerDrawsEntity` service's to say; the application
|
||||||
|
scene supplies it.
|
||||||
Panel layout, position/drag, notices, recording and deferred UI work have separate
|
Panel layout, position/drag, notices, recording and deferred UI work have separate
|
||||||
owners with synchronous cleanup. Existing scene, share and HUD engines retain
|
owners with synchronous cleanup. Existing scene, share and HUD engines retain
|
||||||
their entry points. `ui/styles` loads the ordered stylesheet entry; component
|
their entry points. `ui/styles` loads the ordered stylesheet entry; component
|
||||||
|
|||||||
@@ -881,7 +881,9 @@ unchanged.
|
|||||||
Polled layer refreshes and the HUD's camera readout pause while the page is
|
Polled layer refreshes and the HUD's camera readout pause while the page is
|
||||||
hidden. An app embedded inline in a panel keeps both running, because the
|
hidden. An app embedded inline in a panel keeps both running, because the
|
||||||
panel's host can report the page as hidden while it is on screen. This is the
|
panel's host can report the page as hidden while it is on screen. This is the
|
||||||
same rule the render loop follows (`keepPanelRendering` in `app/embed.js`).
|
same rule the render loop follows (`keepPanelRendering` in
|
||||||
|
`render/cesium/panelRendering.js`, which the application scene hands the embed
|
||||||
|
views).
|
||||||
|
|
||||||
Application scene setup owns request services, terrain/floor caches and annotation
|
Application scene setup owns request services, terrain/floor caches and annotation
|
||||||
lookup state. Controls, layers and voice share those owners, and cancellation
|
lookup state. Controls, layers and voice share those owners, and cancellation
|
||||||
@@ -1128,8 +1130,9 @@ port's `preUpdate`, with the shared geo maths, and no longer loads the Cesium
|
|||||||
camera factory: a caller handing it a Cesium viewer, with no
|
camera factory: a caller handing it a Cesium viewer, with no
|
||||||
renderer bound, loads the `./render/cesium/unbound` export once first, or its
|
renderer bound, loads the `./render/cesium/unbound` export once first, or its
|
||||||
controller throws naming it. Whether the aircraft it flies still draws comes
|
controller throws naming it. Whether the aircraft it flies still draws comes
|
||||||
from its `trackedEntityDrawn` service (the application asks the viewer's
|
from its `trackedEntityDrawn` service (the shell asks the entity's record,
|
||||||
entities); without one, Cockpit takes the aircraft as drawn.
|
and the application scene's `viewerDrawsEntity` for an entity of the viewer's
|
||||||
|
own); without one, Cockpit takes the aircraft as drawn.
|
||||||
|
|
||||||
## Rendered-mesh floor cells — November 8, 2026
|
## Rendered-mesh floor cells — November 8, 2026
|
||||||
|
|
||||||
|
|||||||
@@ -1130,6 +1130,8 @@
|
|||||||
"src/view/index.test.mjs",
|
"src/view/index.test.mjs",
|
||||||
"src/tools/views.test.mjs",
|
"src/tools/views.test.mjs",
|
||||||
"src/app/embed.test.mjs",
|
"src/app/embed.test.mjs",
|
||||||
|
"src/render/cesium/panelRendering.js",
|
||||||
|
"src/render/cesium/panelRendering.test.mjs",
|
||||||
"src/tools/globePanel.test.mjs",
|
"src/tools/globePanel.test.mjs",
|
||||||
"src/costEndpointThrottle.test.mjs",
|
"src/costEndpointThrottle.test.mjs",
|
||||||
"src/sources/gbfsStations.test.mjs",
|
"src/sources/gbfsStations.test.mjs",
|
||||||
|
|||||||
@@ -4295,7 +4295,8 @@
|
|||||||
"src/maps/engine.js",
|
"src/maps/engine.js",
|
||||||
"src/maps/attribution.js",
|
"src/maps/attribution.js",
|
||||||
"src/render/cesium/mapEngine.js",
|
"src/render/cesium/mapEngine.js",
|
||||||
"src/sky/icrf.js"
|
"src/sky/icrf.js",
|
||||||
|
"src/render/cesium/panelRendering.js"
|
||||||
],
|
],
|
||||||
"external": [
|
"external": [
|
||||||
"hls.js",
|
"hls.js",
|
||||||
|
|||||||
Vendored
+4
-2
@@ -8,10 +8,10 @@ import { t } from '../i18n/index.js';
|
|||||||
* Construct the existing controls and camera presentation. `initialShareCode`
|
* Construct the existing controls and camera presentation. `initialShareCode`
|
||||||
* opens a share code (the `<code>` of `/share/<code>`) at start-up, for a host
|
* opens a share code (the `<code>` of `/share/<code>`) at start-up, for a host
|
||||||
* whose address does not carry one. `localePicker: false` removes the language
|
* whose address does not carry one. `localePicker: false` removes the language
|
||||||
* picker, for a host that does not initialize Core's locale.
|
* picker, for a page that does not initialize the app's locale.
|
||||||
*/
|
*/
|
||||||
export function createApplicationControls({
|
export function createApplicationControls({
|
||||||
scene: { viewer, mapStackController, operations },
|
scene: { viewer, mapStackController, operations, viewerDrawsEntity },
|
||||||
loaderStatus,
|
loaderStatus,
|
||||||
Controls = StyleManager,
|
Controls = StyleManager,
|
||||||
services,
|
services,
|
||||||
@@ -30,6 +30,8 @@ export function createApplicationControls({
|
|||||||
fetchRegionalBrief: (...args) =>
|
fetchRegionalBrief: (...args) =>
|
||||||
operations.requests.regional.getBrief(...args),
|
operations.requests.regional.getBrief(...args),
|
||||||
...catalogControlServices(catalog),
|
...catalogControlServices(catalog),
|
||||||
|
// Whether an entity is one of the viewer's own; the scene answers it.
|
||||||
|
viewerDrawsEntity: viewerDrawsEntity ?? services?.viewerDrawsEntity,
|
||||||
},
|
},
|
||||||
requestServices: operations.requests,
|
requestServices: operations.requests,
|
||||||
mapStackController,
|
mapStackController,
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ export function createApplicationData({
|
|||||||
const dataManager = new LayerLifecycle(viewer, {
|
const dataManager = new LayerLifecycle(viewer, {
|
||||||
allowQaRegistration,
|
allowQaRegistration,
|
||||||
// A panel's host may report it hidden while it is on screen; its layers
|
// A panel's host may report it hidden while it is on screen; its layers
|
||||||
// keep polling (see keepPanelRendering in embed.js).
|
// keep polling (see keepPanelRendering in render/cesium/panelRendering.js).
|
||||||
visibilityTarget: panelAwareVisibility(document),
|
visibilityTarget: panelAwareVisibility(document),
|
||||||
getSourceAvailability: catalog?.getSourceAvailability,
|
getSourceAvailability: catalog?.getSourceAvailability,
|
||||||
});
|
});
|
||||||
|
|||||||
+14
-78
@@ -11,16 +11,9 @@
|
|||||||
* embedded or not.
|
* embedded or not.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Cesium from 'cesium';
|
|
||||||
import { announceNavigationAuthority } from '../navigationPolicy.js';
|
import { announceNavigationAuthority } from '../navigationPolicy.js';
|
||||||
import { cameraOf } from '../render/cesium/camera.js';
|
import { toRadians } from '../geo/index.js';
|
||||||
// The application's tools reach `findGlobe` callers too (the Recent Imagery
|
import { cameraOf } from '../render/rendererOf.js';
|
||||||
// panel, Import and others): a viewer with no renderer bound gets its globe
|
|
||||||
// port from here, as it gets its camera.
|
|
||||||
import '../render/cesium/globe.js';
|
|
||||||
// The application's data reaches `findEffects` (the cyber contact sweep):
|
|
||||||
// such a viewer gets its effects port from here too.
|
|
||||||
import '../render/cesium/effects.js';
|
|
||||||
import { annotationsFromParams, createView } from '../view/index.js';
|
import { annotationsFromParams, createView } from '../view/index.js';
|
||||||
|
|
||||||
const EMBED_VIEW_MESSAGE = 'gev:view';
|
const EMBED_VIEW_MESSAGE = 'gev:view';
|
||||||
@@ -55,7 +48,8 @@ export function isEmbeddedInline() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* `doc`'s visibility for work that pauses in a hidden page. A panel's host
|
* `doc`'s visibility for work that pauses in a hidden page. A panel's host
|
||||||
* may report it hidden while it is on screen (see keepPanelRendering), so an
|
* may report it hidden while it is on screen (see keepPanelRendering in
|
||||||
|
* render/cesium/panelRendering.js), so an
|
||||||
* inline panel always reads as visible.
|
* inline panel always reads as visible.
|
||||||
*/
|
*/
|
||||||
export function panelAwareVisibility(doc = globalThis.document) {
|
export function panelAwareVisibility(doc = globalThis.document) {
|
||||||
@@ -75,69 +69,6 @@ export function panelAwareVisibility(doc = globalThis.document) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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?.();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const delay = (ms, signal) =>
|
const delay = (ms, signal) =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
const timer = setTimeout(resolve, ms);
|
const timer = setTimeout(resolve, ms);
|
||||||
@@ -159,8 +90,8 @@ function flyTo(viewer, camera) {
|
|||||||
{ lon: camera.lon, lat: camera.lat, height: camera.altitude_m },
|
{ lon: camera.lon, lat: camera.lat, height: camera.altitude_m },
|
||||||
{
|
{
|
||||||
orientation: {
|
orientation: {
|
||||||
heading: Cesium.Math.toRadians(camera.heading_deg),
|
heading: toRadians(camera.heading_deg),
|
||||||
pitch: Cesium.Math.toRadians(camera.pitch_deg),
|
pitch: toRadians(camera.pitch_deg),
|
||||||
roll: 0,
|
roll: 0,
|
||||||
},
|
},
|
||||||
durationS: FLIGHT_SECONDS,
|
durationS: FLIGHT_SECONDS,
|
||||||
@@ -249,6 +180,9 @@ export async function applyView(
|
|||||||
/**
|
/**
|
||||||
* Install embed mode when the page asks for it, and draw any annotations the
|
* Install embed mode when the page asks for it, and draw any annotations the
|
||||||
* opening link carries. Returns a function that removes the message handler.
|
* opening link carries. Returns a function that removes the message handler.
|
||||||
|
* `keepRendering({windowRef})` keeps the globe drawing in an inline panel
|
||||||
|
* whose host stops animation frames, and returns a function that stops it;
|
||||||
|
* the application scene gives it (`keepPanelRendering`).
|
||||||
*/
|
*/
|
||||||
export function installViews({
|
export function installViews({
|
||||||
shell,
|
shell,
|
||||||
@@ -256,6 +190,7 @@ export function installViews({
|
|||||||
dataManager,
|
dataManager,
|
||||||
run,
|
run,
|
||||||
signal,
|
signal,
|
||||||
|
keepRendering = null,
|
||||||
location = globalThis.location,
|
location = globalThis.location,
|
||||||
windowRef = globalThis.window,
|
windowRef = globalThis.window,
|
||||||
}) {
|
}) {
|
||||||
@@ -271,9 +206,10 @@ export function installViews({
|
|||||||
|
|
||||||
windowRef.document.body.classList.add('ui-embed');
|
windowRef.document.body.classList.add('ui-embed');
|
||||||
shell.setCleanView?.(true);
|
shell.setCleanView?.(true);
|
||||||
const stopRendering = isEmbeddedInline()
|
const stopRendering =
|
||||||
? keepPanelRendering(viewer, { windowRef })
|
isEmbeddedInline() && keepRendering
|
||||||
: () => {};
|
? keepRendering({ windowRef })
|
||||||
|
: () => {};
|
||||||
// A framing page talks to the app across frames; an inline panel shares
|
// A framing page talks to the app across frames; an inline panel shares
|
||||||
// the page with it and talks through the page's own window.
|
// the page with it and talks through the page's own window.
|
||||||
const peer = isEmbeddedInline() ? windowRef : windowRef.parent;
|
const peer = isEmbeddedInline() ? windowRef : windowRef.parent;
|
||||||
|
|||||||
+8
-68
@@ -5,7 +5,6 @@ import {
|
|||||||
applyView,
|
applyView,
|
||||||
installViews,
|
installViews,
|
||||||
isEmbedded,
|
isEmbedded,
|
||||||
keepPanelRendering,
|
|
||||||
panelAwareVisibility,
|
panelAwareVisibility,
|
||||||
} from './embed.js';
|
} from './embed.js';
|
||||||
import { LayerLifecycle } from '../data/lifecycle.js';
|
import { LayerLifecycle } from '../data/lifecycle.js';
|
||||||
@@ -203,6 +202,7 @@ test('an app loaded inline into a panel page talks through its own window', asyn
|
|||||||
globalThis.GEV_EMBED_INLINE = true;
|
globalThis.GEV_EMBED_INLINE = true;
|
||||||
try {
|
try {
|
||||||
assert.equal(isEmbedded({ search: '' }), true);
|
assert.equal(isEmbedded({ search: '' }), true);
|
||||||
|
const kept = [];
|
||||||
const remove = installViews({
|
const remove = installViews({
|
||||||
shell: { initialRestorePromise: Promise.resolve() },
|
shell: { initialRestorePromise: Promise.resolve() },
|
||||||
viewer: fakeViewer(),
|
viewer: fakeViewer(),
|
||||||
@@ -210,7 +210,13 @@ test('an app loaded inline into a panel page talks through its own window', asyn
|
|||||||
run: recorder().run,
|
run: recorder().run,
|
||||||
location: { search: '', hash: '' },
|
location: { search: '', hash: '' },
|
||||||
windowRef,
|
windowRef,
|
||||||
|
// The scene's panel rendering, kept on while the views are installed.
|
||||||
|
keepRendering: (options) => {
|
||||||
|
kept.push(options.windowRef === windowRef);
|
||||||
|
return () => kept.push('stopped');
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
assert.deepEqual(kept, [true]);
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
assert.deepEqual(posted, [{ type: 'gev:ready' }]);
|
assert.deepEqual(posted, [{ type: 'gev:ready' }]);
|
||||||
const event = new Event('message');
|
const event = new Event('message');
|
||||||
@@ -223,6 +229,7 @@ test('an app loaded inline into a panel page talks through its own window', asyn
|
|||||||
assert.equal(posted[1].id, 7);
|
assert.equal(posted[1].id, 7);
|
||||||
assert.equal(posted[1].ok, true);
|
assert.equal(posted[1].ok, true);
|
||||||
remove();
|
remove();
|
||||||
|
assert.deepEqual(kept, [true, 'stopped']);
|
||||||
} finally {
|
} finally {
|
||||||
delete globalThis.GEV_EMBED_INLINE;
|
delete globalThis.GEV_EMBED_INLINE;
|
||||||
}
|
}
|
||||||
@@ -301,73 +308,6 @@ test('annotations in a link are drawn after it restores, embedded or not', async
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('a followed aircraft owns the camera, and cockpit view is entered after it', async () => {
|
test('a followed aircraft owns the camera, and cockpit view is entered after it', async () => {
|
||||||
const viewer = fakeViewer();
|
const viewer = fakeViewer();
|
||||||
const { calls, run } = recorder();
|
const { calls, run } = recorder();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
cesiumViewerOf,
|
cesiumViewerOf,
|
||||||
} from '../render/cesium/appRenderer.js';
|
} from '../render/cesium/appRenderer.js';
|
||||||
import { trimStaleSceneCommands } from '../render/cesium/sceneCommandRelease.js';
|
import { trimStaleSceneCommands } from '../render/cesium/sceneCommandRelease.js';
|
||||||
|
import { keepPanelRendering } from '../render/cesium/panelRendering.js';
|
||||||
import { registerDataCredits } from '../data/dataCredits.js';
|
import { registerDataCredits } from '../data/dataCredits.js';
|
||||||
import { configureCreditKeyboardAccess } from '../creditKeyboard.js';
|
import { configureCreditKeyboardAccess } from '../creditKeyboard.js';
|
||||||
import { MapStackController } from '../mapStackController.js';
|
import { MapStackController } from '../mapStackController.js';
|
||||||
@@ -169,5 +170,11 @@ export async function createApplicationScene({
|
|||||||
// Drops the draw commands the scene keeps after it stops drawing them;
|
// Drops the draw commands the scene keeps after it stops drawing them;
|
||||||
// run after a drawn frame (see src/sceneCommandRelease.js).
|
// run after a drawn frame (see src/sceneCommandRelease.js).
|
||||||
trimStaleCommands: () => trimStaleSceneCommands(viewer.scene),
|
trimStaleCommands: () => trimStaleSceneCommands(viewer.scene),
|
||||||
|
// Keeps the globe drawing in an inline panel whose host stops animation
|
||||||
|
// frames (embed mode, src/app/embed.js).
|
||||||
|
keepPanelRendering: (options) => keepPanelRendering(viewer, options),
|
||||||
|
// Whether an entity is one of the viewer's own (Cockpit asks whether
|
||||||
|
// the aircraft it flies still draws).
|
||||||
|
viewerDrawsEntity: (entity) => viewer.entities.contains(entity),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+2
-1
@@ -165,7 +165,7 @@ export function createApplicationTools({
|
|||||||
// the loop, refresh the one DOM surface we gated, render a frame.
|
// the loop, refresh the one DOM surface we gated, render a frame.
|
||||||
const syncVisibilitySuspension = () => {
|
const syncVisibilitySuspension = () => {
|
||||||
// A panel's host may report it hidden while it is on screen; the panel
|
// A panel's host may report it hidden while it is on screen; the panel
|
||||||
// keeps drawing itself (see keepPanelRendering in embed.js).
|
// keeps drawing itself (see keepPanelRendering in render/cesium/panelRendering.js).
|
||||||
const hidden = document.hidden && !isEmbeddedInline();
|
const hidden = document.hidden && !isEmbeddedInline();
|
||||||
renderer.frame.suspend(hidden);
|
renderer.frame.suspend(hidden);
|
||||||
cockpitCloudEffects?.setSuspended?.(hidden);
|
cockpitCloudEffects?.setSuspended?.(hidden);
|
||||||
@@ -232,6 +232,7 @@ export function createApplicationTools({
|
|||||||
dataManager,
|
dataManager,
|
||||||
run: (name, args) => voiceCommands.runner(name, args, { signal }),
|
run: (name, args) => voiceCommands.runner(name, args, { signal }),
|
||||||
signal,
|
signal,
|
||||||
|
keepRendering: scene.keepPanelRendering,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return { sceneDirector, annotations, voiceCommands };
|
return { sceneDirector, annotations, voiceCommands };
|
||||||
|
|||||||
+1
-1
@@ -441,7 +441,7 @@ export class IntelHUD {
|
|||||||
|
|
||||||
// Camera-derived data — 4 updates/second (250ms). Skipped in a hidden
|
// Camera-derived data — 4 updates/second (250ms). Skipped in a hidden
|
||||||
// page, except an inline panel, whose host may report it hidden while it
|
// page, except an inline panel, whose host may report it hidden while it
|
||||||
// is on screen (see keepPanelRendering in app/embed.js).
|
// is on screen (see keepPanelRendering in render/cesium/panelRendering.js).
|
||||||
this._updateInterval = setInterval(() => {
|
this._updateInterval = setInterval(() => {
|
||||||
if (!this._visible || (document.hidden && !isEmbeddedInline())) return;
|
if (!this._visible || (document.hidden && !isEmbeddedInline())) return;
|
||||||
this._updateCameraData();
|
this._updateCameraData();
|
||||||
|
|||||||
@@ -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/scene.js", "src/data/geoImportPins.js"]
|
||||||
"dev/conformance/main.js",
|
|
||||||
"src/app/embed.js",
|
|
||||||
"src/app/scene.js",
|
|
||||||
"src/data/geoImportPins.js",
|
|
||||||
"src/ui/applicationShell.js"
|
|
||||||
]
|
|
||||||
@@ -49,13 +49,11 @@ const UNBOUND = 'src/render/cesium/unbound.js';
|
|||||||
/**
|
/**
|
||||||
* Entries that take their Cesium code injected: the module named here is
|
* 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
|
* 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
|
* entry's flight finds no camera (`findCamera`) and does nothing. None is
|
||||||
* settings are given their viewer by the application shell, which loads
|
* left: visual settings, once given their viewer by the application shell,
|
||||||
* both factories; without it, their styles keep records and draw nothing.
|
* now leave the factories to their caller as the shell does.
|
||||||
*/
|
*/
|
||||||
const INJECTED = {
|
const INJECTED = {};
|
||||||
'./ui/visual-settings': 'src/ui/applicationShell.js',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules whose use of the bridge holds up without the factory: with no
|
* 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.
|
// eye and shade the globe through the ports alone.
|
||||||
'./application/layers',
|
'./application/layers',
|
||||||
'./standalone/catalog',
|
'./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
|
// It shows its source's credit through `findCredits`, and switches stacks
|
||||||
// through the map engine that `./render/cesium/unbound` provides too.
|
// through the map engine that `./render/cesium/unbound` provides too.
|
||||||
'./maps/controller',
|
'./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'));
|
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', () => {
|
test('every public entry that reaches a findEffects caller loads the unbound effects factory, or its caller can', () => {
|
||||||
checkLookupFactory('findEffects', EFFECTS_FACTORY);
|
checkLookupFactory('findEffects', EFFECTS_FACTORY, { fromCaller: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
|
test('every public entry that reaches a findGlobe caller loads the unbound globe factory', () => {
|
||||||
|
|||||||
@@ -32,13 +32,9 @@ import {
|
|||||||
} from './cyberSonarControls.js';
|
} from './cyberSonarControls.js';
|
||||||
|
|
||||||
import { toDegrees, toRadians } from '../geo/index.js';
|
import { toDegrees, toRadians } from '../geo/index.js';
|
||||||
import { cameraOf, findCamera } from '../render/cesium/camera.js';
|
// A viewer with no renderer bound gets its ports (camera, effects, globe)
|
||||||
// Loads the effects factory, so visual settings on a viewer with no renderer
|
// once its owner has loaded the package's `./render/cesium/unbound` export.
|
||||||
// bound still get an effects port. Loading the camera and effects factories,
|
import { cameraOf, canvasOf, findCamera } from '../render/rendererOf.js';
|
||||||
// and asking the viewer's entities whether Cockpit's aircraft still draws,
|
|
||||||
// keep this module on the Cesium allow-list.
|
|
||||||
import '../render/cesium/effects.js';
|
|
||||||
import '../render/cesium/globe.js';
|
|
||||||
|
|
||||||
import { aircraftTrackingTarget } from '../cockpitTracking.js';
|
import { aircraftTrackingTarget } from '../cockpitTracking.js';
|
||||||
|
|
||||||
@@ -380,10 +376,11 @@ export class StyleManager extends ShellFacade {
|
|||||||
warmGroundFloor: services.warmGroundFloor,
|
warmGroundFloor: services.warmGroundFloor,
|
||||||
sampleMeshFloorCells: services.sampleMeshFloorCells,
|
sampleMeshFloorCells: services.sampleMeshFloorCells,
|
||||||
// Whether the aircraft Cockpit flies still draws: an entity of the
|
// Whether the aircraft Cockpit flies still draws: an entity of the
|
||||||
// viewer's own, or a tracked contact whose layer draws it through
|
// viewer's own (the scene's `viewerDrawsEntity` says), or a tracked
|
||||||
// the draw port and says so in its entity record.
|
// contact whose layer draws it through the draw port and says so in
|
||||||
|
// its entity record.
|
||||||
trackedEntityDrawn: (entity) =>
|
trackedEntityDrawn: (entity) =>
|
||||||
viewer.entities.contains(entity) ||
|
services.viewerDrawsEntity?.(entity) === true ||
|
||||||
readEntityRecord(entity)?.drawn?.() === true,
|
readEntityRecord(entity)?.drawn?.() === true,
|
||||||
holdContinuousRender: services.holdContinuousRender,
|
holdContinuousRender: services.holdContinuousRender,
|
||||||
releaseContinuousRender: services.releaseContinuousRender,
|
releaseContinuousRender: services.releaseContinuousRender,
|
||||||
@@ -1030,7 +1027,7 @@ export class StyleManager extends ShellFacade {
|
|||||||
_radioVolumeValue: this._radioVolumeValue,
|
_radioVolumeValue: this._radioVolumeValue,
|
||||||
},
|
},
|
||||||
radio: radioLayer,
|
radio: radioLayer,
|
||||||
canvas: this.viewer?.canvas,
|
canvas: canvasOf(this.viewer) ?? undefined,
|
||||||
actions: {
|
actions: {
|
||||||
isRegistered: () => this._dataManager?.layers?.has('radio'),
|
isRegistered: () => this._dataManager?.layers?.has('radio'),
|
||||||
isEnabled: () => this._dataManager?.isEnabled('radio'),
|
isEnabled: () => this._dataManager?.isEnabled('radio'),
|
||||||
|
|||||||
Reference in new issue
Block a user