]> git.tdb.fi Git - r2c2.git/commitdiff
Move duplicated successor step creation code to a function
authorMikko Rasa <tdb@tdb.fi>
Fri, 20 Feb 2015 16:11:41 +0000 (18:11 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 20 Feb 2015 16:11:41 +0000 (18:11 +0200)
source/libr2c2/trainrouteplanner.cpp
source/libr2c2/trainrouteplanner.h

index 75d746b3c6dd103cd148ae233f90361a189c2328..b6d2f07cb66203ded55f3471110f94a0270287c0 100644 (file)
@@ -519,23 +519,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 +548,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;
index e3d3770c52a113bf8f4bcb6c813bb381fc899fba..3076c3978efa5ed0b27edae5cec7b4130e72afa7 100644 (file)
@@ -109,6 +109,7 @@ private:
                RoutingStep(const RoutingStep *);
 
                void create_successors(std::list<RoutingStep> &) const;
+               static void create_successor(RoutingStep &, unsigned, unsigned, std::list<RoutingStep> &);
                bool update_states();
                bool check_deadlocks() const;
                int get_occupant(Track &) const;