From 942be2d4b6e5330101c2618f13b2693b9c71d56e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 15 Apr 2011 20:14:31 +0000 Subject: [PATCH] Fix some stuff in Timetable --- source/libr2c2/timetable.cpp | 45 ++++++++++++++++++++++++++++-------- source/libr2c2/timetable.h | 4 ++-- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index c2a86a6..dcdbb00 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -31,7 +31,7 @@ Timetable::Timetable(Train &t): train.signal_advanced.connect(sigc::mem_fun(this, &Timetable::train_advanced)); train.signal_arrived.connect(sigc::mem_fun(this, &Timetable::train_arrived)); Layout &layout = train.get_layout(); - layout.get_driver().signal_sensor.connect(sigc::mem_fun(this, &Timetable::sensor_event)); + layout.signal_block_state_changed.connect(sigc::mem_fun(this, &Timetable::block_state_changed)); layout.signal_block_reserved.connect(sigc::mem_fun(this, &Timetable::block_reserved)); } @@ -104,9 +104,15 @@ void Timetable::tick(const Time::TimeStamp &t, const Time::TimeDelta &) set_enabled(false); break; case TRAVEL_TO: - pending_block = &get_sensor(row.get_param(0)).get_block(); - pending_train = &train; - executing = false; + { + Block *block = &get_sensor(row.get_param(0)).get_block(); + if(block->get_train()!=&train || block->get_state()(0)).get_block(); @@ -127,9 +133,16 @@ void Timetable::tick(const Time::TimeStamp &t, const Time::TimeDelta &) } 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(); - executing = false; + { + Train *other_train = &train.get_layout().get_train(row.get_param(0)); + Block *block = &get_sensor(row.get_param(1)).get_block(); + if(block->get_train()!=other_train || block->get_state()get_train()==pending_train && addr==pending_block->get_sensor_id() && state) + if(rows.empty() || !enabled) + return; + + if(&block==pending_block && block.get_train()==pending_train && state>=Block::MAYBE_ACTIVE) { pending_block = 0; current_row = (current_row+1)%rows.size(); @@ -198,6 +214,9 @@ void Timetable::sensor_event(unsigned addr, bool state) void Timetable::block_reserved(Block &block, Train *trn) { + if(rows.empty() || !enabled) + return; + if(&block==pending_block && trn==pending_train) { Row &row = rows[current_row]; @@ -212,6 +231,9 @@ void Timetable::block_reserved(Block &block, Train *trn) void Timetable::train_advanced(Block &block) { + if(rows.empty() || !enabled) + return; + Row &row = rows[current_row]; if(row.type==TRAVEL_PAST && &block==pending_block && pending_train) pending_train = 0; @@ -219,6 +241,9 @@ void Timetable::train_advanced(Block &block) void Timetable::train_arrived() { + if(rows.empty() || !enabled) + return; + Row &row = rows[current_row]; if(row.type==ARRIVE) { @@ -266,7 +291,7 @@ string Timetable::Row::str() const 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)); + return format("wait for train %d at sensor %d", get_param(0), get_param(1)); case ARRIVE: return "travel until arrival"; case SPEED: diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 1bf8f4f..b2f4fae 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -12,11 +12,11 @@ Distributed under the GPL #include #include #include +#include "block.h" #include "trainai.h" namespace R2C2 { -class Block; class Track; class Train; class Zone; @@ -108,7 +108,7 @@ private: Track &get_sensor(unsigned); Track &get_turnout(unsigned); Zone &get_zone(const std::string &); - void sensor_event(unsigned, bool); + void block_state_changed(Block &, Block::State); void block_reserved(Block &, Train *); void train_advanced(Block &); void train_arrived(); -- 2.45.2