Game Development Reference
In-Depth Information
parameter with the name, quotes, and so on. You also always have to make sure
there are matching closing tags. All this combined leads to larger text files.
But one big advantage of XML is that it allows for the enforcement of sticking to a
schema , or a set of requirements on which tags and properties must be used. This
means that it can be easy to validate an XML file and make sure it conforms and
declares all the necessary parameters.
As with the other common file formats, a lot of different parsers support loading in
XML. The most popular one for C/C++ is arguably TinyXML (and its companion
for C++, ticpp). Some languages also have built-in XML parsing; for instance, C#
has a System.Xml namespace devoted to XML files.
JSON
JSON , or JavaScript Object Notation, is a newer file format than INI or XML,
but it's also one that's gained a great deal of popularity in recent years. Although
JSONismorecommonlyusedfortransmitting dataovertheInternet,itcertainlyis
possible to use it as a lightweight data format in a game. Recall that we used JSON
to store the sound metadata in Chapter 6 , “ Sound . ” There are several third-party
libraries that can parse JSON, including libjson ( http://libjson.sourceforge.net ) for
C++ and JSON.NET for C# and other .NET languages.
Depending on the type of data being stored, a JSON file may be both smaller and
more efficient to parse than a comparable XML file. But this isn't always the case.
For example, if we were to take the sword data from The Witcher 2 and instead
store it in a JSON file, it actually ends up being larger than the XML version:
Click here to view code image
"ability": {
"name": "Forgotten Sword of Vrans _Stats",
"damage_min": {
"mult": false, "always_random": false, "min":
50, "max": 50
},
"damage_max": {
"mult": false, "always_random": false, "min":
55, "max": 55
},
"endurance": {
"mult": false, "always_random": false, "min":
Search WWH ::




Custom Search