Codechange: Remove min/max functions in favour of STL variants (#8502)

This commit is contained in:
Charles Pigott
2021-01-08 10:16:18 +00:00
committed by GitHub
parent c1fddb9a6a
commit 9b800a96ed
181 changed files with 900 additions and 954 deletions

View File

@@ -234,8 +234,8 @@ static height_t TGPGetMaxHeight()
{ 12, 19, 25, 31, 67, 75, 87 }, ///< Alpinist
};
int max_height_from_table = max_height[_settings_game.difficulty.terrain_type][min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS];
return I2H(min(max_height_from_table, _settings_game.construction.max_heightlevel));
int max_height_from_table = max_height[_settings_game.difficulty.terrain_type][std::min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS];
return I2H(std::min<uint>(max_height_from_table, _settings_game.construction.max_heightlevel));
}
/**
@@ -270,7 +270,7 @@ static amplitude_t GetAmplitude(int frequency)
/* Get the table index, and return that value if possible. */
int index = frequency - MAX_TGP_FREQUENCIES + lengthof(amplitudes[smoothness]);
amplitude_t amplitude = amplitudes[smoothness][max(0, index)];
amplitude_t amplitude = amplitudes[smoothness][std::max(0, index)];
if (index >= 0) return amplitude;
/* We need to extrapolate the amplitude. */
@@ -349,7 +349,7 @@ static void HeightMapGenerate()
/* Trying to apply noise to uninitialized height map */
assert(_height_map.h != nullptr);
int start = max(MAX_TGP_FREQUENCIES - (int)min(MapLogX(), MapLogY()), 0);
int start = std::max(MAX_TGP_FREQUENCIES - (int)std::min(MapLogX(), MapLogY()), 0);
bool first = true;
for (int frequency = start; frequency < MAX_TGP_FREQUENCIES; frequency++) {
@@ -725,7 +725,7 @@ static double perlin_coast_noise_2D(const double x, const double y, const double
*/
static void HeightMapCoastLines(uint8 water_borders)
{
int smallest_size = min(_settings_game.game_creation.map_x, _settings_game.game_creation.map_y);
int smallest_size = std::min(_settings_game.game_creation.map_x, _settings_game.game_creation.map_y);
const int margin = 4;
int y, x;
double max_x;
@@ -736,7 +736,7 @@ static void HeightMapCoastLines(uint8 water_borders)
if (HasBit(water_borders, BORDER_NE)) {
/* Top right */
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
max_x = max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
max_x = std::max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = 0; x < max_x; x++) {
_height_map.height(x, y) = 0;
@@ -746,7 +746,7 @@ static void HeightMapCoastLines(uint8 water_borders)
if (HasBit(water_borders, BORDER_SW)) {
/* Bottom left */
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45, 67) + 0.75) * 8);
max_x = max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
max_x = std::max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
_height_map.height(x, y) = 0;
@@ -759,7 +759,7 @@ static void HeightMapCoastLines(uint8 water_borders)
if (HasBit(water_borders, BORDER_NW)) {
/* Top left */
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
max_y = max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
max_y = std::max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = 0; y < max_y; y++) {
_height_map.height(x, y) = 0;
@@ -769,7 +769,7 @@ static void HeightMapCoastLines(uint8 water_borders)
if (HasBit(water_borders, BORDER_SE)) {
/* Bottom right */
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
max_y = max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
max_y = std::max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
_height_map.height(x, y) = 0;
@@ -809,7 +809,7 @@ static void HeightMapSmoothCoastInDirection(int org_x, int org_y, int dir_x, int
* Soften the coast slope */
for (depth = 0; IsValidXY(x, y) && depth <= max_coast_Smooth_depth; depth++, x += dir_x, y += dir_y) {
h = _height_map.height(x, y);
h = min(h, h_prev + (4 + depth)); // coast softening formula
h = std::min<uint>(h, h_prev + (4 + depth)); // coast softening formula
_height_map.height(x, y) = h;
h_prev = h;
}
@@ -842,13 +842,13 @@ static void HeightMapSmoothSlopes(height_t dh_max)
{
for (int y = 0; y <= (int)_height_map.size_y; y++) {
for (int x = 0; x <= (int)_height_map.size_x; x++) {
height_t h_max = min(_height_map.height(x > 0 ? x - 1 : x, y), _height_map.height(x, y > 0 ? y - 1 : y)) + dh_max;
height_t h_max = std::min(_height_map.height(x > 0 ? x - 1 : x, y), _height_map.height(x, y > 0 ? y - 1 : y)) + dh_max;
if (_height_map.height(x, y) > h_max) _height_map.height(x, y) = h_max;
}
}
for (int y = _height_map.size_y; y >= 0; y--) {
for (int x = _height_map.size_x; x >= 0; x--) {
height_t h_max = min(_height_map.height(x < _height_map.size_x ? x + 1 : x, y), _height_map.height(x, y < _height_map.size_y ? y + 1 : y)) + dh_max;
height_t h_max = std::min(_height_map.height(x < _height_map.size_x ? x + 1 : x, y), _height_map.height(x, y < _height_map.size_y ? y + 1 : y)) + dh_max;
if (_height_map.height(x, y) > h_max) _height_map.height(x, y) = h_max;
}
}