From 5f660cea9369dde438489f4446cd5fd074ce6c85 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Thu, 8 Oct 2009 22:00:14 +0200 Subject: [PATCH] add runtime display --- apps/plugins/chopper.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/plugins/chopper.c b/apps/plugins/chopper.c index 1ff0a2055..5c985319a 100644 --- a/apps/plugins/chopper.c +++ b/apps/plugins/chopper.c @@ -203,6 +203,7 @@ static int iLevelMode; static int blockh,blockw; static int highscore; static int score; +static long runtime = 0; #define CFG_FILE "chopper.cfg" #define MAX_POINTS 50000 @@ -664,7 +665,7 @@ static void chopDrawParticle(struct CParticle *mParticle) static void chopDrawScene(void) { char s[30]; - int w; + int w, h; #if LCD_DEPTH > 2 rb->lcd_set_background(LCD_BLACK); #elif LCD_DEPTH == 2 @@ -692,7 +693,7 @@ static void chopDrawScene(void) #else rb->snprintf(s, sizeof(s), "Distance: %d", score); #endif - rb->lcd_getstringsize(s, &w, NULL); + rb->lcd_getstringsize(s, &w, &h); rb->lcd_putsxy(2, 2, s); if (score < highscore) { @@ -706,6 +707,8 @@ static void chopDrawScene(void) if (LCD_WIDTH - 2 - w2 > w + 2) rb->lcd_putsxy(LCD_WIDTH - 2 - w2, 2, s); } + rb->snprintf(s, sizeof(s), "Runtime: %ld", runtime); + rb->lcd_putsxy(2,2+h,s); rb->lcd_set_drawmode(DRMODE_SOLID); rb->lcd_update(); @@ -793,8 +796,9 @@ static int chopGameLoop(void) chopDrawScene(); + runtime = 0; while (!exit) { - + int start = *rb->current_tick; end = *rb->current_tick + CYCLETIME; if(chopUpdateTerrainRecycling(&mGround) == 1) @@ -832,6 +836,7 @@ static int chopGameLoop(void) move_button=rb->button_status(); if (rb->button_get(false) == QUIT) { ret = chopMenu(1); + runtime = 0; if (ret != -1) return PLUGIN_OK; bdelay = 0; @@ -906,6 +911,7 @@ static int chopGameLoop(void) chopKillPlayer(); chopDrawScene(); ret = chopMenu(0); + runtime = 0; if (ret != -1) return ret; } @@ -914,7 +920,7 @@ static int chopGameLoop(void) rb->sleep(end - *rb->current_tick); /* wait until time is over */ else rb->yield(); - + runtime += *rb->current_tick - start; } return PLUGIN_OK; } -- 2.11.4.GIT