]> git.tdb.fi Git - r2c2.git/commitdiff
Don't advance the estimated train position outside current blocks
authorMikko Rasa <tdb@tdb.fi>
Tue, 22 Dec 2009 18:54:28 +0000 (18:54 +0000)
committerMikko Rasa <tdb@tdb.fi>
Tue, 22 Dec 2009 18:54:28 +0000 (18:54 +0000)
source/libmarklin/train.cpp

index 4beda974bf85d65f10c0547325038322aead6975..5524a5d77c6a2740e24d4894a811dcac75441b44 100644 (file)
@@ -154,14 +154,25 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
                        path = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_path();
 
                offset += get_real_speed(loco.get_speed())*(dt/Time::sec);
-               if(offset>cur_track->get_type().get_path_length(path))
+               float path_len = cur_track->get_type().get_path_length(path);
+               if(offset>path_len)
                {
                        unsigned out = cur_track->traverse(cur_track_ep, path);
                        Track *next = cur_track->get_link(out);
-                       if(next)
-                               cur_track_ep = next->get_endpoint_by_link(*cur_track);
-                       cur_track = next;
-                       offset = 0;
+
+                       bool ok = false;
+                       for(list<BlockRef>::const_iterator i=cur_blocks.begin(); (!ok && i!=cur_blocks.end()); ++i)
+                               ok = i->block->get_tracks().count(next);
+
+                       if(ok)
+                       {
+                               if(next)
+                                       cur_track_ep = next->get_endpoint_by_link(*cur_track);
+                               cur_track = next;
+                               offset = 0;
+                       }
+                       else
+                               offset = path_len-0.001;
                }
 
                if(cur_track)