Debugging

The following debugging features have found their way into the source code:

stderr debug output

The debug_spool(int level,char *fmt,...) function can be used to send messages to stderr. By default, !RunImage redirects stderr to !DeathDawn.err. If the debug level is higher than the current value of debug_level (or the DEBUG_OVERRIDE level) then no output is produced.

Onscreen debug text

Per-frame debug text can be displayed using the debug_msg() function. This text is stored internally in an 8K buffer, and printed to screen using puts at the end of each frame. It is also sent to stderr.

Code profiling

Code profiling via the use of jprof2 is supported by calling the debug_prof function. On the first call, full-code profiling will be initialised; on subsequent calls, current profiling results will be sent to stderr. Once started, the only way to stop the profiling is by quitting the game. For profiling to work, the DTime module must be loaded (which itself relies on HALTimer).

Debug levels

Debugging can be disabled globally by #defining DEBUG to be 0 in debug.h. The debug output level can be changed at runtime by changing the debug_level variable; it can also be overriden on a per-file basis by #defining DEBUG_OVERRIDE to the required value, before the debug.h #include. The default debug value is contained in debug.c. The following levels are currently in use:

0: No output
1: Low output - typically prints debug info when functions are entered, and high-level game operations
2: Medium output - prints return status of functions
3: High output

Debug blobs

Blobs (blood splats) can be drawn at arbitrary world locations on a per-frame basis using the debug_blob() and debug_blob2() functions.

Map rendering debug

If debug_level is >0, pressing the D key will cause the map renderer to output a screenshot of each block as it is rendered for the current frame, along with its coordinates in screen space. Note that this may take several minutes to complete, as even the empty air blocks will be output. So don't touch the D key! (This code can easily be disabled in plot.c)
TODO:
CODE: UNKNOWN: Fix the malloc logging to not crash?
CODE: QUICK: Introduce simple demo recording, for profiling, bug fixing, etc? At start of recording, needs to save random number seed. Then for each frame, saves gametime and keyboard input. Then for playback, just need to reseed rnd with the saved seed, fix the framerate to that of the timestamps, and use the saved keyboard input.
CODE: QUICK: Add debug menu to WIMP? Just toggle certain debug options on/off (per-frame screen debug, spooling to disc, disable screen banking, etc.)
???
Profit!