Timing Problems

BlitzMax Forums/BlitzMax Programming/Timing Problems

SSS(Posted 2008) [#1]
I know that there are many threads on the subject of Delta Timing but I couldn't find anything that addresses the problem I'm having. Basically I calculate the ratio for my timing every frame using the following code:
Function Calculate()
	Local dt# = MilliSecs()-_oldtime
	 _actualrate = 1000/dt
	_ratio = _framerate/_actualrate
	_oldtime = MilliSecs()
End Function

The problem is that the ratio varies wildly from frame to frame. It even becomes negative at times. This, obviously, results in very jumpy behavior. The funny thing is that I've used this before and it worked fairly well. Does anyone have any idea why it's not working? If it makes any difference I'm using the Chipmunk Physics Engine as well.


tonyg(Posted 2008) [#2]
What are the values of your variables when you get an unexpected ratio? I would decide what might be 'odd' (e.g. negative) and then write out the values at that time. It might just be one variable being calculated incorrectly.


Muttley(Posted 2008) [#3]
It's not really a good idea to use delta timing with most physics libraries. Fixed timestep stuff is where it's at.

http://www.gaffer.org/game-physics/fix-your-timestep