1
0
Fork 0

(svn r23714) -Codechange: don't mix Viewport with non-viewport code

release/1.2
truebrain 2012-01-02 13:44:37 +00:00
parent 0d929e877f
commit 091bc25a90
6 changed files with 26 additions and 14 deletions

View File

@ -480,6 +480,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->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);

View File

@ -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. * 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 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. * @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; byte old_z = this->z_pos;
@ -239,7 +239,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
this->UpdateZPosition(); this->UpdateZPosition();
} }
this->UpdateViewport(true, turned); this->UpdateViewport(true, update_delta);
return old_z; return old_z;
} }

View File

@ -987,6 +987,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->UpdateInclination(true, true); v->UpdateInclination(true, true);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); 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 */ /* 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->UpdateInclination(true, true); v->UpdateInclination(true, true);
return true; return true;
} }
@ -1277,6 +1279,7 @@ again:
} }
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true; return true;
} }
@ -1342,6 +1345,7 @@ again:
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, true));
return true; return true;
} }
@ -1430,6 +1434,7 @@ again:
v->frame++; v->frame++;
v->x_pos = x; v->x_pos = x;
v->y_pos = y; v->y_pos = y;
VehicleUpdatePosition(v);
RoadZPosAffectSpeed(v, v->UpdateInclination(true, false)); RoadZPosAffectSpeed(v, v->UpdateInclination(true, false));
return true; return true;
} }
@ -1478,6 +1483,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);
RoadZPosAffectSpeed(v, v->UpdateInclination(false, true)); RoadZPosAffectSpeed(v, v->UpdateInclination(false, true));
return true; return true;
} }

View File

@ -326,7 +326,7 @@ static bool CheckShipLeaveDepot(Ship *v)
v->vehstatus &= ~VS_HIDDEN; v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0; v->cur_speed = 0;
v->UpdateViewport(false, true); v->UpdateViewport(true, true);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
PlayShipSound(v); PlayShipSound(v);
@ -601,6 +601,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->UpdateViewport(true, true); v->UpdateViewport(true, true);
return; return;

View File

@ -1542,12 +1542,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->UpdateInclination(true, true); v->UpdateInclination(true, true);
return; return;
} }
} }
} }
VehicleUpdatePosition(v);
v->UpdateViewport(true, true); v->UpdateViewport(true, true);
} }
@ -2155,10 +2157,8 @@ static bool CheckTrainStayInDepot(Train *v)
v->vehstatus &= ~VS_HIDDEN; v->vehstatus &= ~VS_HIDDEN;
v->cur_speed = 0; v->cur_speed = 0;
v->UpdateDeltaXY(v->direction); v->UpdateViewport(true, true);
v->cur_image = v->GetImage(v->direction, EIT_ON_MAP);
VehicleUpdatePosition(v); VehicleUpdatePosition(v);
VehicleUpdateViewport(v, false);
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);
@ -3321,6 +3321,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);
/* 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);
@ -3488,7 +3489,10 @@ static void ChangeTrainDirRandomly(Train *v)
/* Refrain from updating the z position of the vehicle when on /* Refrain from updating the z position of the vehicle when on
* 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) v->UpdateInclination(false, false); if (v->track != TRACK_BIT_WORMHOLE) {
VehicleUpdatePosition(v);
v->UpdateInclination(false, false);
}
} }
} while ((v = v->Next()) != NULL); } while ((v = v->Next()) != NULL);
} }

View File

@ -986,19 +986,19 @@ struct SpecializedVehicle : public Vehicle {
/** /**
* Update vehicle sprite- and position caches * Update vehicle sprite- and position caches
* @param moved Was the vehicle moved? * @param force_update Force updating the vehicle on the viewport.
* @param turned Did the vehicle direction change? * @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 - /* 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 (turned) ((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 (moved || this->cur_image != old_image) VehicleUpdatePositionAndViewport(this); if (force_update || this->cur_image != old_image) VehicleUpdateViewport(this, true);
} }
}; };