游戏中的固定帧率与可变帧率:什么是最好的,什么时候最好?

发布于 2024-07-06 03:09:20 字数 229 浏览 11 评论 0原文

在开发游戏一段时间后,我接触到了可变帧速率(您可以计算出自上次更新以来已经过去了多少时间,并相应地更新演员运动)和固定帧速率(您可以计算出多少时间)已经过去了,选择是勾选固定的时间还是休眠直到下一个窗口到来)。

哪种方法最适合特定情况? 请考虑:

  • 迎合不同的系统规格;
  • 易于开发/维护;
  • 易于移植;
  • 最后的表演。

After working for a while developing games, I've been exposed to both variable frame rates (where you work out how much time has passed since the last tick and update actor movement accordingly) and fixed frame rates (where you work out how much time has passed and choose either to tick a fixed amount of time or sleep until the next window comes).

Which method works best for specific situations? Please consider:

  • Catering to different system specifications;
  • Ease of development/maintenance;
  • Ease of porting;
  • Final performance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

绳情 2024-07-13 03:09:20

我倾向于使用可变帧率模型,但在内部某些系统是按固定时间步长进行勾选的。 通过使用时间累加器可以很容易地做到这一点。 物理系统最好在固定时间步长上运行,并在必要时每帧多次勾选,以避免稳定性损失并保持模拟顺利。

一些代码来演示累加器的使用:

const float STEP = 60.f / 1000.f;
float accumulator = 0.f;

void Update(float delta)
{
    accumulator += delta;

    while(accumulator > STEP)
    {
        Simulate(STEP);
        accumulator -= STEP;
    }
}

这无论如何都不完美,但提出了基本思想 - 有很多方法可以改进这个模型。 显然,当输入帧速率非常慢时,需要解决一些问题。 然而,最大的优点是,无论增量有多快或多慢,模拟都会在“玩家时间”内以平稳的速度移动——这是用户会察觉到任何问题的地方。

一般来说,我不涉及图形和图像。 音频方面,但我认为它们不像物理、输入和网络代码那样受到影响。

I lean towards a variable framerate model, but internally some systems are ticked on a fixed timestep. This is quite easy to do by using a time accumulator. Physics is one system which is best run on a fixed timestep, and ticked multiple times per frame if necessary to avoid a loss in stability and keep the simulation smooth.

A bit of code to demonstrate the use of an accumulator:

const float STEP = 60.f / 1000.f;
float accumulator = 0.f;

void Update(float delta)
{
    accumulator += delta;

    while(accumulator > STEP)
    {
        Simulate(STEP);
        accumulator -= STEP;
    }
}

This is not perfect by any means but presents the basic idea - there are many ways to improve on this model. Obviously there are issues to be sorted out when the input framerate is obscenely slow. However, the big advantage is that no matter how fast or slow the delta is, the simulation is moving at a smooth rate in "player time" - which is where any problems will be perceived by the user.

Generally I don't get into the graphics & audio side of things, but I don't think they are affected as much as Physics, input and network code.

寒江雪… 2024-07-13 03:09:20

似乎大多数 3D 开发人员更喜欢可变 FPS:Quake、Doom 和 Unreal 引擎都会根据系统性能进行缩放。

  • 至少你必须补偿太快的帧速率(不像在 90 年代运行的 80 年代游戏,太快了)
  • 无论如何,你的主循环应该通过时间步长进行参数化,只要它不是太长,一个像样的积分器RK4 应该能够顺利地处理物理现象 某些类型的动画(关键帧精灵)可能很难进行参数化。 也需要智能,例如避免拥有更快机器的玩家发射太多子弹,但无论如何都需要进行这种限制以补偿延迟(动画参数化也将有助于隐藏网络延迟)
  • 网络代码 计时代码需要针对每个平台进行修改,但这是一个小的本地化更改(尽管某些系统使极其精确的计时变得困难,但 Windows、Mac、Linux 似乎还可以)
  • 可变帧速率可实现最大性能。 固定帧速率可以实现一致的性能,但永远不会在所有系统上达到最大值(这似乎是任何严肃游戏的阻碍)

如果您正在编写性能很重要的网络 3D 游戏,我不得不说,咬紧牙关,实施可变帧速率。

如果这是一款 2D 益智游戏,您可能可以使用固定的帧速率,也许可以针对超慢的计算机和明年的模型进行稍微参数化。

It seems that most 3D developers prefer variable FPS: the Quake, Doom and Unreal engines both scale up and down based on system performance.

  • At the very least you have to compensate for too fast frame rates (unlike 80's games running in the 90's, way too fast)
  • Your main loop should be parameterized by the timestep anyhow, and as long as it's not too long, a decent integrator like RK4 should handle the physics smoothly Some types of animation (keyframed sprites) could be a pain to parameterize. Network code will need to be smart as well, to avoid players with faster machines from shooting too many bullets for example, but this kind of throttling will need to be done for latency compensation anyhow (the animation parameterization would help hide network lag too)
  • The timing code will need to be modified for each platform, but it's a small localized change (though some systems make extremely accurate timing difficult, Windows, Mac, Linux seem ok)
  • Variable frame rates allow for maximum performance. Fixed frame rates allow for consistent performance but will never reach max on all systems (that's seems to be a show stopper for any serious game)

If you are writing a networked 3D game where performance matters I'd have to say, bite the bullet and implement variable frame rates.

If it's a 2D puzzle game you probably can get away with a fixed frame rate, maybe slightly parameterized for super slow computers and next years models.

西瓜 2024-07-13 03:09:20

作为一名用户,我希望更频繁地看到的一个选项是当帧速率变化超出特定范围时动态更改细节级别(广义上,而不仅仅是技术意义上)。 如果您以 5FPS 渲染,请关闭凹凸贴图。 如果您以 90FPS 进行渲染,请稍微增加一些附加功能,并为用户提供一些更漂亮的图像来浪费他们的 CPU 和 GPU。

如果做得正确,用户应该可以从游戏中获得最佳体验,而无需进入设置屏幕并自行调整,并且作为关卡设计师,您应该不必担心在不同场景中保持多边形数量相同。

当然,我是作为一名游戏用户这么说的,而不是一个严肃的用户——我从未尝试过编写一款不平凡的游戏。

One option that I, as a user, would like to see more often is dynamically changing the level of detail (in the broad sense, not just the technical sense) when framerates vary outside of a certian envelope. If you are rendering at 5FPS, then turn off bump-mapping. If you are rendering at 90FPS, increase the bells and whistles a bit, and give the user some prettier images to waste their CPU and GPU with.

If done right, the user should get the best experince out of the game without having to go into the settings screen and tweak themselves, and you should have to worry less, as a level designer, about keeping the polygon count the same across difference scenes.

Of course, I say this as a user of games, and not a serious one at that -- I've never attempted to write a nontrivial game.

甜嗑 2024-07-13 03:09:20

我在使用可变长度帧时间时遇到的主要问题是浮点精度,并且可变帧时间可能会让您大吃一惊。

例如,如果您将帧时间 * 速度添加到某个位置,并且帧时间变得非常小,并且位置较大,则您的对象可能会减慢或停止移动,因为所有增量都因精度而丢失。 您可以使用单独的误差累加器来补偿这一点,但这很痛苦。

固定帧时间(或至少是帧长度的下限)可以让您控制需要考虑的 FP 错误量。

The main problem I've encountered with variable length frame times is floating point precision, and variable frame times can surprise you in how they bite you.

If, for example, you're adding the frame time * velocity to a position, and frame time gets very small, and position is largish, your objects can slow down or stop moving because all your delta was lost due to precision. You can compensate for this using a separate error accumulator, but it's a pain.

Having fixed (or at least a lower bound on frame length) frame times allows you to control how much FP error you need to take into account.

街角迷惘 2024-07-13 03:09:20

我的经验相当仅限于一些简单的游戏(使用 SDL 和 C++ 开发),但我发现实现静态帧速率非常容易。 您正在开发 2d 或 3d 游戏吗? 我认为更复杂的 3D 环境会从可变帧速率中受益更多,并且难度会更大。

My experience is fairly limited to somewhat simple games (developed with SDL and C++) but I have found that it is quite easy just to implement a static frame rate. Are you working with 2d or 3d games? I would assume that more complex 3d environments would benefit more from a variable frame rate and that the difficulty would be greater.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文