mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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:
1 parent
3e3aa0bd9f
commit
12c9651a67
10 files changed
+145
-105
No files matched your search
Vendored
+3
-1
@@ -5,7 +5,7 @@ import { initCockpitCloudEffects } from '../cockpitCloudEffects.js';
|
||||
|
||||
/** Construct the existing controls and camera presentation. */
|
||||
export function createApplicationControls({
|
||||
scene: { viewer, mapStackController, operations },
|
||||
scene: { viewer, engine, mapStackController, operations },
|
||||
loaderStatus,
|
||||
Controls = StyleManager,
|
||||
services,
|
||||
@@ -24,6 +24,8 @@ export function createApplicationControls({
|
||||
...catalogControlServices(catalog),
|
||||
},
|
||||
requestServices: operations.requests,
|
||||
// The page's globe engine: the shell's overlay host runs on it.
|
||||
engine,
|
||||
mapStackController,
|
||||
placeSearch,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
// controls.js and the shell import browser-only UI modules, so these read the
|
||||
// source: the scene engine is threaded to the shell, which hands it (not the
|
||||
// viewer) to the world overlay. initWorldOverlay itself is tested on the fake
|
||||
// engine without a viewer (src/overlays/worldOverlay.test.mjs).
|
||||
const read = (relative) =>
|
||||
readFileSync(new URL(relative, import.meta.url), 'utf8');
|
||||
|
||||
test('the controls pass the scene engine to the shell', () => {
|
||||
const controls = read('./controls.js');
|
||||
assert.match(controls, /scene: \{ viewer, engine, mapStackController, operations \}/);
|
||||
assert.match(controls, /new Controls\(viewer, \{[\s\S]*?\n\s+engine,\n/);
|
||||
});
|
||||
|
||||
test('the shell initializes the world overlay on its engine', () => {
|
||||
const shell = read('../ui/applicationShell.js');
|
||||
assert.match(shell, /\{\n\s+engine = null,\n\s+mapStackController = null,/);
|
||||
assert.match(shell, /initWorldOverlay\(engine\);/);
|
||||
assert.doesNotMatch(shell, /initWorldOverlay\(viewer\)/);
|
||||
});
|
||||
@@ -80,9 +80,9 @@ test('the scene engine is the one engineFromViewer returns for its viewer until
|
||||
assert.equal(engineFromViewer(viewer), engine);
|
||||
for (const cleanup of cleanups.reverse()) cleanup();
|
||||
assert.equal(engine.fake.destroyed, true);
|
||||
assert.throws(
|
||||
() => engineFromViewer(viewer),
|
||||
/createCesiumEngine needs a viewer/,
|
||||
'no longer registered: a fresh one would be built',
|
||||
assert.equal(
|
||||
engineFromViewer(viewer),
|
||||
null,
|
||||
'no longer registered, and none is built',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user