From baa096deb2108fe7f692172602ec2d047b68c068 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 10 Feb 2011 21:50:09 +0000 Subject: [PATCH] Fix travel to sensor handling Handle situations where the train is already at the target location --- source/libr2c2/timetable.cpp | 22 +++++++++++++++------- source/libr2c2/timetable.h | 3 ++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index c28cbcc..8b469b5 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -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(0)))) set_enabled(false); break; case GOTO_ZONE: + arrived = false; if(!train.go_to(get_zone(row.get_param(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(0)/3.6*train.get_layout().get_catalogue().get_scale()); + if(!arrived) + train.set_control("speed", row.get_param(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(0); case TRAVEL: - return "travel to "+get_param(0); + return format("travel to sensor %d", get_param(0)); case WAIT_TIME: return format("wait for %d seconds", get_param(0)); case WAIT_UNTIL: @@ -239,7 +247,7 @@ DataFile::Statement Timetable::Row::save() const case GOTO_ZONE: return DataFile::Statement("goto_zone"), get_param(0); case TRAVEL: - return DataFile::Statement("travel"), get_param(0); + return DataFile::Statement("travel"), get_param(0); case WAIT_TIME: return DataFile::Statement("wait"), get_param(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) diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index ea3ff0b..8f64ad1 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -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 &); -- 2.45.2