export class Time {
    maxDelta;
    timeScaleValue;
    frameValue = 0;
    elapsedValue = 0;
    unscaledElapsedValue = 0;
    deltaValue = 0;
    unscaledDeltaValue = 0;
    smoothedDeltaValue = 0;
    constructor(maxDelta, timeScaleValue = 1) {
        this.maxDelta = maxDelta;
        this.timeScaleValue = timeScaleValue;
        if (!Number.isFinite(maxDelta) || maxDelta <= 0)
            throw new RangeError("maxDelta must be finite and positive.");
        this.setTimeScale(timeScaleValue);
    }
    setTimeScale(timeScale) {
        if (!Number.isFinite(timeScale) || timeScale < 0)
            throw new RangeError("timeScale must be finite and non-negative.");
        this.timeScaleValue = timeScale;
    }
    update(unscaledDelta) {
        if (!Number.isFinite(unscaledDelta) || unscaledDelta < 0)
            throw new RangeError("delta must be finite and non-negative.");
        this.unscaledDeltaValue = Math.min(unscaledDelta, this.maxDelta);
        this.deltaValue = this.unscaledDeltaValue * this.timeScaleValue;
        this.unscaledElapsedValue += this.unscaledDeltaValue;
        this.elapsedValue += this.deltaValue;
        this.frameValue++;
        this.smoothedDeltaValue = this.frameValue === 1 ? this.deltaValue : this.smoothedDeltaValue * 0.9 + this.deltaValue * 0.1;
        return this.snapshot();
    }
    snapshot() {
        return Object.freeze({
            frame: this.frameValue,
            elapsed: this.elapsedValue,
            unscaledElapsed: this.unscaledElapsedValue,
            delta: this.deltaValue,
            unscaledDelta: this.unscaledDeltaValue,
            smoothedDelta: this.smoothedDeltaValue,
            timeScale: this.timeScaleValue
        });
    }
}
//# sourceMappingURL=Time.js.map