C++:计算移动 FPS
我想计算游戏最后2-4秒的FPS。最好的方法是什么?
谢谢。
编辑:更具体地说,我只能访问以一秒为增量的计时器。
I would like to calculate the FPS of the last 2-4 seconds of a game. What would be the best way to do this?
Thanks.
Edit: To be more specific, I only have access to a timer with one second increments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
差点错过了最近的一个帖子。请参阅我对使用指数加权移动平均线的回复。
C++:计算游戏中的总帧数
这是示例代码。
最初:
每秒(假设最后一秒的总帧数在
framesThisSecond
中):Near miss of a very recent posting. See my response there on using exponential weighted moving averages.
C++: Counting total frames in a game
Here's sample code.
Initially:
Every second (assuming the total number of frames in the last second is in
framesThisSecond
):这是一个可能适合您的解决方案。我将用伪/C 语言编写此内容,但您可以根据您的游戏引擎调整该想法。
Here's a solution that might work for you. I'll write this in pseudo/C, but you can adapt the idea to your game engine.
可以保留最后 100 帧的帧时间的循环缓冲区,并对它们进行平均吗?这将是“最后 100 帧的 FPS”。 (或者更确切地说,99,因为您无法区分最新时间和最旧时间。)
调用一些准确的系统时间,毫秒或更好。
Could keep a circular buffer of the frame time for the last 100 frames, and average them? That'll be "FPS for the last 100 frames". (Or, rather, 99, since you won't diff the newest time and the oldest.)
Call some accurate system time, milliseconds or better.
你真正想要的是这样的(在你的 mainLoop 中):
如果你知道如何处理结构/数组,那么你应该很容易将此示例扩展到 4 秒而不是 2 秒。但是如果你想要更详细的帮助,你真的应该提到为什么你无法访问精确的计时器(哪种架构,语言) - 否则一切就像猜测......
What you actually want is something like this (in your mainLoop):
If you know, how to deal with structures/arrays it should be easy for you to extend this example to i.e. 4 seconds instead of 2. But if you want more detailed help, you should really mention WHY you haven't access to an precise timer (which architecture, language) - otherwise everything is like guessing...