Jump to content
  • Advertisement

Archived

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

Reverse_Gecko

Millisecond Timers

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

Hello. Im working on a project and I''m doing frame rate independance, whitch works perfectly fine exept for 1 problem. I''m currently isung a startard time.h timer that only ticks at about 18.2 tiems per second, whitch is fine when my program is running at 18.2 a second or less. However programs that run at 18.2 fps or less ar undesireable. So what I need is for you to tell me how or point me to a source where I can get at millisecond timer. Basically all I need is to have a function that is called every frame that updates a global float with the amount of seconds the program has been running. And BTW, if it matters im using dev-c++ 4 Thanks for your help.

Share this post


Link to post
Share on other sites
Advertisement
All modern chips support it. I''ve heard that the 486 does not. In any case; if your game is only running 20 fps on a modern machine, it won''t run on the 486 to begin with. And, you can allways add getTickCount support - QueryPerformanceCounter returns 0 if the hardware timer is unavailable.

Share this post


Link to post
Share on other sites
Just for info, here are the performances of various timing mechanisms, profiled on a 733MHZ machine:

Timer Profile (RDTSC):
Frequency: 733373724Hz
Resolution: 1.36356e-09s
Error: 0.000227604s
Speed: 1.38006e-07s

Timer Profile (PerformanceCounter):
Frequency: 3579545Hz
Resolution: 2.79365e-07s
Error: 0.000274057s
Speed: 1.44208e-06s

Timer Profile (TimeGetTime):
Frequency: 1000Hz
Resolution: 0.001s
Error: 0.01s
Speed: 1.82705e-07s

Timer Profile (GetTickCount):
Frequency: 1000Hz
Resolution: 0.001s
Error: 0.01s
Speed: 5.39175e-08s

Timer Profile (Clock):
Frequency: 1000Hz
Resolution: 0.001s
Error: 0s
Speed: 3.71584e-06s

Frequency and resolution are pretty obvious. Error is the average error when timing for a second and will probably be a bit off (it''s difficult to calculate error when you don''t have a fully accurate timer to test against). Speed is the time taken to execute the timer mechanism.

Enigma

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Beware, NT (and that includes XP) often does not have 1 milisecond resolution with timeGetTime!
1 ms resolution is only on win9x/ME.
At the beginning you should timeGetDevCaps and than timeBeginPeriod with the minimum resolution which is returned.

I would use QueryPerformanceFrequency and QueryPerformanceCounter and if there isn''t performance counter only then I would use timeGetTime as is explained.

Share this post


Link to post
Share on other sites
Dont use timeGetTime(). Ever. It returns the time since the system was started up - if the system has been up for longer than 3 hours (IIRC) then it overflows the DWORD it returns - and disaster ensues.

Share this post


Link to post
Share on other sites
quote:
Original post by Sark
Dont use timeGetTime(). Ever. It returns the time since the system was started up - if the system has been up for longer than 3 hours (IIRC) then it overflows the DWORD it returns - and disaster ensues.


Nope. It doesn't matter if you take the difference between two values. I wrote this simple little example in Delphi:

  procedure Test;
var
NewTime: DWORD;
OldTime: DWORD;
Difference: DWORD;
begin
NewTime := 2;
OldTime := $FFFFFFFF; // $ = 0x, means hex


Difference := NewTime - OldTime; // no problem here


// format is like printf in C

ShowMessage(Format('%u', [Difference]));
end;

Try to guess the output. Yep, it was 3. It behaved properly.

[edited by - Alimonster on September 11, 2002 7:10:34 PM]

Share this post


Link to post
Share on other sites
I think it''s supposed to be every 49 days (4294967295 milliseconds) that the DWORD overflows, not after 3 hours. Put it this way, I''ve been using timeGetTime and its never overflowed on me (and I''m sure I''ve managed more than 3 hours uptime at some point ).

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.

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!