summaryrefslogtreecommitdiff
path: root/src/cargopacket.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-10-19 01:12:51 +0000
committerrubidium <rubidium@openttd.org>2009-10-19 01:12:51 +0000
commit2cca30d2e308ca63eacdfcc9d45920c4b2f2a37c (patch)
treee3332fca3b4c2c4b4038a12480fe46b3b44c7a5a /src/cargopacket.h
parent40a32bb976a00d9f79b6368eda02461a74c74988 (diff)
downloadopenttd-2cca30d2e308ca63eacdfcc9d45920c4b2f2a37c.tar.xz
(svn r17812) -Codechange: move the feeder_share cache from CargoList to VehicleCargoList; saves 512 bytes per station and 1-2% on CargoList::MoveTo.
Diffstat (limited to 'src/cargopacket.h')
-rw-r--r--src/cargopacket.h46
1 files changed, 36 insertions, 10 deletions
diff --git a/src/cargopacket.h b/src/cargopacket.h
index 2d5c824e9..90081855e 100644
--- a/src/cargopacket.h
+++ b/src/cargopacket.h
@@ -197,7 +197,6 @@ public:
};
protected:
- 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
@@ -251,15 +250,6 @@ public:
}
/**
- * Returns total sum of the feeder share for all packets
- * @return the before mentioned number
- */
- FORCEINLINE Money FeederShare() const
- {
- return this->feeder_share;
- }
-
- /**
* Returns source of the first cargo packet in this list
* @return the before mentioned source
*/
@@ -326,15 +316,49 @@ public:
* CargoList that is used for vehicles.
*/
class VehicleCargoList : public CargoList<VehicleCargoList> {
+protected:
+ /** The (direct) parent of this class */
+ typedef CargoList<VehicleCargoList> Parent;
+
+ Money feeder_share; ///< Cache for the feeder share
+
+ /**
+ * Update the cache to reflect adding of this packet.
+ * Increases count, feeder share and days_in_transit
+ * @param cp a new packet to be inserted
+ */
+ void AddToCache(const CargoPacket *cp);
+
+ /**
+ * Update the cached values to reflect the removal of this packet.
+ * Decreases count, feeder share and days_in_transit
+ * @param cp Packet to be removed from cache
+ */
+ void RemoveFromCache(const CargoPacket *cp);
+
public:
+ /** The super class ought to know what it's doing */
+ friend class CargoList<VehicleCargoList>;
/** The vehicles have a cargo list (and we want that saved). */
friend const struct SaveLoad *GetVehicleDescription(VehicleType vt);
/**
+ * Returns total sum of the feeder share for all packets
+ * @return the before mentioned number
+ */
+ FORCEINLINE Money FeederShare() const
+ {
+ return this->feeder_share;
+ }
+
+ /**
* Ages the all cargo in this list
*/
void AgeCargo();
+ /** Invalidates the cached data and rebuild it */
+ void InvalidateCache();
+
/**
* Are two the two CargoPackets mergeable in the context of
* a list of CargoPackets for a Vehicle?
@@ -357,6 +381,8 @@ public:
*/
class StationCargoList : public CargoList<StationCargoList> {
public:
+ /** The super class ought to know what it's doing */
+ friend class CargoList<StationCargoList>;
/** The stations, via GoodsEntry, have a CargoList. */
friend const struct SaveLoad *GetGoodsDesc();