From 60e9383a42cd47cc5d570e66a8f601bd97d94732 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Sun, 1 May 2016 19:21:09 +0200 Subject: [PATCH 1/2] Improve seeding of UnsyncedRandomRng --- src/lib/C4Random.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/C4Random.cpp b/src/lib/C4Random.cpp index 78fef9d2b..f04edef29 100644 --- a/src/lib/C4Random.cpp +++ b/src/lib/C4Random.cpp @@ -21,14 +21,21 @@ #include "lib/C4Random.h" #include "control/C4Record.h" +#include #include int RandomCount = 0; -static pcg32 RandomRng, UnsyncedRandomRng; + +static pcg32 SeededRng() +{ + pcg_extras::seed_seq_from seed_source; + return pcg32(seed_source); +} + +static pcg32 RandomRng, UnsyncedRandomRng = SeededRng(); void FixedRandom(uint64_t seed) { - UnsyncedRandomRng.seed(seed); RandomRng.seed(seed); RandomCount = 0; } From dd48a759d7e698a4b8d9c68e1aa34e5db4792e50 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Sun, 1 May 2016 19:25:12 +0200 Subject: [PATCH 2/2] Add mathematical modulo helper function Mod(a, b) --- planet/System.ocg/Math.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/planet/System.ocg/Math.c b/planet/System.ocg/Math.c index 69b01d0f5..c98bea06e 100644 --- a/planet/System.ocg/Math.c +++ b/planet/System.ocg/Math.c @@ -160,4 +160,10 @@ global func GetSurfaceVector(int x, int y) } return normal; -} \ No newline at end of file +} + +// Proper modulo operation. +global func Mod(a, b) +{ + return (a % b + b) % b; +}