Hi all,

I'm making yet another game, this time one that constantly refreshes the screen.. the only problem is, it runs faster at times and slower at other times (as in, during the *game*). I've tried a couple of methods, but both kind of suck:

a) Check the time, store it in a variable, then at the end of the loop check the time and sleep for x minus the time elapsed during the body of the loop.

-Works ok, but for some reason sometimes freezes the game when I minimize or move the window. I'm suspecting it's because when a variable gets high enough, it loops back into negatives.. then it ends up sleeping for x - (-348723) millisecs (?)

b) Set a timer, and when the time is up, call a gameMain() function, which resets the timer, etc.

-Doesn't freeze, but is very slow and inconsistant, thus defeating the purpose. I'm thinking it's because WM_TIMER messages have really low priority.


Does anybody have any better way (as in low performance cost, doesn't screw up) of evening out the framerate?