mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Separate scene handoff and attachment from the page shell
Move the page handoff sequence into SceneSwitcher and include restoration in the application's candidate attachment. Release a failed candidate once before the request coordinator recovers the working engine. Keep address ordering, parked renderers, retained layers and cockpit resumption intact. Define the layer session and its field owners. Share its retention decision across teardown paths. Separate layer scene binding from lifecycle policy, and shell scene composition from page controls. Keep failed renderer releases in the binding owner, with the existing retry behavior. Give Director the scene and use the engine host for its canvas and pack container. Keep the existing tracked-subject interaction guard so neither engine's behavior changes. Pass startup chrome the first backend's explicit welcome policy instead of testing for a viewer. Cesium remains the behavior reference; this restructuring intentionally changes no visible behavior on either engine. Viewer references outside the Cesium engine fall from 948 to 933. All other coupling counts stay unchanged. Scene service ownership, raw debug access, and the remaining shell and host queues still need consolidation. Checked in the browser, keyless, on the dev server: the engine switch, Director engine switch, layer panel and layer visibility on both engines pass, and 14 of 15 strict scenarios pass (rapid, hidden-tab, context-loss, parked-release, Navara HD, failure matrix and soak among them). app-once and the Director next-shot step fail the same way before this change.
This commit is contained in:
1 parent
f385986383
commit
656943641c
23 files changed
+1265
-888
No files matched your search
+15
-123
@@ -4,14 +4,10 @@ import {
|
||||
} from './standalone/application.js';
|
||||
import { createRendererCache } from './standalone/rendererCache.js';
|
||||
import { describeError } from './standalone/errors.js';
|
||||
import {
|
||||
createEngineAddress,
|
||||
createEngineSwitch,
|
||||
handOffSession,
|
||||
resumeSession,
|
||||
waitForFirstFrame,
|
||||
} from './standalone/engineSwitch.js';
|
||||
import { createEngineAddress } from './standalone/engineSwitch.js';
|
||||
import { ENGINE_STORAGE_KEY, engineOfChoice } from './app/engineChoice.js';
|
||||
import { createSceneSwitcher } from './standalone/sceneSwitcher.js';
|
||||
import { createLayerSession } from './app/layerSession.js';
|
||||
import { createSessionDiagnostics } from './app/sessionDiagnostics.js';
|
||||
import { useDisplayStore } from './ui/stores/display.js';
|
||||
import { applicationPinia } from './ui/vueRuntime.js';
|
||||
@@ -31,8 +27,6 @@ const display = useDisplayStore(applicationPinia());
|
||||
const loading = document.getElementById('loading-screen');
|
||||
let application;
|
||||
let engineSwitch = null;
|
||||
let cover = null;
|
||||
let cockpit = null;
|
||||
// ?parkedMs= shortens how long a parked globe waits before it is released,
|
||||
// so a QA scenario can switch back to a released one.
|
||||
const renderers = createRendererCache({
|
||||
@@ -41,7 +35,7 @@ const renderers = createRendererCache({
|
||||
parkedMs:
|
||||
Number(new URLSearchParams(location.search).get('parkedMs')) || undefined,
|
||||
});
|
||||
const layerSession = { lifetime: new AbortController() };
|
||||
const layerSession = createLayerSession();
|
||||
const { signal } = layerSession.lifetime;
|
||||
// Which session objects this page holds now (scripts/qa-app-once.mjs).
|
||||
const session = createSessionDiagnostics(() => {
|
||||
@@ -113,115 +107,6 @@ function liveComponents() {
|
||||
// The page's application is created once; a switch detaches and attaches
|
||||
// only its engine-bound parts.
|
||||
|
||||
// Hand the session off and release the running engine. Its renderer is
|
||||
// parked for a later switch back.
|
||||
async function leave(from) {
|
||||
const components = liveComponents();
|
||||
const attached = Boolean(components);
|
||||
if (attached) {
|
||||
cover ??= keepGlobeFrame(components.scene.engine);
|
||||
cockpit = components.controls.styleManager.getCockpitState();
|
||||
handOffSession(layerSession, {
|
||||
addressLayerIds:
|
||||
components.controls.styleManager.shareLinkManager?.currentLayerState?.()
|
||||
?.enabledLayerIds,
|
||||
});
|
||||
renderers.retain(from);
|
||||
}
|
||||
if (attached) await application.detachScene({ handoff: true });
|
||||
session.count('detaches');
|
||||
}
|
||||
|
||||
// Start an engine on the retained session. Success means the engine runs
|
||||
// with the session attached and the address's view restored; its first frame
|
||||
// only decides when the cover goes (settle).
|
||||
async function enter(kind, { recovery = false } = {}) {
|
||||
if (!application || application.getState().status !== 'ready') {
|
||||
// The first engine never started: there is no application to attach to.
|
||||
return enterNewApplication(kind);
|
||||
}
|
||||
layerSession.restoringView = true;
|
||||
try {
|
||||
await application.attachScene(kind);
|
||||
signal.throwIfAborted();
|
||||
await resume(application.getComponents().controls.styleManager);
|
||||
if (recovery) session.count('rollbacks');
|
||||
} catch (error) {
|
||||
// pagehide owns the teardown once the lifetime is aborted. A failed
|
||||
// candidate is detached; the session stays for the working engine.
|
||||
if (!signal.aborted)
|
||||
await application
|
||||
.detachScene({ handoff: true })
|
||||
.catch((cleanupError) =>
|
||||
console.error('A failed globe could not be released:', cleanupError),
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// The session continues on the engine that attached: the view is restored,
|
||||
// parked work resumes and Cockpit re-enters on the aircraft it had.
|
||||
async function resume(style) {
|
||||
await style.initialRestorePromise;
|
||||
signal.throwIfAborted();
|
||||
layerSession.restoringView = false;
|
||||
session.count('attachments');
|
||||
resumeSession(layerSession);
|
||||
// Only resume the aircraft that actually survived the handoff. A history
|
||||
// entry may select a different subject, and a stale track may disappear.
|
||||
const target = style.getAircraftTrackingTarget();
|
||||
if (
|
||||
cockpit?.active &&
|
||||
target &&
|
||||
target?.id === cockpit.subject?.id &&
|
||||
target?.layerId === cockpit.subject?.layerId &&
|
||||
style.controlCockpit('enter').ok
|
||||
) {
|
||||
style.cockpitView.setVisionMode(cockpit.visionMode);
|
||||
}
|
||||
}
|
||||
|
||||
// A new application on the retained session, for a page whose first engine
|
||||
// never started.
|
||||
async function enterNewApplication(kind) {
|
||||
const app = createApplication(kind, true);
|
||||
try {
|
||||
const { controls } = await app.start();
|
||||
signal.throwIfAborted();
|
||||
await resume(controls.styleManager);
|
||||
} catch (error) {
|
||||
// pagehide owns the teardown once the lifetime is aborted.
|
||||
if (!signal.aborted)
|
||||
await app
|
||||
.destroy()
|
||||
.catch((cleanupError) =>
|
||||
console.error('A failed globe could not be released:', cleanupError),
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function settle() {
|
||||
const components = liveComponents();
|
||||
try {
|
||||
if (cover && components) await waitForFirstFrame(components.scene.engine);
|
||||
} finally {
|
||||
cover?.remove();
|
||||
cover = null;
|
||||
}
|
||||
// A page left without an engine keeps the last handoff for the next try.
|
||||
if (!components) return;
|
||||
layerSession.handoffLayers = null;
|
||||
cockpit = null;
|
||||
withdrawEngineRetry();
|
||||
// An engine runs again after a failed recovery showed its error: the
|
||||
// application, built once, does not start its loading chrome again.
|
||||
loading.classList.add('hidden');
|
||||
// The running engine owns the address again, including an entry visited
|
||||
// before its share link listened or while it was held.
|
||||
components.controls.styleManager.shareLinkManager?.resumeNavigation?.();
|
||||
}
|
||||
|
||||
// Voice calls made while the engines switch wait for the next engine
|
||||
// (src/voice/sceneRunner.js); a settled switch lets them look again.
|
||||
layerSession.switching = () => engineSwitch?.state().busy === true;
|
||||
@@ -296,13 +181,20 @@ createApplication(initialKind, false)
|
||||
.start()
|
||||
.then(() => {
|
||||
session.count('attachments');
|
||||
engineSwitch = createEngineSwitch({
|
||||
engineSwitch = createSceneSwitcher({
|
||||
kind: initialKind,
|
||||
requested: pageEngineKind,
|
||||
signal,
|
||||
leave,
|
||||
enter,
|
||||
settle,
|
||||
getApplication: () => application,
|
||||
startApplication: (kind) => createApplication(kind, true),
|
||||
layerSession,
|
||||
renderers,
|
||||
diagnostics: session,
|
||||
keepFrame: keepGlobeFrame,
|
||||
onSettled() {
|
||||
withdrawEngineRetry();
|
||||
loading.classList.add('hidden');
|
||||
},
|
||||
address: createEngineAddress({
|
||||
location,
|
||||
history,
|
||||
|
||||
Reference in new issue
Block a user