mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Define the renderer contract, with a stub renderer and a conformance suite
The renderer contract is what the application asks of a 3D renderer. It is nine ports (frame, globe, draw, camera, query, input, effects, credits, quality) plus the renderer itself, one strict .d.ts per port in src/render/contract/. PORTS lists every member at run time, and a TypeScript-compiler test fails when the list and the types disagree on one member. An optional member exists only with its capability; a required one answers null or empty without it. Nothing in the application uses the contract yet. The stub renderer (src/render/stub/) implements every port in memory and draws nothing. Its camera is a port of the default camera's maths: views, lookAt, flights with their height arc and easing, rectangle framing on the geodesic midpoint, the view rectangle with its horizon and pole cases, changed thresholds, follows, and flights that finish inside the call. The conformance suite (src/render/conformance/) runs 59 checks against a renderer through the contract alone, in Node or in a browser page. The camera checks compare traces recorded from Cesium's own Camera, headless on a virtual clock (scripts/record-camera-goldens.mjs), to 1 mm, 1e-9 and 1e-3 px. The other checks cover listener rules on every subscription, the frame loop, draw sets, picks, motion clocks, heights, leases, imagery, styles, credits and quality knobs. The stub passes all of them but the model check, which needs a glTF asset. Reference scenes draw one scene per primitive family, a city and a calibration path from orbit to the street, from contract calls only and with no network. /dev/conformance/ draws them on the Cesium scene renderer (src/render/cesium/sceneRenderer.js), records references through a dev-server-only, loopback-only endpoint, and compares captures with pixelmatch's antialias detection plus a solid-pixel count. Measured on Cesium: every MSAA setting passes, and a dropped 4 px point, a dropped 2 px line and a 1 px shift of the view fail. visual.js states the limits. The package exports ./render/contract, ./render/stub and ./render/conformance. Documented in docs/RENDERER-CONTRACT.md, docs/CODE-BOUNDARIES.md and docs/CURRENT-STATE.md.
This commit is contained in:
1 parent
464c29a9ed
commit
8db995acfc
65 files changed
+12759
-9
No files matched your search
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* The frame loop, render on demand and scene time.
|
||||
*
|
||||
* A renderer draws on demand: a frame is drawn when something asks for one
|
||||
* (`requestRender`), while any continuous hold is out, or every frame on an
|
||||
* engine that cannot idle (it then reports `mode()` as `'continuous'`).
|
||||
*
|
||||
* One frame runs in this order, and the renderer keeps it:
|
||||
* camera flight → input → camera `changed` → follow → `preUpdate` →
|
||||
* move detection (`moveStart` / `moveEnd`) → `preRender` → render →
|
||||
* `postRender`. `preUpdate` fires on every frame the loop ticks, including
|
||||
* frames that end up drawing nothing, so owners that write the camera there
|
||||
* (a cockpit, a follow clamp) see each one.
|
||||
*/
|
||||
import type { Off, Release } from './common';
|
||||
|
||||
export type FramePhase = 'preUpdate' | 'preRender' | 'postRender';
|
||||
|
||||
/** The order the phases (and the steps between them) run in one frame. */
|
||||
export type FrameStep =
|
||||
| 'flight'
|
||||
| 'input'
|
||||
| 'changed'
|
||||
| 'follow'
|
||||
| 'preUpdate'
|
||||
| 'moveDetection'
|
||||
| 'preRender'
|
||||
| 'render'
|
||||
| 'postRender';
|
||||
|
||||
export interface FrameTime {
|
||||
/** Frames ticked since creation. */
|
||||
frame: number;
|
||||
/** Scene time, epoch ms: what sun, stars and lighting show. */
|
||||
time: number;
|
||||
/** The loop's clock, ms (virtual under a test clock). */
|
||||
now: number;
|
||||
/** Seconds since the previous tick. */
|
||||
dt: number;
|
||||
/** Whether this tick draws. */
|
||||
rendering: boolean;
|
||||
}
|
||||
|
||||
export interface FrameDiagnostics {
|
||||
mode: 'demand' | 'continuous';
|
||||
frames: number;
|
||||
rendered: number;
|
||||
/** Reasons given to `requestRender` since the last frame drawn. */
|
||||
pendingReasons: string[];
|
||||
/** Reasons of the holds now out. */
|
||||
holds: string[];
|
||||
suspended: boolean;
|
||||
targetFps: number;
|
||||
}
|
||||
|
||||
export interface FramePort {
|
||||
on(phase: FramePhase, cb: (t: FrameTime) => void): Off;
|
||||
/** Ask for one frame. The reason shows in diagnostics and signals. */
|
||||
requestRender(reason: string): void;
|
||||
/** Keep drawing every frame until released. Holds are counted. */
|
||||
holdContinuous(reason: string): Release;
|
||||
mode(): 'demand' | 'continuous';
|
||||
diagnostics(): FrameDiagnostics;
|
||||
/** Stop ticking while the page is hidden; resume on `false`. */
|
||||
suspend(hidden: boolean): void;
|
||||
/** Draw a frame now, synchronously. */
|
||||
renderNow(): void;
|
||||
/** Resolves after the next frame has been drawn and presented. */
|
||||
renderOnce(options?: { timeoutMs?: number }): Promise<void>;
|
||||
/** Cap the loop's rate; 0 is the display's rate. */
|
||||
setTargetFps(fps: number): void;
|
||||
/** Set scene time, epoch ms. */
|
||||
setTime(ms: number): void;
|
||||
/** Scene time, epoch ms. */
|
||||
time(): number;
|
||||
}
|
||||
Reference in new issue
Block a user