Browse Source

optimize debug counters

Thomas B 2 weeks ago
parent
commit
ff7658091e
1 changed files with 31 additions and 16 deletions
  1. 31
    16
      src/window.c

+ 31
- 16
src/window.c View File

@@ -287,8 +287,7 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
287 287
     }
288 288
 
289 289
     // TODO support one debug value on DMG
290
-    if ((_cpu == CGB_TYPE)
291
-            && (conf_get()->debug_flags & DBG_OUT_ON)) {
290
+    if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON)) {
292 291
         static int32_t prev_score = 0;
293 292
         if (initial || (score != prev_score)) {
294 293
             prev_score = score;
@@ -300,30 +299,46 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
300 299
         uint8_t x_off = number(score, 0, 0, is_black) >> 3;
301 300
         uint8_t y_off = 0;
302 301
 
303
-        // TODO only re-draw when value has changed!
304
-
305
-        if (conf_get()->debug_flags & DBG_SHOW_FPS) {
306
-            sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)game_get_fps());
307
-            str_ascii(str_buff, x_off, y_off, 1);
302
+        if ((conf_get()->debug_flags & DBG_SHOW_FPS) && (y_off < 2)) {
303
+            static uint8_t prev_fps = 0;
304
+            uint8_t fps = game_get_fps();
305
+            if (fps != prev_fps) {
306
+                prev_fps = fps;
307
+                sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)fps);
308
+                str_ascii(str_buff, x_off, y_off, 1);
309
+            }
308 310
             y_off++;
309 311
         }
310 312
 
311
-        if (conf_get()->debug_flags & DBG_SHOW_FRAMES) {
312
-            sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
313
-            str_ascii(str_buff, x_off, y_off, 1);
313
+        if ((conf_get()->debug_flags & DBG_SHOW_FRAMES) && (y_off < 2)) {
314
+            static uint16_t prev_framecount = 0;
315
+            uint16_t framecount = game_get_framecount();
316
+            if (framecount != prev_framecount) {
317
+                prev_framecount = framecount;
318
+                sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)framecount);
319
+                str_ascii(str_buff, x_off, y_off, 1);
320
+            }
314 321
             y_off++;
315 322
         }
316 323
 
317
-        if (conf_get()->debug_flags & DBG_SHOW_TIMER) {
318
-            sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer_get());
319
-            str_ascii(str_buff, x_off, y_off, 1);
324
+        if ((conf_get()->debug_flags & DBG_SHOW_TIMER) && (y_off < 2)) {
325
+            static uint16_t prev_timer = 0;
326
+            uint16_t timer = timer_get();
327
+            if (timer != prev_timer) {
328
+                sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer);
329
+                str_ascii(str_buff, x_off, y_off, 1);
330
+            }
320 331
             y_off++;
321 332
         }
322 333
 
323
-        if (conf_get()->debug_flags & DBG_SHOW_STACK) {
334
+        if ((conf_get()->debug_flags & DBG_SHOW_STACK) && (y_off < 2)) {
335
+            static uint16_t prev_stack_pointer = 0;
324 336
             get_sp();
325
-            sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
326
-            str_ascii(str_buff, x_off, y_off, 1);
337
+            if (stack_pointer != prev_stack_pointer) {
338
+                prev_stack_pointer = stack_pointer;
339
+                sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
340
+                str_ascii(str_buff, x_off, y_off, 1);
341
+            }
327 342
             y_off++;
328 343
         }
329 344
 

Loading…
Cancel
Save