Posted: 16th Aug 2011 7:20
Here's a simple debug UI for Tier 1 apps who may want to watch their performance. It's similiar to a popular XNA component that divides the time taken up for different operations into a colored bar.



To use, plop the files from the archive into your project directory, then add #include "debug.agc" to the top of your source and then use these commands:

+ Code Snippet
// Commands
//  - SetupDebug(Segments)
//  - BeginDebug()
//  - EndDebug()
//  - BeginDebugSegment(Segment)
//  - EndDebugSegment()
//  - SetDebugSegmentFrameTime(Segment, Time)
//  - SetDebugSegmentName(Segment, Name)
//  - UpdateDebug()


More specific instructions for each command are in the comments above the function declarations.

An example of how to set it up:

+ Code Snippet
// Bar segment constants, to give each a name
#Constant NUMSEGMENTS 3
#Constant LOGICSEGMENT 1
#Constant PHYSICSSEGMENT 2
#Constant DRAWSEGMENT 3

// Setup the debug UI (creates sprites and global variables)
// Provides an X, Y, Width, Height, and Segment count
SetupDebug(20, 600-40, 800-40, 30, NUMSEGMENTS)

// Name each segment
// You may also want to use SetDebugSegmentColor(Segment, R,G,B,A)
// otherwise they will have random colors
SetDebugSegmentName(LOGICSEGMENT,"Game Logic")
SetDebugSegmentName(PHYSICSSEGMENT, "Physics")
SetDebugSegmentName(DRAWSEGMENT, "Drawing")

// Begin debugging
BeginDebug()

// In your loop...
BeginDebugSegment(LOGICSEGMENT)
   // Do stuff
EndDebugSegment()
SetDebugSegmentFrameTime(PHYSICSSEGMENT, GetPhysicsTime())
SetDebugSegmentFrameTime(DRAWSEGMENT, GetDrawingTime())
UpdateDebug()


Make sure to call UpdateDebug() in your loop. The values shown in the bar are averaged over a full second and are proportional to the total amount of time taken to do the various tasks during that second. Also, the text sometimes overlaps - but I'll leave that as an excercise to the user to fix (perhaps with a key instead of placing the text in the bar?)

It uses sprites and text objects with depths ranging from 0 to 3. You may have to be careful to make sure they don't interfere with your game.

Maybe somebody will find this useful, maybe not. I like it a little better than having a bunch of Print statements in the upper left corner showing nonsensical numbers
Posted: 16th Aug 2011 10:03
Very good, I'll use it myself!