From 280818e144be4fc9eea55b72eb6df08ebda6805a Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Wed, 16 Sep 2020 15:47:13 -0700 Subject: [PATCH 1/2] process messageQueue before stepping world; cleanup --- src/ammo.worker.js | 12 ++++++------ src/body.js | 5 ----- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ammo.worker.js b/src/ammo.worker.js index 749e053..2d32b60 100644 --- a/src/ammo.worker.js +++ b/src/ammo.worker.js @@ -75,12 +75,6 @@ const tick = () => { setTimeout(tick, simulationRate); if (isBufferConsumed()) { - const now = performance.now(); - const dt = now - lastTick; - world.step(dt / 1000); - stepDuration = performance.now() - now; - lastTick = now; - while (messageQueue.length > 0) { const message = messageQueue.shift(); switch (message.type) { @@ -107,6 +101,12 @@ const tick = () => { } } + const now = performance.now(); + const dt = now - lastTick; + world.step(dt / 1000); + stepDuration = performance.now() - now; + lastTick = now; + /** Buffer Schema * Every physics body has 26 * 4 bytes (64bit float/int) assigned in the buffer * 0-15: Matrix4 elements (floats) diff --git a/src/body.js b/src/body.js index 7f4b11c..b310d77 100644 --- a/src/body.js +++ b/src/body.js @@ -71,7 +71,6 @@ function Body(bodyConfig, matrix, world) { ? bodyConfig.activationState : ACTIVATION_STATE.ACTIVE_TAG; this.type = bodyConfig.type ? bodyConfig.type : TYPE.DYNAMIC; - this.emitCollisionEvents = bodyConfig.hasOwnProperty("emitCollisionEvents") ? bodyConfig.emitCollisionEvents : false; this.disableCollision = bodyConfig.hasOwnProperty("disableCollision") ? bodyConfig.disableCollision : false; this.collisionFilterGroup = bodyConfig.hasOwnProperty("collisionFilterGroup") ? bodyConfig.collisionFilterGroup : 1; //32-bit mask this.collisionFilterMask = bodyConfig.hasOwnProperty("collisionFilterMask") ? bodyConfig.collisionFilterMask : 1; //32-bit mask @@ -138,10 +137,6 @@ Body.prototype._initBody = (function() { this.updateCollisionFlags(); this.world.addBody(this.physicsBody, this.matrix, this.collisionFilterGroup, this.collisionFilterMask); - - if (this.emitCollisionEvents) { - this.world.addEventListener(this.physicsBody); - } }; })(); From a3976a4f66f484ce7eb283ea34a1ffde241ceebb Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Wed, 16 Sep 2020 15:53:49 -0700 Subject: [PATCH 2/2] additional dead code removal --- package-lock.json | 2 +- src/body.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a093049..160790d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "three-ammo", - "version": "1.0.1", + "version": "1.0.11", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/body.js b/src/body.js index b310d77..eb33d9e 100644 --- a/src/body.js +++ b/src/body.js @@ -47,7 +47,6 @@ function almostEqualsQuaternion(epsilon, u, v) { * parsing the elements geometry. */ function Body(bodyConfig, matrix, world) { - this.loadedEvent = bodyConfig.loadedEvent ? bodyConfig.loadedEvent : ""; this.mass = bodyConfig.hasOwnProperty("mass") ? bodyConfig.mass : 1; const worldGravity = world.physicsWorld.getGravity(); this.gravity = new Ammo.btVector3(worldGravity.x(), worldGravity.y(), worldGravity.z());