Advertisement

stupid timer (i took my moron pills today)

Started by January 12, 2001 02:22 PM
0 comments, last by Prairie 24 years ago
I just don't seem to be able to think this afternoon. I'm sure it's just an order problem, but if you could take a look at my function and point me towards a solution it would be gratefully recieved The problem is that once started, the FPS display counter slowly decreases. the timer is initialised as follows: next_time = timeGetTime(); next_time += 1000; my updateFPS function is called just before my render routine in the main program loop. void UpdateFPS() { current_time = timeGetTime(); if (current_time >= next_time){ //fpsdisplay is converted to a string //and rendered in my render function FPSdisplay = FPScount FPScount=0; next_time = current_time; next_time += 1000; } else{ FPScount++; } } there's the code, it's very simple so i'm just being a moron today. Thanks; Prairie Edited by - Prairie on January 12, 2001 3:25:44 PM Edited by - Prairie on January 12, 2001 3:26:29 PM
Is it impossible that it actually is slowing down?

Nope, your code is crap =) I made the same mistake when I first started fiddling with timers.

When you calculate the time to sleep, you need to sub off this cycles time.

SleepTime=1000;

while(....)
Sleep(SleepTime);
now = timeGetTime();
Elapsed = prevTime - now;
prevtime=now;
SleepTime = 1000 - Elapsed; //if it's negative the computer is too slow


Edited by - Magmai Kai Holmlor on January 12, 2001 7:51:17 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement