1
0
Fork 0

(svn r26863) -Codechange: move a number of Vehicle* functions into the Vehicle class

release/1.5
rubidium 2014-09-20 15:31:26 +00:00
parent c4311903b7
commit 6c2abf0930
11 changed files with 81 additions and 87 deletions

View File

@ -337,8 +337,8 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
UpdateAircraftCache(v, true); UpdateAircraftCache(v, true);
VehicleUpdatePosition(v); v->UpdatePosition();
VehicleUpdatePosition(u); u->UpdatePosition();
/* Aircraft with 3 vehicles (chopper)? */ /* Aircraft with 3 vehicles (chopper)? */
if (v->subtype == AIR_HELICOPTER) { if (v->subtype == AIR_HELICOPTER) {
@ -359,7 +359,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, const Engine *
w->UpdateDeltaXY(INVALID_DIR); w->UpdateDeltaXY(INVALID_DIR);
u->SetNext(w); u->SetNext(w);
VehicleUpdatePosition(w); w->UpdatePosition();
} }
} }
@ -487,7 +487,7 @@ static void HelicopterTickHandler(Aircraft *v)
u->cur_image = img; u->cur_image = img;
VehicleUpdatePositionAndViewport(u); u->UpdatePositionAndViewport();
} }
/** /**
@ -503,7 +503,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
v->y_pos = y; v->y_pos = y;
v->z_pos = z; v->z_pos = z;
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateViewport(true, false); v->UpdateViewport(true, false);
if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP); if (v->subtype == AIR_HELICOPTER) v->Next()->Next()->cur_image = GetRotorImage(v, EIT_ON_MAP);
@ -518,7 +518,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
u->z_pos = GetSlopePixelZ(safe_x, safe_y); u->z_pos = GetSlopePixelZ(safe_x, safe_y);
u->cur_image = v->cur_image; u->cur_image = v->cur_image;
VehicleUpdatePositionAndViewport(u); u->UpdatePositionAndViewport();
u = u->Next(); u = u->Next();
if (u != NULL) { if (u != NULL) {
@ -526,7 +526,7 @@ void SetAircraftPosition(Aircraft *v, int x, int y, int z)
u->y_pos = y; u->y_pos = y;
u->z_pos = z + ROTOR_Z_OFFSET; u->z_pos = z + ROTOR_Z_OFFSET;
VehicleUpdatePositionAndViewport(u); u->UpdatePositionAndViewport();
} }
} }

View File

@ -445,6 +445,6 @@ void AddArticulatedParts(Vehicle *first)
if (flip_image) v->spritenum++; if (flip_image) v->spritenum++;
VehicleUpdatePosition(v); v->UpdatePosition();
} }
} }

View File

@ -151,7 +151,7 @@ static void InitializeDisasterVehicle(DisasterVehicle *v, int x, int y, int z, D
v->current_order.Free(); v->current_order.Free();
DisasterVehicleUpdateImage(v); DisasterVehicleUpdateImage(v);
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} }
static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z) static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
@ -162,7 +162,7 @@ static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
v->tile = TileVirtXY(x, y); v->tile = TileVirtXY(x, y);
DisasterVehicleUpdateImage(v); DisasterVehicleUpdateImage(v);
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
DisasterVehicle *u = v->Next(); DisasterVehicle *u = v->Next();
if (u != NULL) { if (u != NULL) {
@ -176,13 +176,13 @@ static void SetDisasterVehiclePos(DisasterVehicle *v, int x, int y, int z)
u->direction = v->direction; u->direction = v->direction;
DisasterVehicleUpdateImage(u); DisasterVehicleUpdateImage(u);
VehicleUpdatePositionAndViewport(u); u->UpdatePositionAndViewport();
if ((u = u->Next()) != NULL) { if ((u = u->Next()) != NULL) {
u->x_pos = x; u->x_pos = x;
u->y_pos = y; u->y_pos = y;
u->z_pos = z + 5; u->z_pos = z + 5;
VehicleUpdatePositionAndViewport(u); u->UpdatePositionAndViewport();
} }
} }
} }
@ -476,7 +476,7 @@ static bool DisasterTick_Helicopter_Rotors(DisasterVehicle *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;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
return true; return true;
} }

View File

@ -46,7 +46,7 @@ static bool ChimneySmokeTick(EffectVehicle *v)
v->cur_image = SPR_CHIMNEY_SMOKE_0; v->cur_image = SPR_CHIMNEY_SMOKE_0;
} }
v->progress = 7; v->progress = 7;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} }
return true; return true;
@ -79,7 +79,7 @@ static bool SteamSmokeTick(EffectVehicle *v)
moved = true; moved = true;
} }
if (moved) VehicleUpdatePositionAndViewport(v); if (moved) v->UpdatePositionAndViewport();
return true; return true;
} }
@ -96,11 +96,11 @@ static bool DieselSmokeTick(EffectVehicle *v)
if ((v->progress & 3) == 0) { if ((v->progress & 3) == 0) {
v->z_pos++; v->z_pos++;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} else if ((v->progress & 7) == 1) { } else if ((v->progress & 7) == 1) {
if (v->cur_image != SPR_DIESEL_SMOKE_5) { if (v->cur_image != SPR_DIESEL_SMOKE_5) {
v->cur_image++; v->cur_image++;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} else { } else {
delete v; delete v;
return false; return false;
@ -124,7 +124,7 @@ static bool ElectricSparkTick(EffectVehicle *v)
v->progress = 0; v->progress = 0;
if (v->cur_image != SPR_ELECTRIC_SPARK_5) { if (v->cur_image != SPR_ELECTRIC_SPARK_5) {
v->cur_image++; v->cur_image++;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} else { } else {
delete v; delete v;
return false; return false;
@ -161,7 +161,7 @@ static bool SmokeTick(EffectVehicle *v)
moved = true; moved = true;
} }
if (moved) VehicleUpdatePositionAndViewport(v); if (moved) v->UpdatePositionAndViewport();
return true; return true;
} }
@ -178,7 +178,7 @@ static bool ExplosionLargeTick(EffectVehicle *v)
if ((v->progress & 3) == 0) { if ((v->progress & 3) == 0) {
if (v->cur_image != SPR_EXPLOSION_LARGE_F) { if (v->cur_image != SPR_EXPLOSION_LARGE_F) {
v->cur_image++; v->cur_image++;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} else { } else {
delete v; delete v;
return false; return false;
@ -203,7 +203,7 @@ static bool BreakdownSmokeTick(EffectVehicle *v)
} else { } else {
v->cur_image = SPR_BREAKDOWN_SMOKE_0; v->cur_image = SPR_BREAKDOWN_SMOKE_0;
} }
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} }
v->animation_state--; v->animation_state--;
@ -227,7 +227,7 @@ static bool ExplosionSmallTick(EffectVehicle *v)
if ((v->progress & 3) == 0) { if ((v->progress & 3) == 0) {
if (v->cur_image != SPR_EXPLOSION_SMALL_B) { if (v->cur_image != SPR_EXPLOSION_SMALL_B) {
v->cur_image++; v->cur_image++;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} else { } else {
delete v; delete v;
return false; return false;
@ -304,7 +304,7 @@ static bool BulldozerTick(EffectVehicle *v)
return false; return false;
} }
} }
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
} }
return true; return true;
@ -477,7 +477,7 @@ static bool BubbleTick(EffectVehicle *v)
if (v->spritenum == 0) { if (v->spritenum == 0) {
v->cur_image++; v->cur_image++;
if (v->cur_image < SPR_BUBBLE_GENERATE_3) { if (v->cur_image < SPR_BUBBLE_GENERATE_3) {
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
return true; return true;
} }
if (v->animation_substate != 0) { if (v->animation_substate != 0) {
@ -523,7 +523,7 @@ static bool BubbleTick(EffectVehicle *v)
v->z_pos += b->z; v->z_pos += b->z;
v->cur_image = SPR_BUBBLE_0 + b->image; v->cur_image = SPR_BUBBLE_0 + b->image;
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
return true; return true;
} }
@ -607,7 +607,7 @@ EffectVehicle *CreateEffectVehicle(int x, int y, int z, EffectVehicleType type)
_effect_init_procs[type](v); _effect_init_procs[type](v);
VehicleUpdatePositionAndViewport(v); v->UpdatePositionAndViewport();
return v; return v;
} }

View File

@ -329,7 +329,7 @@ CommandCost CmdBuildRoadVehicle(TileIndex tile, DoCommandFlag flags, const Engin
/* Initialize cached values for realistic acceleration. */ /* Initialize cached values for realistic acceleration. */
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) v->CargoChanged(); if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) v->CargoChanged();
VehicleUpdatePosition(v); v->UpdatePosition();
CheckConsistencyOfArticulatedVehicle(v); CheckConsistencyOfArticulatedVehicle(v);
} }
@ -1017,7 +1017,7 @@ static bool RoadVehLeaveDepot(RoadVehicle *v, bool first)
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateInclination(true, true); v->UpdateInclination(true, true);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@ -1146,15 +1146,15 @@ bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev)
/* Vehicle has just entered a bridge or tunnel */ /* Vehicle has just entered a bridge or tunnel */
v->x_pos = gp.x; v->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateInclination(true, true); v->UpdateInclination(true, true);
return true; return true;
} }
v->x_pos = gp.x; v->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
VehicleUpdatePosition(v); v->UpdatePosition();
if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true); if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
return true; return true;
} }
@ -1303,7 +1303,7 @@ again:
} }
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v); v->UpdatePosition();
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true; return true;
} }
@ -1369,7 +1369,7 @@ again:
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v); v->UpdatePosition();
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true; return true;
} }
@ -1457,7 +1457,7 @@ again:
v->frame++; v->frame++;
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v); v->UpdatePosition();
RoadZPosAffectSpeed(v, v->UpdateInclination(true, false)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
return true; return true;
} }
@ -1506,7 +1506,7 @@ again:
if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++; if (!HasBit(r, VETS_ENTERED_WORMHOLE)) v->frame++;
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v); v->UpdatePosition();
RoadZPosAffectSpeed(v, v->UpdateInclination(false, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
return true; return true;
} }

View File

@ -459,8 +459,8 @@ void AfterLoadVehicles(bool part_of_load)
v->UpdateDeltaXY(v->direction); v->UpdateDeltaXY(v->direction);
v->coord.left = INVALID_COORD; v->coord.left = INVALID_COORD;
VehicleUpdatePosition(v); v->UpdatePosition();
VehicleUpdateViewport(v, false); v->UpdateViewport(false);
} }
} }

View File

@ -625,8 +625,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)) { 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->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
VehicleUpdatePosition(v); v->UpdatePosition();
if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true); if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
return; return;
} }
} }
@ -638,7 +638,7 @@ static void ShipController(Ship *v)
v->z_pos = GetSlopePixelZ(gp.x, gp.y); v->z_pos = GetSlopePixelZ(gp.x, gp.y);
getout: getout:
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateViewport(true, true); v->UpdateViewport(true, true);
return; return;
@ -722,7 +722,7 @@ CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, u
v->InvalidateNewGRFCacheOfChain(); v->InvalidateNewGRFCacheOfChain();
VehicleUpdatePosition(v); v->UpdatePosition();
} }
return CommandCost(); return CommandCost();

View File

@ -642,7 +642,7 @@ static CommandCost CmdBuildRailWagon(TileIndex tile, DoCommandFlag flags, const
_new_vehicle_id = v->index; _new_vehicle_id = v->index;
VehicleUpdatePosition(v); v->UpdatePosition();
v->First()->ConsistChanged(CCF_ARRANGE); v->First()->ConsistChanged(CCF_ARRANGE);
UpdateTrainGroupID(v->First()); UpdateTrainGroupID(v->First());
@ -705,7 +705,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
v->SetMultiheaded(); v->SetMultiheaded();
u->SetMultiheaded(); u->SetMultiheaded();
v->SetNext(u); v->SetNext(u);
VehicleUpdatePosition(u); u->UpdatePosition();
/* Now we need to link the front and rear engines together */ /* Now we need to link the front and rear engines together */
v->other_multiheaded_part = u; v->other_multiheaded_part = u;
@ -777,7 +777,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin
v->SetFrontEngine(); v->SetFrontEngine();
v->SetEngine(); v->SetEngine();
VehicleUpdatePosition(v); v->UpdatePosition();
if (rvi->railveh_type == RAILVEH_MULTIHEAD) { if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
AddRearEngineToMultiheadedTrain(v); AddRearEngineToMultiheadedTrain(v);
@ -1565,14 +1565,14 @@ static void UpdateStatusAfterSwap(Train *v)
/* We have just left the wormhole, possibly set the /* We have just left the wormhole, possibly set the
* "goingdown" bit. UpdateInclination() can be used * "goingdown" bit. UpdateInclination() can be used
* because we are at the border of the tile. */ * because we are at the border of the tile. */
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateInclination(true, true); v->UpdateInclination(true, true);
return; return;
} }
} }
} }
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateViewport(true, true); v->UpdateViewport(true, true);
} }
@ -2183,7 +2183,7 @@ static bool CheckTrainStayInDepot(Train *v)
v->cur_speed = 0; v->cur_speed = 0;
v->UpdateViewport(true, true); v->UpdateViewport(true, true);
VehicleUpdatePosition(v); v->UpdatePosition();
UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner);
v->UpdateAcceleration(); v->UpdateAcceleration();
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
@ -3334,8 +3334,8 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
} else { } else {
v->x_pos = gp.x; v->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
VehicleUpdatePosition(v); v->UpdatePosition();
if ((v->vehstatus & VS_HIDDEN) == 0) VehicleUpdateViewport(v, true); if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
continue; continue;
} }
} }
@ -3345,7 +3345,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
v->x_pos = gp.x; v->x_pos = gp.x;
v->y_pos = gp.y; v->y_pos = gp.y;
VehicleUpdatePosition(v); v->UpdatePosition();
/* update the Z position of the vehicle */ /* update the Z position of the vehicle */
int old_z = v->UpdateInclination(gp.new_tile != gp.old_tile, false); int old_z = v->UpdateInclination(gp.new_tile != gp.old_tile, false);
@ -3515,7 +3515,7 @@ static void ChangeTrainDirRandomly(Train *v)
* a bridge, because UpdateInclination() will put the vehicle under * a bridge, because UpdateInclination() will put the vehicle under
* the bridge in that case */ * the bridge in that case */
if (v->track != TRACK_BIT_WORMHOLE) { if (v->track != TRACK_BIT_WORMHOLE) {
VehicleUpdatePosition(v); v->UpdatePosition();
v->UpdateInclination(false, false); v->UpdateInclination(false, false);
} }
} }

View File

@ -206,7 +206,7 @@ uint Vehicle::Crash(bool flooded)
/* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */ /* We do not transfer reserver cargo back, so TotalCount() instead of StoredCount() */
if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.TotalCount(); if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.TotalCount();
v->vehstatus |= VS_CRASHED; v->vehstatus |= VS_CRASHED;
MarkSingleVehicleDirty(v); v->MarkAllViewportsDirty();
} }
/* Dirty some windows */ /* Dirty some windows */
@ -809,7 +809,7 @@ Vehicle::~Vehicle()
/* 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 (!(this->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(this); if (!(this->vehstatus & VS_HIDDEN)) this->MarkAllViewportsDirty();
Vehicle *v = this->Next(); Vehicle *v = this->Next();
this->SetNext(NULL); this->SetNext(NULL);
@ -1464,45 +1464,43 @@ void VehicleEnterDepot(Vehicle *v)
/** /**
* Update the position of the vehicle. This will update the hash that tells * Update the position of the vehicle. This will update the hash that tells
* which vehicles are on a tile. * which vehicles are on a tile.
* @param v The vehicle to update.
*/ */
void VehicleUpdatePosition(Vehicle *v) void Vehicle::UpdatePosition()
{ {
UpdateVehicleTileHash(v, false); UpdateVehicleTileHash(this, false);
} }
/** /**
* Update the vehicle on the viewport, updating the right hash and setting the * Update the vehicle on the viewport, updating the right hash and setting the
* new coordinates. * new coordinates.
* @param v The vehicle to update.
* @param dirty Mark the (new and old) coordinates of the vehicle as dirty. * @param dirty Mark the (new and old) coordinates of the vehicle as dirty.
*/ */
void VehicleUpdateViewport(Vehicle *v, bool dirty) void Vehicle::UpdateViewport(bool dirty)
{ {
int img = v->cur_image; int img = this->cur_image;
Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); Point pt = RemapCoords(this->x_pos + this->x_offs, this->y_pos + this->y_offs, this->z_pos);
const Sprite *spr = GetSprite(img, ST_NORMAL); const Sprite *spr = GetSprite(img, ST_NORMAL);
pt.x += spr->x_offs; pt.x += spr->x_offs;
pt.y += spr->y_offs; pt.y += spr->y_offs;
UpdateVehicleViewportHash(v, pt.x, pt.y); UpdateVehicleViewportHash(this, pt.x, pt.y);
Rect old_coord = v->coord; Rect old_coord = this->coord;
v->coord.left = pt.x; this->coord.left = pt.x;
v->coord.top = pt.y; this->coord.top = pt.y;
v->coord.right = pt.x + spr->width + 2 * ZOOM_LVL_BASE; this->coord.right = pt.x + spr->width + 2 * ZOOM_LVL_BASE;
v->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE; this->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE;
if (dirty) { if (dirty) {
if (old_coord.left == INVALID_COORD) { if (old_coord.left == INVALID_COORD) {
MarkSingleVehicleDirty(v); this->MarkAllViewportsDirty();
} else { } else {
MarkAllViewportsDirty( ::MarkAllViewportsDirty(
min(old_coord.left, v->coord.left), min(old_coord.left, this->coord.left),
min(old_coord.top, v->coord.top), min(old_coord.top, this->coord.top),
max(old_coord.right, v->coord.right) + 1 * ZOOM_LVL_BASE, max(old_coord.right, this->coord.right) + 1 * ZOOM_LVL_BASE,
max(old_coord.bottom, v->coord.bottom) + 1 * ZOOM_LVL_BASE max(old_coord.bottom, this->coord.bottom) + 1 * ZOOM_LVL_BASE
); );
} }
} }
@ -1510,21 +1508,19 @@ void VehicleUpdateViewport(Vehicle *v, bool dirty)
/** /**
* Update the position of the vehicle, and update the viewport. * Update the position of the vehicle, and update the viewport.
* @param v The vehicle to update.
*/ */
void VehicleUpdatePositionAndViewport(Vehicle *v) void Vehicle::UpdatePositionAndViewport()
{ {
VehicleUpdatePosition(v); this->UpdatePosition();
VehicleUpdateViewport(v, true); this->UpdateViewport(true);
} }
/** /**
* Marks viewports dirty where the vehicle's image is. * Marks viewports dirty where the vehicle's image is.
* @param v vehicle to mark dirty
*/ */
void MarkSingleVehicleDirty(const Vehicle *v) void Vehicle::MarkAllViewportsDirty() const
{ {
MarkAllViewportsDirty(v->coord.left, v->coord.top, v->coord.right + 1 * ZOOM_LVL_BASE, v->coord.bottom + 1 * ZOOM_LVL_BASE); ::MarkAllViewportsDirty(this->coord.left, this->coord.top, this->coord.right + 1 * ZOOM_LVL_BASE, this->coord.bottom + 1 * ZOOM_LVL_BASE);
} }
/** /**

View File

@ -696,6 +696,11 @@ public:
void UpdateVisualEffect(bool allow_power_change = true); void UpdateVisualEffect(bool allow_power_change = true);
void ShowVisualEffect() const; void ShowVisualEffect() const;
void UpdatePosition();
void UpdateViewport(bool dirty);
void UpdatePositionAndViewport();
void MarkAllViewportsDirty() const;
inline uint16 GetServiceInterval() const { return this->service_interval; } inline uint16 GetServiceInterval() const { return this->service_interval; }
inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; } inline void SetServiceInterval(uint16 interval) { this->service_interval = interval; }
@ -1067,14 +1072,12 @@ struct SpecializedVehicle : public Vehicle {
*/ */
inline void UpdateViewport(bool force_update, bool update_delta) inline void UpdateViewport(bool force_update, bool update_delta)
{ {
extern void VehicleUpdateViewport(Vehicle *v, bool dirty);
/* Explicitly choose method to call to prevent vtable dereference - /* Explicitly choose method to call to prevent vtable dereference -
* it gives ~3% runtime improvements in games with many vehicles */ * it gives ~3% runtime improvements in games with many vehicles */
if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction); if (update_delta) ((T *)this)->T::UpdateDeltaXY(this->direction);
SpriteID old_image = this->cur_image; SpriteID old_image = this->cur_image;
this->cur_image = ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP); this->cur_image = ((T *)this)->T::GetImage(this->direction, EIT_ON_MAP);
if (force_update || this->cur_image != old_image) VehicleUpdateViewport(this, true); if (force_update || this->cur_image != old_image) this->Vehicle::UpdateViewport(true);
} }
}; };

View File

@ -67,11 +67,6 @@ void CheckVehicleBreakdown(Vehicle *v);
void AgeVehicle(Vehicle *v); void AgeVehicle(Vehicle *v);
void VehicleEnteredDepotThisTick(Vehicle *v); void VehicleEnteredDepotThisTick(Vehicle *v);
void VehicleUpdatePosition(Vehicle *v);
void VehicleUpdateViewport(Vehicle *v, bool dirty);
void VehicleUpdatePositionAndViewport(Vehicle *v);
void MarkSingleVehicleDirty(const Vehicle *v);
UnitID GetFreeUnitNumber(VehicleType type); UnitID GetFreeUnitNumber(VehicleType type);
void VehicleEnterDepot(Vehicle *v); void VehicleEnterDepot(Vehicle *v);