- Now base the old PRNG flag on Edward850's implementation but done in reverse.

Also disable it for some generators.
https://forum.zdoom.org/viewtopic.php?f=4&t=47546
This commit is contained in:
drfrag 2020-08-24 17:06:09 +02:00
parent e002d61823
commit eeef1c2dad
6 changed files with 44 additions and 22 deletions

View file

@ -63,7 +63,7 @@
#include "vm.h"
#include "s_music.h"
static FRandom pr_script("FScript");
static FRandom pr_script("FScript", false);
// functions. FParser::SF_ means Script Function not, well.. heh, me

View file

@ -171,7 +171,7 @@ static TDeletingArray<FRandom *> NewRNGs;
// CODE --------------------------------------------------------------------
// Which one is deterministic?
int P_Random (void)
unsigned int P_Random (void)
{
prndindex = (prndindex+1)&0xff;
return rndtable[prndindex];
@ -191,7 +191,7 @@ void M_ClearRandom (void)
//==========================================================================
FRandom::FRandom ()
: NameCRC (0)
: NameCRC (0), useOldRNG (false)
{
#ifndef NDEBUG
Name = NULL;
@ -210,9 +210,10 @@ FRandom::FRandom ()
//
//==========================================================================
FRandom::FRandom (const char *name)
FRandom::FRandom (const char *name, bool useold)
{
NameCRC = CalcCRC32 ((const uint8_t *)name, (unsigned int)strlen (name));
useOldRNG = useold;
#ifndef NDEBUG
initialized = false;
Name = name;
@ -273,6 +274,21 @@ FRandom::~FRandom ()
}
}
//==========================================================================
//
// FRandom::GetRandom()
//
// Returns either an old PRNG value or an SFMT value
//
//==========================================================================
unsigned int FRandom::GetRandom()
{
if (useOldRNG && (compatflags2 & COMPATF2_OLD_RANDOM_GENERATOR))
return P_Random();
else return GenRand32();
}
//==========================================================================
//
// FRandom :: StaticClearRandom
@ -325,7 +341,8 @@ uint32_t FRandom::StaticSumSeeds ()
pr_spawnmobj.sfmt.u[0] + pr_spawnmobj.idx +
pr_acs.sfmt.u[0] + pr_acs.idx +
pr_chase.sfmt.u[0] + pr_chase.idx +
pr_damagemobj.sfmt.u[0] + pr_damagemobj.idx;
pr_damagemobj.sfmt.u[0] + pr_damagemobj.idx +
prndindex;
}
//==========================================================================

View file

@ -45,13 +45,15 @@ class FRandom
{
public:
FRandom ();
FRandom (const char *name);
FRandom (const char *name, bool useold = true);
~FRandom ();
unsigned int GetRandom(); // [ED850]
// Returns a random number in the range [0,255]
int operator()()
{
return GenRand32() & 255;
return GetRandom() & 255;
}
// Returns a random number in the range [0,mod)
@ -59,7 +61,7 @@ public:
{
return (0 == mod)
? 0
: (GenRand32() % mod);
: (GetRandom() % mod);
}
// Returns rand# - rand#
@ -71,8 +73,8 @@ public:
// Returns (rand# & mask) - (rand# & mask)
int Random2(int mask)
{
int t = GenRand32() & mask & 255;
return t - (GenRand32() & mask & 255);
int t = GetRandom() & mask & 255;
return t - (GetRandom() & mask & 255);
}
// HITDICE macro used in Heretic and Hexen
@ -213,6 +215,9 @@ private:
#ifndef NDEBUG
bool initialized;
#endif
// Use the old PRNG table if/when requested [ED850]
bool useOldRNG;
};
extern uint32_t rngseed; // The starting seed (not part of state)
@ -225,7 +230,7 @@ extern bool use_staticrng;
extern FRandom M_Random;
// Returns a number from 0 to 255, from a lookup table.
int P_Random (void);
unsigned int P_Random (void);
void M_ClearRandom (void);
extern int prndindex;

View file

@ -543,7 +543,7 @@
extern FILE *Logfile;
FRandom pr_acs ("ACS");
FRandom pr_acs ("ACS", false);
// I imagine this much stack space is probably overkill, but it could
// potentially get used with recursive functions.

View file

@ -88,19 +88,19 @@
AActor *SingleActorFromTID(int tid, AActor *defactor);
static FRandom pr_camissile ("CustomActorfire");
static FRandom pr_cabullet ("CustomBullet");
static FRandom pr_cwjump ("CustomWpJump");
static FRandom pr_cwpunch ("CustomWpPunch");
static FRandom pr_camissile ("CustomActorfire", false);
static FRandom pr_cabullet ("CustomBullet", false);
static FRandom pr_cwjump ("CustomWpJump", false);
static FRandom pr_cwpunch ("CustomWpPunch", false);
static FRandom pr_grenade ("ThrowGrenade");
static FRandom pr_crailgun ("CustomRailgun");
static FRandom pr_spawndebris ("SpawnDebris");
static FRandom pr_spawnitemex ("SpawnItemEx");
static FRandom pr_burst ("Burst");
static FRandom pr_crailgun ("CustomRailgun", false);
static FRandom pr_spawndebris ("SpawnDebris", false);
static FRandom pr_spawnitemex ("SpawnItemEx", false);
static FRandom pr_burst ("Burst", false);
static FRandom pr_monsterrefire ("MonsterRefire");
static FRandom pr_teleport("A_Teleport");
static FRandom pr_bfgselfdamage("BFGSelfDamage");
FRandom pr_cajump("CustomJump");
FRandom pr_cajump("CustomJump", false);
//==========================================================================
//

View file

@ -51,7 +51,7 @@
#include "doomstat.h"
#include "backend/codegen.h"
FRandom pr_exrandom ("EX_Random");
FRandom pr_exrandom ("EX_Random", false);
static FxExpression *ParseRandom(FScanner &sc, FName identifier, PClassActor *cls);
static FxExpression *ParseRandomPick(FScanner &sc, FName identifier, PClassActor *cls);