mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
This commit is contained in:
parent
fc646a16a4
commit
00a52cc475
@ -437,7 +437,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
|
|
||||||
void RoadVehicle::MarkDirty()
|
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);
|
v->UpdateViewport(false, false);
|
||||||
}
|
}
|
||||||
this->CargoChanged();
|
this->CargoChanged();
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "vehicle_base.h"
|
#include "vehicle_base.h"
|
||||||
|
|
||||||
void RecalcShipStuff(Vehicle *v);
|
void RecalcShipStuff(Ship *v);
|
||||||
void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
|
void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,7 +292,7 @@ void Ship::UpdateDeltaXY(Direction direction)
|
|||||||
this->z_extent = 6;
|
this->z_extent = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecalcShipStuff(Vehicle *v)
|
void RecalcShipStuff(Ship *v)
|
||||||
{
|
{
|
||||||
v->UpdateViewport(false, true);
|
v->UpdateViewport(false, true);
|
||||||
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
|
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
|
||||||
|
@ -1771,7 +1771,7 @@ static void ReverseTrainDirection(Train *v)
|
|||||||
v->ConsistChanged(true);
|
v->ConsistChanged(true);
|
||||||
|
|
||||||
/* update all images */
|
/* 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 */
|
/* update crossing we were approaching */
|
||||||
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
|
if (crossing != INVALID_TILE) UpdateLevelCrossing(crossing);
|
||||||
@ -2806,7 +2806,7 @@ TileIndex Train::GetOrderStationLocation(StationID station)
|
|||||||
|
|
||||||
void Train::MarkDirty()
|
void Train::MarkDirty()
|
||||||
{
|
{
|
||||||
Vehicle *v = this;
|
Train *v = this;
|
||||||
do {
|
do {
|
||||||
v->UpdateViewport(false, false);
|
v->UpdateViewport(false, false);
|
||||||
} while ((v = v->Next()) != NULL);
|
} while ((v = v->Next()) != NULL);
|
||||||
|
@ -1069,7 +1069,7 @@ void VehicleEnterDepot(Vehicle *v)
|
|||||||
case VEH_SHIP:
|
case VEH_SHIP:
|
||||||
SetWindowClassesDirty(WC_SHIPS_LIST);
|
SetWindowClassesDirty(WC_SHIPS_LIST);
|
||||||
Ship::From(v)->state = TRACK_BIT_DEPOT;
|
Ship::From(v)->state = TRACK_BIT_DEPOT;
|
||||||
RecalcShipStuff(v);
|
RecalcShipStuff(Ship::From(v));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VEH_AIRCRAFT:
|
case VEH_AIRCRAFT:
|
||||||
|
@ -317,21 +317,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual uint Crash(bool flooded = false);
|
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.
|
* Returns the Trackdir on which the vehicle is currently located.
|
||||||
* Works for trains and ships.
|
* Works for trains and ships.
|
||||||
@ -661,6 +646,23 @@ struct SpecializedVehicle : public Vehicle {
|
|||||||
assert(v->type == Type);
|
assert(v->type == Type);
|
||||||
return (const T *)v;
|
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)
|
#define FOR_ALL_VEHICLES_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, vehicle_index, var, 0) if (var->type == name::EXPECTED_TYPE)
|
||||||
|
Loading…
Reference in New Issue
Block a user