Skip to content

Commit

Permalink
deprecated Matter.Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Dec 12, 2021
1 parent a6b5e7d commit e366d0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
22 changes: 22 additions & 0 deletions src/collision/Grid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* This module has now been replaced by `Matter.Detector`.
*
* All usage should be migrated to `Matter.Detector` or another alternative.
* For back-compatibility purposes this module will remain for a short term and then later removed in a future release.
*
* The `Matter.Grid` module contains methods for creating and manipulating collision broadphase grid structures.
*
* @class Grid
* @deprecated
*/

var Grid = {};
Expand All @@ -10,11 +16,13 @@ module.exports = Grid;

var Pair = require('./Pair');
var Common = require('../core/Common');
var deprecated = Common.deprecated;

(function() {

/**
* Creates a new grid.
* @deprecated replaced by Matter.Detector
* @method create
* @param {} options
* @return {grid} A new grid
Expand Down Expand Up @@ -49,6 +57,7 @@ var Common = require('../core/Common');

/**
* Updates the grid.
* @deprecated replaced by Matter.Detector
* @method update
* @param {grid} grid
* @param {body[]} bodies
Expand Down Expand Up @@ -127,8 +136,11 @@ var Common = require('../core/Common');
grid.pairsList = Grid._createActivePairsList(grid);
};

deprecated(Grid, 'update', 'Grid.update ➤ replaced by Matter.Detector');

/**
* Clears the grid.
* @deprecated replaced by Matter.Detector
* @method clear
* @param {grid} grid
*/
Expand All @@ -138,9 +150,12 @@ var Common = require('../core/Common');
grid.pairsList = [];
};

deprecated(Grid, 'clear', 'Grid.clear ➤ replaced by Matter.Detector');

/**
* Finds the union of two regions.
* @method _regionUnion
* @deprecated replaced by Matter.Detector
* @private
* @param {} regionA
* @param {} regionB
Expand All @@ -158,6 +173,7 @@ var Common = require('../core/Common');
/**
* Gets the region a given body falls in for a given grid.
* @method _getRegion
* @deprecated replaced by Matter.Detector
* @private
* @param {} grid
* @param {} body
Expand All @@ -176,6 +192,7 @@ var Common = require('../core/Common');
/**
* Creates a region.
* @method _createRegion
* @deprecated replaced by Matter.Detector
* @private
* @param {} startCol
* @param {} endCol
Expand All @@ -196,6 +213,7 @@ var Common = require('../core/Common');
/**
* Gets the bucket id at the given position.
* @method _getBucketId
* @deprecated replaced by Matter.Detector
* @private
* @param {} column
* @param {} row
Expand All @@ -208,6 +226,7 @@ var Common = require('../core/Common');
/**
* Creates a bucket.
* @method _createBucket
* @deprecated replaced by Matter.Detector
* @private
* @param {} buckets
* @param {} bucketId
Expand All @@ -221,6 +240,7 @@ var Common = require('../core/Common');
/**
* Adds a body to a bucket.
* @method _bucketAddBody
* @deprecated replaced by Matter.Detector
* @private
* @param {} grid
* @param {} bucket
Expand Down Expand Up @@ -258,6 +278,7 @@ var Common = require('../core/Common');
/**
* Removes a body from a bucket.
* @method _bucketRemoveBody
* @deprecated replaced by Matter.Detector
* @private
* @param {} grid
* @param {} bucket
Expand Down Expand Up @@ -287,6 +308,7 @@ var Common = require('../core/Common');
/**
* Generates a list of the active pairs in the grid.
* @method _createActivePairsList
* @deprecated replaced by Matter.Detector
* @private
* @param {} grid
* @return [] pairs
Expand Down
47 changes: 4 additions & 43 deletions src/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ var Mouse = require('../core/Mouse');
showDebug: false,
showStats: false,
showPerformance: false,
showBroadphase: false,
showBounds: false,
showVelocity: false,
showCollisions: false,
Expand Down Expand Up @@ -116,6 +115,9 @@ var Mouse = require('../core/Mouse');
}
};

// for temporary back compatibility only
render.options.showBroadphase = false;

if (render.options.pixelRatio !== 1) {
Render.setPixelRatio(render, render.options.pixelRatio);
}
Expand Down Expand Up @@ -436,9 +438,6 @@ var Mouse = require('../core/Mouse');

Render.constraints(constraints, context);

if (options.showBroadphase)
Render.grid(render, engine.grid, context);

if (options.hasBounds) {
// revert view transforms
Render.endViewTransform(render);
Expand Down Expand Up @@ -1285,45 +1284,6 @@ var Mouse = require('../core/Mouse');
c.stroke();
};

/**
* Description
* @private
* @method grid
* @param {render} render
* @param {grid} grid
* @param {RenderingContext} context
*/
Render.grid = function(render, grid, context) {
var c = context,
options = render.options;

if (options.wireframes) {
c.strokeStyle = 'rgba(255,180,0,0.1)';
} else {
c.strokeStyle = 'rgba(255,180,0,0.5)';
}

c.beginPath();

var bucketKeys = Common.keys(grid.buckets);

for (var i = 0; i < bucketKeys.length; i++) {
var bucketId = bucketKeys[i];

if (grid.buckets[bucketId].length < 2)
continue;

var region = bucketId.split(/C|R/);
c.rect(0.5 + parseInt(region[1], 10) * grid.bucketWidth,
0.5 + parseInt(region[2], 10) * grid.bucketHeight,
grid.bucketWidth,
grid.bucketHeight);
}

c.lineWidth = 1;
c.stroke();
};

/**
* Description
* @private
Expand Down Expand Up @@ -1765,6 +1725,7 @@ var Mouse = require('../core/Mouse');
/**
* A flag to enable or disable the collision broadphase debug overlay.
*
* @deprecated no longer implemented
* @property options.showBroadphase
* @type boolean
* @default false
Expand Down

0 comments on commit e366d0e

Please sign in to comment.