PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GetTickCount rollover

Does anyone ever consider the fact that GetTickCount could roll over from a really big number (2^32 - 1) to zero during program execution?

Does GetTickCount reset back to zero when the device is put into suspend mode?

If my math is right, the counter should roll over every 50 days or so.

Eric
Yep, you are right. The counter will roll over every 49.7 days.

But this doesn't really matter, does it? What you are interested in is the difference between two points in time. Not the absolute time.
If you use unsigned longs, the accuracy of the numbers makes it come out right.

For instance, if you were using unsigned 8 bit numbers...

253 was last time
rolled over to 3.
delta=3-253
will give you 6.
hmmm... my animation timing system works by comparing the current time to the previous time and if the current time - previous time >= frame time period then update the frame used.

maybe I should use abs(current time - previous time) that way the animation only jumps a little when the time resets to 0.

What solution do other people use ?
abiemann wrote:hmmm... my animation timing system works by comparing the current time to the previous time and if the current time - previous time >= frame time period then update the frame used.


"(current time - previous time) >= frame time" is perfectly fine. That's what you should use.

abiemann wrote:maybe I should use abs(current time - previous time) that way the animation only jumps a little when the time resets to 0.


There is no need for abs(). GetClock() returns an unsigned number. So (current time - last time) will always be >= 0. It won't jump at all when the timer "resets" to 0.

abiemann wrote:What solution do other people use ?


The one you proposed =)
hehe, thanks!