Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/reference/changelog-r2025.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added missing import libraries on Windows ([#6753](https://github.com/cyberbotics/webots/pull/6753)).
- Added some missing function definitions to the existing Windows libraries ([#6753](https://github.com/cyberbotics/webots/pull/6753)).
- Webots now prints the cause when it fails to create a memory-mapped file for a camera node ([#6896](https://github.com/cyberbotics/webots/pull/6896)).
- Made the timestep algorithm more consistent when running in realtime mode ([#6898](https://github.com/cyberbotics/webots/pull/6898)).
- Cleanup
- **Removed `libController.a` and `libCppController.a` libraries on Windows. Please use `Controller.lib` and `CppController.lib` instead ([#6753](https://github.com/cyberbotics/webots/pull/6753)).**
- Bug Fixes
Expand Down
1 change: 1 addition & 0 deletions scripts/packaging/files_msys64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/mingw64/bin/libpcre2-16-0.dll
/mingw64/bin/libpng16-16.dll
/mingw64/bin/libssl-3-x64.dll
/mingw64/bin/libwinpthread-1.dll
/mingw64/bin/Qt6Core.dll
/mingw64/bin/Qt6Gui.dll
/mingw64/bin/Qt6Network.dll
Expand Down
41 changes: 8 additions & 33 deletions src/webots/engine/WbSimulationWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ WbSimulationWorld::WbSimulationWorld(WbTokenizer *tokenizer) :
}
}

mSleepRealTime = basicTimeStep();

WbPerformanceLog *log = WbPerformanceLog::instance();
if (log)
log->setTimeStep(basicTimeStep());
Expand Down Expand Up @@ -128,6 +126,7 @@ WbSimulationWorld::WbSimulationWorld(WbTokenizer *tokenizer) :
if (log)
log->stopMeasure(WbPerformanceLog::LOADING);

mTimer->setTimerType(Qt::PreciseTimer);
connect(mTimer, &QTimer::timeout, this, &WbSimulationWorld::triggerStepFromTimer);
const WbSimulationState *const s = WbSimulationState::instance();
connect(s, &WbSimulationState::rayTracingEnabled, this, &WbSimulationWorld::rayTracingEnabled);
Expand Down Expand Up @@ -185,35 +184,10 @@ void WbSimulationWorld::step() {

const double timeStep = basicTimeStep();

if (WbSimulationState::instance()->isRealTime()) {
const int elapsed = mRealTimeTimer.restart();

// computing the mean of an history of several elapsedTime
// improves significantly the stability of the algorithm
// in case of simulations where elapsedTime oscillates often
// above and below basicTimeStep.
// Moreover it improves the stability of simulations where
// basicTimeStep contains significant decimals
mElapsedTimeHistory.append(elapsed);
if (mElapsedTimeHistory.size() > qMax(4.0, 128.0 / timeStep)) // history size found empirically
mElapsedTimeHistory.pop_front();
double mean = 0.0;
foreach (const int &v, mElapsedTimeHistory)
mean += v;
mean /= mElapsedTimeHistory.size();

// useful hack: uncomment to run Webots at 90% of the real-time
// (if the real-time mode is enabled, of course)
// mean *= 0.90;

if (mean > timeStep && mSleepRealTime > 0.0) {
mSleepRealTime -= 0.03 * timeStep;
if (mSleepRealTime < 0)
mSleepRealTime = 0.0;
} else if (mean < timeStep)
mSleepRealTime += 0.03 * timeStep;

mTimer->start(mSleepRealTime);
// Update the timer's timestep if it's been changed
if (timeStep != mOldTimeStep && WbSimulationState::instance()->isRealTime()) {
mOldTimeStep = timeStep;
mTimer->start(timeStep);
}

emit physicsStepStarted();
Expand Down Expand Up @@ -303,6 +277,7 @@ void WbSimulationWorld::restartStepTimer() {

void WbSimulationWorld::modeChanged() {
WbPerformanceLog *log = WbPerformanceLog::instance();
const double timeStep = basicTimeStep();

const WbSimulationState::Mode mode = WbSimulationState::instance()->mode();
switch (mode) {
Expand All @@ -317,10 +292,10 @@ void WbSimulationWorld::modeChanged() {
WbSoundEngine::setMute(WbPreferences::instance()->value("Sound/mute").toBool());
break;
case WbSimulationState::REALTIME:
mRealTimeTimer.start();
WbSoundEngine::setPause(false);
WbSoundEngine::setMute(WbPreferences::instance()->value("Sound/mute").toBool());
mTimer->start(mSleepRealTime);
mOldTimeStep = timeStep;
mTimer->start(timeStep);
break;
case WbSimulationState::FAST:
WbSoundEngine::setPause(false);
Expand Down
4 changes: 1 addition & 3 deletions src/webots/engine/WbSimulationWorld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ protected slots:
WbOdeContext *mOdeContext;
WbPhysicsPlugin *mPhysicsPlugin;
QTimer *mTimer;
QElapsedTimer mRealTimeTimer;
double mSleepRealTime;
QList<int> mElapsedTimeHistory;
double mOldTimeStep;
QVector<WbNode *> mAddedNode; // list of nodes added since the simulation started

void storeLastSaveTime() override;
Expand Down
Loading