From 649f7e566cc3e23e9f8ad76fef1726b849edf536 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 16 Feb 2026 08:38:55 -0800 Subject: Show frame time --- src/main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 87515c1..1be2ac3 100644 --- a/src/main.c +++ b/src/main.c @@ -16,8 +16,8 @@ #include #include -static constexpr int BufferWidth = 160; -static constexpr int BufferHeight = 120; +static constexpr int BufferWidth = 320; +static constexpr int BufferHeight = 240; static constexpr R Aspect = (R)BufferWidth / (R)BufferHeight; static const char* WindowTitle = "GAME"; @@ -140,7 +140,7 @@ static void ShowStats(const sgCounters* last_stats, const sgCounters* stats, R t const uint64_t frames_elapsed = stats->frames - last_stats->frames; #define RATE_PER_SEC(STAT) (int)((R)(stats->STAT - last_stats->STAT) / time_elapsed) -#define RATE_PER_FRAME(STAT) (int)((stats->STAT - last_stats->STAT) / frames_elapsed) +#define RATE_PER_FRAME(STAT) (int)( (stats->STAT - last_stats->STAT) / frames_elapsed) const int fps = RATE_PER_SEC(frames); const int pps = RATE_PER_SEC(pixels); const int tps = RATE_PER_SEC(triangles3); @@ -148,8 +148,11 @@ static void ShowStats(const sgCounters* last_stats, const sgCounters* stats, R t const int tpf = RATE_PER_FRAME(triangles3); #undef RATE_PER_FRAME #undef RATE_PER_SEC + constexpr R MicrosInSec = (R)1e6; + const int frame_time = (int)((MicrosInSec * time_elapsed) / (R)(stats->frames - last_stats->frames)); - printf("fps: %d, pps: %d, tps: %d, ppf: %d, tpf: %d\n", fps, pps, tps, ppf, tpf); + printf("time(us): %d, fps: %d, pps: %d, tps: %d, ppf: %d, tpf: %d\n", + frame_time, fps, pps, tps, ppf, tpf); } static CameraCommand CameraCommandFromInput( -- cgit v1.2.3