update hl_sys_time to support OS below Windows 8
@@ -164,17 +164,26 @@ HL_PRIM void hl_sys_exit( int code ) {
HL_PRIM double hl_sys_time() {
#ifdef HL_WIN
#define EPOCH_DIFF (134774*24*60*60.0)
+ static double time_diff = 0.;
static double freq = 0.;
LARGE_INTEGER time;
+ LARGE_INTEGER start_time;
FILETIME ft;
+
if( freq == 0 ) {
QueryPerformanceFrequency(&time);
freq = (double)time.QuadPart;
}
- GetSystemTimePreciseAsFileTime(&ft);
- time.LowPart = ft.dwLowDateTime;
- time.HighPart = ft.dwHighDateTime;
- return ((double)time.QuadPart) / freq - EPOCH_DIFF;
+ QueryPerformanceCounter(&time);
+
+ if( time_diff == 0 ) {
+ GetSystemTimeAsFileTime(&ft);
+ start_time.LowPart = ft.dwLowDateTime;
+ start_time.HighPart = ft.dwHighDateTime;
+ time_diff = ((double)start_time.QuadPart - (double)time.QuadPart) / freq - EPOCH_DIFF;
+ }
+
+ return time_diff + ((double)time.QuadPart) / freq;
#else
struct timeval tv;
if( gettimeofday(&tv,NULL) != 0 )
