News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Possible SetFPS() / FPS() bug

Started by thaaks, December 29, 2005, 05:05:58 PM

Previous topic - Next topic

thaaks

Hi,
if you run this code, all works as expected.

SetFPS 60

do
cls 0
text 100,100, "FPS test, FPS is " + Str$(FPS()) + ", max FPS should be " + Str$(GetFPS())
sync
loop


The FPS always is around the value of 60 (mostly 57) on my machine.

But if you run this code

SetFPS 60

do
cls 0
bla = FPS()
text 100,100, "FPS test, FPS is " + Str$(FPS()) + ", max FPS should be " + Str$(GetFPS())
sync
loop

the FPS is doubled. You can increase the FPS by copy/pasting the bla=FPS() line.

Is that on purpose? I doubt it.
I would guess that I can call FPS() as many times as I want without affecting the real FPS value...

Took me a while until I figured out why my SetFPS wasn't working as expected...

Any ideas, Kevin???

Cheers,
Tommy

kevin

Each time you call FPS(), it actually calculates the rate.  So If you call it twice per frame, the returned rate will double, if you call 3 times the frame returned rate will triple.. etc

Solution, only call it once per frame :)

thaaks

QuoteEach time you call FPS(), it actually calculates the rate.  So If you call it twice per frame, the returned rate will double, if you call 3 times the frame returned rate will triple.. etc

Solution, only call it once per frame :)

Hmmm, if FPS() calculates the rate, why would the result change, just by calculating it? :huh:

The online help for FPS() says:
QuoteThe FPS function returns the current number of frame redraws (sync's) that were drawn over the past second.
The number of frame redraws over the past second should not change, no matter how often I call FPS().

I can deal with the solution (calling FPS() only once per frame) and I don't want to be fussy but could you explain why this is not a bug?

Cheers,
Tommy

kevin

urm, here's why.  :)




Do
Cls 0

 Print CalcFps()
 Print Fps()

 if Spacekey()
  Print CalcFps()
  Print Fps()
 endif


sync
loop



Function CalcFPS()
  Static FPS_NextSecond, FPS_CurrentRate, FPS_TempRate

  CurrentTimer=Timer()
  If currenttimer>FPS_NextSecond
   FPS_NextSecond=CurrentTimer+1000
 FPS_CurrentRate=FPS_TempRate
 FPS_TempRate=0
Else
 FPS_TempRate=FPS_TempRate+1
  EndIf
EndFunction FPS_CurrentRate



thaaks

Aaah, got it.
Then maybe you should enhance the online help and note that FPS() should only be called once in the main loop.

Thanks for explaining it!

Tommy