@@ -73,8 +73,6 @@ WbSimulationWorld::WbSimulationWorld(WbTokenizer *tokenizer) :
7373 }
7474 }
7575
76- mSleepRealTime = basicTimeStep ();
77-
7876 WbPerformanceLog *log = WbPerformanceLog::instance ();
7977 if (log)
8078 log->setTimeStep (basicTimeStep ());
@@ -128,6 +126,7 @@ WbSimulationWorld::WbSimulationWorld(WbTokenizer *tokenizer) :
128126 if (log)
129127 log->stopMeasure (WbPerformanceLog::LOADING);
130128
129+ mTimer ->setTimerType (Qt::PreciseTimer);
131130 connect (mTimer , &QTimer::timeout, this , &WbSimulationWorld::triggerStepFromTimer);
132131 const WbSimulationState *const s = WbSimulationState::instance ();
133132 connect (s, &WbSimulationState::rayTracingEnabled, this , &WbSimulationWorld::rayTracingEnabled);
@@ -185,30 +184,6 @@ void WbSimulationWorld::step() {
185184
186185 const double timeStep = basicTimeStep ();
187186
188- if (WbSimulationState::instance ()->isRealTime ()) {
189- const int elapsed = mRealTimeTimer .restart ();
190-
191- // How long should we have slept to be in real-time?
192- double idealSleepTime = timeStep - (elapsed - mSleepRealTime );
193- // Limit to timeStep to avoid weird behavior on large pauses (e.g., on startup)
194- // We also can't wait less than 0 ms.
195- idealSleepTime = qBound (0.0 , idealSleepTime, timeStep);
196- // computing the mean of an history of several time values
197- // improves significantly the stability of the algorithm.
198- // Moreover it improves the stability of simulations where
199- // basicTimeStep contains significant decimals
200- mIdealSleepTimeHistory .append (idealSleepTime);
201- if (mIdealSleepTimeHistory .size () > qMax (4.0 , 128.0 / timeStep)) // history size found empirically
202- mIdealSleepTimeHistory .pop_front ();
203- double mean = 0.0 ;
204- foreach (const double &v, mIdealSleepTimeHistory )
205- mean += v;
206- mean /= mIdealSleepTimeHistory .size ();
207- mSleepRealTime = mean;
208-
209- mTimer ->start (mSleepRealTime );
210- }
211-
212187 emit physicsStepStarted ();
213188
214189 if (log)
@@ -310,10 +285,9 @@ void WbSimulationWorld::modeChanged() {
310285 WbSoundEngine::setMute (WbPreferences::instance ()->value (" Sound/mute" ).toBool ());
311286 break ;
312287 case WbSimulationState::REALTIME:
313- mRealTimeTimer .start ();
314288 WbSoundEngine::setPause (false );
315289 WbSoundEngine::setMute (WbPreferences::instance ()->value (" Sound/mute" ).toBool ());
316- mTimer ->start (mSleepRealTime );
290+ mTimer ->start (basicTimeStep () );
317291 break ;
318292 case WbSimulationState::FAST:
319293 WbSoundEngine::setPause (false );
0 commit comments