Sign in to follow this  
Wavesonics

Do most engines use fixed or variable time step for game logic?

Recommended Posts

Wavesonics    330
Well the title pretty much says it all, do most engines use a fixed time step or variable time step for game logic? such as:

// Fixed size steps
while( true ) {
   for( frameTimer % stepSize ) {
       stepGame();
   }
}

// Varriable size steps
while( true ) {
   stepGame( frameTime ); // Everything that wants frame rate independence scales it's self by the frame time
}

Quake based engines? Ogre?

Share this post


Link to post
Share on other sites
dietepiet    157
I recall that Age of Empires (And probably most RTS games with networking) uses a fixed step size in order to keep all peers in the game fully synchronised.

Share this post


Link to post
Share on other sites
ToohrVyk    1596
The second version, as you described it, is very non-robust, because it will update things independently of each other, and create issues with objects creating in the middle of the time step. It's always necessary to perform collision handling checks (or similar cross-object operations) "at the right time": either at a fixed step which guarantees that everything behaves with enough granularity, or by using collision detection and executing things with a variable time step using an event scheduler.

In the end, both fixed-step and variable-step engines have their purposes. Fixed-step updates are usually best used for networking because they're much easier to work with, while variable-step updates are better at expressing durations in script code.

However, the choice is not fixed. It's possible to use a fixed-step engine as if it were variable-step, and a variable-step engine as if it were fixed-step.

Share this post


Link to post
Share on other sites
Zipster    2365
Most of the engines I've worked with use a variable time-step in most systems. You only need to run your update code once, and in most cases It Just Works™. But there are a lot of times (physics, collision detection, and networking come to mind) where variable time-steps cause a lot of trouble. In those cases you can easily retrofit fixed time-step logic into the relevant systems using the variable time-step. So the bottom line is, it depends!

As for games that are heavily synchronized, usually it doesn't matter whether you're using fixed or variable time-step since synchronization would be based on something like the frame number (which is why such games are always no faster than the slowest machine).

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