Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On what is game time based? Real time or frames?

I'm designing a game for the first time, but I wonder on what game time is based. Is it based on the clock or does it rely on frames? (Note: I'm not sure if 'game time' is the right word here, correct me if it isn't)

To be more clear, imagine these scenarios:

  1. Computer 1 is fast, up to 60fps
  2. Computer 2 is slow, not more than 30fps

On both computers the same game is played, in which a character walks at the same speed.

If game time is based on frames, the character would move twice as fast on computer 1. On the other hand, if game time was based on actual time, computer 1 would show twice as much frames, but the character would move just as fast as on computer 2.

My question is, what is the best way to deal with game time and what are advantages and disadvantages?

like image 630
Harmen Avatar asked Jun 28 '10 18:06

Harmen


2 Answers

In general, commercial games have two things running - a "simulation" loop and a "rendering" loop. These need to be decoupled as much as possible.

You want to fix your simulation time-step to some value (greater or equal to your maximum framerate). Complex physics doesn't like variable time steps. I'm surprised no-one has mentioned this, but fixed-time steps versus variable time steps are a big deal if you have any kind of interesting physics. Here's a good link: http://gafferongames.com/game-physics/fix-your-timestep/

Then your rendering loop can run as fast as possible, and render the output of the current simulation step.

So, referring to your example:

You would run your simulation at 60fps, that is 16.67ms time step. Computer A would render at 60fps, ie it would render every simulation frame. Computer B would render every second simulation frame. Thus the character would move the same distance in the same time, but not as smoothly.

like image 199
Justicle Avatar answered Oct 20 '22 18:10

Justicle


Really old games used a frame-count. It became fairly obvious quickly that this was a poor idea, since machines get newer, and thus the games run faster.

Thus, base it on the system clock. Generally this is done by knowing how long last frame took, and using that number to know how much 'real time' to go through this frame.

like image 21
zebediah49 Avatar answered Oct 20 '22 19:10

zebediah49