]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.cpp
Change terminology to better distinguish routes on the layout from paths across track...
[r2c2.git] / source / libmarklin / train.cpp
index 9c56a5ddb5fc4f46147bad8645698c940683b22e..e904ebfc5f94b8152890c47c68a9b77cc4ebf189 100644 (file)
@@ -42,8 +42,8 @@ Train::Train(TrafficManager &tm, Locomotive &l):
        const map<unsigned, Turnout *> &turnouts = trfc_mgr.get_control().get_turnouts();
        for(map<unsigned, Turnout *>::const_iterator i=turnouts.begin(); i!=turnouts.end(); ++i)
        {
-               i->second->signal_route_changing.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_route_changing), i->second));
-               i->second->signal_route_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_route_changed), i->second));
+               i->second->signal_path_changing.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_path_changing), i->second));
+               i->second->signal_path_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_path_changed), i->second));
        }
 }
 
@@ -140,14 +140,14 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
 
        if(cur_track)
        {
-               unsigned route = 0;
+               unsigned path = 0;
                if(cur_track->get_turnout_id())
-                       route = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_route();
+                       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_route_length(route))
+               if(offset>cur_track->get_type().get_path_length(path))
                {
-                       int out = cur_track->traverse(cur_track_ep, route);
+                       int out = cur_track->traverse(cur_track_ep, path);
                        if(out>=0)
                        {
                                Track *next = cur_track->get_link(out);
@@ -161,7 +161,7 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
                }
 
                if(cur_track)
-                       pos = cur_track->get_point(cur_track_ep, route, offset);
+                       pos = cur_track->get_point(cur_track_ep, path, offset);
        }
 }
 
@@ -183,6 +183,15 @@ void Train::locomotive_reverse_changed(bool)
                i->entry = i->block->traverse(i->entry);
        reserve_more();
        update_speed();
+
+       if(cur_track)
+       {
+               unsigned path = 0;
+               if(unsigned turnout = cur_track->get_turnout_id())
+                       path = trfc_mgr.get_control().get_turnout(turnout).get_path();
+               cur_track_ep = cur_track->traverse(cur_track_ep, path);
+               offset = cur_track->get_type().get_path_length(path)-offset;
+       }
 }
 
 void Train::sensor_event(bool state, Sensor *sensor)
@@ -250,7 +259,7 @@ void Train::sensor_event(bool state, Sensor *sensor)
        }
 }
 
-void Train::turnout_route_changing(unsigned, Turnout *turnout)
+void Train::turnout_path_changing(unsigned, Turnout *turnout)
 {
        unsigned tid = turnout->get_address();
        for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
@@ -271,7 +280,7 @@ void Train::turnout_route_changing(unsigned, Turnout *turnout)
        }
 }
 
-void Train::turnout_route_changed(unsigned, Turnout *turnout)
+void Train::turnout_path_changed(unsigned, Turnout *turnout)
 {
        unsigned tid = turnout->get_address();
        for(list<BlockRef>::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i)