Game Engine Architecture

(Ben Green) #1
377

that draws the primitive is called rarely or intermitt ently (e.g., a func-
tion that calculates the initial velocity of a projectile), then you do not
want the primitive to fl icker on-screen for just one frame and then dis-
appear. In such situations the programmer should be able to give his or
her debug primitives a longer lifetime, on the order of a few seconds.
z It’s also important that the debug drawing system be capable of han-
dling a large number of debug primitives effi ciently. When you’re draw-
ing debug information for 1,000 game objects, the number of primitives
can really add up, and you don’t want your game to be unusable when
debug drawing is turned on.
The debug drawing API in Naughty Dog’s Uncharted: Drake’s Fortune en-
gine looks something like this:


class DebugDrawManager
{
public:

// Adds a line segment to the debug drawing queue.
void AddLine( const Point& fromPosition,
const Point& toPosition,
Color color,
float lineWidth = 1.0f,
float duration = 0.0f,
bool depthEnabled = true);
// Adds an axis-aligned cross (3 lines converging at
// a point) to the debug drawing queue.
void AddCross( const Point& position,
Color color,
float size,
float duration = 0.0f,
bool depthEnabled = true);
// Adds a wireframe sphere to the debug drawing queue.
void AddSphere( const Point& centerPosition,
float radius,
Color color,
float duration = 0.0f,
bool depthEnabled = true);
// Adds a circle to the debug drawing queue.
void AddCircle( const Point& centerPosition,
const Vector& planeNormal,
float radius,
Color color,
float duration = 0.0f,
bool depthEnabled = true);

9.2. Debug Drawing Facilities

Free download pdf