- Added random2 function to DECORATE's expression evaluator. This is to

better emulate some calculation of internal code pointers.
- Added named RNG support to DECORATE's expression evaluator. Just use
  random[name](min, max).


SVN r391 (trunk)
This commit is contained in:
Christoph Oelckers 2006-11-26 12:13:12 +00:00
commit d840d9b68a
8 changed files with 133 additions and 43 deletions

View file

@ -250,6 +250,53 @@ void FRandom::StaticReadRNGState (PNGHandle *png)
}
}
// This function attempts to find an RNG with the given name.
// If it can't it will create a new one. Duplicate CRCs will
// be ignored and if it happens map to the same RNG.
// This is for use by DECORATE.
extern FRandom pr_exrandom;
class NewRNGList : public TArray<FRandom*>
{
public:
~NewRNGList()
{
for(unsigned i=0;i<Size();i++)
{
delete (*this)[i];
}
}
};
static NewRNGList NewRNGs;
FRandom *FRandom::StaticFindRNG (const char *name)
{
DWORD NameCRC = CalcCRC32 ((const BYTE *)name, (unsigned int)strlen (name));
// Use the default RNG if this one happens to have a CRC of 0.
if (NameCRC==0) return &pr_exrandom;
// Find the RNG in the list, sorted by CRC
FRandom **prev = &RNGList, *probe = RNGList;
while (probe != NULL && probe->NameCRC < NameCRC)
{
prev = &probe->Next;
probe = probe->Next;
}
// Found one so return it.
if (probe == NULL || probe->NameCRC != NameCRC)
{
// A matching RNG doesn't exist yet so create it.
probe = new FRandom(name);
// Store the new RNG for destruction when ZDoom quits.
NewRNGs.Push(probe);
}
return probe;
}
#ifdef _DEBUG
void FRandom::StaticPrintSeeds ()
{
@ -267,3 +314,4 @@ CCMD (showrngs)
FRandom::StaticPrintSeeds ();
}
#endif