]> git.tdb.fi Git - r2c2.git/commitdiff
Fix travel to sensor handling
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Feb 2011 21:50:09 +0000 (21:50 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Feb 2011 21:50:09 +0000 (21:50 +0000)
Handle situations where the train is already at the target location

source/libr2c2/timetable.cpp
source/libr2c2/timetable.h

index c28cbccae245a6dcb7650eb4e0237feb85056ccf..8b469b52fd848feb52f09c07346a521780c1d8ca 100644 (file)
@@ -25,7 +25,8 @@ Timetable::Timetable(Train &t):
        current_row(0),
        executing(true),
        pending_block(0),
-       pending_train(0)
+       pending_train(0),
+       arrived(false)
 {
        train.signal_arrived.connect(sigc::mem_fun(this, &Timetable::train_arrived));
        train.get_layout().get_driver().signal_sensor.connect(sigc::mem_fun(this, &Timetable::sensor_event));
@@ -90,10 +91,12 @@ void Timetable::tick(const Time::TimeStamp &t)
                switch(row.type)
                {
                case GOTO_SENSOR:
+                       arrived = false;
                        if(!train.go_to(get_sensor(row.get_param<unsigned>(0))))
                                set_enabled(false);
                        break;
                case GOTO_ZONE:
+                       arrived = false;
                        if(!train.go_to(get_zone(row.get_param<string>(0))))
                                set_enabled(false);
                        break;
@@ -121,10 +124,13 @@ void Timetable::tick(const Time::TimeStamp &t)
                        executing = false;
                        break;
                case ARRIVE:
-                       executing = false;
+                       if(!arrived)
+                               executing = false;
+                       arrived = false;
                        break;
                case SPEED:
-                       train.set_control("speed", row.get_param<unsigned>(0)/3.6*train.get_layout().get_catalogue().get_scale());
+                       if(!arrived)
+                               train.set_control("speed", row.get_param<unsigned>(0)/3.6*train.get_layout().get_catalogue().get_scale());
                        break;
                case REVERSE:
                        train.set_control("reverse", !train.get_control("reverse"));
@@ -179,6 +185,8 @@ void Timetable::train_arrived()
                current_row = (current_row+1)%rows.size();
                executing = true;
        }
+       else
+               arrived = true;
 }
 
 
@@ -210,7 +218,7 @@ string Timetable::Row::str() const
        case GOTO_ZONE:
                return "set route to "+get_param<string>(0);
        case TRAVEL:
-               return "travel to "+get_param<string>(0);
+               return format("travel to sensor %d", get_param<unsigned>(0));
        case WAIT_TIME:
                return format("wait for %d seconds", get_param<unsigned>(0));
        case WAIT_UNTIL:
@@ -239,7 +247,7 @@ DataFile::Statement Timetable::Row::save() const
        case GOTO_ZONE:
                return DataFile::Statement("goto_zone"), get_param<string>(0);
        case TRAVEL:
-               return DataFile::Statement("travel"), get_param<string>(0);
+               return DataFile::Statement("travel"), get_param<unsigned>(0);
        case WAIT_TIME:
                return DataFile::Statement("wait"), get_param<unsigned>(0);
        case WAIT_UNTIL:
@@ -388,9 +396,9 @@ void Timetable::Loader::speed(unsigned s)
        obj.rows.push_back(Row(SPEED, s));
 }
 
-void Timetable::Loader::travel(const string &t)
+void Timetable::Loader::travel(unsigned s)
 {
-       obj.rows.push_back(Row(TRAVEL, t));
+       obj.rows.push_back(Row(TRAVEL, s));
 }
 
 void Timetable::Loader::wait(unsigned t)
index ea3ff0b45e78aa79fd91bced272ec0498d73cbe6..8f64ad1c1f1ec828c81f4a7691aff1cf40b6bbee 100644 (file)
@@ -36,7 +36,7 @@ public:
                void route(const std::string &);
                void reverse();
                void speed(unsigned);
-               void travel(const std::string &);
+               void travel(unsigned);
                void wait(unsigned);
                void wait_train(unsigned, unsigned);
                void wait_until(unsigned, unsigned);
@@ -85,6 +85,7 @@ private:
        Block *pending_block;
        Train *pending_train;
        Msp::Time::TimeStamp wait_timeout;
+       bool arrived;
 
 public:
        Timetable(Train &);