UNPKG

@hastearcade/snowglobe

Version:

A TypeScript port of CrystalOrb, a high-level Rust game networking library

42 lines 1.59 kB
import * as Timestamp from './timestamp.js'; export class Tweened { _displayState; timestamp; constructor(_displayState, timestamp) { this._displayState = _displayState; this.timestamp = timestamp; } displayState() { return this._displayState; } floatTimestamp() { return this.timestamp; } clone() { return new Tweened(this._displayState.clone(), this.timestamp); } } export function timestampedFromInterpolation(state1, state2, t, fromInterpolation) { if (t === 0) { return Timestamp.set(state1.clone(), Timestamp.get(state1)); } else if (Math.abs(t - 1) < Number.EPSILON) { return Timestamp.set(state2.clone(), Timestamp.get(state2)); } else { console.assert(Timestamp.get(state1) === Timestamp.get(state2), 'The timestamps for interpolation do not match'); return Timestamp.set(fromInterpolation(state1, state2, t), Timestamp.get(state1)); } } export function tweenedFromInterpolation(state1, state2, t, fromInterpolation) { const timestampDifference = Timestamp.sub(Timestamp.get(state2), Timestamp.get(state1)); const timestampOffset = t * timestampDifference; const timestampInterpolated = Timestamp.get(state1) + timestampOffset; const results = fromInterpolation(state1, state2, t); state1.dispose(); return new Tweened(results, timestampInterpolated); } export function tweenedFromTimestamped(timestamped) { return new Tweened(timestamped.clone(), Timestamp.get(timestamped)); } //# sourceMappingURL=display_state.js.map