Jump to content
  • Advertisement
Sign in to follow this  
2dcoder

API - timeBeginPeriod - ok to use?

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

http://gpwiki.org/index.php/VB:Timers At the above page there seems to be an elegant, easy to use solution for precise millisecond timing using the following apis: Private Declare Function timeGetTime Lib "winmm.dll" () As Integer Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Integer) As Integer It allows you to "specify an accuracy of 1 ms to match the 1 ms resolution of timeGetTime". This would allow your game to get precise ms handling without resorting to using the highperformance timers which may or may not be present on the host computer. Are the above api's stable and ok to use? Any drawbacks??? Thanks for any input.

Share this post


Link to post
Share on other sites
Advertisement
I've been using that setup since I started in game development. That was 5 years ago. Still using it [smile]

I started off with the resolution set at 1 ms. I later realized that the framerate wasn't ever really fast enough to warrent a 1ms timer, so I jacked it up to 5 ms. No visible difference. The accuracy is still perfectly on the single millisecond mark, but the callback is called every 5 ms instead of 1 ms.

I can't tell you if there are any hidden flaws, but I've never had any complaints with demos.

Share this post


Link to post
Share on other sites
Quote:
Original post by 2dcoder
This would allow your game to get precise ms handling without resorting to using the highperformance timers which may or may not be present on the host computer.

Just a quick note - I presume you're referring to the QueryPerformanceCounter() and QueryPerformanceFrequency() methods with this? Or is it that rtdsc (?) instruction counter thing.

Either way, I remember reading that pretty much every desktop PC has had this capability since the 386's with a few exceptions upto the early Pentium-100 level (think the more "obscure" chipsets like Cyrix were a bit odd). Chances of meeting a desktop that doesn't support high resolution timers is probably so unlikely as to not bother worrying about [smile]

Cheers,
Jack

Share this post


Link to post
Share on other sites
It looks like the documentation on that page is wrong, it appears the vars should be passed as long not integers. ?

Share this post


Link to post
Share on other sites
Quote:
Original post by 2dcoder
It looks like the documentation on that page is wrong, it appears the vars should be passed as long not integers. ?

You just supply a callback. The callback is called every so many milliseconds. You can increase any type of variable you would like by any amount you want in the callback method.

Under 32-bit processor, long == int. You definitely want a variable whos value won't loop over very soon.

Share this post


Link to post
Share on other sites
I'm using VB6 which doesn't support the callback so I just read timeGetTime. ;)

This is working like a charm. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by 2dcoder
I'm using VB6 which doesn't support the callback so I just read timeGetTime. ;)

Bit of a moot point if it's working fine for you... but VB6 does support Win32 callbacks... Not sure you can use them as a general purpose language construct, but they are available for Win32 API calls..

Have a look at the AddressOf operator (example)

hth
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!