Delta Timing?

Blitz3D Forums/Blitz3D Programming/Delta Timing?

This is what I ended up using
It works best as far as smoothing.
apologies to who ever contributed to this.
There are a few extra variables in the
code. Looks like it's time to clean out a
few of those


;for timing
Global frames
Global r_time
Global fpscount
Global render_time 
Global multiplier#=0.2
Global multiplier2#
Global xspeed=10
Global AvgMultiplier#
Dim AvgMult#(10)
Global AvgMultiplierCount
Global TimePerFrame#
Global Second_Timer

SetFrameRate(30)
Const  TARGET_FPS# = 30.0	
Global previous% = MilliSecs()	
Global lastFPS%  = MilliSecs()

while

	now%   = MilliSecs()
	delta# = (now - previous) / (1000 / TARGET_FPS)
	If delta <= 0 Then delta = 0.001
	previous = now

wend

Function CalcTimer#()

	ms_passed#=MilliSecs()-render_time
	render_time=MilliSecs()
	multiplier#=(multiplier#*4.0 + Float(ms_passed#/ TimePerFrame))/5.0
	If multiplier# >2 Then multiplier#=2
	;Get fps
	frames=frames+1
	If MilliSecs()-r_time=>1000 Then fpscount=frames : frames=0 : r_time=MilliSecs()
 
End Function

;initilalize timer
Function SetFrameRate(FPS)
    TimePerFrame = (1000.0 / FPS)
	render_time=MilliSecs()
End Function