summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@Simon-Elementary.(none)>2011-10-16 23:16:43 (GMT)
committer Simon Robertshaw <simon@Simon-Elementary.(none)>2011-10-16 23:16:43 (GMT)
commit44a0008d4e8f80fce9697bbde09193e837bc0072 (patch)
treee96a3df113a11ee5bb3f70ad568ff2f44e050bad /src
parentbbe5aabf4f85c0b83da54fb8f55b4c509c323609 (diff)
downloadpowder-44a0008d4e8f80fce9697bbde09193e837bc0072.zip
powder-44a0008d4e8f80fce9697bbde09193e837bc0072.tar.gz
Debug performance/time graph
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c53
-rw-r--r--src/main.c51
2 files changed, 103 insertions, 1 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 5d7354d..60572dc 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -2718,6 +2718,59 @@ int sdl_open(void)
int draw_debug_info(pixel* vid, int lm, int lx, int ly, int cx, int cy, int line_x, int line_y)
{
char infobuf[256];
+ if(debug_flags & DEBUG_PERFORMANCE_FRAME || debug_flags & DEBUG_PERFORMANCE_CALC)
+ {
+ int t1, t2, x = 0, i = debug_perf_istart;
+ float partiavg = 0, frameavg = 0;
+ while(i != debug_perf_iend)
+ {
+ partiavg += abs(debug_perf_partitime[i]/100000);
+ frameavg += abs(debug_perf_frametime[i]/100000);
+ if(debug_flags & DEBUG_PERFORMANCE_CALC)
+ t1 = abs(debug_perf_partitime[i]/100000);
+ else
+ t1 = 0;
+
+ if(debug_flags & DEBUG_PERFORMANCE_FRAME)
+ t2 = abs(debug_perf_frametime[i]/100000);
+ else
+ t2 = 0;
+
+ if(t1 > YRES)
+ t1 = YRES;
+ if(t1+t2 > YRES)
+ t2 = YRES-t1;
+
+ if(t1>0)
+ draw_line(vid, x, YRES, x, YRES-t1, 0, 255, 120, XRES+BARSIZE);
+ if(t2>0)
+ draw_line(vid, x, YRES-t1, x, YRES-(t1+t2), 255, 120, 0, XRES+BARSIZE);
+
+ i++;
+ x++;
+ i %= DEBUG_PERF_FRAMECOUNT;
+ }
+
+ if(debug_flags & DEBUG_PERFORMANCE_CALC)
+ t1 = abs(partiavg / x);
+ else
+ t1 = 0;
+
+ if(debug_flags & DEBUG_PERFORMANCE_FRAME)
+ t2 = abs(frameavg / x);
+ else
+ t2 = 0;
+
+ if(t1 > YRES)
+ t1 = YRES;
+ if(t1+t2 > YRES)
+ t2 = YRES-t1;
+
+ if(t1>0)
+ fillrect(vid, x, YRES-t1-1, 5, t1+2, 0, 255, 0, 255);
+ if(t2>0)
+ fillrect(vid, x, (YRES-t1)-t2-1, 5, t2+1, 255, 0, 0, 255);
+ }
if(debug_flags & DEBUG_DRAWTOOL)
{
if(lm == 1) //Line tool
diff --git a/src/main.c b/src/main.c
index 09dfffd..2615e4f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -187,8 +187,13 @@ int frameidx = 0;
//int CGOL = 0;
//int GSPEED = 1;//causes my .exe to crash..
int sound_enable = 0;
-int debug_flags = 0;
+int debug_flags = 0;
+int debug_perf_istart = 1;
+int debug_perf_iend = 0;
+long debug_perf_frametime[DEBUG_PERF_FRAMECOUNT];
+long debug_perf_partitime[DEBUG_PERF_FRAMECOUNT];
+long debug_perf_time = 0;
sign signs[MAXSIGNS];
@@ -1813,8 +1818,52 @@ int main(int argc, char *argv[])
if(ngrav_enable && drawgrav_enable)
draw_grav(vid_buf);
draw_walls(part_vbuf);
+
+ if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
+ {
+ #ifdef WIN32
+ #elif defined(MACOSX)
+ #else
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ debug_perf_time = ts.tv_nsec;
+ #endif
+ }
+
update_particles(part_vbuf); //update everything
+
+ if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
+ {
+ #ifdef WIN32
+ #elif defined(MACOSX)
+ #else
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+
+ debug_perf_partitime[debug_perf_iend] = ts.tv_nsec - debug_perf_time;
+
+ debug_perf_time = ts.tv_nsec;
+ #endif
+ }
+
render_parts(part_vbuf); //draw particles
+
+ if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
+ {
+ #ifdef WIN32
+ #elif defined(MACOSX)
+ #else
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+
+ debug_perf_frametime[debug_perf_iend] = ts.tv_nsec - debug_perf_time;
+ #endif
+ debug_perf_iend++;
+ debug_perf_iend %= DEBUG_PERF_FRAMECOUNT;
+ debug_perf_istart++;
+ debug_perf_istart %= DEBUG_PERF_FRAMECOUNT;
+ }
+
if(sl == WL_GRAV+100 || sr == WL_GRAV+100)
draw_grav_zones(part_vbuf);