Merge pull request #5134 from samme/feature/arcade-physics-collisions-perf

Arcade Physics collisions optimizations
This commit is contained in:
Richard Davey 2020-07-13 12:02:38 +01:00 committed by GitHub
commit 2f48e5ee00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1341,12 +1341,14 @@ var World = new Class({
* @param {ArcadePhysicsCallback} [processCallback] - The process callback.
* @param {*} [callbackContext] - The context in which to invoke the callback.
* @param {boolean} [overlapOnly] - If this a collide or overlap check?
* @param {boolean} [intersects] - Assert that the bodies intersect and should not be tested before separation.
*
* @return {boolean} True if separation occurred, otherwise false.
*/
separate: function (body1, body2, processCallback, callbackContext, overlapOnly)
separate: function (body1, body2, processCallback, callbackContext, overlapOnly, intersects)
{
if (
!intersects &&
!body1.enable ||
!body2.enable ||
body1.checkCollision.none ||
@ -1398,8 +1400,14 @@ var World = new Class({
var resultX = false;
var resultY = false;
// Do we separate on x or y first?
if (this.forceX || Math.abs(this.gravity.y + body1.gravity.y) < Math.abs(this.gravity.x + body1.gravity.x))
// Do we separate on x first or y first or both?
if (overlapOnly)
{
// No separation but we need to calculate overlapX, overlapY, etc.
resultX = SeparateX(body1, body2, overlapOnly, this.OVERLAP_BIAS);
resultY = SeparateY(body1, body2, overlapOnly, this.OVERLAP_BIAS);
}
else if (this.forceX || Math.abs(this.gravity.y + body1.gravity.y) < Math.abs(this.gravity.x + body1.gravity.x))
{
resultX = SeparateX(body1, body2, overlapOnly, this.OVERLAP_BIAS);
@ -1977,7 +1985,7 @@ var World = new Class({
continue;
}
if (this.separate(bodyA, bodyB, processCallback, callbackContext, overlapOnly))
if (this.separate(bodyA, bodyB, processCallback, callbackContext, overlapOnly, true))
{
if (collideCallback)
{