Increasing framerate from 60 to 90 in Cocos2D V3 no effect - objective-c

In CCAppDelegate I set:
NSTimeInterval animationInterval = [(config[CCSetupAnimationInterval] ?: #(1.0/90.0)) doubleValue];
[director setAnimationInterval:animationInterval];
director.fixedUpdateInterval = [(config[CCSetupFixedUpdateInterval] ?: #(1.0/90.0)) doubleValue];
and in CCDirectoriOS - startAnimation I set:
int frameInterval = (int) floor(_animationInterval * 90.0f);
CCLOG(#"cocos2d: animation started with frame interval: %.2f", 90.0f/frameInterval);
But the FPS counter shows 59/60 fps max.
How do I increase the framerate?

It doesn't make sense to increase the frame rate above 60, because the screen refresh rate is 60Hz, so it would not make any difference on screen and it would be just waste of battery and CPU.
You could in theory increase it in cocos2d, however you would have to change some code, as cocos2d uses CADisplayLink as its inner timer, which is obviously linked to the display thus giving you max 60 fps. You would have to have your own refresh timer with interval 1.0/90.0. But you still wouldn't see the difference.

The real reason is that iOS devices have a fixed screen refresh rate of 60 Hz. You can not display more than 60 frames per second on iOS because the screen doesn't refresh faster than 60 Hz (= times per second). The same is true for just about every other mobile device.
Now on PCs it's rather common to turn vertical synchronisation off and have the GPU render as fast as it can, with all the screen tearing you can possibly stand. On mobile devices, VSync is always on and you can not turn it off, ever.
Mobile benchmarking software frequently uses so-called "offscreen render" tests where they render everything into a memory buffer to circumvent the 60 Hz limit and to come up with a theoretically achievable framerate, like 150 fps. Of course you won't see realtime updates of the test on the screen while the test is running.

Related

How can I speed up my animations to make my EarlGrey test suite run faster

I saw the below API in GREYConfiguration that says that EarlGrey by default truncates CALayer animations more than 10 seconds -
/**
* Configuration for setting max allowable animation duration (in seconds) for any CALayer based
* animation. Animations exceeding the specified time will have their duration truncated to value
* specified by this config.
*
* Accepted values: #c double (negative values shouldn't be used)
* Default value: 10.0
*/
GREY_EXTERN NSString *const kGREYConfigKeyCALayerMaxAnimationDuration;
I'm developing a small gaming app that has a number of such animations going on. I noticed that my tests take a long time to run when I have my animations enabled, which is required for my UI Tests. I know that I can change the animation speed for my entire app using UIApplication.sharedApplication.keyWindow.layer.speed. Is there any way that I can change it only for my EarlGrey tests?
Put your UIApplication.sharedApplication.keyWindow.layer.speed behind a conditional statement:
#if EARLGREY_ENV
UIApplication.sharedApplication.keyWindow.layer.speed = 100
#endif
The line of code will only execute when the app is being run through Earl Grey.
For more information around dealing with animations in Earl Grey, see How should I handle animations? under their FAQs.

Long-running animations in iOS (up to 1/2 hour)

So I've got this animated pie chart working now. It can indicate e.g. progress over time (similar to UIProgressView).
For legacy reasons I am still using it with a timer that fires approx. every second and increases progress. It should now be possible to get rid of this timer and set the overall duration of a pie animation e.g. to 1/2 hour instead of letting the timer fire 30 * 60 times and starting as many short incremental animations.
So my question is this: are there any good reasons that speak against using such long (say up to 1/2 hour long) animations in iOS? In the example of the pie chart no more than approx. 360 frames would be needed even over 1/2 hour.
There is a good reason against very long animations: memory.
CoreAnimation will create a presentationLayer for every frame (see for example your other question), and (at least up to iOS 7.1) it will allocate and initialize them in background the moment you add the animation to the layer.
The frame rate depends on the device, not on the magnitude of the change of the animated property; moreover, there doesn't seem to be a way to tweak CoreAnimation's frame rate on iOS (while on OSX NSAnimation has a frameRate property), so if you animate progress (but it would be the same with any property) and set a duration time of 30 minutes, you will end up with a lot of memory wasted.
Some numbers. I scheduled some CABasicAnimations with path progress on your DZRoundProgressLayer, and added some logging in -initWithLayer:. This revealed that on the simulator, roughly 50 shadow copies (frames) are needed per second of animation.
This means 90K shadow copies are going to be created for 30 minutes: for several seconds after the beginning of the animation, CoreAnimation was still allocating the first thousands of copies. Adding some data payload to the instance variables of DZRoundProgressLayer showed the memory usage raising by several MB in the first seconds (then some memory management took over the unconstrained allocations, presumably freeing the old copies).
Is it a bad idea? It's a waste of resources, memory and CPU, even if your layer occupies a few bytes in memory, considering that the change in the pie area per frame is too small to be noticed. Setting up a NSTimer or KVO doesn't require many lines of code, so it might be worth to change approach.

iOS framerate - always 30fps with UIImage?

i want to create a frame-by-frame animation with an array of images.
There is to set the animationDuration, the standard value is 1.
Can i be sure that it is always 30fps on every iOS-device when i start the animation with startAnimating?
So i need exactly 15 images for a 1 second animation - is there a special calculation i can use when i have more or less than 15 images that have to be animated in exactly one second?
E.g. 60/15*(count number of images in array)
I don't think you can count on UIImageView animationImages to give you 30FPS everywhere and everytime.
Indeed, this is meant for very simple and "opportunistic" animations. If you google for it, you will find reports of that method hogging a device (in specific conditions). On the other hand, if your images are small, then chances are that it could work, but you get no guarantees (nor ways to enforce the FPS you need).
So i need exactly 15 images for a 1 second animation - is there a special calculation i can use when i have more or less than 15 images that have to be animated in exactly one second?
If I understand your question right, then you can try with:
duration = number_of_images / FPS; // e.g., 60 images / 30 FPS = 2 seconds
of course, if the device will then show properly the 60 images at 30 FPS is another story.

OpenGL - animation stuttering when in full screen

I'm currently running into a problem regarding animation in OpenGL. I have between 200 and 10000 gears on the screen at a time all rotating. When the window is not in maximized view, my CPU runs at about 10-20 % consistently. No spikes, no stuttering in the animation, it runs perfectly smooth regardless of the number of gears on screen. When I maximize the window though, everything falls apart. My CPU maxes out, I begin getting weird spikes in CPU usage, the animation begins stuttering as a result, and it just looks really ugly, even when I have only 200 gears on screen.
My animation technique looks like this:
While Animating
Calculate current rotation angle based on a running timer
draw Image
call glFlush()
End While
If it helps, I'm using the Tao framework in VB.net. I'm not performing any other calculations other than the ones to calculate the rotation angle mentioned above and perform a few glRotateD and glscaleD in the method to draw the image.
In addition, I guess I was under the impression that regardless of the window size in an orthographic 2-dimensional drawing that is scaling on resizing of the window, the drawing time would always take the same amount of time. Is this a correct assumption?
Any help is greatly appreciated =)
Edit
Note that I've seen the animation run perfectly smooth at full screen before. Every once in awhile, OpenGL will decide it's happy and run perfectly at full screen using between 10-20% of the CPU (same as when not maximized). I haven't pinpointed what causes this though, because it will run one time perfectly, then without changing anything, I will run it again and encounter the choppiness. I simply want to pinpoint what causes the animation to slow down and eliminate it.
I've run a dot trace on my program and it says that the swapBuffers method is using 55 % of my processing time even though I'm never explicitly calling the method. Is the method called by something else that I can eliminate, or is this simply OpenGL's "dead time" method to limit the animation to 60 fps?
I was under the impression that regardless of the window size in an orthographic 2-dimensional drawing that is scaling on resizing of the window, the drawing time would always take the same amount of time. Is this a correct assumption?
If only :)
More pixels require more memory bandwidth/shader units/etc. Look into fillrate.

how to get the maximum fps in ipad?

I have developed a game for iPhone using coco2d 0.99.3. I want it to work on iPad. I have the new images which are bigger in size and resolution than iPhone images.
Every thing is fine, but I got the fps problem. In iphone simulator I used to get 50 - 60 fps and even in iPhone device I used to get 50 above fps.
But, in ipad simulator the fps is very low, it is below 10fps. I could not understand where is the problem. What should I do to raise the fps ?
Thank You.
this is a common phenomenon among other developers (including myself)
BUT it's nothing to worry about; fps on the real iPad are much higher than the simulator. However, this only seems to happen with large images, so I don't add them till the very end of the development process. You can get reasonable results by doing so.
hope this helps