Serializing the game data

So I’m working on the level designer for my game, Runner (in stores near you in 2006 or so). Up until tonight, I’ve been envisioning the game data (the levels and scripts) being stored in an XML format on disk, so that someone could come along, grok my nice open format, come up with a better editor for the data than I could, and thereby enhance my game.

However, serializing into XML has no middle ground: it is either blissfully easy or incredibly, painfully, hard. Despite the help from such wonderful tools as Chris Sells’ XmlSerializer Pre-Compiler, which I first heard about from Christoph and his article about the XmlSerializer, and some exception digging and Googling, it seemed like it was no dice for my game data being easily saved into XML.

“Wait a minute,” I thought to myself. “I don’t want to futz around figuring out how to save the stuff, I want to get on with making cool game stuff!” So I relied on the good ol’ System.Runtime.Serialization.Formatters.Binary.BinaryFormatter which saved my data, with only two hitches, directly into a binary format. What were the two hitches? Seems that the BinaryFormatter has problems with System.Drawing.Pen (fine, no problem), and, more worryingly, it can’t deserialize a non-public delegate into an event. Makes sense (it is private, after all)... but it still kinda sucks. Lucky for me, I only had to change one delegate/event pair to workaround this. And what have I lost? Nothing, so far, as long as I abstract away from the BinaryFormatter stuff so that all anyone knows about is Save() and Load(). I think I’m set.

Very cool.

One Response to “Serializing the game data”

  1. David Says:

    Why does this post get more comment spam than all the others?