1
0
Fork 0

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

release/0.6
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_IN_OUT_block); // commuter airport
CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental CLRBITS(st->airport_flags, RUNWAY_IN2_block); // intercontinental
BeginVehicleMove(v); MarkSingleVehicleDirty(v);
EndVehicleMove(v);
DoDeleteAircraft(v); DoDeleteAircraft(v);
} }
@ -1417,7 +1416,7 @@ void Aircraft::MarkDirty()
{ {
this->cur_image = this->GetImage(this->direction); this->cur_image = this->GetImage(this->direction);
if (this->subtype == AIR_HELICOPTER) this->Next()->Next()->cur_image = GetRotorImage(this); 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) 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); DisasterVehicleUpdateImage(v);
VehiclePositionChanged(v); VehiclePositionChanged(v);
BeginVehicleMove(v); MarkSingleVehicleDirty(v);
EndVehicleMove(v);
} }
static void DeleteDisasterVeh(Vehicle *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; if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
VehiclePositionChanged(v); VehiclePositionChanged(v);
BeginVehicleMove(v); MarkSingleVehicleDirty(v);
EndVehicleMove(v);
} }
/** /**
@ -706,8 +704,7 @@ static void DisasterTick_Submarine(Vehicle *v)
if (++v->age > 8880) { if (++v->age > 8880) {
VehiclePositionChanged(v); VehiclePositionChanged(v);
BeginVehicleMove(v); MarkSingleVehicleDirty(v);
EndVehicleMove(v);
delete v; delete v;
return; return;
} }

View File

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

View File

@ -229,7 +229,7 @@ static void HandleBrokenShip(Vehicle *v)
void Ship::MarkDirty() void Ship::MarkDirty()
{ {
this->cur_image = this->GetImage(this->direction); 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) static void PlayShipSound(const Vehicle *v)

View File

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

View File

@ -596,11 +596,9 @@ void DeleteVehicleChain(Vehicle *v)
do { do {
Vehicle *u = v; Vehicle *u = v;
if (!(v->vehstatus & VS_HIDDEN)) {
/* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles,
* it may happen that vehicle chain is deleted when visible */ * 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); if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v);
}
v = v->Next(); v = v->Next();
delete u; delete u;
} while (v != NULL); } while (v != NULL);
@ -2356,9 +2354,15 @@ 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.left = v->left_coord;
_old_vehicle_coords.top = v->top_coord; _old_vehicle_coords.top = v->top_coord;
@ -2366,7 +2370,13 @@ void BeginVehicleMove(Vehicle *v)
_old_vehicle_coords.bottom = v->bottom_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( MarkAllViewportsDirty(
min(_old_vehicle_coords.left, v->left_coord), min(_old_vehicle_coords.left, v->left_coord),
@ -2376,6 +2386,19 @@ void EndVehicleMove(Vehicle *v)
); );
} }
/**
* 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 */ /* returns true if staying in the same tile */
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
{ {

View File

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

View File

@ -735,7 +735,7 @@ static void FloodVehicle(Vehicle *v)
BEGIN_ENUM_WAGONS(v) BEGIN_ENUM_WAGONS(v)
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count(); if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count();
v->vehstatus |= VS_CRASHED; 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) END_ENUM_WAGONS(v)
v = u; v = u;