|
@ -638,20 +638,31 @@ class PhysicsEngine { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
_stabilizationBatch() { |
|
|
_stabilizationBatch() { |
|
|
|
|
|
var self = this; |
|
|
|
|
|
var running = () => (self.stabilized === false && self.stabilizationIterations < self.targetIterations); |
|
|
|
|
|
var sendProgress = () => { |
|
|
|
|
|
self.body.emitter.emit('stabilizationProgress', { |
|
|
|
|
|
iterations: self.stabilizationIterations, |
|
|
|
|
|
total: self.targetIterations |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// this is here to ensure that there is at least one start event.
|
|
|
// this is here to ensure that there is at least one start event.
|
|
|
if (this.startedStabilization === false) { |
|
|
if (this.startedStabilization === false) { |
|
|
this.body.emitter.emit('startStabilizing'); |
|
|
this.body.emitter.emit('startStabilizing'); |
|
|
this.startedStabilization = true; |
|
|
this.startedStabilization = true; |
|
|
|
|
|
sendProgress(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var count = 0; |
|
|
var count = 0; |
|
|
while (this.stabilized === false && count < this.options.stabilization.updateInterval && this.stabilizationIterations < this.targetIterations) { |
|
|
|
|
|
|
|
|
while (running() && count < this.options.stabilization.updateInterval) { |
|
|
this.physicsTick(); |
|
|
this.physicsTick(); |
|
|
count++; |
|
|
count++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (this.stabilized === false && this.stabilizationIterations < this.targetIterations) { |
|
|
|
|
|
this.body.emitter.emit('stabilizationProgress', {iterations: this.stabilizationIterations, total: this.targetIterations}); |
|
|
|
|
|
|
|
|
sendProgress(); |
|
|
|
|
|
|
|
|
|
|
|
if (running()) { |
|
|
setTimeout(this._stabilizationBatch.bind(this),0); |
|
|
setTimeout(this._stabilizationBatch.bind(this),0); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|