3 ms·
Cool! Is there a big advantage to a manual rewrite vs emscripten? With emscripten folding in updates from Box2D 'native' would be easier, it seems.
by santaclaus 10y ago
Cool! Is there a big advantage to a manual rewrite vs emscripten? With emscripten folding in updates from Box2D 'native' would be easier, it seems.
- caseywebdev 10y agoOne advantage is that the planck [1] is over 4x smaller than the emscripten build [2]. [1]: https://github.com/shakiba/planck.js/blob/master/dist/planck.min.js https://github.com/shakiba/planck.js/blob/master/dist/planck... [2]: https://github.com/kripken/box2d.js/blob/master/build/Box2D_v2.3.1_min.js https://github.com/kripken/box2d.js/blob/master/build/Box2D_...
- shakiba 10y agoThanks! Repost from reddit: The main reasons that I decided not to use Emscripten port was usability: - First, it is generated and unreadable code, therefore it is impossible to understand how it actually works in JS to use it optimally, debug it or improve it for JS. While it possible to improve Planck.js if it is not as fast in some cases, it is not possible to do anything with Emscripten port. - Second, API of Emscripten port does not follow JavaScript conventions and is inconvenient to use in JavaScript. For example it returns an empty object, instead of no object (null or undefined) as last element of a linked list (which is very confusing in JS). Here are some more usage comparisons: // emscripten var bd_ground = new Box2D.b2BodyDef(); var ground = world.CreateBody(bd_ground); var shape0 = new Box2D.b2EdgeShape(); shape0.Set(new Box2D.b2Vec2(-40.0, -6.0), new Box2D.b2Vec2(40.0, -6.0)); ground.CreateFixture(shape0, 0.0); // planck.js var ground = world.createBody({}); ground.createFixture(planck.Edge(Vec2(-40.0, -6.0), Vec2(40.0, -6.0)), 0.0); // emscripten var bd = new Box2D.b2BodyDef(); bd.set_type(Box2D.b2_dynamicBody); bd.set_position(ZERO); var body = world.CreateBody(bd); // planck.js var body = world.createBody({ type: "dynamic", position: Vec2(0, 0), }); // or just world.createDynamicBody(); // emscripten myQueryCallback = new Box2D.JSQueryCallback(); myQueryCallback.ReportFixture = function(fixturePtr) { }; // planck.js myQueryCallback = function(fixture) { };