Remove RNG implementation from C4Random.h

liquid_container
Lukas Werling 2016-04-25 17:28:04 +02:00
parent aeabe28d82
commit e734f15117
3 changed files with 32 additions and 14 deletions

View File

@ -18,6 +18,7 @@
#include "platform/StdScheduler.h"
#include <pcg/pcg_random.hpp>
#ifndef INC_C4Particles
#define INC_C4Particles

View File

@ -21,14 +21,14 @@
#include "lib/C4Random.h"
#include "control/C4Record.h"
#include <pcg/pcg_random.hpp>
int RandomCount = 0;
static pcg32 RandomRng;
pcg32 SafeRandom;
static pcg32 RandomRng, UnsyncedRandomRng;
void FixedRandom(uint64_t seed)
{
// for SafeRandom
SafeRandom.seed(seed);
UnsyncedRandomRng.seed(seed);
RandomRng.seed(seed);
RandomCount = 0;
}
@ -61,3 +61,22 @@ uint32_t Random(uint32_t iRange)
RecordRandom(iRange, result);
return result;
}
uint32_t SafeRandom()
{
return UnsyncedRandomRng();
}
uint32_t SafeRandom(uint32_t iRange)
{
if (!iRange) return 0u;
return UnsyncedRandomRng(iRange);
}
uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
{
if (!iRange) return 0;
pcg32 rng(iSeed);
return rng(iRange);
}

View File

@ -20,20 +20,18 @@
#ifndef INC_C4Random
#define INC_C4Random
#include <pcg/pcg_random.hpp>
#include <inttypes.h>
extern int RandomCount;
extern pcg32 SafeRandom;
// Seeds both the synchronized and the unsynchronized RNGs.
void FixedRandom(uint64_t dwSeed);
// Synchronized RNG.
uint32_t Random(uint32_t iRange);
inline uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
{
if (!iRange) return 0;
pcg32 rng(iSeed);
return rng(iRange);
}
// Unsynchronized RNG.
uint32_t SafeRandom();
uint32_t SafeRandom(uint32_t range);
// Generates a single random value from a seed.
uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange);
#endif // INC_C4Random