Box2Scene Format (read: port maintainers & Erin)

This is up to the user. Like I said, stuff like "coin values" is implementation-dependent. My level editor will have no idea what a "coin" is, or what a "coin value" is. It would just persist whatever data you give to it. It would also have no idea how to deserialize the userdata. As I said though, there are still kinks to work out, and this is one of them. My guess is we can also just leave UserData as a string.

-P
https://github.com/timkerchmar/TrippySoftLib

The SVG parser in C++ is usable. The same SVG parser is used on the C++ side as will be demonstrated in the AS3 version. I ripped out some of the core SVG parsing routines from SVGWeb, creating MiniSVGWeb. Using a pretty generic delegate class, you can draw to Box2D or anything else if you wanted. On an actual iPad, the SVG parsing is still pretty slow.

There are several very nice gems in this iPad app:

1. minimal objective C (kept quarentined in a few particular files).
2. shows a satisfying scroll/throw touch handling
3. renders everything with OpenGL ES 2.0 shaders
4. same numbers and math can be used for OpenGL or upcoming AS3 version (screen goes from 0-1024 wide on both)
5. Allows easy override of SVG unit -> box2D unit scale, and box2D -> screen unit scale
6. Shows DrawDebugDataInAABB (which I lazily stuck directly into b2World).

The repository is public, so if you are interested, please use and update. This is for us all.

The Box2Scene work is still pending. Translating from AS3's containers and GC conveniences to C++'s is quite a chore.
I checked in an update to the iPadSample that is b2XML's loading from XML translated to C++. The saving part has not been done.

The iPadSample shows:

- a tilemap drawn using OpenGL 2.0 ES shaders
- the physics is loaded from an svg
- some object's shape definitions come from the settings.xml, but centered where the original object was located in the SVG
Nice.

How complex is the SVG code? As I said above maybe we can integrate this directly with Box2Scene as a way of cleaning up importing of edge shapes.

-P
The SVG parser has a bit of bulk to it, but it does seem to work pretty well. I used another svg parser before with Box2D and had nothing but trouble getting a wide variety of items to import correctly. Depending upon which language you were porting to, you may prefer to start from AS3 or C++ as your starting point. Both are functionally equivalent. I do need to fix 1 issue that I am noticing in the C++ version with how curves are being smoothed.
I meant in the XML side, the implementation isn't too important to me right now.

-P
Updated to fix bug with curve decomposition. The XML side sadly is not using Box2Scene, but it might be a really nice place to start for a C++ implementation of Box2Scene, which is pretty similar to b2XML. In particular, you can pass in defaults for your defs, and the XML will use those defaults unless overridden from the XML.
I like the defaults idea. I think I'll implement that in Version 2. My idea is simply that you make a body or fixture with an attribute of "Default" and it will act as a default value holder or something.. I'll experiment with it after.

-p
Guys about the user data thing. I was thinking about writing my own world serialiser (before looking here), and the way I was thinking of doing it is with a callback like how other things are done in Box2D.

For example the base class would look like this

Code:
class b2UserDataSerialiser /// I'm not particularly good at thinking up class names haha
{
  public:
    b2UserDataSerialiser();
    ~b2UserDataSerialiser();
    virtual void* serialiseJoint(std::istream* buffer){return NULL;}
    virtual void* serialiseBody(std::istream* buffer){return NULL;}
    virtual void serialiseJoint(void* userData, std::ostream* buffer){}
    virtual void serialiseBody(void* userData, std::ostream* buffer){}
};


And obviously, when you want to save or load a world, you pass in (or set) an instance of this class before passing in the stream
Unless you guys already have somethingfor user data/finished this/moved on from this little project, I can't reference to it anywhere and its not been long since the last post
In a language without reflection, it's really hard to properly serialize user data, as it can be of any arbitrary type.

In C/C++, my advice is to make a table of known data types and conversion functions (passing in a void* parameter to the object to be serialized/deserialized).

Another option is to leave the user data section up to the user; provide a callback function that allows the user to interpret the raw userdata however he needs it.

Box2Scene, the two main implementations, are written in C#, which allows for very simple deserialization.

-P

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