# Game Programming All in One Timer Question.

This topic is 5449 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There is a timer class in the source code for Game Programming All in one. It's in vs 6. I put the code in my c++ .NET class and the GetDelta() function returns 0. Is there a difference between vs 6 and .NET?
void XTimer::Update(void){

LARGE_INTEGER kTempTimer;
time_t iTempTimeDate;

QueryPerformanceCounter(&kTempTimer);

time(&iTempTimeDate);
m_pkTime = localtime(&iTempTimeDate);

}

float XTimer::GetDelta(void){
}



##### Share on other sites
Does anybody know? Am I not doing the QueryPerformanceCounter function right?

##### Share on other sites
It may look like it returns 0, but it's not actually 0. It's just so small, you can only look at its value if your debugging it or write a function to see its value. I'd suggestion multiplying it by a thousand(to turn it from nano to micro seconds), and then have float = that value, and print to screen to see if its working.

__int64s are very weird, and so is the query performance crap. I got my fixed_time engine running by guessing, intuition, and logic.

Make sure you call Update just once, before you begin calling GetDelta. Heres some simple code to show the Performance* functions in action.

__int64 g_i64Ticks;  __int64 g_i64Frequency;float   g_Timemain(){    // Must know frequency of computer for accurate Performance Queries.    QueryPerformanceFrequency((LARGE_INTEGER*) &g_i64Frequency)    while(bGame == true)    {        QueryPerformanceCounter((LARGE_INTEGER*) &g_i64Frequency);        g_Time = (float)1000*((__int64)g_i64Ticks/(__int64)g_i64Frequency)        // ... rest of game code ... //    }}

##### Share on other sites
Its seems like that only increments by one a second. The code I had was telling me how many FPS I was getting. But what I really want to do I create a timeout function and after so many milliseconds call the function. So I need to find out how to get milliseconds.

##### Share on other sites
Wow only one poster out of 119. I guess you guys are all beginners like I am. I guess I'll have to do some more searching on google.

##### Share on other sites
I don't see anything wrong with those two functions. The problem is likely to be how they are being used. For example, if you call XTimer::Update twice in a row, then XTimer::GetDelta might return 0 (depending on the resolution of the timer).

Oh, and I have noticed that my version of MSVC seems to have a problem converting __int64 to float. See if using double instead of float makes a difference.

Also, maybe you forgot to initialize m_iFrequency.

##### Share on other sites
I suggest you use doubles instead of floats, since you'll probably need the extra resolution if you're not doing a full 'real'(ie, physics, AI, animation etc) game update between calls.

Floats are only 32 bits, so there is 0 chance that they can properly represent the range of 64 bit integers, so the two numbers would have to be different by at least 2^32 for the difference to show up at all, and even then it is unlikely to work well since floats aren't linear. Doubles, being 64 bits(on 32-bit x86 anyways), are more likely to be able to represent them to a high enough degree of accuracy. Really, you'd want the 80 bit 'long double' if it is available in your compiler.

##### Share on other sites
I used doubles and I had to times it by 1000 * 1000 to get a hundredth of one. My question is why does it work in the books code and not in mine. I inited the frequency. I even updated the time when it did. I don't understand.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 16
• 13
• 14