I'm working on some game libraries, tools and utilties. The first thing I'm posting is some debugging libraries. Stuff I use while making a game, specifically a console game.
There's 4 major parts to it
- a debug console.
This is just the ability to do a printf to the display. Most development systems let you print to a terminal or inside the debugger. The problem with those systems is the artist, the desginer or myself is not looking at the debugger. We are looking at the game. Therefore, important messages need to be displayed in the game or they will go un-noticed.
On top of that, games generally erase and re-draw the entire screen every frame so some method of re-drawing the messages needs to be created. Without a system like this that process can get quite cumbersome.
The systmem supports output in different colors as well as flashing output to make very important messages stand out.
- print to the debug terminal
Most dev systems have an OutputDebugString type of way to get a message to the terminal. These are just wrappers that provide more functionalty like printf and so I have one place to fix if I switch engines.
- print to the screen
Again, most systems have a DrawText function that will draw a string. I just always need wrappers so I can do printf style formatting and again, I want it in one place so if I switch engines I don't have to learn a new api or change other code to use a new api.
- debug menus
This is the biggest part. These are menus, controllable from the joypad/controller that you can pull up in the game to inspect and or edit things in realtime.
For all of these my #1 goal was to make something easy to use. So for example there is no need to init any of them. While you can set a few parameters they will work without any settings. The menus and the console only require 1 function to be called for them to operate, etc...
The menus in particular have been designed to be easy to add items to with lots of default handlers. In one line you can add menus that edit bools, ints, floats, either directly or can edit them through functions or even member functions. Menus that call callbacks in C style, CPP function object style and member function style.
They handle enums, although you need to supply a value−label table. They can also handle STL collections and display them as menu items.
Some other features.
- They handle menus that have too many items to fit on the screen and will let the user scroll through them.
- They support non-uniform height menu items.
- They handle the menus cascacding past the right edge of the screen
- They are semi draw order independent.
Originally when a submenu cascaded into the right edge of the screen I would just move it flush right. I assumed since a menu's parent was drawn before itself I thought the children would draw over their parents and therefore be usable. Unfortunately when I tried it out it became clear that in the engine I was using it in, draw order was not preserved. Text draws and rectangle draws were queued separately. So, I changed the menus to figure out what the right most edge they need is and then I push everything else to the left. Now the draw order doesn't matter as much since nothing ever overlaps. Rectangles still need to be either drawn before text or with a lower Z order but that's not the responsibility of these routines.
There is a file debugplatform.h that defines a few functions. You create your own debugplatform.cpp and provide those few stubbs and the all these debug systems will start working.
Anyway, I have no idea if anyone other than me will find these useful. I know that many teams are using systems that have other ways to accomplish this kind of thing. For me though I have found them useful and so have the teams I've been on. It's my hope that now that I have my own I'll never have to write them again.
If you are interested you can find them on sourceforge here. They are released under the NewBSD license so use them how ever you want. There are not a lot of docs yet but the code is pretty well commented. There's also a file called debugmenus_examples.cpp that shows how to setup a bunch of different kinds of menus. And, there's a Win32 sample as well to actually see them run. To keep it simple the sample uses the keyboard to emulate a joypad. The cursor keys are the DPAD. The space bar is the Action button if you want to call it that. Think X on the PS3 or A on the 360. Backspace is the cancel button.