Switch love.timer over to double precision floats

This commit is contained in:
Bart van Strien
2011-09-30 14:57:03 +02:00
parent caf46ad430
commit eb7053b43f
2 changed files with 20 additions and 23 deletions
+12 -12
View File
@@ -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
}
+8 -11
View File
@@ -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