Changeset - r13216:2c9a757db2cc
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-10-06 21:24:03
rubidium@openttd.org
(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.
2 files changed with 14 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/cargopacket.cpp
Show inline comments
 
@@ -78,14 +78,13 @@ CargoList::~CargoList()
 

	
 
void CargoList::AgeCargo()
 
{
 
	if (this->Empty()) return;
 
	for (List::const_iterator it = this->packets.begin(); it != this->packets.end(); it++) {
 
		/* If we're at the maximum, then we can't increase no more. */
 
		if ((*it)->days_in_transit == 0xFF) continue;
 

	
 
	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;
 
		(*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;
 
	this->cargo_days_in_transit = 0;
 

	
 
	if (this->packets.empty()) return;
 

	
 
	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;
 
}
src/cargopacket.h
Show inline comments
 
@@ -161,11 +161,11 @@ public:
 
	};
 

	
 
private:
 
	Money feeder_share;   ///< Cache for the feeder share
 
	uint count;           ///< Cache for the number of cargo entities
 
	uint days_in_transit; ///< Cache for the number of days in transit
 
	Money feeder_share;         ///< Cache for the feeder share
 
	uint count;                 ///< Cache for the number of cargo entities
 
	uint cargo_days_in_transit; ///< Cache for the sum of number of days in transit of each entity; comparable to man-hours
 

	
 
	List packets;         ///< The cargo packets in this list
 
	List packets;               ///< The cargo packets in this list
 

	
 
public:
 
	/** The GoodsEntry has a CargoList. */
 
@@ -232,7 +232,7 @@ public:
 
	 */
 
	FORCEINLINE uint DaysInTransit() const
 
	{
 
		return this->days_in_transit;
 
		return this->count == 0 ? 0 : this->cargo_days_in_transit / this->count;
 
	}
 

	
 

	
0 comments (0 inline, 0 general)