diff options
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) |