Browse Source

Switch love.timer over to double precision floats

Bart van Strien 14 years ago
parent
commit
eb7053b43f
2 changed files with 20 additions and 23 deletions
  1. 12 12
      src/modules/timer/sdl/Timer.cpp
  2. 8 11
      src/modules/timer/sdl/Timer.h

+ 12 - 12
src/modules/timer/sdl/Timer.cpp

@@ -37,7 +37,7 @@ namespace timer
 namespace sdl
 namespace sdl
 {
 {
 	Timer::Timer()
 	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)
 		frames(0), dt(0)
 	{
 	{
 		// Init the SDL timer system.
 		// Init the SDL timer system.
@@ -68,10 +68,10 @@ namespace sdl
 		currTime = SDL_GetTicks();
 		currTime = SDL_GetTicks();
 
 
 		// Convert to number of seconds
 		// Convert to number of seconds
-		dt = (currTime - prevTime)/1000.0f;
+		dt = (currTime - prevTime)/1000.0;
 
 
 		// Update FPS?
 		// Update FPS?
-		if((currTime - prevFpsUpdate)/1000.0f > fpsUpdateFrequency)
+		if((currTime - prevFpsUpdate)/1000.0 > fpsUpdateFrequency)
 		{
 		{
 			fps = frames/fpsUpdateFrequency;
 			fps = frames/fpsUpdateFrequency;
 			prevFpsUpdate = currTime;
 			prevFpsUpdate = currTime;
@@ -79,28 +79,28 @@ namespace sdl
 		}
 		}
 	}
 	}
 
 
-	void Timer::sleep(float seconds)
+	void Timer::sleep(double seconds)
 	{
 	{
 		if(seconds > 0)
 		if(seconds > 0)
 			delay((int) (seconds*1000));
 			delay((int) (seconds*1000));
 	}
 	}
 
 
-	float Timer::getDelta() const
+	double Timer::getDelta() const
 	{
 	{
 		return dt;
 		return dt;
 	}
 	}
 
 
-	float Timer::getFPS() const
+	double Timer::getFPS() const
 	{
 	{
 		return fps;
 		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
 #ifdef LOVE_WINDOWS
 		__int64 ticks, freq;
 		__int64 ticks, freq;
@@ -110,12 +110,12 @@ namespace sdl
 		QueryPerformanceFrequency(&temp);
 		QueryPerformanceFrequency(&temp);
 		freq = temp.QuadPart;
 		freq = temp.QuadPart;
 		__int64 secs = ticks/freq;
 		__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
 #else
 		timeval t;
 		timeval t;
 		gettimeofday(&t, NULL);
 		gettimeofday(&t, NULL);
-		return t.tv_sec%86400 + t.tv_usec/1000000.0f;
+		return t.tv_sec%86400 + t.tv_usec/1000000.0;
 #endif
 #endif
 	}
 	}
 
 

+ 8 - 11
src/modules/timer/sdl/Timer.h

@@ -41,25 +41,22 @@ namespace sdl
 	{
 	{
 	private:
 	private:
 
 
-		// Timing vars for benchmarking.
-		Uint32 time_init;
-
 		// Frame delta vars.
 		// Frame delta vars.
 		Uint32 currTime;
 		Uint32 currTime;
 		Uint32 prevTime;
 		Uint32 prevTime;
 		Uint32 prevFpsUpdate;
 		Uint32 prevFpsUpdate;
 
 
 		// Updated with a certain frequency.
 		// Updated with a certain frequency.
-		float fps;
+		double fps;
 
 
 		// The frequency by which to update the FPS.
 		// The frequency by which to update the FPS.
-		float fpsUpdateFrequency;
+		double fpsUpdateFrequency;
 
 
 		// Frames since last FPS update.
 		// Frames since last FPS update.
 		int frames;
 		int frames;
 
 
 		// The current timestep.
 		// The current timestep.
-		float dt;
+		double dt;
 
 
 	public:
 	public:
 
 
@@ -90,34 +87,34 @@ namespace sdl
 		* usually 1ms.
 		* usually 1ms.
 		* @param seconds The number of seconds to sleep for.
 		* @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
 		* Gets the time between the last two frames, assuming step is called
 		* each frame.
 		* each frame.
 		**/
 		**/
-		float getDelta() const;
+		double getDelta() const;
 
 
 		/**
 		/**
 		* Gets the average FPS over the last second. Beucase the value is only updated
 		* 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.
 		* once per second, it does not look erratic when displayed on screen.
 		* @return The "current" FPS.
 		* @return The "current" FPS.
 		**/
 		**/
-		float getFPS() const;
+		double getFPS() const;
 
 
 		/**
 		/**
 		* Gets the amount of time since the program started. Only useful for timing
 		* Gets the amount of time since the program started. Only useful for timing
 		* code or measuring intervals.
 		* code or measuring intervals.
 		* @return The time (in seconds) since the program started.
 		* @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
 		 * Gets the amount of time passed since an unspecified time. The time is accurate
 		 * to the microsecond, and is limited to 24 hours.
 		 * to the microsecond, and is limited to 24 hours.
 		 * @return The time (in seconds)
 		 * @return The time (in seconds)
 		 **/
 		 **/
-		float getMicroTime() const;
+		double getMicroTime() const;
 
 
 	}; // Timer
 	}; // Timer