diff options
author | rubidium <rubidium@openttd.org> | 2011-01-26 17:31:07 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-01-26 17:31:07 +0000 |
commit | b11f1bd4ed68fc0d031429df2925b87ed6baceb3 (patch) | |
tree | 5bb149c0bafdbb9a3987237fa5f1d659f92268cf | |
parent | 12b64a12b06f93d81a433cb311dfd1228d155e98 (diff) | |
download | openttd-b11f1bd4ed68fc0d031429df2925b87ed6baceb3.tar.xz |
(svn r21911) -Codechange: move tcache.last_speed to gcache.last_speed and make SetLastSpeed a function of GroundVehicle
-rw-r--r-- | src/ground_vehicle.hpp | 20 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 2 | ||||
-rw-r--r-- | src/train.h | 4 | ||||
-rw-r--r-- | src/train_cmd.cpp | 19 |
4 files changed, 26 insertions, 19 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 */ diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index d93b74989..32b692f1d 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -336,7 +336,7 @@ void AfterLoadVehicles(bool part_of_load) 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; diff --git a/src/train.h b/src/train.h index f7142e47a..1d153337c 100644 --- a/src/train.h +++ b/src/train.h @@ -65,8 +65,6 @@ struct TrainCache { /* 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 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> { 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; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index ccc644666..2c816c280 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1395,17 +1395,6 @@ void Train::UpdateDeltaXY(Direction direction) 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 @@ static void MarkTrainAsStuck(Train *v) /* 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 @@ CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 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 @@ static bool TrainLocoHandler(Train *v, bool mode) 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 @@ static bool TrainLocoHandler(Train *v, bool mode) ProcessOrders(v); } } - SetLastSpeed(v, v->cur_speed); + v->SetLastSpeed(); } for (Train *u = v; u != NULL; u = u->Next()) { |