Friday, October 1, 2010

Debug Rendering

There are many useful in-game debugging tools you can build to help track problems and be more aware of the details of things happening in your game. I'll cover a few useful techniques in this post you can try out.

Debug Primitives are on of the most useful tools you can build into your codebase. Being able to generate primitives easily will allow you to test new entities and debug existing behaviour much easier. You will want to be able to simply render the following primitives with the least amount of code possible: Circles, Boxes, Arrows, Lines and Text.

Since this is for debugging purposes performance does not really matter so much, focus on keeping the code required to render these primitives as painless as possible. The code should be callable anywhere and have an interface as simple as something like:

CDebug.Circle(position, radius, color);
CDebug.Line(a, b, thickness, color);
CDebug.Vector(position, direction);
CDebug.Text(position, string);

Provide lots of overloads to cut out all the parameters you don't care about so you can just dump something on the screen with minimal code. It is worth creating screenspace and worldspace versions of these functions!

Using these primitives you can generate debug displays for your other systems, such as rendering your collision boxes for objects, or displaying your collision quadtree.

A useful trick can be to use object memory addresses to generate a color, so you can do something like drawing a randomly colored box for all your GUI components to help visualize the real layout if the textures are not clean box shapes. Making these partially transparent will let you see the overlap of UI components and sometimes spot some unnecessary UI parts floating around.

Having all your entities renderable as a simple string is useful for tracking down invisible objects or offscreen objects. Finding an object seems to be alive but offscreen somewhere? Add a debug utility to render all your objects as strings and clamp to the edge of the screen. When you see a floating CBulletEntity text clamped to the edge but with no visible entity you know something isn't getting deleted properly.

Happy debugging!

No comments:

Post a Comment