From eb7053b43f9456ac9dfd94bbf19fd542fa6b7e9b Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 30 Sep 2011 14:57:03 +0200 Subject: [PATCH] Switch love.timer over to double precision floats --- src/modules/timer/sdl/Timer.cpp | 24 ++++++++++++------------ src/modules/timer/sdl/Timer.h | 19 ++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/modules/timer/sdl/Timer.cpp b/src/modules/timer/sdl/Timer.cpp index 2428b5855..da9dca743 100644 --- a/src/modules/timer/sdl/Timer.cpp +++ b/src/modules/timer/sdl/Timer.cpp @@ -37,7 +37,7 @@ namespace timer namespace sdl { Timer::Timer() - : time_init(0), currTime(0), prevFpsUpdate(0), fps(0), fpsUpdateFrequency(1), + : currTime(0), prevFpsUpdate(0), fps(0), fpsUpdateFrequency(1), frames(0), dt(0) { // Init the SDL timer system. @@ -68,10 +68,10 @@ namespace sdl currTime = SDL_GetTicks(); // Convert to number of seconds - dt = (currTime - prevTime)/1000.0f; + dt = (currTime - prevTime)/1000.0; // Update FPS? - if((currTime - prevFpsUpdate)/1000.0f > fpsUpdateFrequency) + if((currTime - prevFpsUpdate)/1000.0 > fpsUpdateFrequency) { fps = frames/fpsUpdateFrequency; prevFpsUpdate = currTime; @@ -79,28 +79,28 @@ namespace sdl } } - void Timer::sleep(float seconds) + void Timer::sleep(double seconds) { if(seconds > 0) delay((int) (seconds*1000)); } - float Timer::getDelta() const + double Timer::getDelta() const { return dt; } - float Timer::getFPS() const + double Timer::getFPS() const { return fps; } - float Timer::getTime() const + double Timer::getTime() const { - return (SDL_GetTicks() - time_init)/1000.0f; + return SDL_GetTicks()/1000.0; } - float Timer::getMicroTime() const + double Timer::getMicroTime() const { #ifdef LOVE_WINDOWS __int64 ticks, freq; @@ -110,12 +110,12 @@ namespace sdl QueryPerformanceFrequency(&temp); freq = temp.QuadPart; __int64 secs = ticks/freq; - __int64 usecs = static_cast<__int64>((ticks%freq)/(freq/1000000.0f)); - return secs%86400 + usecs/1000000.0f; + __int64 usecs = static_cast<__int64>((ticks%freq)/(freq/1000000.0)); + return secs%86400 + usecs/1000000.0; #else timeval t; gettimeofday(&t, NULL); - return t.tv_sec%86400 + t.tv_usec/1000000.0f; + return t.tv_sec%86400 + t.tv_usec/1000000.0; #endif } diff --git a/src/modules/timer/sdl/Timer.h b/src/modules/timer/sdl/Timer.h index cea9b28ff..9f8772d48 100644 --- a/src/modules/timer/sdl/Timer.h +++ b/src/modules/timer/sdl/Timer.h @@ -41,25 +41,22 @@ namespace sdl { private: - // Timing vars for benchmarking. - Uint32 time_init; - // Frame delta vars. Uint32 currTime; Uint32 prevTime; Uint32 prevFpsUpdate; // Updated with a certain frequency. - float fps; + double fps; // The frequency by which to update the FPS. - float fpsUpdateFrequency; + double fpsUpdateFrequency; // Frames since last FPS update. int frames; // The current timestep. - float dt; + double dt; public: @@ -90,34 +87,34 @@ namespace sdl * usually 1ms. * @param seconds The number of seconds to sleep for. **/ - void sleep(float seconds); + void sleep(double seconds); /** * Gets the time between the last two frames, assuming step is called * each frame. **/ - float getDelta() const; + double getDelta() const; /** * Gets the average FPS over the last second. Beucase the value is only updated * once per second, it does not look erratic when displayed on screen. * @return The "current" FPS. **/ - float getFPS() const; + double getFPS() const; /** * Gets the amount of time since the program started. Only useful for timing * code or measuring intervals. * @return The time (in seconds) since the program started. **/ - float getTime() const; + double getTime() const; /** * Gets the amount of time passed since an unspecified time. The time is accurate * to the microsecond, and is limited to 24 hours. * @return The time (in seconds) **/ - float getMicroTime() const; + double getMicroTime() const; }; // Timer