/** * Join the link graph job and destroy it. */ LinkGraphJob::~LinkGraphJob() { assert(this->thread == NULL); /* Link graph has been merged into another one. */ if (!LinkGraph::IsValidID(this->link_graph.index)) return; uint size = this->Size(); for (NodeID node_id = 0; node_id < size; ++node_id) { Node from = (*this)[node_id]; /* The station can have been deleted. */ Station *st = Station::GetIfValid(from.Station()); if (st == NULL) continue; /* Link graph merging and station deletion may change around IDs. Make * sure that everything is still consistent or ignore it otherwise. */ GoodsEntry &ge = st->goods[this->Cargo()]; if (ge.link_graph != this->link_graph.index || ge.node != node_id) continue; LinkGraph *lg = LinkGraph::Get(ge.link_graph); FlowStatMap &flows = from.Flows(); for (EdgeIterator it(from.Begin()); it != from.End(); ++it) { if (from[it->first].Flow() == 0) continue; StationID to = (*this)[it->first].Station(); Station *st2 = Station::GetIfValid(to); if (st2 == NULL || st2->goods[this->Cargo()].link_graph != this->link_graph.index || st2->goods[this->Cargo()].node != it->first || (*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) { /* Edge has been removed. Delete flows. */ flows.DeleteFlows(to); } } /* Swap shares and invalidate ones that are completely deleted. Don't * really delete them as we could then end up with unroutable cargo * somewhere. */ for (FlowStatMap::iterator it(ge.flows.begin()); it != ge.flows.end(); ++it) { FlowStatMap::iterator new_it = flows.find(it->first); if (new_it == flows.end()) { it->second.Invalidate(); } else { it->second.SwapShares(new_it->second); flows.erase(new_it); } } ge.flows.insert(flows.begin(), flows.end()); InvalidateWindowData(WC_STATION_VIEW, st->index, this->Cargo()); } }
/** * Join the link graph job and destroy it. */ LinkGraphJob::~LinkGraphJob() { assert(this->thread == NULL); /* Don't update stuff from other pools, when everything is being removed. * Accessing other pools may be invalid. */ if (CleaningPool()) return; /* Link graph has been merged into another one. */ if (!LinkGraph::IsValidID(this->link_graph.index)) return; uint size = this->Size(); for (NodeID node_id = 0; node_id < size; ++node_id) { Node from = (*this)[node_id]; /* The station can have been deleted. */ Station *st = Station::GetIfValid(from.Station()); if (st == NULL) continue; /* Link graph merging and station deletion may change around IDs. Make * sure that everything is still consistent or ignore it otherwise. */ GoodsEntry &ge = st->goods[this->Cargo()]; if (ge.link_graph != this->link_graph.index || ge.node != node_id) continue; LinkGraph *lg = LinkGraph::Get(ge.link_graph); FlowStatMap &flows = from.Flows(); for (EdgeIterator it(from.Begin()); it != from.End(); ++it) { if (from[it->first].Flow() == 0) continue; StationID to = (*this)[it->first].Station(); Station *st2 = Station::GetIfValid(to); if (st2 == NULL || st2->goods[this->Cargo()].link_graph != this->link_graph.index || st2->goods[this->Cargo()].node != it->first || (*lg)[node_id][it->first].LastUpdate() == INVALID_DATE) { /* Edge has been removed. Delete flows. */ StationIDStack erased = flows.DeleteFlows(to); /* Delete old flows for source stations which have been deleted * from the new flows. This avoids flow cycles between old and * new flows. */ while (!erased.IsEmpty()) ge.flows.erase(erased.Pop()); } else if ((*lg)[node_id][it->first].LastUnrestrictedUpdate() == INVALID_DATE) { /* Edge is fully restricted. */ flows.RestrictFlows(to); } } /* Swap shares and invalidate ones that are completely deleted. Don't * really delete them as we could then end up with unroutable cargo * somewhere. Do delete them if automatic distribution has been turned * off for that cargo, though. */ for (FlowStatMap::iterator it(ge.flows.begin()); it != ge.flows.end();) { FlowStatMap::iterator new_it = flows.find(it->first); if (new_it == flows.end()) { if (_settings_game.linkgraph.GetDistributionType(this->Cargo()) != DT_MANUAL) { it->second.Invalidate(); ++it; } else { ge.flows.erase(it++); } } else { it->second.SwapShares(new_it->second); flows.erase(new_it); ++it; } } ge.flows.insert(flows.begin(), flows.end()); InvalidateWindowData(WC_STATION_VIEW, st->index, this->Cargo()); } }