Files
esengine/packages/framework/network/src/sync/IStateSnapshot.ts

139 lines
2.9 KiB
TypeScript
Raw Normal View History

/**
* @zh
* @en State Snapshot Interface
*
* @zh
* @en Provides state snapshot abstraction for network synchronization
*/
// =============================================================================
// 快照接口 | Snapshot Interface
// =============================================================================
/**
* @zh
* @en Timestamped state snapshot
*/
export interface IStateSnapshot<T> {
/**
* @zh
* @en Server timestamp in milliseconds
*/
readonly timestamp: number;
/**
* @zh
* @en State data
*/
readonly state: T;
}
/**
* @zh
* @en Transform state
*/
export interface ITransformState {
/**
* @zh X
* @en X coordinate
*/
x: number;
/**
* @zh Y
* @en Y coordinate
*/
y: number;
/**
* @zh
* @en Rotation angle in radians
*/
rotation: number;
}
/**
* @zh
* @en Transform state with velocity
*/
export interface ITransformStateWithVelocity extends ITransformState {
/**
* @zh X
* @en X velocity
*/
velocityX: number;
/**
* @zh Y
* @en Y velocity
*/
velocityY: number;
/**
* @zh
* @en Angular velocity
*/
angularVelocity: number;
}
// =============================================================================
// 快照缓冲区接口 | Snapshot Buffer Interface
// =============================================================================
/**
* @zh
* @en Snapshot buffer configuration
*/
export interface ISnapshotBufferConfig {
/**
* @zh
* @en Maximum buffer size
*/
maxSize: number;
/**
* @zh
* @en Interpolation delay in milliseconds
*/
interpolationDelay: number;
}
/**
* @zh
* @en Snapshot buffer interface
*/
export interface ISnapshotBuffer<T> {
/**
* @zh
* @en Add snapshot
*/
push(snapshot: IStateSnapshot<T>): void;
/**
* @zh
* @en Get two snapshots for interpolation
*
* @param renderTime - @zh @en Render time
* @returns @zh [, , ] null @en [previous, next, factor] or null
*/
getInterpolationSnapshots(renderTime: number): [IStateSnapshot<T>, IStateSnapshot<T>, number] | null;
/**
* @zh
* @en Get latest snapshot
*/
getLatest(): IStateSnapshot<T> | null;
/**
* @zh
* @en Get buffer size
*/
readonly size: number;
/**
* @zh
* @en Clear buffer
*/
clear(): void;
}