Skip to content

Commit

Permalink
Fix thread safety of PcgRandom use in BiomeGen
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 authored and nerzhul committed May 5, 2020
1 parent ab06880 commit f3e87c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mapgen/mg_biome.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f3e87c5

Please sign in to comment.