render: hold continuous render while the world clock plays away from live

Playback moves something every frame, so it draws at the display's rate
rather than the parked scene's 60 FPS cap. followWorldTime reports when the
clock starts and stops playing (not live, not stepped, not waiting for data).
This commit is contained in:
Sameh Khamis committed 2026-11-15 13:35:11 -08:00
1 parent cb3be34283
commit 8af8c086a6
3 files changed
+90 -4

No files matched your search

+23 -4
View File
@@ -11,16 +11,29 @@ import * as Cesium from 'cesium';
* 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]
* @param {{subscribe?: Function, requestRender?: () => void,
* onPlaying?: (playing: boolean) => void}} [options]
* A world clock to hear moves from, so a resting scene repaints when the
* world time jumps.
* world time jumps. `onPlaying` hears when the world clock starts and stops
* playing away from live (not stepped by a driver and not waiting for a
* layer's data), so the scene can draw every frame meanwhile.
* @returns {() => void} Stop following.
*/
export function followWorldTime(
viewer,
readTime,
{ subscribe, requestRender = () => viewer.scene.requestRender() } = {},
{
subscribe,
requestRender = () => viewer.scene.requestRender(),
onPlaying = () => {},
} = {},
) {
let playing = false;
const setPlaying = (next) => {
if (next === playing) return;
playing = next;
onPlaying(next);
};
const date = new Date();
const removePreUpdate = viewer.scene.preUpdate.addEventListener(
(_scene, time) => {
@@ -33,7 +46,12 @@ export function followWorldTime(
);
let last = readTime();
const unsubscribe =
subscribe?.(() => {
subscribe?.((state) => {
setPlaying(
Boolean(
state?.playing && !state.live && !state.stepping && !state.buffering,
),
);
const next = readTime();
if (next === last) return;
last = next;
@@ -42,5 +60,6 @@ export function followWorldTime(
return () => {
removePreUpdate();
unsubscribe();
setPlaying(false);
};
}