PyGame "smart" Group and Sprite implementations

These days Marcelo asked for a prototype in Python and SDL (PyGame) to work on Nokia/maemo devices.

After a preliminary attempt using pygame.sprite.OrderedUpdates I realized it was way too slow. Since heavy operations are handled in C by SDL itself, that shouldn't happen.

After some hunting and code review, it was the way PyGame's OrderedUpdates (and RenderUpdates) does clear() and mark regions to be updated after draw() that was the culprit. Both clear and updated rectangles may overlap, causing SDL to operate on the same area more than once, which is awful.

So Chenca and I started to work on a way to split rectangles that overlap into smaller pieces, avoiding more than one covering the same area, I've implemented this algorithm in Python and now the code runs about 2-3 times faster :-)

I've written 3 new classes to help development with PyGame, you can get them and the example at my SVN: http://barbieri-playground.googlecode.com/svn/pygame/smart_render/

Chenca and I will try to provide some other utilities to make pygame development for Maemo easier, like these rectangle split in C, functions to blit images with per-pixel alpha faster and also one to blit per-pixel images added to image alpha (enable fade in/out of elements with pixel transparency). Stay tuned.

UPDATE: SDL (and thus PyGame) already provide accelerated blit functions for 16bpp, just enable RLEACCEL flag of your Surface. I'm using the following code to load images (check SVN link above):

img = pygame.image.load(filename)
img.set_alpha(255, RLEACCEL)
img = img.convert()