Timing: Hugely frustrating.

Started by
4 comments, last by skjinedmjeet 18 years, 8 months ago
Here's my problem: I'm using QueryPerformanceCounter for timing, and my game does run perfectly framerate independant on a wide variety of systems. Now, the problem is, if I just let the game synchronize to vsync, it runs perfectly smoothly. When using QPC to base timing off of, it runs fine most of the time, but every once in a while, a frame appears to "catch" and then rendering seems to jump ahead a couple of frames. I've experienced the same problem with SDL_GetTicks() and Allegro timers. It's not noticable when I only have a few objects on screen, but when I've got multiple parallaxing backgrounds, it becomes super noticable. Edit: I've just noticed that if I change, in task manager, the priority class to "high" the problem becomes infrequent, borderlining on completely unnoticable - is there a way to force this?
Advertisement
What kind of processor is this on?
Turring Machines are better than C++ any day ^_~
AMD Athlon XP 64 3000. I'd be tempted to chalk it up to a processor specific phenomena, except that most games run perfectly on this system.

I logged the delta values (time difference between frames) and noticed this happening:

1.044130.9588651.000331.00081.000971.002311.000121.00081.000571.001071.001271.001242.00219       <---- very high value1.00051.000871.001091.007320.9950541.000651.000841.002091.00028


It happens every now and then, and it seems to directly correlate to my problem.
It sounds like your game is getting swapped out so other processes may run a bit, in a noticibly coarse grain - suggesting (to me) that your game is eating up a lot of the CPU. Assuming this is all true, adding the occasional (by which I mean, single, within the body of the game loop) sleep(0) statement or similar may help (e.g. swap out if other processes have a need to execute - note that sleep(0) may be a no-op depending on the exact function called, this is API dependant stuff).

It's not guaranteed to work, but the theory is if other processes get a chance to run more often, chances are they'll have less work to do once they get that chance. It's worth a try, anyways. Chances are this would harm preformance when the user is running (as in, actually running, eating up CPU, not just idling in the background using pagefile space) enough other programs.

All this said, the fact that your example shows a spike to nearly exactly 2.0 (not 1.9 or 2.1) seems a bit fishy, prehaps you've got a bug in your logic code or drivers? Just throwing out suggestions.

Also, since you mention process priorities, I should mention SetPriorityClass. I wouldn't recommend it, but if you want to go down that path, there's information on this functino in The MSDN

HTH
This sounds like another process is taking too long. Certain things seem to do this on certain patforms. I'm developing on Debian linux and for me i notice that web pages open that have any kind of flash/java business on them (like those silly animated flash adverts) will chunkify the framerate. I also notice it when i have my System Monitor open, which monitors active processes (including the game and itself). Ironically, it throws in it's own "hiccup" every 3-4 seconds or so.

I suggest closing every other non-critical application open on your system and seeing if that helps first.
sleep(0); has definitely helped a bit, it still chunks every once in a while, but if I turn off other applications it seems to do okay. Thanks for the help, dudes!

This topic is closed to new replies.

Advertisement