Changeset - r20902:793defaf2fb1
[Not reviewed]
master
0 3 0
fonsinchen - 11 years ago 2013-11-07 20:50:03
fonsinchen@openttd.org
(svn r25948) -Fix [FS#5796]: Make sure LinkRefresher doesn't delete the LinkGraph DeleteStaleLinks() is examining.
3 files changed with 22 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/linkgraph/refresh.cpp
Show inline comments
 
@@ -20,8 +20,9 @@
 
/**
 
 * Refresh all links the given vehicle will visit.
 
 * @param v Vehicle to refresh links for.
 
 * @param allow_merge If the refresher is allowed to merge or extend link graphs.
 
 */
 
/* static */ void LinkRefresher::Run(Vehicle *v)
 
/* static */ void LinkRefresher::Run(Vehicle *v, bool allow_merge)
 
{
 
	/* If there are no orders we can't predict anything.*/
 
	if (v->orders.list == NULL) return;
 
@@ -31,7 +32,7 @@
 
	if (first == NULL) return;
 

	
 
	HopSet seen_hops;
 
	LinkRefresher refresher(v, &seen_hops);
 
	LinkRefresher refresher(v, &seen_hops, allow_merge);
 

	
 
	refresher.RefreshLinks(first, first, v->last_loading_station != INVALID_STATION ? 1 << HAS_CARGO : 0);
 
}
 
@@ -59,9 +60,12 @@ bool LinkRefresher::Hop::operator<(const
 
/**
 
 * Constructor for link refreshing algorithm.
 
 * @param vehicle Vehicle to refresh links for.
 
 * @param seen_hops Set of hops already seen. This is shared between this
 
 *                  refresher and all its children.
 
 * @param allow_merge If the refresher is allowed to merge or extend link graphs.
 
 */
 
LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops) :
 
		vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID)
 
LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_merge) :
 
		vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge)
 
{
 
	/* Assemble list of capacities and set last loading stations to 0. */
 
	for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
 
@@ -190,10 +194,19 @@ void LinkRefresher::RefreshStats(const O
 
	if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
 
		for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) {
 
			/* Refresh the link and give it a minimum capacity. */
 

	
 
			if (i->second == 0) continue;
 
			CargoID c = i->first;
 

	
 
			/* If not allowed to merge link graphs, make sure the stations are
 
			 * already in the same link graph. */
 
			if (!this->allow_merge && st->goods[c].link_graph != Station::Get(next_station)->goods[c].link_graph) {
 
				continue;
 
			}
 

	
 
			/* A link is at least partly restricted if a
 
			 * vehicle can't load at its source. */
 
			IncreaseStats(st, i->first, next_station, i->second,
 
			IncreaseStats(st, c, next_station, i->second,
 
					(cur->GetLoadType() & OLFB_NO_LOAD) == 0 ? LinkGraph::REFRESH_UNRESTRICTED : LinkGraph::REFRESH_RESTRICTED);
 
		}
 
	}
src/linkgraph/refresh.h
Show inline comments
 
@@ -23,7 +23,7 @@
 
 */
 
class LinkRefresher {
 
public:
 
	static void Run(Vehicle *v);
 
	static void Run(Vehicle *v, bool allow_merge = true);
 

	
 
protected:
 
	/**
 
@@ -87,8 +87,9 @@ protected:
 
	RefitList refit_capacities; ///< Current state of capacity remaining from previous refits versus overall capacity per vehicle in the consist.
 
	HopSet *seen_hops;          ///< Hops already seen. If the same hop is seen twice we stop the algorithm. This is shared between all Refreshers of the same run.
 
	CargoID cargo;              ///< Cargo given in last refit order.
 
	bool allow_merge;           ///< If the refresher is allowed to merge or extend link graphs.
 

	
 
	LinkRefresher(Vehicle *v, HopSet *seen_hops);
 
	LinkRefresher(Vehicle *v, HopSet *seen_hops, bool allow_merge);
 

	
 
	void HandleRefit(const Order *next);
 
	void ResetRefit();
src/station_cmd.cpp
Show inline comments
 
@@ -3447,7 +3447,7 @@ void DeleteStaleLinks(Station *from)
 
						 * - We could try to figure out if we've seen a consist with the same cargo on the
 
						 *   same list already and if the consist can actually carry the cargo we're looking
 
						 *   for. With conditional and refit orders this is not quite trivial, though. */
 
						LinkRefresher::Run(v);
 
						LinkRefresher::Run(v, false); // Don't allow merging. Otherwise lg might get deleted.
 
						if (edge.LastUpdate() == _date) updated = true;
 
					}
 
					if (updated) break;
0 comments (0 inline, 0 general)