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

Re: [pygame] refresh rate and timing issues



Hi Andre,
  flip doesn't work exactly the way you are thinking. more below.


On Nov 18, 2007 11:14 AM, Andre <andre.knops@xxxxxx> wrote:
> I want pygame to synchronize the presentation of a certain stimulus with the
> vertical refresh of the monitor, which is what flip() should do in this mode,
> right?
>
That is what it is supposed to do in that mode. However, for
performance reasons, flip doesn't wait for the flip operation to
happen before returning. It's more like a "set and forget it" op. the
idea is that the game ought to be able to make use of the cpu by
updating game state while the video card is waiting to do the flip for
you. It's not a busy-wait-for-flip operation.

Pygame flip just calls SDL_Flip, read here and you will see
verification of what I am talking about.:
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fFlip

Note that the docs there imply that if you tried to lock or blit to
the display buffer after calling flip, you would need to wait for the
retrace to finish before the lock/blit would be done. The reasoning
for that behavior is that the buffer you would use after the flip is
the one in use by the video card before the flip - so you can't do
more drawing or whatever until after the flip, which is why those
operations would have to block.


> But what I get is somthing like this:
> 51, 47, 32, 51, 20, 23, 54, 28, 40, 18, 41, 18, 18, 72, 32, 37,...
>
I'm curious, do you get something -like- that, or did you actually get
that? the reason I ask is you might be able to see telling patterns
from the actual data that you didn't notice - so if those are just
numbers you typed, they wouldn't help people on the list see patterns
which you didn't recognize.

In other words, if you have actual numbers, it's good to post those.
Posting your impression of the numbers will likely confuse the issue
and hide what actually goes on.


> I understand the longer times, since the pictures are taken from the HD,
>
Also, you may also get the occasional long times because of other apps
swapping in and all that. I think the windows 2K/XP timeslice can be
anywhere from 10-100ms depending on performance settings and whether
the app is foreground or background, meaning if some user app gets the
cpu from your app, it may not get it back for a tenth of a second. The
moral there is if you don't want to get interrupted in areas where you
need the CPU, make sure to sleep and such when you -don't- need the
CPU


> but the "18"s, "20"s, etc. I do not understand. How is this possible?
>
Probably because your app delayed for 18ms, the flip returned
immediately and the previous load+draw must have happened in less than
1ms?


> What I really want is the time WHEN pygame REALLY presented something on screen
> which can then be used for later analyses.
>
> Does anybody have an idea how to do this?
>
Try the lock/blit idea, re: the sdl docs for flips