From b44fcf3f82f792baa4410dd19010d79b3315b364 Mon Sep 17 00:00:00 2001 From: Brice Chevalier Date: Mon, 20 Nov 2017 11:52:44 +0900 Subject: [PATCH 1/4] aglorithm optimization of Pairs.update method --- src/collision/Pair.js | 1 + src/collision/Pairs.js | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/collision/Pair.js b/src/collision/Pair.js index 7f654b5..ccfd088 100644 --- a/src/collision/Pair.js +++ b/src/collision/Pair.js @@ -33,6 +33,7 @@ var Contact = require('./Contact'); activeContacts: [], separation: 0, isActive: true, + confirmedActive: true, isSensor: bodyA.isSensor || bodyB.isSensor, timeCreated: timestamp, timeUpdated: timestamp, diff --git a/src/collision/Pairs.js b/src/collision/Pairs.js index 48bd2ac..6e05e60 100644 --- a/src/collision/Pairs.js +++ b/src/collision/Pairs.js @@ -55,12 +55,15 @@ var Common = require('../core/Common'); collisionEnd.length = 0; collisionActive.length = 0; + for (i = 0; i < pairsList.length; i++) { + pairsList[i].confirmedActive = false; + } + for (i = 0; i < collisions.length; i++) { collision = collisions[i]; if (collision.collided) { pairId = Pair.id(collision.bodyA, collision.bodyB); - activePairIds.push(pairId); pair = pairsTable[pairId]; @@ -76,6 +79,7 @@ var Common = require('../core/Common'); // update the pair Pair.update(pair, collision, timestamp); + pair.confirmedActive = true; } else { // pair did not exist, create a new pair pair = Pair.create(collision, timestamp); @@ -91,7 +95,7 @@ var Common = require('../core/Common'); // deactivate previously active pairs that are now inactive for (i = 0; i < pairsList.length; i++) { pair = pairsList[i]; - if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) { + if (!pair.confirmedActive) { Pair.setActive(pair, false, timestamp); collisionEnd.push(pair); } From 7813c782c7e0c5155d40b55c724fc21b40221514 Mon Sep 17 00:00:00 2001 From: Brice Chevalier Date: Wed, 22 Nov 2017 11:59:06 +0900 Subject: [PATCH 2/4] fixed code style --- src/collision/Pairs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collision/Pairs.js b/src/collision/Pairs.js index 6e05e60..a85e4b1 100644 --- a/src/collision/Pairs.js +++ b/src/collision/Pairs.js @@ -56,7 +56,7 @@ var Common = require('../core/Common'); collisionActive.length = 0; for (i = 0; i < pairsList.length; i++) { - pairsList[i].confirmedActive = false; + pairsList[i].confirmedActive = false; } for (i = 0; i < collisions.length; i++) { From 59708eff22546768a06f02c9680742e6abc504ba Mon Sep 17 00:00:00 2001 From: Brice Chevalier Date: Wed, 22 Nov 2017 12:02:23 +0900 Subject: [PATCH 3/4] removal of unnecessary variable activePairs --- src/collision/Pairs.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/collision/Pairs.js b/src/collision/Pairs.js index a85e4b1..83a8991 100644 --- a/src/collision/Pairs.js +++ b/src/collision/Pairs.js @@ -44,7 +44,6 @@ var Common = require('../core/Common'); collisionStart = pairs.collisionStart, collisionEnd = pairs.collisionEnd, collisionActive = pairs.collisionActive, - activePairIds = [], collision, pairId, pair, From 4e04043fe0daf7deec681ab49f244d3867f75062 Mon Sep 17 00:00:00 2001 From: Brice Chevalier Date: Sat, 24 Mar 2018 16:39:25 +0900 Subject: [PATCH 4/4] Fixed end collision triggering more than once --- src/collision/Pairs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collision/Pairs.js b/src/collision/Pairs.js index 83a8991..117b955 100644 --- a/src/collision/Pairs.js +++ b/src/collision/Pairs.js @@ -94,7 +94,7 @@ var Common = require('../core/Common'); // deactivate previously active pairs that are now inactive for (i = 0; i < pairsList.length; i++) { pair = pairsList[i]; - if (!pair.confirmedActive) { + if (pair.isActive && !pair.confirmedActive) { Pair.setActive(pair, false, timestamp); collisionEnd.push(pair); }