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

Re: [pygame] [Pygame] How can I have an accurate timing when I am showing an image?



I want to thank all of you for the suggestions you provided me: now
the program is working really better. After some tests, I noticed that
If I load images before the time I need timing accuracy results are
indeed good: sometimes I lose 1 msec, but it is not so dramatic for my
purposes. The class provided by Brian Fisher provides also really
accurate results, the problem is that, if I am not wrong, any signal
could terminate the sleep (since users should interact with the
keyboard after images are displayed, I fear that they could
accidentally hit one key before the right time, namely after image
disappear): is pygame.time.wait more accurate than time.sleep?

Francesco

On Sat, May 24, 2008 at 9:19 AM, Noah Kantrowitz <kantrn@xxxxxxx> wrote:
>
> On May 24, 2008, at 12:08 AM, Brian Fisher wrote:
>>
>> On Fri, May 23, 2008 at 9:15 PM, Noah Kantrowitz <kantrn@xxxxxxx> wrote:
>>
>> Anywhere you need that kind of timing accuracy, python is probably not the
>> right tool for the job. I would recommend using plain SDL in C, you will
>> likely find it much more stable timing-wise.
>>
>> You may be right that python is a poor tool in cases where you need timing
>> accuracy for stuff where you execute a lot of python code, but I really
>> doubt python would pose any limitation for just showing an image for a
>> specific amount of time. Task switching, timer resolution and video refresh
>> all represent larger chunks of time than python code execution, and also the
>> approach to doing the timing matters a lot more than whether python is
>> executing it or c is for most tasks.
>
> Beware the cycle detector. It introduceth non-deterministic execution
> profiles.
>
> With that disabled, and care taken to make sure nothing will be loaded off
> disk when you don't expect it (lazy module loading or activation for
> example), it should be okay, but with C you know exactly what code is
> running and when.
>
> A note on the original code, you probably want to use
> pygame.time.get_ticks(), not time.time().
>
> --Noah
>