diff options
| author | Robin Watts | 2008-02-17 16:12:54 +0000 |
|---|---|---|
| committer | Robin Watts | 2008-02-17 16:12:54 +0000 |
| commit | 890bca8f7ec17d308733b5d740700807508868b9 (patch) | |
| tree | 7e408e92c8788cf2ba84f7512f823c12a31ef89e /common | |
| parent | 5b31fe75d4cf8cc7c6c0272d660ebf07a49916bd (diff) | |
| download | scummvm-rg350-890bca8f7ec17d308733b5d740700807508868b9.tar.gz scummvm-rg350-890bca8f7ec17d308733b5d740700807508868b9.tar.bz2 scummvm-rg350-890bca8f7ec17d308733b5d740700807508868b9.zip | |
Tweaks to fmopl; same net effect overall, just faster.
Eliminate divisions, floating point, and mod operation from inner synth loop.
svn-id: r30896
Diffstat (limited to 'common')
| -rw-r--r-- | common/util.cpp | 6 | ||||
| -rw-r--r-- | common/util.h | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/common/util.cpp b/common/util.cpp index 82a910f9a8..1f48a6ddd9 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -196,6 +196,12 @@ uint RandomSource::getRandomNumber(uint max) { return _randSeed % (max + 1); } +uint RandomSource::getRandomBit(void) { + _randSeed = 0xDEADBF03 * (_randSeed + 1); + _randSeed = (_randSeed >> 13) | (_randSeed << 19); + return _randSeed & 1; +} + uint RandomSource::getRandomNumberRng(uint min, uint max) { return getRandomNumber(max - min) + min; } diff --git a/common/util.h b/common/util.h index e7a71ff42c..dd205f159c 100644 --- a/common/util.h +++ b/common/util.h @@ -83,7 +83,7 @@ bool matchString(const char *str, const char *pat); class StringTokenizer { public: /** - * Creates a StringTokenizer. + * Creates a StringTokenizer. * @param str The string to be tokenized. * @param delimiters String containing all the delimiter characters (i.e. the characters to be ignored). * @note Uses space, horizontal tab, carriage return, newline, form feed and vertical tab as delimiters by default. @@ -132,6 +132,12 @@ public: */ uint getRandomNumber(uint max); /** + * Generates a random unsigned integer in the interval [0, 1]. + * Identical to getRandomNumber(1), but faster, hopefully. + * @return a random number in the interval [0, max]. + */ + uint getRandomBit(void); + /** * Generates a random unsigned integer in the interval [min, max]. * @param min the lower bound * @param max the upper bound |
