diff options
author | rubidium <rubidium@openttd.org> | 2009-10-06 21:24:03 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-10-06 21:24:03 +0000 |
commit | 9b045ac7b2dc4749b3eb511f4a8ec2dc53ba324a (patch) | |
tree | 32cb8acf08397b2e6ffa7dec1b1ba900944f3cc0 /src/cargopacket.cpp | |
parent | 80f0df17ba7d52900d3cb434d4feb65c83c4b772 (diff) | |
download | openttd-9b045ac7b2dc4749b3eb511f4a8ec2dc53ba324a.tar.xz |
(svn r17733) -Codechange: store the 'days in transit' cache as the sum of the days in transit instead of the average; the variable isn't requested that often (primarily station NewGRFs) that the dividing/testing for dividing by 0 step needs to be cached.
Diffstat (limited to 'src/cargopacket.cpp')
-rw-r--r-- | src/cargopacket.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index b84dc46ec..e5a636bb4 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -78,14 +78,13 @@ CargoList::~CargoList() void CargoList::AgeCargo() { - if (this->Empty()) return; - - uint dit = 0; for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) { - if ((*it)->days_in_transit != 0xFF) (*it)->days_in_transit++; - dit += (*it)->days_in_transit * (*it)->count; + /* If we're at the maximum, then we can't increase no more. */ + if ((*it)->days_in_transit == 0xFF) continue; + + (*it)->days_in_transit++; + this->cargo_days_in_transit += (*it)->count; } - this->days_in_transit = dit / count; } void CargoList::Append(CargoPacket *cp) @@ -216,15 +215,11 @@ void CargoList::InvalidateCache() { this->count = 0; this->feeder_share = 0; - this->days_in_transit = 0; - - if (this->packets.empty()) return; + this->cargo_days_in_transit = 0; - uint dit = 0; for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) { - this->count += (*it)->count; - dit += (*it)->days_in_transit * (*it)->count; - this->feeder_share += (*it)->feeder_share; + this->count += (*it)->count; + this->cargo_days_in_transit += (*it)->days_in_transit * (*it)->count; + this->feeder_share += (*it)->feeder_share; } - this->days_in_transit = dit / count; } |