' ------------------------------------------------------------------------------------------------
' Exact FPS counter
' ------------------------------------------------------------------------------------------------

Type TFPS

	Global renders:Int = 0

	Field fps:Int = 60										' current FPS value
	Field averagefps:Int = 60								' average FPS value
	Field framedrops:Int = 0								' dropped frames
	Field memory:Int = 0									' used memory
	Field oldlooptime:Int = 0
	Field looptime:Int = 0
	Field multi:Float										' main loop multiplicator

	Field old:Int = MilliSecs()
	Field totalfps:Int = 0
	Field ticks:Int

	' --------------------------------------------------------------------------------------------
	' METHOD: Update FPS counter
	' --------------------------------------------------------------------------------------------
	Method Update()

		renders:+1

		looptime = MilliSecs() - oldlooptime
		oldlooptime = MilliSecs()

		If MilliSecs() - old >= 1000 Then

			old = MilliSecs()

			FPS = renders
			renders = 0
			totalfps:+FPS
			ticks:+1
			
			averagefps = totalfps / ticks

			memory = GCMemAlloced()

		EndIf

	End Method

End Type