Mercurial > hg > openttd
changeset 15127:c065afa82756 draft
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
author | smatz <smatz@openttd.org> |
---|---|
date | Mon, 03 May 2010 23:36:17 +0000 |
parents | 5b846f30cecc |
children | f8fb58b4a217 |
files | src/roadveh_cmd.cpp src/ship.h src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp src/vehicle_base.h |
diffstat | 6 files changed, 23 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -437,7 +437,7 @@ void RoadVehicle::MarkDirty() { - for (Vehicle *v = this; v != NULL; v = v->Next()) { + for (RoadVehicle *v = this; v != NULL; v = v->Next()) { v->UpdateViewport(false, false); } this->CargoChanged();
--- a/src/ship.h +++ b/src/ship.h @@ -14,7 +14,7 @@ #include "vehicle_base.h" -void RecalcShipStuff(Vehicle *v); +void RecalcShipStuff(Ship *v); void GetShipSpriteSize(EngineID engine, uint &width, uint &height); /**
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -292,7 +292,7 @@ this->z_extent = 6; } -void RecalcShipStuff(Vehicle *v) +void RecalcShipStuff(Ship *v) { v->UpdateViewport(false, true); SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1771,7 +1771,7 @@ v->ConsistChanged(true); /* update all images */ - for (Vehicle *u = v; u != NULL; u = u->Next()) u->UpdateViewport(false, false); + for (Train *u = v; u != NULL; u = u->Next()) u->UpdateViewport(false, false); /* update crossing we were approaching */ if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing); @@ -2806,7 +2806,7 @@ void Train::MarkDirty() { - Vehicle *v = this; + Train *v = this; do { v->UpdateViewport(false, false); } while ((v = v->Next()) != NULL);
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1069,7 +1069,7 @@ case VEH_SHIP: SetWindowClassesDirty(WC_SHIPS_LIST); Ship::From(v)->state = TRACK_BIT_DEPOT; - RecalcShipStuff(v); + RecalcShipStuff(Ship::From(v)); break; case VEH_AIRCRAFT:
--- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -318,21 +318,6 @@ virtual uint Crash(bool flooded = false); /** - * Update vehicle sprite- and position caches - * @param moved Was the vehicle moved? - * @param turned Did the vehicle direction change? - */ - inline void UpdateViewport(bool moved, bool turned) - { - extern void VehicleMove(Vehicle *v, bool update_viewport); - - if (turned) this->UpdateDeltaXY(this->direction); - SpriteID old_image = this->cur_image; - this->cur_image = this->GetImage(this->direction); - if (moved || this->cur_image != old_image) VehicleMove(this, true); - } - - /** * Returns the Trackdir on which the vehicle is currently located. * Works for trains and ships. * Currently works only sortof for road vehicles, since they have a fuzzy @@ -661,6 +646,23 @@ assert(v->type == Type); return (const T *)v; } + + /** + * Update vehicle sprite- and position caches + * @param moved Was the vehicle moved? + * @param turned Did the vehicle direction change? + */ + FORCEINLINE void UpdateViewport(bool moved, bool turned) + { + extern void VehicleMove(Vehicle *v, bool update_viewport); + + /* Explicitly choose method to call to prevent vtable dereference - + * it gives ~3% runtime improvements in games with many vehicles */ + if (turned) ((T *)this)->T::UpdateDeltaXY(this->direction); + SpriteID old_image = this->cur_image; + this->cur_image = ((T *)this)->T::GetImage(this->direction); + if (moved || this->cur_image != old_image) VehicleMove(this, true); + } }; #define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)