aboutsummaryrefslogtreecommitdiff
path: root/scumm
diff options
context:
space:
mode:
authorOliver Kiehl2002-12-01 14:57:50 +0000
committerOliver Kiehl2002-12-01 14:57:50 +0000
commit133f624cc530a210c82d38e6e5ecf2cd732011b7 (patch)
tree94809a1086a54ed4929606a4d6e879806ea0d6b5 /scumm
parent89eaf9b319299950872229e585dca30e2995772f (diff)
downloadscummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.tar.gz
scummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.tar.bz2
scummvm-rg350-133f624cc530a210c82d38e6e5ecf2cd732011b7.zip
moved RNG to common/util.cpp
svn-id: r5778
Diffstat (limited to 'scumm')
-rw-r--r--scumm/akos.cpp2
-rw-r--r--scumm/gfx.cpp4
-rw-r--r--scumm/saveload.cpp2
-rw-r--r--scumm/script_v1.cpp2
-rw-r--r--scumm/script_v2.cpp4
-rw-r--r--scumm/scumm.h7
-rw-r--r--scumm/scummvm.cpp27
7 files changed, 16 insertions, 32 deletions
diff --git a/scumm/akos.cpp b/scumm/akos.cpp
index cc588cc1b2..10ec09534a 100644
--- a/scumm/akos.cpp
+++ b/scumm/akos.cpp
@@ -1419,7 +1419,7 @@ bool Scumm::akos_increaseAnim(Actor *a, int chan, byte *aksq, uint16 *akfo, int
continue;
case AKC_Random:
- a->setAnimVar(GB(6), getRandomNumberRng(GW(2), GW(4)));
+ a->setAnimVar(GB(6), _rnd.getRandomNumberRng(GW(2), GW(4)));
continue;
case AKC_SkipGE:
case AKC_SkipG:
diff --git a/scumm/gfx.cpp b/scumm/gfx.cpp
index 9ac04e68cd..21f9211855 100644
--- a/scumm/gfx.cpp
+++ b/scumm/gfx.cpp
@@ -2076,7 +2076,7 @@ void Scumm::dissolveEffect(int width, int height) {
for (i = 1; i < w * h; i++) {
int j;
- j = getRandomNumber(i - 1);
+ j = _rnd.getRandomNumber(i - 1);
offsets[i] = offsets[j];
offsets[j] = i;
}
@@ -2099,7 +2099,7 @@ void Scumm::dissolveEffect(int width, int height) {
for (i = 1; i < w * h; i++) {
int j;
- j = getRandomNumber(i - 1);
+ j = _rnd.getRandomNumber(i - 1);
offsets[i] = offsets[j];
offsets[j] = offsets2[i];
}
diff --git a/scumm/saveload.cpp b/scumm/saveload.cpp
index bedb3eebb9..33ecf348bf 100644
--- a/scumm/saveload.cpp
+++ b/scumm/saveload.cpp
@@ -431,6 +431,7 @@ void Scumm::saveOrLoad(Serializer *s)
MKLINE(Scumm, _screenEffectFlag, sleByte),
+ // FIXME: remove when new savegame system is implemented
MKLINE(Scumm, _randSeed1, sleUint32),
MKLINE(Scumm, _randSeed2, sleUint32),
@@ -545,6 +546,7 @@ void Scumm::saveOrLoad(Serializer *s)
MKLINE(Scumm, _screenEffectFlag, sleByte),
+ // FIXME: remove when new savegame system is implemented
MKLINE(Scumm, _randSeed1, sleUint32),
MKLINE(Scumm, _randSeed2, sleUint32),
diff --git a/scumm/script_v1.cpp b/scumm/script_v1.cpp
index cbf17a5a60..bd67df81d7 100644
--- a/scumm/script_v1.cpp
+++ b/scumm/script_v1.cpp
@@ -1134,7 +1134,7 @@ void Scumm::o5_ifNotState()
void Scumm::o5_getRandomNr()
{
getResultPos();
- setResult(getRandomNumber(getVarOrDirectByte(0x80)));
+ setResult(_rnd.getRandomNumber(getVarOrDirectByte(0x80)));
}
void Scumm::o5_getScriptRunning()
diff --git a/scumm/script_v2.cpp b/scumm/script_v2.cpp
index 8e631ec1dd..49beb10f1a 100644
--- a/scumm/script_v2.cpp
+++ b/scumm/script_v2.cpp
@@ -1209,7 +1209,7 @@ void Scumm::o6_loadRoomWithEgo()
void Scumm::o6_getRandomNumber()
{
int rnd;
- rnd = getRandomNumber(pop());
+ rnd = _rnd.getRandomNumber(pop());
_vars[VAR_V6_RANDOM_NR] = rnd;
push(rnd);
}
@@ -1218,7 +1218,7 @@ void Scumm::o6_getRandomNumberRange()
{
int max = pop();
int min = pop();
- int rnd = getRandomNumberRng(min, max);
+ int rnd = _rnd.getRandomNumberRng(min, max);
_vars[VAR_V6_RANDOM_NR] = rnd;
push(rnd);
}
diff --git a/scumm/scumm.h b/scumm/scumm.h
index 50247319ce..61d92896a2 100644
--- a/scumm/scumm.h
+++ b/scumm/scumm.h
@@ -27,6 +27,7 @@
#include "common/gameDetector.h"
#include "common/timer.h"
#include "common/file.h"
+#include "common/util.h"
class GameDetector;
class NewGui;
@@ -351,10 +352,8 @@ public:
void convertKeysToClicks();
/* Random number generation */
- uint32 _randSeed1, _randSeed2;
- void initRandSeeds();
- uint getRandomNumber(uint max);
- uint getRandomNumberRng(uint min, uint max);
+ uint32 _randSeed1, _randSeed2; // FIXME: can be removed when new savegame system is implemented
+ RandomSource _rnd;
/* Core variable definitions */
byte _gameId;
diff --git a/scumm/scummvm.cpp b/scumm/scummvm.cpp
index 511fe03a6d..3694bb1c4c 100644
--- a/scumm/scummvm.cpp
+++ b/scumm/scummvm.cpp
@@ -73,25 +73,6 @@ Engine *Engine_SCUMM_create(GameDetector *detector, OSystem *syst)
return engine;
}
-void Scumm::initRandSeeds()
-{
- _randSeed1 = 0xA943DE33;
- _randSeed2 = 0x37A9ED29;
-}
-
-uint Scumm::getRandomNumber(uint max)
-{
- /* TODO: my own random number generator */
- _randSeed1 = 0xDEADBF03 * (_randSeed1 + 1);
- _randSeed1 = (_randSeed1 >> 13) | (_randSeed1 << 19);
- return _randSeed1 % (max + 1);
-}
-
-uint Scumm::getRandomNumberRng(uint min, uint max)
-{
- return getRandomNumber(max - min) + min;
-}
-
Scumm::Scumm (GameDetector *detector, OSystem *syst)
: Engine(detector, syst), _pauseDialog(0), _optionsDialog(0), _saveLoadDialog(0)
{
@@ -118,6 +99,10 @@ Scumm::Scumm (GameDetector *detector, OSystem *syst)
_dynamicRoomOffsets = 0;
_shakeEnabled = 0;
+ // FIXME: remove when new savegame system is implemented
+ _randSeed1 = 0xA943DE33;
+ _randSeed2 = 0x37A9ED29;
+
if (_gameId == GID_ZAK256) { // FmTowns is 320x240
_realWidth = 320;
_realHeight = 240;
@@ -404,7 +389,7 @@ int Scumm::scummLoop(int delta)
// Randomize the PRNG by calling it at regular intervals. This ensures
// that it will be in a different state each time you run the program.
- getRandomNumber(2);
+ _rnd.getRandomNumber(2);
_vars[VAR_TMR_1] += delta;
_vars[VAR_TMR_2] += delta;
@@ -1589,8 +1574,6 @@ void Scumm::launch()
readIndexFile();
- initRandSeeds();
-
if (_features & GF_NEW_OPCODES)
setupOpcodes2();
else