即使使用 CADisplayLink 还是卡在 40 fps 上?

发布于 2024-10-09 22:40:34 字数 312 浏览 0 评论 0原文

起初我使用 NSTimer 并遇到帧速率卡在每秒 40 帧的问题。我读过有关使用 CADisplayLink 来解决问题的信息。它似乎工作了一段时间,但最近,应用程序以 60 fps 启动,然后过了一会儿(大约 5 - 20 秒),应用程序开始以 40 - 41 fps 运行并卡在那里。我进行了剔除,以便当对象在视野之外时减少绘制,但它仍然卡在那里。一种不寻常的方法似乎可以暂时解决这个问题(大约 10 秒),那就是断开 iPhone 底部的电线,然后重新连接。显然,这并不理想,但只是想知道为什么会发生这种情况以及为什么它会在某种程度上修复它,就好像它重置了某些值或其他东西一样。任何帮助将不胜感激,谢谢。

At first I used NSTimer and ran into the problem of the frame rate being stuck at 40 frames per second. I've read about using CADisplayLink to fix the problem. It seemed to work for a while, but recently, the app starts at 60, then after a little while (about 5 - 20 seconds in) the app starts to run at 40 - 41 fps and gets stuck there. And I'm culling so that there's less draws when objects are out of view, but yet it stays stuck there. A unusual way that does seem to remedy the problem for a moment (about 10 seconds) is to disconnect the wire from the bottom of the iphone and then connect it again. Obviously, this is not ideal, but just wondering why does this happen and why does it somewhat fix it, as if it resets certain values or something. ANY help will be greatly appreciated, thanks.

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

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

发布评论

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

评论(3

梦醒灬来后我 2024-10-16 22:40:34

您是否检查过是否确实丢帧?您使用的CPU/GPU是否达到每秒只能绘制40帧的程度,或者问题出在软件的某个地方?

请记住,如果 CADisplayLink 无法触发屏幕刷新(由于主线程正忙于绘制前一帧等事情),那么它可能会跳过它,因为它没有足够的时间来完成。因此,如果某些帧的绘制时间超过 0.01666... 秒,您将错过随后绘制帧的时间间隔,并且速度可能会比实际情况更糟。

另请记住,移动设备并不总是能够快速绘制所有内容。 iPhone 4 中的 A4 处理器非常好,但每秒填充 960x640 屏幕像素 60 次仍然是一项艰巨的任务。如果您的帧速率是 40 fps 而不是 60 fps,绝大多数用户不会注意到 - 人眼通常不会注意到抖动或屏幕滞后,直到您的帧速率约为 20 fps 或更低。

Have you checked to see whether you're actually dropping frames? Are you using the CPU/GPU to the extent that you can only draw 40 frames in a second, or is the problem somewhere in the software?

Remember that if a CADisplayLink is unable to fire for a screen refresh (due to the main thread being busy doing things like drawing the previous frame) then it may skip it, as it won't have enough time to complete. So if some of your frames take more than 0.01666... seconds to draw, you'll miss the interval to draw the frames right after, and the slowdown may appear worse than it is.

Also remember that a mobile device is not always capable of drawing everything quickly. The A4 processor in an iPhone 4 is very good, but it's still a tall order to fill 960x640 screen pixels 60 times a second. The vast majority of your users will not notice if your frame rate is 40fps instead of 60fps--the human eye doesn't generally notice judder or screen lag until you're around 20fps and lower.

画骨成沙 2024-10-16 22:40:34

我在3G上也遇到同样的问题。我已将我的应用程序简化为在空白(粉红色)后缓冲区上绘制的 FPS 计数器,但它仍然是 40 fps。

经过一番谷歌搜索后,我发现 cocos2d-iphone.org 论坛上正在讨论一个非常相似的问题。

解决方案是关闭视图控制器的自动旋转。所以我让我的 shouldAutorotateToInterfaceOrientation 总是返回 NO 并且这有效(!!!)。我有稳定的 60 FPS。然后我返回了我的简单游戏图形,它是稳定的 60 FPS。但我原本应该在横向模式下运行的游戏目前正在默认的纵向模式下运行。

我不想编写自己的自动旋转代码,所以看起来我要切换回 40 fps。有谁知道如何避免这种自动旋转帧率下降?

I have got the same issue on 3G. I have simplified my app just to FPS counter drawn over the blank (pink) backbuffer and it was 40 fps nevertheless.

After some googling I have found a very similar issue being discussed at cocos2d-iphone.org forum.

The solution was to turn off autorotation of the view controller. So i made my shouldAutorotateToInterfaceOrientation always return NO and this worked (!!!). I had stable 60 FPS. Then I returned my simple game graphics back and it was stable 60 FPS. But my game expected to run in the landscape mode is currently running in default portrait mode.

I have no desire to write my own autorotation code so looks like I am switching back to 40 fps. Does anybody know how to avoid this autorotation framerate drop?

笨笨の傻瓜 2024-10-16 22:40:34

这里同样的问题。我有一个非常基本的 openGL 视图(旋转立方体),它以 60fps 开始,一旦我运行繁重的任务以使其慢一点,它就再也不会回到 60fps,并且一直稳定在 40fps。我正在使用 CADisplayLink,它只是在一个测试应用程序上运行,基本上没有做任何实验来解决这个问题:/

如果有人有解决方案,我将非常感激。

Same problem here. I have a very basic openGL view (rotating cube), it starts at 60fps, once I run a heavy task to slow it down a bit, it never come bacl to 60fps after and its stick at a steady 40fps. I'm using CADisplayLink, and its just running on a test app doing basically nothing that experimenting with this issue :/

If someone have a solution, I would be really grateful.

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