Sign in to follow this  
paradise

How to obtain frame rate independence??

Recommended Posts

Hi , I am making a car game and I need to get frame rate independence to get some restrictions done in the game. Please tell me as many ways to obtain frame rate independence in the game loop . Thank You

Share this post


Link to post
Share on other sites
You want your rendering/rasterization to be independant of all the calculations that need to be done with your AI/Physics? If this is the case you could multi-thread your app so that people w/ dual-core processors or multi-processor systems could do that.

Share this post


Link to post
Share on other sites
Get the time elapsed since the beginning of the game (or the level, or whatever arbitrary origin of time you choose). Divide this time by the duration of a logical step: this will give you the amount of steps that should have been performed since then.

Now, count the number of steps you actually did. If it is smaller than the one you computed, perform some additional steps so you keep up. If it is equal, wait a little (or spend some time rendering or doing some background task). It will never be greater by definition.

So in the end, you have framerate-independent logical steps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Have you tried using threads? ie. create the main vehcile dynamics in a seperate thread and update your position and rotational matrices in a shared structure which your game loop (probably at a slower rate) can use when it needs to update the eyepoint / geometry.

Mr. Creamy

Share this post


Link to post
Share on other sites
Quote:
Original post by paradise
Please tell me as many ways to obtain frame rate independence in the game loop .

fix your timestep. Not abso-exact-lutely the same thing, but the final code leads to what you want, plus the explanations provided are very nice.

Share this post


Link to post
Share on other sites
The duel threads method mentioned a couple of times here is a good way to handle this, I've waffled a bit about my own implimentation (inspired by something Superpig mentioned a while bacl) which gives quiet acceptable results for 8 spining cubes at least [wink]
Once I get some free time I'm going to try and improve it so the structure is better (currently a hack job) and have it handling more complex cases to see how things scale on a single CPU system (I currently dont have access to a duel core system for testing, which is a shame).

Share this post


Link to post
Share on other sites
Thank you all for the replies.


and genjix,could you please explain what are "time" and "pause time" variable ??


while not done:
timetaken = GetTime()

dostuff()

timetaken = GetTime() - time

if timetaken > 0:
Pause(pausetime - timetaken)


I'm not understanding how this is leading to frame rate independence ??

Share this post


Link to post
Share on other sites
Quote:
Original post by tolaris
Quote:
Original post by paradise
Please tell me as many ways to obtain frame rate independence in the game loop .

fix your timestep. Not abso-exact-lutely the same thing, but the final code leads to what you want, plus the explanations provided are very nice.

Seconded.

Share this post


Link to post
Share on other sites
Just have a timestep size, greater than you're likely to have FPS. Like 100 or something.

Then do


do {
while (ticks done < ticks passed to date) {
Do a tick;
}
Render();
} while (true)


Of course you might want to put in a maximum number of ticks between frames, so that if the FPS becomes too low, you don't end up doing too many ticks (slow the game down instead). Essentially limit the number of frame skips to 10 or something.

If your rendering ends up happening faster than 1 tick, you'll simply render the same frame twice.

Or you could use interpolation, but that is more complicated.

Don't use threads unless you realise all the implications of doing so and are prepared to live with them.

Mark

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