Frame rate counter

BlitzPlus Forums/BlitzPlus Programming/Frame rate counter

WoeIsMe(Posted 2003) [#1]
I've done a bit of code to show the frame rate of my game, but it seems to change the number a lot. Is this normal/to do with my game, or is there a better way of designing a frame rate counter?

here's the code

If debug=1 Then 
nowmillisecs#=MilliSecs()-lastmillisecs#
	Color 150,150,0
	Rect 600,500,150,50
	SetFont ammostatfont
	Color 255,255,255	
	Text 610,510,nowmillisecs+"ms/f"
	Text 610,530,1/(nowmillisecs#/1000)+" FPS"
EndIf

lastmillisecs#=MilliSecs()



It shows the frame rate in milliseconds per frame (ms/f) and frames per second (fps)


MadMax(Posted 2003) [#2]
Try this, dunno but it may suit you

Graphics 800,600,16

SetBuffer BackBuffer()

ffps=MilliSecs()


While Not KeyDown(1)

Cls

;******************************************



;       MAIN CODE HERE




;******************************************

conta=conta+1

If MilliSecs()=>ffps+1000
ffps=MilliSecs()
fps=conta
conta=0
EndIf

Text 20,40,"FPS :"+fps

Flip True

Wend

End



WolRon(Posted 2003) [#3]
You could take the average of so many samples so that the numbers wouldn't change so much. Say, every other frame or fifth frame.


Ross C(Posted 2003) [#4]
try this. it will update the fps every second.

graphics 800,600
setbuffer backbuffer()

while not keyhit(1)
        cls

	If MilliSecs()<timer+1000 Then
								    frame=frame+1
	Else
								    fps=frame
								    frame=0
								    timer=MilliSecs()
	End If

        text 0,0,"fps="+fps
        flip
wend
end



Ross C(Posted 2003) [#5]
oh and change
flip

to
flip false


to get the true fps, (turns off wait for vsync)


QuickSilva(Posted 2003) [#6]
My game has gone from running at a constant 85 fps to 75 for some reason that I cannot fathom. I had to re-install my OS and now the exact same code runs at 10 frames slower. Any ideas as to what could cause this? I`m still in a screen mode with a 85mhz update rate and am using the lastest nvdia drivers that I had before.

Jason.


MadMax(Posted 2003) [#7]
That's very odd, have a look at your windows set up, and look at the refresh rate it has set.


Ross C(Posted 2003) [#8]
use flip false to see what the fps is actually


WolRon(Posted 2003) [#9]
Something running in the background (of Windows) that wasn't before?


DrMartin(Posted 2003) [#10]
You have just lowered the refreshrate of your monitor from 85 to 75). Flip by default waits for the monitor to refresh the entire screen (which is done for example 75 times per second) before drawing a new frame. As joker pointed out, use Flip false instead of flip to disable the monitor-waiting.


WoeIsMe(Posted 2003) [#11]
Thanks. I decided to take an average frame rate and got a reading of 62/63 FPS. It should be running at about 60, so that's good, and I can tell it's working because I can slow it down when I want (by adding an extra WaitTimer) and the numbers follow.


QuickSilva(Posted 2003) [#12]
I found out what the problem was. As I said before I was still in a monitor mode with a 85mhz refresh rate so that wasn`t the problem. I found that after I installed DirectX 9 again (I had forgotten to and was still using version 8) I regained my extra ten frames and was back to 85fps. Does this mean that the latest NVidia drivers work at there best with DX9 installed? Has anybody else experienced this?

Jason.