Friday 26 March 2010

Mignonette game SDK

Tomorrow I'm going to be going to a Mitch Altman workshop "How To Make Cool Things With Microcontrollers"[1] and I was looking at the choices of things to make and noticed the "Mignonette Game kit". It has a SDK of sorts and a few games had been written for it so I though this would be a cool choice. Being unable to find an emulator I decided to port the game SDK to SDL[3] so I could run the games on a wide variaty of platforms that SDL supports.

After a little work I present you with the miggl game SDK. This compiles on Windows and Linux and supports the graphics and sound APIs. I've restructured them a bit and hacked around with the code to abstract it and it now has less hardware specific things exposed. Most of the common code is in libmiggl.c and then the platform specific code is in miggl-$(TARGET).c.

The current targets are SDL and ARDUINO although it should be noted that although the ARDUINO target compiles I've never tested the code generated as I don't have the hardware yet.

I've also written a game called invaders that is a space invaders clone which I havn't finished yet. It seems to work fine under SDL but It'll be interesting to see if it runs on the arduino.

I'm just working on getting my mercurial repo public but if you'd like to have a look in the mean time you can download from here.

[1] - http://bristol.hackspace.org.uk/journal/2010/02/how-to-make-cool-things-with-microcontrollers/
[2] - http://www.mignonette-game.com
[3] - http://www.libsdl.org

Saturday 6 March 2010

Google Appengine upload_data to restore keys via bulkloader is broken (Using local SDK)

I've logged an issue. 2925

I've been trying to save and restore my dataset including keys using the bulkloader as docuemnted. There are a few undocumented things that are not mentioned and quite important. First is how to save your model keys. If we had the following model

class TestModel(BaseModel):
name = db.StringProperty(required=True)


Then the following is defined to export the model

class TestModelExporter(bulkloader.Exporter):
def __init__(self):
bulkloader.Exporter.__init__(self, 'TestModel',
[('__key__', str, None),
('name', str, None),
])

Notice the '__key__' Field. This saves the key in the csv for that model.
The following should load the model back in with the key, updating it if the model already exists.

class TestModelLoader(bulkloader.Loader):
def __init__(self):
bulkloader.Loader.__init__(self, 'TestModel',
[('key', lambda x: x.decode('utf-8')),
('name', lambda x: x.decode('utf-8')),
])

Notice the special field key. This is Used in the Model.__init__ constructor in file "google/appengine/ext/db/__init__.py" Line 655 to recreate the Key from the string. This is created in bulkloader.py line 1260.

This key is then used when _populate_entity "google/appengine/ext/db/__init__.py" is called from bulkload at line 1264

_populate_entity then fills out the 'id' field with using the id() call on the key. The Issue with this is that key.id() returns a long

The Entity is then Created but line 422 of file "google/appengine/api/datastore.py" checks to see if the id is an int but it's a long so the creation fails. Can the id be a long?

My solution is to cast the return from "self._key.id()" at "google/appengine/ext/db/__init__.py" line 823 to an int.

This then fixs stuff nicly.