summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/ship.h2
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp4
-rw-r--r--src/vehicle.cpp2
-rw-r--r--src/vehicle_base.h32
6 files changed, 23 insertions, 21 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 7c234cc14..f207efaf7 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -437,7 +437,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
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();
diff --git a/src/ship.h b/src/ship.h
index 2138e732e..0a271e637 100644
--- 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);
/**
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 5de839bf7..8e12a9f6e 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -292,7 +292,7 @@ void Ship::UpdateDeltaXY(Direction direction)
this->z_extent = 6;
}
-void RecalcShipStuff(Vehicle *v)
+void RecalcShipStuff(Ship *v)
{
v->UpdateViewport(false, true);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 3143624bd..f1260f7ff 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1771,7 +1771,7 @@ static void ReverseTrainDirection(Train *v)
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 @@ TileIndex Train::GetOrderStationLocation(StationID station)
void Train::MarkDirty()
{
- Vehicle *v = this;
+ Train *v = this;
do {
v->UpdateViewport(false, false);
} while ((v = v->Next()) != NULL);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8d902b241..e14d4979c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1069,7 +1069,7 @@ void VehicleEnterDepot(Vehicle *v)
case VEH_SHIP:
SetWindowClassesDirty(WC_SHIPS_LIST);
Ship::From(v)->state = TRACK_BIT_DEPOT;
- RecalcShipStuff(v);
+ RecalcShipStuff(Ship::From(v));
break;
case VEH_AIRCRAFT:
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)