Sign in to follow this  
Boder

What do you think of this format?

Recommended Posts

I've been thinking up a good file format for storing data. It's kind of like a text/XML combo. Tell me what you think.
# This is a comment

# This is some info about the file
! Preference File Version 1.0.0

# Now some tags
window @size=800,600 #bpp=32 $title='Test Framework' windowed=false
audio
 sound on=false
 music on=true volume=0.8



Share this post


Link to post
Share on other sites
I think that looks messy and hard to write:

I made up this style for mine, which i think you'll agree is clearer.


shader_list
{
shader
{
_name : shader1;
_path : "../Shaders/shader.fx";
_params : float4x4(M_WVP, "matWorldViewProj" );
}
}


Dave

Share this post


Link to post
Share on other sites
I have a question fo you both: why do you invent a text format for your specific use? There is already a lof of existing one (you cited XML, I can cite INI files (rather easy to use under Windows, a bit more tricky under linux but nothing too difficult).

(I am very tired, so please don't blame me if I'm not polite enough: it is not intented at all)

Regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
I have a question fo you both: why do you invent a text format for your specific use? There is already a lof of existing one (you cited XML, I can cite INI files (rather easy to use under Windows, a bit more tricky under linux but nothing too difficult).

(I am very tired, so please don't blame me if I'm not polite enough: it is not intented at all)

Regards,


Depending on needs, I guess.

INI is rather limiting in the face it can only have a section and a key. What about sub sections? I still use INI to this day because it's simple, but sometimes people want something more and XML can be overkill.

I also find it fun to do little things here and there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
I have a question fo you both: why do you invent a text format for your specific use?


For the pure joy of opening up a file and seeing your own format lol...maybe it's because I'm a newbie in game programming, but its just nice I guess. On another note, I don't think you actually need to use formats such as xml for small projects where you're the only one reading the data and have no intent of expanding it in the future.

Share this post


Link to post
Share on other sites
I wrote something similer a year ago. It looked something like this


# A Keyword declaration. Keywords are basically datatypes
$Character: Name, Race, Class;
$Monster: Name, Species, Palette;

# Actual rows
Character: Bob, Elf, Ranger;
Character: Bill, Dorf, Paladin;
Monster: Koopa, Turtle, Green;
Monster: Goomba, Mushroom, Brown;
Character: Luigi, Italian, Plumber;



Getting data out of it is basically Config.GetString("Character", 2, "Name") would return Luigi.

Or, if needed, you can declare your keywords in one file, and in a seperate file just put rows of data without a keyword in the start of the row, like


$Monster: Name, Species, Palette
--------AND IN A DIFF FILE-----------------

Koopa, Turtle, Green;
Goomba, Mushroom, Brown;
Beetle, Beetle, Gray;
Birdo, Freak, Pink;




That feature existed mainly to read existing files that were made without consideration for my required keywords. Its one downside is a keywordless file has to only contain one type of data rows. If it mixes different types of data rows together it won't work.

It has another feature that makes it really flexible for existing files, is the marking characters between fields, and keywords, and end of lines, are all configurable. In the above examples it uses ':', ',', and ';'. But you can just as easily set it to use '_', '#', and '\n', and it will look for those characters. You can also set any to null, and it will look for any whitespace instead. I havn't tried it, but I think setting the markers all to null, and using a keyword like

$MountObject MountPoint DevPoint FileSystem Flags UID GID

would read a /etc/fstab as a keywordless file too. That was sort of the goal. To make something that would read as many existing files as possible. (It reads INI's too somehow...)

XML is definatly frequently overkill, and you have to just find another library to help you use the XML anyway. And you need to bother with dtd's and whatnot too. And INI has no crossplatform support.

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
I have a question fo you both: why do you invent a text format for your specific use? There is already a lof of existing one (you cited XML, I can cite INI files (rather easy to use under Windows, a bit more tricky under linux but nothing too difficult).

(I am very tired, so please don't blame me if I'm not polite enough: it is not intented at all)

Regards,


I have just ported it all to XML actually :D.

Share this post


Link to post
Share on other sites
There are a lot of good ideas around. Tinyn I like the idea you had about datatypes and separating characters.

XML is good and but it can be overkill. INI can be underkill. XML also is not nearly as easy to read or parse as INI.

But I have been wondering, is there a way to use PhysFS with TinyXML?

Share this post


Link to post
Share on other sites
XML look overkill, but in fact it is not, for at least two reasons:

  • it is rather simple
  • you dont have to write the parser :) (tinyxml is simple enough to be included in your projects)

Moreover, you designed your file format to look like XML - I believe that writing a parser to redo something that already exists is more overkill than using the existing XML parser :)

Quote:
Original post by Boder
But I have been wondering, is there a way to use PhysFS with TinyXML?


What do you mean? TinyXML can read the file from the hard drive or from memory - using a asciiz buffer.

Regards,

Share this post


Link to post
Share on other sites
You make good points. I will probably end up using XML. I found something called xmllint, that made me laugh. Are DTD's and XSD's the overkill part for games? TinyXML is lightweight but Xerces is not so much. There are two types of XML parsers and I never know which one to use (SAX or DOM). See I start talking about XML and before I know it I'm over my head with TLA's! [grin]

XML does have a lot of markup, and is not that easy to write. Here is the first file in XML format.

<!-- This is a comment -->

<!-- This is some info about the file -->
<preference_file version="1.0.0" />

<!-- Now some tags -->
<window width="800" height="600" bpp="32" title="Test Framework" windowed="0" />
<audio>
<sound on="0" />
<music on="1" volume="0.8" />
</audio>


It's the little things like pushing shift to make <>, enclosing every attribute in quotes, and closing every tag.

Share this post


Link to post
Share on other sites
Well, if you dislike the named end tags and the requirement for all property data to be surrounded in double quotes, you could use Lisp S-expressions.

Share this post


Link to post
Share on other sites
Hehe, I remember the Lisp vs. XML battle. WOW!

I've typed a lot of XHTML over the years, so maybe I've just seen too much of it.

Share this post


Link to post
Share on other sites
To me it is rather intuitive, although if you're going to store a lot of data, consider these ways:
  1. Use XML and build a 'XML Editor' - Fast and easy.
  2. Use scripting languages (Lua is a good candidate), you'll probably need it later anyway.
  3. Use a database - a bit overkill in this moment I think.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this