Skip to content

Commit 924453e

Browse files
committed
use get_stat_color also for FPS
select the color automatically (lime for +- 2-5%, brown for >5% diff) This simplifies the code by sharing the logic in common; also exceeding FPS is now colored (until this just lower than nominal was colored).
1 parent 56d6435 commit 924453e

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,7 @@ print_fps(const char *prefix, steady_clock::time_point *t0, int *frames,
307307
return;
308308
}
309309
const double fps = *frames / seconds;
310-
const int fps_perc = (int) floor(fps / nominal_fps * 100.);
311-
const char *fps_col = fps_perc >= MIN_FPS_PERC_WARN ? ""
312-
: fps_perc >= MIN_FPS_PERC_WARN2
313-
? T256_FG_SYM(T_ARCTIC_LIME)
314-
: T256_FG_SYM(T_SADDLE_BROWN);
310+
const char *const fps_col = get_stat_color(fps / nominal_fps);
315311
log_msg(LOG_LEVEL_INFO,
316312
TERM_BOLD TERM_BG_BLACK TERM_FG_BRIGHT_GREEN
317313
"%s" TERM_RESET " %d frames in %g seconds = " TERM_BOLD

src/video_display.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#include "types.h"
8181
#include "utils/color_out.h"
8282
#include "utils/macros.h"
83+
#include "utils/misc.h" // for get_stat_color
8384
#include "utils/thread.h"
8485
#include "video.h"
8586
#include "video_display/splashscreen.h"
@@ -363,13 +364,8 @@ static bool display_frame_helper(struct display *d, struct video_frame *frame, l
363364
if (seconds_ns > 5 * NS_IN_SEC) {
364365
const double seconds = (double) seconds_ns / NS_IN_SEC;
365366
const double fps = d->frames / seconds;
366-
const int fps_perc = floor(fps / frame->fps * 100.);
367-
const char *fps_col = "";
368-
if (fps_perc < MIN_FPS_PERC_WARN) {
369-
fps_col = fps_perc >= MIN_FPS_PERC_WARN2
370-
? T256_FG_SYM(T_ARCTIC_LIME)
371-
: T256_FG_SYM(T_SADDLE_BROWN);
372-
}
367+
const char *const fps_col = get_stat_color(fps / frame->fps);
368+
373369
log_msg(LOG_LEVEL_INFO,
374370
TERM_BOLD TERM_FG_MAGENTA
375371
"%s" TERM_RESET "%d frames in %g seconds = " TERM_BOLD

0 commit comments

Comments
 (0)