Archived

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

a way to see how much time has passed since the last frame?

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

Pseudo code:

//Frame Start
StartTime=GetTime()
DrawStuff()
//Frame end
TimeElapsed=GetTime()-StartTime


For GetTime you can use a number of functions, such as GetTickCount (not very accurate). I''m sure everyone will give you an opinon on which time function is the best.

Share this post


Link to post
Share on other sites

// Get the current time and keep track of the last time.
float fTime = timeGetTime() * 0.001f;
static float fLastTime = fTime;

// Subtract the current time from the last time to
// get the difference in seconds.
float fTimeElapsed = fTime - fLasttime;

// The current time is now the last time.
fLastTime = fTime;




"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan

Share this post


Link to post
Share on other sites
I was wondering what other function can u use instead of timeGetTime() to get elapsed time??
the function doesn''t seem to work well in winXP

Share this post


Link to post
Share on other sites
quote:
Original post by Michalson
Pseudo code:

//Frame Start
StartTime=GetTime()
DrawStuff()
//Frame end
TimeElapsed=GetTime()-StartTime


For GetTime you can use a number of functions, such as GetTickCount (not very accurate). I''m sure everyone will give you an opinon on which time function is the best.


i know how to find the elapsed time if i have some routine that counts at a steady rate no matter what. thats what i need is some function that ticks at least 60 times a second, preferably 200 or more. what lib is timeGetTime() in? i see it in the sdk examples, but i''m not sure what to include or link to use it. when i just try it in my code, i get a identifier error. so there must be a header or link i''m missing.

Share this post


Link to post
Share on other sites
quote:
Original post by billybob
i know how to find the elapsed time if i have some routine that counts at a steady rate no matter what. thats what i need is some function that ticks at least 60 times a second, preferably 200 or more. what lib is timeGetTime() in? i see it in the sdk examples, but i''m not sure what to include or link to use it. when i just try it in my code, i get a identifier error. so there must be a header or link i''m missing.


GetTickCount counts in ms (1/1000 of a second), it''s very fast (it simply returns the value of an OS variables), the only downside is that the value can be off by close to 10ms (+/-10ms).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

All times taken on a Pentium III - 600 MHz system.
Report file for timing the various timers.

*** Key number is the avg time.
The smaller this number, the faster the timer.


QueryPerformanceFrequency() freq = 0 1193180


method 0:
QueryPerfCntr..() 100 times
tot: 0 467
avg: 4.670000
avg time: 3.91391e-006 sec
method 0:
QueryPerfCntr..() 500 times
tot: 0 2322
avg: 4.644000
avg time: 3.89212e-006 sec
method 0:
QueryPerfCntr..() 1000 times
tot: 0 4635
avg: 4.635000
avg time: 3.88458e-006 sec
method 0:
QueryPerfCntr..() 10000 times
tot: 0 91039
avg: 9.103900
avg time: 7.62995e-006 sec



method 1:
GetTickCount() 100 times
tot: 0 11
avg: 0.110000
avg time: 9.21906e-008 sec
method 1:
GetTickCount() 500 times
tot: 0 39
avg: 0.078000
avg time: 6.53715e-008 sec
method 1:
GetTickCount() 1000 times
tot: 0 72
avg: 0.072000
avg time: 6.03429e-008 sec
method 1:
GetTickCount() 10000 times
tot: 0 680
avg: 0.068000
avg time: 5.69906e-008 sec



method 2:
TimeGetTime() 100 times
tot: 0 619
avg: 6.190000
avg time: 5.18782e-006 sec
method 2:
TimeGetTime() 500 times
tot: 0 3022
avg: 6.044000
avg time: 5.06546e-006 sec
method 2:
TimeGetTime() 1000 times
tot: 0 6681
avg: 6.681000
avg time: 5.59932e-006 sec
method 2:
TimeGetTime() 10000 times
tot: 0 137033
avg: 13.703300
avg time: 1.14847e-005 sec



method 3:
Pentium internal high-freq cntr() 100 times
tot: 0 26
avg: 0.260000
avg time: 2.17905e-007 sec
method 3:
Pentium internal high-freq cntr() 500 times
tot: 0 112
avg: 0.224000
avg time: 1.87734e-007 sec
method 3:
Pentium internal high-freq cntr() 1000 times
tot: 0 222
avg: 0.222000
avg time: 1.86057e-007 sec
method 3:
Pentium internal high-freq cntr() 10000 times
tot: 0 2197
avg: 0.219700
avg time: 1.8413e-007 sec

This tool comes with the Cg development Kit from nVidia.

-James

Share this post


Link to post
Share on other sites
quote:
Original post by Michalson
[quote]Original post by billybob
i know how to find the elapsed time if i have some routine that counts at a steady rate no matter what. thats what i need is some function that ticks at least 60 times a second, preferably 200 or more. what lib is timeGetTime() in? i see it in the sdk examples, but i''m not sure what to include or link to use it. when i just try it in my code, i get a identifier error. so there must be a header or link i''m missing.


GetTickCount counts in ms (1/1000 of a second), it''s very fast (it simply returns the value of an OS variables), the only downside is that the value can be off by close to 10ms (+/-10ms).

what library are these counters in? what one is timeGetTime() and GetTickCount in? i''ll try them both and see if there are frame fluctuations with the tick count. but i need to know what libs these are in.

Share this post


Link to post
Share on other sites
TimeGetTime defaults to some crappy inaccurate value, but is usually capable of being set to 1ms precision. Look up the timeGetDevCaps function w/ TIMECAPS structure (esp its wPeriodMin field), timeBeginPeriod and timeEndPeriod.

Link to winmm.lib and #include <mmsystem.h>

You can also use QueryPerformanceFrequency/QueryPerformanceCounter. Nehe has some code for that in some of his tutorials (can''t remember which ones). Some machines return wonky values sometimes, however, with QueryPerformance*, so be wary.

Share this post


Link to post
Share on other sites