Saturday 9 January 2010

Tweaking variables using XML

A few months ago, I was tasked to tweak a car to behave like an actual vehicle (using XNA). Nothing close to a simulator, but a task like this can take up weeks of your time if you don't have proper tools. I did not have proper tools...

With a fresh project coming up (got till about April to work on the engine, before I can put it to use for another school project) I can take some time to develop tools like the one mentioned before. I've no current plans to develop these tools for a wide audience, this makes it somewhat easier to code them. I do of course release snippets and full source when applicable. Most of my current code works, but is not qualified to be released without a proper cleanup. Releasing something to a wide audience of programmers without fully debugging or tweaking your code is not in anyone's best interest.

Like a lot of other previous posts, this one will be cut into two parts. The first part I will talk about a possible method that you can implement into your project/engine when trying to save time tweaking. The next part will show an example (with snippets etc.) using this method.

If you've ever made a game before, you will know how much time fine-tuning or tweaking any object in your game can consume of your total development cycle. To help reducing the amount of time spend building and rebuilding your game with only slight changes in your character's run speed, you need a tool. I use XML to help save time. It's still a work in progress, but tests have shown good results so far. I'll explain the concept below...

Every class that uses constant values that should not change during runtime (i.e. default run speed or friction in a spring) can be tweaked using this XML method. The tweakable value is not a 'const' as this would not allow us to change its value in runtime. Instead we will use a 'public static', which holds the value that is used for every instance of the class. to Get/Set this value with XML (explained in more detail in the second part) we will need a 'private (non-static)' value.

public static float FrictionDef;
private float frictionDef
{
get { return FrictionDef; }
set { FrictionDef = value; }
}


In its current implementation you will have to manually open the XML file created for the class (one XML file for every class that uses tweakables) in a text-editor and change the value to anything you'd like in runtime, saving the file and reloading it using a simple key command in-game will load your new values to the 'public static' variables. Any instance will now use the new values and you get direct feedback on any changes made.

I will go more in-depth of the coding required to achieve this in part two. And provide a video with the implementation in effect (if time permits)

No comments:

Post a Comment