Jump to content
  • Advertisement

Archived

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

MutteringGoblin

Accurate polling timer?

This topic is 5546 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

Hi, I need an accurate polling timer! The WinAPI documentation says that on Windows 95 and above, GetTickCount() is only accurate to within 55 milliseconds. That''s pretty poor. What other options are there?

Share this post


Link to post
Share on other sites
Advertisement
BOOL QueryPerformanceFrequency(

LARGE_INTEGER *lpFrequency // address of current frequency
);

BOOL QueryPerformanceCounter(

LARGE_INTEGER *lpPerformanceCount // address of current counter value
);


are the two functions u need...surprisingly they are in the API... first initialize the timer with the frequency and every frame get the time with counter...to get accurate down to the millisecond...divide the current time by the frequency (or multiply by the inverse <----faster, but keep the inverse as a constant variable somewhere)

[edited by - SnakeHunta on April 19, 2003 11:45:26 PM]

Share this post


Link to post
Share on other sites
This should help:

fTimeDelta is time in ms between liCurrentTime and liLastTime.

liCurrentTime, liLastTime, liTimeDelta, and liFrequency are all LARGE_INTEGERs

liFrequency is obtained from the QueryPerformanceFrequency() call.

	//Calculate time delta
QueryPerformanceCounter (&liCurrentTime);
liTimeDelta.QuadPart = liCurrentTime.QuadPart - liLastTime.QuadPart;
fTimeDelta = (double)liTimeDelta.QuadPart / (double)liFrequency.QuadPart * 1000;
liLastTime = liCurrentTime;


This is not blazingly fast, but it's very accurate and speed shouldn't be too much of an issue if you only do this once per frame.
You could optimize it by multiplying liFrequency by 1000 as soon as you get the timer frequency.

[edited by - glassJAw on April 19, 2003 12:08:45 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!