Files
esengine/src/Utils/Time.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

/**
*
*
*/
export class Time {
/**
*
*/
public static deltaTime: number = 0;
/**
*
*/
public static unscaledDeltaTime: number = 0;
/**
*
*/
public static totalTime: number = 0;
/**
*
*/
public static unscaledTotalTime: number = 0;
/**
*
*/
public static timeScale: number = 1;
/**
*
*/
public static frameCount: number = 0;
/**
2025-06-12 09:42:35 +08:00
* 使deltaTime更新时间信息
* @param deltaTime
*/
2025-06-12 09:42:35 +08:00
public static update(deltaTime: number): void {
// 设置未缩放的帧时间
this.unscaledDeltaTime = deltaTime;
this.deltaTime = deltaTime * this.timeScale;
// 更新总时间
this.unscaledTotalTime += this.unscaledDeltaTime;
this.totalTime += this.deltaTime;
// 更新帧数
this.frameCount++;
}
/**
*
*/
public static sceneChanged(): void {
2025-06-12 09:42:35 +08:00
this.frameCount = 0;
this.totalTime = 0;
this.unscaledTotalTime = 0;
this.deltaTime = 0;
this.unscaledDeltaTime = 0;
}
/**
*
* @param interval
* @param lastTime
* @returns
*/
public static checkEvery(interval: number, lastTime: number): boolean {
return this.totalTime - lastTime >= interval;
}
}