Skip to content

Commit

Permalink
merge tumult:old_ie_fixes + tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jul 12, 2014
2 parents 18a2627 + b91af36 commit 6e1ab9a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/body/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var Composite = {};
* @return {composite} The original compositeA with the composite removed
*/
Composite.removeComposite = function(compositeA, compositeB, deep) {
var position = compositeA.composites.indexOf(compositeB);
var position = Common.indexOf(compositeA.composites, compositeB);
if (position !== -1) {
Composite.removeCompositeAt(compositeA, position);
Composite.setModified(compositeA, true, true, false);
Expand Down Expand Up @@ -219,7 +219,7 @@ var Composite = {};
* @return {composite} The original composite with the body removed
*/
Composite.removeBody = function(composite, body, deep) {
var position = composite.bodies.indexOf(body);
var position = Common.indexOf(composite.bodies, body);
if (position !== -1) {
Composite.removeBodyAt(composite, position);
Composite.setModified(composite, true, true, false);
Expand Down Expand Up @@ -272,7 +272,7 @@ var Composite = {};
* @return {composite} The original composite with the constraint removed
*/
Composite.removeConstraint = function(composite, constraint, deep) {
var position = composite.constraints.indexOf(constraint);
var position = Common.indexOf(composite.constraints, constraint);
if (position !== -1) {
Composite.removeConstraintAt(composite, position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ var Grid = {};
*/
var _bucketRemoveBody = function(grid, bucket, body) {
// remove from bucket
bucket.splice(bucket.indexOf(body), 1);
bucket.splice(Common.indexOf(bucket, body), 1);

// update pair counts
for (var i = 0; i < bucket.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/collision/Pairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var Pairs = {};
// deactivate previously active pairs that are now inactive
for (i = 0; i < pairsList.length; i++) {
pair = pairsList[i];
if (pair.isActive && activePairIds.indexOf(pair.id) === -1) {
if (pair.isActive && Common.indexOf(activePairIds, pair.id) === -1) {
Pair.setActive(pair, false, timestamp);
collisionEnd.push(pair);
}
Expand Down
18 changes: 18 additions & 0 deletions src/core/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ var Common = {};
return Common._nextId++;
};

/**
* A cross browser compatible indexOf implementation
* @method indexOf
* @param {array} haystack
* @param {object} needle
*/
Common.indexOf = function(haystack, needle) {
if (haystack.indexOf)
return haystack.indexOf(needle);

for (var i = 0; i < haystack.length; i++) {
if (haystack[i] === needle)
return i;
}

return -1;
};

var _seededRandom = function() {
// https://gist.github.com/ngryman/3830489
Common._seed = (Common._seed * 9301 + 49297) % 233280;
Expand Down
6 changes: 3 additions & 3 deletions src/render/RenderPixi.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ var RenderPixi = {};
}

// add to scene graph if not already there
if (container.children.indexOf(primitive) === -1)
if (Common.indexOf(container.children, primitive) === -1)
container.addChild(primitive);

// render the constraint on every update, since they can change dynamically
Expand Down Expand Up @@ -307,7 +307,7 @@ var RenderPixi = {};
sprite = render.sprites[spriteId] = _createBodySprite(render, body);

// add to scene graph if not already there
if (spriteBatch.children.indexOf(sprite) === -1)
if (Common.indexOf(spriteBatch.children, sprite) === -1)
spriteBatch.addChild(sprite);

// update body sprite
Expand All @@ -326,7 +326,7 @@ var RenderPixi = {};
}

// add to scene graph if not already there
if (container.children.indexOf(primitive) === -1)
if (Common.indexOf(container.children, primitive) === -1)
container.addChild(primitive);

// update body primitive
Expand Down

0 comments on commit 6e1ab9a

Please sign in to comment.