arriving(0),
destination(0),
destination_changed(false),
- metrics_stale(false)
+ metrics_stale(false),
+ current_sequence(0),
+ sequence_check_pending(false)
{
train.get_layout().signal_block_reserved.connect(sigc::mem_fun(this, &TrainRouter::block_reserved));
train.signal_advanced.connect(sigc::mem_fun(this, &TrainRouter::train_advanced));
destination = 0;
waypoints.clear();
sequence_points.clear();
- pending_sequence_checks.clear();
current_sequence = 0;
+ sequence_check_pending = false;
route_changed();
routes.push_back(create_lead_route(0, planned_routes.front()));
routes.insert(routes.end(), planned_routes.begin(), planned_routes.end());
sequence_points = planner->get_sequence_for(train);
- pending_sequence_checks.clear();
current_sequence = 0;
+ sequence_check_pending = false;
route_changed();
}
}
}
- for(list<SequencePoint *>::iterator i=pending_sequence_checks.begin(); i!=pending_sequence_checks.end(); ++i)
- if((*i)->preceding_train->get_ai_of_type<TrainRouter>()->get_current_sequence()>=(*i)->sequence_in)
- {
- (*i)->preceding_train = 0;
- if(*i==&sequence_points.front())
- train.stop_at(0);
- }
- pending_sequence_checks.clear();
+ if(sequence_check_pending)
+ {
+ if(sequence_points.front().is_cleared())
+ train.stop_at(0);
+ sequence_check_pending = false;
+ }
if(arriving==1 && !train.get_speed())
{
if(!t)
return;
- TrainRouter *other_router = 0;
- for(list<SequencePoint>::iterator i=sequence_points.begin(); i!=sequence_points.end(); ++i)
- if(i->block==&block && i->preceding_train==t)
- {
- if(!other_router)
- other_router = t->get_ai_of_type<TrainRouter>();
- if(other_router->get_current_sequence()>=i->sequence_in)
- {
- i->preceding_train = 0;
- if(i==sequence_points.begin())
- train.stop_at(0);
- }
- else
- pending_sequence_checks.push_back(&*i);
- }
+ SequencePoint &sp = sequence_points.front();
+ if(sp.preceding_train==t && sp.block==&block)
+ {
+ if(sp.is_cleared())
+ train.stop_at(0);
+ else
+ sequence_check_pending = true;
+ }
return;
}
if(!sequence_points.empty())
{
SequencePoint &sp = sequence_points.front();
- if(sp.preceding_train && sp.block==b_iter_next.block())
+ if(sp.block==b_iter_next.block() && !sp.is_cleared())
train.stop_at(&block);
}
}
sequence_out(o)
{ }
+bool TrainRouter::SequencePoint::is_cleared() const
+{
+ if(!preceding_train)
+ return true;
+
+ TrainRouter *router = preceding_train->get_ai_of_type<TrainRouter>();
+ return router->get_current_sequence()>=sequence_in;
+}
+
TrainRouter::Loader::Loader(TrainRouter &r):
DataFile::ObjectLoader<TrainRouter>(r)
unsigned sequence_out;
SequencePoint(Block &, unsigned);
+
+ bool is_cleared() const;
};
private:
std::vector<TrainRouteMetric *> metrics;
bool metrics_stale;
std::list<SequencePoint> sequence_points;
- std::list<SequencePoint *> pending_sequence_checks;
unsigned current_sequence;
+ bool sequence_check_pending;
Msp::Time::TimeDelta delay;
Msp::RefPtr<TrainRoutePlanner> planner;