diff options
author | Max Horn | 2011-05-16 16:35:10 +0200 |
---|---|---|
committer | Max Horn | 2011-05-17 12:17:26 +0200 |
commit | 4cbe4ede66e65ec9289811eca2f5f62285174c8d (patch) | |
tree | 19e97e1d96797a2e063786e5f7f9c3e4ebb71d93 /common/random.cpp | |
parent | 305c13a4aac6074ac734f77dad708e0aca86bbd7 (diff) | |
download | scummvm-rg350-4cbe4ede66e65ec9289811eca2f5f62285174c8d.tar.gz scummvm-rg350-4cbe4ede66e65ec9289811eca2f5f62285174c8d.tar.bz2 scummvm-rg350-4cbe4ede66e65ec9289811eca2f5f62285174c8d.zip |
COMMON: Registers RandomSources in constructor with the event recorder
This also removes the dependency of engines on the event recorder header
and API, and will make it easier to RandomSources that are not properly
registered.
Diffstat (limited to 'common/random.cpp')
-rw-r--r-- | common/random.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/common/random.cpp b/common/random.cpp index 5a00d48357..be69d39d2d 100644 --- a/common/random.cpp +++ b/common/random.cpp @@ -21,10 +21,23 @@ #include "common/random.h" #include "common/system.h" +#include "common/EventRecorder.h" namespace Common { +RandomSource::RandomSource(const String &name) { + // Use system time as RNG seed. Normally not a good idea, if you are using + // a RNG for security purposes, but good enough for our purposes. + assert(g_system); + uint32 seed = g_system->getMillis(); + setSeed(seed); + + // Register this random source with the event recorder. This might + // reset the seed, so call it *after* the initial seed has been set. + g_eventRec.registerRandomSource(*this, name); +} + RandomSource::RandomSource() { // Use system time as RNG seed. Normally not a good idea, if you are using // a RNG for security purposes, but good enough for our purposes. @@ -33,6 +46,10 @@ RandomSource::RandomSource() { setSeed(seed); } +RandomSource::~RandomSource() { + // TODO: Unregister with g_eventRec +} + void RandomSource::setSeed(uint32 seed) { _randSeed = seed; } |