Fix thread safety of PcgRandom use in BiomeGen
authorsfan5 <sfan5@live.de>
Sun, 26 Apr 2020 16:33:50 +0000 (18:33 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Tue, 5 May 2020 17:26:59 +0000 (19:26 +0200)
src/mapgen/mg_biome.cpp

index 8c59ac9e62a4fde58748a98ba83c2180f3f345f3..610c3859438d63f0c0edb63a3dc137f0eda5f114 100644 (file)
@@ -154,9 +154,11 @@ const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat,
                }
        }
 
-       mysrand(pos.Y + (heat + humidity) * 0.9f);
+       const u64 seed = pos.Y + (heat + humidity) * 0.9f;
+       PcgRandom rng(seed);
+
        if (biome_closest_blend && dist_min_blend <= dist_min &&
-                       myrand_range(0, biome_closest_blend->vertical_blend) >=
+                       rng.range(0, biome_closest_blend->vertical_blend) >=
                        pos.Y - biome_closest_blend->max_pos.Y)
                return biome_closest_blend;
 
@@ -319,10 +321,11 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
        // Carefully tune pseudorandom seed variation to avoid single node dither
        // and create larger scale blending patterns similar to horizontal biome
        // blend.
-       mysrand(pos.Y + (heat + humidity) * 0.9f);
+       const u64 seed = pos.Y + (heat + humidity) * 0.9f;
+       PcgRandom rng(seed);
 
        if (biome_closest_blend && dist_min_blend <= dist_min &&
-                       myrand_range(0, biome_closest_blend->vertical_blend) >=
+                       rng.range(0, biome_closest_blend->vertical_blend) >=
                        pos.Y - biome_closest_blend->max_pos.Y)
                return biome_closest_blend;