What is python-ps3?

Simply put, python-ps3 is a package of libraries for game development on the PS3 using the Python interpreted language. This allows game development to be carried out with an elegant and easy to learn language, yet still retains good performance as the complicated graphics tasks are handled in the background by the PS3's processor's secret weapon - the 6 SPU cores.

Unfortunately, despite the obviously immense power offered by the PS3, Sony have restricted access to the RSX (or graphics chip), so that the normal route for fast graphics is reserved for those wishing to purchase an official development kit, which is well out of the price range of most hobby developers (including me). All is not lost, however, because the Other OS environment does have some access to the graphics card - via a block of memory which is directly mapped to the screen. Normally, this method wouldn't even be considered for games due to speed issues, with the extra processing power available to the PS3, it's possible to do almost all the rendering tasks on the SPUs putting almost no load on the main processor. As a result, once python-ps3 is running, about 90% of the 3.0GHz PPC processor is available. So, whilst interpreted languages are obviously nowhere near as fast as compiled languages, there's still more than enough time left over to run a decent game!

You might wonder why I didn't try to get pygame working on the PS3 instead of writing my own library. Well, actually, I thougt of that (and actually, it does work... just painfully slowly!) The main problem is that pygame is built upon SDL which in turn uses libraries such as OpenGL, and so there was a lot of work to achieve that goal, and in all likelihood some games would work and others wouldn't. I decided to start from scratch, and this has allowed for some unique features that pygame doesn't support - realtime mixing of as many sound effects as you like, for example.

So, what do I need?

Pretty much, the requirements are just a PS3, another computer to develop on, some technical knowledge and a willingness to learn a bit, specifically about Linux. My distribution of choice is Ubuntu, and if you've installed Ubuntu on your PS3 (which is a fairly simple task), you can pretty much just download python-ps3 and be running within a few minutes.

Obviously, there are some issues. Older versions of the Linux kernel don't support wireless controllers and some very new kernel versions have removed support for double buffered graphics. But, on the whole, it's relatively easy if you're prepared to learn a little.

I have plans to provide a base CD image, so that python-ps3 games can be overlaid to form a ready-to-run CD, although this step isn't finished yet.

Having a seperate PC is very important for development; life is much easier if you use Linux on this too, but that's less important. But certainly, it's impossible to develop directly on the PS3 for the simple reason that the python-ps3 library takes control of the screen directly. My usual development system is a ssh session to the PS3 for running programs and an editor running on the PS3 displaying on the PC using X. Another approach is to use NFS, so that you edit your source directly on your PC and the PS3 accesses it across the network.

I have settled on using WingIDE as my preferred development environment, as it offers a lot of IDE features that I've grown used to using IDEs for other languages, such as auto-completion etc. I'm working on integrating the debugging module into my PS3 setup so that I can debug code directly from the PC. Prior to that, I was using vi on an ssh session on the PS3. Use whatever you find comfortable.

What features does python-ps3 have?

Just to whet your interest, here's a simple example of how easy it is to draw an image onto the screen (taken directly from the file):

image = Blittable("miglu.jpg"))
for count in xrange(screen.height-image.height):
        screen.blit(image, (count,count) )

Obviously, the above example gives good control over what's actually going on, but it's quite tedious (and ugly) having to list out everything that needs to be redrawn each frame. Here's an example using the Sprite API:

# this part, creates a text sprite that we put onto the screen and forget about
font = Graphics.Font("Vera.ttf", 72)
text1 = Sprite(font.text("Hello", (192,64,64)), order=3, pos=(60,60))

# the parallel of the prevous example's Blittable
image = Sprite(file="miglu.jpg")
image.pos = (20,50)

while True:
    for c in Control.controllers:
	# move the sprite (note the difference to drawing it)
        image.translate((c.leftx/2048, c.lefty/2048))

	# throw in a quick example of the sound API
        if c.start and playback != None:

    # this part ensures any sprites are drawn onto the screen
Notice how it looks a lot cleaner since we only need to update sprites that have actually moved since the last frame. The sort order can easily be specified on each sprite to allow full control over when it is drawn.

An easy to understand example for the sprites is - a well commented example that displays a real-time clicking clock!

A more complicated example using sprites is pubble - currently a work-in-progress writing a Puzzle Bobble style game, but as you'll notice once you've created a sprite, you can pretty much forget about it unless you want to move it around the screen. Notice also how subclasses the Sprite is used as this is the key to it all.

What else have you got planned?

There are a bunch of features I want to add soon. Here are a few of the things I'm planning: