Skip to content

Commit

Permalink
justTest for all narrowphase methods, improve overlapKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Dec 15, 2015
1 parent 5a2a885 commit 145b4f7
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 72 deletions.
7 changes: 3 additions & 4 deletions src/collision/Broadphase.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ Broadphase.prototype.collisionPairs = function(world,p1,p2){
* @param {Body} bodyB
* @return {bool}
*/
var Broadphase_needBroadphaseCollision_STATIC_OR_KINEMATIC = Body.STATIC | Body.KINEMATIC;
Broadphase.prototype.needBroadphaseCollision = function(bodyA,bodyB){

// Check collision filter masks
Expand All @@ -61,9 +60,9 @@ Broadphase.prototype.needBroadphaseCollision = function(bodyA,bodyB){
}

// Check types
if(((bodyA.type & Broadphase_needBroadphaseCollision_STATIC_OR_KINEMATIC)!==0 || bodyA.sleepState === Body.SLEEPING) &&
((bodyB.type & Broadphase_needBroadphaseCollision_STATIC_OR_KINEMATIC)!==0 || bodyB.sleepState === Body.SLEEPING)) {
// Both bodies are static, kinematic or sleeping. Skip.
if(((bodyA.type & Body.STATIC)!==0 || bodyA.sleepState === Body.SLEEPING) &&
((bodyB.type & Body.STATIC)!==0 || bodyB.sleepState === Body.SLEEPING)) {
// Both bodies are static or sleeping. Skip.
return false;
}

Expand Down
40 changes: 23 additions & 17 deletions src/collision/OverlapKeeper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,35 @@ function unpackAndPush(array, key){
* @param {array} removals
*/
OverlapKeeper.prototype.getDiff = function(additions, removals) {
var i=0, j=0;
var a = this.current;
var b = this.previous;
var al = a.length;
var bl = b.length;
while(i < al && j < bl){
var iKey = a[i];
var jKey = b[j];
if(iKey < jKey){
unpackAndPush(removals, jKey);
i++;
} else if(iKey === jKey){
i++;
j++;
} else {
unpackAndPush(additions, iKey);

var j=0;
for (var i = 0; i < al; i++) {
var found = false;

while(a[i] > b[j]){
j++;
}
found = a[i] === b[j];

if(!found){
unpackAndPush(additions, a[i]);
}
}
for(var k=i; k<al; k++){
unpackAndPush(additions, a[k]);
}
for(var k=j; k<bl; k++){
unpackAndPush(removals, b[k]);
j = 0;
for (var i = 0; i < bl; i++) {
var found = false;

while(b[i] > a[j]){
j++;
}
found = a[j] === b[i];

if(!found){
unpackAndPush(removals, b[i]);
}
}
};

0 comments on commit 145b4f7

Please sign in to comment.