]> git.tdb.fi Git - r2c2.git/commitdiff
Limit timestep to 10 milliseconds
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Mar 2015 07:04:54 +0000 (09:04 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Mar 2015 07:04:54 +0000 (09:04 +0200)
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
source/libr2c2/layout.h

index fe21881a2e4ab46a5f7f1e3b6a6e48c75bf7c2af..70a9f106849d26ec2f9b59ad0eb2d5b8d13a2169 100644 (file)
@@ -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);
 
index a1c37d312b682ed6fabb086018824a0876d54d2e..2488f9371aa98c08a284daadc29bae40d976c05d 100644 (file)
@@ -5,6 +5,7 @@
 #include <set>
 #include <sigc++/sigc++.h>
 #include <msp/datafile/objectloader.h>
+#include <msp/time/timedelta.h>
 #include <msp/time/timestamp.h>
 #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;