Thursday, May 31, 2007

Making Pygames more easily runnable.

There are a few things which would allow pygames to be run more easily. I had a little chat with Phil the other day about where pygame could be heading. So these are some of the things we talked about. In case anyone else is interested.

First though, the why. Why should pygames be easier to run? So all of the people making games can have their friends and family play them. So they can get more feedback about them. People like feedback - feedback is an engine which drives people to work on something for fun. They create things in a way, and want to show the world. Or sometimes people make things to just show their friends and family. Or their peers. However do you want opinionated, uneducated game players giving you feedback? Isn't a nice little community of game developers a worthwhile thing? I don't want to lose our nice little pygame community of artistic folks. People interested in making small games, rather than working on engines - and 3D MMORPG web browser plugins (as their first game). Do we want people to install pygame, so they can modify the games themselves? Tweaking games is the most fun part of games for some creative people. So making pygames more easily run-able should be for those who want non pygame programmers to play their games - however we should still try and let people modify games. Once people modify games, then they can create new games themselves - or continue to modify existing games.

So here is the list of things which could make pygames more easily runnable. Most of these are _not_ new ideas - these ideas just need to be done well.

* installer maker scripts which work. So people can go python make_executables and it would generate executables for each platform it supports. Failing that it could make it for just the platform it is running on. It should work out of the box on at least MacOSX, Windows, and Linux. There's been installer scripts around since 2001 - however they are just not polished enough. Recently Phil of Galcon fame has worked out a lot of the issues for macosx, windows, and linux binary generators. I think these will be a great start - however they'll need a bunch of tweaking to support other popular difficult libraries - like pyopengl, pyode, and pyogre. A common game skeleton would help too.

* a common game skeleton(or using convention). Richard plans to make a skeleton for the next pyweek. So each game would have common directories. Eg. a data/images data/sound data/music directories. It would be run with a script, or something similar. It would have screen shots in the screenshots/ directory with file names: screenshot001.png screenshot002.png screenshot00x.png It might have a .ini file with meta data like game instructions, name of game, authors, etc. Stuff like that. People have been proposing a common skeleton since 2000. However it needs to designed quite well, and we need the pygame, and pyweek site to document it well, and encourage people to use it. So we first need to design a skeleton which will work for everyone - and then update all the tutorials, and documentation to use it.

* a portable pygame runner. Something which could take a .zip file or a directory, and run the game. The runner should be able to run on at least macosx, windows, linux, freebsd etc. There have been a few attempts at this over the years - and it's been suggested about 100 times. However it's quite hard work getting this done. Phils work with the installer scripts will help out a lot here. I can't remember the other efforts to get this working. Something which used OS level protections would be great too. Things such as jail, chroot, ulimit, capabilities etc. There is work on safer python which works quite well. However OS level protection would be great too. Also a way for people to inspect games before they can be played on the runner - giving quality control and trust to the games available.

* Converting to flash swf, AND/OR javascript. Pypy is a great little python which has backends for javascript. Haxe is a javascript/actionscript compiler that can generate .swf files, or run javascript. So write the pygame api in flash/javascript(with the canvas tag) then have pypy pipe its output into haxe - which would generate the swf file. Phil has done a manual conversion from a pygame to actionscript - using basically the same api. So theoretically it should work quite well.

* More games getting into distributions. There's heaps of pygames these days. Good quality pygames. If more of them get out into the world, then there's going to be more pygame installs around. There's only 3 pygames in debian for example!!! If more pygames get out there - then people are more likely to install pygame. So we need to make it easier for people to publicise their games. Help them to port their games. Help people to announce them on freshmeat, and big game portals.

* Getting pygame installed by default in OSX. Python is installed on OSX by default- so why not pygame too? OSX is supposed to be about letting people do things easily - making games easily would be a good fit for them. Even getting SDL installed on OSX by default would be great - since then it's much easier to get pygame working. Especially with Alex's great work on pygame-ctypes (if ctypes is to be on OSX too). It'd be great to start an effort to get at least SDL installed by default. Does anyone have connections within Apple? Who are the Apple python people? Who are the Apple game people?

* The OLPC project will increase pygame usage a lot. However I'm quite scared about millions of kids using pygame - how will this change the community? It would be great if the OLPC people could come to a pygame mini sprint - we really need to start working on the issues. I'm not sure who the OLPC people are who are working on pygame? So if anyone knows - please let me know?

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Wednesday, May 30, 2007

Validating XML with a DTD and python.

Below is a way to validate an XML file using python and an external DTD.

Are there any other ways to do XML DTD validation with python?

A DTD is one way of specifying how an XML should be formed - a schema for XML documents.

from xml.parsers.xmlproc import xmlproc
from xml.parsers.xmlproc import xmlval
from xml.parsers.xmlproc import xmldtd

def validate_xml(xml_filename, dtd_filename):
"""Validate a given XML file with a given external DTD.
If the XML file is not valid, an exception will be
printed with an error message.
dtd = xmldtd.load_dtd(dtd_filename)
parser = xmlproc.XMLProcessor()
parser.set_application(xmlval.ValidatingApp(dtd, parser))
parser.dtd = dtd
parser.ent = dtd

if __name__ == "__main__":
import sys
xml_filename, dtd_filename = sys.argv[1], sys.argv[2]
validate_xml(xml_filename, dtd_filename)

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Pygame weekly mini sprint 2007/05/30

These are my notes from this weeks pygame mini sprint.

Fixed some documentation. mask, scrap, font modules.

Fixed the mask.set_at get_at functions to raise a nice exception. Thanks piman!

surface.fill() now takes the same BLEND_ADD BLEND_SUB etc flags that
surface.blit() takes. Which makes fade to white, and fade to black
type operations simple and fast. Thanks Marcus!!

Added the GL_SWAP_CONTROL constant from SDL. Thanks Eyal Lotem!

Added the new blitters from Marcus. These speed up the blend functions
and the alpha blit function.

Added a -warnings flag to for extra warnings with gcc.

A fix from Marcus for the scrap module in X11.

DR0ID has been working on a new sprite module which has a number of features. Including support for layers, and blend modes. It's supposed to be quite quick, and automatically detect if dirty rectangles will be faster, or a full screen update. DR0ID wants to make it compatible with the pygame.sprite.RenderUpdates so that people can drop it into existing games.
Here is his work so far.

I made a couple of changes to the pygame website. So that comments for releases are listed newest first, and also so that nick names are shown. This is useful for people in irc who would like to know who the person on the website is in irc. eg. if I make a comment it would show Rene Dudfield nickname:(illume)

Sunday, May 20, 2007

Pretty print xml with python - indenting xml.

Here's a fairly simple way to pretty print xml with python. By pretty printing XML, I mean indenting XML with python nicely.

from xml.dom.ext import PrettyPrint
from xml.dom.ext.reader.Sax import FromXmlFile
import sys
doc = FromXmlFile(sys.argv[1])
PrettyPrint(doc, sys.stdout)

Are there any other ways to pretty print xml with python?

How do you pretty print xml with your favourite xml API? Pretty printing xml with ElementTree anyone?

UPDATE: there's a few other ways listed in the comments.

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Wednesday, May 16, 2007

Pygame weekly mini sprint 2007/05/16

This week there were a number of patches, and bug reports to the mailing list.

Marcus got to most of them - fixing up some 64bit issues, as well as some crashes with hardware surfaces inside the transform module. Thanks to John Myers, John Poppleweel, and Christopher Stone.

Marcus also added some more warnings for gcc. Which you can enable with the command:
python build -bigw

Marcus then went through and got rid of a bunch of problems that the warnings showed.

I committed sprite changes that John Krukoff proposed in an email to the mailing list last week. They allowed the sprite module to be extended with regards to collision detection. We fixed up a slight performance problem with it for the existing type of collision detection it does.

I started to look at adding the bitmask collision stuff into the sprite module - and then noticed we weren't using a lot of its functionality. Then we got onto discussing collision response... and I wrote another big email to the mailing list about that. The subject of the email thread is:
"[pygame] [Announce] Python bindings for the bitmask collision detection library"
It hasn't appeared to have made it to the archives.

Marcus got into working on the alpha compositing patch. After some tests he found that it was slightly faster for small surfaces, but up to two times slower for large surfaces. So he plans on looking at tweaking some loops, and I plan to tighten up the graphics.

Jacob- wanted to know what could be done by someone who doesn't know C that well. Pygame needs unittests. Testing what happens with different inputs to functions is one area that needs testing. Like what happens if I pass -1 into a set clip function? Also the example programs could be extended or changed. Especially the sprite module needs unittests for the collision functions - since we plan on refactoring them soon. So Jacob- said he would make some unittests for the sprite module. the test/ is where they would go.

JKrukoff is writing another proposal for sprite collision - but this time using a more OO api. Possibly with mixins. To see how that API would turn out. He's also working on a proposal to add a Vector class to pygame - for the collision response stuff. But sshhhhh - don't tell anyone.

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Wednesday, May 09, 2007

Pygame weekly mini sprint 2007/05/09

In this weeks pygame mini sprint a few things got done.

Marcus has been working on the scrap module some more this week. He got image pasting working with the gimp. As well as got images working on windows. In the process of trying to get it working on MacOSX a mac got broken! oh noes!! Hopefully Bob can step up and do his MacOSX magic once more.

I worked on getting the bitmask library from Ulf Ekstrom integrated into pygame.

Pixel perfect collision detection is what it is good for. Since it is in C it runs very quickly too. The demo looks really cool, with things bouncing off each other.

It's in subversion now, but there's still a few things I need to do.

- make constructor which takes a surface.
- a 'make_from_surface' method in C. should take a threshold for alpha.
- complete the documentation (now in src/mask.doc)
- complete the unittests (test/test/
- make set_at and get_at raise IndexError when wrong index is given.
- double check the reference counting.
- integrate Mask into examples/

You can try it out by doing running:
    cd examples
    python data/alien1.gif

JKrukoff made a proposal in IRC about how to modify the current sprite class, so that it is extendible for different types of collision detection. So for example sphere based, AABB, or Rect, bitmask collision detection could be used. Or your own custom collision detection function. He's going to make a proposal, and implementation to the pygame mailing list - so people there can comment on it.

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Saturday, May 05, 2007

Consistent variable names across different languages - for Webs.

A dynamic website is often made up of at least three parts:
- html
- a server side programming language (eg python, php)
- a database

(* note, in the current web world, there's more than three. You probably have CSS, javascript, json, xmlprc, rss, and possibly many other encodings of a variable name.)

Why do people still use different variable names for the same data? The html form variable name, the programming variable name, and the database variable name.

Say you have a form which asks people to type their name in and their favourite colour.

First name <input type="text" name="first_name">
Favourite colour <input type="text" name="colour">
<input type="submit" name="submit" value="What is your favourite Colour?">

First name
Favourite colour

Now in the server side programming language they convert that to 'firstName' for some weird reason. That's one change that has to be done manually. Since the html variable name is 'first_name'.

$firstName = $_GET['first_name'];

Now in the database they have:

CREATE TABLE products (
`fname` varchar(255) default NULL,
`fav_color` varchar(255) default NULL,

That's a third different variable name 'fname', for the same data!

Ok, now here's the fun part. Let's add an 'ORM' which is a Object Relation Mum^H^H^H Manager. For some reason the ORM ads one more variable name change into the mix.

So rather than one variable name, you now have four. Four times as many variable names? No. Because the different names could be anything, fname, f_name, fName, first_name, firstname, firstn, Firstname, etc etc. You have to ask yourself, how was the variable name in the database written? How was it written in the HTML form? Rather than ask yourself these questions you should apply consistency, and then you will know how it is spelt.

Even if you are consistent amongst each different language, you still need to make that mental leap each time - which variable naming scheme am I using now?

Consistent variable names in one programming language is mostly a common practice. However keeping consistent variable names across all of the languages used seems to be lacking. I think the reason for this is that each language has its ways of variable naming. So people forget to apply this consistency across all of them. Preferring to keep consistent in each individual language.

Keep variable names consistent across different languages, and you will have to remember less. Which leaves room in your head for other things.

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Wednesday, May 02, 2007

Pygame weekly mini sprint 2007/05/02

Today I worked through the list of patches, and bug reports.

[BUG] fromstring,tostring work for alpha. Thanks Brian Fisher.
[BUG] Surf.set_clip(None) works correctly. Thanks Diego Essaya.
Scrap changes from Marcus so windows/osx compile.
Added scancode attribute to keyboard events. Thanks Quentin Smith.
[BUG] movie_set_display hangs on movie file-like object. Thanks Martin.

So there's a few new unittests in there for these bugs/patches too.

I think I'll finish my way through the remaining bugs, and patches next week. After that I want to resurrect movieext. movieext is a half finished module that uses ffmpeg to display movies. Also there are heaps of doc comments to look through. About 300 spam ones I reckon - but there's good stuff in there too. I also need to set my windows development environment up again. I'm hoping to fully document it this time, so that other people can get a windows pygame dev environment set up easily.

Marcus is trying to contact some Gimp people to solve an issue we are having with pasting image data into the Gimp. Pasting from the Gimp works ok - but mysteriously pasting into the Gimp does not.

We discovered that gcc isn't reporting uninitialised values of structs. It should be an extra warning flag we could use. If not, we might change to using pointers so we can get those warnings. The Surface.set_clip(None) bug brought this up.

We also had some chats about improving the display of pygame projects on the website. Browsing by date, rankings, and tags would be cool. Also the concept of a favourite playlist came up. Where people can list their favourite games in a play list. So you can share what games you like with others.

More details about the pygame weekly mini sprint can be found here: Anyone who wants to join in next week is most welcome!

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Tuesday, May 01, 2007

One Speaker Per Child (OSPC) project.

100 speakers. One for each person at a party.

Here's six mini usb sound cards attached to some usb hubs and extension cables.

The plan is to hook up 100 speakers to 50 sound cards attached to a bunch of linux computers connected via the network. Then using the OSC protocol to get them to act as one massive speaker system.

The cool thing is that there'll also be 50 microphone inputs.

I'm not sure what kind of limits I'll run into yet. It'll be interesting to see how many sound cards I can attach to each computer. Hopefully all 50 sound cards on one computer!

Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.