Strange SetUpdateRate behavior

Monkey Forums/Monkey Programming/Strange SetUpdateRate behavior

devolonter(Posted 2011) [#1]
I conducted all tests with an example from the distribution kit "Bouncy Aliens!". Monkey v43 version. The number of sprites - 25, alpha enabled, -config=release. After each test, I deleted folder .build

XNA(PC)
When I call SetUpdateRate (60) I do not always get FPS equal to 60 - usually it is 53-54FPS. At the same time, if I call SetUpdateRate (69), I get FPS equal to 61 (stable 61FPS). Below there is a small table that shows the results for different values:
+------------------+---------+
|SetUpdateRate(69) |  61FPS  |
+------------------+---------+
|SetUpdateRate(65) |  61FPS  |
+------------------+---------+
|SetUpdateRate(60) |  53FPS  |
+------------------+---------+
|SetUpdateRate(59) |  52FPS  |
+------------------+---------+
|SetUpdateRate(50) |  44FPS  |
+------------------+---------+
|SetUpdateRate(49) |  43FPS  |
+------------------+---------+

Flash
Here FPS never goes above 60. Even if you do not see a single sprite on the screen.
+------------------+---------+
|SetUpdateRate(69) |  60FPS  |
+------------------+---------+
|SetUpdateRate(65) |  60FPS  |
+------------------+---------+
|SetUpdateRate(60) |  60FPS  |
+------------------+---------+
|SetUpdateRate(59) |  59FPS  |
+------------------+---------+
|SetUpdateRate(50) |  50FPS  |
+------------------+---------+
|SetUpdateRate(49) |  49FPS  |
+------------------+---------+

Android. (HTC Desire Z. Android 2.2)
FPS never goes above 58-59FPS. Even if you do not see a single sprite on the screen. Sprites move with barely noticeable stutter, but if you set the herz equal to 58 (exactly 58), the movements become completely smooth.
+------------------+----------+
|SetUpdateRate(69) | 58-59FPS |
+------------------+----------+
|SetUpdateRate(65) | 58-59FPS |
+------------------+----------+
|SetUpdateRate(60) | 58-59FPS |
+------------------+----------+
|SetUpdateRate(59) | 58-59FPS |
+------------------+----------+
|SetUpdateRate(50) | 50-51FPS |
+------------------+----------+
|SetUpdateRate(49) | 49-50FPS |
+------------------+----------+

In glfw and html5 targets FPS is fully consistent with the specified herz in SetUpdateRate


muddy_shoes(Posted 2011) [#2]
SetUpdateRate sets the rate that mojo attempts to call OnUpdate. It doesn't actually set the frame rate and some targets will have a framerate cap that won't be exceeded no matter how many times OnRender is called.

There is also only a one to one relationship between OnUpdate and OnRender as long as both calls are fitting within the time required to meet the requested update rate. If you fall behind then OnUpdate will be called and frames dropped. Move the fps increment in the bouncing aliens code into the OnUpdate call and you'll see the "fps" matching the requested update rate even when the visual framerate is crawling.


devolonter(Posted 2011) [#3]
@muddy_shoes Yes, you're right. When I move the FPS increment in OnUpdate method, all values are equal. I also reviewed the documentation and if I understand correctly I need to set UpdateRate range of values: 15,30,60. In this case I do not understand how I can make the movement more smooth... Anyway it is not related to the topic.
Sorry.


muddy_shoes(Posted 2011) [#4]
There's nothing to be sorry about. The mojo update loop behaviour and SetUpdateRate effects aren't particularly intuitive but much of what you're seeing is explained by their implementation. It's also why I suggested that people need to time/count both the OnUpdate and OnRender calls when analysing performance under mojo.

Your Android "stuttering" is harder to diagnose because it's not clear what you mean by stuttering. Your figures do show one or two missed frames a second, but would that be visible as stuttering at 60fps?


marksibly(Posted 2011) [#5]
Hi,

If you move the frame rate calculation to OnUpdate, the numbers come out right.

The issue is that on some targets (XNA/Android) Monkey has no control over when OnRender gets called, and some targets appear to be locked to 60FPS. This means if you set update rate to >60 on those targets, you'll actually get multiple OnRenders per single OnUpdate.

> I also reviewed the documentation and if I understand correctly I need to set UpdateRate range of values: 15,30,60.

These are just recommendations really.

I'm not sure what's up with the Android stuttering, but I don't get it myself. It has always been my intention to 'special case' an update rate of 60 though, as some targets provide specific support for timing based on 60FPS vsync. This may help with Android stuttering and I'll have a look into it soon.