Skip to content

Commit 4d4c535

Browse files
committed
Added World positionIterations property to help settle busy scenes
1 parent 7c5f6ad commit 4d4c535

2 files changed

Lines changed: 40 additions & 27 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ var Body = new Class({
314314

315315
this._sleep = 0;
316316

317-
this.sleepIterations = 60;
317+
this.sleepIterations = 60 * world.positionIterations;
318318

319319
// 0 = none, 1 = soft block, 2 = hard block
320320
this.forcePosition = 0;
@@ -1063,7 +1063,7 @@ var Body = new Class({
10631063
this.checkWorldRebound();
10641064
}
10651065

1066-
if (this.forcePosition !== 5)
1066+
if (this.forcePosition < 5)
10671067
{
10681068
position.x += this.getMoveX(velocity.x * delta);
10691069
position.y += this.getMoveY(velocity.y * delta);
@@ -1174,8 +1174,8 @@ var Body = new Class({
11741174
}
11751175
else if (!this.sleeping)
11761176
{
1177-
gameObject.x += dx;
1178-
gameObject.y += dy;
1177+
gameObject.x += dx / this.world.positionIterations;
1178+
gameObject.y += dy / this.world.positionIterations;
11791179

11801180
if (this.allowRotation)
11811181
{
@@ -2292,22 +2292,22 @@ var Body = new Class({
22922292
{
22932293
ArrayAdd(this.blockers.up, collisionInfo);
22942294
}
2295-
else
2295+
else if (body2.isWorldBlockedUp())
22962296
{
2297-
if (body2.isWorldBlockedUp())
2298-
{
2299-
this.setHardBlockedUp();
2300-
}
2297+
this.setHardBlockedUp();
2298+
2299+
this.forcePosition = 6;
2300+
2301+
this.y = body2.bottom;
23012302
}
23022303

23032304
// We don't reposition this body if it's already blocked on a face
2304-
if (this.forcePosition === 5 || this.worldBlocked.down || this.worldBlocked.up)
2305+
if (this.forcePosition === 5 || this.isWorldBlockedUp() || this.isWorldBlockedDown())
23052306
{
23062307
return this;
23072308
}
23082309

2309-
// if (body2 && !collisionInfo.set)
2310-
if (body2)
2310+
if (body2 && !collisionInfo.set)
23112311
{
23122312
console.log(this.gameObject.name, 'setBlockedUp', body2.bottom);
23132313

@@ -2317,7 +2317,7 @@ var Body = new Class({
23172317

23182318
this.forcePosition = 1;
23192319

2320-
// collisionInfo.set = true;
2320+
collisionInfo.set = true;
23212321
}
23222322
}
23232323

@@ -2337,22 +2337,22 @@ var Body = new Class({
23372337
{
23382338
ArrayAdd(this.blockers.down, collisionInfo);
23392339
}
2340-
else
2340+
else if (body2.isWorldBlockedDown())
23412341
{
2342-
if (body2.isWorldBlockedDown())
2343-
{
2344-
this.setHardBlockedDown();
2345-
}
2342+
this.setHardBlockedDown();
2343+
2344+
this.forcePosition = 7;
2345+
2346+
this.bottom = body2.y;
23462347
}
23472348

23482349
// We don't reposition this body if it's already blocked on a face
2349-
if (this.forcePosition === 5 || this.worldBlocked.down || this.worldBlocked.up)
2350+
if (this.forcePosition === 5 || this.isWorldBlockedUp() || this.isWorldBlockedDown())
23502351
{
23512352
return this;
23522353
}
23532354

2354-
// if (body2 && !collisionInfo.set)
2355-
if (body2)
2355+
if (body2 && !collisionInfo.set)
23562356
{
23572357
console.log(this.gameObject.name, 'setBlockedDown', body2.y);
23582358

@@ -2362,7 +2362,7 @@ var Body = new Class({
23622362

23632363
this.forcePosition = 2;
23642364

2365-
// collisionInfo.set = true;
2365+
collisionInfo.set = true;
23662366
}
23672367
}
23682368

src/physics/arcade/World.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ var World = new Class({
155155
*/
156156
this.fps = GetValue(config, 'fps', 60);
157157

158+
/**
159+
* The number of times all of the active dynamic bodies will be iterated through,
160+
* in order to settle down their positions.
161+
*
162+
* @name Phaser.Physics.Arcade.World#positionIterations
163+
* @type {integer}
164+
* @since 3.17.0
165+
*/
166+
this.positionIterations = 6;
167+
158168
/**
159169
* The amount of elapsed ms since the last frame.
160170
*
@@ -1034,13 +1044,16 @@ var World = new Class({
10341044

10351045
if (!this.isPaused)
10361046
{
1037-
for (i = 0; i < len; i++)
1047+
for (var c = 0; c < this.positionIterations; c++)
10381048
{
1039-
body = bodies[i];
1040-
1041-
if (body.enable)
1049+
for (i = 0; i < len; i++)
10421050
{
1043-
body.postUpdate();
1051+
body = bodies[i];
1052+
1053+
if (body.enable)
1054+
{
1055+
body.postUpdate();
1056+
}
10441057
}
10451058
}
10461059
}

0 commit comments

Comments
 (0)