Fix ship speed changes not updating image as per VCF_REDRAW_ON_SPEED_CHANGE
This commit is contained in:
@@ -420,6 +420,20 @@ static bool CheckShipLeaveDepot(Ship *v)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void UpdateShipSpeed(Vehicle *v, uint speed)
|
||||
{
|
||||
if (v->cur_speed == speed) return;
|
||||
|
||||
v->cur_speed = speed;
|
||||
|
||||
/* updates statusbar only if speed have changed to save CPU time */
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
|
||||
if (HasBit(v->vcache.cached_veh_flags, VCF_REDRAW_ON_SPEED_CHANGE)) {
|
||||
v->InvalidateImageCacheOfChain();
|
||||
}
|
||||
}
|
||||
|
||||
static bool ShipAccelerate(Vehicle *v)
|
||||
{
|
||||
uint spd;
|
||||
@@ -440,11 +454,7 @@ static bool ShipAccelerate(Vehicle *v)
|
||||
spd = std::min<uint>(spd, v->breakdown_severity);
|
||||
}
|
||||
|
||||
/* updates statusbar only if speed have changed to save CPU time */
|
||||
if (spd != v->cur_speed) {
|
||||
v->cur_speed = spd;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
UpdateShipSpeed(v, spd);
|
||||
|
||||
/* Convert direction-independent speed into direction-dependent speed. (old movement method) */
|
||||
spd = v->GetOldAdvanceSpeed(spd);
|
||||
@@ -626,7 +636,7 @@ static bool HandleSpeedOnAqueduct(Ship *v, TileIndex tile, TileIndex ramp)
|
||||
if (IsValidTile(scc.search_tile) &&
|
||||
(HasVehicleOnPos(ramp, VEH_SHIP, &scc, FindShipOnTile) ||
|
||||
HasVehicleOnPos(GetOtherTunnelBridgeEnd(ramp), VEH_SHIP, &scc, FindShipOnTile))) {
|
||||
v->cur_speed /= 4;
|
||||
UpdateShipSpeed(v, v->cur_speed / 4);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -688,7 +698,7 @@ static void CheckDistanceBetweenShips(TileIndex tile, Ship *v, TrackBits tracks,
|
||||
if (found) {
|
||||
|
||||
/* Speed adjustment related to distance. */
|
||||
v->cur_speed /= scc.search_tile == tile ? 8 : 2;
|
||||
UpdateShipSpeed(v, v->cur_speed / (scc.search_tile == tile ? 8 : 2));
|
||||
|
||||
/* Clean none wanted trackbits, including pathfinder track, TRACK_BIT_WORMHOLE and no 90 degree turns. */
|
||||
if (IsDiagonalTrack(track)) {
|
||||
@@ -756,10 +766,7 @@ static bool ShipMoveUpDownOnLock(Ship *v)
|
||||
int dz = ShipTestUpDownOnLock(v);
|
||||
if (dz == 0) return false;
|
||||
|
||||
if (v->cur_speed != 0) {
|
||||
v->cur_speed = 0;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
UpdateShipSpeed(v, 0);
|
||||
|
||||
if ((v->tick_counter & 7) == 0) {
|
||||
v->z_pos += dz;
|
||||
@@ -931,7 +938,7 @@ static void ShipController(Ship *v)
|
||||
|
||||
default:
|
||||
/* Stop for rotation */
|
||||
v->cur_speed = 0;
|
||||
UpdateShipSpeed(v, 0);
|
||||
v->direction = new_direction;
|
||||
/* Remember our current location to avoid movement glitch */
|
||||
v->rotation_x_pos = v->x_pos;
|
||||
@@ -971,7 +978,7 @@ reverse_direction:
|
||||
/* Remember our current location to avoid movement glitch */
|
||||
v->rotation_x_pos = v->x_pos;
|
||||
v->rotation_y_pos = v->y_pos;
|
||||
v->cur_speed = 0;
|
||||
UpdateShipSpeed(v, 0);
|
||||
v->path.clear();
|
||||
goto getout;
|
||||
}
|
||||
|
Reference in New Issue
Block a user