2001-04-26 16:45:43 +00:00
|
|
|
/*
|
2011-04-08 13:03:26 -07:00
|
|
|
Simple DirectMedia Layer
|
2013-02-15 08:47:44 -08:00
|
|
|
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
2011-04-08 13:03:26 -07:00
|
|
|
|
|
|
|
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.
|
2001-04-26 16:45:43 +00:00
|
|
|
*/
|
2006-02-21 08:46:50 +00:00
|
|
|
#include "SDL_config.h"
|
2001-04-26 16:45:43 +00:00
|
|
|
|
2011-01-20 18:04:05 -08:00
|
|
|
#ifdef SDL_TIMER_WINDOWS
|
2006-04-14 04:46:47 +00:00
|
|
|
|
2011-01-24 21:20:30 -08:00
|
|
|
#include "../../core/windows/SDL_windows.h"
|
2011-01-27 15:31:00 -08:00
|
|
|
#include <mmsystem.h>
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
#include "SDL_timer.h"
|
|
|
|
|
|
|
|
#define TIME_WRAP_VALUE (~(DWORD)0)
|
|
|
|
|
2001-07-07 08:03:34 +00:00
|
|
|
/* The first (low-resolution) ticks value of the application */
|
2001-04-26 16:45:43 +00:00
|
|
|
static DWORD start;
|
|
|
|
|
2001-07-07 08:03:34 +00:00
|
|
|
#ifndef USE_GETTICKCOUNT
|
|
|
|
/* Store if a high-resolution performance counter exists on the system */
|
|
|
|
static BOOL hires_timer_available;
|
|
|
|
/* The first high-resolution ticks value of the application */
|
|
|
|
static LARGE_INTEGER hires_start_ticks;
|
|
|
|
/* The number of ticks per second of the high-resolution performance counter */
|
|
|
|
static LARGE_INTEGER hires_ticks_per_second;
|
|
|
|
#endif
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_StartTicks(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
/* Set first ticks value */
|
2001-04-26 16:45:43 +00:00
|
|
|
#ifdef USE_GETTICKCOUNT
|
2006-07-10 21:04:37 +00:00
|
|
|
start = GetTickCount();
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2013-05-02 16:54:03 -07:00
|
|
|
/* QueryPerformanceCounter has had problems in the past, but lots of games
|
|
|
|
use it, so we'll rely on it here.
|
|
|
|
*/
|
2006-07-10 21:04:37 +00:00
|
|
|
if (QueryPerformanceFrequency(&hires_ticks_per_second) == TRUE) {
|
|
|
|
hires_timer_available = TRUE;
|
|
|
|
QueryPerformanceCounter(&hires_start_ticks);
|
2013-05-02 16:54:03 -07:00
|
|
|
} else {
|
2006-07-10 21:04:37 +00:00
|
|
|
hires_timer_available = FALSE;
|
|
|
|
timeBeginPeriod(1); /* use 1 ms timer precision */
|
|
|
|
start = timeGetTime();
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
Uint32
|
|
|
|
SDL_GetTicks(void)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
DWORD now, ticks;
|
2001-07-07 08:03:34 +00:00
|
|
|
#ifndef USE_GETTICKCOUNT
|
2006-07-10 21:04:37 +00:00
|
|
|
LARGE_INTEGER hires_now;
|
2001-07-07 08:03:34 +00:00
|
|
|
#endif
|
2001-04-26 16:45:43 +00:00
|
|
|
|
|
|
|
#ifdef USE_GETTICKCOUNT
|
2006-07-10 21:04:37 +00:00
|
|
|
now = GetTickCount();
|
2001-04-26 16:45:43 +00:00
|
|
|
#else
|
2006-07-10 21:04:37 +00:00
|
|
|
if (hires_timer_available) {
|
|
|
|
QueryPerformanceCounter(&hires_now);
|
|
|
|
|
|
|
|
hires_now.QuadPart -= hires_start_ticks.QuadPart;
|
|
|
|
hires_now.QuadPart *= 1000;
|
|
|
|
hires_now.QuadPart /= hires_ticks_per_second.QuadPart;
|
|
|
|
|
|
|
|
return (DWORD) hires_now.QuadPart;
|
|
|
|
} else {
|
|
|
|
now = timeGetTime();
|
|
|
|
}
|
2001-04-26 16:45:43 +00:00
|
|
|
#endif
|
2001-07-07 08:03:34 +00:00
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
if (now < start) {
|
|
|
|
ticks = (TIME_WRAP_VALUE - start) + now;
|
|
|
|
} else {
|
|
|
|
ticks = (now - start);
|
|
|
|
}
|
|
|
|
return (ticks);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 14:45:04 -07:00
|
|
|
Uint64
|
|
|
|
SDL_GetPerformanceCounter(void)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER counter;
|
|
|
|
|
|
|
|
if (!QueryPerformanceCounter(&counter)) {
|
|
|
|
return SDL_GetTicks();
|
|
|
|
}
|
|
|
|
return counter.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint64
|
|
|
|
SDL_GetPerformanceFrequency(void)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
|
|
|
|
if (!QueryPerformanceFrequency(&frequency)) {
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
return frequency.QuadPart;
|
|
|
|
}
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
void
|
|
|
|
SDL_Delay(Uint32 ms)
|
2001-04-26 16:45:43 +00:00
|
|
|
{
|
2006-07-10 21:04:37 +00:00
|
|
|
Sleep(ms);
|
2001-04-26 16:45:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 18:04:05 -08:00
|
|
|
#endif /* SDL_TIMER_WINDOWS */
|
|
|
|
|
2006-07-10 21:04:37 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|