From: Mikko Rasa Date: Fri, 26 Nov 2010 14:09:55 +0000 (+0000) Subject: Add an absolute wait command to Timetable X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9a4aeac8f8278eea6cbd67addfb76ace8c937e3c;p=r2c2.git Add an absolute wait command to Timetable --- diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index dd91d21..c28cbcc 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -106,6 +106,15 @@ void Timetable::tick(const Time::TimeStamp &t) wait_timeout = t+row.get_param(0)*Time::sec; executing = false; break; + case WAIT_UNTIL: + { + unsigned unixtime = t.to_unixtime(); + unsigned mod = row.get_param(1); + unsigned secs = ((mod+row.get_param(0))-(unixtime%mod))%mod; + wait_timeout = t+secs*Time::sec; + executing = false; + } + break; case WAIT_TRAIN: pending_train = &train.get_layout().get_train(row.get_param(0)); pending_block = &get_sensor(row.get_param(1)).get_block(); @@ -204,6 +213,8 @@ string Timetable::Row::str() const return "travel to "+get_param(0); case WAIT_TIME: return format("wait for %d seconds", get_param(0)); + case WAIT_UNTIL: + return format("wait until %d mod %d seconds", get_param(0), get_param(1)); case WAIT_TRAIN: return format("wait for train %d at %s", get_param(0), get_param(1)); case ARRIVE: @@ -231,6 +242,8 @@ DataFile::Statement Timetable::Row::save() const return DataFile::Statement("travel"), get_param(0); case WAIT_TIME: return DataFile::Statement("wait"), get_param(0); + case WAIT_UNTIL: + return DataFile::Statement("wait_until"), get_param(0), get_param(1); case WAIT_TRAIN: return DataFile::Statement("wait_train"), get_param(0), get_param(1); case ARRIVE: @@ -275,6 +288,27 @@ Timetable::Row Timetable::Row::parse(const string &s) } } } + else if(!s.compare(0, 11, "wait until ")) + { + string::size_type mod = s.find(" mod ", 11); + unsigned nondigit = (mod!=string::npos ? mod+5 : 11); + while(nondigit(s.substr(11, mod-11)); + Row row(WAIT_UNTIL, time); + row.params.push_back(lexical_cast(s.substr(mod+5, nondigit-mod-5))); + return row; + } + else + { + unsigned time = lexical_cast(s.substr(11, nondigit-11)); + Row row(WAIT_UNTIL, time); + row.params.push_back(3600); + return row; + } + } else if(!s.compare(0, 10, "set speed ")) { unsigned nondigit = 11; @@ -312,6 +346,7 @@ Timetable::Loader::Loader(Timetable &tt): add("travel", &Loader::travel); add("wait", &Loader::wait); add("wait_train", &Loader::wait_train); + add("wait_until", &Loader::wait_until); // Deprecated alias add("goto", static_cast(&Loader::goto_sensor)); @@ -370,4 +405,11 @@ void Timetable::Loader::wait_train(unsigned t, unsigned s) obj.rows.push_back(row); } +void Timetable::Loader::wait_until(unsigned t, unsigned m) +{ + Row row(WAIT_UNTIL, t); + row.params.push_back(m); + obj.rows.push_back(row); +} + } // namespace R2C2 diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 86b4ae2..ea3ff0b 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -39,6 +39,7 @@ public: void travel(const std::string &); void wait(unsigned); void wait_train(unsigned, unsigned); + void wait_until(unsigned, unsigned); }; enum RowType @@ -47,6 +48,7 @@ public: GOTO_ZONE, TRAVEL, WAIT_TIME, + WAIT_UNTIL, WAIT_TRAIN, ARRIVE, SPEED,