mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Show the timeline only while a layer with time to show is on
The bar now needs more than the world clock being away from live: a layer that moves with the clock must be on with time to show. In Core that is weather radar, satellite or lightning with frames; a host adds layers by following them. Turning the last one off hides the bar; turning it back on brings it back. The world clock reports this as `supported` in its state. Weather products register their frames as coverage one by one, suspended or not, so the way back to live stays on screen with reduced motion. Weather refreshes and satellite catalog changes tell the clock their coverage may have changed. A coverage that throws counts as none, and the clock reads its state once per notification round.
This commit is contained in:
1 parent
434fc9602d
commit
690a6637e2
12 files changed
+205
-25
No files matched your search
@@ -164,6 +164,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
|
||||
|
||||
layerState._count = layerState._points.size;
|
||||
layerState._catalogRevision++;
|
||||
layerState.coverageChanged();
|
||||
layerState._denseStatus = 'ready';
|
||||
console.log(
|
||||
`[Data:Satellites] Dense catalog: +${added} ${DENSE_GROUP_PATH} (points only)`,
|
||||
@@ -231,6 +232,7 @@ export function createCatalog({ state: layerState, services, parts, source }) {
|
||||
layerState._denseCursor = 0;
|
||||
layerState._count = layerState._points.size;
|
||||
layerState._catalogRevision++;
|
||||
layerState.coverageChanged();
|
||||
}
|
||||
return {
|
||||
_abortActiveUpdates,
|
||||
|
||||
@@ -170,6 +170,7 @@ export function createIngestion({
|
||||
layerState._coreStale = coreStale;
|
||||
layerState._count = layerState._points.size;
|
||||
layerState._catalogRevision++;
|
||||
layerState.coverageChanged();
|
||||
layerState._lastUpdate = Date.now();
|
||||
layerState._lastPropagation = Date.now();
|
||||
layerState._lastTrackingRefreshOutcome = {
|
||||
|
||||
@@ -33,6 +33,7 @@ function ingestionFor(catalogText) {
|
||||
_catalogRevision: 0,
|
||||
_params: { catalog: 'core', showOrbits: false },
|
||||
now: Date.now,
|
||||
coverageChanged() {},
|
||||
};
|
||||
const parts = {
|
||||
orbits: {
|
||||
|
||||
@@ -13,7 +13,8 @@ export function createLifecycle({
|
||||
// their element sets.
|
||||
let releaseCoverage = null;
|
||||
const coverWorldTime = () => {
|
||||
releaseCoverage ??= worldClock.register({
|
||||
if (releaseCoverage) return;
|
||||
const release = worldClock.register({
|
||||
id: 'satellites',
|
||||
coverage: () => {
|
||||
if (!layerState._catalog.size) return null;
|
||||
@@ -24,6 +25,10 @@ export function createLifecycle({
|
||||
};
|
||||
},
|
||||
});
|
||||
// Registering tells the world's listeners, which may turn the layer off
|
||||
// (or off and on, registering again) before this returns.
|
||||
if (layerState._enabled && !releaseCoverage) releaseCoverage = release;
|
||||
else release();
|
||||
};
|
||||
const uncoverWorldTime = () => {
|
||||
releaseCoverage?.();
|
||||
@@ -67,6 +72,7 @@ export function createLifecycle({
|
||||
layerState._denseStatus = 'idle';
|
||||
layerState._denseError = null;
|
||||
layerState._catalogRevision++;
|
||||
layerState.coverageChanged();
|
||||
|
||||
// Point primitives for satellite dots
|
||||
layerState._pointCollection = new Cesium.PointPrimitiveCollection();
|
||||
@@ -185,6 +191,7 @@ export function createLifecycle({
|
||||
layerState._denseStatus = 'idle';
|
||||
layerState._denseError = null;
|
||||
layerState._catalogRevision++;
|
||||
layerState.coverageChanged();
|
||||
layerState._rowControlsListener = null;
|
||||
layerState._count = 0;
|
||||
layerState._lastUpdate = null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import { worldTimeFor } from '../../time/worldClock.js';
|
||||
import { worldClock, worldTimeFor } from '../../time/worldClock.js';
|
||||
|
||||
export function createState({ services }) {
|
||||
const { setOverlayEntries, setOverlaySourceVisible, clearOverlaySource } =
|
||||
@@ -156,6 +156,10 @@ export function createState({ services }) {
|
||||
|
||||
state.now = worldTimeFor('satellites');
|
||||
|
||||
/** The catalog changed, so the time satellites can be shown at may have. */
|
||||
|
||||
state.coverageChanged = () => worldClock.coverageChanged();
|
||||
|
||||
// Scratch variables
|
||||
|
||||
state._scratchCartesian = new Cesium.Cartesian3();
|
||||
|
||||
+30
-12
@@ -162,7 +162,34 @@ export function createWeatherClock({
|
||||
throw new Error(`Duplicate weather product: ${product.id}`);
|
||||
const entry = { product, controller: null };
|
||||
registry.set(product.id, entry);
|
||||
releases.set(product.id, world.hold(product.id));
|
||||
// The product moves with the world clock, and its frames are time the
|
||||
// world clock's timeline can show while it is on, suspended or not, so
|
||||
// the way back to live stays on screen. Both calls notify the world's
|
||||
// listeners, which may destroy this clock: the release is in place
|
||||
// first, and anything acquired after a destroy is let go at once.
|
||||
let unhold = null;
|
||||
let uncover = null;
|
||||
const release = () => {
|
||||
uncover?.();
|
||||
unhold?.();
|
||||
uncover = unhold = null;
|
||||
};
|
||||
releases.set(product.id, release);
|
||||
unhold = world.hold(product.id);
|
||||
if (!destroyed)
|
||||
uncover = world.register({
|
||||
id: product.id,
|
||||
coverage: () => {
|
||||
const marks = timesFor(product).map((time) => Date.parse(time));
|
||||
return marks.length
|
||||
? { start: marks[0], end: marks.at(-1), marks }
|
||||
: null;
|
||||
},
|
||||
});
|
||||
if (destroyed) {
|
||||
release();
|
||||
return () => {};
|
||||
}
|
||||
void api.refresh();
|
||||
return () => {
|
||||
if (registry.get(product.id) !== entry) return;
|
||||
@@ -242,6 +269,8 @@ export function createWeatherClock({
|
||||
},
|
||||
refresh() {
|
||||
if (destroyed) return Promise.resolve(false);
|
||||
// New frames, or products added or dropped.
|
||||
world.coverageChanged();
|
||||
if (!canPlay()) {
|
||||
stopPlaying();
|
||||
cancelTimer();
|
||||
@@ -262,7 +291,6 @@ export function createWeatherClock({
|
||||
++generation;
|
||||
cancelTimer();
|
||||
unfollowWorld();
|
||||
uncover();
|
||||
// The last weather clock leaves the world live, as a new one expects.
|
||||
if (driver.detach() === 0) world.goLive();
|
||||
for (const release of releases.values()) release();
|
||||
@@ -292,16 +320,6 @@ export function createWeatherClock({
|
||||
else notify();
|
||||
}
|
||||
const unfollowWorld = world.subscribe(followWorld);
|
||||
// The observed frames this clock can show, for a host's timeline.
|
||||
const uncover = world.register({
|
||||
id: 'weather',
|
||||
coverage: () => {
|
||||
const marks = getTimeline().map((time) => Date.parse(time));
|
||||
return marks.length
|
||||
? { start: marks[0], end: marks.at(-1), marks }
|
||||
: null;
|
||||
},
|
||||
});
|
||||
driver = world.attachDriver({
|
||||
play: () => (canPlay() ? void api.play() : false),
|
||||
pause: () => api.pause(),
|
||||
|
||||
@@ -436,9 +436,10 @@ test('a target superseded from a listener resolves false', async (t) => {
|
||||
assert.equal(radar.shown, time(10));
|
||||
});
|
||||
|
||||
test('the observed frames are the world clock coverage, while registered', (t) => {
|
||||
test('each product’s frames are world clock coverage, and support the timeline while shown', (t) => {
|
||||
const { clock, world } = harness(t);
|
||||
assert.equal(world.coverage(), null);
|
||||
assert.equal(world.getState().supported, false);
|
||||
const radar = product('radar', [0, 10]);
|
||||
const unregister = clock.register(radar);
|
||||
clock.register(product('lightning', [5]));
|
||||
@@ -447,7 +448,48 @@ test('the observed frames are the world clock coverage, while registered', (t) =
|
||||
end: Date.parse(time(10)),
|
||||
marks: [0, 5, 10].map((m) => Date.parse(time(m))),
|
||||
});
|
||||
assert.equal(world.getState().supported, true);
|
||||
unregister();
|
||||
assert.deepEqual(world.coverage().marks, [Date.parse(time(5))]);
|
||||
clock.destroy();
|
||||
assert.equal(world.coverage(), null);
|
||||
assert.equal(world.getState().supported, false);
|
||||
});
|
||||
|
||||
test('a suspended product keeps its coverage, so the way back to live stays', (t) => {
|
||||
const { clock, world } = harness(t);
|
||||
const radar = product('radar', [0, 10]);
|
||||
clock.register(radar);
|
||||
radar.suspended = true;
|
||||
void clock.refresh();
|
||||
assert.equal(world.getState().supported, true);
|
||||
assert.deepEqual(
|
||||
world.coverage().marks,
|
||||
[0, 10].map((m) => Date.parse(time(m))),
|
||||
);
|
||||
});
|
||||
|
||||
test('new frames reach the world clock through refresh', (t) => {
|
||||
const { clock, world } = harness(t);
|
||||
const radar = product('radar', []);
|
||||
clock.register(radar);
|
||||
const supported = [];
|
||||
world.subscribe((state) => supported.push(state.supported));
|
||||
assert.equal(world.getState().supported, false);
|
||||
radar.times = [time(0)];
|
||||
void clock.refresh();
|
||||
assert.equal(supported.at(-1), true);
|
||||
});
|
||||
|
||||
test('a clock destroyed while it registers a product lets go of it', (t) => {
|
||||
const { clock, world } = harness(t);
|
||||
const off = world.subscribe(() => {
|
||||
off();
|
||||
clock.destroy();
|
||||
});
|
||||
const unregister = clock.register(product('radar', [0, 10]));
|
||||
unregister();
|
||||
assert.equal(world.follows('radar'), false);
|
||||
assert.equal(world.coverage(), null);
|
||||
assert.equal(world.getState().supported, false);
|
||||
});
|
||||
Reference in new issue
Block a user