From 176634834df3ac62646d1aec78e35f9364750d7d Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 27 Apr 2013 13:05:55 +0300 Subject: [PATCH] Fix logic with signals and train direction check The train pointer wasn't being cleared in case of wrong direction. Since commit 4086edb it's possible to implement the logic in a more efficient way too. --- source/libr2c2/signal.cpp | 28 ++++++++++------------------ source/libr2c2/signal.h | 1 - 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 6efc250..a8b0be0 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -20,7 +20,6 @@ Signal::Signal(Layout &l, const SignalType &t): block(0), entry(0), train(0), - check_train_direction(false), check_allocated_blocks(false), passing(false) { @@ -102,19 +101,6 @@ void Signal::set_direction(float d) void Signal::tick(const Time::TimeDelta &) { - if(check_train_direction) - { - int train_entry = train->get_entry_to_block(*block); - if(train_entry>=0 && static_cast(train_entry)==entry) - { - if(train_conn) - train_conn.disconnect(); - train_conn = train->signal_advanced.connect(sigc::mem_fun(this, &Signal::train_advanced)); - } - check_train_direction = false; - check_allocated_blocks = true; - } - if(check_allocated_blocks) { unsigned n_blocks = 0; @@ -147,9 +133,16 @@ void Signal::block_reserved(const Block &b, Train *t) { if(t) { - train = t; - passing = false; - check_train_direction = true; + int train_entry = t->get_entry_to_block(*block); + if(train_entry>=0 && static_cast(train_entry)==entry) + { + if(train_conn) + train_conn.disconnect(); + train = t; + passing = false; + train_conn = train->signal_advanced.connect(sigc::mem_fun(this, &Signal::train_advanced)); + check_allocated_blocks = true; + } } else { @@ -177,7 +170,6 @@ void Signal::reset() train = 0; if(train_conn) train_conn.disconnect(); - check_train_direction = false; check_allocated_blocks = false; } diff --git a/source/libr2c2/signal.h b/source/libr2c2/signal.h index c7bb0ef..dcaa17a 100644 --- a/source/libr2c2/signal.h +++ b/source/libr2c2/signal.h @@ -37,7 +37,6 @@ private: Block *block; unsigned entry; Train *train; - bool check_train_direction; sigc::connection train_conn; bool check_allocated_blocks; bool passing; -- 2.43.0