1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Cleaned up Win32 timer.

This commit is contained in:
Camilla Berglund 2013-10-28 12:07:09 +01:00
parent 174c72f2c0
commit 7d1ae7aea7
2 changed files with 26 additions and 29 deletions

View File

@ -174,8 +174,7 @@ typedef struct _GLFWlibraryWin32
struct { struct {
GLboolean hasPC; GLboolean hasPC;
double resolution; double resolution;
unsigned int t0_32; unsigned __int64 base;
__int64 t0_64;
} timer; } timer;
#ifndef _GLFW_NO_DLOAD_WINMM #ifndef _GLFW_NO_DLOAD_WINMM

View File

@ -28,6 +28,21 @@
#include "internal.h" #include "internal.h"
// Return raw time
//
static unsigned __int64 getRawTime(void)
{
if (_glfw.win32.timer.hasPC)
{
unsigned __int64 time;
QueryPerformanceCounter((LARGE_INTEGER*) &time);
return time;
}
else
return (unsigned __int64) _glfw_timeGetTime();
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -36,20 +51,20 @@
// //
void _glfwInitTimer(void) void _glfwInitTimer(void)
{ {
__int64 freq; unsigned __int64 frequency;
if (QueryPerformanceFrequency((LARGE_INTEGER*) &freq)) if (QueryPerformanceFrequency((LARGE_INTEGER*) &frequency))
{ {
_glfw.win32.timer.hasPC = GL_TRUE; _glfw.win32.timer.hasPC = GL_TRUE;
_glfw.win32.timer.resolution = 1.0 / (double) freq; _glfw.win32.timer.resolution = 1.0 / (double) frequency;
QueryPerformanceCounter((LARGE_INTEGER*) &_glfw.win32.timer.t0_64);
} }
else else
{ {
_glfw.win32.timer.hasPC = GL_FALSE; _glfw.win32.timer.hasPC = GL_FALSE;
_glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms _glfw.win32.timer.resolution = 0.001; // winmm resolution is 1 ms
_glfw.win32.timer.t0_32 = _glfw_timeGetTime();
} }
_glfw.win32.timer.base = getRawTime();
} }
@ -59,30 +74,13 @@ void _glfwInitTimer(void)
double _glfwPlatformGetTime(void) double _glfwPlatformGetTime(void)
{ {
double t; return (double) (getRawTime() - _glfw.win32.timer.base) *
__int64 t_64; _glfw.win32.timer.resolution;
}
if (_glfw.win32.timer.hasPC) void _glfwPlatformSetTime(double time)
{ {
QueryPerformanceCounter((LARGE_INTEGER*) &t_64); _glfw.win32.timer.base = getRawTime() -
t = (double)(t_64 - _glfw.win32.timer.t0_64); (unsigned __int64) (time / _glfw.win32.timer.resolution);
}
else
t = (double)(_glfw_timeGetTime() - _glfw.win32.timer.t0_32);
return t * _glfw.win32.timer.resolution;
}
void _glfwPlatformSetTime(double t)
{
__int64 t_64;
if (_glfw.win32.timer.hasPC)
{
QueryPerformanceCounter((LARGE_INTEGER*) &t_64);
_glfw.win32.timer.t0_64 = t_64 - (__int64) (t / _glfw.win32.timer.resolution);
}
else
_glfw.win32.timer.t0_32 = _glfw_timeGetTime() - (int)(t * 1000.0);
} }