Skip to main content
gamedev.net
🔒 Locked

Odd Timer problem

Started by matt3d Jun 16, 2007 at 4:49 PM 0 replies 550+ views
Original Post
matt3d
matt3d
I have a basic framework for a 3d world I am creating. I just have some rotating objects and player input (to move around the world) so I have just implemented standard timer code for my game loop. However, as the game starts, everything that is run in the loop begin to speed up. For instance, my rotating objects increase and increase in rotational speed. I also have keyboard to camera input running here as well and the keypresses also are effected (as camera movement is effected by timeDelta). So as the game runs the movement becomes more sensitive. Here is my code with only the necessary bits intact..

function gameLoop()
{
   static float lastTime = (float)timeGetTime(); 

   while(!mDone)
   {
      float currTime  = (float)timeGetTime();
      float timeDelta = (currTime - lastTime)*0.001f;
   
      // do stuff (timeDelta)
   
      lastTime = currTime;
   }
}
erissian
erissian
#1: Try using a threshold for your time delta. Often times the actual steps involved with be very, very small, to the point of being around your epsilon. If anything productive happens, it's because the delta errors on the positive side, and there's enough cumulative error to push it forward. Once things start happening, and processing takes long, then delta may genuinely start increasing to 1ms, maybe even 2ms. When that happens, you'll see things start to take larger jumps. Even though it should come out the same, it most likely won't because you're simulating at a lower resolution all of a sudden. If you have any kind of decent machine, there's a good chance that your time delta is very near 0, since timeGetTime has a millisecond resolution.

So try something like:
if (timeDelta < timeThreshold)  continue;// do stuff


#2. If you want to keep results consistent, you should use a constant time step. This is sort of a compromise between the predictability of using frames and the independence of using actual time. Typically, I pass whatever my threshold is as the dt argument.

If I were going to suggest a threshold, I would say anywhere from 5-20ms.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.