Box2Scene Format (read: port maintainers & Erin)

Yessir.

The reason shapes and fixtures are not inside of the bodies is so they can be re-used between Bodies and Fixtures.

I had actually not known you had done something like this before; I know someone did something for Farseer, but that was all I knew about.

This specification probably won't get anywhere until it reaches out to 2.2.0, so there's still room to change things around before anyone ever actually uses it. If you think changes should be made, drop me some sort of message describing exactly what should be changed and how - something like what would happen in a real standards committee. Not like it matters, but it seems to get things done faster this way. I appreciate the criticism and would like this format to be as modular and open as possible.

The format was designed to be as simplistic, modular and human-readable as possible. As long as implementers follow the implementation notes, everything should be peachy (or they can just port over the mini-XML parser I wrote for Box2Scene). In reality, yes, it is "XML", but I'm not pushing that people require a valid XML parser to do this format. It is its' own format based on the syntax of XML.

mayo: the level editor will fully support making entire worlds. It's written in C#, but you could easily write a Box2Scene-to-C++ converter that generates BodyDef/FixtureDef/Shape/JointDef code based on the contents.

EDIT: Thinking about exactly how this may be used, the reason I wanted it in the core is because then people using the C++ one (or ports for that matter) could just use the functions without having to do anything extra. However, now that I think about it, C++ users would just need to copy the files to their folder and include them in the project. Not sure about porters yet, though, that would be a different story.

-P
@mayobutter: I have mainly worked in the commercial game industry working on large teams. We tend to use a combination of expensive tools, like Maya, and custom tools built by a small army of programmers. TBH, Box2D is the only toe I have into the realm of independent games.

I would really like an XML reader/writer to be available for reproducing bugs cross platform. It would be great if someone on Flash could dump out their world in the current configuration and attach it to a forum post that I could then load into the C++ testbed. AFAIK, platforms like Flash already have built-in XML readers, whereas I might need to acquire an XML library for the C++ version. I would prefer to use the streaming model to reduce memory consumption.
Well, the XML file need not be stored in memory, it can be dumped right after loading. I wrote one in C# that you can check out here: http://code.google.com/p/box2c/source/b ... er.cs?r=32

It's a mini fragment parser, only about 400 lines of C#, it loads and stores the nodes recursively for later parsing. It does not use a stream model, it reads out the entire file into memory and then parses out the values (reason being C#'s StreamReader does not allow seeking. In C++ with the cstdio library you could do this with ease; in fact, about 100 of those lines are dealing with the fact that I couldn't stream it).

It doesn't do writing yet though, I will consider adding that later on. I just used C#'s XmlDocument class for the writing portion.

-P
Erin: This week I will attach a link to a cross platform (C++ in format that will work with XCode's GCC, and AS3's Box2DFlash) library and I will require another contributor to help me work on getting it to also work with MSVC. It will load the same world on all platforms. After I release my game (before end of month, I hope!), I will also check in an SVG parser that supports custom game objects (works well with SVG files produced from Inkscape, Illustrator hasn't been tested recently but used to work), with a simple example that shows how to load from SVG and stream back out to XML, both on AS3 and C++.

You can see my link http://tim.kerchmar.com/ropeburn/RopeBurn.swf for my game, most of it will be turned into TSBox2D examples, which is a library that provides some of these essential extras, and you are welcome to either keep a version of my library in your contributions folder, or people may naturally just start linking to it from forum posts or whatever. I am just glad to support such an awesome library. Thank you Erin.
Is this related to Box2Scene in any way? I'm looking to get it standardized as the format to communicate levels between and inside of ports.

-P
I can go with any XML format for the world. I haven't looked, but is there an easy way for me to get a current copy of your implementation?
I'm not sure exactly what your post above was trying to say though, that's why I'm a bit confused at what you were trying to get at. It just sounded like you were advocating a whole different format here, which is a little odd considering this thread was about Box2Scene :p

(EDIT: Sorry! I see now you mean it was an SVG parser of sorts. I totally mis-interpreted your post. If you wish, and if this turns out to be a good format (Box2Scene that is), perhaps we can integrate your SVG right inside of the format?)

All the details required to implement it is in the first post. A simple parser that supports the XML fragment reading is available in the Box2C SVN (my parser is http://code.google.com/p/box2c/source/b ... er.cs?r=32 , my (unfinished) implementation is in http://code.google.com/p/box2c/source/b ... ze.cs?r=32 )

Keep in mind that things are subject to change, and Version 1 only supports 2.1.2. Version 2 will support 2.2.0 and will have a contribution ready hopefully before its release (I have to get the level editor finished up as well).

-P
It looks like you do some C#ish magic for streaming in the userdata types. I will probably use a delegate that allows various overrides. For example, in the each level's SVG, my coins are represented as rectangles, but in the game I use a particular sized circle. Its nice to have a little more interaction with how the world is put together, and how/where in the process game objects are deserialized along with their Box2D subelements. I will be using that delegate in both AS3 and C++. Gameobjects are explicitly created in a switch statement in a delegate callback for each body loaded, before the body has been created. Each TSGameObject instance is also offered a chance to choose which, if any, of the shapes loaded should be used, or can provide its own (in a callback with a collection, not on per shape basis). Otherwise, the XML format itself can conform to your specs. From the looks of it, some b2XML serializations might just load without problem in Box2Scene. I really look forward to standardizing a XML format, because it would pave the road for a widely useful GUI editor.
I'm working on the GUI editor, actually. It's in the same SVN.

The UserData portion is implementation-dependent and usage-dependent. No implementation is required to even implement handling of UserData. In C#, I can use reflection to deserialize the string into its proper object, but other languages don't have this capability. To be completely fair, UserData is more or less just for saving and loading of games. Levels should never need to use it.

"Name" is only a string and could be used for identifiers (for instance, if it was a Box2D testbed, we could always infer that a body with the name "Wheel" can be controlled with left and right arrows and rotated).

-P
Without userdata, in levels, how do you specify coin reward amounts or other similar values?

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