export interface Timers { set(callback: () => void, ms: number): unknown; clear(handle: unknown): void; now(): number; } export declare const browserTimers: Timers; /** * A rate gate for the draw: what `createGate` returns. * * @example * ```ts * import { createGate, type Gate } from "@johnmorrisdotca/chikyu-earth/realistic"; * * const gate: Gate = createGate(33, () => console.log("draw")); * gate.request(); * gate.drawn(); * gate.cancel(); * ``` */ export interface Gate { /** Ask for `fire` to run: now if the last run was `minMs` ago or more, else once, when that time has passed. */ request(): void; /** Like `request`, but every ask made in one task is one ask, made when the task ends: a time and a view set together are one draw. */ soon(): void; /** Forget a run that is waiting. */ cancel(): void; /** Change the least time between runs (a lower frame rate on a battery). */ setMinMs(minMs: number): void; /** * Tell the gate a draw has begun (call it first thing in the draw). From the first call, an ask made after a run and before the draw it asked for is dropped, since that draw reads the state as it is * when it runs and so shows the change too: two tiles that arrive a few milliseconds apart are one draw, not a draw and a second, empty one 33 ms later. A draw that does not come within `minMs` * (a hidden tab, a busy machine) no longer holds asks back. */ drawn(): void; } /** * A rate gate for the draw: asks that come faster than `minMs` apart become one, and the last ask is never lost, so a burst of changes costs one draw. * * @param minMs - The least time between two runs, in milliseconds. * @param fire - What to run. * @param timers - A clock and timers; the browser's by default (a test passes its own). * @returns The gate: `request()` to ask, `cancel()` to forget a waiting run, `setMinMs()` to change the pace. * * @example * ```ts * import { createGate } from "@johnmorrisdotca/chikyu-earth/realistic"; * * const gate = createGate(30, () => console.log("drawn")); * gate.request(); * gate.request(); * gate.request(); * gate.cancel(); * ``` */ export declare function createGate(minMs: number, fire: () => void, timers?: Timers): Gate; /** * The frame rate cap for this device: `maxFps` (30 by default), lower on a small device. * * @param maxFps - The most frames a second to allow. * @param device - `deviceMemory` in gigabytes and `hardwareConcurrency` in cores, from `navigator`; either may be left out. * @returns The frames a second to allow, at least 1; 20 at most on a small device. * * @example * ```ts * import { frameCap } from "@johnmorrisdotca/chikyu-earth/realistic"; * * console.log(frameCap(), frameCap(30, { deviceMemory: 1 })); * ``` */ export declare function frameCap(maxFps?: number, device?: { deviceMemory?: number; hardwareConcurrency?: number; }): number;