Horde3D

Next-Generation Graphics Engine
It is currently 15.05.2024, 12:42

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: JSON instead of XML
PostPosted: 21.04.2009, 21:31 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
Would it be an idea to move to JSON for the data files? It's more lightweight, human readable, widely supported and easy to convert from XML. The shaders have already moved away from XML. An example:

Code:
<Material>
 <Shader source="model.shader" />
 <ShaderFlag name="_F03_ParallaxMapping" />
 <Sampler name="albedoMap" map="ball.tga" />
 <Sampler name="normalMap" map="ball_normal.tga" />
</Material>

Code:
    material:{
        shader: {source:"model.shader"},
        shaderflag: {name:"_F03_ParallaxMapping"},
        sampler:[
            {name:"albedoMap", map:"ball.tga"},
            {name:"normalMap", map:"ball_normal.tga"}
        ]
    }

or even more tight:
Code:
    material:{
        shader: "model.shader",
        shaderflag: ["_F03_ParallaxMapping"],
        sampler:[
            {name:"albedoMap", map:"ball.tga"},
            {name:"normalMap", map:"ball_normal.tga"}
        ]
    }


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 22.04.2009, 23:14 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
JSON looks interesting but I see two problems: it does not seem to support comments and it would be even more difficult to reuse it as simple scripting language (required for pipelines). Although Horde has a lot of XML, I am not a huge fan of XML per se. It is just used because it is very practical and everyone knows it. But I would be open to replace it by another (also custom) syntax if that would bring a real advantage.


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 23.04.2009, 03:03 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
AFAIK json comments are just /* comment */

XML isn't very appropriate for a scripting language either, because strictly speaking, the order that elements are stored in a file is supposed to be irrelevant (XML stores sets of data, not sequences of data).

What about in the long run if all of Horde's XML functionality was moved into a "file to class translation" module (responsible for converting data from disc into internal classes/objects). Then perhaps the file formats (XML/JSON/binary) could be changed with Horde extensions?


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 23.04.2009, 03:46 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
This is a little offtopic : Is there any way to compile XML files to hide the Shaders, Scenes and ... from intruders?


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 23.04.2009, 07:25 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Siavash wrote:
This is a little offtopic : Is there any way to compile XML files to hide the Shaders, Scenes and ... from intruders?
Yes, Horde's resource loading code doesn't actually implement file-loading (it only loads resources from memory, not from files).

Horde3D utils is the part that actually loads files - so you need to replace this utility file loading code to use a "virtual file system" (which could be encrypted to stop people from looking at the files).
If you're interested in this, I would suggest using PhysFS as a starting point (it implements a .ZIP virtual file system).


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 23.04.2009, 09:38 
Offline

Joined: 10.04.2008, 09:13
Posts: 86
Optimally I would like s-expressions, but that might scare people...


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 23.04.2009, 21:00 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
If you are going to move away from XML, I would suggest skipping the intermediate stage of JSON, and moving all the way to YAML.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 24.04.2009, 11:25 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
DarkAngel wrote:
AFAIK json comments are just /* comment */

I also though that at first but it does not seem to be in the spec, at least that's what I found by some googling.

DarkAngel wrote:
XML isn't very appropriate for a scripting language either, because strictly speaking, the order that elements are stored in a file is supposed to be irrelevant (XML stores sets of data, not sequences of data).

Yes I know, but it sort of works :)

DarkAngel wrote:
What about in the long run if all of Horde's XML functionality was moved into a "file to class translation" module (responsible for converting data from disc into internal classes/objects). Then perhaps the file formats (XML/JSON/binary) could be changed with Horde extensions?

I think we should stick to some well-engineered but fixed file formats in Horde. Although I like flexibility, too much of it can hurt. It would become nearly impossible to write tools if everyone uses his own formats (e.g. different material syntaxes using XML or JSON). If someone really requires a different format, it is easy to change the loading code but we shouldn't encourage that. Much of an open source engine like Horde is the community projects and tools around it, so I think we should not do anything that complicates this development.

swiftcoder wrote:
If you are going to move away from XML, I would suggest skipping the intermediate stage of JSON, and moving all the way to YAML.

I would say it is ok to stick with XML for now. Our XML files are not that big and I think they are readable enough. The first example that jimbo brough is slightly unfair since the XML did not contain any indentation. The big advantage is that everyone knows XML and has a parser for it (when creating small tools).
Concerning performance: I started writing my own extremely lightweight XML parser some time ago. It is non-extractive (just stores references instead of copying data) and uses node pools to minimize the number of memory allocations. It should be really fast so I don't expect any performance problems with XML files.


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 25.04.2009, 03:13 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
marciano wrote:
Concerning performance: I started writing my own extremely lightweight XML parser some time ago. It is non-extractive (just stores references instead of copying data) and uses node pools to minimize the number of memory allocations. It should be really fast so I don't expect any performance problems with XML files.
There are quite a number of these already out there - you might want to have a look at rapidxml and fastxml, before committing to maintaining a custom solution ;)

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 25.04.2009, 18:10 
Offline

Joined: 26.08.2008, 18:48
Posts: 120
We are using http://code.google.com/p/pugixml/ in our title. In our test this was the fastest and required the less memory, we haven't checked fastxml though.

I think XML is the best solution, the worst I can imagine is a custom format. There is no need to reinvent the wheel... (Simplicity rulez. :) )


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 25.04.2009, 18:59 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
swiftcoder wrote:
There are quite a number of these already out there - you might want to have a look at rapidxml and fastxml, before committing to maintaining a custom solution ;)

Thanks for the links! Especially rapidxml looks very interesting. BTW, my own parser is already working (was just a longer evening of work) but it only takes a quite limited subset of XML so I would not be against using something more proven (like rapidxml). But I guess the XML parsing is not a bottleneck for anyone at the moment so I would consider it as one of the later optimization steps.

attila wrote:
We are using http://code.google.com/p/pugixml/ in our title. In our test this was the fastest and required the less memory, we haven't checked fastxml though.

Pugixml looks also interesting, although according to this (biased) benchmark, rapidxml seems to be a bit faster. But the difference is really marginal.

attila wrote:
I think XML is the best solution, the worst I can imagine is a custom format. There is no need to reinvent the wheel... (Simplicity rulez. :) )

The only real motivation for a custom format would be that we could create one that can embed binary data. So model and animation files could also become more readable. But anyway, that's not essential and XML has the other advantages of popularity and broad support so we will probably keep it.


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 26.04.2009, 19:00 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
attila wrote:
I think XML is the best solution, the worst I can imagine is a custom format. There is no need to reinvent the wheel... (Simplicity rulez. :) )
I am not disagreeing with your overall point, but XML is not really designed for simplicity - if that were the only goal, JSON or YAML would be better, being specifically designed for simplicity, and also widely used (FaceBook, Google, etc.).

As is, we don't really derive any benefit from using XML, since a) nobody wants to hand-craft these files, b) our format isn't widely supported by 3rd party tools, and c) we aren't using Schemas, DTDs, etc. (the one area where XML truly excels).

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 27.04.2009, 03:57 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
marciano wrote:
I think we should stick to some well-engineered but fixed file formats in Horde. Although I like flexibility, too much of it can hurt. It would become nearly impossible to write tools if everyone uses his own formats (e.g. different material syntaxes using XML or JSON). If someone really requires a different format, it is easy to change the loading code but we shouldn't encourage that. Much of an open source engine like Horde is the community projects and tools around it, so I think we should not do anything that complicates this development.
That's a good point..

It's pretty obvious though that everyone has a different preference for file format though!

Would you be interested in non-human readable formats (e.g. binary material files, etc)?

If there were two standard file formats (human/XML and binary), which were interchangeable and could be converted from one to the other, then people could use YAML etc in their own work-flow, as long as they write their own YAML<-> binary converter.

Then if someone needs to view a YAML file in XML form then a binary interchange format makes it possible: YAML -> binary -> XML.


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 28.04.2009, 15:37 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
DarkAngel wrote:
Would you be interested in non-human readable formats (e.g. binary material files, etc)?

If there were two standard file formats (human/XML and binary), which were interchangeable and could be converted from one to the other, then people could use YAML etc in their own work-flow, as long as they write their own YAML<-> binary converter.

Then if someone needs to view a YAML file in XML form then a binary interchange format makes it possible: YAML -> binary -> XML.
Binary files would be nice on the face of it, but since by production time you tend to have all these files in a compressed, packed-archive format, it doesn't really matter. Also a binary format means we need to deal with endian issues, etc.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
 Post subject: Re: JSON instead of XML
PostPosted: 28.04.2009, 19:44 
Offline

Joined: 11.04.2009, 08:42
Posts: 14
Location: France
swiftcoder wrote:
Also a binary format means we need to deal with endian issues, etc.

I don't think endianness is the biggest issue with binary files. It requires some care during the design phase (either indicating the endianness used upon storage in the file or using a fixed endian and converting upon read/write on machines that need it) but is relatively easy to deal with.

In my experience storage of recursive data structures and backward/forward compat are much bigger concerns than endianness (none likes to maintain several loaders/writers just to keep support for old file formats).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group