Domanda

I have been attempting to create a timer for my game and I heard about QueryPerformanceCounter and QueryPerformanceFrequency. Could someone please explain how these can be used to calculate time/fps/ticks in a game loop?.

È stato utile?

Soluzione

Microsoft support has a Knowledge Base article specifically about this:

How To Use QueryPerformanceCounter to Time Code

Basically you use QueryPerformanceCounter to get a high resolution timer value before and after the event you want to time.

Then use QueryPerformanceFrequency to get the number of ticks per second. Divide the time difference by this value to convert the value to seconds.

Altri suggerimenti

LARGE_INTEGER m_liPerformanceFrequency;
QueryPerformanceFrequency( &m_liPerformanceFrequency);

//...

LARGE_INTEGER liPerformanceCount;
QueryPerformanceCounter( &liPerformanceCount);
double dTime = double(liPerformanceCount.QuadPart)/double(m_liPerformanceFrequency.QuadPart);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top