I changed the win32 timing loop to be more accurate. The current implementation uses GetLocalTime which is only millisecond accurate on win32. I changed it to use QueryPerformanceCounter which hardware-supported high resolution timer.
Changes to CCStdC.cpp are as follows:
external/cocos2dx/platform/CCStdC.cpp | 19 +++++--------------
1 files changed, 5 insertions(+), 14 deletions(-)
diff --git a/external/cocos2dx/platform/CCStdC.cpp b/external/cocos2dx/platform/CCStdC.cpp
index f0d0f8c..8bb8992 100644
--- a/external/cocos2dx/platform/CCStdC.cpp
+++ b/external/cocos2dx/platform/CCStdC.cpp
@@ -30,20 +30,11 @@ int CC_DLL gettimeofday(struct timeval * val, struct timezone *)
{
if (val)
{
- SYSTEMTIME wtm;
- GetLocalTime(&wtm);
-
- struct tm tTm;
- tTm.tm_year = wtm.wYear - 1900;
- tTm.tm_mon = wtm.wMonth - 1;
- tTm.tm_mday = wtm.wDay;
- tTm.tm_hour = wtm.wHour;
- tTm.tm_min = wtm.wMinute;
- tTm.tm_sec = wtm.wSecond;
- tTm.tm_isdst = -1;
-
- val->tv_sec = (long)mktime(&tTm); // time_t is 64-bit on win32
- val->tv_usec = wtm.wMilliseconds * 1000;
+ LARGE_INTEGER liTime, liFreq;
+ QueryPerformanceFrequency( &liFreq );
+ QueryPerformanceCounter( &liTime );
+ val->tv_sec = (long)( liTime.QuadPart / liFreq.QuadPart );
+ val->tv_usec = (long)( liTime.QuadPart * 1000000.0 / liFreq.QuadPart - val->tv_sec * 1000000.0 );
}
return 0;
}
Hopefully you like it!