XML in Games?

Started by
7 comments, last by jpetrie 16 years, 4 months ago
As much as you could possibly known, how commonly used is XML in 3D games/applications? When used, how are the XML scripts loaded? Do the coders generally develop an XML loader?
Advertisement
In my game engine, I use XML for map files, settings, and some animation data. I do NOT use XML for scripts - I use a stripped-down form of C++. (XML is a great way of describing hierarchal DATA, but it's not a very good way to describe a procedure.)

I wrote my own XML loader within the framework of my engine.
hackerkey://v4sw7+8CHS$hw6+8ln6pr8O$ck4ma4+9u5Lw7VX$m0l5Ri8ONotepad++/e3+8t3b8AORTen7+9a17s0r4g8OP
I've seen a few modern games that use XML but most game devs just come up with their own formats. I know for a fact that S.T.A.L.K.E.R. uses quite a lot of XML and even has a DLL dedicated to parsing it. That's more an exception than the rule though (not them writing their own parser but them using XML).

There's also a (fairly) good reason for not using XML in games. XML is expensive to parse and will increase load times. It's fine to use for small stuff like config files, but people tend to go nuts with it and put stuff like geometry data in it which is bad.

EDIT: Just so you don't get me wrong: I think XML is great, it's just sometimes better to go for a binary format. Also, using XML for scripting is fine... I just think the notation is overly verbose, but that's just me.
Quote:Original post by Harry Hunt
I've seen a few modern games that use XML but most game devs just come up with their own formats. I know for a fact that S.T.A.L.K.E.R. uses quite a lot of XML and even has a DLL dedicated to parsing it. That's more an exception than the rule though (not them writing their own parser but them using XML).

The Stalker team did NOT write their own parser! They simply built TinyXML as DLL.

-----PARPG - open source isometric 2d old school RPG still looking for interested contributors
We use XML for commercial games, so does a nearby studio. XML is good for 'near human readable and editable', small size configuration files. When paired with a fast, light weight XML parser, can be usable for PC and Console games at load time. For bigger data structures, the data really needs to be converted into a more platform ready format for fast loading. XML has nothing to do with scripting unless you consider the concept of data driven configuration the same as script.

The summary of my rant is that XML is used. There is a time and place for it. It is often a better choice than yet another custom TEXT data file. The down side is embedding complex text data, particularly by hand, due to the XML syntax. Also the relatively slower speed compared to binary or memory mapped binary. Hand editing XML is of limited value due to limited commenting syntax etc. We also use a block data format that can be serialized as XML or binary. Nice to debug or hand edit for testing in XML.

By the way, we use MXML. Another reasonable choice is TinyXML. There are certainly lots more around. I believe Microsoft recently produced a small embedable parser for this kind of use.
For the exact reasons mentioned by GregDude, XML makes an excellent intermediate format for games. It's great to be able to hack up XML files during game development and then at the end of development you could have a 'compiler' of sorts that converts XML files to your game's native binary format.

Not to mention using it as an intermediate format could aid in cross-platform development, and it makes debugging the initial implementation a little easier too, simply because you can visualize your data easier.

If you're planning on using XML you might want to weigh the difference between DOM and SAX parsers, as it will have an effect on the final efficiency of your XML load routines. I'm not sure which methods TinyXML or MXML use, but it would be worth checking out.

Hope this helps,
Matt Rudder
We use XML for development files just like the above two post mention.

Its a good format for editing by both humans and programs, its standardized, and cross platform. Probably the main benefit is that you can easily and rapidly extend or modify a files structure, making it nice for development.

Basically our game editor reads and writes game assets in XML format, and then we build platform specific binary assets when deploying to dev kits.

We use TinyXML in case you're curious.




It's kind of strange when XML is used, like in RenderMonkey.
It would take 1 minute to load when I was testig out the beta version and on my slow cpu. These days, with +2GHz cpus it is less of a problem but...

I use TinyXML for my config file so performance is not an issue.
I would never use it for game assets.
The same could be said for other text file formats like .obj and .ase
Too slow to load.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I use XML all over. But only in content processing. By the time my code actually executes, I've converted everything(*) to a binary format.

I use TinyXML for C++, and the .NET XML / XPath stuff for C#.

(*) Actually not true, my GUI layouts are still in XML form, I just haven't fixed that yet.

This topic is closed to new replies.

Advertisement