summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-01-16 21:17:31 +0000
committersmatz <smatz@openttd.org>2008-01-16 21:17:31 +0000
commitfc2895e8c252697f4b0b47e8fc4dd3d2f2efd5b7 (patch)
tree022a2d92b742035ec46b042383c3dcb37eefd6be /src
parentdf7286e7c12a4b4d7eece797c6da4ff809e8089c (diff)
downloadopenttd-fc2895e8c252697f4b0b47e8fc4dd3d2f2efd5b7.tar.xz
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp5
-rw-r--r--src/disaster_cmd.cpp9
-rw-r--r--src/roadveh_cmd.cpp7
-rw-r--r--src/ship_cmd.cpp2
-rw-r--r--src/train_cmd.cpp7
-rw-r--r--src/vehicle.cpp53
-rw-r--r--src/vehicle_func.h5
-rw-r--r--src/water_cmd.cpp2
8 files changed, 54 insertions, 36 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index efd0700f6..f8122e33f 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -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)
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 83d73f07a..d346d214d 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -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;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index f56e220e3..4a5a98221 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -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);
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 92af6e5ec..cae413356 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -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)
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index f42ffe007..d9e54e1f1 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -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;
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 0d514ec12..d551bda88 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -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)
{
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 728d2c723..476c35782 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -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);
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index db9fbf839..0605de526 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -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;