mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Drag the timeline along, and play through it smoothly
The zoomed track now drags: the handle still drags the time, while the track around it drags the view along (or the time, with all of it shown), a tap goes to the time under it, two fingers pinch it, and a sideways swipe or a shift-wheel drags it too, the same with a mouse, a trackpad or a finger. A view dragged off the handle stays put until the time moves. Play moved in steps: the world clock told of its time four times a second, so the handle and the globe jumped, and play stopped at every weather frame while it drew, loaded ahead or not. The clock now tells of its time each animation frame, and play no longer waits on the frame it is at: that frame loads as play goes on, and play holds only at the next frame while the one before it still loads. Weather loads its next frame ahead while the world plays too, tells its listeners of frames as they change rather than every frame, and the sun and moon move on each minute of world time.
This commit is contained in:
1 parent
4fc9722356
commit
8eab6a76a8
20 files changed
+534
-137
No files matched your search
+24
-4
@@ -24,15 +24,21 @@ const MAX_DATE_MS = 8.64e15;
|
||||
export const isWorldTime = (ms) =>
|
||||
Number.isFinite(ms) && Math.abs(ms) <= MAX_DATE_MS;
|
||||
|
||||
/** How often subscribers hear of a continuously playing cursor. */
|
||||
/**
|
||||
* How often subscribers hear of a continuously playing cursor with no
|
||||
* animation frames to go by; with them, they hear of it every frame.
|
||||
*/
|
||||
export const WORLD_CLOCK_TICK_MS = 250;
|
||||
|
||||
/**
|
||||
* @param {{now?: () => number, monotonicNow?: () => number,
|
||||
* setInterval?: typeof globalThis.setInterval,
|
||||
* clearInterval?: typeof globalThis.clearInterval,
|
||||
* requestFrame?: typeof globalThis.requestAnimationFrame | null,
|
||||
* cancelFrame?: typeof globalThis.cancelAnimationFrame | null,
|
||||
* follow?: Iterable<string>}} [options] `follow` lists the layers that
|
||||
* move with the cursor from the start.
|
||||
* move with the cursor from the start. Playing, the clock tells its
|
||||
* listeners of the time each animation frame, or each tick without frames.
|
||||
*/
|
||||
export function createWorldClock({
|
||||
// Read at each call, so a stand-in for Date.now (a test's, a harness's)
|
||||
@@ -41,6 +47,8 @@ export function createWorldClock({
|
||||
monotonicNow = () => globalThis.performance.now(),
|
||||
setInterval = globalThis.setInterval,
|
||||
clearInterval = globalThis.clearInterval,
|
||||
requestFrame = globalThis.requestAnimationFrame?.bind(globalThis) ?? null,
|
||||
cancelFrame = globalThis.cancelAnimationFrame?.bind(globalThis) ?? null,
|
||||
follow = [],
|
||||
} = {}) {
|
||||
const listeners = new Set();
|
||||
@@ -128,11 +136,23 @@ export function createWorldClock({
|
||||
}
|
||||
}
|
||||
};
|
||||
// Playing, the time moves on smoothly: each frame, so the timeline and the
|
||||
// globe move with it and a layer's next frame is met as it comes, or each
|
||||
// tick where there are no frames.
|
||||
const frames = Boolean(requestFrame && cancelFrame);
|
||||
const frame = () => {
|
||||
ticker = requestFrame(frame);
|
||||
notify();
|
||||
};
|
||||
const syncTicker = () => {
|
||||
if (continuous() && listeners.size) {
|
||||
ticker ??= setInterval(notify, WORLD_CLOCK_TICK_MS);
|
||||
if (ticker === null)
|
||||
ticker = frames
|
||||
? requestFrame(frame)
|
||||
: setInterval(notify, WORLD_CLOCK_TICK_MS);
|
||||
} else if (ticker !== null) {
|
||||
clearInterval(ticker);
|
||||
if (frames) cancelFrame(ticker);
|
||||
else clearInterval(ticker);
|
||||
ticker = null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user