From: Mikko Rasa Date: Fri, 27 Mar 2015 07:04:54 +0000 (+0200) Subject: Limit timestep to 10 milliseconds X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=1709c7afe41a96b079f3d34c9625d1a790dcc805;p=r2c2.git 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. --- 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;