Sign in to follow this  
jdub

Newbie confused on Fixed Time steps

Recommended Posts

I have been googling around a lot lately for information with regards to Fixed Timesteps in games. I From the 2 tutorials that I have seen (Gaffer,flipcode) I am still left in the blue. 1) When you update the game, if updating takes too long, you update again and skip rendering right? How do you know if your game has taken too long to update? 2) I had an idea. As you went through updating and rendering frames, you could keep track of the amount of time that it takes to Update the current frame and average that time with previous times that it has taken to update. Then, every new frame, you could perform an update and if it took longer previous averaged update times, you would skip rendering and update again. Would this be a viable solution

Share this post


Link to post
Share on other sites
You're not being very explicit, but since you say rendering, is it correct to assume you mean openGL/DirectX?

I have never used DirectX, but in openGL, you really don't have to worry about any of that stuff. Most openGL programs use a double display buffer. This means that you render into the back buffer, and display the front buffer. When you call "glPostRedisplay()" it will automatically switch the buffers whenever the next frame is ready.

It is very easy to tell the amount of time since your last render, too, if you want to do FPS calculations. Just take a time-stamp in your display function :P

Share this post


Link to post
Share on other sites
Quote:
I have never used DirectX, but in openGL, you really don't have to worry about any of that stuff. Most openGL programs use a double display buffer. This means that you render into the back buffer, and display the front buffer. When you call "glPostRedisplay()" it will automatically switch the buffers whenever the next frame is ready.

It is very easy to tell the amount of time since your last render, too, if you want to do FPS calculations. Just take a time-stamp in your display function :P
I'm not sure if that really relates to what the OP is asking about. He appears to be asking about fixed time steps for game updates, which can be important for a few different reasons (reproducibility, consistent behavior in physics simulations).

When using a fixed time step, it's not always obvious how the render and update cycles should be related, and I think this is what the OP is trying to figure out.

@The OP: Here is an article on the subject. I can't comment on its quality, but it's frequently cited when this topic comes up.

Share this post


Link to post
Share on other sites
AFAIK you take the time passed since your last update and squeeze as much game updates as possible in that time frame, remembering the modulo. For example say your time step is 5ms and 12 ms have passed since the last update you do two time steps in this update, leaving you with "extra" 2ms.

Hope this makes sense.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this