Changeset - r15117:4610e022866d
[Not reviewed]
master
0 6 0
smatz - 14 years ago 2010-05-03 23:36:17
smatz@openttd.org
(svn r19756) -Codechange: move UpdateViewport() from Vehicle to SpecializedVehicle in order to improve performance
6 files changed with 23 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/roadveh_cmd.cpp
Show inline comments
 
@@ -437,7 +437,7 @@ CommandCost CmdTurnRoadVeh(TileIndex til
 

	
 
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();
src/ship.h
Show inline comments
 
@@ -14,7 +14,7 @@
 

	
 
#include "vehicle_base.h"
 

	
 
void RecalcShipStuff(Vehicle *v);
 
void RecalcShipStuff(Ship *v);
 
void GetShipSpriteSize(EngineID engine, uint &width, uint &height);
 

	
 
/**
src/ship_cmd.cpp
Show inline comments
 
@@ -292,7 +292,7 @@ void Ship::UpdateDeltaXY(Direction direc
 
	this->z_extent      = 6;
 
}
 

	
 
void RecalcShipStuff(Vehicle *v)
 
void RecalcShipStuff(Ship *v)
 
{
 
	v->UpdateViewport(false, true);
 
	SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
src/train_cmd.cpp
Show inline comments
 
@@ -1771,7 +1771,7 @@ static void ReverseTrainDirection(Train 
 
	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
 

	
 
void Train::MarkDirty()
 
{
 
	Vehicle *v = this;
 
	Train *v = this;
 
	do {
 
		v->UpdateViewport(false, false);
 
	} while ((v = v->Next()) != NULL);
src/vehicle.cpp
Show inline comments
 
@@ -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:
src/vehicle_base.h
Show inline comments
 
@@ -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 Vehic
 
		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)
0 comments (0 inline, 0 general)