Timing

• 06-23-2004
jimboob
Timing
Does anybody know of a good way for getting system time?
i've tried timeGetTime but maybe I didn't do it right. I put the below code into the program but the numbers it outputted came out bizaar.

///////////////////////////////////////////////////////

float FrameInterval;

void CalculateSpeed()
{

static float lastTime = 0.0f;

static float frameTime = 0.0f;

float currentTime = timeGetTime();

FrameInterval = currentTime - frameTime;
frameTime = currentTime;
}

////////////////////////////////////////////////////////////

This code is actually for an OpenGL program i'm 'trying' to make which is based on Time Based Movement. I read some tutorials and the 'timeGetTime' function was the one they recommended. I posted this in this Board instead of the "Game Programming Board" because I figured it had more to do with the whole of C++.
TIA
• 06-23-2004
Salem
> I put the below code into the program but the numbers it outputted came out bizaar.
So show how you output the numbers, and what sort of output you get
• 06-23-2004
jimboob
Whoops... Sorry about above code compared to this one... I used the old code on the above example...
Heres the whole Program
///////////////////////////////////////////////////////

#include <windows.h>
#include <iostream.h>
#include <mmsystem.h>

float FrameInterval = 0.0f;

void CalculateSpeed()
{
static float frameTime = 0.0f; // This stores the last frame's time

float currentTime = timeGetTime() * 0.001f;

FrameInterval = currentTime - frameTime;
frameTime = currentTime;
}

int main()
{
for (int index = 0; index < 100000000000; index++)
{
CalculateSpeed();
cout << FrameInterval << endl;
}
return 0;
}

/////////////////////////////////////////////////////

I get a group of numbers.... Something like
0.0076599 and repeats a couple of times
0.0076598 and repeats a couple of times
0.0076597 and repeats a couple of times
And it keeps counting down.

Is there a possibility my computer is too fast for timeGetTime?
I have a athlon2500xp @ 3200xp

Thanks
• 06-23-2004
Salem
Try outputting timeGetTime() without all the float arithmetic

I'd expect some variation from one call to the next (calculating time differences), so it should wander around some mean value.
Are you sure it counts down to 0?

Also, if you want to preserve all the accuracy returned by timeGetTime(), you need a double, not a float.