From dcb09c03a8c2ebcc21487beb8aa1322accc60912 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sat, 3 Mar 2012 11:42:39 +0100 Subject: [PATCH] That was only part of the problem, now it should all work properly (and more accurately) --- src/modules/timer/Timer.h | 2 +- src/modules/timer/sdl/Timer.cpp | 6 +++--- src/modules/timer/sdl/Timer.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/timer/Timer.h b/src/modules/timer/Timer.h index ff781eac9..daa7f3b04 100644 --- a/src/modules/timer/Timer.h +++ b/src/modules/timer/Timer.h @@ -61,7 +61,7 @@ namespace timer * once per second, it does not look erratic when displayed on screen. * @return The "current" FPS. **/ - virtual double getFPS() const = 0; + virtual int getFPS() const = 0; /** * Gets the amount of time since the program started. Only useful for timing diff --git a/src/modules/timer/sdl/Timer.cpp b/src/modules/timer/sdl/Timer.cpp index 3bd96c8a6..c2394f6ff 100644 --- a/src/modules/timer/sdl/Timer.cpp +++ b/src/modules/timer/sdl/Timer.cpp @@ -70,11 +70,11 @@ namespace sdl // Convert to number of seconds dt = (currTime - prevTime)/1000.0; - int timeSinceLast = (currTime - prevFpsUpdate)/1000.0; + double timeSinceLast = (currTime - prevFpsUpdate)/1000.0; // Update FPS? if (timeSinceLast > fpsUpdateFrequency) { - fps = frames/timeSinceLast; + fps = int((frames/timeSinceLast) + 0.5); prevFpsUpdate = currTime; frames = 0; } @@ -91,7 +91,7 @@ namespace sdl return dt; } - double Timer::getFPS() const + int Timer::getFPS() const { return fps; } diff --git a/src/modules/timer/sdl/Timer.h b/src/modules/timer/sdl/Timer.h index aaf191e11..7ac495e30 100644 --- a/src/modules/timer/sdl/Timer.h +++ b/src/modules/timer/sdl/Timer.h @@ -55,7 +55,7 @@ namespace sdl void step(); void sleep(double seconds); double getDelta() const; - double getFPS() const; + int getFPS() const; double getTime() const; double getMicroTime() const; @@ -70,7 +70,7 @@ namespace sdl Uint32 prevFpsUpdate; // Updated with a certain frequency. - double fps; + int fps; // The frequency by which to update the FPS. double fpsUpdateFrequency;