Mercurial > hg > openttd
changeset 17172:679a25d71a9d draft
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 26 Jan 2011 17:31:07 +0000 |
parents | 7f703880d137 |
children | 587b92c2457c |
files | src/ground_vehicle.hpp src/saveload/vehicle_sl.cpp src/train.h src/train_cmd.cpp |
diffstat | 4 files changed, 26 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ 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 @@ * @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 */
--- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -336,7 +336,7 @@ case VEH_TRAIN: { Train *t = Train::From(v); if (t->IsFrontEngine() || t->IsFreeWagon()) { - t->tcache.last_speed = t->cur_speed; // update displayed train speed + t->gcache.last_speed = t->cur_speed; // update displayed train speed t->ConsistChanged(false); } break;
--- a/src/train.h +++ b/src/train.h @@ -65,8 +65,6 @@ /* 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. */ bool cached_tilt; ///< train can tilt; feature provides a bonus in curves @@ -110,7 +108,7 @@ void PlayLeaveStationSound() const; bool IsPrimaryVehicle() const { return this->IsFrontEngine(); } SpriteID GetImage(Direction direction) const; - int GetDisplaySpeed() const { return this->tcache.last_speed; } + int GetDisplaySpeed() const { return this->gcache.last_speed; } int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; } Money GetRunningCost() const; int GetDisplayImageWidth(Point *offset = NULL) const;
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1395,17 +1395,6 @@ this->z_extent = 6; } -static inline void SetLastSpeed(Train *v, int spd) -{ - int old = v->tcache.last_speed; - if (spd != old) { - v->tcache.last_speed = spd; - if (_settings_client.gui.vehicle_speed || (old == 0) != (spd == 0)) { - SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); - } - } -} - /** Mark a train as stuck and stop it if it isn't stopped right now. */ static void MarkTrainAsStuck(Train *v) { @@ -1418,7 +1407,7 @@ /* Stop train */ v->cur_speed = 0; v->subspeed = 0; - SetLastSpeed(v, 0); + v->SetLastSpeed(); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); } @@ -1843,7 +1832,7 @@ ToggleBit(v->flags, VRF_REVERSING); } else { v->cur_speed = 0; - SetLastSpeed(v, 0); + v->SetLastSpeed(); HideFillingPercent(&v->fill_percent_te_id); ReverseTrainDirection(v); } @@ -3659,7 +3648,7 @@ int adv_spd = v->GetAdvanceDistance(); if (j < adv_spd) { /* if the vehicle has speed 0, update the last_speed field. */ - if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed); + if (v->cur_speed == 0) v->SetLastSpeed(); } else { TrainCheckIfLineEnds(v); /* Loop until the train has finished moving. */ @@ -3683,7 +3672,7 @@ ProcessOrders(v); } } - SetLastSpeed(v, v->cur_speed); + v->SetLastSpeed(); } for (Train *u = v; u != NULL; u = u->Next()) {