[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Limited FPS?



It's probably exactly what you said - flip must be waiting for vertical retrace. If your animation took 21.8 seconds to do 610 frames, and 12.8 of that was something other than flip, than whatever you are doing to draw the animation cannot be done in 60 fps (because 610/12.8 is like 48 or something). Given that your drawing is too slow to hit 60, then flip can't hit every retrace (your monitor probably has a refresh rate of 60, or maybe even 55 given these numbers), and instead had to hit every other retrace (hence the 30 fps). The time taken by flip is mostly whatever it took to hit the next retrace and get whatever framerate is the highest whole number factor of 60 it could get.

If that is indeed what is going on, then it's not an SDL problem, and not a pygame problem. It's just how things work with vertical retrace. The alternative would be ignoring vertical retrace which would cause tearing with your display, and would cause the user to not see every part of every screen presented. Although monitor refresh rate influences what's going on, the retrace behavior is just a fact regardless of what language and environment and libraries you program in with any computer currently in existence, cause they all have retrace/refresh issues. You either wait for it and get accurate display, or don't wait and get tearing and lost data.

If you want to investigate things yourself, try flip in some controlled environments. Try it by itself, see that it takes whatever time it takes to get 60. Then try flip with a busy wait nearly as large as the time flip is taking on average, and see that flip takes nearly no time in that case (again, just what it takes to get to 60). Try it with a delay that would cause the frame rate to be below 60 if nothing else happened, see that flip takes the right amount of time to go to 30 (going to the next highest lower factor of 60)

So why did you expect things to be different?


On Wed, Nov 19, 2008 at 5:05 AM, Chris Smith <maximinus@xxxxxxxxx> wrote:
On this machine (Ubuntu 8.04, PyGame 1.7.1), pygame flip() is very slow.

A little demo I set-up and profiled showed that for 610 frames of animation - taking 21.8 seconds - pygame.flip() was taking over 9 seconds of that! Now I know that flip() has to wait for the monitor raster to get to the top of the screen, but my monitor is much more than 30 FPS! I can also understand it being a software blit, but the same number of fill() routines to clear the screen - which I have to assume moves the same amount of data - only takes 1.8s.

As I understand it PyGame is a thin layer over SDL, so is this something in SDL itself? Or am I doing something wrong?

-- Chris