|
|
@ -274,9 +274,10 @@ class PhysicsEngine { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
_emitStabilized(amountOfIterations = this.stabilizationIterations) { |
|
|
|
if (this.stabilizationIterations > 1) { |
|
|
|
if (this.stabilizationIterations > 1 || this.startedStabilization === true) { |
|
|
|
setTimeout(() => { |
|
|
|
this.body.emitter.emit('stabilized', {iterations: amountOfIterations}); |
|
|
|
this.startedStabilization = false; |
|
|
|
this.stabilizationIterations = 0; |
|
|
|
}, 0); |
|
|
|
} |
|
|
@ -288,6 +289,12 @@ class PhysicsEngine { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
physicsTick() { |
|
|
|
// this is here to ensure that there is no start event when the network is already stable.
|
|
|
|
if (this.startedStabilization === false) { |
|
|
|
this.body.emitter.emit('startStabilizing'); |
|
|
|
this.startedStabilization = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.stabilized === false) { |
|
|
|
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
|
|
|
|
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { |
|
|
@ -350,13 +357,6 @@ class PhysicsEngine { |
|
|
|
if (this.stabilized === true) { |
|
|
|
this.revert(); |
|
|
|
} |
|
|
|
else { |
|
|
|
// this is here to ensure that there is no start event when the network is already stable.
|
|
|
|
if (this.startedStabilization === false) { |
|
|
|
this.body.emitter.emit('startStabilizing'); |
|
|
|
this.startedStabilization = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.stabilizationIterations++; |
|
|
|
} |
|
|
@ -671,14 +671,7 @@ class PhysicsEngine { |
|
|
|
this.body.emitter.emit('_requestRedraw'); |
|
|
|
|
|
|
|
if (this.stabilized === true) { |
|
|
|
// I want at least one stabilized event if there is nothing to stabilize.
|
|
|
|
if (this.stabilizationIterations < 2) { |
|
|
|
this.stabilizationIterations = 2; |
|
|
|
this._emitStabilized(0); // the zero overrules the iterations
|
|
|
|
} |
|
|
|
else { |
|
|
|
this._emitStabilized(); |
|
|
|
} |
|
|
|
this._emitStabilized(); |
|
|
|
} |
|
|
|
else { |
|
|
|
this.startSimulation(); |
|
|
|