mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
Merge branch 'optim-pairs-update' into optim-pair-update
This commit is contained in:
commit
7220435e35
2 changed files with 7 additions and 3 deletions
|
@ -28,6 +28,7 @@ module.exports = Pair;
|
|||
activeContacts: [],
|
||||
separation: 0,
|
||||
isActive: true,
|
||||
confirmedActive: true,
|
||||
isSensor: bodyA.isSensor || bodyB.isSensor,
|
||||
timeCreated: timestamp,
|
||||
timeUpdated: timestamp,
|
||||
|
|
|
@ -44,7 +44,6 @@ var Common = require('../core/Common');
|
|||
collisionStart = pairs.collisionStart,
|
||||
collisionEnd = pairs.collisionEnd,
|
||||
collisionActive = pairs.collisionActive,
|
||||
activePairIds = [],
|
||||
collision,
|
||||
pairId,
|
||||
pair,
|
||||
|
@ -55,12 +54,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 +78,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 +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.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
|
||||
if (pair.isActive && !pair.confirmedActive) {
|
||||
Pair.setActive(pair, false, timestamp);
|
||||
collisionEnd.push(pair);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue