From c45ec454571f36286de25ce93e37f3f033455f42 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 19 Mar 2020 02:07:25 -0500 Subject: [PATCH] [nostalgia/core/sdl] Add disabled FPS logging --- src/nostalgia/core/sdl/gfx.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/nostalgia/core/sdl/gfx.cpp b/src/nostalgia/core/sdl/gfx.cpp index 3d3e2eb5..828f750a 100644 --- a/src/nostalgia/core/sdl/gfx.cpp +++ b/src/nostalgia/core/sdl/gfx.cpp @@ -8,6 +8,9 @@ #include #include +#ifdef NOST_FPS_PRINT +#include +#endif #include @@ -150,7 +153,23 @@ void drawBackground(const TileMap &tm, SDL_Texture *tex) { } } +#ifdef NOST_FPS_PRINT +static uint64_t prevFpsCheckTime = 0; +static uint64_t draws = 0; +#endif + void draw() { +#ifdef NOST_FPS_PRINT + ++draws; + if (draws >= 5000) { + using namespace std::chrono; + auto now = duration_cast(system_clock::now().time_since_epoch()).count(); + auto duration = static_cast(now - prevFpsCheckTime) / 1000.0; + std::cout << "FPS: " << static_cast(static_cast(draws) / duration) << '\n'; + prevFpsCheckTime = now; + draws = 0; + } +#endif SDL_RenderClear(renderer); for (std::size_t i = 0; i < bgTileMaps.size(); i++) { auto tex = bgTextures[i];