XML or textfiles

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • XML or textfiles

      Hello!

      I was wondering about the idea of using txt files with my own format instead of XML for storing my actors data and all that.

      I have read that XML is better for databases and stuff, but aside from that my main concern is if I could still use them in other operating systems than windows without problem.

      Or is just not a good idea to use txt files instead of XML at all?
      bit fever
    • RE: XML or textfiles

      As always, the answer depends on what kind of data your are storing, how much data you are storing, and how you want to access it.

      Formatted text files, such as CSV, are good to store multiple rows of data that all share the same general format. A good example of this is a LOG file, that records game events, messages, and errors.

      Text files are easy to edit, can store their data fairly efficiently, but aren't easily accessed randomly - they are better read from beginning to end.

      An XML file has the advantage of being able to store more structured data, such as an entire hierarchical database with multiple tables. Since XML files can have a schema attached, you can even have XML parsers check your data. There are also XML editors too, off the shelf, that make it easy to edit your data.

      The downside, they tend to store data a lot less efficiently than unstructured text files because of all the extra tags, formatting, and attribute names. They also can't be accessed in a random order.

      Both text and XML files are cross platform beasts and can be read by many operating systems without having to change the file. Except maybe line endings, which are different on UNIX, but most text editors handle that without a problem.

      Something that is more efficient than XML is JSON, in that it has simpler tags and an assumed data structure.

      If you are looking for very efficient storage and random access, you probably want to go with a platform dependent binary format.

      What many game studios do is store actor format in human readable form, like XML, for development. Then, these files are "cooked" into binary format for the game to read.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: XML or textfiles

      Hamsters with flamethowers! I'm SO in.....
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • RE: XML or textfiles

      Oh by the way - here's another interesting possibility I just found out about, YAML.

      It turns out that Unity Pro stores its scene files in this format.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • I handle my data exactly the way Mike described, I have

      -a message logger that stores messages in a text file
      -an XML File to load in Application Configuration Settings
      -and pretty well XML for everything else
      -except Lua for scripting (although some small LuaScripts are written directly in XML)
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • In my own personal game engine, I'm trying an experiment. Instead of using XML, all of my text-based data is in Lua. When I initialize an actor or other object that has tuning data associated with it, I just pass in the appropriate Lua table as a parameter and grab the values from it. So far, it's worked out really well. It's extremely powerful to have a scripting language acting as your data format. Common problems you have with XML, like data duplication, completely go away in Lua. Another common problem is running a calculation. For example, say I find that the perfect tuning for a utility curve is e * 0.68, where e is Euler's number. In XML, I'd have to actually type out 1.848431643 and maybe have a comment talking about where it came from. In Lua, I can just set it directly using the formula, making it a lot easier to tune.

      I'm sure there are down sides too. It might be slower or potentially take up more memory, though both of those things can be optimized quite a bit. I can load my data as binary Lua, for example. I'm also careful to assign nil to any Lua structures that exist purely for loading, which causes the garbage collector to clear them out.

      -Rez
    • That is very true, I may also experiment with this some time, so if I wanted to say, change my settings file to lua, I could just expose the appropriate functions to lua for changing the Application's display parameters etc and instead of having to read in and parse the xml, it would instead directly make the call through Lua? Or is that not what you are talking about.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz