Fix ship speed changes not updating image as per VCF_REDRAW_ON_SPEED_CHANGE

This commit is contained in:
Jonathan G Rennison
2021-08-29 22:04:06 +01:00
parent 4cf6b1e923
commit 1af37ef845

View File

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