Browse Source

Ensure start and end of stabilization progress events is sent (#3165)

Fix for #3106

Event `stabilizationProgress` is now always sent for iteration 0 and for the very last stabilization iteration.
gemini
wimrijnders 7 years ago
committed by yotamberk
parent
commit
69fef3dbf4
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      lib/network/modules/PhysicsEngine.js

+ 14
- 3
lib/network/modules/PhysicsEngine.js View File

@ -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 {

Loading…
Cancel
Save