mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::swap() instead of Swap() (#13883)
parent
8a53ccf8f1
commit
79ef4e98fe
|
@ -258,7 +258,7 @@ struct AIConfigWindow : public Window {
|
||||||
|
|
||||||
case WID_AIC_MOVE_UP:
|
case WID_AIC_MOVE_UP:
|
||||||
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
|
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot - 1))) {
|
||||||
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
|
std::swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot - 1]);
|
||||||
this->selected_slot = CompanyID(this->selected_slot - 1);
|
this->selected_slot = CompanyID(this->selected_slot - 1);
|
||||||
this->vscroll->ScrollTowards(this->selected_slot.base());
|
this->vscroll->ScrollTowards(this->selected_slot.base());
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
|
@ -267,7 +267,7 @@ struct AIConfigWindow : public Window {
|
||||||
|
|
||||||
case WID_AIC_MOVE_DOWN:
|
case WID_AIC_MOVE_DOWN:
|
||||||
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
|
if (IsEditable(this->selected_slot) && IsEditable((CompanyID)(this->selected_slot + 1))) {
|
||||||
Swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
|
std::swap(GetGameSettings().ai_config[this->selected_slot], GetGameSettings().ai_config[this->selected_slot + 1]);
|
||||||
++this->selected_slot;
|
++this->selected_slot;
|
||||||
this->vscroll->ScrollTowards(this->selected_slot.base());
|
this->vscroll->ScrollTowards(this->selected_slot.base());
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
|
|
|
@ -476,7 +476,7 @@ public:
|
||||||
int w = as->size_x;
|
int w = as->size_x;
|
||||||
int h = as->size_y;
|
int h = as->size_y;
|
||||||
Direction rotation = as->layouts[_selected_airport_layout].rotation;
|
Direction rotation = as->layouts[_selected_airport_layout].rotation;
|
||||||
if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
|
if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h);
|
||||||
SetTileSelectSize(w, h);
|
SetTileSelectSize(w, h);
|
||||||
|
|
||||||
this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
|
this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
|
||||||
|
|
|
@ -476,14 +476,14 @@ static Colours GenerateCompanyColour()
|
||||||
/* And randomize it */
|
/* And randomize it */
|
||||||
for (uint i = 0; i < 100; i++) {
|
for (uint i = 0; i < 100; i++) {
|
||||||
uint r = Random();
|
uint r = Random();
|
||||||
Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
|
std::swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bubble sort it according to the values in table 1 */
|
/* Bubble sort it according to the values in table 1 */
|
||||||
for (uint i = 0; i < COLOUR_END; i++) {
|
for (uint i = 0; i < COLOUR_END; i++) {
|
||||||
for (uint j = 1; j < COLOUR_END; j++) {
|
for (uint j = 1; j < COLOUR_END; j++) {
|
||||||
if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
|
if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
|
||||||
Swap(colours[j - 1], colours[j]);
|
std::swap(colours[j - 1], colours[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ static Colours GenerateCompanyColour()
|
||||||
if (similar == INVALID_COLOUR) break;
|
if (similar == INVALID_COLOUR) break;
|
||||||
|
|
||||||
for (uint i = 1; i < COLOUR_END; i++) {
|
for (uint i = 1; i < COLOUR_END; i++) {
|
||||||
if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]);
|
if (colours[i - 1] == similar) std::swap(colours[i - 1], colours[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,19 +271,6 @@ constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) no
|
||||||
|
|
||||||
constexpr bool IsInsideMM(const ConvertibleThroughBase auto x, const size_t min, const size_t max) noexcept { return IsInsideMM(x.base(), min, max); }
|
constexpr bool IsInsideMM(const ConvertibleThroughBase auto x, const size_t min, const size_t max) noexcept { return IsInsideMM(x.base(), min, max); }
|
||||||
|
|
||||||
/**
|
|
||||||
* Type safe swap operation
|
|
||||||
* @param a variable to swap with b
|
|
||||||
* @param b variable to swap with a
|
|
||||||
*/
|
|
||||||
template <typename T>
|
|
||||||
constexpr void Swap(T &a, T &b)
|
|
||||||
{
|
|
||||||
T t = a;
|
|
||||||
a = b;
|
|
||||||
b = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a "fract" value 0..255 to "percent" value 0..100
|
* Converts a "fract" value 0..255 to "percent" value 0..100
|
||||||
* @param i value to convert, range 0..255
|
* @param i value to convert, range 0..255
|
||||||
|
|
|
@ -834,7 +834,7 @@ static void GenerateTerrain(int type, uint flag)
|
||||||
uint w = templ->width;
|
uint w = templ->width;
|
||||||
uint h = templ->height;
|
uint h = templ->height;
|
||||||
|
|
||||||
if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
|
if (DiagDirToAxis(direction) == AXIS_Y) std::swap(w, h);
|
||||||
|
|
||||||
const uint8_t *p = templ->data;
|
const uint8_t *p = templ->data;
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ bool AirportSpec::IsWithinMapBounds(uint8_t table, TileIndex tile) const
|
||||||
|
|
||||||
uint8_t w = this->size_x;
|
uint8_t w = this->size_x;
|
||||||
uint8_t h = this->size_y;
|
uint8_t h = this->size_y;
|
||||||
if (this->layouts[table].rotation == DIR_E || this->layouts[table].rotation == DIR_W) Swap(w, h);
|
if (this->layouts[table].rotation == DIR_E || this->layouts[table].rotation == DIR_W) std::swap(w, h);
|
||||||
|
|
||||||
return TileX(tile) + w < Map::SizeX() &&
|
return TileX(tile) + w < Map::SizeX() &&
|
||||||
TileY(tile) + h < Map::SizeY();
|
TileY(tile) + h < Map::SizeY();
|
||||||
|
|
|
@ -418,7 +418,7 @@ TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets,
|
||||||
|
|
||||||
/* Swap width and height depending on axis for railway stations */
|
/* Swap width and height depending on axis for railway stations */
|
||||||
if (axis == INVALID_AXIS && HasStationTileRail(tile)) axis = GetRailStationAxis(tile);
|
if (axis == INVALID_AXIS && HasStationTileRail(tile)) axis = GetRailStationAxis(tile);
|
||||||
if (axis == AXIS_Y) Swap(x, y);
|
if (axis == AXIS_Y) std::swap(x, y);
|
||||||
|
|
||||||
/* Make sure we never roam outside of the map, better wrap in that case */
|
/* Make sure we never roam outside of the map, better wrap in that case */
|
||||||
return Map::WrapToMap(tile + TileDiffXY(x, y));
|
return Map::WrapToMap(tile + TileDiffXY(x, y));
|
||||||
|
|
|
@ -110,8 +110,8 @@ uint32_t GetPlatformInfo(Axis axis, uint8_t tile, int platforms, int length, int
|
||||||
uint32_t retval = 0;
|
uint32_t retval = 0;
|
||||||
|
|
||||||
if (axis == AXIS_X) {
|
if (axis == AXIS_X) {
|
||||||
Swap(platforms, length);
|
std::swap(platforms, length);
|
||||||
Swap(x, y);
|
std::swap(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (centred) {
|
if (centred) {
|
||||||
|
|
|
@ -208,7 +208,7 @@ static void PlaceRail_Station(TileIndex tile)
|
||||||
} else {
|
} else {
|
||||||
int w = _settings_client.gui.station_numtracks;
|
int w = _settings_client.gui.station_numtracks;
|
||||||
int h = _settings_client.gui.station_platlength;
|
int h = _settings_client.gui.station_platlength;
|
||||||
if (!_station_gui.axis) Swap(w, h);
|
if (!_station_gui.axis) std::swap(w, h);
|
||||||
|
|
||||||
StationPickerSelection params = _station_gui;
|
StationPickerSelection params = _station_gui;
|
||||||
RailType rt = _cur_railtype;
|
RailType rt = _cur_railtype;
|
||||||
|
@ -372,7 +372,7 @@ static void BuildRailClick_Remove(Window *w)
|
||||||
if (!_settings_client.gui.station_dragdrop) {
|
if (!_settings_client.gui.station_dragdrop) {
|
||||||
int x = _settings_client.gui.station_numtracks;
|
int x = _settings_client.gui.station_numtracks;
|
||||||
int y = _settings_client.gui.station_platlength;
|
int y = _settings_client.gui.station_platlength;
|
||||||
if (_station_gui.axis == 0) Swap(x, y);
|
if (_station_gui.axis == 0) std::swap(x, y);
|
||||||
SetTileSelectSize(x, y);
|
SetTileSelectSize(x, y);
|
||||||
} else {
|
} else {
|
||||||
VpSetPlaceSizingLimit(_settings_game.station.station_spread);
|
VpSetPlaceSizingLimit(_settings_game.station.station_spread);
|
||||||
|
@ -935,7 +935,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end)
|
||||||
uint numtracks = ta.w;
|
uint numtracks = ta.w;
|
||||||
uint platlength = ta.h;
|
uint platlength = ta.h;
|
||||||
|
|
||||||
if (_station_gui.axis == AXIS_X) Swap(numtracks, platlength);
|
if (_station_gui.axis == AXIS_X) std::swap(numtracks, platlength);
|
||||||
|
|
||||||
StationPickerSelection params = _station_gui;
|
StationPickerSelection params = _station_gui;
|
||||||
RailType rt = _cur_railtype;
|
RailType rt = _cur_railtype;
|
||||||
|
@ -1132,7 +1132,7 @@ public:
|
||||||
} else {
|
} else {
|
||||||
int x = _settings_client.gui.station_numtracks;
|
int x = _settings_client.gui.station_numtracks;
|
||||||
int y = _settings_client.gui.station_platlength;
|
int y = _settings_client.gui.station_platlength;
|
||||||
if (_station_gui.axis == AXIS_X) Swap(x, y);
|
if (_station_gui.axis == AXIS_X) std::swap(x, y);
|
||||||
if (!_remove_button_clicked) {
|
if (!_remove_button_clicked) {
|
||||||
SetTileSelectSize(x, y);
|
SetTileSelectSize(x, y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1065,7 +1065,7 @@ bool AfterLoadGame()
|
||||||
case MP_ROAD:
|
case MP_ROAD:
|
||||||
/* Swap m3 and m4, so the track type for rail crossings is the
|
/* Swap m3 and m4, so the track type for rail crossings is the
|
||||||
* same as for normal rail. */
|
* same as for normal rail. */
|
||||||
Swap(t.m3(), t.m4());
|
std::swap(t.m3(), t.m4());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
|
|
|
@ -272,7 +272,7 @@
|
||||||
if (!IsRailTile(tile)) return false;
|
if (!IsRailTile(tile)) return false;
|
||||||
if (from == to || ScriptMap::DistanceManhattan(from, tile) != 1 || ScriptMap::DistanceManhattan(tile, to) != 1) return false;
|
if (from == to || ScriptMap::DistanceManhattan(from, tile) != 1 || ScriptMap::DistanceManhattan(tile, to) != 1) return false;
|
||||||
|
|
||||||
if (to < from) ::Swap(from, to);
|
if (to < from) std::swap(from, to);
|
||||||
|
|
||||||
if (tile - from == 1) {
|
if (tile - from == 1) {
|
||||||
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0;
|
if (to - tile == 1) return (GetRailTracks(tile) & RAILTRACK_NE_SW) != 0;
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
inline void SwapShares(FlowStat &other)
|
inline void SwapShares(FlowStat &other)
|
||||||
{
|
{
|
||||||
this->shares.swap(other.shares);
|
this->shares.swap(other.shares);
|
||||||
Swap(this->unrestricted, other.unrestricted);
|
std::swap(this->unrestricted, other.unrestricted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2539,7 +2539,7 @@ CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airpor
|
||||||
Direction rotation = as->layouts[layout].rotation;
|
Direction rotation = as->layouts[layout].rotation;
|
||||||
int w = as->size_x;
|
int w = as->size_x;
|
||||||
int h = as->size_y;
|
int h = as->size_y;
|
||||||
if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
|
if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h);
|
||||||
TileArea airport_area = TileArea(tile, w, h);
|
TileArea airport_area = TileArea(tile, w, h);
|
||||||
|
|
||||||
if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
|
if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
|
||||||
|
@ -3718,7 +3718,7 @@ static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, i
|
||||||
x &= 0xF;
|
x &= 0xF;
|
||||||
y &= 0xF;
|
y &= 0xF;
|
||||||
|
|
||||||
if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
|
if (DiagDirToAxis(dir) != AXIS_X) std::swap(x, y);
|
||||||
if (y == TILE_SIZE / 2) {
|
if (y == TILE_SIZE / 2) {
|
||||||
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
|
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
|
||||||
stop &= TILE_SIZE - 1;
|
stop &= TILE_SIZE - 1;
|
||||||
|
@ -4822,9 +4822,9 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const
|
||||||
if (interval2 >= new_max) return StationID::Invalid(); // Only the two excluded stations in the map.
|
if (interval2 >= new_max) return StationID::Invalid(); // Only the two excluded stations in the map.
|
||||||
new_max -= interval2;
|
new_max -= interval2;
|
||||||
if (begin > begin2) {
|
if (begin > begin2) {
|
||||||
Swap(begin, begin2);
|
std::swap(begin, begin2);
|
||||||
Swap(end, end2);
|
std::swap(end, end2);
|
||||||
Swap(interval, interval2);
|
std::swap(interval, interval2);
|
||||||
}
|
}
|
||||||
rand = RandomRange(new_max);
|
rand = RandomRange(new_max);
|
||||||
SharesMap::const_iterator it3 = this->shares.upper_bound(this->unrestricted);
|
SharesMap::const_iterator it3 = this->shares.upper_bound(this->unrestricted);
|
||||||
|
|
|
@ -28,8 +28,8 @@ OrthogonalTileArea::OrthogonalTileArea(TileIndex start, TileIndex end)
|
||||||
uint ex = TileX(end);
|
uint ex = TileX(end);
|
||||||
uint ey = TileY(end);
|
uint ey = TileY(end);
|
||||||
|
|
||||||
if (sx > ex) Swap(sx, ex);
|
if (sx > ex) std::swap(sx, ex);
|
||||||
if (sy > ey) Swap(sy, ey);
|
if (sy > ey) std::swap(sy, ey);
|
||||||
|
|
||||||
this->tile = TileXY(sx, sy);
|
this->tile = TileXY(sx, sy);
|
||||||
this->w = ex - sx + 1;
|
this->w = ex - sx + 1;
|
||||||
|
|
|
@ -1643,12 +1643,12 @@ void ReverseTrainSwapVeh(Train *v, int l, int r)
|
||||||
a->vehstatus.Set(VehState::Hidden, b_hidden);
|
a->vehstatus.Set(VehState::Hidden, b_hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
Swap(a->track, b->track);
|
std::swap(a->track, b->track);
|
||||||
Swap(a->direction, b->direction);
|
std::swap(a->direction, b->direction);
|
||||||
Swap(a->x_pos, b->x_pos);
|
std::swap(a->x_pos, b->x_pos);
|
||||||
Swap(a->y_pos, b->y_pos);
|
std::swap(a->y_pos, b->y_pos);
|
||||||
Swap(a->tile, b->tile);
|
std::swap(a->tile, b->tile);
|
||||||
Swap(a->z_pos, b->z_pos);
|
std::swap(a->z_pos, b->z_pos);
|
||||||
|
|
||||||
SwapTrainFlags(&a->gv_flags, &b->gv_flags);
|
SwapTrainFlags(&a->gv_flags, &b->gv_flags);
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,7 @@ CommandCost CmdBuildBridge(DoCommandFlags flags, TileIndex tile_end, TileIndex t
|
||||||
return CommandCost(STR_ERROR_START_AND_END_MUST_BE_IN);
|
return CommandCost(STR_ERROR_START_AND_END_MUST_BE_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tile_end < tile_start) Swap(tile_start, tile_end);
|
if (tile_end < tile_start) std::swap(tile_start, tile_end);
|
||||||
|
|
||||||
uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end);
|
uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end);
|
||||||
if (transport_type != TRANSPORT_WATER) {
|
if (transport_type != TRANSPORT_WATER) {
|
||||||
|
|
|
@ -793,7 +793,7 @@ void EndSpriteCombine()
|
||||||
*/
|
*/
|
||||||
static bool IsInRangeInclusive(int begin, int end, int check)
|
static bool IsInRangeInclusive(int begin, int end, int check)
|
||||||
{
|
{
|
||||||
if (begin > end) Swap(begin, end);
|
if (begin > end) std::swap(begin, end);
|
||||||
return begin <= check && check <= end;
|
return begin <= check && check <= end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2672,8 +2672,8 @@ void UpdateTileSelection()
|
||||||
if (_thd.IsDraggingDiagonal()) {
|
if (_thd.IsDraggingDiagonal()) {
|
||||||
new_diagonal = true;
|
new_diagonal = true;
|
||||||
} else {
|
} else {
|
||||||
if (x1 >= x2) Swap(x1, x2);
|
if (x1 >= x2) std::swap(x1, x2);
|
||||||
if (y1 >= y2) Swap(y1, y2);
|
if (y1 >= y2) std::swap(y1, y2);
|
||||||
}
|
}
|
||||||
_thd.new_pos.x = x1;
|
_thd.new_pos.x = x1;
|
||||||
_thd.new_pos.y = y1;
|
_thd.new_pos.y = y1;
|
||||||
|
@ -2936,7 +2936,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
|
||||||
uint h0, h1; // Start height and end height.
|
uint h0, h1; // Start height and end height.
|
||||||
|
|
||||||
if (start_tile == end_tile) return 0;
|
if (start_tile == end_tile) return 0;
|
||||||
if (swap) Swap(start_tile, end_tile);
|
if (swap) std::swap(start_tile, end_tile);
|
||||||
|
|
||||||
switch (style & HT_DRAG_MASK) {
|
switch (style & HT_DRAG_MASK) {
|
||||||
case HT_RECT:
|
case HT_RECT:
|
||||||
|
@ -3007,7 +3007,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swap) Swap(h0, h1);
|
if (swap) std::swap(h0, h1);
|
||||||
return (int)(h1 - h0) * TILE_HEIGHT_STEP;
|
return (int)(h1 - h0) * TILE_HEIGHT_STEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue