Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-07-31 14:30:50 +0000
committerStijn Buys <ingar@osirion.org>2008-07-31 14:30:50 +0000
commit613e0e628b669ae9aaf6fda4be56cf3b2a899893 (patch)
tree12df5cd49ac441c04e9929a1c734e9564d693690 /src/client
parent96521495f8c0070537be42c97f8fcbe55ec3990f (diff)
better fps counter
Diffstat (limited to 'src/client')
-rw-r--r--src/client/view.cc37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
index 41cdd80..f72a149 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -38,7 +38,9 @@ core::Cvar *ui_pointerhovercolor =0;
namespace view
{
-float fps = 0;
+const size_t fps_counter_size = 25; // fps is the average of 20 frames
+float fps_counter_time[fps_counter_size];
+size_t fps_counter_index = 0;
void init()
{
@@ -58,6 +60,9 @@ void init()
ui_pointerhovercolor->set_info("[r g b] mouse pointer hover color");
targets::init();
+
+ for (size_t i =0; i < fps_counter_size; i++)
+ fps_counter_time[i] = 0.0f;
}
void shutdown()
@@ -93,16 +98,36 @@ void draw_status()
using namespace render;
std::stringstream status;
+
+ int minutes = (int) floorf(core::application()->time() / 60.0f);
+ int seconds = (int) floorf(core::application()->time() - (float) minutes* 60.0f);
+
+ status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+ Text::draw(video::width-Text::fontwidth()*11-4, 4, status);
+
if (core::game()) {
int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f);
- status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
- Text::draw(video::width-Text::fontwidth()*11-4, 4, status);
+ status << "^Ngame ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+ Text::draw(video::width-Text::fontwidth()*11-4, Text::fontheight()+ 4, status);
}
// print stats if desired
if (draw_stats && draw_stats->value()) {
+ // average fps
+ fps_counter_time[fps_counter_index] = core::application()->time();
+ fps_counter_index = (fps_counter_index + 1 ) % fps_counter_size;
+ float min_time = core::application()->time();
+ 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);
+ if (t > 0) {
+ fps = roundf(((float) fps_counter_size - 1.0f) / t);
+ }
+
std::stringstream stats;
stats << "^Nfps ^B" << std::setw(6) << fps << "\n";
if (core::application()->connected()) {
@@ -331,12 +356,6 @@ void frame(float seconds)
{
using namespace render;
- // calculate frames per second
- if (seconds > 0.0f)
- fps = floorf(1.0f / seconds);
- else
- fps = 9999;
-
// flush console messages
console()->flush();