summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2016-07-10 12:17:00 +0000
committerfonsinchen <fonsinchen@openttd.org>2016-07-10 12:17:00 +0000
commitf769305d7d102d022f9a5139336a52c34ca24103 (patch)
tree59c7ee1662ec7384ce5d603b9689f82ea179dc5b /src
parent022b284064d4ddeb7c2faeda98f791d47dab4353 (diff)
downloadopenttd-f769305d7d102d022f9a5139336a52c34ca24103.tar.xz
(svn r27614) -Codechange: Use a fixed array instead of a map for link refresher cargo capacities. (JGR)
Diffstat (limited to 'src')
-rw-r--r--src/linkgraph/refresh.cpp19
-rw-r--r--src/linkgraph/refresh.h3
2 files changed, 13 insertions, 9 deletions
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp
index 02f27f40c..501f06352 100644
--- a/src/linkgraph/refresh.cpp
+++ b/src/linkgraph/refresh.cpp
@@ -72,10 +72,15 @@ LinkRefresher::LinkRefresher(Vehicle *vehicle, HopSet *seen_hops, bool allow_mer
vehicle(vehicle), seen_hops(seen_hops), cargo(CT_INVALID), allow_merge(allow_merge),
is_full_loading(is_full_loading)
{
+ memset(this->capacities, 0, sizeof(this->capacities));
+
/* Assemble list of capacities and set last loading stations to 0. */
for (Vehicle *v = this->vehicle; v != NULL; v = v->Next()) {
this->refit_capacities.push_back(RefitDesc(v->cargo_type, v->cargo_cap, v->refit_cap));
- if (v->refit_cap > 0) this->capacities[v->cargo_type] += v->refit_cap;
+ if (v->refit_cap > 0) {
+ assert(v->cargo_type < NUM_CARGO);
+ this->capacities[v->cargo_type] += v->refit_cap;
+ }
}
}
@@ -200,11 +205,11 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
StationID next_station = next->GetDestination();
Station *st = Station::GetIfValid(cur->GetDestination());
if (st != NULL && next_station != INVALID_STATION && next_station != st->index) {
- for (CapacitiesMap::const_iterator i = this->capacities.begin(); i != this->capacities.end(); ++i) {
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
/* Refresh the link and give it a minimum capacity. */
- if (i->second == 0) continue;
- CargoID c = i->first;
+ uint cargo_quantity = this->capacities[c];
+ if (cargo_quantity == 0) continue;
/* If not allowed to merge link graphs, make sure the stations are
* already in the same link graph. */
@@ -225,7 +230,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
st->index == vehicle->last_station_visited &&
this->vehicle->orders.list->GetTotalDuration() >
(Ticks)this->vehicle->current_order_time) {
- uint effective_capacity = i->second * this->vehicle->load_unload_ticks;
+ uint effective_capacity = cargo_quantity * this->vehicle->load_unload_ticks;
if (effective_capacity > (uint)this->vehicle->orders.list->GetTotalDuration()) {
IncreaseStats(st, c, next_station, effective_capacity /
this->vehicle->orders.list->GetTotalDuration(), 0,
@@ -233,10 +238,10 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next)
} else if (RandomRange(this->vehicle->orders.list->GetTotalDuration()) < effective_capacity) {
IncreaseStats(st, c, next_station, 1, 0, EUM_INCREASE | restricted_mode);
} else {
- IncreaseStats(st, c, next_station, i->second, 0, EUM_REFRESH | restricted_mode);
+ IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
}
} else {
- IncreaseStats(st, c, next_station, i->second, 0, EUM_REFRESH | restricted_mode);
+ IncreaseStats(st, c, next_station, cargo_quantity, 0, EUM_REFRESH | restricted_mode);
}
}
}
diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h
index 6687b8a3b..42067ebcf 100644
--- a/src/linkgraph/refresh.h
+++ b/src/linkgraph/refresh.h
@@ -80,11 +80,10 @@ protected:
};
typedef std::vector<RefitDesc> RefitList;
- typedef std::map<CargoID, uint> CapacitiesMap;
typedef std::set<Hop> HopSet;
Vehicle *vehicle; ///< Vehicle for which the links should be refreshed.
- CapacitiesMap capacities; ///< Current added capacities per cargo ID in the consist.
+ uint capacities[NUM_CARGO]; ///< Current added capacities per cargo ID in the consist.
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.