mirror of https://github.com/OpenTTD/OpenTTD
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
parent
69cb009075
commit
ac7bc24b0e
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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 */
|
if (!(v->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(v);
|
||||||
MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
|
|
||||||
}
|
|
||||||
v = v->Next();
|
v = v->Next();
|
||||||
delete u;
|
delete u;
|
||||||
} while (v != NULL);
|
} 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.left = v->left_coord;
|
||||||
_old_vehicle_coords.top = v->top_coord;
|
_old_vehicle_coords.top = v->top_coord;
|
||||||
_old_vehicle_coords.right = v->right_coord;
|
_old_vehicle_coords.right = v->right_coord;
|
||||||
_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),
|
||||||
min(_old_vehicle_coords.top,v->top_coord),
|
min(_old_vehicle_coords.top, v->top_coord),
|
||||||
max(_old_vehicle_coords.right,v->right_coord)+1,
|
max(_old_vehicle_coords.right, v->right_coord) + 1,
|
||||||
max(_old_vehicle_coords.bottom,v->bottom_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 */
|
/* returns true if staying in the same tile */
|
||||||
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
|
GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue