Public Group

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

This topic is 3635 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
timeGetTime() has around 5-10 ms of accuracy. Which means, you'd never get 0.0019 (1.9 ms). Try using QueryPerformanceCounter and QueryPerformanceFrequency.

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 on other sites
Why are you doing a modulus of the delta?

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();}

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 12
• 14
• 9
• Forum Statistics

• Total Topics
633351
• Total Posts
3011479
• Who's Online (See full list)

There are no registered users currently online

×