SetUpdateRate(60) But FPS=120?

Monkey Forums/Monkey Programming/SetUpdateRate(60) But FPS=120?

c.k.(Posted 2012) [#1]
Would it be possible to have a SetUpdateRate(60) command in OnCreate, but be getting FPS of up to 120? I ask because that's what seems to be happening for me, but it doesn't make sense.

I probably just don't understand. Does SetUpdateRate() specify a MINIMUM rate? (Maybe I should just RTFM. Which I will do, but feel free to pipe up here.)

THANKS! :-)


GfK(Posted 2012) [#2]
Setupdaterate sets the maximum number of times the update method will be called per second. Nothing to do with frames per second.


c.k.(Posted 2012) [#3]
GfK, the docs say SetUpdateRate() determines FPS.

From http://blitz-wiki.appspot.com/SetUpdateRate:

"...SetUpdateRate effectively also sets the target frames per second."

So, I'm confused somewhat.

I'm using fantomEngine, so maybe there's a bug (Michael?).


muddy_shoes(Posted 2012) [#4]
Different targets have different behaviours. Gfk is right that SetUpdateRate doesn't set the frame rate, but the docs are also right that a standard mojo app has the intent of a 1-to-1 relationship between update and render.

Without code there's not a lot that can be said about why you're seeing 120FPS for an update rate of 60. You could be measuring wrong. You could be calling your render code twice per update.


DruggedBunny(Posted 2012) [#5]
It might depend on how you (or fantomEngine) are measuring the FPS, and whether that's within OnUpdate or OnRender.

Oh, edit: what he said. ^^^


Neuro(Posted 2012) [#6]
I'm using fantomEngine, so maybe there's a bug (Michael?).

Are you calling eng.GetFPS() more than once?


c.k.(Posted 2012) [#7]
Interesting, Neuro.

I was referencing eng.GetFPS() once in the OnUpdate(), as well as once in the OnRender.

In the OnUpdate(), I was doing:

[monkeycode]
txtFPS.SetText( "FPS: " + eng.GetFPS() )
[/monkeycode]

In the OnRender(), I was doing

[monkeycode]
FPS = eng.GetFPS()
[/monkeycode]

FPS is a field of the game class. It was not being used anywhere except right there, in that assignment.

Once I commented out the OnRender() reference to GetFPS(), I get the expected ~60fps displayed onscreen. Woohoo!

However... WHY does calling it once in OnRender() and once in OnUpdate() DOUBLE the FPS count? That doesn't make sense. It should give me an accurate rendering each time it's called, no matter from where! Right? :-D

Anyway, thanks for the heads-up! :-)


Samah(Posted 2012) [#8]
I'm assuming GetFPS() updates the frame counter as well as calculating the FPS. Calling it in both OnUpdate() and OnRender() would increment the frame counter by two every frame, essentially giving you 120 per second.

This is why "getters" shouldn't modify values. Move the frame counter increment into a separate Update() that's called once every frame.


MikeHart(Posted 2012) [#9]
The guys are right. Just call GetFPS once. Everytime you call this it is recalculated. As oyu are not the first one who has problems with its behaviour, I will think about a different method.