2009-03-27 04:49:17 +00:00
|
|
|
/*
|
|
|
|
** m_random.cpp
|
|
|
|
** Random number generators
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2002-2009 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
** This file employs the techniques for improving demo sync and backward
|
|
|
|
** compatibility that Lee Killough introduced with BOOM. However, none of
|
|
|
|
** the actual code he wrote is left. In contrast to BOOM, each RNG source
|
|
|
|
** in ZDoom is implemented as a separate class instance that provides an
|
|
|
|
** interface to the high-quality Mersenne Twister. See
|
|
|
|
** <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html>.
|
|
|
|
**
|
|
|
|
** As Killough's description from m_random.h is still mostly relevant,
|
|
|
|
** here it is:
|
|
|
|
** killough 2/16/98:
|
|
|
|
**
|
|
|
|
** Make every random number generator local to each control-equivalent block.
|
|
|
|
** Critical for demo sync. The random number generators are made local to
|
|
|
|
** reduce the chances of sync problems. In Doom, if a single random number
|
|
|
|
** generator call was off, it would mess up all random number generators.
|
|
|
|
** This reduces the chances of it happening by making each RNG local to a
|
|
|
|
** control flow block.
|
|
|
|
**
|
|
|
|
** Notes to developers: if you want to reduce your demo sync hassles, follow
|
|
|
|
** this rule: for each call to P_Random you add, add a new class to the enum
|
|
|
|
** type below for each block of code which calls P_Random. If two calls to
|
|
|
|
** P_Random are not in "control-equivalent blocks", i.e. there are any cases
|
|
|
|
** where one is executed, and the other is not, put them in separate classes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// HEADER FILES ------------------------------------------------------------
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "farchive.h"
|
|
|
|
#include "b_bot.h"
|
|
|
|
#include "m_png.h"
|
|
|
|
#include "m_crc32.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "files.h"
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
// MACROS ------------------------------------------------------------------
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
#define RAND_ID MAKE_ID('r','a','N','d')
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
// TYPES -------------------------------------------------------------------
|
|
|
|
|
|
|
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
|
|
|
|
|
|
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
|
|
|
|
|
|
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
|
|
|
|
|
|
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
|
|
|
|
|
|
|
extern FRandom pr_spawnmobj;
|
|
|
|
extern FRandom pr_acs;
|
|
|
|
extern FRandom pr_chase;
|
|
|
|
extern FRandom pr_exrandom;
|
2013-05-30 10:18:46 +00:00
|
|
|
extern FRandom pr_damagemobj;
|
2009-03-27 04:49:17 +00:00
|
|
|
|
|
|
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
FRandom M_Random;
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
// Global seed. This is modified predictably to initialize every RNG.
|
|
|
|
DWORD rngseed;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
FRandom *FRandom::RNGList;
|
2009-03-27 04:49:17 +00:00
|
|
|
static TDeletingArray<FRandom *> NewRNGs;
|
|
|
|
|
|
|
|
// CODE --------------------------------------------------------------------
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom - Nameless constructor
|
|
|
|
//
|
|
|
|
// Constructing an RNG in this way means it won't be stored in savegames.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
FRandom::FRandom ()
|
2009-03-27 04:49:17 +00:00
|
|
|
: NameCRC (0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
#ifndef NDEBUG
|
2006-02-24 04:48:15 +00:00
|
|
|
Name = NULL;
|
2009-03-27 04:49:17 +00:00
|
|
|
initialized = false;
|
2006-02-24 04:48:15 +00:00
|
|
|
#endif
|
|
|
|
Next = RNGList;
|
|
|
|
RNGList = this;
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom - Named constructor
|
|
|
|
//
|
|
|
|
// This is the standard way to construct RNGs.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
FRandom::FRandom (const char *name)
|
|
|
|
{
|
|
|
|
NameCRC = CalcCRC32 ((const BYTE *)name, (unsigned int)strlen (name));
|
2009-03-27 04:49:17 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
initialized = false;
|
2006-02-24 04:48:15 +00:00
|
|
|
Name = name;
|
|
|
|
// A CRC of 0 is reserved for nameless RNGs that don't get stored
|
|
|
|
// in savegames. The chance is very low that you would get a CRC of 0,
|
|
|
|
// but it's still possible.
|
|
|
|
assert (NameCRC != 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Insert 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;
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
#ifndef NDEBUG
|
2006-02-24 04:48:15 +00:00
|
|
|
if (probe != NULL)
|
|
|
|
{
|
|
|
|
// Because RNGs are identified by their CRCs in save games,
|
|
|
|
// no two RNGs can have names that hash to the same CRC.
|
|
|
|
// Obviously, this means every RNG must have a unique name.
|
|
|
|
assert (probe->NameCRC != NameCRC);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Next = probe;
|
|
|
|
*prev = this;
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom - Destructor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
FRandom::~FRandom ()
|
|
|
|
{
|
|
|
|
FRandom *rng, **prev;
|
|
|
|
|
|
|
|
FRandom *last = NULL;
|
|
|
|
|
|
|
|
prev = &RNGList;
|
|
|
|
rng = RNGList;
|
|
|
|
|
|
|
|
while (rng != NULL && rng != this)
|
|
|
|
{
|
|
|
|
last = rng;
|
|
|
|
rng = rng->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rng != NULL)
|
|
|
|
{
|
|
|
|
*prev = rng->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticClearRandom
|
|
|
|
//
|
|
|
|
// Initialize every RNGs. RNGs are seeded based on the global seed and their
|
|
|
|
// name, so each different RNG can have a different starting value despite
|
|
|
|
// being derived from a common global seed.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
void FRandom::StaticClearRandom ()
|
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
// go through each RNG and set each starting seed differently
|
|
|
|
for (FRandom *rng = FRandom::RNGList; rng != NULL; rng = rng->Next)
|
|
|
|
{
|
|
|
|
rng->Init(rngseed);
|
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: Init
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
2009-03-27 04:49:17 +00:00
|
|
|
// Initialize a single RNG with a given seed.
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
void FRandom::Init(DWORD seed)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
// [RH] Use the RNG's name's CRC to modify the original seed.
|
|
|
|
// This way, new RNGs can be added later, and it doesn't matter
|
|
|
|
// which order they get initialized in.
|
|
|
|
DWORD seeds[2] = { NameCRC, seed };
|
|
|
|
InitByArray(seeds, 2);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticSumSeeds
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// This function produces a DWORD that can be used to check the consistancy
|
|
|
|
// of network games between different machines. Only a select few RNGs are
|
|
|
|
// used for the sum, because not all RNGs are important to network sync.
|
2009-03-27 04:49:17 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
DWORD FRandom::StaticSumSeeds ()
|
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
return
|
|
|
|
pr_spawnmobj.sfmt.u[0] + pr_spawnmobj.idx +
|
|
|
|
pr_acs.sfmt.u[0] + pr_acs.idx +
|
|
|
|
pr_chase.sfmt.u[0] + pr_chase.idx +
|
2013-05-30 10:18:46 +00:00
|
|
|
pr_damagemobj.sfmt.u[0] + pr_damagemobj.idx;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticWriteRNGState
|
|
|
|
//
|
|
|
|
// Stores the state of every RNG into a savegame.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-05-26 04:38:22 +00:00
|
|
|
void FRandom::StaticWriteRNGState (FILE *file)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
FRandom *rng;
|
|
|
|
FPNGChunkArchive arc (file, RAND_ID);
|
|
|
|
|
|
|
|
arc << rngseed;
|
|
|
|
|
|
|
|
for (rng = FRandom::RNGList; rng != NULL; rng = rng->Next)
|
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
// Only write those RNGs that have names
|
|
|
|
if (rng->NameCRC != 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
arc << rng->NameCRC << rng->idx;
|
|
|
|
for (int i = 0; i < SFMT::N32; ++i)
|
|
|
|
{
|
|
|
|
arc << rng->sfmt.u[i];
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticReadRNGState
|
|
|
|
//
|
|
|
|
// Restores the state of every RNG from a savegame. RNGs that were added
|
|
|
|
// since the savegame was created are cleared to their initial value.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2006-05-26 04:38:22 +00:00
|
|
|
void FRandom::StaticReadRNGState (PNGHandle *png)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
FRandom *rng;
|
|
|
|
|
|
|
|
size_t len = M_FindPNGChunk (png, RAND_ID);
|
|
|
|
|
|
|
|
if (len != 0)
|
|
|
|
{
|
2009-03-27 22:07:16 +00:00
|
|
|
const size_t sizeof_rng = sizeof(rng->NameCRC) + sizeof(rng->idx) + sizeof(rng->sfmt.u);
|
|
|
|
const int rngcount = (int)((len-4) / sizeof_rng);
|
2006-02-24 04:48:15 +00:00
|
|
|
int i;
|
|
|
|
DWORD crc;
|
|
|
|
|
|
|
|
FPNGChunkArchive arc (png->File->GetFile(), RAND_ID, len);
|
|
|
|
|
|
|
|
arc << rngseed;
|
|
|
|
FRandom::StaticClearRandom ();
|
|
|
|
|
|
|
|
for (i = rngcount; i; --i)
|
|
|
|
{
|
|
|
|
arc << crc;
|
|
|
|
for (rng = FRandom::RNGList; rng != NULL; rng = rng->Next)
|
|
|
|
{
|
|
|
|
if (rng->NameCRC == crc)
|
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
arc << rng->idx;
|
|
|
|
for (int i = 0; i < SFMT::N32; ++i)
|
|
|
|
{
|
|
|
|
arc << rng->sfmt.u[i];
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-03-27 04:49:17 +00:00
|
|
|
if (rng == NULL)
|
|
|
|
{ // The RNG was removed. Skip it.
|
|
|
|
int idx;
|
|
|
|
DWORD sfmt;
|
|
|
|
arc << idx;
|
|
|
|
for (int i = 0; i < SFMT::N32; ++i)
|
|
|
|
{
|
|
|
|
arc << sfmt;
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
png->File->ResetFilePtr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticFindRNG
|
|
|
|
//
|
2006-11-26 12:13:12 +00:00
|
|
|
// 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.
|
2009-03-27 04:49:17 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
2006-11-26 12:13:12 +00:00
|
|
|
|
|
|
|
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.
|
2009-03-27 04:49:17 +00:00
|
|
|
if (NameCRC == 0) return &pr_exrandom;
|
2006-11-26 12:13:12 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2009-03-27 04:49:17 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// FRandom :: StaticPrintSeeds
|
|
|
|
//
|
|
|
|
// Prints a snapshot of the current RNG states. This is probably wrong.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2006-02-24 04:48:15 +00:00
|
|
|
void FRandom::StaticPrintSeeds ()
|
|
|
|
{
|
|
|
|
FRandom *rng = RNGList;
|
|
|
|
|
|
|
|
while (rng != NULL)
|
|
|
|
{
|
2009-03-27 04:49:17 +00:00
|
|
|
int idx = rng->idx < SFMT::N32 ? rng->idx : 0;
|
|
|
|
Printf ("%s: %08x .. %d\n", rng->Name, rng->sfmt.u[idx], idx);
|
2006-02-24 04:48:15 +00:00
|
|
|
rng = rng->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (showrngs)
|
|
|
|
{
|
|
|
|
FRandom::StaticPrintSeeds ();
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-26 12:13:12 +00:00
|
|
|
|