ecspresso
Version:
A minimal Entity-Component-System library for typescript and javascript.
48 lines (47 loc) • 2.1 kB
TypeScript
/**
* Diagnostics Plugin for ECSpresso
*
* Runtime diagnostics: FPS, entity count, per-system timing, per-phase timing,
* and an optional DOM overlay for visual debugging.
*/
import type { SystemPhase } from 'ecspresso';
export interface DiagnosticsData {
fps: number;
entityCount: number;
systemTimings: ReadonlyMap<string, number>;
phaseTimings: Readonly<Record<SystemPhase, number>>;
averageFrameTime: number;
}
export interface DiagnosticsResourceTypes {
diagnostics: DiagnosticsData;
}
export interface DiagnosticsPluginOptions<G extends string = 'diagnostics'> {
/** System group name (default: 'diagnostics') */
systemGroup?: G;
/** Enable timing collection on initialize (default: true) */
enableTimingOnInit?: boolean;
/** Number of frames to sample for FPS average (default: 60) */
fpsSampleCount?: number;
}
export interface DiagnosticsOverlayOptions {
/** Corner position (default: 'top-left') */
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
/** Milliseconds between DOM updates (default: 200) */
updateInterval?: number;
/** Show per-system timings (default: true) */
showSystemTimings?: boolean;
/** Maximum systems to show in overlay (default: 10) */
maxSystemsShown?: number;
}
export declare function createDiagnosticsPlugin<G extends string = 'diagnostics'>(options?: DiagnosticsPluginOptions<G>): import("ecspresso").Plugin<import("ecspresso").WithResources<import("ecspresso").EmptyConfig, DiagnosticsResourceTypes>, import("ecspresso").EmptyConfig, "diagnostics-collect", G, never, never>;
/**
* Create a DOM overlay that displays diagnostics data.
* Returns a cleanup function that removes the element and clears the interval.
*
* @param ecs An ECSpresso instance with the diagnostics resource
* @param options Overlay configuration
* @returns Cleanup function
*/
export declare function createDiagnosticsOverlay<R extends DiagnosticsResourceTypes>(ecs: {
getResource<K extends keyof R>(key: K): R[K];
}, options?: DiagnosticsOverlayOptions): () => void;