我想计算游戏最后 2-4 秒的 FPS。执行此操作的最佳方法是什么?
谢谢。
编辑:更具体地说,我只能访问一个以一秒为增量的计时器。
最佳答案
差点错过最近的帖子。请参阅我对使用指数加权移动平均线的回复。
C++: Counting total frames in a game
这是示例代码。
最初:
avgFps = 1.0; // Initial value should be an estimate, but doesn't matter much.
每秒(假设最后一秒的总帧数在framesThisSecond
中):
// Choose alpha depending on how fast or slow you want old averages to decay.
// 0.9 is usually a good choice.
avgFps = alpha * avgFps + (1.0 - alpha) * framesThisSecond;
关于C++:计算移动 FPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4687430/