From 1c63cbf204b1d2c667ce9f821ccb197d0ffb0ac3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 11 May 2011 14:48:17 +0000 Subject: Review of the main loop timer, converted timers from float to unsigned long, corrected a number of timing bugs, improved client framerate stability. --- src/client/infowidget.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/client/infowidget.cc') diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc index 52af5ef..752c09b 100644 --- a/src/client/infowidget.cc +++ b/src/client/infowidget.cc @@ -104,16 +104,19 @@ StatsInfoWidget::StatsInfoWidget(ui::Widget *parent) : ui::Widget(parent) void StatsInfoWidget::draw() { // average fps - fps_counter_time[fps_counter_index] = core::application()->time(); + unsigned long fps = 0.0f; + const unsigned long now = core::application()->timestamp(); + fps_counter_time[fps_counter_index] = now; fps_counter_index = (fps_counter_index + 1) % fps_counter_size; - float min_time = core::application()->time(); + + unsigned long min_time = now; for (size_t i = 0; i < fps_counter_size; i++) if (fps_counter_time[i] < min_time) min_time = fps_counter_time[i]; - float fps = 0.0f; - float t = (core::application()->time() - min_time); + + const unsigned long t = now - min_time; if (t > 0) { - fps = roundf(((float) fps_counter_size ) / t); + fps = (fps_counter_size - 1) * 1000 / t; } std::ostringstream textstream; @@ -133,13 +136,13 @@ void StatsInfoWidget::draw() if (core::Stats::network_bytes_sent + core::Stats::network_bytes_received) { net_counter_traffic[net_counter_index] = core::Stats::network_bytes_sent + core::Stats::network_bytes_received; - net_counter_time[net_counter_index] = core::application()->time(); + net_counter_time[net_counter_index] = core::application()->timestamp(); size_t index_max = net_counter_index; net_counter_index = (net_counter_index + 1) % net_counter_size; size_t index_min = net_counter_index; - float d = net_counter_time[index_max] - net_counter_time[index_min]; + float d = float (net_counter_time[index_max] - net_counter_time[index_min]) / 1000.0f; if (d > 0) { float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min]; textstream << "^Nnet ^B" << std::setw(6) << roundf((float) traffic / d) << "\n"; -- cgit v1.2.3