Skip to content

Commit d65d478

Browse files
CoolSpy3TonyWelte
andcommitted
use Qt::PreciseTimer and remove synchronization code
Co-authored-by: Anthony Welte <[email protected]>
1 parent 9a8de34 commit d65d478

File tree

2 files changed

+2
-31
lines changed

2 files changed

+2
-31
lines changed

src/webots/engine/WbSimulationWorld.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/webots/engine/WbSimulationWorld.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ protected slots:
7676
WbOdeContext *mOdeContext;
7777
WbPhysicsPlugin *mPhysicsPlugin;
7878
QTimer *mTimer;
79-
QElapsedTimer mRealTimeTimer;
80-
double mSleepRealTime;
81-
QList<double> mIdealSleepTimeHistory;
8279
QVector<WbNode *> mAddedNode; // list of nodes added since the simulation started
8380

8481
void storeLastSaveTime() override;

0 commit comments

Comments
 (0)