mirror of https://github.com/stella-emu/stella.git
Slight rework of random number generator.
- break dependence on OSystem; source for seed could actually be anything (doesn't have to come from OSystem)
This commit is contained in:
parent
86a242a8cf
commit
d71b33918a
|
@ -95,7 +95,6 @@ OSystem::OSystem()
|
|||
|
||||
mySettings = MediaFactory::createSettings(*this);
|
||||
myAudioSettings = AudioSettings(mySettings.get());
|
||||
myRandom = make_unique<Random>(*this);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -158,8 +157,8 @@ bool OSystem::create()
|
|||
// a real serial port on the system
|
||||
mySerialPort = MediaFactory::createSerialPort();
|
||||
|
||||
// Re-initialize random seed
|
||||
myRandom->initSeed();
|
||||
// Create random number generator
|
||||
myRandom = make_unique<Random>(getTicks());
|
||||
|
||||
// Create PNG handler
|
||||
myPNGLib = make_unique<PNGLibrary>(*this);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#define RANDOM_HXX
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "OSystem.hxx"
|
||||
#include "Serializable.hxx"
|
||||
|
||||
/**
|
||||
|
@ -35,15 +34,15 @@ class Random : public Serializable
|
|||
/**
|
||||
Create a new random number generator
|
||||
*/
|
||||
Random(const OSystem& osystem) : myOSystem(osystem) { initSeed(); }
|
||||
Random(uInt32 seed) { initSeed(seed); }
|
||||
|
||||
/**
|
||||
Re-initialize the random number generator with a new seed,
|
||||
to generate a different set of random numbers.
|
||||
*/
|
||||
void initSeed()
|
||||
void initSeed(uInt32 seed)
|
||||
{
|
||||
myValue = uInt32(myOSystem.getTicks());
|
||||
myValue = seed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,9 +109,6 @@ class Random : public Serializable
|
|||
string name() const override { return "Random"; }
|
||||
|
||||
private:
|
||||
// Set the OSystem we're using
|
||||
const OSystem& myOSystem;
|
||||
|
||||
// Indicates the next random number
|
||||
// We make this mutable, since it's not immediately obvious that
|
||||
// calling next() should change internal state (ie, the *logical*
|
||||
|
|
|
@ -39,7 +39,7 @@ System::System(const OSystem& osystem, M6502& m6502, M6532& m6532,
|
|||
mySystemInAutodetect(false)
|
||||
{
|
||||
// Re-initialize random generator
|
||||
randGenerator().initSeed();
|
||||
randGenerator().initSeed(myOSystem.getTicks());
|
||||
|
||||
// Initialize page access table
|
||||
PageAccess access(&myNullDevice, System::PA_READ);
|
||||
|
|
|
@ -27,6 +27,7 @@ class NullDevice;
|
|||
#include "bspf.hxx"
|
||||
#include "Device.hxx"
|
||||
#include "NullDev.hxx"
|
||||
#include "OSystem.hxx"
|
||||
#include "Random.hxx"
|
||||
#include "Serializable.hxx"
|
||||
|
||||
|
|
Loading…
Reference in New Issue