Saturday, October 23, 2010

tricks for good 2d rendering performance with pygame

pygame's API for initializing a display has a couple attractive sounding flags. Or at least, they sound attractive once you notice that updating your 320x240 window at 30fps is consuming all available cycles on your brand new Intel i9 CPU. They're HWSURFACE and DOUBLEBUF. Hardware surfaces and double buffering is how you make graphics fast, right?



Well... no. You probably can't get a hardware surface anyway, and double buffering is unlikely to help until you figure out how to have a window larger than 320x240 anyway.



What you really need to do to get reasonable rendering performance is make sure that any images you blit to the display have the same color depth. You can do this with the Surface.convert method (you get back a Surface when you load an image from a file, eg a png or a gif). Check the depth of your display surface and then convert your image surfaces to that depth (and just keep the converted versions). Blitting them will get hundreds of times faster.



It's a pretty simple thing, but it's easy to get distracted by HWSURFACE and not notice the depth mismatch (like I did for three days).

Friday, October 22, 2010

pyn is dead, long live pyn

Just about eight years ago I started working on an IRC bot using Twisted, pynfo. I managed to stay interested in working on it for about six months. I kept running an instance of it until this morning. Over the years its features have slowly decayed: it hasn't relayed messages between networks or announced pypi releases for years; more recently changes to Freenode have stopped it from even responding to commands.

As such an old project, I wrote it before I knew about things like unit tests, so even if I were interested in maintaining an IRC bot anymore, it would be easier to start over than try to resuscitate pynfo. Thus, pynfo, I consign you to oblivion. Rest in peace:


USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
exarkun 5621 8.9 12.1 275416 251248 ? Rl 2009 70025:19 /usr/bin/python /usr/bin/twistd -f infobot.tap