Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Commit

Permalink
Ensure start and end of stabilization progress events is sent (#3165)
Browse files Browse the repository at this point in the history
Fix for #3106

Event `stabilizationProgress` is now always sent for iteration 0 and for the very last stabilization iteration.
  • Loading branch information
wimrijnders authored and yotamberk committed Jun 13, 2017
1 parent 33c3e3d commit 69fef3d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/network/modules/PhysicsEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,20 +638,31 @@ class PhysicsEngine {
* @private
*/
_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.
if (this.startedStabilization === false) {
this.body.emitter.emit('startStabilizing');
this.startedStabilization = true;
sendProgress();
}

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();
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);
}
else {
Expand Down

0 comments on commit 69fef3d

Please sign in to comment.