summaryrefslogtreecommitdiff
path: root/src/linkgraph/linkgraph.cpp
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-06-14 13:35:39 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-06-14 13:35:39 +0000
commit957f5ca11758d556763881d04ced39cd34c470c1 (patch)
tree03a1c5061a2d4466526f39b637a0967333a5591f /src/linkgraph/linkgraph.cpp
parente8e5cdde034dcf5c3874790b5a9cd67ad300ee9d (diff)
downloadopenttd-957f5ca11758d556763881d04ced39cd34c470c1.tar.xz
(svn r26646) -Fix [FS#6041]: Save locations instead of distances in link graphs to reduce size.
Diffstat (limited to 'src/linkgraph/linkgraph.cpp')
-rw-r--r--src/linkgraph/linkgraph.cpp30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp
index 01b3d1ee2..50945d361 100644
--- a/src/linkgraph/linkgraph.cpp
+++ b/src/linkgraph/linkgraph.cpp
@@ -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;
@@ -147,21 +147,6 @@ void LinkGraph::RemoveNode(NodeID id)
}
/**
- * 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
* other nodes. The distances to _all_ nodes are important as the demand
@@ -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;
}