From f87e2b444ae9091eed723eff1b0e84579bd7d3e0 Mon Sep 17 00:00:00 2001 From: Martin Ziel Date: Sun, 26 Apr 2015 21:02:47 +0200 Subject: [PATCH 1/2] JavaScript CreateFixture method no longer accesses global world variable. --- liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js | 8 +++++++- liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js index f7653d850..f37e387d0 100644 --- a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js +++ b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js @@ -77,11 +77,13 @@ var b2Body_SetType = // memory offsets var b2Body_xf_offset = Offsets.b2Body.xf; var b2Body_userData_offset = Offsets.b2Body.userData; +var b2Body_world_offset = Offsets.b2Body.world; /**@constructor*/ function b2Body(ptr) { this.buffer = new DataView(Module.HEAPU8.buffer, ptr); this.ptr = ptr; this.fixtures = []; + this.world = null; } b2Body.prototype.ApplyAngularImpulse = function(impulse, wake) { @@ -110,7 +112,7 @@ b2Body.prototype.CreateFixtureFromDef = function(fixtureDef) { fixture._SetPtr(fixtureDef.shape._CreateFixture(this, fixtureDef)); fixture.body = this; b2World._Push(fixture, this.fixtures); - world.fixturesLookup[fixture.ptr] = fixture; + this.world.fixturesLookup[fixture.ptr] = fixture; return fixture; }; @@ -184,6 +186,10 @@ b2Body.prototype.GetUserData = function() { return this.buffer.getUint32(b2Body_userData_offset, true); }; +b2Body.prototype.GetWorld = function() { + return this.world; +}; + b2Body.prototype.GetWorldCenter = function() { b2Body_GetWorldCenter(this.ptr, _vec2Buf.byteOffset); var result = new Float32Array(_vec2Buf.buffer, _vec2Buf.byteOffset, _vec2Buf.length); diff --git a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js index 5d1fc9a98..8597034bf 100644 --- a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js +++ b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js @@ -133,6 +133,7 @@ b2World.prototype.CreateBody = function(bodyDef) { bodyDef.linearVelocity.y, bodyDef.position.x, bodyDef.position.y, bodyDef.type, bodyDef.userData)); b2World._Push(body, this.bodies); + body.world = this; this.bodiesLookup[body.ptr] = body; return body; }; From 7947063f0f6816e93222c2baed51bd44e382fd94 Mon Sep 17 00:00:00 2001 From: Martin Ziel Date: Mon, 27 Apr 2015 09:31:20 +0200 Subject: [PATCH 2/2] Removed unused b2Body_world_offset variable. --- liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js | 1 - 1 file changed, 1 deletion(-) diff --git a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js index f37e387d0..5d9585477 100644 --- a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js +++ b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js @@ -77,7 +77,6 @@ var b2Body_SetType = // memory offsets var b2Body_xf_offset = Offsets.b2Body.xf; var b2Body_userData_offset = Offsets.b2Body.userData; -var b2Body_world_offset = Offsets.b2Body.world; /**@constructor*/ function b2Body(ptr) { this.buffer = new DataView(Module.HEAPU8.buffer, ptr);