summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2012-01-02 13:44:30 +0000
committertruebrain <truebrain@openttd.org>2012-01-02 13:44:30 +0000
commit0d929e877faf9572a80803db382ab973702e02c0 (patch)
treef19cea6421726b0719b1cfc7c403a8ac6262bc60 /src/vehicle.cpp
parent19004a77f843fccd0850cc980dd2c80de6d81462 (diff)
downloadopenttd-0d929e877faf9572a80803db382ab973702e02c0.tar.xz
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 0aa4f302a..72f25830d 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1386,16 +1386,23 @@ void VehicleEnterDepot(Vehicle *v)
/**
- * Move a vehicle in the game state; that is moving its position in
- * the position hashes and marking its location in the viewport dirty
- * if requested.
- * @param v vehicle to move
- * @param update_viewport whether to dirty the viewport
+ * Update the position of the vehicle. This will update the hash that tells
+ * which vehicles are on a tile.
+ * @param v The vehicle to update.
*/
-void VehicleMove(Vehicle *v, bool update_viewport)
+void VehicleUpdatePosition(Vehicle *v)
{
UpdateVehicleTileHash(v, false);
+}
+/**
+ * Update the vehicle on the viewport, updating the right hash and setting the
+ * new coordinates.
+ * @param v The vehicle to update.
+ * @param dirty Mark the (new and old) coordinates of the vehicle as dirty.
+ */
+void VehicleUpdateViewport(Vehicle *v, bool dirty)
+{
int img = v->cur_image;
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos);
const Sprite *spr = GetSprite(img, ST_NORMAL);
@@ -1411,7 +1418,7 @@ void VehicleMove(Vehicle *v, bool update_viewport)
v->coord.right = pt.x + spr->width + 2 * ZOOM_LVL_BASE;
v->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE;
- if (update_viewport) {
+ if (dirty) {
MarkAllViewportsDirty(
min(old_coord.left, v->coord.left),
min(old_coord.top, v->coord.top),
@@ -1422,12 +1429,18 @@ void VehicleMove(Vehicle *v, bool update_viewport)
}
/**
- * Marks viewports dirty where the vehicle's image is
- * In fact, it equals
- * BeginVehicleMove(v); EndVehicleMove(v);
+ * Update the position of the vehicle, and update the viewport.
+ * @param v The vehicle to update.
+ */
+void VehicleUpdatePositionAndViewport(Vehicle *v)
+{
+ VehicleUpdatePosition(v);
+ VehicleUpdateViewport(v, true);
+}
+
+/**
+ * Marks viewports dirty where the vehicle's image is.
* @param v vehicle to mark dirty
- * @see BeginVehicleMove()
- * @see EndVehicleMove()
*/
void MarkSingleVehicleDirty(const Vehicle *v)
{