summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2012-01-02 13:44:37 +0000
committertruebrain <truebrain@openttd.org>2012-01-02 13:44:37 +0000
commit091bc25a90bb68118f7dbd0e4d750de266cbf855 (patch)
tree77aaea1eca3aa6705991e37d915c3e0aa5e4ce44
parent0d929e877faf9572a80803db382ab973702e02c0 (diff)
downloadopenttd-091bc25a90bb68118f7dbd0e4d750de266cbf855.tar.xz
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
-rw-r--r--src/aircraft_cmd.cpp1
-rw-r--r--src/ground_vehicle.hpp6
-rw-r--r--src/roadveh_cmd.cpp6
-rw-r--r--src/ship_cmd.cpp3
-rw-r--r--src/train_cmd.cpp12
-rw-r--r--src/vehicle_base.h12
6 files changed, 26 insertions, 14 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 15d151d0c..55ffefecf 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -480,6 +480,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
v->y_pos = y;
v->z_pos = z;
+ VehicleUpdatePosition(v);
v->UpdateViewport(true, false);
if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP);
diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp
index 7f8f2eb25..4ff0c09bf 100644
--- a/src/ground_vehicle.hpp
+++ b/src/ground_vehicle.hpp
@@ -226,10 +226,10 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
/**
* Checks if the vehicle is in a slope and sets the required flags in that case.
* @param new_tile True if the vehicle reached a new tile.
- * @param turned Indicates if the vehicle has turned.
+ * @param update_delta Indicates to also update the delta.
* @return Old height of the vehicle.
*/
- inline byte UpdateInclination(bool new_tile, bool turned)
+ inline byte UpdateInclination(bool new_tile, bool update_delta)
{
byte old_z = this->z_pos;
@@ -239,7 +239,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
this->UpdateZPosition();
}
- this->UpdateViewport(true, turned);
+ this->UpdateViewport(true, update_delta);
return old_z;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 75eea8b45..e298dca49 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -987,6 +987,7 @@ static bool RoadVehLeaveDepot(RoadVehicle *v, bool first)
v->x_pos = x;
v->y_pos = y;
+ VehicleUpdatePosition(v);
v->UpdateInclination(true, true);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -1121,6 +1122,7 @@ static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *p
/* Vehicle has just entered a bridge or tunnel */
v->x_pos = gp.x;
v->y_pos = gp.y;
+ VehicleUpdatePosition(v);
v->UpdateInclination(true, true);
return true;
}
@@ -1277,6 +1279,7 @@ again:
}
v->x_pos = x;
v->y_pos = y;
+ VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true;
}
@@ -1342,6 +1345,7 @@ again:
v->x_pos = x;
v->y_pos = y;
+ VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true;
}
@@ -1430,6 +1434,7 @@ again:
v->frame++;
v->x_pos = x;
v->y_pos = y;
+ VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
return true;
}
@@ -1478,6 +1483,7 @@ again:
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
v->x_pos = x;
v->y_pos = y;
+ VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
return true;
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 2a65dfcf4..8b72b41f0 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -326,7 +326,7 @@ static bool CheckShipLeaveDepot(Ship *v)
v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0;
- v->UpdateViewport(false, true);
+ v->UpdateViewport(true, true);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
PlayShipSound(v);
@@ -601,6 +601,7 @@ static void ShipController(Ship *v)
v->z_pos = GetSlopePixelZ(gp.x, gp.y);
getout:
+ VehicleUpdatePosition(v);
v->UpdateViewport(true, true);
return;
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 5ab9bb330..0dc5f59cd 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1542,12 +1542,14 @@ static void UpdateStatusAfterSwap(Train *v)
/* We have just left the wormhole, possibly set the
* "goingdown" bit. UpdateInclination() can be used
* because we are at the border of the tile. */
+ VehicleUpdatePosition(v);
v->UpdateInclination(true, true);
return;
}
}
}
+ VehicleUpdatePosition(v);
v->UpdateViewport(true, true);
}
@@ -2155,10 +2157,8 @@ static bool CheckTrainStayInDepot(Train *v)
v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0;
- v->UpdateDeltaXY(v->direction);
- v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
+ v->UpdateViewport(true, true);
VehicleUpdatePosition(v);
- VehicleUpdateViewport(v, false);
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
v->UpdateAcceleration();
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -3321,6 +3321,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
v->x_pos = gp.x;
v->y_pos = gp.y;
+ VehicleUpdatePosition(v);
/* update the Z position of the vehicle */
int old_z = v->UpdateInclination(gp.new_tile != gp.old_tile, false);
@@ -3488,7 +3489,10 @@ static void ChangeTrainDirRandomly(Train *v)
/* Refrain from updating the z position of the vehicle when on
* a bridge, because UpdateInclination() will put the vehicle under
* the bridge in that case */
- if (v->track != TRACK_BIT_WORMHOLE) v->UpdateInclination(false, false);
+ if (v->track != TRACK_BIT_WORMHOLE) {
+ VehicleUpdatePosition(v);
+ v->UpdateInclination(false, false);
+ }
}
} while ((v = v->Next()) != NULL);
}
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 31b8332d4..852442e2e 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -986,19 +986,19 @@ struct SpecializedVehicle : public Vehicle {
/**
* Update vehicle sprite- and position caches
- * @param moved Was the vehicle moved?
- * @param turned Did the vehicle direction change?
+ * @param force_update Force updating the vehicle on the viewport.
+ * @param update_delta Also update the delta?
*/
- inline void UpdateViewport(bool moved, bool turned)
+ inline void UpdateViewport(bool force_update, bool update_delta)
{
- extern void VehicleUpdatePositionAndViewport(Vehicle *v);
+ extern void VehicleUpdateViewport(Vehicle *v, bool dirty);
/* 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);
+ if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction);
SpriteID old_image = this->cur_image;
this->cur_image = ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP);
- if (moved || this->cur_image != old_image) VehicleUpdatePositionAndViewport(this);
+ if (force_update || this->cur_image != old_image) VehicleUpdateViewport(this, true);
}
};