import { EventBus } from '../core/EventBus';
export interface FrameBudgetConfig {
    /** Target frame time in ms (default: 16.67 → 60fps). */
    targetFrameMs: number;
    /** Budget allocation per subsystem (0-1, must sum to ≤ 1). */
    allocations: Record<string, number>;
    /** Warn if total frame time exceeds target by this factor (default: 1.5). */
    warningThreshold: number;
    /** Sample window for rolling averages (default: 60 frames). */
    sampleWindow: number;
}
export interface BudgetReport {
    subsystem: string;
    budgetMs: number;
    actualMs: number;
    overBudget: boolean;
    utilizationPercent: number;
}
export interface FrameBudgetSnapshot {
    frameNumber: number;
    totalMs: number;
    overBudget: boolean;
    subsystems: BudgetReport[];
}
export declare class FrameBudgetManager {
    readonly events: EventBus;
    private config;
    private currentFrame;
    private history;
    private frameCount;
    private startTimes;
    private rollingTotals;
    private rollingSubsystems;
    constructor(config?: Partial<FrameBudgetConfig>);
    /** Mark the start of a subsystem's work in this frame. */
    beginSubsystem(name: string): void;
    /** Mark the end of a subsystem's work in this frame. */
    endSubsystem(name: string): void;
    /** Complete the current frame, generate report, advance to next. */
    endFrame(): FrameBudgetSnapshot;
    /** Get the average frame time over the rolling window. */
    getAverageFrameMs(): number;
    /** Get average time for a specific subsystem. */
    getSubsystemAverageMs(name: string): number;
    /** Get latest snapshot. */
    getLatest(): FrameBudgetSnapshot | null;
    /** Get the worst-case frame in history. */
    getWorstFrame(): FrameBudgetSnapshot | null;
    /** Format a concise budget text report. */
    formatReport(): string;
    /** Reset all collected data. */
    reset(): void;
}
export interface MemoryTracker {
    category: string;
    count: number;
    peakCount: number;
    totalAllocated: number;
    totalFreed: number;
}
export interface MemorySnapshot {
    timestamp: number;
    trackers: Map<string, MemoryTracker>;
    totalActive: number;
    /** JS heap size in bytes (if available). */
    heapUsed: number | null;
    heapTotal: number | null;
}
export interface LeakSuspect {
    category: string;
    growthRate: number;
    currentCount: number;
    windowCount: number;
    severity: 'low' | 'medium' | 'high';
}
export declare class MemoryLeakDetector {
    readonly events: EventBus;
    private trackers;
    private snapshots;
    private maxSnapshots;
    private checkIntervalMs;
    private lastCheckTime;
    constructor(maxSnapshots?: number, checkIntervalMs?: number);
    /** Track an allocation (e.g., new entity, texture, sound). */
    trackAlloc(category: string, count?: number): void;
    /** Track a deallocation / free. */
    trackFree(category: string, count?: number): void;
    /** Take a snapshot of current allocations. */
    takeSnapshot(): MemorySnapshot;
    /** Call from game loop — takes periodic snapshots and checks for leaks. */
    update(): void;
    /** Analyze snapshots for continuous growth patterns. */
    detectLeaks(): LeakSuspect[];
    /** Get current tracker for a category. */
    getTracker(category: string): MemoryTracker | undefined;
    /** Get all trackers. */
    get allTrackers(): MemoryTracker[];
    /** Format a human-readable leak report. */
    formatReport(): string;
    /** Reset all tracking data. */
    reset(): void;
}
export type QualityLevel = 'ultra' | 'high' | 'medium' | 'low' | 'potato';
export interface AutoLODConfig {
    /** Target FPS (default: 60). */
    targetFps: number;
    /** FPS below which quality downgrades (default: 50). */
    downgradeThreshold: number;
    /** FPS above which quality upgrades (default: 58). */
    upgradeThreshold: number;
    /** Seconds of stable performance before upgrading (default: 5). */
    stabilityWindow: number;
    /** Minimum seconds between quality changes (default: 3). */
    cooldownSec: number;
}
export interface QualitySettings {
    level: QualityLevel;
    /** Render scale (0.5 = half res, 1.0 = native). */
    renderScale: number;
    /** Max draw distance. */
    drawDistance: number;
    /** Shadow quality (0 = off, 1-3 = low-high). */
    shadowQuality: number;
    /** Particle multiplier (0-1). */
    particleMultiplier: number;
    /** Post-processing enabled. */
    postProcessing: boolean;
    /** Physics simulation rate multiplier (0.5 = half, 1.0 = full). */
    physicsFidelity: number;
}
export declare const QUALITY_PRESETS: Record<QualityLevel, QualitySettings>;
export declare class AutoLODManager {
    readonly events: EventBus;
    private config;
    private currentLevel;
    private currentSettings;
    private fpsHistory;
    private lastChangeTime;
    private stableAboveSince;
    constructor(initialLevel?: QualityLevel, config?: Partial<AutoLODConfig>);
    get level(): QualityLevel;
    get settings(): Readonly<QualitySettings>;
    /** Call each frame with current FPS. */
    update(currentFps: number): void;
    private downgrade;
    private upgrade;
    /** Manually set quality level. */
    setLevel(level: QualityLevel, now?: number): void;
    /** Get a quality preset. */
    getPreset(level: QualityLevel): QualitySettings;
    private getAverageFps;
}
export type WorkerTaskStatus = 'pending' | 'running' | 'done' | 'error';
export interface WorkerTask<T = unknown> {
    id: number;
    type: string;
    data: unknown;
    status: WorkerTaskStatus;
    result: T | null;
    error: string | null;
    submittedAt: number;
    completedAt: number | null;
}
export interface WorkerPoolConfig {
    /** Number of worker threads (default: navigator.hardwareConcurrency - 1). */
    poolSize: number;
    /** Maximum queued tasks before rejecting (default: 100). */
    maxQueueSize: number;
}
/**
 * Abstract worker pool for offloading CPU-heavy tasks.
 * Concrete implementations provide the actual Worker script.
 */
export declare class WorkerPool {
    readonly events: EventBus;
    private workers;
    private busyWorkers;
    private taskQueue;
    private activeTasks;
    private nextTaskId;
    private config;
    private workerScriptUrl;
    constructor(workerScriptUrl: string, config?: Partial<WorkerPoolConfig>);
    /** Initialize the worker pool. */
    init(): void;
    /** Submit a task to the worker pool. Returns a promise resolved when done. */
    submit<T>(type: string, data: unknown): Promise<T>;
    private dispatchNext;
    private handleResult;
    private handleError;
    /** Number of idle workers. */
    get idleCount(): number;
    /** Number of queued tasks. */
    get queueSize(): number;
    /** Terminate all workers. */
    dispose(): void;
}
/** Simple high-resolution timer. */
export declare class PerfTimer {
    private marks;
    mark(name: string): void;
    measure(startMark: string, endMark?: string): number;
    clear(): void;
}
/** Object pool for reducing garbage collection pressure. */
export declare class ObjectPool<T> {
    private pool;
    private factory;
    private resetFn;
    readonly maxSize: number;
    constructor(factory: () => T, resetFn: (obj: T) => void, maxSize?: number);
    /** Get an object from the pool (or create a new one). */
    acquire(): T;
    /** Return an object to the pool after use. */
    release(obj: T): void;
    /** Pre-populate the pool. */
    prewarm(count: number): void;
    get available(): number;
    clear(): void;
}
