From 445505ada572fbf7be3ce474a1af31419ff68c2b Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Thu, 12 Apr 2018 22:51:20 +0200 Subject: Better game timing and better FPS/TPS display. --- src/game/game.cpp | 14 +++++++------- src/game/interface.cpp | 11 +---------- 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'src/game') diff --git a/src/game/game.cpp b/src/game/game.cpp index 2a944af..4cac4eb 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -288,11 +288,12 @@ void state_t::resume(void) paused = false; } -#define TIME_DELTA ((ntime_t)1000000000 / 60) +#define TIME_DELTA ((ntime_t)1000000000 / 100) +#define TIME_LIMIT ((ntime_t)1000000000 / 10) void state_t::tick(ntime_t time_) { - size_t target, frames_this_tick = 0; + size_t target; if (paused) return; @@ -315,13 +316,12 @@ void state_t::tick(ntime_t time_) frames++; frames_since_t0++; - frames_this_tick++; time += TIME_DELTA; - if (frames_this_tick == 3) { - t0 = time_; - frames_since_t0 = 0; - frames_behind++; + fc_game.tick(); + + if (nclock() - time_ > TIME_LIMIT) { + frames_behind += target - frames_since_t0; break; } } diff --git a/src/game/interface.cpp b/src/game/interface.cpp index b187d42..c6d5e19 100644 --- a/src/game/interface.cpp +++ b/src/game/interface.cpp @@ -332,7 +332,6 @@ void state_t::render_to(render::state_t *render) size_t w = window->getSize().x, h = window->getSize().y; v2f_t x; std::stringstream ss; - double fps; if (select.selecting) { sf::Color color; @@ -391,18 +390,10 @@ void state_t::render_to(render::state_t *render) ss << render->stats.entities; render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White); - perf_hist_index = (perf_hist_index + 1) % COUNT(perf_hist); - perf_hist[perf_hist_index] = 1.0 / render->dt; - - fps = 0.0; - for (size_t i = 0; i < COUNT(perf_hist); i++) - fps += perf_hist[i]; - fps /= COUNT(perf_hist); - x[1] += em; ss.str(std::string()); ss << std::fixed << std::setprecision(1); - ss << "FPS: " << fps; + ss << "FPS: " << fc_render.freq_ma() << ", " << fc_game.freq_ma() << " Hz"; render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White); x[1] += em; -- cgit