//#region src/preview/RenderStats.ts
/**
* RenderStats collects performance data from the rendering system.
*
* Usage:
* ```typescript
* const stats = new RenderStats(adaptiveTracker);
*
* // In render loop (always call this)
* stats.recordFrame(renderTime, timestamp, isAtRest);
*
* // In display (only when visible)
* const data = stats.getStats(renderWidth, renderHeight, resolutionScale);
* ```
*/
var RenderStats = class {
	constructor(adaptiveTracker) {
		this.renderTimes = [];
		this.frameIntervals = [];
		this.lastFrameTime = 0;
		this.ROLLING_WINDOW_SIZE = 30;
		this.TARGET_FRAME_TIME_MS = 33.33;
		this.adaptiveTracker = adaptiveTracker;
	}
	/**
	* Record a completed frame render.
	* Call this from the render loop after each frame completes.
	*
	* @param renderTime - Time spent rendering this frame (ms)
	* @param timestamp - Current timestamp from performance.now() or rAF
	* @param isAtRest - Whether the system is at rest (not playing/scrubbing)
	*/
	recordFrame(renderTime, timestamp, isAtRest) {
		this.renderTimes.push(renderTime);
		if (this.renderTimes.length > this.ROLLING_WINDOW_SIZE) this.renderTimes.shift();
		if (this.lastFrameTime > 0) {
			const interval = timestamp - this.lastFrameTime;
			this.frameIntervals.push(interval);
			if (this.frameIntervals.length > this.ROLLING_WINDOW_SIZE) this.frameIntervals.shift();
		}
		this.lastFrameTime = timestamp;
		if (!isAtRest) this.adaptiveTracker.recordFrame(renderTime, timestamp);
	}
	/**
	* Get current statistics for display.
	*
	* @param renderWidth - Current render width in pixels
	* @param renderHeight - Current render height in pixels
	* @param resolutionScale - Current resolution scale (0-1), or null if not applicable
	* @returns Current playback statistics
	*/
	getStats(renderWidth, renderHeight, resolutionScale = null) {
		const avgRenderTime = this.renderTimes.length > 0 ? this.renderTimes.reduce((a, b) => a + b, 0) / this.renderTimes.length : null;
		const avgFrameInterval = this.frameIntervals.length > 0 ? this.frameIntervals.reduce((a, b) => a + b, 0) / this.frameIntervals.length : 16.67;
		const fps = avgFrameInterval > 0 ? 1e3 / avgFrameInterval : 0;
		const headroom = avgRenderTime !== null ? this.TARGET_FRAME_TIME_MS - avgRenderTime : null;
		const trackerStats = this.adaptiveTracker.getStats();
		return {
			fps,
			avgRenderTime,
			headroom,
			pressureState: trackerStats.pressureState,
			pressureHistory: trackerStats.pressureHistory,
			renderWidth,
			renderHeight,
			resolutionScale,
			samplesAtCurrentScale: trackerStats.samplesAtCurrentScale,
			canScaleUp: trackerStats.canScaleUp,
			canScaleDown: trackerStats.canScaleDown
		};
	}
	/**
	* Reset all collected statistics.
	* Useful when switching modes or starting a new session.
	*/
	reset() {
		this.renderTimes = [];
		this.frameIntervals = [];
		this.lastFrameTime = 0;
	}
};

//#endregion
export { RenderStats };
//# sourceMappingURL=RenderStats.js.map