"use client"; import { useEffect, useState } from "react"; /** Self-contained rAF-based FPS counter — the engine exposes no perf API of its own. */ export default function StatsReadout() { const [fps, setFps] = useState(null); useEffect(() => { let frameCount = 0; let windowStart = performance.now(); let raf = 0; const tick = (now: number) => { frameCount += 1; const elapsed = now - windowStart; if (elapsed >= 500) { setFps(Math.round((frameCount * 1000) / elapsed)); frameCount = 0; windowStart = now; } raf = requestAnimationFrame(tick); }; raf = requestAnimationFrame(tick); return () => cancelAnimationFrame(raf); }, []); return (
FPS {fps ?? "--"}
); }