views:

545

answers:

9

What update rate should I run my fixed-rate game logic at?

I've used 60 updates per second in the past, but that's hard because it's not an even number of updates per second (16.666666). My current games uses 100, but that seems like overkill for most things.

A: 

Can you expand on what it is you are asking here?

Game updates in what sense?

Bob Chatman
A: 

Bear in mind that unless your code is measured down to the cycle, not each game loop will take the same number of milliseconds to complete - so 16.6666 being irrational is not an issue really as you will need to time and compensate anyway. Besides it's not 16.6666 updates per second, but the average number of milliseconds your game loop should be targeting.

Richard Franks
A: 

Such variables are generally best found via the guess and check strategy.

Implement your game logic in such a way that is refresh agnostic (Say for instance, exposing the ms/update as a variable, and using it in any calculations), then play around with the refresh until it works, and then keep it there.

As a short term solution, if you want an even update rate but don't care about the evenness of the updates per second, 15ms is close to 60 updates/sec. While if you are about both, your closest options is 20ms or 50 updates/sec is probably the closest you are going to get.

In either case, I would simply treat time as a double (Or a long with high-resolution), and provide the rate to your game as a variable, rather then hard coding them.

Guvante
A: 

The ideal is to run at the same refresh-rate as the monitor. That way your visuals and the game updates don't go in and out of phase with each other. The fact that each frame doesn't last an integral number of milliseconds shouldn't matter to you; why is that a problem?

+7  A: 

None of the above. For the smoothest gameplay possible, your game should be time-based, not frame-locked. Frame-locking works for simple games where you can tweak the logic and lock down the framerate. It doesn't do so well with modern 3D titles where the framerate jumps all over the board and the screen may not be VSynced.

All you need to do is figure out how fast an object should be going (i.e. virtual units per second), compute the amount of time since the last frame, scale the number of virtual units to match the amount of time that has passed, then add those values to your object's position. Voila! Time-based movement.

64BitBob
Doom 3 ran on a fixed 60fps, as do many games.
mos
This often doesn't work well with (eg) physics. Many games (such as Half Life 2 for one) use a fixed timestep game-loop, and will run the game-logic multiple times in a single frame to cover the duration of the frame.
Mos: Open your NVidia or ATI control panel and find the setting for "Vertical Sync". Flip it to "off". Run Doom 3 and see if it still runs at an exact 60 FPS.
64BitBob
Bob: Doom will draw frames as fast as it possibly can. But it's not running the game-logic every frame it draws, only interpolating the worldstate between the previous and current game updates.
A: 

I usually use 30 or 33. It's often enough for the user to feel the flow and rare enough not to hog the CPU too much.

Milan Babuškov
A: 

Normally I don't limit the FPS of the game, instead I change all my logic to take the time elapsed from last frame as input.

As far as fixed-rate goes, unless you need a high rate for any reason, you should use something like 25/30. That should be enough rate, and will be making your game a little lighter on CPU usage.

mrlinx
God, I wish people would stop with this "can't notice frames above 25 or 30 fps" garbage.
mos
Download the fpscmp02.zip file from this site to see the difference between 30 and 60 with your own eyes.http://forums.gameon.co.uk/showthread.php?t=9989
mos
+2  A: 

I like 50 for fixed rate pc games. I can't really tell the difference between 50 and 60 (and if you are making a game that can/cares you should probably be at 100).

you'll notice the question is 'fixed-rate game logic' and not 'draw loop'. For clarity, the code will look something like:

while(1) 
{ 
  while(CurrentTime() < lastUpdate + TICK_LENGTH) 
  { 
     UpdateGame(); 
     lastUpdate += TICK_LENGTH;
  } 

  Draw();
}

The question is what should TICK_LENGTH be?

Jeff
But then if the monitor is running at 60Hz then every 5th frame will be displayed for two frames instead of one, leading to a nasty jerking effect that video geeks will recognise as a 3:2 pulldown.
It's NOT how many FPS are drawn to the screen, it's how many times per second you run code for collision-detection, AI, and so on
Orion Edwards
+4  A: 

I used to maintain a Quake3 mod and this was a constant source of user-questions.

Q3 uses 20 'ticks per second' by default - the graphics subsystem interpolates so you get smooth motion on the screen. I initially thought this was way low, but it turns out to be fine, and there really aren't many games at all with faster action than q3

I'd personally go with the "good enough for john carmack, good enough for me"

Orion Edwards