feat: rebuild the orbital vault as an operational map

This commit is contained in:
2026-11-09 22:01:14 +07:00
parent 2129e80c38
commit fba4a1e628
25 changed files with 1342 additions and 1333 deletions

View File

@@ -1,34 +1,25 @@
import { useEffect, useRef, useState } from "react";
import { useLayoutEffect } from "react";
/** Seconds since mount, frozen while paused. */
export function useGalaxyTime(paused: boolean): number {
const [t, setT] = useState(0);
const start = useRef(performance.now());
const frozen = useRef(0);
const wasPaused = useRef(paused);
useEffect(() => {
if (paused) {
frozen.current = (performance.now() - start.current) / 1000;
wasPaused.current = true;
return;
}
if (wasPaused.current) {
start.current = performance.now() - frozen.current * 1000;
wasPaused.current = false;
}
let raf = 0;
const tick = () => {
setT((performance.now() - start.current) / 1000);
raf = requestAnimationFrame(tick);
export function useGalaxyMotion(active: boolean, draw: (elapsed: number) => boolean) {
useLayoutEffect(() => {
let frame = 0;
let previous: number | undefined;
const tick = (now: number) => {
const keepDrawing = draw(previous === undefined ? 0 : (now - previous) / 1000);
previous = now;
if (keepDrawing) frame = requestAnimationFrame(tick);
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [paused]);
return paused ? frozen.current : t;
}
export function easeOutCubic(x: number): number {
return 1 - Math.pow(1 - x, 3);
const sync = () => {
cancelAnimationFrame(frame);
previous = undefined;
if (!document.hidden && active) frame = requestAnimationFrame(tick);
};
draw(0);
sync();
document.addEventListener("visibilitychange", sync);
return () => {
cancelAnimationFrame(frame);
document.removeEventListener("visibilitychange", sync);
};
}, [active, draw]);
}