mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
Keep one world clock that every timed layer reads
Core told time eight ways: Date.now() in most layers, JulianDate.now() for flights and military, Cesium's clock frozen at page load for the sky, the weather clock for observed imagery. They now read one clock, src/time/worldClock.js, exported as ./time. Live is a mode, not a timestamp: while live the clock is the wall clock, so every layer draws as before. Away from live only the layers that follow the clock move with it. The weather products follow it, as they followed the weather transport; a host opts others in with follow(id). - The weather clock takes its time from the world clock and drives its replay, stepping its frames as before. - Satellites, launches, flights and military (still 30 s and 15 s behind), transit, GNSS, Recent Imagery, street level, the HUD and the celestial ring read worldTimeFor(id). Cadences stay on the wall clock. - Cesium's sky (stars, sun, moon, atmosphere, lighting) draws at the world time each frame instead of the moment the page loaded. - Weather frames and satellites declare coverage() for a host's timeline.
This commit is contained in:
1 parent
92bb1d6a89
commit
0c4da3cdb2
43 files changed
+1091
-75
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import * as Cesium from 'cesium';
|
||||
|
||||
/**
|
||||
* Draw Cesium's sky at the world time: the sun, moon, stars, atmosphere and
|
||||
* the lighting on the tiles all read `frameState.time`, which Cesium takes
|
||||
* from its own clock. That clock never animates in GEV, so before this the
|
||||
* sky stayed at the moment the page loaded.
|
||||
*
|
||||
* Each frame's time is set in `preUpdate`, before the scene stamps the frame
|
||||
* with it, so the sky is drawn at the same moment the layers read that frame.
|
||||
* The clock's `currentTime` follows too, for anything that samples it.
|
||||
* @param {Cesium.Viewer} viewer
|
||||
* @param {() => number} readTime Epoch ms the sky is drawn at.
|
||||
* @param {{subscribe?: Function, requestRender?: () => void}} [options]
|
||||
* A world clock to hear moves from, so a resting scene repaints when the
|
||||
* world time jumps.
|
||||
* @returns {() => void} Stop following.
|
||||
*/
|
||||
export function followWorldTime(
|
||||
viewer,
|
||||
readTime,
|
||||
{ subscribe, requestRender = () => viewer.scene.requestRender() } = {},
|
||||
) {
|
||||
const date = new Date();
|
||||
const removePreUpdate = viewer.scene.preUpdate.addEventListener(
|
||||
(_scene, time) => {
|
||||
date.setTime(readTime());
|
||||
const clock = viewer.clock;
|
||||
Cesium.JulianDate.fromDate(date, clock.currentTime);
|
||||
// The frame's own time: Cesium stamps the frame with this object next.
|
||||
if (time) Cesium.JulianDate.clone(clock.currentTime, time);
|
||||
},
|
||||
);
|
||||
let last = readTime();
|
||||
const unsubscribe =
|
||||
subscribe?.(() => {
|
||||
const next = readTime();
|
||||
if (next === last) return;
|
||||
last = next;
|
||||
requestRender();
|
||||
}) ?? (() => {});
|
||||
return () => {
|
||||
removePreUpdate();
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user