Improve your games input latency using video frame capture

Video Game Consoles Through the Decades
Image by libraryman via Flickr

So here is some info that should be useful if you are creating or thinking about creating video games…

Action games are coming into fashion again. Game consoles have their download services where action games are the top sellers and the new mobile devices like iPhone and Android have opened up a whole new market for small and quick action games.

In action games you need your game to respond to input as quick as possible. This is Key!

Creating a fast responding action game can be a real challenge, and knowing just how long latency your game has isn’t trivial, even if you created it.

For this discussion I’ll use the term latency for the time between when you press the fire button in a game to when you see your player actually firing in the game.

Latency, or network latency, is often used for network game and there you see extra latency caused by your connection to other players over internet. Let’s just save that whole discussion for another day.

When something happens on your computer screen it takes a few mili-seconds before you will react and press a button in response on your game control. This time is up to your reaction time, this is the time that you as a player has control over.

So what happens when a button is pressed? The game will need to read the input, feed that input into the game and do some calculation as to what should happen as a result of that button press. This whole sequence is called the games update loop. The player has no control over this time, its up to you as a game developer to make this time as short as possible.

The game then needs to render to the screen, the graphic card needs to output it to the display. Let’s call this the render update. This can also take more than one frame depending on your games rendering architecture.

Finally the monitor needs to show the graphics on screen. Ideally you want this to happen as quickly as possible. This part is up to the hardware vendor but as a game developer or a gamer you should be aware.

Your monitor has a response time and this is the time it takes for something to appear on the screen. Some monitors, made for watching television, will apply filters to make the picture look better. These filters are applied over several frames ie output is delayed and all games will have longer latency. For the best gaming experience you want a monitor with a small response time and no filtering or filter’s you can turn off.

As a game developer you need to focus on the game update and rendering loop.

To measure how many frames latency your game has get a video camera that is capable of capturing at 60 fps. Film the game screen with you holding the control in front of the screen. Record as you click the button, preferable with some debug rendering enabled so that you render something on screen that you can not miss and that you can compare with something in the actual game.

If you do not want to buy a fast video camera you can do a poor mans version. Write bytes straight to the front buffer memory at the same time as you read the input device. Then just record a video screen capture. The written bytes will appear as flicker on the screen but that is all you really need. This approach will work on consoles but on some platforms you simply don’t have that low level access to the front buffer.

Use video capture software like Fast video indexer to extract frame by frame from when you click the button to when you see the result. Count the number of frames and there is your games latency in 60 fps frames ie 16,67 ms frames.

Here are some general tips for improving your games latency.

Peek input buffers as close to their use as possible. If your game uses DirectInput, xinput or any other buffered input device, try to read the input buffer as close to where the data is used as possible.

Many game loops start reading the input at the beginning of the frame independent of the game state as reading devices is game state independent. If your loop does anything between input update and input response, key presses during that time will have one frame of extra delay.

Run at as high fps as possible. If you can run your game at 60 fps instead of 30 fps the latency will be mush lower. If your game is GPU bound you still want your game loop running quicker. Consider separating the rendering and update loop.

Don’t introduce extra frame latency. This might seem obvious, but it is quite easy to introduce frames of latency when optimizing for parallelism, blending animations, etc Analyze the flow from an input point of view and verify your result with screen captures.

Low input latency can be the difference between a fun or a frustrating game experience, don’t forget or ignore it.

Enhanced by Zemanta

Leave a Reply

Your email address will not be published. Required fields are marked *