Box2Scene Format (read: port maintainers & Erin)

Okay, so I've been working on this for a while, and I'm finally ready to present version 1 of the documentation for Box2D 2.1.2.

Presenting: Box2Scene, the XML-based scene format for Box2D!

I'm hoping that all versions, including the C++ one, can implement this as a regular feature, so that we can have one standardized format that we can share levels between different languages with ease. I'm also working on a level editor, but first, let's focus on the format.

The format is an XML fragment, and is very simple; it defines shapes, fixturedefs, bodydefs, and jointdefs, which together make up an entire World.

The current specification is available here:
http://alteredsoftworks.com/box2d/Box2Scene.pdf

Current supporters and/or implementers of the format:
- Box2CS (my project)
- Farseer Physics Engine

Please not that Version 1 tailors to Box2D 2.1.2, the current working stable version. I don't expect that the C++ version will be modified to accompany Box2Scene, however, most ports are still using this, so we can get them started on it before 2.2.0 gets released (and hopefully has Box2Scene integrated in it).

-P
I like the idea of being able to serialize a scene for debugging purposes. I would be happy to add such a library to the Contributions folder.
Well, it's not for debugging purposes really, it's for levels. I meant this format to be a standardized method for cross-port levels. The possibilities of usage are endless here.

The reason I don't want it to just be a contribution, and actually be a part of Box2D's workings (in a separate part though of course, but still in the DLL itself) is so that DLL ports can access it, if they are binding from a shared or dynamic library, which would remove the requirement that every port has its own parser (which is inefficient, not to mention it'd be harder for them all to keep up to date on it).

I don't mind maintaining the parser and serializer itself in the C++ version, but consider it as a base feature.

I noticed you were looking for a method to generate a testbed test from a world - this could be used for that occasion. You can use the level editor (which I'm working on) to generate the world, and implement any special needs inside the editor (using the Name or UserData fields to work out extra things such as what bodies are wheels, etc).

EDIT: Oh, you meant so people can send test cases more easily. Fair enough, I read that the wrong way.

-P
Right, so people can send me test cases.

Why do you think it needs to be part of the engine? As long as the serialization code can access all the data, there is no reverse dependency of the current engine on the serialization code.

I don't put any code in Box2D that isn't my own. I'm not going to get into the reasons here, but serialization either has to be a contribution or written and maintained by myself.
The part that I say may need to be part of the engine is the part that decompiles the XML file into serialization structures which can then be used however the program needs to use them. This would just simplify import-based ports, since they can just import the proper structures and functions and go right to it, and not have to deal with implementing their own parser to parse the XML file (if their standard libs don't have one).

I understand why you feel that way about the coding standard there, but my wish with Box2Scene is that it can become a standard part of Box2D and be supported across all ports. If you feel this strongly you can write the parser yourself if you have the spare time; if not, we can go with the contribution method, although that would mean more work on the side of port maintainers in order for them to get to use the deserializing functions.

-P
Have you seen my old attempt at this?

If you are going to make an all encompassing format, you should consider what already exists for that purpose before creating your own, or else you are just making the problem worse. Mine's for 2.0, though, so I guess it's ok. I have a half finished upgrade to 2.1 though.

There's a few take away ideas I have that you should investigate:
Some fields (particularly joint anchors) are implicitly defined, and can be specified in multiple co-ordinates. E.g. it's very common for distance joints to be initialized at rest-length, so that is the default.
Optional elements have well defined defaults.
Technically, all elements are optional - this allows the same format to be used as "patches" or "templates", expecting that other parts will get filled in with code. The parser provides methods not just for loading worlds, but loading any element from the corresponding tag.
Objects can go in any order, and identifiers are by name - this is much more idiomatic XML, and enables fragments of a world to be safer copy pasted, worlds to be concatenated, etc. My shapes are nested inside their bodies, too.
Comes with a formal schema definition - this saves on ambiguity in the specs, and enables certain XML frameworks to work better.
You say your building a GUI for this. Will this GUI also allow for attaching graphics to bodies / shapes? That's the only way I would find this useful (besides the running of tests like Erin mentioned). I would love to have something that sets up all the OpenGL stuff or whatever for running in C++. I guess I basically want Flash that compiles to C++ 🙂 (in other words, a C++ level editor). Maybe have rendering hooks in your editor so that someone could compile in their own graphics framework? I know what I'm suggesting here is ridiculously complicated... but it's really the only way I can see myself getting any use from this.
I'm still confused about why this needs to be a part of the engine. All you need is a library that takes an XML file and returns a b2World or vice-versa. The library can create a b2World just like any other client program.

I've worked on several game projects that serialize the physics data and all of them do this outside of the physics engine. I prefer it this way because it forces me to keep the code more modular.
Slightly off topic question for Erin: What tools / programs are used in the industry to create 2d C++ games? Specifically what is used to layout game levels? Are there any open source / free programs, or is every thing closed source / commercial? Or is it just "roll your own editor" for everything?

I agree there is no need for this in core but it would make a great contribution combined with a powerful editor GUI.
Erin - I think he wants you to bless it in some way that encourages porters and wrappers.

Original thread: https://box2d.org/forum/viewtopic.php?t=6117