* Copyright (c) 2006-2012 LOVE Development Team
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
# include <windows.h>
# include <time.h>
# include <sys/time.h>
: currTime(0), prevFpsUpdate(0), fps(0), fpsUpdateFrequency(1),
// Init the SDL timer system.
if (SDL_InitSubSystem(SDL_INIT_TIMER) < 0)
// Quit SDL timer.
const char * Timer::getName() const
// Frames rendered
// "Current" time is previous time by now.
prevTime = currTime;
// Get ticks from SDL
currTime = SDL_GetTicks();
// Convert to number of seconds
dt = (currTime - prevTime)/1000.0;
// Update FPS?
if ((currTime - prevFpsUpdate)/1000.0 > fpsUpdateFrequency)
fps = frames/fpsUpdateFrequency;
prevFpsUpdate = currTime;
frames = 0;
void Timer::sleep(double seconds)
if (seconds > 0)
double Timer::getDelta() const
double Timer::getFPS() const
double Timer::getTime() const
double Timer::getMicroTime() const
static __int64 freq = 0;
freq = (__int64) temp.QuadPart;
// The 64 to 32 bit integer conversion, assuming the fraction part down
// to microseconds takes 20 bits, should not be a problem unless the
// system has an uptime of a few decades.
return (double) microTime.QuadPart / (double) freq;
return t.tv_sec + t.tv_usec/1000000.0;
} // sdl
} // timer
} // love