Hertz and Flip

BlitzMax Forums/BlitzMax Beginners Area/Hertz and Flip

This thread and article describes it well.

http://www.blitzbasic.com/Community/posts.php?topic=57977

here's mine from Easter Bonus (Blitz Plus):

	;timing vars
	Global LastTime%
	Global NumTicks#
	Global LastNumTicks#

Function InitTimingVars()
	;set a first value for LastTime (it will be used in the main loop)
	LastTime = MilliSecs()/MS
	NumTicks = 0
	LastNumTicks = 1	
End Function

	InitTimingVars()
	
	Repeat
		If DoVWait Then
			;for our purposes, a tick is based on FRAMERATE
			;get in the time and make sure at least 1 tick expired
			Repeat
				TmpMS = MilliSecs()/MS
		
				;little sanity check here in case the timer flips back to 0 :)
				If TmpMS < LastTime Then LastTime = TmpMS - LastNumTicks
		
				NumTicks = TmpMS - LastTime
			Until NumTicks > 0
			LastTime = TmpMS
			;account for when the user alt-tabs :)
			;If NumTicks > 500 Then NumTicks = LastNumTicks
			If NumTicks > 50 Then NumTicks = 50 ;LastNumTicks ;Laptop runs at 7 in windowed mode
			LastNumTicks = NumTicks		
			If NumTicks > MaxTicks Then MaxTicks = NumTicks
		EndIf
		
		;now we do the logic loop ... from 1 not 0!
		;don't do ticks as it @#!*s things up
		For i = 1 To NumTicks

                     ;logic
                Next

                DrawStuff()
                Flip
	Until LoopExit <> 0