summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/aircraft_cmd.cpp12
-rw-r--r--src/articulated_vehicles.cpp2
-rw-r--r--src/disaster_cmd.cpp11
-rw-r--r--src/effectvehicle.cpp27
-rw-r--r--src/roadveh_cmd.cpp5
-rw-r--r--src/saveload/vehicle_sl.cpp3
-rw-r--r--src/ship_cmd.cpp5
-rw-r--r--src/train_cmd.cpp12
-rw-r--r--src/vehicle.cpp37
-rw-r--r--src/vehicle_base.h4
-rw-r--r--src/vehicle_func.h4
11 files changed, 70 insertions, 52 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 6581e3800..15d151d0c 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -314,8 +314,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
UpdateAircraftCache(v, true);
- VehicleMove(v, false);
- VehicleMove(u, false);
+ VehicleUpdatePosition(v);
+ VehicleUpdatePosition(u);
/* Aircraft with 3 vehicles (chopper)? */
if (v->subtype == AIR_HELICOPTER) {
@@ -336,7 +336,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
w->UpdateDeltaXY(INVALID_DIR);
u->SetNext(w);
- VehicleMove(w, false);
+ VehicleUpdatePosition(w);
}
}
@@ -464,7 +464,7 @@ static void HelicopterTickHandler(Aircraft *v)
u->cur_image = img;
- VehicleMove(u, true);
+ VehicleUpdatePositionAndViewport(u);
}
/**
@@ -494,7 +494,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
u->z_pos = GetSlopePixelZ(safe_x, safe_y);
u->cur_image = v->cur_image;
- VehicleMove(u, true);
+ VehicleUpdatePositionAndViewport(u);
u = u->Next();
if (u != NULL) {
@@ -502,7 +502,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
u->y_pos = y;
u->z_pos = z + ROTOR_Z_OFFSET;
- VehicleMove(u, true);
+ VehicleUpdatePositionAndViewport(u);
}
}
diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp
index 0d5d2b2fc..a9b678903 100644
--- a/src/articulated_vehicles.cpp
+++ b/src/articulated_vehicles.cpp
@@ -397,6 +397,6 @@ void AddArticulatedParts(Vehicle *first)
if (flip_image) v->spritenum++;
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
}
}
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index 319113a0a..61cf0e120 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -149,8 +149,7 @@ static void InitializeDisasterVehicle(DisasterVehicle *v, int x, int y, int z, D
v->current_order.Free();
DisasterVehicleUpdateImage(v);
- VehicleMove(v, false);
- MarkSingleVehicleDirty(v);
+ VehicleUpdatePositionAndViewport(v);
}
static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
@@ -161,7 +160,7 @@ static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
v->tile = TileVirtXY(x, y);
DisasterVehicleUpdateImage(v);
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
DisasterVehicle *u = v->Next();
if (u != NULL) {
@@ -175,13 +174,13 @@ static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
u->direction = v->direction;
DisasterVehicleUpdateImage(u);
- VehicleMove(u, true);
+ VehicleUpdatePositionAndViewport(u);
if ((u = u->Next()) != NULL) {
u->x_pos = x;
u->y_pos = y;
u->z_pos = z + 5;
- VehicleMove(u, true);
+ VehicleUpdatePositionAndViewport(u);
}
}
}
@@ -479,7 +478,7 @@ static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *v)
if (++v->cur_image > SPR_ROTOR_MOVING_3) v->cur_image = SPR_ROTOR_MOVING_1;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
return true;
}
diff --git a/src/effectvehicle.cpp b/src/effectvehicle.cpp
index 700fa86cd..97ec93759 100644
--- a/src/effectvehicle.cpp
+++ b/src/effectvehicle.cpp
@@ -45,7 +45,7 @@ static bool ChimneySmokeTick(EffectVehicle *v)
v->cur_image = SPR_CHIMNEY_SMOKE_0;
}
v->progress = 7;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
}
return true;
@@ -78,7 +78,7 @@ static bool SteamSmokeTick(EffectVehicle *v)
moved = true;
}
- if (moved) VehicleMove(v, true);
+ if (moved) VehicleUpdatePositionAndViewport(v);
return true;
}
@@ -95,11 +95,11 @@ static bool DieselSmokeTick(EffectVehicle *v)
if ((v->progress & 3) == 0) {
v->z_pos++;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
} else if ((v->progress & 7) == 1) {
if (v->cur_image != SPR_DIESEL_SMOKE_5) {
v->cur_image++;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
} else {
delete v;
return false;
@@ -123,7 +123,7 @@ static bool ElectricSparkTick(EffectVehicle *v)
v->progress = 0;
if (v->cur_image != SPR_ELECTRIC_SPARK_5) {
v->cur_image++;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
} else {
delete v;
return false;
@@ -160,7 +160,7 @@ static bool SmokeTick(EffectVehicle *v)
moved = true;
}
- if (moved) VehicleMove(v, true);
+ if (moved) VehicleUpdatePositionAndViewport(v);
return true;
}
@@ -177,7 +177,7 @@ static bool ExplosionLargeTick(EffectVehicle *v)
if ((v->progress & 3) == 0) {
if (v->cur_image != SPR_EXPLOSION_LARGE_F) {
v->cur_image++;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
} else {
delete v;
return false;
@@ -202,7 +202,7 @@ static bool BreakdownSmokeTick(EffectVehicle *v)
} else {
v->cur_image = SPR_BREAKDOWN_SMOKE_0;
}
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
}
v->animation_state--;
@@ -226,7 +226,7 @@ static bool ExplosionSmallTick(EffectVehicle *v)
if ((v->progress & 3) == 0) {
if (v->cur_image != SPR_EXPLOSION_SMALL_B) {
v->cur_image++;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
} else {
delete v;
return false;
@@ -303,7 +303,7 @@ static bool BulldozerTick(EffectVehicle *v)
return false;
}
}
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
}
return true;
@@ -476,7 +476,7 @@ static bool BubbleTick(EffectVehicle *v)
if (v->spritenum == 0) {
v->cur_image++;
if (v->cur_image < SPR_BUBBLE_GENERATE_3) {
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
return true;
}
if (v->animation_substate != 0) {
@@ -522,7 +522,7 @@ static bool BubbleTick(EffectVehicle *v)
v->z_pos += b->z;
v->cur_image = SPR_BUBBLE_0 + b->image;
- VehicleMove(v, true);
+ VehicleUpdatePositionAndViewport(v);
return true;
}
@@ -606,8 +606,7 @@ EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
_effect_init_procs[type](v);
- VehicleMove(v, false);
- MarkSingleVehicleDirty(v);
+ VehicleUpdatePositionAndViewport(v);
return v;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 96fdab63e..75eea8b45 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -300,7 +300,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin
/* Initialize cached values for realistic acceleration. */
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) v->CargoChanged();
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
CheckConsistencyOfArticulatedVehicle(v);
}
@@ -1127,7 +1127,8 @@ static bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *p
v->x_pos = gp.x;
v->y_pos = gp.y;
- VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
+ VehicleUpdatePosition(v);
+ if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
return true;
}
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index 19c615ab1..7c04448db 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -442,7 +442,8 @@ void AfterLoadVehicles(bool part_of_load)
v->UpdateDeltaXY(v->direction);
v->coord.left = INVALID_COORD;
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
+ VehicleUpdateViewport(v, false);
}
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 00bc770d8..2a65dfcf4 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -588,7 +588,8 @@ static void ShipController(Ship *v)
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
v->x_pos = gp.x;
v->y_pos = gp.y;
- VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
+ VehicleUpdatePosition(v);
+ if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
return;
}
}
@@ -680,7 +681,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u
v->InvalidateNewGRFCacheOfChain();
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
}
return CommandCost();
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index cfce4b819..5ab9bb330 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -595,7 +595,7 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const
_new_vehicle_id = v->index;
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
v->First()->ConsistChanged(false);
UpdateTrainGroupID(v->First());
@@ -657,7 +657,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
v->SetMultiheaded();
u->SetMultiheaded();
v->SetNext(u);
- VehicleMove(u, false);
+ VehicleUpdatePosition(u);
/* Now we need to link the front and rear engines together */
v->other_multiheaded_part = u;
@@ -726,7 +726,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin
v->SetFrontEngine();
v->SetEngine();
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
AddRearEngineToMultiheadedTrain(v);
@@ -2157,7 +2157,8 @@ static bool CheckTrainStayInDepot(Train *v)
v->UpdateDeltaXY(v->direction);
v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
- VehicleMove(v, false);
+ VehicleUpdatePosition(v);
+ VehicleUpdateViewport(v, false);
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
v->UpdateAcceleration();
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@@ -3309,7 +3310,8 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
} else {
v->x_pos = gp.x;
v->y_pos = gp.y;
- VehicleMove(v, !(v->vehstatus & VS_HIDDEN));
+ VehicleUpdatePosition(v);
+ if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true);
continue;
}
}
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)
{
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 1427d8004..31b8332d4 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -991,14 +991,14 @@ struct SpecializedVehicle : public Vehicle {
*/
inline void UpdateViewport(bool moved, bool turned)
{
- extern void VehicleMove(Vehicle *v, bool update_viewport);
+ extern void VehicleUpdatePositionAndViewport(Vehicle *v);
/* 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);
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) VehicleMove(this, true);
+ if (moved || this->cur_image != old_image) VehicleUpdatePositionAndViewport(this);
}
};
diff --git a/src/vehicle_func.h b/src/vehicle_func.h
index 96bb87a45..8a3eb2fee 100644
--- a/src/vehicle_func.h
+++ b/src/vehicle_func.h
@@ -59,7 +59,9 @@ void CheckVehicleBreakdown(Vehicle *v);
void AgeVehicle(Vehicle *v);
void VehicleEnteredDepotThisTick(Vehicle *v);
-void VehicleMove(Vehicle *v, bool update_viewport);
+void VehicleUpdatePosition(Vehicle *v);
+void VehicleUpdateViewport(Vehicle *v, bool dirty);
+void VehicleUpdatePositionAndViewport(Vehicle *v);
void MarkSingleVehicleDirty(const Vehicle *v);
UnitID GetFreeUnitNumber(VehicleType type);