summaryrefslogtreecommitdiff
path: root/src/ground_vehicle.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-26 17:31:07 +0000
committerrubidium <rubidium@openttd.org>2011-01-26 17:31:07 +0000
commitb11f1bd4ed68fc0d031429df2925b87ed6baceb3 (patch)
tree5bb149c0bafdbb9a3987237fa5f1d659f92268cf /src/ground_vehicle.hpp
parent12b64a12b06f93d81a433cb311dfd1228d155e98 (diff)
downloadopenttd-b11f1bd4ed68fc0d031429df2925b87ed6baceb3.tar.xz
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
Diffstat (limited to 'src/ground_vehicle.hpp')
-rw-r--r--src/ground_vehicle.hpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index 141f99731..0dcfbeaf8 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -13,7 +13,9 @@
#define GROUND_VEHICLE_HPP
#include "vehicle_base.h"
+#include "vehicle_gui.h"
#include "landscape.h"
+#include "window_func.h"
/** What is the status of our acceleration? */
enum AccelStatus {
@@ -41,6 +43,9 @@ struct GroundVehicleCache {
uint16 cached_total_length; ///< Length of the whole vehicle (valid only for the first engine).
EngineID first_engine; ///< Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself.
uint8 cached_veh_length; ///< Length of this vehicle in units of 1/8 of normal length. It is cached because this can be set by a callback.
+
+ /* Cached UI information. */
+ uint16 last_speed; ///< The last speed we did display, so we only have to redraw when this changes.
};
/** Ground vehicle flags. */
@@ -357,6 +362,21 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
* @return True if the engine has an articulated part.
*/
FORCEINLINE bool HasArticulatedPart() const { return this->Next() != NULL && this->Next()->IsArticulatedPart(); }
+
+ /**
+ * Update the GUI variant of the current speed of the vehicle.
+ * Also mark the widget dirty when that is needed, i.e. when
+ * the speed of this vehicle has changed.
+ */
+ FORCEINLINE void SetLastSpeed()
+ {
+ if (this->cur_speed != this->gcache.last_speed) {
+ if (_settings_client.gui.vehicle_speed || (this->gcache.last_speed == 0) != (this->cur_speed == 0)) {
+ SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
+ }
+ this->gcache.last_speed = this->cur_speed;
+ }
+ }
};
#endif /* GROUND_VEHICLE_HPP */