Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

How can I create a very accurate timer with very small intervals?(win32 platform)

This topic is 6560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Look into QueryPerformanceFrequency() and QueryPerformanceCounter() in the Win32 API. timeGetTime() is a less accurate method, but still gives you resolution of 1 ms in Windows 9x (default 5 ms in NT). The frequency of the performance counter is usually 1.19 MHz, which is 0.84 microsecond resolution. Not bad, huh?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
He was asking about a timer not functions that give you the current time. You can create a high resolution multimedia timer with a resolution of 1ms.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Multimedia timer 1ms interval ?
I created this
setTimer(hWnd,1,1,NULL);
and this
WM_TIMER:
x++;
break;

Normaly will x be 1000 after 1 sec but it is rater 4 ??????
I need at least 200 updates each sec. Because I use in my meanloop(called around 100 times/sec):
if (keys[VK_UP])
world.movez(x);
if (keys[VK_DOWN])
world.movez(-x);
if (keys[VK_LEFT])
world.rotateY(x/constant);
if (keys[VK_RIGHT])
world.rotateY(-x/constant);

And I have a framrate of around 100. So if the update speed is slower then this framerate will it look like there is a slower framrate.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How can I create a very accurate timer with very small intervals?(win32 platform)

Share this post


Link to post
Share on other sites
Ok, as far as I know, there are THREE common timer systems on the windows platform. The standard Windows timer, the MultiMedia timer, and the High Performance timer. The first has a resolution of 55ms (useless), the second SUPPOSEDLY 1ms (but it has a higher latency than that), and the third (the one I recommend) is REALLY more like getting the time than a built in timer.

I''m currently writting a gamedev.net article on this subject, but I''ll give the you basic idea. What you do is layer your own concept of a timer on top of calls to QueryPerformanceCounter() in the message loop. Each iteration (or after a fixed number of iterations) through the message loop, you query the timer, then check to see if each of your timers has elapsed its time interval. If it has, post ITS associated message. This makes it behave just like the Multimedia timer, but with much greater accuracy, and only about 20-200 lines of code (depending on the level of sophistication you need).

Share this post


Link to post
Share on other sites