box2d v2.3.0 vs box2d v3.1 in Solar2d Game Engine

We have successfully ported Box2D 3.1 to Solar2D(now supporting iOS and Android), with significant performance improvements(a few methods may differ slightly). We will test its stability in actual projects, and if there are no issues, we will open-source the code.

We hope that both Box2D 3 and Box2d 2 can coexist with the Solar2d engine, allowing developers to choose the version of Box2D they need through require(“physics”) and require(“physics3”), ensuring that old projects can still run as they were.

However, we have not yet figured out how to implement this coexistence.

8 Likes

This is great work.
I noticed it when it was released, it has huge performance improvements over the very old box2D version of S2D.

1 Like

Thats great!
Or is it possible to make it seamlessly compatible with current Solar2D API?
Or toggle with Defaults settings?
I think @StarCrunch will have some ideas.

1 Like

It may be seamlessly compatible with the current API, but not in behavior.

“Toggle with Defaults settings” is a good idea.

If it were a build.settings thing, you could choose the correct options up front.

With setDefault() (not sure if this is what was meant), you would have to deal with setting it too late (after some physics has already been done, with the default; what do you do with the old stuff?), or setting it multiple times (same problem). These issues would also show up with different require() names , and I think it would be much easier to accidentally require("physics") in a module after already switching to version 3.


Gave the migration guide a quick look.

Just from seeing that I see that, despite the massive ABI overhaul, there are still common types, e.g. b2Vec2 is in both cases for Chains.

I looked over the engine source files that #include Box2D headers.


I think you could duplicate the Rtt_PhysicsSomething.cpp / .h files as Rtt_PhysicsSomething3.cpp, then replace the appropriate behaviors. This is probably essentially what you did anyway to add the version 3 behavior. Ditto for b2GLESDebugDraw and Rtt_DisplayObjectExtensions. There is at least some virtual interface in some of these already. (Particle systems might fit in here too.)


Rtt_Event.cpp's collision events need to handle either case, but maybe it’s localized enough that you could just do if (version1) {} else {} tests in those.

Rtt_LuaProxyVTable also has a few big switch statements for all the various Box2D properties. You’d probably also want another if / else thing there.

In these cases you would (without a bit of work… could elaborate if interested) be including the headers for both versions of Box2D. But then you’d be having duplicate names stomping on one another. Ideally you could #include version 3’s headers into a namespace and scope those names that way.


I saw that b2vec2 is also being used just as a handy vector type in some other spots. So we’d have to make sure those didn’t stomp on version 3, or get stomped on by it, either.


(Was just rattling these off skimming the search results in Visual Studio, but could link to various stuff too.)

1 Like