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


GetTickCount is not perfect!

Recommended Posts

Yesterday, I ran one of my programs. It uses GetTickCount for animations. I just multiply the distance or angles with the GetTickCount result. The problem: It ran at half the normal speed!!! But after a reset, all went back to normal. Are there more people who even encountered such a problem?

Share this post

Link to post
Share on other sites
i think maybe it had to do somthing with your computer's buffers, not your program. i think that there is a function that can refreshes your video buffers when your program starts to fix this problem.

but i like timeGetTime() better anyways for my FPS regulations and animations.

Edited by - gameprogrammerwiz on June 15, 2000 6:21:54 PM

Share this post

Link to post
Share on other sites
Yes, using the timer functions can be really anyoying sometimes. There is a better set of functions in the mmsystem.h include file called the high performance counter functions, which are super accurate. The only problem with them is they don''t work on older systems (486 and under I believe, if I am wrong someone correct me). Other than that, I have used hires timer for everything and haven''t run into a single problem yet.

the two functions you use are:
QueryPerformanceFrequency and QueryPerformanceCounter

Share this post

Link to post
Share on other sites
Just thought I would throw in my experiences with the hires timers.

I used to use GetTickCount() to time animations and move objects based on the frame rate. That worked fine for my pIII600 but when I went and tried it on a p200 I would get jerkiness. Then I decided to try out QueryPerformanceFrequency and QueryPerformanceCounter. After trying those out my program ran smoothly on both pc''s.

To get the time intervel/resolution of the hires timer call
QueryPerformanceFrequency, that will give you the ticks per


Share this post

Link to post
Share on other sites
Some code to help you along.


LARGE_INTEGER Freq, OldTick,CurTick,DeltaTick;


and the actual timer(I convert to a float)


SubLarge(&OldTick, &CurTick, &DeltaTick);

OldTick = CurTick;

if (DeltaTick.LowPart > 0)
ElapsedTime = 1.0f / (((float)Freq.LowPart / (float)DeltaTick.LowPart));
ElapsedTime = 0.001f;

Utility for 64bit interger math

void SubLarge(LARGE_INTEGER *start, LARGE_INTEGER *end, LARGE_INTEGER *delta)
mov ebx,dword ptr [start]
mov esi,dword ptr [end]

mov eax,dword ptr [esi+0]
sub eax,dword ptr [ebx+0]

mov edx,dword ptr [esi+4]
sbb edx,dword ptr [ebx+4]

mov ebx,dword ptr [delta]
mov dword ptr [ebx+0],eax
mov dword ptr [ebx+4],edx

Share this post

Link to post
Share on other sites