|
@ -274,9 +274,10 @@ class PhysicsEngine { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
_emitStabilized(amountOfIterations = this.stabilizationIterations) { |
|
|
_emitStabilized(amountOfIterations = this.stabilizationIterations) { |
|
|
if (this.stabilizationIterations > 1) { |
|
|
|
|
|
|
|
|
if (this.stabilizationIterations > 1 || this.startedStabilization === true) { |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
this.body.emitter.emit('stabilized', {iterations: amountOfIterations}); |
|
|
this.body.emitter.emit('stabilized', {iterations: amountOfIterations}); |
|
|
|
|
|
this.startedStabilization = false; |
|
|
this.stabilizationIterations = 0; |
|
|
this.stabilizationIterations = 0; |
|
|
}, 0); |
|
|
}, 0); |
|
|
} |
|
|
} |
|
@ -288,6 +289,12 @@ class PhysicsEngine { |
|
|
* @private |
|
|
* @private |
|
|
*/ |
|
|
*/ |
|
|
physicsTick() { |
|
|
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) { |
|
|
if (this.stabilized === false) { |
|
|
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
|
|
|
// adaptivity means the timestep adapts to the situation, only applicable for stabilization
|
|
|
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { |
|
|
if (this.adaptiveTimestep === true && this.adaptiveTimestepEnabled === true) { |
|
@ -350,13 +357,6 @@ class PhysicsEngine { |
|
|
if (this.stabilized === true) { |
|
|
if (this.stabilized === true) { |
|
|
this.revert(); |
|
|
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++; |
|
|
this.stabilizationIterations++; |
|
|
} |
|
|
} |
|
@ -671,14 +671,7 @@ class PhysicsEngine { |
|
|
this.body.emitter.emit('_requestRedraw'); |
|
|
this.body.emitter.emit('_requestRedraw'); |
|
|
|
|
|
|
|
|
if (this.stabilized === true) { |
|
|
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 { |
|
|
else { |
|
|
this.startSimulation(); |
|
|
this.startSimulation(); |
|
|