(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance

This commit is contained in:
smatz
2010-05-03 23:36:17 +00:00
parent fc646a16a4
commit 00a52cc475
6 changed files with 23 additions and 21 deletions

View File

@@ -317,21 +317,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.
@@ -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)