]> git.tdb.fi Git - r2c2.git/commitdiff
Fix logic with signals and train direction check
authorMikko Rasa <tdb@tdb.fi>
Sat, 27 Apr 2013 10:05:55 +0000 (13:05 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 27 Apr 2013 10:05:55 +0000 (13:05 +0300)
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
source/libr2c2/signal.h

index 6efc250256477a7115cae0cff3962da7667be158..a8b0be029799afdcec0c5c379b2788e31919583d 100644 (file)
@@ -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<unsigned>(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<unsigned>(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;
 }
 
index c7bb0efbd4fd353f40e5c3306533641219823634..dcaa17a3cd997dba36a5cdedc03badae601cc8df 100644 (file)
@@ -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;