Reworked FRandom constructors

Removes ambiguity while keeping old constructor syntax in check for better overall portability.
This commit is contained in:
Boondorl 2024-11-06 22:41:26 -05:00 committed by Ricardo Luís Vaz Silva
commit 3ea5be1ea7
42 changed files with 130 additions and 119 deletions

View file

@ -79,11 +79,11 @@
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
FRandom pr_exrandom("EX_Random", false);
FRandom pr_exrandom("EX_Random");
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FRandom M_Random(true);
FCRandom M_Random;
// Global seed. This is modified predictably to initialize every RNG.
uint32_t rngseed;
@ -145,7 +145,7 @@ FRandom::FRandom (bool client)
#ifndef NDEBUG
Name = NULL;
#endif
if (client)
if (bClient)
{
Next = CRNGList;
CRNGList = this;
@ -178,7 +178,7 @@ FRandom::FRandom (const char *name, bool client) : bClient(client)
#endif
// Insert the RNG in the list, sorted by CRC
FRandom **prev = (client ? &CRNGList : &RNGList), * probe = (client ? CRNGList : RNGList);
FRandom **prev = (bClient ? &CRNGList : &RNGList), * probe = (bClient ? CRNGList : RNGList);
while (probe != NULL && probe->NameCRC < NameCRC)
{

View file

@ -44,9 +44,9 @@ class FSerializer;
class FRandom : public SFMTObj
{
public:
FRandom (bool client);
FRandom (const char *name, bool client);
~FRandom ();
FRandom() : FRandom(false) {}
FRandom(const char* name) : FRandom(name, false) {}
~FRandom();
int Seed() const
{
@ -178,6 +178,10 @@ public:
static void StaticPrintSeeds ();
#endif
protected:
FRandom(bool client);
FRandom(const char* name, bool client);
private:
#ifndef NDEBUG
const char *Name;
@ -189,6 +193,13 @@ private:
static FRandom *RNGList, *CRNGList;
};
class FCRandom : public FRandom
{
public:
FCRandom() : FRandom(true) {}
FCRandom(const char* name) : FRandom(name, true) {}
};
extern uint32_t rngseed; // The starting seed (not part of state)
extern uint32_t staticrngseed; // Static rngseed that can be set by the user
@ -196,6 +207,6 @@ extern bool use_staticrng;
// M_Random can be used for numbers that do not affect gameplay
extern FRandom M_Random;
extern FCRandom M_Random;
#endif