To XML or not to XML, that is the question...
BlitzMax Forums/BlitzMax Programming/To XML or not to XML, that is the question...
| ||
. |
| ||
No, it's not practical. Xml is good for anything that would benefit from a written form, such as materials, entity layouts for maps, etc. The actual level data itself? No, it'd just be bloated. |
| ||
maybe a combo:<?xml version="1.0" encoding="utf-8"?> <BrEgOrS_game> <level name = "First Level"> <tilemap> </file> level_one_file.TIL </tilemap> </level> </BrEgOrS_game> |
| ||
That's not valid Xml, bradford O_o |
| ||
. |
| ||
you could even embed the binary data of "entrance.dat" within the xml file using BASE64 encoding. would look something like this: ... <levels> <level name="Entrance" music="snd/mL1.ogg"> <data encoding="base64"> SGV5IHlvdVwncmUgYWJsZSB0byBk ZWNvZGUgYmFzZTY0ISB1bmJlbGlld mFibGUhIDspDQpIZXkgeW91XCdyZS BhYmxlIHRvIGRlY29kZSBiYXNlNjQhI HVuYmVsaWV2YWJsZSEgOykNCkhle SB5b3VcJ3JlIGFibGUgdG8gZGVjb2Rl IGJhc2U2NCEgdW5iZWxpZXZhYmxlI SA7KQ0KSGV5IHlvdVwncmUgYWJsZ SB0byBkZWNvZGUgYmFzZTY0ISB1b mJlbGlldmFibGUhIDspDQpIZXkgeW 91XCdyZSBhYmxlIHRvIGRlY29kZSBi YXNlNjQhIHVuYmVsaWV2YWJsZSEg OykNCkhleSB5b3VcJ3JlIGFibGUgdG 8gZGVjb2RlIGJhc2U2NCEgdW5iZWx pZXZhYmxlISA7KQ0KSGV5IHlvdVwn cmUgYWJsZSB0byBkZWNvZGUgYmF zZTY0ISB1bmJlbGlldmFibGUhIDspD QpIZXkgeW91XCdyZSBhYmxlIHRvIG RlY29kZSBiYXNlNjQhIHVuYmVsaWV 2YWJsZSEgOyk= </data> </level> </levels> ... |
| ||
That's not valid Xml, bradford O_o it was pseudo-XML (new word, I just made it up:) ) great idea OJAY! <?xml version='1.0' encoding='UTF-8'?> <game> <level difficulty="2" levelnumber="1" name="Welcome to funsville" tilefile="level1.tiles"> <!-- here are some things in my level --> <ball file="ball.png" xpos="0" ypos="100"></ball> <cooler file="cooler.png" xpos="100" ypos="100"> <lunchbox file="lunchbox.png" xpos="100" ypos="100"> <fooditem file="apple.png" name="Red Delicious Apple"></fooditem> </lunchbox> </cooler> </level> <level difficulty="5" levelnumber="2" name="Had enough yet?" tilefile="level2.tiles"> <!-- here are some things in my level --> <weapon file="trebuchet.png" strength="100" weightLBS="350" xpos="0" ypos="100"></weapon> <weapon file="crossbow.png" strength="10" weightLBS="25" xpos="0" ypos="100"></weapon> </level> </game> I think the point is that XML for describing a Level could be very useful. |
| ||
XML is pointless for game formats where you will not be modding. |
| ||
yeah, but the point is: using xml *makes* a game modable (to some extend) :) |
| ||
3 good reasons to do this: 1. XML is readable and easily modified 2. XML can be used for level files, configuration files, save game data, etc. 3. This would be a fun way to learn XML for other, more serious applications |
| ||
. |
| ||
Don't know how many lines a ~500k file would run at base64, but it definately sounds feasible for smaller projects. its "feasible" for large projects too. i currently have 4 fullprize games installed, which use xml entirely for all content! however they use a compression algorythm to keep the actual files small. zlib (even with lowest compression) does a very good job here... |
| ||
CrystalSpace 3D does this, it uses xml for everything; maps, materials, sprites, libraries, etc... I think is a good idea if you don't mind the final user messing with it. |
| ||
. |
| ||
you can do compression to shrink the size and encryption to protect the integrity of the data. |
| ||
This is something I did a while back, not guaranteed to work well at all though. What you could do is use Xml and provide a 'compiler' for it, reducing an otherwise large file to a chunk-based format that would be signifigantly smaller. You could compile them at runtime and include an MD5 in the compiled version to check against the existing Xml file, and if the MD5 doesn't match then you rebuild the compiled version. The advantage of this is loading speed and size. The compiled version could be more tailored to loading straight to memory because you could simple do something like Stream.ReadBytes( Varptr obj.FirstField, dataSize ) instead of having to enumerate all of the elements and attributes in an Xml file. Well, just my $.02. |