?? timer.cpp
字號:
#include "stdafx.h"
#include "timer.h"
unsigned int lowshift;
double pfreq;
static double curtime = 0.0;
static double lastcurtime = 0.0;
LARGE_INTEGER g_freq;
int TimerInit()
{
unsigned int lowpart, highpart;;
if(QueryPerformanceFrequency(&g_freq))
{
}
else
{
return TIMER_NO_PERFCOUNTER;
}
lowpart = (unsigned int)g_freq.LowPart;
highpart = (unsigned int)g_freq.HighPart;
lowshift = 0;
while (highpart || (lowpart > 2000000.0))
{
lowshift++;
lowpart >>= 1;
lowpart |= (highpart & 1) << 31;
highpart >>= 1;
}
pfreq = 1.0 / (double)lowpart;
return TIMER_OK;
}
LARGE_INTEGER TimerGet()
{
LARGE_INTEGER time;
time.QuadPart=0;
QueryPerformanceCounter(&time);
return time;
}
//routine taken from PocketQuake sources
double TimerGetDouble()
{
static int sametimecount;
static unsigned int oldtime;
static int first = 1;
LARGE_INTEGER PerformanceCount;
unsigned int temp, t2;
double time;
QueryPerformanceCounter (&PerformanceCount);
temp = ((unsigned int)PerformanceCount.LowPart >> lowshift) |
((unsigned int)PerformanceCount.HighPart << (32 - lowshift));
if (first)
{
oldtime = temp;
first = 0;
}
else
{
// check for turnover or backward time
if ((temp <= oldtime) && ((oldtime - temp) < 0x10000000))
{
oldtime = temp; // so we can't get stuck
}
else
{
t2 = temp - oldtime;
time = (double)t2 * pfreq;
oldtime = temp;
curtime += time;
if (curtime == lastcurtime)
{
sametimecount++;
if (sametimecount > 100000)
{
curtime += 1.0;
sametimecount = 0;
}
}
else
{
sametimecount = 0;
}
lastcurtime = curtime;
}
}
return curtime;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -