(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places

This commit is contained in:
smatz 2008-01-16 21:17:31 +00:00
parent 69cb009075
commit ac7bc24b0e
8 changed files with 54 additions and 36 deletions

View File

@ -1288,8 +1288,7 @@ static void HandleCrashedAircraft(Vehicle *v)
CLRBITS(st->airport_flags, RUNWAY_IN_OUT_block); // commuter airport
CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
DoDeleteAircraft(v);
}
@ -1417,7 +1416,7 @@ void Aircraft::MarkDirty()
{
this->cur_image = this->GetImage(this->direction);
if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this);
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
MarkSingleVehicleDirty(this);
}
static void CrashAirplane(Vehicle *v)

View File

@ -138,8 +138,7 @@ static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Directio
DisasterVehicleUpdateImage(v);
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
}
static void DeleteDisasterVeh(Vehicle *v)
@ -547,8 +546,7 @@ static void DisasterTick_Helicopter_Rotors(Vehicle *v)
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
}
/**
@ -706,8 +704,7 @@ static void DisasterTick_Submarine(Vehicle *v)
if (++v->age > 8880) {
VehiclePositionChanged(v);
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
delete v;
return;
}

View File

@ -564,7 +564,7 @@ void RoadVehicle::MarkDirty()
{
for (Vehicle *v = this; v != NULL; v = v->Next()) {
v->cur_image = v->GetImage(v->direction);
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
MarkSingleVehicleDirty(v);
}
}
@ -615,8 +615,7 @@ static void DeleteLastRoadVeh(Vehicle *v)
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v);
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
delete v;
}
@ -690,7 +689,7 @@ static void RoadVehCrash(Vehicle *v)
u->vehstatus |= VS_CRASHED;
MarkAllViewportsDirty(u->left_coord, u->top_coord, u->right_coord + 1, u->bottom_coord + 1);
MarkSingleVehicleDirty(u);
}
ClearSlot(v);

View File

@ -229,7 +229,7 @@ static void HandleBrokenShip(Vehicle *v)
void Ship::MarkDirty()
{
this->cur_image = this->GetImage(this->direction);
MarkAllViewportsDirty(this->left_coord, this->top_coord, this->right_coord + 1, this->bottom_coord + 1);
MarkSingleVehicleDirty(this);
}
static void PlayShipSound(const Vehicle *v)

View File

@ -2572,7 +2572,7 @@ void Train::MarkDirty()
Vehicle *v = this;
do {
v->cur_image = v->GetImage(v->direction);
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
MarkSingleVehicleDirty(v);
} while ((v = v->Next()) != NULL);
/* need to update acceleration and cached values since the goods on the train changed. */
@ -2790,7 +2790,7 @@ static void SetVehicleCrashed(Vehicle *v)
BEGIN_ENUM_WAGONS(v)
v->vehstatus |= VS_CRASHED;
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
MarkSingleVehicleDirty(v);
END_ENUM_WAGONS(v)
}
@ -3137,8 +3137,7 @@ static void DeleteLastWagon(Vehicle *v)
RebuildVehicleLists();
BeginVehicleMove(v);
EndVehicleMove(v);
MarkSingleVehicleDirty(v);
/* 'v' shouldn't be accessed after it has been deleted */
TrackBits track = v->u.rail.track;

View File

@ -596,11 +596,9 @@ void DeleteVehicleChain(Vehicle *v)
do {
Vehicle *u = v;
if (!(v->vehstatus & VS_HIDDEN)) {
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
* it may happen that vehicle chain is deleted when visible */
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
}
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
* it may happen that vehicle chain is deleted when visible */
if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v);
v = v->Next();
delete u;
} while (v != NULL);
@ -2356,26 +2354,51 @@ CommandCost CmdChangeServiceInt(TileIndex tile, uint32 flags, uint32 p1, uint32
}
static Rect _old_vehicle_coords;
static Rect _old_vehicle_coords; ///< coords of vehicle before it has moved
void BeginVehicleMove(Vehicle *v)
/**
* Stores the vehicle image coords for later call to EndVehicleMove()
* @param v vehicle which image's coords to store
* @see _old_vehicle_coords
* @see EndVehicleMove()
*/
void BeginVehicleMove(const Vehicle *v)
{
_old_vehicle_coords.left = v->left_coord;
_old_vehicle_coords.top = v->top_coord;
_old_vehicle_coords.right = v->right_coord;
_old_vehicle_coords.left = v->left_coord;
_old_vehicle_coords.top = v->top_coord;
_old_vehicle_coords.right = v->right_coord;
_old_vehicle_coords.bottom = v->bottom_coord;
}
void EndVehicleMove(Vehicle *v)
/**
* Marks screen dirty after a vehicle has moved
* @param v vehicle which is marked dirty
* @see _old_vehicle_coords
* @see BeginVehicleMove()
*/
void EndVehicleMove(const Vehicle *v)
{
MarkAllViewportsDirty(
min(_old_vehicle_coords.left,v->left_coord),
min(_old_vehicle_coords.top,v->top_coord),
max(_old_vehicle_coords.right,v->right_coord)+1,
max(_old_vehicle_coords.bottom,v->bottom_coord)+1
min(_old_vehicle_coords.left, v->left_coord),
min(_old_vehicle_coords.top, v->top_coord),
max(_old_vehicle_coords.right, v->right_coord) + 1,
max(_old_vehicle_coords.bottom, v->bottom_coord) + 1
);
}
/**
* Marks viewports dirty where the vehicle's image is
* In fact, it equals
* BeginVehicleMove(v); EndVehicleMove(v);
* @param v vehicle to mark dirty
* @see BeginVehicleMove()
* @see EndVehicleMove()
*/
void MarkSingleVehicleDirty(const Vehicle *v)
{
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
}
/* returns true if staying in the same tile */
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
{

View File

@ -57,8 +57,9 @@ void CheckVehicleBreakdown(Vehicle *v);
void AgeVehicle(Vehicle *v);
void VehicleEnteredDepotThisTick(Vehicle *v);
void BeginVehicleMove(Vehicle *v);
void EndVehicleMove(Vehicle *v);
void BeginVehicleMove(const Vehicle *v);
void EndVehicleMove(const Vehicle *v);
void MarkSingleVehicleDirty(const Vehicle *v);
UnitID GetFreeUnitNumber(VehicleType type);

View File

@ -735,7 +735,7 @@ static void FloodVehicle(Vehicle *v)
BEGIN_ENUM_WAGONS(v)
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
v->vehstatus |= VS_CRASHED;
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
MarkSingleVehicleDirty(v);
END_ENUM_WAGONS(v)
v = u;