SyntaxHighlighter

Saturday 20 November 2010

Content Pipeline extensions

Well I've had some fun so far today. I finally got tired of my firewall sandboxing my application every time I needed to use XmlSerializer to load a map file, meaning that I needed to recompile twice everytime I made a change to the source code.

So I decided to try and use the Content pipeline to load my maps. This would also have the advantage of compiling my maps to the binary xnb format, taking advantage of the format's compression.

It took me a while to get my head around it, but eventually I came up with the following importer:



[ContentImporter(".mm", DefaultProcessor = "", DisplayName = "AETileMapImporter")]
public class AETileMapImporter : XmlImporter
{
      public AETileMapImporter()
           : base()
       {
       }

       public override object Import(string filename, ContentImporterContext context)
       {

           SaveMapStruct retMapStruct = new SaveMapStruct();

           FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read);
           try
           {
               XmlSerializer serializer = new XmlSerializer(typeof(SaveMapStruct));
               retMapStruct = (SaveMapStruct)serializer.Deserialize(stream);

           }
           finally
           {
               stream.Close();
           }

           XmlWriterSettings settings = new XmlWriterSettings();
           settings.Indent = true;
           filename += "X";
           using (XmlWriter writer = XmlWriter.Create(filename, settings))
           {
               IntermediateSerializer.Serialize(writer, retMapStruct, null);
           }

           return base.Import(filename, context);
       }

}



This code could easily be tweaked by others to use for their own custom importer, allowing them to import xml files serialized with XmlSerializer.

Hope someone finds it useful!

Friday 19 November 2010

Character physics integrated!

Just a quick progress report. I've adapted the Farseer 3.0 platformer tutorial for Alta, and I've added a AEPhysicsCharacter class, which I've integrated into the AECharacter class alongside AEAvatar. It will now play animations at the same time as moving the character around.

Next up, implementing physics tags to the AETileEngine, automatically creating static physics blocks where indicated.

Sounds like a fun project for this weekend!

Monday 8 November 2010

Farseer 3.0

Well, progress this weekend was hampered somewhat due to the fact that it took me a lot longer than I thought to get an understanding of how Farseer works. There is a very good tutorial on getting started with Farseer on Sgt. Conker, but unfortunately it was made for Farseer 2.1.3, and the latest version is 3.1.

On the face of it that shouldn't be a challenge, but alas, I'm finding more and more often in the world of game development that things are rarely as simple as they seem.

The biggest issue with applying the 2.1.3 tutorial to 3.0 is the units system. 2.1.3 uses screenspace pixel units, whereas 3.0 (based on Box2D) uses what it calls 'MKS' or meters, kilograms, seconds. This has the unfortunate side effect that a falling block of 50x50 pixels has the physics of a falling building if you just plug the pixel dimensions into the physics engine.

At first, after trying to convert the units manually, I thought this was a deal breaker, and decided to use 2.1.3 instead (when I discovered that it compiles directly under xna 4.0, but that's another story). However I was persuaded by Farseer's creator that 3.0 offered a number of benefits over 2.1.3, I decided to give it another try.

Then I came across the ConvertUnits helper class in one of the samples that ships with Farseer 3.0. This largely solved my unit problems, although I still had some issues with things like magnitudes of forces ir impulses.

So after a couple of hours of playing with the tutorial, including faking a anglular spring (which isn't included in 3.0) with a anglejoint, I finally got the tutorial working. Being the good community member that I am, I will be writing up my adventure later in the week and sending it off to Sgt. Conker as an update to the current tutorial.

Watch this space for a link! Then it'll be back to Alta for an abstraction layer around Farseer 3.0, which among other things, will attempt to convince the developer that they are working in pixel units!

Friday 5 November 2010

Progress report

Things are picking up now at last. The AEAvatar class is tested and working, I've written a skeleton of the AECharacter class which will fill out as I write the physics and AI engines.

Next up is Farseer integration which means adding a nice wrapper over its API, and integrating its setup code into AEGame.

More soon I hope!

Monday 1 November 2010

Avatar!


Nope, not blue aliens with plaits that let them talk to alien animals. Nope, not the cutsy Xbox version of Nintendo's Mii's.

I'm talking about the actual meaning of the word, a proxy visual token to represent another object or person in the virtual world.

This weekend I've been working on my animation engine for Alta. As well as various structs and helper classes, I wrote a class called AEAvatar. This is to be a class which will be a component of the upcoming AECharacter class, and manages the visual representations of characters, including playing and queuing animations.

It's finished but untested as yet. I'll be writing the wider character class this week, and putting together a quick sample that plays animations loaded from the editor.

Next up, physics (which will be a wrapper on Farseer), character art and putting animations to use, some tweaking of various systems,  and then finally gameplay.

I'm a long way behind schedule and Mario is taking longer then I'd hoped, but the engine is still progressing.

Once Mario is done I'll be migrating Alta to xna 4.0, and potting Mario to windows phone 7 to test the engine's performance on the phone. Then on to my first commercial game.

I *will* have my first game out by March. Maybe...

PS my wp7 device arrives today. Going to be awesome, can't wait! :)