Skip to main content
gamedev.net
🔒 Locked

Saving/Loading Data

Started by Diceydawg 3 replies 1k views
Original Post
Diceydawg
Diceydawg
Is XML the de-facto way to store/load data these days? I've been looking online but cannot find any resources about XML and directx although XNA supports SML. Sorry if the question is ambiguous
TheTroll
TheTroll
XML is one way to do it.

XML is preferred if you want the data to be human readable.

I prefer binary serialization, that way you just output your classes to the file stream and save. To read you do the reverse. The nice part it that you can save your game in the current state without really much work.

theTroll
swiftcoder
swiftcoder
For production you often want a more efficient binary format, but text-based formats are very useful during development, for ease of editing and visualisation.

Personally I am not fond of XML, I find it overly verbose and hard to read/edit. You should have a look at YAML before deciding - it is a more modern (and very readable) standard for textual data.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Clapfoot
Clapfoot
One approach that has worked well for me is to store all of your save data into a class or struct (that can contain nested classes/struct) and then serialize them to disk.

If your classes/structs contain many fields you can write generic serialize functions to handle each field. If you want to have a text version of your saved data (as swiftcoder suggested) you can have a separate path in your serialize functions that spit out text instead of binary data.
ddn3
ddn3
XML is used for generic data which isn't time sensitive to load, usually. Most games use a custom binary format for data which needs to be loaded/save quickly.

There is tinyXML which i use for simple configuration data stored in XML.

http://www.grinninglizard.com/tinyxml/

-ddn

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.