UNPKG

@rpgjs/physic

Version:

A deterministic 2D top-down physics library for RPG, sandbox and MMO games

47 lines 1.62 kB
export interface PredictionState<DirectionType = unknown> { x: number; y: number; direction?: DirectionType; } export interface PredictionControllerConfig<DirectionType = unknown> { correctionThreshold?: number; historyTtlMs?: number; maxHistoryEntries?: number; getPhysicsTick: () => number; getCurrentState: () => PredictionState<DirectionType>; setAuthoritativeState: (state: PredictionState<DirectionType>) => void; } /** * Shared client-side prediction controller. * * Handles input history, pending server snapshots and reconciliation. */ export declare class PredictionController<DirectionType = unknown> { private readonly config; private readonly correctionThreshold; private readonly historyTtlMs; private readonly maxHistoryEntries; private frameCounter; private history; private pendingSnapshot; private lastAckFrame; private lastAckTick; constructor(config: PredictionControllerConfig<DirectionType>); recordInput(direction: DirectionType, timestamp: number): { frame: number; tick: number; }; attachPredictedState(frame: number, state: PredictionState<DirectionType>): void; hasPendingInputs(): boolean; queueServerSnapshot(snapshot: PredictionState<DirectionType>): void; tryApplyPendingSnapshot(): void; applyServerAck(ack: { frame: number; serverTick?: number; state?: PredictionState<DirectionType>; }): void; cleanup(now: number): void; private trimHistory; private applySnapshot; } //# sourceMappingURL=PredictionController.d.ts.map