UNPKG

@hiddentao/clockwork-engine

Version:

A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering

77 lines 2.38 kB
import type { IGameLoop } from "./IGameLoop"; interface TimerCallback { id: number; callback: () => void; targetTick: number; interval?: number; isActive: boolean; } export declare class Timer implements IGameLoop { protected timers: Map<number, TimerCallback>; protected nextId: number; protected currentTick: number; protected updateStartTick: number; protected isUpdating: boolean; /** * Schedule a one-time callback to execute after the specified number of ticks * @param callback Callback to execute * @param ticks Number of ticks to wait before execution * @returns Timer ID that can be used to cancel the timer */ setTimeout(callback: () => void, ticks: number): number; /** * Schedule a repeating callback to execute every specified number of ticks * @param callback Callback to execute * @param ticks Number of ticks between executions * @returns Timer ID that can be used to cancel the timer */ setInterval(callback: () => void, ticks: number): number; /** * Cancel a timer * @param id Timer ID returned from setTimeout or setInterval * @returns True if timer was found and cancelled */ clearTimer(id: number): boolean; /** * Update the timer system - called by GameEngine * Executes all ready timers with proper error handling */ update(_deltaTicks: number, totalTicks: number): void; /** * Reset the timer system * Clears all timers and resets the tick counter */ reset(): void; /** * Get the number of active timers */ getActiveTimerCount(): number; /** * Get information about all active timers */ getTimerInfo(): Array<{ id: number; targetTick: number; ticksRemaining: number; isRepeating: boolean; isActive: boolean; }>; /** * Pause a specific timer * @param id Timer ID * @returns True if timer was found and paused */ pauseTimer(id: number): boolean; /** * Resume a paused timer * @param id Timer ID * @returns True if timer was found and resumed */ resumeTimer(id: number): boolean; /** * Get the total number of timers (including inactive ones) */ getTotalTimerCount(): number; } export {}; //# sourceMappingURL=Timer.d.ts.map