开发对战平台的时候,需要获取并计算ping值。这时候GetTickCount就显得精度不够了,很多时候得到的ping值是0。所以有了下面这个函数:
static DWORD GetTimeCount()
{
static bool init = false;
static bool hires = false;
static __int64 freq = 1;
if(!init)
{
hires = !QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
if(!hires)
{
freq = 1000;
}
init = true;
}
__int64 now;
if(hires)
{
QueryPerformanceCounter((LARGE_INTEGER *)&now);
return (DWORD)((now*1000) / freq);
}
else
{
return GetTickCount();
}
}