OnRender() called as often as possible?

Monkey Forums/Monkey Programming/OnRender() called as often as possible?

Pudsy(Posted 2011) [#1]
Hi,

I'm looking for the best/safest way to have OnRender() called as often as the target device is capable of. It will then do tweened rendering while the game updates run to a fixed clock of eg. 15 or 30 ticks per second.

Also wonder if there's any reason not to have OnRender() actually handle triggering the game updates. Anything stating that OnRender() should finish ASAP for example?

So unless there's a better way, I'm currently picturing setting the update rate to something like 60, but OnUpdate() wouldn't actually do anything itself. OnRender() would trigger as many game updates as required since the last call (possibly zero), then render the scene.

Is that likely to cause any problems for any target devices?

BTW I've seen the delta timing sample - not quite what I'm after though.

As a side question...
Any ideas what the expected result of the (currently default) SetUpdateRate(0) should be?

I'm seeing what looks to be 10 calls per second to my OnRender() and zero (as expected) calls to OnUpdate(). I'm guessing it's safer to just set it myself anyway.

Also, with v32 I experimented with negative update rates, which perhaps was calling OnRender() as fast as possible? But v33 now seems to lock up my browser (FF4) with negative values. No big deal as it probably shouldn't allow them anyway.

Thanks.


Perturbatio(Posted 2011) [#2]
If I recall correctly, OnRender isn't guaranteed to be called at all, it will only get called if there is enough time.


Xaron(Posted 2011) [#3]
Hmm... Actually I would see to have OnRender called only when it's necessary. It doesn't make any sense to me to call it as often as possible. Render should only render. All tweening should be done in OnUpdate or am I wrong here?


Pudsy(Posted 2011) [#4]
What I was trying to achieve is (on devices that might cope with it) a higher frame-rate (tweened) while retaining the game update rate of eg. 30 or possibly less.

But the problem is that SetUpdateRate(30) limits rendering to 30 fps too - and as mentioned, that's only if there is enough time for that many render calls.

I guess if I had a rate of eg. 60, OnUpdate() can simply update the game eg. every other tick (or monitor it's own timer), but OnRender can always draw (with tweening).

That would keep the updates out of OnRender().