UNPKG

replay-viewer

Version:

Rocket League replay viewer React component and tooling

60 lines (59 loc) 2.34 kB
import { ReplayData } from "../models/ReplayData"; /** * This clock provides a simple callback system that keeps track of elapsed and delta time * transformations. This makes it extremely easy to parse the deltas of a replay by their frame * count, and maintain a real-time comparison against those frames. Primarily to be used by the * THREE.js animation system and communicate changes back to the parent container of animations so * that we can display data which is recorded at a frame and not at a time. * * When constructing this object, you should provide an array of elapsed durations*1000, where each * index in the array represents the time in milliseconds since the beginning of the animation. The * first index, 0, should be set to 0 (the elapsed time since the start), followed by these times. * * For example: * 0: 0 * 1: 483.877919614315 * 2: 838.5848999023438 * 3: 1322.4628567695618 * 4: 1809.6305429935455 */ export default class FPSClock { currentFrame: number; private lastDelta; private readonly deltaQueue; private elapsedTime; private readonly frameToDuration; private paused; private animation?; constructor(frameToDuration: number[]); reset(): void; setFrame(frame: number): void; isPaused(): boolean; play(): void; pause(): void; /** * Returns the elapsed time in milliseconds. */ getElapsedTime(): number; /** * Returns the number of seconds elapsed since the last time getDelta was called. This function * uses a combination of the performance.now() functionality when animations are rolling, * combined with a small queue of delta modifications made by the setFrame function. This will * allow us to apply delta factors quite easily and in one spot (i.e. 2x speed) as opposed to * scattering arithmetic throughout the code. * * @returns {number} seconds */ private getDelta; private update; private getElapsedFrames; private timeout; private doCallbacks; /** * Note that the final frame is ignored when considering the elapsed time per frame. If we * considered this final delta, we would need a frame to "animate to". * * @param data Contains frame delta information */ static convertReplayToClock(data: ReplayData): FPSClock; }