What is game time based on? Real time or frame?

I am developing a game for the first time, but I wonder what the playing time is based on. Is it based on watches or relies on frames? (Note: I'm not sure that “playing time” is the right word here, correct me if it is not)

To be more clear, imagine these scenarios:

  • Computer 1 runs fast, up to 60 frames per second
  • Computer 2 runs slowly, no more than 30 frames per second

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

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

My question is: what is the best way to handle playing time and what are the advantages and disadvantages?

+6
language-agnostic
source share
9 answers

Indeed, in older games, frame counting was used. It became pretty obvious that this was a bad idea, as cars are getting new, and therefore games are faster.

Thus, set it to the system clock. Typically, this is done, knowing how long the last frame lasted, and using this number to find out how much "real time" will go through this frame.

+7
source share

In general, in commercial games there are two things: the "simulation" cycle and the "rendering" cycle. They should be as free as possible.

You want to correct your simulation time interval to a value (greater than or equal to the maximum frame rate). Complex physics does not like variable time steps. I am surprised that no one mentioned this, but fixed-time steps compared to 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 cycle can work as fast as possible and display the output of the current simulation step.

So, referring to your example:

You will run the simulation at 60 frames per second, which is 16.67 ms. Computer A will display at 60 frames per second, i.e. Will display each simulation frame. Computer B will display every second simulation frame. Thus, the character will move the same distance at the same time, but not so smoothly.

+10
source share

It should rely on the system clock, not the number of frames. You made your own case for this.

+3
source share

FPS is simply the size of a frame that a computer can display per second.

Game time is game time. You define it. It is often called the "Game Loop". Frame rendering is part of the game loop. Also check out FSM related to game programming.

I highly recommend you read a couple of books on game programming. The question you ask is what these books explain in the first chapters.

+1
source share

For each user who has the same experience, you will want to use the actual time, otherwise different users will have advantages / disadvantages depending on their equipment.

0
source share

Games should use clocks, not frames, to provide the same gameplay regardless of platform. This is obvious when you look at MMOs or online shooters: no player should be faster than others.

0
source share

It depends on what you are processing, which part of the game is in question.

For example, animations, physics, and AI must be frequency independent in order to function properly. If you have an FPS-dependent animation or physical flow, then the physical system will slow down, or the character will move slower on slower systems and will work incredibly fast on very fast systems. Not good.

For some other elements, such as scripting and rendering, you obviously need to have it for each frame and therefore depend on the frame rate. You would like to process each script and render each object once per frame, regardless of the time difference between frames.

0
source share

The game should be based on the system clock. Since you do not want your game to play on decent computers recently!

0
source share

Games typically use the highest resolution timer, such as QueryPerformanceCounter, for Windows. Old games were used to use frames, but after you could literally run faster in Quake by changing FPS, we learned how to no longer do this.

0
source share

All Articles