about fps control

BlitzMax Forums/BlitzMax Beginners Area/about fps control

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

here a code from Indiepath. Should i now 'paste' my main loop 'inside' the RenderGFX() function ?
i'm very bad with fps limitation !!!

initial post : http://www.blitzbasic.com/Community/posts.php?topic=49306&hl=delta%20time

Graphics 800,600,32,NOSYNC

Type DeltaTime
	Global DeltaTList:TList

	Field OldTime:Double
	Field ElapsedTime:Double
	Field Delta:Double
	Field dFps:Double
	Field dDelta:Double
	Field CurrFps:Double
	Field FPSCounter:Double
	Field CurrTime:Double
	Field CheckTime:Double
	
		Method New ()
            	If DeltaTList = Null Then DeltaTList = New TList
            	DeltaTList.AddLast Self
    	End Method		
		
		Method Destroy ()
            	DeltaTList.Remove Self
        End Method

	
		Function Create:DeltaTime(Fps:Double)
			Local dTime:DeltaTime = New DeltaTime
			dTime.Delta = 1
			dTime.dFps = Fps
			dTime.dDelta = 1000/Fps
			Return dTime
		End Function
		
		Function Update()
			Local dTime:DeltaTime
			For dTime:DeltaTime = EachIn DeltaTList
				dTime.CurrTime = MilliSecs()
				dTime.ElapsedTime = dTime.CurrTime - dTime.OldTime
				dTime.OldTime = dTime.CurrTime
				
				If dTime.CurrTime > dTime.CheckTime
					dTime.CheckTime = dTime.CurrTime + 1000
					dTime.CurrFps = dTime.FPSCounter
					dTime.FPSCounter = 0
				Else
					dTime.FPSCounter:+1
				EndIf
			Next
			
		End Function
		
		Function FPS(dTime:DeltaTime)
			Return dTime.CurrFps
		End Function
		
		Function CurrDelta:Double(dTime:DeltaTime)
			Return dTime.ElapsedTime/dTime.dDelta
		End Function
		
End Type


SetMaskColor(255,0,255)
'Global blob:TImage = LoadImage("C:\blitzmax\samples\simonh\fireworks\spark.png")


Global Delta1:DeltaTime = DeltaTime.Create(60) ' Normal 35 FPS
Local  Delta:Double

Global ScreenUpdate:Double
Global bx:Double=10

While Not KeyHit(KEY_ESCAPE)

	DeltaTime.Update()
	
	Delta = DeltaTime.CurrDelta(Delta1)
	
	If Delta > 1 Then Delta = 1 ' Delta should never be bigger than 1.
	
	' -------------------------------GFX FUNCTIONS ---------------------------
	ScreenUpdate = ScreenUpdate + Delta

	
	If ScreenUpdate > 0.30 Then
		Cls
	
		RenderGFX(ScreenUpdate)
		ScreenUpdate = 0
		Flip
	EndIf	
	
	' ------------------------------------------------------------------------
	
'	FlushMem
	
Wend


Function RenderGFX(Delta:Double=1)
		DrawOval bx,100,10,10

			bx=bx+(Delta * 2)
	
	DrawText DeltaTime.FPS(Delta1)+" FPS",10,10

		If bx>799 Then bx = 0
End Function