]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/trainrouteplanner.cpp
Don't bother with creating intermediate steps for state updates
[r2c2.git] / source / libr2c2 / trainrouteplanner.cpp
index 75d746b3c6dd103cd148ae233f90361a189c2328..4186f471c43afcc7322071d53402aa690b7350c7 100644 (file)
@@ -375,7 +375,7 @@ bool TrainRoutePlanner::TrainRoutingState::check_arrival()
                        }
                }
 
-       if(info->first_noncritical->has_track(*track))
+       if(info->first_noncritical->has_track(*next_track))
                critical = false;
 
        return false;
@@ -490,14 +490,8 @@ TrainRoutePlanner::RoutingStep::RoutingStep(const RoutingStep *p):
 void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_steps) const
 {
        RoutingStep next(this);
-       if(next.update_states())
-       {
-               if(next.check_deadlocks())
-                       return;
-
-               new_steps.push_back(next);
+       if(next.update_states() && next.check_deadlocks())
                return;
-       }
 
        int train_index = find_next_train();
        if(train_index<0)
@@ -519,23 +513,14 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
        const TrackType::Endpoint &entry_ep = train.track.endpoint();
        if(train.critical)
        {
-               train.path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path());
-               train.update_estimate();
-               next.update_estimate();
-               if(next.is_viable())
-                       new_steps.push_back(next);
+               unsigned critical_path = train.track->get_type().coerce_path(train.track.entry(), train.track->get_active_path());
+               create_successor(next, train_index, critical_path, new_steps);
        }
        else
        {
                for(unsigned i=0; entry_ep.paths>>i; ++i)
                        if(entry_ep.has_path(i))
-                       {
-                               train.path = i;
-                               train.update_estimate();
-                               next.update_estimate();
-                               if(next.is_viable())
-                                       new_steps.push_back(next);
-                       }
+                               create_successor(next, train_index, i, new_steps);
        }
 
        new_steps.sort();
@@ -557,6 +542,17 @@ void TrainRoutePlanner::RoutingStep::create_successors(list<RoutingStep> &new_st
        }
 }
 
+void TrainRoutePlanner::RoutingStep::create_successor(RoutingStep &next, unsigned train_index, unsigned path, list<RoutingStep> &new_steps)
+{
+       TrainRoutingState &train = next.trains[train_index];
+
+       train.path = path;
+       train.update_estimate();
+       next.update_estimate();
+       if(next.is_viable())
+               new_steps.push_back(next);
+}
+
 bool TrainRoutePlanner::RoutingStep::update_states()
 {
        bool changes = false;