Main loop - does everyone do the same stuff ?

Blitz3D Forums/Blitz3D Beginners Area/Main loop - does everyone do the same stuff ?

A simpler method of putting a choke on the delta time is to simply limit the result from the calculation of the amount of time taken for the last loop.

eg.

If the_time_taken > 100 Then the_time_taken = 100

Function CalculateDeltaTimeAndLocalTime()
; NOTES:
; The variable 'old_time' must be set to the current 'MilliSecs ()' time at the start of a new game and when returning from a pause.

	milli_secs = MilliSecs () ; Store the 'MilliSecs ()' time in the 'milli_secs' global variable so that you can use the stored time value without calling 'MilliSecs ()' again in this loop.

	the_time_taken = milli_secs - old_time ; Calculate the time the last loop took to execute.
	If the_time_taken > 100 Then the_time_taken = 100 ; This applys a choke to the delta timing to stop stalls caused by disk accesses and the like from causing abrupt jumps in position.
	local_time = local_time + the_time_taken ; Calculate the value for the 'local_time' global variable used with timeouts, etc.
	Delta_Time# = the_time_taken / 1000.0 ; Calculate the value for the 'Delta_Time#' global variable used to regulate game speed.
	old_time = milli_secs ; Update the 'old_time' global variable with the current time.

End Function