GLKViewController:不正确的 fps

发布于 2024-12-12 07:45:48 字数 744 浏览 1 评论 0原文

希望有一些 GLKViewController 专家在那里,因为我有一些问题:)

只是对我的应用程序的快速描述。我有一个 UINavigationController,我在其中推送不同的屏幕。

在某些时候,我会进入我的游戏屏幕,它是 UINavigationController 的子类。在此屏幕中,在 viewDidLoad 中,我手动创建 EAGLContext、GLKView 并实例化一个新的 GLKViewController(以处理我的更新和绘制调用)。

我将首选 fps 设置为 30。

问题是前 3-4 个更新调用带有正确的 DT,但随后我有 2-3 帧,帧之间有 1 秒。我使用 controller.timeSinceLastUpdate 测量 DT。 所以我的想法是:

dt=0.33
dt=0.33
dt=0.33
dt=1.07
dt=1.05
dt=0.33
dt=0.33

在此之后,我仅获得有效的 DT 次。我不知道为什么这些帧有这样的延迟。我测量了更新和更新所花费的时间。绘制方法,而且它远不及1秒。

另外,我没有加载任何纹理/创建任何几何体。由于这是一个相当小的游戏,一切都在加载时完成。

另外,如果我弹出游戏屏幕控制器,然后推回游戏屏幕的另一个实例,这个新的 GLKViewController 只会大约每 1 秒调用我的更新方法。

有人在使用 GLKViewController 时遇到过帧速率问题吗?

谢谢,

Hope there are some GLKViewController experts out there because I have some problems :)

Just a quick description of my app. I have a UINavigationController in which I push different screens.

At some point, I get to my game screen which is a subclass of UINavigationController. In this screen, in viewDidLoad I manually create a EAGLContext, GLKView and instantiate a new GLKViewController (to handle my update&draw calls).

I am setting a preferred fps of 30.

The problem is that the first 3-4 update calls come with the correct DT, but then I have 2-3 frames with 1 second between them. I measure the DT using controller.timeSinceLastUpdate.
So I get like:

dt=0.33
dt=0.33
dt=0.33
dt=1.07
dt=1.05
dt=0.33
dt=0.33

After this, I get valid only DT times. I have no idea why those frames have that kind of delay. I measured the time it takes me in the update & draw method, and it's nowhere near 1 second.

Also, I'm not loading any textures/creating any geometry. Everything is done at loading since it is a rather small game.

Also, if I pop the game screen controller and then push back another instance of the game screen, this new GLKViewController will only call my update method aproximately every 1 second.

Did anybody have a problem with the framerate when using GLKViewController?

Thanks,

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

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

发布评论

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

评论(2

滥情哥ㄟ 2024-12-19 07:45:49

好的,所以我终于弄清楚了。事实证明,它甚至与 GLKViewController 无关(惊喜!)。

这与我显示游戏屏幕视图控制器的方式有关,如下所示:

    GameAreaViewController* gameController = [[GameAreaViewController alloc] init];

    [UIView beginAnimations:@"animation" context:nil];
    [self.navigationController pushViewController: gameController animated:NO]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView setAnimationDuration:0.7f];
    [UIView commitAnimations];        

    SAFE_DEL(gameController);

如果我使用 0.3f 的动画持续时间,则不会出现任何延迟。有时在 0.5f 时我能得到它,而在 0.7 时我总是得到它。

Ok, so I finally figured it out. It turns out that it's not even related to the GLKViewController (surprise surprise!).

It had something to do with the way I'm displaying the game screen view controller, like this:

    GameAreaViewController* gameController = [[GameAreaViewController alloc] init];

    [UIView beginAnimations:@"animation" context:nil];
    [self.navigationController pushViewController: gameController animated:NO]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView setAnimationDuration:0.7f];
    [UIView commitAnimations];        

    SAFE_DEL(gameController);

If I use an animation duration of 0.3f, then I don't get any lag. At 0.5f sometimes I get it and at 0.7 I was always getting it.

动听の歌 2024-12-19 07:45:48

问题是你不知道设备在刷新之间还做了什么:)

你可能只花了 0.1 秒处理下一帧,但如果出现内存警告,那么应用程序的其他部分也将需要时间来处理。我猜想 gl 控制器会尽力保持首选帧速率,但如果后台发生很多事情,那么它对此无能为力。

只要您确保代码尽可能快地渲染并且不会以与帧速率相同的方式出现峰值,那么它就不是您的渲染路径。从你的问题看来你已经测试过了。

您可能想做的另一件事是留意可能传递到您的应用程序中的其他通知(即内存警告)。

最后,慢帧是否存在某种模式 - 它们是否与正在加载的新图像或文件访问一致?你事先做了尽可能多的事情吗?编辑 - 重读你的问题让我认为你已经这样做了,抱歉!

抱歉,我不能再使用了:(

The problem is that you don't know what else the device is doing between your refreshes :)

You might only spent 0.1s working on the next frame but if there is a memory warning then other bits of your app will also take time to process. I guess that the gl controller will do it's best to keep to the preferred frame rate but if lots is going on in the background then there's not much it can do about it.

As long as you make sure that your code is rendering as fast as possible and isn't spiking in the same way as the framerate then it's not your render path. From your question it sounds like you've already tested that.

The other thing you might want to do is to watch out for other notifications that might be passed into your app (i.e. memory warnings).

Finally, is there a pattern to the slow frames - do they coincide with a new image being loaded or a file access? Have you done as much as possible beforehand? EDIT - rereading your question makes me think that you've already done this, sorry!

Sorry I can't be any more use :(

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