diff options
author | smatz <smatz@openttd.org> | 2010-05-03 23:36:17 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2010-05-03 23:36:17 +0000 |
commit | 00a52cc4759ecf1bde370ae4d5dfffd7ddae1a6c (patch) | |
tree | c33d9eea9f7a05b9774a143ade14805ebeb95b82 /src/vehicle_base.h | |
parent | fc646a16a4326be420523e15f664c1bcd1b30a93 (diff) | |
download | openttd-00a52cc4759ecf1bde370ae4d5dfffd7ddae1a6c.tar.xz |
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
Diffstat (limited to 'src/vehicle_base.h')
-rw-r--r-- | src/vehicle_base.h | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/vehicle_base.h b/src/vehicle_base.h index bea248538..ea626a40f 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -318,21 +318,6 @@ public: 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 @@ struct SpecializedVehicle : public Vehicle { 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) |