finding fps

Blitz3D Forums/Blitz3D Beginners Area/finding fps

killertomato(Posted 2007) [#1]
hi,

I was wondering, how would I get Blitz to print the fps on screen?

Thanks in advance


Naughty Alien(Posted 2007) [#2]
..here you go...

http://home.cmit.net/rwolbeck/programmingtutorial/


Matty(Posted 2007) [#3]
in your main loop do something like this

repeat

;game stuff goes here, 



updateworld
renderworld
fpscount=fpscount+1
if millisecs()>fpstime then 
    fpstime=millisecs()+1000
    fps=fpscount
    fpscount=0
endif 
text 0,0,"FPS:"+fps
flip

until keydown(1)






Stevie G(Posted 2007) [#4]
Here's one I use ... not sure who wrote it but you can set the update frequency.

Global FPSlastupdatetime
Global FPSframecount
Global FPSlastcount#


Function FPS(frequency=200)

	time=MilliSecs()
	FPSframecount=FPSframecount+1
	elapsed#=time-FPSlastupdatetime
	If elapsed>=frequency
		FPSlastcount=FPSframecount/elapsed*1000.0
		FPSframecount=0
		FPSlastupdatetime=time 
	EndIf
	Return FPSlastcount
	
End Function 



Fernhout(Posted 2007) [#5]
I am a beginner to. But is the Function in this case not a bit out of tune. Cause you can call the function in a game loop more then one time.

don't get me wrong. Its just a idea of it.


Stevie G(Posted 2007) [#6]
Which function? You should be only calling a FPS once per main game loop.


puki(Posted 2007) [#7]
Here is one "halo" posted circa a year ago - I just found it whilst looking at other stuff - not sure how good it is, but it is one of "halo's" so it must be pretty good:

This function will update the FPS every time period specified by the frequency parameter, which is set to 200 msecs by default. It takes an average of the elapsed time period, not just a measurement of the last frame. This also makes it easier to read the value when printed on the screen.

Global FPSLASTUPDATETIME
Global FPSFRAMECOUNT
Global FPSLASTCOUNT#

Function FPS#(frequency=200)
time=MilliSecs()
FPSFRAMECOUNT=FPSFRAMECOUNT+1
elapsed#=time-FPSLASTUPDATETIME
If elapsed>=frequency
FPSLASTCOUNT=FPSFRAMECOUNT/elapsed*1000.0
FPSFRAMECOUNT=0
FPSLASTUPDATETIME=time
EndIf
Return FPSLASTCOUNT
End Function