mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Added confirmedActive speed optimisation to matter.js and removed Common.indexOf
This commit is contained in:
parent
f1ea070256
commit
ffeff9d2f7
5 changed files with 9 additions and 10 deletions
|
@ -176,7 +176,6 @@ var Body = require('./Body');
|
|||
* @return {composite} The original compositeA with the composite removed
|
||||
*/
|
||||
Composite.removeComposite = function(compositeA, compositeB, deep) {
|
||||
// var position = Common.indexOf(compositeA.composites, compositeB);
|
||||
var position = compositeA.composites.indexOf(compositeB);
|
||||
if (position !== -1) {
|
||||
Composite.removeCompositeAt(compositeA, position);
|
||||
|
@ -230,7 +229,6 @@ var Body = require('./Body');
|
|||
* @return {composite} The original composite with the body removed
|
||||
*/
|
||||
Composite.removeBody = function(composite, body, deep) {
|
||||
// var position = Common.indexOf(composite.bodies, body);
|
||||
var position = composite.bodies.indexOf(body);
|
||||
if (position !== -1) {
|
||||
Composite.removeBodyAt(composite, position);
|
||||
|
@ -284,7 +282,6 @@ var Body = require('./Body');
|
|||
* @return {composite} The original composite with the constraint removed
|
||||
*/
|
||||
Composite.removeConstraint = function(composite, constraint, deep) {
|
||||
// var position = Common.indexOf(composite.constraints, constraint);
|
||||
var position = composite.constraints.indexOf(constraint);
|
||||
if (position !== -1) {
|
||||
Composite.removeConstraintAt(composite, position);
|
||||
|
|
|
@ -272,7 +272,6 @@ var Common = require('../core/Common');
|
|||
*/
|
||||
var _bucketRemoveBody = function(grid, bucket, body) {
|
||||
// remove from bucket
|
||||
// bucket.splice(Common.indexOf(bucket, body), 1);
|
||||
bucket.splice(bucket.indexOf(body), 1);
|
||||
|
||||
// update pair counts
|
||||
|
|
|
@ -33,6 +33,7 @@ var Contact = require('./Contact');
|
|||
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,8 +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 && activePairIds.indexOf(pair.id) === -1) {
|
||||
if (!pair.confirmedActive) {
|
||||
Pair.setActive(pair, false, timestamp);
|
||||
collisionEnd.push(pair);
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ module.exports = Common;
|
|||
* @return {boolean} True if the object is a string, otherwise false
|
||||
*/
|
||||
Common.isString = function(obj) {
|
||||
return toString.call(obj) === '[object String]';
|
||||
return Object.prototype.toString.call(obj) === '[object String]';
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -369,7 +369,6 @@ module.exports = Common;
|
|||
* @param {array} haystack
|
||||
* @param {object} needle
|
||||
* @return {number} The position of needle in haystack, otherwise -1.
|
||||
*/
|
||||
Common.indexOf = function(haystack, needle) {
|
||||
if (haystack.indexOf)
|
||||
return haystack.indexOf(needle);
|
||||
|
@ -381,6 +380,7 @@ module.exports = Common;
|
|||
|
||||
return -1;
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* A cross browser compatible array map implementation.
|
||||
|
|
Loading…
Reference in a new issue