Improvement in CPP SCENE EXPORT

What would you like to see in future versions of the editor?
Post Reply
fisher
Posts: 6
Joined: Sat Feb 15, 2014 9:31 pm

Improvement in CPP SCENE EXPORT

Post by fisher » Sat Feb 15, 2014 9:47 pm

Hello,

I think about improvement for option: File->Export Scene->Save as source code.

Exporting scene to *.cpp file is quite nice, however, objects are exported in their own scope, that is, between "{}". I know that this was the easiest way to generate objects tree, but each object has the same name, for example:

Code: Select all

b2BodyDef bd;
b2FixtureDef fd;
etc..

However, if you want to find something or extract any object, you can't really say where your object is looking at cpp code.

But, in RUBE each object has a NAME property.

Why not include this NAME (and other properties) in object's scope? For example as a comment:

Code: Select all

{
    //name: small_box
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....
}
or even better, as some kind of mapping name->object:

Code: Select all

{
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....

    bodies["small_box"] = &bd;
}
or advanced version with property table:

Code: Select all

{
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....

    ObjectProperties *objProp = new ObjectProperties();
    objProp.name = "small_box"
    
    bodies["small_box"] = objProp;
}
Is it possible to make such improvement?

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Improvement in CPP SCENE EXPORT

Post by iforce2d » Mon Feb 17, 2014 12:12 am

The cpp export uses the b2World::Dump function of Box2D directly, and was added mostly as an afterthought. It remains there just in case it could be handy for some situations like quickly getting a simple scene running without the overhead of setting up a loader fully. I would not encourage using it for anything more than that. Come to think of it, I would not really encourage using it at all. viewtopic.php?f=6&t=95

The C++ loader can be set up by adding a few files to your project, and will give you easy access to the full data available in the scene. In the "sampleLoaders" folder that comes with the trial download, you should find a bunch of examples that are done in C++, for example box2d-testbed-(C++) or SFML-(C++). Look for the 'rubestuff' folder in these, and add the contents of that to your project. Then you can start using the loader as described here: http://www.iforce2d.net/b2djson/

Post Reply