Skip to content

Commit

Permalink
added cache checks to Matter.Composite
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 9, 2021
1 parent 10afaea commit 32fd285
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/body/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var Body = require('./Body');
Composite.setModified = function(composite, isModified, updateParents, updateChildren) {
composite.isModified = isModified;

if (isModified) {
if (isModified && composite.cache) {
composite.cache.allBodies = null;
composite.cache.allConstraints = null;
composite.cache.allComposites = null;
Expand All @@ -73,7 +73,7 @@ var Body = require('./Body');
}

if (updateChildren) {
for(var i = 0; i < composite.composites.length; i++) {
for (var i = 0; i < composite.composites.length; i++) {
var childComposite = composite.composites[i];
Composite.setModified(childComposite, isModified, updateParents, updateChildren);
}
Expand Down Expand Up @@ -359,7 +359,7 @@ var Body = require('./Body');
* @return {body[]} All the bodies
*/
Composite.allBodies = function(composite) {
if (composite.cache.allBodies) {
if (composite.cache && composite.cache.allBodies) {
return composite.cache.allBodies;
}

Expand All @@ -368,7 +368,9 @@ var Body = require('./Body');
for (var i = 0; i < composite.composites.length; i++)
bodies = bodies.concat(Composite.allBodies(composite.composites[i]));

composite.cache.allBodies = bodies;
if (composite.cache) {
composite.cache.allBodies = bodies;
}

return bodies;
};
Expand All @@ -380,7 +382,7 @@ var Body = require('./Body');
* @return {constraint[]} All the constraints
*/
Composite.allConstraints = function(composite) {
if (composite.cache.allConstraints) {
if (composite.cache && composite.cache.allConstraints) {
return composite.cache.allConstraints;
}

Expand All @@ -389,7 +391,9 @@ var Body = require('./Body');
for (var i = 0; i < composite.composites.length; i++)
constraints = constraints.concat(Composite.allConstraints(composite.composites[i]));

composite.cache.allConstraints = constraints;
if (composite.cache) {
composite.cache.allConstraints = constraints;
}

return constraints;
};
Expand All @@ -401,7 +405,7 @@ var Body = require('./Body');
* @return {composite[]} All the composites
*/
Composite.allComposites = function(composite) {
if (composite.cache.allComposites) {
if (composite.cache && composite.cache.allComposites) {
return composite.cache.allComposites;
}

Expand All @@ -410,7 +414,9 @@ var Body = require('./Body');
for (var i = 0; i < composite.composites.length; i++)
composites = composites.concat(Composite.allComposites(composite.composites[i]));

composite.cache.allComposites = composites;
if (composite.cache) {
composite.cache.allComposites = composites;
}

return composites;
};
Expand Down

0 comments on commit 32fd285

Please sign in to comment.