Sign in to follow this  

trying to calculate delta time each frame and getting weird results?

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

I'm trying to calculate delta time each frame, but the results seem odd, especially compared to the amount of frames I'm getting? Useing timeGetTime() for simplicity sake. I get the time at the beginning of a frame and save it, on the next frame I get the new time and subtract the old time from it to get DELTA. then I do a calculation like so.
unsinged int DELTA;
float decimalDELTA;

decimalDELTA = int( DELTA % 1000 );
decimalDELTA *= 0.001;

I'm doing this to turn the delta into a decimal value to make other parts of my code easier to adjust. The weird part and I'm not sure if it's getting the right value, the decimalDELTA averages 0.081, but the frame rates hover around 524. If I'm correct using the frames per second to get the delta it'd be 1/524 or 0.0019. Technically the 0.0009 would be out of range for timeGetTime(), but still I should be averageing 0.001 for the delta right?

Share this post


Link to post
Share on other sites
If for some reason you don't want to use the Performance Counters, you can look at this.

http://msdn.microsoft.com/en-us/library/ms713418(VS.85).aspx

Notably this section:

"Windows NT/2000: The default precision of the timeGetTime function can be five milliseconds or more, depending on the machine. You can use the timeBeginPeriod and timeEndPeriod functions to increase the precision of timeGetTime. If you do so, the minimum difference between successive values returned by timeGetTime can be as large as the minimum period value set using timeBeginPeriod and timeEndPeriod. Use the QueryPerformanceCounter and QueryPerformanceFrequency functions to measure short time intervals at a high resolution,"

If you read into those, you can see that using the timeBeginPeriod, and timeEndPeriod, you can set the precision to a 1ms, but it might degrade the performance of the machine (since it's a system wide setting (note, that this is set to the lowest resolution any programmers, as for, meaning if you set yours to 1, everything will be at 1, and can't make it go higher, until timeEndPeriod is called, at least), processes and such might be switching more often, causing a degrade).

But, I'd just use the Performance Counters ;-)

EDIT: I'm not going to edit it, but see if you can decipher through that horrible grammar in that second paragraph. XD

Share this post


Link to post
Share on other sites
For what are you needing such a framerate? My LCD monitor can draw 50 frames per second.

You have now:

loop(){
do_something();
count_time();
}


Change it into:

loop(){
repeat 10 times{
do_something();
// If you need time here, use your counter-variable and latest time to calculate it
}
count_time();
}

Share this post


Link to post
Share on other sites

This topic is 3294 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this