mirror of https://github.com/OpenTTD/OpenTTD
(svn r23714) -Codechange: don't mix Viewport with non-viewport code
parent
0d929e877f
commit
091bc25a90
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue