UNPKG

@thi.ng/timestep

Version:

Deterministic fixed timestep simulation updates with state interpolation

56 lines 2.26 kB
import { type Event, type INotify, type Listener } from "@thi.ng/api"; import { type ITimeStep, type ReadonlyTimeStep, type TimeStepEventType, type TimeStepOpts } from "./api.js"; export declare class TimeStep implements INotify<TimeStepEventType> { start: number; dt: number; maxFrameTime: number; scale: number; t: number; current: number; accumulator: number; frame: number; updates: number; protected __eventFrame: Event<TimeStepEventType>; protected __eventSubFrame: Event<TimeStepEventType>; constructor(opts?: Partial<TimeStepOpts>); addListener(id: TimeStepEventType, fn: Listener<TimeStepEventType>, scope?: any): boolean; removeListener(id: TimeStepEventType, fn: Listener<TimeStepEventType>, scope?: any): boolean; notify(event: Event<TimeStepEventType>): boolean; /** * Updates internal time to given new time `now` (given value will be scaled * via {@link TimeStepOpts.scale}) and performs the required number of fixed * timesteps to integrate and interpolate the given `state` values. * * @remarks * If the scaled time difference since the last step is greater than * {@link TimeStepOpts.maxFrameTime}, it will be limited to the latter. * * If `interpolate` is false, the {@link ITimeStep.interpolate} phase of the * update cycle is skipped. This is useful when using this setup to simulate * sub-steps (e.g. in XPBD) and only requiring the interpolation stage for * the last step. * * @param now * @param items * @param interpolate */ update(now: number, items: ITimeStep[], interpolate?: boolean): void; } export declare const defTimeStep: (opts?: Partial<TimeStepOpts>) => TimeStep; /** * Calls {@link ITimeStep.integrate} for all given items (in given order). * * @param dt * @param ctx * @param items */ export declare const integrateAll: (dt: number, ctx: ReadonlyTimeStep, ...items: ITimeStep[]) => void; /** * Calls {@link ITimeStep.interpolate} for all given items (in given order). * * @param dt * @param ctx * @param items */ export declare const interpolateAll: (alpha: number, ctx: ReadonlyTimeStep, ...items: ITimeStep[]) => void; //# sourceMappingURL=timestep.d.ts.map