Advertisement

Question about timing

Started by June 10, 2000 10:35 PM
3 comments, last by UberXenon 24 years, 6 months ago
I started my first game a few days ago. It's a simple Tetris clone. I was just trying to get an accurate FPS readout so I could see how fast things were running. My question is, is GetTickCount() sufficient for this, or do I need to use QueryPerformanceFrequency() and QueryPerformanceCounter() to figure my FPS? I have a feeling that GetTickCount() isn't accurate enough. The following code is how my main game loop goes...

static DWORD millisecs;
static char buffer[20];
static float fps;
millisecs = GetTickCount();

/* clear back buffer */
/* get keyboard input */
/* blit one block around according to key input */

if(GetTickCount() == millisecs)
    sprintf(buffer, "FPS: MAX");
else {
    fps = 1.0f / (((float)GetTickCount() - (float)millisecs) / 1000.0f);
    sprintf(buffer, "FPS: %f", fps);
}

/* get DC and write fps using TextOUT */
This has been giving me "FPS: MAX" every single time. Shouldn't a memory fill, some keyboard checks, and a blit take at least one millisecond? Please give a newbie some help Four WARRIORS arrive, each holding an ORB... Edited by - UberXenon on 6/10/00 11:12:16 PM
------------------------------------------------------------Four young warriors arrive, each holding an ORB...byrdjb@email.uah.edu
Ooops, I forgot to close my code tag, but you get the idea
------------------------------------------------------------Four young warriors arrive, each holding an ORB...byrdjb@email.uah.edu
Advertisement
I think GetTickCount() should suffice. Keyboard checks, a memory fill and a blit may take less than 1 second if you have a killer system.

========================================================
If something sounds stupid but works, it's not stupid
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
is there only one "=" in
if(GetTickCount() = millisecs)
I think that would cause the problem because it would always be true(non-zero) (unless millisecs is zero which I doubt)

Dethsled
No, it is actually "==" in my code, I just typed it wrong in the post. Nice catch, tho
------------------------------------------------------------Four young warriors arrive, each holding an ORB...byrdjb@email.uah.edu

This topic is closed to new replies.

Advertisement