diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-04-02 23:51:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-02 23:51:08 +0200 |
commit | 2481ea27ce0f423f3e6f3522539d20e1500cf572 (patch) | |
tree | 73251dcbf9146d7499177f59b266d8c60b0eaae7 /src/mapgen | |
parent | e98fd934ce17a7af0b4629fc88158373303c88a0 (diff) | |
download | minetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.tar.gz minetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.tar.bz2 minetest-2481ea27ce0f423f3e6f3522539d20e1500cf572.zip |
Fix many issues reported by clang-tidy (#7189)
* Fix many issues reported by clang-tidy
We have many issues in code related to some performance to float <-> double.
Clang-tidy reported it in performance-type-promotion-in-math-fn
I fixed many of them. It's not ready for a promote to blocking
Also fix some value which should be const-ref
Diffstat (limited to 'src/mapgen')
-rw-r--r-- | src/mapgen/cavegen.cpp | 3 | ||||
-rw-r--r-- | src/mapgen/dungeongen.cpp | 3 | ||||
-rw-r--r-- | src/mapgen/mapgen_carpathian.cpp | 6 | ||||
-rw-r--r-- | src/mapgen/mapgen_fractal.cpp | 21 | ||||
-rw-r--r-- | src/mapgen/mapgen_v7.cpp | 11 | ||||
-rw-r--r-- | src/mapgen/mapgen_valleys.cpp | 15 | ||||
-rw-r--r-- | src/mapgen/mg_ore.cpp | 4 |
7 files changed, 34 insertions, 29 deletions
diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp index d4cb5733b..6f571ba1f 100644 --- a/src/mapgen/cavegen.cpp +++ b/src/mapgen/cavegen.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "util/numeric.h" +#include <cmath> #include "map.h" #include "mapgen.h" #include "mapgen_v5.h" @@ -248,7 +249,7 @@ bool CavernsNoise::generateCaverns(MMVManip *vm, v3s16 nmin, v3s16 nmax) VoxelArea::add_y(em, vi, -1), cavern_amp_index++) { content_t c = vm->m_data[vi].getContent(); - float n_absamp_cavern = fabs(noise_cavern->result[index3d]) * + float n_absamp_cavern = std::fabs(noise_cavern->result[index3d]) * cavern_amp[cavern_amp_index]; // Disable CavesRandomWalk at a safe distance from caverns // to avoid excessively spreading liquids in caverns. diff --git a/src/mapgen/dungeongen.cpp b/src/mapgen/dungeongen.cpp index b5d7ec7ad..a4e8c74dc 100644 --- a/src/mapgen/dungeongen.cpp +++ b/src/mapgen/dungeongen.cpp @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "dungeongen.h" +#include <cmath> #include "mapgen.h" #include "voxel.h" #include "noise.h" @@ -121,7 +122,7 @@ void DungeonGen::generate(MMVManip *vm, u32 bseed, v3s16 nmin, v3s16 nmax) } // Add them - for (u32 i = 0; i < floor(nval_density); i++) + for (u32 i = 0; i < std::floor(nval_density); i++) makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE); // Optionally convert some structure to alternative structure diff --git a/src/mapgen/mapgen_carpathian.cpp b/src/mapgen/mapgen_carpathian.cpp index 0cde17037..db276ffba 100644 --- a/src/mapgen/mapgen_carpathian.cpp +++ b/src/mapgen/mapgen_carpathian.cpp @@ -205,7 +205,7 @@ inline float MapgenCarpathian::getLerp(float noise1, float noise2, float mod) float MapgenCarpathian::getSteps(float noise) { float w = 0.5f; - float k = floor(noise / w); + float k = std::floor(noise / w); float f = (noise - k * w) / w; float s = std::fmin(2.f * f, 1.f); return (k + s) * w; @@ -342,8 +342,8 @@ float MapgenCarpathian::terrainLevelAtPoint(s16 x, s16 z) std::fmax(std::fmin(hill1, hill2), std::fmin(hill3, hill4)); // Rolling hills - float hill_mnt = hilliness * pow(n_hills, 2.f); - float hills = pow(hter, 3.f) * hill_mnt; + float hill_mnt = hilliness * std::pow(n_hills, 2.f); + float hills = std::pow(hter, 3.f) * hill_mnt; // Ridged mountains float ridge_mnt = hilliness * (1.f - std::fabs(n_ridge_mnt)); diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp index d0c670acc..45526b138 100644 --- a/src/mapgen/mapgen_fractal.cpp +++ b/src/mapgen/mapgen_fractal.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen.h" +#include <cmath> #include "voxel.h" #include "noise.h" #include "mapblock.h" @@ -306,45 +307,45 @@ bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z) break; case 6: // 3D "Christmas Tree" // Altering the formula here is necessary to avoid division by zero - if (fabs(oz) < 0.000000001f) { + if (std::fabs(oz) < 0.000000001f) { nx = ox * ox - oy * oy - oz * oz + cx; ny = 2.0f * oy * ox + cy; nz = 4.0f * oz * ox + cz; } else { - float a = (2.0f * ox) / (sqrt(oy * oy + oz * oz)); + float a = (2.0f * ox) / (std::sqrt(oy * oy + oz * oz)); nx = ox * ox - oy * oy - oz * oz + cx; ny = a * (oy * oy - oz * oz) + cy; nz = a * 2.0f * oy * oz + cz; } break; case 7: // 3D "Mandelbulb" - if (fabs(oy) < 0.000000001f) { + if (std::fabs(oy) < 0.000000001f) { nx = ox * ox - oz * oz + cx; ny = cy; - nz = -2.0f * oz * sqrt(ox * ox) + cz; + nz = -2.0f * oz * std::sqrt(ox * ox) + cz; } else { float a = 1.0f - (oz * oz) / (ox * ox + oy * oy); nx = (ox * ox - oy * oy) * a + cx; ny = 2.0f * ox * oy * a + cy; - nz = -2.0f * oz * sqrt(ox * ox + oy * oy) + cz; + nz = -2.0f * oz * std::sqrt(ox * ox + oy * oy) + cz; } break; case 8: // 3D "Cosine Mandelbulb" - if (fabs(oy) < 0.000000001f) { + if (std::fabs(oy) < 0.000000001f) { nx = 2.0f * ox * oz + cx; ny = 4.0f * oy * oz + cy; nz = oz * oz - ox * ox - oy * oy + cz; } else { - float a = (2.0f * oz) / sqrt(ox * ox + oy * oy); + float a = (2.0f * oz) / std::sqrt(ox * ox + oy * oy); nx = (ox * ox - oy * oy) * a + cx; ny = 2.0f * ox * oy * a + cy; nz = oz * oz - ox * ox - oy * oy + cz; } break; case 9: // 4D "Mandelbulb" - float rxy = sqrt(ox * ox + oy * oy); - float rxyz = sqrt(ox * ox + oy * oy + oz * oz); - if (fabs(ow) < 0.000000001f && fabs(oz) < 0.000000001f) { + float rxy = std::sqrt(ox * ox + oy * oy); + float rxyz = std::sqrt(ox * ox + oy * oy + oz * oz); + if (std::fabs(ow) < 0.000000001f && std::fabs(oz) < 0.000000001f) { nx = (ox * ox - oy * oy) + cx; ny = 2.0f * ox * oy + cy; nz = -2.0f * rxy * oz + cz; diff --git a/src/mapgen/mapgen_v7.cpp b/src/mapgen/mapgen_v7.cpp index 55a81c531..fba2defef 100644 --- a/src/mapgen/mapgen_v7.cpp +++ b/src/mapgen/mapgen_v7.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen.h" +#include <cmath> #include "voxel.h" #include "noise.h" #include "mapblock.h" @@ -228,7 +229,7 @@ int MapgenV7::getSpawnLevelAtPoint(v2s16 p) if (spflags & MGV7_RIDGES) { float width = 0.2; float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2; - if (fabs(uwatern) <= width) + if (std::fabs(uwatern) <= width) return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point } @@ -426,9 +427,9 @@ bool MapgenV7::getFloatlandMountainFromMap(int idx_xyz, int idx_xz, s16 y) { // Make rim 2 nodes thick to match floatland base terrain float density_gradient = (y >= floatland_level) ? - -pow((float)(y - floatland_level) / float_mount_height, + -std::pow((float)(y - floatland_level) / float_mount_height, float_mount_exponent) : - -pow((float)(floatland_level - 1 - y) / float_mount_height, + -std::pow((float)(floatland_level - 1 - y) / float_mount_height, float_mount_exponent); float floatn = noise_mountain->result[idx_xyz] + float_mount_density; @@ -456,7 +457,7 @@ void MapgenV7::floatBaseExtentFromMap(s16 *float_base_min, s16 *float_base_max, base_max = floatland_level - (amp - ridge * 2.0f) / 2.0f; } else { // Hills and ridges - float diff = fabs(amp - ridge) / ridge; + float diff = std::fabs(amp - ridge) / ridge; // Smooth ridges using the 'smoothstep function' float smooth_diff = diff * diff * (3.0f - 2.0f * diff); base_max = floatland_level + ridge - smooth_diff * ridge; @@ -569,7 +570,7 @@ void MapgenV7::generateRidgeTerrain() int j = (z - node_min.Z) * csize.X + (x - node_min.X); float uwatern = noise_ridge_uwater->result[j] * 2; - if (fabs(uwatern) > width) + if (std::fabs(uwatern) > width) continue; float altitude = y - water_level; diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index 5fd3455a6..54643583b 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -366,7 +366,7 @@ float MapgenValleys::terrainLevelFromNoise(TerrainNoise *tn) float base = tn->terrain_height + valley_d; // "river" represents the distance from the river, in arbitrary units. - float river = fabs(*tn->rivers) - river_size_factor; + float river = std::fabs(*tn->rivers) - river_size_factor; // Use the curve of the function 1-exp(-(x/a)^2) to model valleys. // Making "a" vary (0 < a <= 1) changes the shape of the valleys. @@ -375,7 +375,7 @@ float MapgenValleys::terrainLevelFromNoise(TerrainNoise *tn) // "valley" represents the height of the terrain, from the rivers. { float t = std::fmax(river / tn->valley_profile, 0.0f); - *tn->valley = valley_d * (1.f - exp(- MYSQUARE(t))); + *tn->valley = valley_d * (1.f - std::exp(- MYSQUARE(t))); } // approximate height of the terrain at this point @@ -392,7 +392,7 @@ float MapgenValleys::terrainLevelFromNoise(TerrainNoise *tn) float depth; { float t = river / river_size_factor + 1; - depth = (river_depth_bed * sqrt(MYMAX(0, 1.f - MYSQUARE(t)))); + depth = (river_depth_bed * std::sqrt(MYMAX(0, 1.f - MYSQUARE(t)))); } // base - depth : height of the bottom of the river @@ -496,7 +496,7 @@ int MapgenValleys::generateTerrain() heightmap[index_2d] = -MAX_MAP_GENERATION_LIMIT; if (surface_y > surface_max_y) - surface_max_y = ceil(surface_y); + surface_max_y = std::ceil(surface_y); if (humid_rivers) { // Derive heat from (base) altitude. This will be most correct @@ -562,7 +562,7 @@ int MapgenValleys::generateTerrain() float t_alt = MYMAX(noise_rivers->result[index_2d], (float)heightmap[index_2d]); float humid = m_bgen->humidmap[index_2d]; float water_depth = (t_alt - river_y) / humidity_dropoff; - humid *= 1.f + pow(0.5f, MYMAX(water_depth, 1.f)); + humid *= 1.f + std::pow(0.5f, MYMAX(water_depth, 1.f)); // Reduce humidity with altitude (ignoring riverbeds). // This is similar to the lua version's seawater adjustment, @@ -637,11 +637,12 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth) // lava_depth varies between one and ten as you approach // the bottom of the world. - s16 lava_depth = ceil((lava_max_height - node_min.Y + 1) * 10.f / mapgen_limit); + s16 lava_depth = std::ceil((lava_max_height - node_min.Y + 1) * 10.f / mapgen_limit); // This allows random lava spawns to be less common at the surface. s16 lava_chance = MYCUBE(lava_features_lim) * lava_depth; // water_depth varies between ten and one on the way down. - s16 water_depth = ceil((mapgen_limit - abs(node_min.Y) + 1) * 10.f / mapgen_limit); + s16 water_depth = std::ceil((mapgen_limit - std::abs(node_min.Y) + 1) * 10.f / + mapgen_limit); // This allows random water spawns to be more common at the surface. s16 water_chance = MYCUBE(water_features_lim) * water_depth; diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp index 672af7cdb..f83933ed1 100644 --- a/src/mapgen/mg_ore.cpp +++ b/src/mapgen/mg_ore.cpp @@ -345,7 +345,7 @@ void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, float ydist = (s32)y1 - (s32)csize / 2; float zdist = (s32)z1 - (s32)csize / 2; - noiseval -= (sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize); + noiseval -= std::sqrt(xdist * xdist + ydist * ydist + zdist * zdist) / csize; if (noiseval < nthresh) continue; @@ -469,7 +469,7 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, noise_stratum_thickness->result[index] : (float)stratum_thickness) / 2.0f; float nmid = noise->result[index]; - y0 = MYMAX(nmin.Y, ceil(nmid - nhalfthick)); + y0 = MYMAX(nmin.Y, std::ceil(nmid - nhalfthick)); y1 = MYMIN(nmax.Y, nmid + nhalfthick); } else { // Simple horizontal stratum y0 = nmin.Y; |