refactor(overlays): hand the shell's overlay host the engine, not the viewer

The controls pass the scene engine to the shell, which initializes the
world overlay on it; initWorldOverlay takes only a globe engine (a viewer
or null is refused), so the shell no longer needs a viewer for its
overlay. engineFromViewer only returns the engine registered for a viewer
(the scene engine until teardown) and never builds one, so no engine can
outlive its viewer without a destroy path. Overlay and detection tests
and the allocation worker build a Cesium engine on their mock viewers and
destroy it with them; frame allocation is unchanged.
This commit is contained in:
German Khokhlov committed 2026-10-15 18:53:57 +04:00
1 parent 3e3aa0bd9f
commit 12c9651a67
10 files changed
+145 -105

No files matched your search

+8 -16
View File
@@ -1,12 +1,10 @@
// The bridge for shell callers that still hold only a Cesium viewer (layers
// until phase 1c, standalone entries, tests): the engine of that viewer. The
// app registers its scene engine (src/app/globeEngine.js); any other viewer
// gets one built on first use and cached. Building one changes nothing in
// the viewer, and it is never destroyed here: its subscriptions live only as
// long as their callers keep them.
// until phase 1c): the engine registered for that viewer. The app registers
// its scene engine (src/app/globeEngine.js) and unregisters it before
// destroying it. Nothing is ever built here, so no engine can outlive its
// viewer without a destroy path: an unregistered or torn-down viewer has none.
import { isGlobeEngine } from '../contract.js';
import { createCesiumEngine } from './createCesiumEngine.js';
const engines = new WeakMap();
@@ -24,17 +22,11 @@ export function registerViewerEngine(viewer, engine) {
/**
* @param {object | null | undefined} viewer A Cesium viewer, or an engine
* (returned as is).
* @param {Parameters<typeof createCesiumEngine>[1]} [options] Used only when
* an engine has to be built.
* @returns {import('../contract.js').GlobeEngine | null}
* @returns {import('../contract.js').GlobeEngine | null} The registered
* engine, or null.
*/
export function engineFromViewer(viewer, options) {
export function engineFromViewer(viewer) {
if (viewer == null) return null;
if (isGlobeEngine(viewer)) return viewer;
let engine = engines.get(viewer);
if (!engine) {
engine = createCesiumEngine(viewer, options);
engines.set(viewer, engine);
}
return engine;
return engines.get(viewer) ?? null;
}