[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] How fast is pygame meant to be?



On Monday 03 June 2002 13:59 pm, you wrote:
> Hi,
>       I'm a Blitz Basic (www.blitzbasic.com) user who's been playing
> aroudn with pygame, so the first thing I decided to do was to make a pygame
> version of the "firepaint" demo that comes with BB. It's a simple demo that
> shoots sparks from your mouse cursor that fall to the screen when you click
> the mouse. I'm no good at optimising, so the code just follows the BB
> firepaint demo pretty closely. When I ran the demo, it ran *much* slower
> than the BB demo, at 8fps, whereas in BB it runs at my refresh rate
> (80fps+) Is pygame just not meant to be used for this kind of thing, and
> just blitting a few images and playing some sounds, or is there some secret
> different way of doing things I haven't found yet? :)
> If you're interested, I've uploaded my firepaint demo to
> www.ebizimonkey.com/firepaint.py
>
>       Christian Perfect

I don't know about the huge speed difference but I have a few things:

First, I checked for a divide by zero in fps=int(1/(ms-oldms)) to make the 
program run at all.

Second, use "screen.fill(col, [self.pos, [4, 4]])". pygame.draw.rect. is used 
to draw borders and is much slower when filling rectangles.

Third,          
                frags.remove(self)
I am not sure how this works internally - perhaps a real python developer 
could explain? - but it looks very slow. You pass 'remove' an object and then 
something has to figure out where in frags[] that object is and remove it. At 
least at my box the program ran faster when i used frags.pop and passed it an 
index number:

        # update frags
        for n in range(len(frags) - 1, -1, -1):
                frags[n].update()
                if (not frags[n].onScreen()): 
                        frags.pop(n)

It walks through the array backwards to allow removing an object without 
screwing up the numbering of the remaining items. onScreen is a method of the 
frag class:

        def onScreen(self): return self.pos[1] < 480 and self.pos[0] >= 0 and\
                        self.pos[0] < 640

Of course this is still not the fastest way to filter the frags list, but I 
don't think it is the bottleneck. My new version did 6 fps instead of 1 fps 
(measured around 2000 frags)
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org