Game Engine Architecture

(Ben Green) #1

368 9. Tools for Debugging and Development


of bugs using breakpoints and watch windows. Some bugs are timing-depen-
dent; they only happen when the program is running at full speed. Other bugs
are caused by a complex sequence of events too long and intricate to trace
manually one-by-one. In these situations, the most powerful debugging tool
is oft en a sequence of print statements.
Every game platform has some kind of console or teletype (TTY) output
device. Here are some examples:
z In a console application writt en in C/C++, running under Linux or
Win32, you can produce output in the console by printing to stdout or
stderr via printf(), fprintf(), or STL’s iostream interface.
z Unfortunately, printf() and iostream don’t work if your game is built
as a windowed application under Win32, because there’s no console
in which to display the output. However, if you’re running under the
Visual Studio debugger, it provides a debug console to which you can
print via the Win32 function OutputDebugString().
z On the PLAYSTATION 3, an application known as the Target Manager
runs on your PC and allows you to launch programs on the console.
The Target Manager includes a set of TTY output windows to which
messages can be printed by the game engine.
So printing out information for debugging purposes is almost always as easy
as adding calls to printf() throughout your code. However, most game en-
gines go a bit farther than this. In the following sections, we’ll investigate the
kinds of printing facilities most game engines provide.

9.1.1. Formatted Output with OutputDebugString()
The Win32 function OutputDebugString() is great for printing debug-
ging information to Visual Studio’s Debug Output window. However, unlike
printf(), OutputDebugString() does not support formatt ed output—it can
only print raw strings in the form of char arrays. For this reason, most Windows
game engines wrap OutputDebugString() in a custom function, like this:
#include <stdio.h> // for va_list et al
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h> // for OutputDebugString()
int VDebugPrintF(const char* format, va_list argList)
{
const U32 MAX_CHARS = 1023;
static char s_buffer[MAX_CHARS + 1];
Free download pdf