diff options
Diffstat (limited to 'engines/wintermute')
-rw-r--r-- | engines/wintermute/Ad/AdActor.cpp | 8 | ||||
-rw-r--r-- | engines/wintermute/Ad/AdTalkHolder.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/Base/BGame.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/utils/utils.cpp | 23 | ||||
-rw-r--r-- | engines/wintermute/wintermute.cpp | 4 | ||||
-rw-r--r-- | engines/wintermute/wintermute.h | 1 |
6 files changed, 23 insertions, 21 deletions
diff --git a/engines/wintermute/Ad/AdActor.cpp b/engines/wintermute/Ad/AdActor.cpp index 55e73ea482..27adf1a6f2 100644 --- a/engines/wintermute/Ad/AdActor.cpp +++ b/engines/wintermute/Ad/AdActor.cpp @@ -25,7 +25,7 @@ * http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
-#define FORBIDDEN_SYMBOL_EXCEPTION_rand
+
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/dctypes.h"
#include "engines/wintermute/persistent.h"
@@ -48,7 +48,7 @@ #include "engines/wintermute/Base/scriptables/ScStack.h"
#include "engines/wintermute/utils/utils.h"
#include "engines/wintermute/PlatformSDL.h"
-#include <math.h>
+#include "engines/wintermute/wintermute.h"
namespace WinterMute {
@@ -1159,7 +1159,7 @@ CBSprite *CAdActor::GetTalkStance(const char *Stance) { }
if (TalkAnims.GetSize() > 0) {
- int rnd = rand() % TalkAnims.GetSize();
+ int rnd = g_wintermute->randInt(0, TalkAnims.GetSize() - 1);
Ret = TalkAnims[rnd]->GetSprite(_dir);
} else {
if (_standSprite) Ret = _standSprite->GetSprite(_dir);
@@ -1200,7 +1200,7 @@ CBSprite *CAdActor::GetTalkStanceOld(const char *Stance) { if (_talkSprites.GetSize() < 1) ret = _standSprite->GetSprite(_dir);
else {
// TODO: remember last
- int rnd = rand() % _talkSprites.GetSize();
+ int rnd = g_wintermute->randInt(0, _talkSprites.GetSize() - 1);
ret = _talkSprites[rnd]->GetSprite(_dir);
}
}
diff --git a/engines/wintermute/Ad/AdTalkHolder.cpp b/engines/wintermute/Ad/AdTalkHolder.cpp index 61e012b261..a2af4223a3 100644 --- a/engines/wintermute/Ad/AdTalkHolder.cpp +++ b/engines/wintermute/Ad/AdTalkHolder.cpp @@ -26,7 +26,6 @@ * Copyright (c) 2011 Jan Nedoma
*/
-#define FORBIDDEN_SYMBOL_EXCEPTION_rand
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/Ad/AdTalkHolder.h"
#include "engines/wintermute/Base/BDynBuffer.h"
@@ -36,6 +35,7 @@ #include "engines/wintermute/Base/BGame.h"
#include "engines/wintermute/Base/BSprite.h"
#include "engines/wintermute/PlatformSDL.h"
+#include "engines/wintermute/wintermute.h"
#include "common/str.h"
namespace WinterMute {
@@ -106,7 +106,7 @@ CBSprite *CAdTalkHolder::GetTalkStance(const char *Stance) { if (_talkSprites.GetSize() < 1) ret = _sprite;
else {
// TODO: remember last
- int rnd = rand() % _talkSprites.GetSize();
+ int rnd = g_wintermute->randInt(0, _talkSprites.GetSize() - 1);
ret = _talkSprites[rnd];
}
}
diff --git a/engines/wintermute/Base/BGame.cpp b/engines/wintermute/Base/BGame.cpp index 953bd24686..b30deadc41 100644 --- a/engines/wintermute/Base/BGame.cpp +++ b/engines/wintermute/Base/BGame.cpp @@ -26,8 +26,6 @@ * Copyright (c) 2011 Jan Nedoma
*/
-#define FORBIDDEN_SYMBOL_EXCEPTION_srand
-
#include "engines/wintermute/dcgf.h"
#include "engines/wintermute/Base/BGame.h"
#include "engines/wintermute/Base/BFader.h"
@@ -148,8 +146,6 @@ CBGame::CBGame(): CBObject(this) { _useD3D = false;
- srand(g_system->getMillis());
-
_registry = new CBRegistry(this);
_stringTable = new CBStringTable(this);
diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index c9131608be..4e4678ffae 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -26,8 +26,6 @@ * Copyright (c) 2011 Jan Nedoma
*/
-#define FORBIDDEN_SYMBOL_EXCEPTION_rand
-
#include "engines/wintermute/dcgf.h"
#include "utils.h"
#include "engines/wintermute/PlatformSDL.h"
@@ -36,6 +34,7 @@ #include "engines/wintermute/Base/BGame.h"
#include "common/str.h"
#include "common/textconsole.h"
+#include "wintermute.h"
namespace WinterMute {
@@ -164,19 +163,21 @@ char *CBUtils::StrEntry(int Entry, const char *Str, const char Delim) { }
//////////////////////////////////////////////////////////////////////////
-int CBUtils::RandomInt(int From, int To) {
- if (To < From) {
- int i = To;
- To = From;
- From = i;
+int CBUtils::RandomInt(int from, int to) {
+ if (to < from) {
+ int i = to;
+ to = from;
+ from = i;
}
- return (rand() % (To - From + 1)) + From;
+ return g_wintermute->randInt(from, to);
+// return (rand() % (to - from + 1)) + from;
}
//////////////////////////////////////////////////////////////////////////
-float CBUtils::RandomFloat(float From, float To) {
- float RandNum = (float)rand() / (float)RAND_MAX;
- return From + (To - From) * RandNum;
+float CBUtils::RandomFloat(float from, float to) {
+ const uint32 randMax = RAND_MAX;
+ float randNum = (float)g_wintermute->randInt(0, randMax) / (float)randMax;
+ return from + (to - from) * randNum;
}
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/wintermute/wintermute.cpp b/engines/wintermute/wintermute.cpp index 7fa59930d5..8b12a422cf 100644 --- a/engines/wintermute/wintermute.cpp +++ b/engines/wintermute/wintermute.cpp @@ -294,4 +294,8 @@ int WinterMuteEngine::messageLoop() { return 0; } +uint32 WinterMuteEngine::randInt(int from, int to) { + return _rnd->getRandomNumberRng(from, to); +} + } // End of namespace WinterMute diff --git a/engines/wintermute/wintermute.h b/engines/wintermute/wintermute.h index 015f31c2bb..d6c3b1faf9 100644 --- a/engines/wintermute/wintermute.h +++ b/engines/wintermute/wintermute.h @@ -46,6 +46,7 @@ public: virtual Common::Error run(); + uint32 randInt(int from, int to); private: int init(); int messageLoop(); |