fleeting-garden/src/game-loop/frame-performance.ts
2026-05-17 14:12:01 +01:00

28 lines
762 B
TypeScript

import { appConfig } from '../config';
export class FramePerformance {
public smoothedFps = appConfig.simulation.budget.initialFps;
private previousFrameTime: DOMHighResTimeStamp | null = null;
public update(time: DOMHighResTimeStamp): void {
const previous = this.previousFrameTime;
this.previousFrameTime = time;
if (previous === null) {
return;
}
const deltaSeconds = (time - previous) / 1000;
if (
deltaSeconds <= 0 ||
deltaSeconds > appConfig.simulation.budget.frameGapResetSeconds
) {
return;
}
const fps = 1 / deltaSeconds;
this.smoothedFps =
this.smoothedFps * appConfig.simulation.budget.fpsSmoothingRetain +
fps * appConfig.simulation.budget.fpsSmoothingNew;
}
}