(svn r26646) -Fix [FS#6041]: Save locations instead of distances in link graphs to reduce size.

This commit is contained in:
fonsinchen
2014-06-14 13:35:39 +00:00
parent e8e5cdde03
commit 957f5ca117
7 changed files with 71 additions and 52 deletions

View File

@@ -21,11 +21,13 @@ INSTANTIATE_POOL_METHODS(LinkGraph)
/**
* Create a node or clear it.
* @param xy Location of the associated station.
* @param st ID of the associated station.
* @param demand Demand for cargo at the station.
*/
inline void LinkGraph::BaseNode::Init(StationID st, uint demand)
inline void LinkGraph::BaseNode::Init(TileIndex xy, StationID st, uint demand)
{
this->xy = xy;
this->supply = 0;
this->demand = demand;
this->station = st;
@@ -34,11 +36,9 @@ inline void LinkGraph::BaseNode::Init(StationID st, uint demand)
/**
* Create an edge.
* @param distance Length of the link as manhattan distance.
*/
inline void LinkGraph::BaseEdge::Init(uint distance)
inline void LinkGraph::BaseEdge::Init()
{
this->distance = distance;
this->capacity = 0;
this->usage = 0;
this->last_unrestricted_update = INVALID_DATE;
@@ -146,21 +146,6 @@ void LinkGraph::RemoveNode(NodeID id)
* been copied around in the loop above. */
}
/**
* Update distances between the given node and all others.
* @param id Node that changed position.
* @param xy New position of the node.
*/
void LinkGraph::UpdateDistances(NodeID id, TileIndex xy)
{
assert(id < this->Size());
for (NodeID other = 0; other < this->Size(); ++other) {
if (other == id) continue;
this->edges[id][other].distance = this->edges[other][id].distance =
DistanceMaxPlusManhattan(xy, Station::Get(this->nodes[other].station)->xy);
}
}
/**
* Add a node to the component and create empty edges associated with it. Set
* the station's last_component to this component. Calculate the distances to all
@@ -180,7 +165,7 @@ NodeID LinkGraph::AddNode(const Station *st)
this->edges.Resize(new_node + 1U,
max(new_node + 1U, this->edges.Height()));
this->nodes[new_node].Init(st->index,
this->nodes[new_node].Init(st->xy, st->index,
HasBit(good.status, GoodsEntry::GES_ACCEPTANCE));
BaseEdge *new_edges = this->edges[new_node];
@@ -189,9 +174,8 @@ NodeID LinkGraph::AddNode(const Station *st)
new_edges[new_node].next_edge = INVALID_NODE;
for (NodeID i = 0; i <= new_node; ++i) {
uint distance = DistanceMaxPlusManhattan(st->xy, Station::Get(this->nodes[i].station)->xy);
new_edges[i].Init(distance);
this->edges[i][new_node].Init(distance);
new_edges[i].Init();
this->edges[i][new_node].Init();
}
return new_node;
}