From b11f1bd4ed68fc0d031429df2925b87ed6baceb3 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 26 Jan 2011 17:31:07 +0000 Subject: (svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle --- src/ground_vehicle.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/ground_vehicle.hpp') 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 { * @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 */ -- cgit v1.2.3-54-g00ecf