Merge main (663b56f62, #1755) into the renderer branch

This commit is contained in:
Sameh Khamis committed 2026-11-15 16:34:05 -08:00
commit a0d299523d
91 files changed
+1793 -396

No files matched your search

+19 -3
View File
@@ -10,9 +10,12 @@ import { findFrame } from '../render/rendererOf.js';
* moment the layers read that frame.
* @param {object} 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(
@@ -21,13 +24,25 @@ export function followWorldTime(
{
subscribe,
requestRender = () => findFrame(viewer)?.requestRender('world-time'),
onPlaying = () => {},
} = {},
) {
let playing = false;
const setPlaying = (next) => {
if (next === playing) return;
playing = next;
onPlaying(next);
};
const frame = findFrame(viewer);
const off = frame?.on('preUpdate', () => frame.setTime(readTime())) ?? null;
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;
@@ -36,5 +51,6 @@ export function followWorldTime(
return () => {
off?.();
unsubscribe();
setPlaying(false);
};
}