Incorporating XML into Games

Started by
10 comments, last by Paradoxish 18 years, 7 months ago
Hello guys, you might remember me from a while ago I said I was gonna get into game programming and then decided I'd instead learn win32 api and socket programming first, and now I'm back, knowledgeable of both (not mastered but at least I know them so I could elaborate on them if needed). I'm getting into programming in OpenGL with a friend, and we will hopefully start making simple games and move on. Anyways, I've seen tons of games that use XML, mostly the smart people use it (JavaCoolDude makes very good use of it). But I'd like to know what I should learn it for. I know it's good to use for when you want to save information in them (what maps have been played etc.), but I've seen other uses for it, and would like to know what I could use it for so that I could start learning it, I think it's like HTML except you could make your own tags and what not. Also, what XML parser do you guys recommend? I downloaded TinyXML cuase someone referenced it (I think JavaCoolDude) but which do you guys think is easier? or easy and powerful? Thanks guys, I look forward to contributing alot here.
Advertisement
XML is a good intermediate format for exchanging data, for example in my current project I'm using XML as a way of storing level information because it's quick and simple to edit to tweak settings etc, this XML data will then be converted into a binary file for efficiency and security against unsolicited editing for use within the final release.

TinyXML seems to be the most popular parser amongst people here, I use it myself and quite like it. There are other parsers out there so I'd advise you to spend 10 minutes or so looking at them to find out which one you like the best. One person's preference isn't likely to be your favourite.
Thanks, that's a creative reason to use it for, I'll look into it. I'd still like to hear other opinions if it's possible, thanks again.
I use XML to configure my particle system. Here is a sample:
<?xml version="1.0" ?><ParticleSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Configuration.xsd">	<Volume name="vol0" type="point" />	<Volume name="vol1" type="line">		<Length>10.0</Length>	</Volume>	<Volume name="vol2" type="rectangle">		<Width> 50.0</Width>		<Height>50.0</Height>	</Volume>	<Volume name="vol3" type="circle">		<Radius>10.0</Radius>	</Volume>	<Volume name="vol4" type="sphere">		<Radius>10.0</Radius>	</Volume>	<Volume name="vol5" type="box">		<Width> 10.0</Width>		<Height>10.0</Height>		<Depth> 10.0</Depth>	</Volume>	<Volume name="vol6" type="cylinder">		<Radius>10.0</Radius>		<Height>10.0</Height>	</Volume>	<Volume name="vol7" type="cone">		<Radius>10.0</Radius>		<Height>10.0</Height>	</Volume>	<BouncePlaneList name="bounceplanes">		<BouncePlane>			<Plane>				<X>0.0</X>				<Y>0.0</Y>				<Z>1.0</Z>				<D>0.0</D>			</Plane>			<Dampening>.5</Dampening>		</BouncePlane>	</BouncePlaneList>	<ClipPlaneList name="clipplanes">		<ClipPlane>			<X>0.0</X>			<Y>0.0</Y>			<Z>1.0</Z>			<D>0.0</D>		</ClipPlane>	</ClipPlaneList>	<Appearance name="appearance">		<RadiusChange>0.</RadiusChange>		<RadialVelocity>0.</RadialVelocity>		<ColorChange>			<R> 0.00</R>			<G> 0.00</G>			<B> 0.00</B>			<A>-0.05</A>		</ColorChange>	</Appearance>	<Appearance name="texturedappearance">		<RadiusChange>0.</RadiusChange>		<RadialVelocity>0.</RadialVelocity>		<ColorChange>			<R>-0.20</R>			<G>-0.40</G>			<B>-0.60</B>			<A>-0.20</A>		</ColorChange>		<Texture>res/ember.tga</Texture>	</Appearance>	<Appearance name="streakappearance">		<Size>2.</Size>		<ColorChange>			<R> 0.00</R>			<G> 0.00</G>			<B> 0.00</B>			<A>-0.05</A>		</ColorChange>	</Appearance>	<Environment name="environment">		<AirFriction>0.4</AirFriction>		<!-- <Bounce>bounceplanes</Bounce> -->		<!-- <Clip>clipplanes</Clip> -->		<Gravity>			<X> 0.0</X>			<Y> 0.0</Y>			<Z>-9.8</Z>		</Gravity>		<WindVelocity>			<X>0.0</X>			<Y>0.0</Y>			<Z>0.0</Z>		</WindVelocity>		<Gustiness>			<X>40.0</X>			<Y>40.0</Y>			<Z>10.0</Z>		</Gustiness>	</Environment><!--	<Emitter name="e0" type="point">		<Volume>vol0</Volume>		<Environment>environment</Environment>		<Appearance>appearance</Appearance>		<Count>20000</Count>		<Lifetime>10.0</Lifetime>		<Spread>0.4</Spread>		<MinSpeed>30.0</MinSpeed>		<MaxSpeed>100.0</MaxSpeed>		<Sorted>1</Sorted>	</Emitter>	<Emitter name="e1" type="streak">		<Volume>vol0</Volume>		<Environment>environment</Environment>		<Appearance>streakappearance</Appearance>		<Count>10000</Count>		<Lifetime>20.0</Lifetime>		<Spread>0.4</Spread>		<MinSpeed>30.0</MinSpeed>		<MaxSpeed>100.0</MaxSpeed>	</Emitter>-->	<Emitter name="e2" type="textured">		<Volume>vol3</Volume>		<Environment>environment</Environment>		<Appearance>texturedappearance</Appearance>		<Count>20000</Count>		<Lifetime>5.0</Lifetime>		<Spread>0.4</Spread>		<MinSpeed>30.0</MinSpeed>		<MaxSpeed>50.0</MaxSpeed>		<Sorted>1</Sorted>	</Emitter><!--	<Emitter name="e3" type="sphere">		<Volume>vol2</Volume>		<Environment>environment</Environment>		<Appearance>appearance</Appearance>		<Count>10000</Count>		<Lifetime>20.0</Lifetime>		<Spread>0.4</Spread>		<MinSpeed>30.0</MinSpeed>		<MaxSpeed>100.0</MaxSpeed>	</Emitter>--></ParticleSystem>
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Nice, Very Creative. Do any of you have any special tutorials you really like that you could please tell me about? Anything you really like having to do with XML, I'm not really looking to spend on books since I still have a couple books I haven't finished reading, but any tutorials would be nice.
Quote:Original post by blankdev
but any tutorials would be nice.


There's a good article here at gamedev about using XML and parsing it with tinyxml here. There's also some good links at the end of the article.
Hey there,
Here's a link for you to take a look at. I use this for work and am using in it in my engine.

http://xml.apache.org/

TinyXML is very simple and nice. Took me about 5 mins to get integrated and working. However, my biggest gripe was that it didn't preserve whitespace in my document. So for me, using it as a configuration file is out. Unless someone knows how to tell it to preserve whitespace when writing out xml files using TinyXML. Anywho...just to give you another idea of what's out there.
Quote:Original post by ArmitageIII87
TinyXML is very simple and nice. Took me about 5 mins to get integrated and working. However, my biggest gripe was that it didn't preserve whitespace in my document. So for me, using it as a configuration file is out. Unless someone knows how to tell it to preserve whitespace when writing out xml files using TinyXML. Anywho...just to give you another idea of what's out there.


If I am reading correctly, then maybe This would be of some help.
"void TiXmlBase::SetCondenseWhiteSpace(bool condense)"

I as well advocate TinyXML; granted it took a few days and some external aid to figure out how it was reading - it is pretty powerful.
Yep, I recommend XML with TinyXML. I'd use XML for anything where storing the data in such a format doesn't hugely bloat the files. A level in XML format is likely to be huge, but when you want readable files that can be editted easily it's great!
One of the best features of xml is that it is very parse-able. Because it is parse-able it can be transformed very easily into different formats. Transformation is done by using xslt.

Go to the excellent w3schools to learn xml, xsd, xpath and xsl.

Cheers

This topic is closed to new replies.

Advertisement