December 30, 2011

XML and Save Games

I'm about ready to continue forward in developing the various game classes (planets, stars, etc.), but there is one last system that I definitely need to build before moving forward much--saving and loading the game state and game parameters.

I'm planning to hold as much data as possible in external files, allowing users to edit and modify as they wish.  I see three different types of data files:

1) Game parameters, such as galaxy sizes, weapons damage, or the max. number of planets allowed per system.
2) Save game data.
3) Application settings information, such as keyboard mappings, video settings, etc.

I'm currently using Java Enums for some of (1), have not even touched (2), and have a Settings object that I pass to the relevant systems for (3).  I plan to convert (1) and (2) entirely to XML, and probably create an XML file that contains (3) as well.

For (1) and (3) I can probably use either Java's native XML capabilities (likely going the DOM route), JAXB, or XPath for creating new, user-generated classes.  The latter two options would be exercised if the user (for example) added new technologies to the game by editing the tech tree XML file.  

For (2), I plan to use XStream, which looks like a very quick and powerful way to grab object data and store it in XML, and then also unpack XML data back into Java objects.  I test ran it the other night by saving just one StarSystem object--and it followed all the references in the Controller, Views, and Model for that system, creating a 1.2MB text file...  Upon review, it had followed references to Java Monkey Engine classes and ended up saving a good chunk of the graphics engine's underlying object data, none of which was necessary.  Oops.  I can write some conversion classes that will better determine what data should be saved.

So all this is what I'll be doing over the next couple weeks--in addition to just refreshing my memory on XML (worked with it for a month or two about 5 years ago!) and celebrating the new year!  I also got the new Deus Ex game for Christmas, so I might be a little slower than I'd like in getting to all this... :)

1 comment:

  1. Hmm... I may be able to use STAX instead of SAX. Investigating. This is all new to me!