Skip to content

Commit f3e87c5

Browse files
sfan5nerzhul
authored andcommittedMay 5, 2020
Fix thread safety of PcgRandom use in BiomeGen
1 parent ab06880 commit f3e87c5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

Diff for: ‎src/mapgen/mg_biome.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,11 @@ const Biome *BiomeManager::getBiomeFromNoiseOriginal(float heat,
154154
}
155155
}
156156

157-
mysrand(pos.Y + (heat + humidity) * 0.9f);
157+
const u64 seed = pos.Y + (heat + humidity) * 0.9f;
158+
PcgRandom rng(seed);
159+
158160
if (biome_closest_blend && dist_min_blend <= dist_min &&
159-
myrand_range(0, biome_closest_blend->vertical_blend) >=
161+
rng.range(0, biome_closest_blend->vertical_blend) >=
160162
pos.Y - biome_closest_blend->max_pos.Y)
161163
return biome_closest_blend;
162164

@@ -319,10 +321,11 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
319321
// Carefully tune pseudorandom seed variation to avoid single node dither
320322
// and create larger scale blending patterns similar to horizontal biome
321323
// blend.
322-
mysrand(pos.Y + (heat + humidity) * 0.9f);
324+
const u64 seed = pos.Y + (heat + humidity) * 0.9f;
325+
PcgRandom rng(seed);
323326

324327
if (biome_closest_blend && dist_min_blend <= dist_min &&
325-
myrand_range(0, biome_closest_blend->vertical_blend) >=
328+
rng.range(0, biome_closest_blend->vertical_blend) >=
326329
pos.Y - biome_closest_blend->max_pos.Y)
327330
return biome_closest_blend;
328331

0 commit comments

Comments
 (0)
Please sign in to comment.