summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/train.h32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/train.h b/src/train.h
index d7b583ee3..ff5b82927 100644
--- a/src/train.h
+++ b/src/train.h
@@ -56,25 +56,33 @@ bool TryPathReserve(Train *v, bool mark_as_stuck = false, bool first_tile_okay =
int GetTrainStopLocation(StationID station_id, TileIndex tile, const Train *v, int *station_ahead, int *station_length);
+/**
+ * Cached acceleration values.
+ * All of these values except cached_slope_resistance are set only for the first part of a vehicle.
+ */
+struct AccelerationCache {
+ /* cached values, recalculated when the cargo on a train changes (in addition to the conditions above) */
+ uint32 cached_weight; ///< total weight of the consist.
+ uint32 cached_slope_resistance; ///< Resistance caused by weight when this vehicle part is at a slope
+ uint32 cached_max_te; ///< max tractive effort of consist
+
+ /* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
+ uint32 cached_power; ///< total power of the consist.
+ uint32 cached_air_drag; ///< Air drag coefficient of the vehicle
+ uint16 cached_axle_resistance; ///< Resistance caused by the axles of the vehicle
+};
+
/** Variables that are cached to improve performance and such */
-struct TrainCache {
+struct TrainCache : public AccelerationCache {
/* Cached wagon override spritegroup */
const struct SpriteGroup *cached_override;
uint16 last_speed; // NOSAVE: only used in UI
/* cached values, recalculated on load and each time a vehicle is added to/removed from the consist. */
- uint32 cached_power; ///< total power of the consist.
- uint16 cached_axle_resistance; ///< Resistance caused by the axles of the vehicle
- uint32 cached_air_drag; ///< Air drag coefficient of the vehicle
- uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
- uint8 cached_veh_length; ///< length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
- bool cached_tilt; ///< train can tilt; feature provides a bonus in curves
-
- /* cached values, recalculated when the cargo on a train changes (in addition to the conditions above) */
- uint32 cached_weight; ///< total weight of the consist.
- uint32 cached_slope_resistance; ///< Resistance caused by weight when this vehicle part is at a slope
- uint32 cached_max_te; ///< max tractive effort of consist
+ uint16 cached_total_length; ///< Length of the whole train, valid only for first engine.
+ uint8 cached_veh_length; ///< length of this vehicle in units of 1/8 of normal length, cached because this can be set by a callback
+ bool cached_tilt; ///< train can tilt; feature provides a bonus in curves
/* cached max. speed / acceleration data */
uint16 cached_max_speed; ///< max speed of the consist. (minimum of the max speed of all vehicles in the consist)