mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
Launches and satellites leave the world clock when destroyed
Both layers registered their time coverage with the page's world clock when created and never unregistered it, so an application destroyed and started again kept each old layer, and its scene and tiles, reachable through the clock. They now unregister on destroy and register again on init, as earthquakes do.
This commit is contained in:
1 parent
9239d3efff
commit
ee306a46fc
3 files changed
+42
-4
No files matched your search
@@ -163,7 +163,7 @@ export function createLifecycle({
|
||||
// has none), cut short and in capitals as the mission index shows names.
|
||||
// Registered once; off, the layer has no time to show, and each step tells
|
||||
// the clock once it has settled.
|
||||
worldClock.register({
|
||||
const clockSource = {
|
||||
id: 'rocket-launches',
|
||||
coverage: () => {
|
||||
if (!layerState._enabled) return null;
|
||||
@@ -184,11 +184,15 @@ export function createLifecycle({
|
||||
if (!marks.length) return null;
|
||||
return { start: marks[0].time, end: marks.at(-1).time, marks };
|
||||
},
|
||||
});
|
||||
};
|
||||
// Unregistered on destroy, so a page that builds the app again holds no old layer; init
|
||||
// registers it again.
|
||||
let uncover = worldClock.register(clockSource);
|
||||
|
||||
const methods = {
|
||||
init(viewer) {
|
||||
layerState._viewer = viewer;
|
||||
uncover ??= worldClock.register(clockSource);
|
||||
layerState._enabled = false;
|
||||
parts.panel.createMissionPanel();
|
||||
parts.overlays.createReplayVehicleOverlay();
|
||||
@@ -324,6 +328,8 @@ export function createLifecycle({
|
||||
|
||||
async destroy(viewer) {
|
||||
hover?.destroy();
|
||||
uncover?.();
|
||||
uncover = null;
|
||||
hover = null;
|
||||
layerState._sourceController.abort();
|
||||
releaseContinuousRender('rocket-launches'); // direct-destroy path (perf wave 2 fix)
|
||||
|
||||
@@ -16,7 +16,7 @@ export function createLifecycle({
|
||||
// While on with a catalog, satellites can be shown at any time in reach of
|
||||
// their element sets. Registered once; off, the layer has no time to show,
|
||||
// and each step tells the clock once it has settled.
|
||||
worldClock.register({
|
||||
const clockSource = {
|
||||
id: 'satellites',
|
||||
coverage: () => {
|
||||
if (!layerState._enabled || !layerState._catalog.size) return null;
|
||||
@@ -26,7 +26,10 @@ export function createLifecycle({
|
||||
end: now + SATELLITE_COVERAGE_MS,
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
// Unregistered on destroy, so a page that builds the app again holds no old layer; init
|
||||
// registers it again.
|
||||
let uncover = worldClock.register(clockSource);
|
||||
const { holdContinuousRender, releaseContinuousRender } = services.render;
|
||||
const { registerPickOwner, unregisterPickOwner } = services.picking;
|
||||
|
||||
@@ -39,6 +42,7 @@ export function createLifecycle({
|
||||
// Catalog data refresh; propagation remains preRender-owned.
|
||||
|
||||
async init(viewer) {
|
||||
uncover ??= worldClock.register(clockSource);
|
||||
// Asked first: a viewer without one fails before anything is built.
|
||||
const frame = frameOf(viewer);
|
||||
parts.catalog._abortActiveUpdates();
|
||||
@@ -154,6 +158,8 @@ export function createLifecycle({
|
||||
|
||||
destroy(viewer) {
|
||||
parts.catalog._abortActiveUpdates();
|
||||
uncover?.();
|
||||
uncover = null;
|
||||
releaseContinuousRender('satellites'); // direct-destroy path (perf wave 2 fix)
|
||||
layerState._enabled = false;
|
||||
parts.tracking._clearTracking();
|
||||
|
||||
@@ -5,6 +5,7 @@ import http from 'node:http';
|
||||
import { EventEmitter, once } from 'node:events';
|
||||
import test from 'node:test';
|
||||
import * as Cesium from 'cesium';
|
||||
import { worldClock } from '../../time/worldClock.js';
|
||||
import { createSatelliteSource } from './source.js';
|
||||
import { createState } from './state.js';
|
||||
import { createControls } from './controls.js';
|
||||
@@ -309,3 +310,28 @@ test('destroy aborts an in-flight response and initialization starts with new ow
|
||||
assert.equal(f.stats().count, CORE.length);
|
||||
assert.equal(f.feed(), 'nominal');
|
||||
});
|
||||
|
||||
test('destroy takes the layer off the world clock, and init puts it back', async (t) => {
|
||||
// Each registration the layer makes, while it stands.
|
||||
const register = worldClock.register;
|
||||
const standing = new Set();
|
||||
worldClock.register = (source) => {
|
||||
standing.add(source);
|
||||
const off = register.call(worldClock, source);
|
||||
return () => {
|
||||
standing.delete(source);
|
||||
off();
|
||||
};
|
||||
};
|
||||
t.after(() => {
|
||||
worldClock.register = register;
|
||||
});
|
||||
const f = await fixture(t);
|
||||
const mine = () =>
|
||||
[...standing].filter(({ id }) => id === 'satellites').length;
|
||||
assert.equal(mine(), 1);
|
||||
f.parts.lifecycle.methods.destroy(f.viewer);
|
||||
assert.equal(mine(), 0);
|
||||
await f.parts.lifecycle.methods.init(f.viewer);
|
||||
assert.equal(mine(), 1);
|
||||
});
|
||||
Reference in new issue
Block a user