mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-22 09:49:11 +00:00
WINTERMUTE: Get rid of rand/srand.
This commit is contained in:
parent
3d49eb1605
commit
850e237d31
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
|
||||
virtual Common::Error run();
|
||||
|
||||
uint32 randInt(int from, int to);
|
||||
private:
|
||||
int init();
|
||||
int messageLoop();
|
||||
|
Loading…
Reference in New Issue
Block a user