From 1709c7afe41a96b079f3d34c9625d1a790dcc805 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 27 Mar 2015 09:04:54 +0200 Subject: [PATCH] Limit timestep to 10 milliseconds The simulation still has some problems with detriggering sensors if a train advances too much during a step. This should alleviate the issue. --- source/libr2c2/layout.cpp | 8 ++++++++ source/libr2c2/layout.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index fe21881..70a9f10 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -425,6 +425,14 @@ void Layout::tick() dt = t-last_tick; last_tick = t; + unsigned count = dt/(10*Time::msec)+1; + dt /= count; + while(count--) + step(dt); +} + +void Layout::step(const Time::TimeDelta &dt) +{ if(!driver || !driver->is_halted()) clock.tick(dt); diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index a1c37d3..2488f93 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "geometry.h" #include "sensor.h" @@ -151,6 +152,9 @@ public: void remove_train(Train &); void tick(); +private: + void step(const Msp::Time::TimeDelta &); +public: void emergency(Block *, const std::string &); void save(const std::string &) const; -- 2.43.0