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

Re: [pygame] blit speedup



2010/3/28 Wakefield, Robert <rjw03002@xxxxxxxxxxxxxx>:
> I've made a tiling engine where tiles are stored as list of subsurfaces from a texture surface, and the game map is stored as a list of tile indices.  The problem is that I'm ending up with some slowdown even at low resolutions.  I was wondering if anyone's run into this before and could offer suggestions.  The code I have in the map draw() function is:
>
>    for i in self.tiledata: # i is an integer, tiledata is a standard list right now, will convert to an array for speed as the next step

Is your tile array larger than one screen?

In case it is, you want to limit this loop to include only the tiles
"touching" the current scroll-position of the player.

>        surf = dat[i]
>        sys.screen.blit(surf, (i, i)) # I would use real coordinates, the i, i is just for speed testing
>
> In particular:
>    (a.) is there a way to speed up surface.blit()?  I've already used surface.convert(), and from some of the tutorials hardware surfaces sound problematic.

H/W surfaces should not really be problematic - pygame is based on
Simple Directmedia Layer (SDL) which has years of robustness on its
shoulders.

convert() creates a new surface, in the same RGB-format as the screen
surface, so H/W blit functionality can be used instead of real-time
conversion (which has to happen anyway, of course, to get the right
colors on the screen...)

>    (b.) Is there a way to call the blit function from inlined C code?  I've seen the SciPy.blitz examples showing a massive speedup on similar loops by doing this.
>
> Thanks in advance!



-- 
http://olofb.wordpress.com