Little Racers again in Peer Review

The week has finally passed, and we’ve been able to start a new peer review of the game. In a week or so, the game should be available for download.

WaaghMan March 12th, 2009 News Comments Off on Little Racers again in Peer Review

Problems with System.Random

Yesterday I ran a profiling tool (CLR Profiler) to see how Little Racers does with heap memory allocation, and found something strange: The log showed that class System.Random allocated around 88Mbytes of RAM during the whole execution.

The reason of this is the way the particle system works: Each particle stores only a seed to generate its random values, and a new Random is generated with that seed each time it needs to be updated (that is, on every frame). So, if we’re showing 50 particles on a frame, we’re calling new Random(seed) 50 times.

With System.Random, there was no possible workaround since it doesn’t have a method available to set the seed without recreating everything. Also, it seems to do some hard work on creation, maybe allocating the N next random numbers, I don’t know.

Anyway, I found a nice replacement called FastRandom: This class has the same interface that System.Random, so they can be easily interchanged. Also, it has a method to set the seed without having to recreate the class.

Anyway, I found a bug in the provided code, related with the methods Next(int) and Next(int,int) , it seems to store a double with the minimum value of an int and then multiply it by the desired range. It didn’t work for me, so I just replaced it with a modulus. Maybe it’s a little slower, but it works perfectly.

Tags:

WaaghMan March 11th, 2009 News Comments Off on Problems with System.Random

Little Racers submission failed

Due to a crash in a very special case (signing out on level load), the game has been rejected for the last submission.

The issue has already been fixed, and some improvements have been done (Better player select section and tips during game load).

Since XNA won’t allow another submission until the next Wednesday, it’s been put on playtest until then.

WaaghMan March 7th, 2009 News Comments Off on Little Racers submission failed

Little Racers into Peer Review

Finally the game is ready for review. We’ll keep you updated with the process status.

WaaghMan March 3rd, 2009 News Comments Off on Little Racers into Peer Review

Plain XML content in XNA Content Pipeline

During the first stages of Little Racers development, I found the need of parsing XML data during the game load. The XNA Content Pipeline system includes XML Parsing, but it uses it in a very particular way. I won’t go much further in the way XNA parses XML because, to be sincere, I’ve not tried it enough to test wether it’s good or not.
My first impression was that it was too strict (probably due to optimization and type safe issues), moreover during parse I would need access to some data structures that only were available at runtime, so I preferred to store plain XML and parse it during game load.
This can be done by extending the content pipeline and adding a new type. To do this we’ll need to add two new projects to our solution.

XmlSource project

The first project we’ll create is the one which has the class that stores our xml plain text. I’ve called it XmlSource.It will have two classes in total.

XmlSource

This class is a very simple one. It simply has a string with the xml plain text:
[sourcecode language=’csharp’]
public class XmlSource
{
public XmlSource(string xmlCode)
{
this.xmlCode = xmlCode;
}

private string xmlCode;
public string XmlCode { get { return xmlCode; } }
}
[/sourcecode]

XmlSourceReader

This class extends ContentTypeReader and simply creates an XmlSource instance from its binary representation. In our case, the binary representation wil be a simple string, so the read is straightforward.

[sourcecode language=’csharp’]
public class XmlSourceReader : ContentTypeReader
{
///

/// Loads an imported shader.
///

protected override XmlSource Read(ContentReader input, XmlSource existingInstance)
{
string xmlData = input.ReadString();

return new XmlSource(xmlData);
}
}
[/sourcecode]

With this, our first project is finished. This project is platform-independant (The Xbox needs to read the binary data) and will have to be referenced from every project that uses the XmlSource class, including the second project we’re making:

XmlSourceImporter

The second project(I called it XmlDocumentImporter) is a project of type “Content Pipeline Extension Library”. This project is referenced from the Content projects, and converts the source text file to binary data that will be saved in the .xnb files.

This project has 2 files:

XmlSourceImporter.cs

This file converts the XML source file into an XmlSource instance, that will be further converted into binary data
[sourcecode language=’csharp’]
[ContentImporter(“.xml”, DisplayName = “Xml Source Importer”)]
class XmlSourceImporter : ContentImporter
{
public override XmlSource Import(string filename, ContentImporterContext context)
{
string sourceCode = System.IO.File.ReadAllText(filename);
return new XmlSource(sourceCode);
}
}
[/sourcecode]

XmlSourceWriter.cs

This file converts an XmlSource into binary data, as opposed to XmlSourceReader
[sourcecode language=’csharp’]
[ContentTypeWriter]
class XmlSourceWriter : ContentTypeWriter
{
protected override void Write(ContentWriter output, XmlSource value)
{
/*StringWriter sw=new StringWriter();
value.Save(sw);
string content = sw.ToString();*/
output.Write(value.XmlCode);
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return typeof(XmlDocument).AssemblyQualifiedName;
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(XmlDocumentReader).AssemblyQualifiedName;
}
}
[/sourcecode]

Sample of use

Once both projects set up (remember to add reference to XmlSourceImporter from the Content project), we can add .xml files to the content project. Under “Content importer”, we’ll need to select “Xml Source importer”, instead of the default XNA one.

Once done this, the program sould compile ok. Loading XML from the program now is very easy:
[sourcecode language=’csharp’]
XmlSource xs = Content.Load(AssetName);
XmlDocument xd = new XmlDocument();
xd.LoadXml(xs.XmlCode);
[/sourcecode]

I know this can be a little confusing, i’ll upload some binaries if someone asks for them.

PS: Here they are: Plain Xml Content Importer

Tags: , ,

WaaghMan March 2nd, 2009 News 3 Comments

Little Racers almost ready for peer review

After about 3 months of development, the final version of Little Racers is almost ready to get into peer review. Supposing it passes the review without problems, the game will be available in Xbox LIVE marketplace very soon.

We’d like to thank the betatesters that found so many issues and gave suggestions, specially the folks at XNA Creators Club . Hopefuly you had as much fun testing the game as we had making it.

WaaghMan March 2nd, 2009 News Comments Off on Little Racers almost ready for peer review

Hello world

Blog created!

MilkstoneStudios February 28th, 2009 News 2 Comments