Advertisement

GetTickCount is not perfect!

Started by June 15, 2000 05:07 PM
4 comments, last by baskuenen 24 years, 6 months ago
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?
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
==============================
whats a signature?
htm[s]l[/s]
Advertisement
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
That''s the function I was looking for! Um, is it compatible with GetTickCount? Like, does it use the same intervals.

------------------------
Captured Reality.
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.

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

ao

Play free Java games at: www.infinitepixels.com
Some code to help you along.
HTH.
gimp



init:

LARGE_INTEGER		Freq, OldTick,CurTick,DeltaTick;QueryPerformanceFrequency(&Freq);QueryPerformanceCounter(&OldTick); 


and the actual timer(I convert to a float)

QueryPerformanceCounter(&CurTick);SubLarge(&OldTick, &CurTick, &DeltaTick);OldTick = CurTick;if (DeltaTick.LowPart > 0)	ElapsedTime =  1.0f / (((float)Freq.LowPart / (float)DeltaTick.LowPart));else 	ElapsedTime = 0.001f; 

Utility for 64bit interger math
void SubLarge(LARGE_INTEGER *start, LARGE_INTEGER *end, LARGE_INTEGER *delta){	_asm 	{		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	}} 
Chris Brodie

This topic is closed to new replies.

Advertisement