tags:

views:

68

answers:

1

I have an NSTimer that runs at 60hz. With an OpenGL scene loaded and rendering, my game can get 60fps, solid, all day long.. Then if I go and recompile the app, or reload it, it will get 40fps. Same resources loaded. I've been running into this problem for years, and I just want to know why. It's crazy, and I want to know if I should just abandon this stupid Timer. Conditions are not different on my 3GS between loads. It will just get 40fps sometimes. Obviously the clockrate is not different between loads, so the performance figures should be constant given a constant scene. Here is a log of my framerates:

A good load: :-)

FrameRate: 61 FrameRate: 61 FrameRate: 61 FrameRate: 60 FrameRate: 60 FrameRate: 61 FrameRate: 60 FrameRate: 60 FrameRate: 61 FrameRate: 60 FrameRate: 61

Now, I'll go ahead and do nothing, recompile, and run:

FrameRate: 43 FrameRate: 50 FrameRate: 45 FrameRate: 48 FrameRate: 40 FrameRate: 45 FrameRate: 42 FrameRate: 41 FrameRate: 42 FrameRate: 44 FrameRate: 41 FrameRate: 46

^- Massive difference visually. What the flying heck could cause this?

SAME area of the scene, SAME camera setup. No variables are different.

[Edit] Some have mentioned that the music not running in the hardware decoder can cause this, and that sometimes the decoder will NOT take over even if you set it up to. However, I can say that even with music disabled, this happens [/Edit]

+2  A: 

Have you tried using CADisplayLink instead? From the documentation:

A CADisplayLink object is a timer object that allows your application to synchronize its drawing to the refresh rate of the display.

...

Once the display link is associated with a run loop, the selector on the target is called when the screen’s contents need to be updated.

I haven't used it personally, but it looks like it might help any issues you have with the lower frame rate, even if it doesn't increase your frame rate per se.

Martin Gordon
I'll give that a try, and report the results. Thanks!
Kyle
It seems to fix the issue, but adds another. Controls are now very lagged. I've seen this in other articles as well. If only controls weren't fed to delegates on interval! You wouldn't happen to have any advice here would you?
Kyle
I know it's not much to go on, but this tweet (http://twitter.com/iradel/status/9217529871) claims that the input lag goes away if you set it 30fps. Although I guess this doesn't help you if you were getting 40-60fps previously. Still, CADisplayLink may be more consistent than NSTimer.
Martin Gordon
Also, this question (http://stackoverflow.com/questions/2004362/cocos2d-on-application-start-gives-random-fps-drop) has a user experiencing the same issues as you using cocos2d (you didn't mention whether you were using it or not).
Martin Gordon
For now, a timer at 240hz seems to fix the issue on all OS versions with no input lag at all. While it seems awfully cheap, it just gives the best results. On older, 3G (and below) phones, the timer is set to 30hz. At 30, it has no problem sustaining that framerate.In the future, and for non CPU-intensive rendering paths, CADisplayLink will likely be the solution for most.
Kyle