diff options
author | Nicolas Chappe <74881848+nchappe@users.noreply.github.com> | 2021-08-17 21:14:29 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-08-18 01:48:11 +0200 |
commit | de28817d9f345fadccc12d3038b11e8ff936ff3d (patch) | |
tree | 0cd385faeecd21fe54e5581f1767000e833197e7 /src/linkgraph/linkgraph.cpp | |
parent | 325d031082dc80b8246859d92ac848ace5a7d413 (diff) | |
download | openttd-de28817d9f345fadccc12d3038b11e8ff936ff3d.tar.xz |
Fix 977604ef: [Linkgraph] Add a special case for unknown travel times on link update
Diffstat (limited to 'src/linkgraph/linkgraph.cpp')
-rw-r--r-- | src/linkgraph/linkgraph.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp index 4c300b0d5..2efbe19d1 100644 --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -74,6 +74,8 @@ void LinkGraph::Compress() if (edge.capacity > 0) { edge.capacity = std::max(1U, edge.capacity / 2); edge.usage /= 2; + } + if (edge.travel_time_sum > 0) { edge.travel_time_sum = std::max(1ULL, edge.travel_time_sum / 2); } } @@ -279,14 +281,12 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, uint32 travel_time, Edge this->edge.capacity += capacity; this->edge.usage += usage; } else if (mode & EUM_REFRESH) { - /* If travel time is not provided, we scale the stored time based on - * the capacity increase. */ - if (capacity > this->edge.capacity && travel_time == 0) { + if (this->edge.travel_time_sum == 0) { + this->edge.capacity = std::max(this->edge.capacity, capacity); + this->edge.travel_time_sum = travel_time * this->edge.capacity; + } else if (capacity > this->edge.capacity) { this->edge.travel_time_sum = this->edge.travel_time_sum / this->edge.capacity * capacity; this->edge.capacity = capacity; - } else { - this->edge.capacity = std::max(this->edge.capacity, capacity); - this->edge.travel_time_sum = std::max<uint64>(this->edge.travel_time_sum, travel_time * capacity); } this->edge.usage = std::max(this->edge.usage, usage); } |