mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-30 10:20:52 -05:00
aglorithm optimization of Pairs.update method
This commit is contained in:
parent
0895d81fa1
commit
b44fcf3f82
2 changed files with 7 additions and 2 deletions
|
@ -33,6 +33,7 @@ var Contact = require('./Contact');
|
||||||
activeContacts: [],
|
activeContacts: [],
|
||||||
separation: 0,
|
separation: 0,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
confirmedActive: true,
|
||||||
isSensor: bodyA.isSensor || bodyB.isSensor,
|
isSensor: bodyA.isSensor || bodyB.isSensor,
|
||||||
timeCreated: timestamp,
|
timeCreated: timestamp,
|
||||||
timeUpdated: timestamp,
|
timeUpdated: timestamp,
|
||||||
|
|
|
@ -55,12 +55,15 @@ var Common = require('../core/Common');
|
||||||
collisionEnd.length = 0;
|
collisionEnd.length = 0;
|
||||||
collisionActive.length = 0;
|
collisionActive.length = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < pairsList.length; i++) {
|
||||||
|
pairsList[i].confirmedActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < collisions.length; i++) {
|
for (i = 0; i < collisions.length; i++) {
|
||||||
collision = collisions[i];
|
collision = collisions[i];
|
||||||
|
|
||||||
if (collision.collided) {
|
if (collision.collided) {
|
||||||
pairId = Pair.id(collision.bodyA, collision.bodyB);
|
pairId = Pair.id(collision.bodyA, collision.bodyB);
|
||||||
activePairIds.push(pairId);
|
|
||||||
|
|
||||||
pair = pairsTable[pairId];
|
pair = pairsTable[pairId];
|
||||||
|
|
||||||
|
@ -76,6 +79,7 @@ var Common = require('../core/Common');
|
||||||
|
|
||||||
// update the pair
|
// update the pair
|
||||||
Pair.update(pair, collision, timestamp);
|
Pair.update(pair, collision, timestamp);
|
||||||
|
pair.confirmedActive = true;
|
||||||
} else {
|
} else {
|
||||||
// pair did not exist, create a new pair
|
// pair did not exist, create a new pair
|
||||||
pair = Pair.create(collision, timestamp);
|
pair = Pair.create(collision, timestamp);
|
||||||
|
@ -91,7 +95,7 @@ var Common = require('../core/Common');
|
||||||
// deactivate previously active pairs that are now inactive
|
// deactivate previously active pairs that are now inactive
|
||||||
for (i = 0; i < pairsList.length; i++) {
|
for (i = 0; i < pairsList.length; i++) {
|
||||||
pair = pairsList[i];
|
pair = pairsList[i];
|
||||||
if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
|
if (!pair.confirmedActive) {
|
||||||
Pair.setActive(pair, false, timestamp);
|
Pair.setActive(pair, false, timestamp);
|
||||||
collisionEnd.push(pair);
|
collisionEnd.push(pair);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue