mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Move the engine switch protocol from the layers into the scene binding
attachRenderer takes one context { engine, signal, viewRestored, ... } and
bindCatalog no longer takes a viewer; no layer module receives Cesium's
viewer any more, and a rehearsal check fails if one reads it.
The handoff between engines is one typed object (layers, camera owners,
selection, director) created when the old scene leaves, replacing the
session's handoffLayers, restoringView and selectionContext. viewRestored
resolves where the camera is restored, and the nine layers that kept
their own restoring-view flag wait on it instead. After attach the
binding applies a disabled layer's visibility, registers the picks each
module declares, and resumes the camera owners, so engineSwitch.js no
longer names directions or satellites.
This commit is contained in:
1 parent
a90407d547
commit
a2905eb700
104 files changed
+1029
-537
No files matched your search
@@ -39,6 +39,7 @@ function fixture({ failResume = false, changeTarget = false } = {}) {
|
||||
session.manager = {
|
||||
layers: new Map([['flights', entry]]),
|
||||
isEffectivelyEnabled: () => true,
|
||||
resumeScene: () => entry.module.resumeViewport(),
|
||||
};
|
||||
session.director = {
|
||||
suspendScene: () => log.push('suspend-director'),
|
||||
@@ -96,8 +97,8 @@ test('a scene switch parks once, resumes the session and cockpit, then returns n
|
||||
const { switcher, session, log, current } = fixture();
|
||||
await switcher.select('navara');
|
||||
assert.equal(current(), 'navara');
|
||||
assert.equal(session.handoffLayers, null);
|
||||
assert.equal(session.restoringView, false);
|
||||
assert.equal(session.handoff, null);
|
||||
await session.viewRestored;
|
||||
assert.deepEqual(log, [
|
||||
'suspend-director',
|
||||
['park', 'first'],
|
||||
@@ -125,7 +126,7 @@ test('resume failure has one candidate release and one rollback on the retained
|
||||
['attach', 'first'],
|
||||
['failure', 'resume failed', true],
|
||||
]);
|
||||
assert.equal(session.handoffLayers, null);
|
||||
assert.equal(session.handoff, null);
|
||||
assert.equal(switcher.state().busy, false);
|
||||
});
|
||||
|
||||
@@ -135,3 +136,101 @@ test('a changed tracking target does not resume the outgoing cockpit', async ()
|
||||
assert.equal(log.includes('cockpit'), false);
|
||||
assert.equal(log.includes('ir'), false);
|
||||
});
|
||||
|
||||
test('the restored camera precedes retained follow and replay', async () => {
|
||||
const { LayerLifecycle } = await import('../data/lifecycle.js');
|
||||
const session = createLayerSession();
|
||||
const log = [];
|
||||
let restoreCamera;
|
||||
const restored = new Promise((resolve) => {
|
||||
restoreCamera = resolve;
|
||||
});
|
||||
const layers = ['follow', 'replay'].map((id) => ({
|
||||
id,
|
||||
name: id,
|
||||
icon: '',
|
||||
source: 'test',
|
||||
init() {},
|
||||
enable() {},
|
||||
disable() {},
|
||||
update() {},
|
||||
destroy() {},
|
||||
attachRenderer() {
|
||||
log.push(`attach:${id}`);
|
||||
},
|
||||
detachRenderer() {},
|
||||
cameraOwner: {
|
||||
suspend() {
|
||||
log.push(`suspend:${id}`);
|
||||
},
|
||||
resume() {
|
||||
log.push(`resume:${id}`);
|
||||
},
|
||||
},
|
||||
}));
|
||||
const catalog = {
|
||||
layers,
|
||||
metadata: layers.map(({ id }) => ({
|
||||
id,
|
||||
token: id,
|
||||
disposition: 'enabled-only',
|
||||
})),
|
||||
};
|
||||
const manager = new LayerLifecycle(null);
|
||||
session.manager = manager;
|
||||
await manager.bindCatalog({ kind: 'first' }, catalog);
|
||||
for (const layer of layers) await manager.setEnabled(layer.id, true);
|
||||
let current = 'first';
|
||||
let attached;
|
||||
const attachment = new Promise((resolve) => {
|
||||
attached = resolve;
|
||||
});
|
||||
const style = {
|
||||
initialRestorePromise: restored,
|
||||
getCockpitState: () => null,
|
||||
getAircraftTrackingTarget: () => null,
|
||||
};
|
||||
const app = {
|
||||
getState: () => ({ status: 'ready' }),
|
||||
getComponents: () => ({
|
||||
scene: { engine: { kind: current } },
|
||||
controls: { styleManager: style },
|
||||
}),
|
||||
async detachScene() {
|
||||
await manager.detachScene();
|
||||
},
|
||||
async attachScene(kind, { resume }) {
|
||||
current = kind;
|
||||
await manager.bindCatalog({ kind }, catalog, {
|
||||
viewRestored: session.viewRestored,
|
||||
});
|
||||
attached();
|
||||
await resume();
|
||||
},
|
||||
};
|
||||
const switcher = createSceneSwitcher({
|
||||
kind: 'first',
|
||||
requested: () => current,
|
||||
layerSession: session,
|
||||
getApplication: () => app,
|
||||
renderers: { retain() {} },
|
||||
address: { select() {}, commit() {}, restore() {} },
|
||||
});
|
||||
const switching = switcher.select('navara');
|
||||
await attachment;
|
||||
assert.deepEqual(log, [
|
||||
'suspend:follow',
|
||||
'suspend:replay',
|
||||
'attach:follow',
|
||||
'attach:replay',
|
||||
]);
|
||||
log.push('camera-restored');
|
||||
restoreCamera();
|
||||
await switching;
|
||||
assert.deepEqual(log.slice(-3), [
|
||||
'camera-restored',
|
||||
'resume:follow',
|
||||
'resume:replay',
|
||||
]);
|
||||
await manager.destroyAll();
|
||||
});
|
||||
Reference in new issue
Block a user