]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/train.cpp
Refer to things in the driver with abstract ids instead of addresses
[r2c2.git] / source / libr2c2 / train.cpp
index 50ad137723d42ec2a8c10775767a3de92c91d745..bb82fe4c34090cf22b53f90cda41aa74478dcc01 100644 (file)
@@ -58,7 +58,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p):
 
        layout.add_train(*this);
 
-       layout.get_driver().add_loco(address, protocol, loco_type);
+       loco_id = layout.get_driver().add_loco(address, protocol, loco_type);
        layout.get_driver().signal_loco_speed.connect(sigc::mem_fun(this, &Train::loco_speed_event));
        layout.get_driver().signal_loco_function.connect(sigc::mem_fun(this, &Train::loco_func_event));
 
@@ -140,7 +140,7 @@ void Train::set_function(unsigned func, bool state)
 {
        if(!loco_type.get_functions().count(func))
                throw invalid_argument("Train::set_function");
-       layout.get_driver().set_loco_function(address, func, state);
+       layout.get_driver().set_loco_function(loco_id, func, state);
 }
 
 float Train::get_control(const string &ctrl) const
@@ -317,7 +317,7 @@ void Train::tick(const Time::TimeDelta &dt)
                bool r = reverse;
                if(loco_type.get_swap_direction())
                        r = !r;
-               driver.set_loco_reverse(address, r);
+               driver.set_loco_reverse(loco_id, r);
 
                allocator.reverse();
                last_entry_block = BlockIter();
@@ -329,7 +329,7 @@ void Train::tick(const Time::TimeDelta &dt)
                if(speed_step!=current_speed_step && !speed_changing && !driver.is_halted() && driver.get_power())
                {
                        speed_changing = true;
-                       driver.set_loco_speed(address, speed_step);
+                       driver.set_loco_speed(loco_id, speed_step);
 
                        pure_speed = false;
                }
@@ -404,24 +404,24 @@ void Train::control_changed(const Controller::Control &ctrl)
        signal_control_changed.emit(ctrl.name, ctrl.value);
 }
 
-void Train::loco_speed_event(unsigned addr, unsigned speed, bool rev)
+void Train::loco_speed_event(unsigned id, unsigned speed, bool rev)
 {
-       if(addr==address)
+       if(id==loco_id)
        {
                current_speed_step = speed;
                bool r = reverse;
                if(loco_type.get_swap_direction())
                        r = !r;
                if(rev!=r)
-                       layout.get_driver().set_loco_reverse(address, r);
+                       layout.get_driver().set_loco_reverse(loco_id, r);
                speed_changing = false;
                pure_speed = false;
        }
 }
 
-void Train::loco_func_event(unsigned addr, unsigned func, bool state)
+void Train::loco_func_event(unsigned id, unsigned func, bool state)
 {
-       if(addr==address)
+       if(id==loco_id)
        {
                if(state)
                        functions |= 1<<func;