Commit 14bd1f7f authored by salix5's avatar salix5

remove rand(), random_shuffle()

parent b62918d8
...@@ -35,6 +35,7 @@ ClientField::ClientField() { ...@@ -35,6 +35,7 @@ ClientField::ClientField() {
mzone[p].resize(7, 0); mzone[p].resize(7, 0);
szone[p].resize(8, 0); szone[p].resize(8, 0);
} }
rnd.reset(std::random_device()());
} }
void ClientField::Clear() { void ClientField::Clear() {
for(int i = 0; i < 2; ++i) { for(int i = 0; i < 2; ++i) {
...@@ -409,7 +410,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -409,7 +410,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
} }
} }
if(has_card_in_grave) { if(has_card_in_grave) {
std::random_shuffle(selectable_cards.begin(), selectable_cards.end()); rnd.shuffle_vector(selectable_cards);
} }
} }
int startpos; int startpos;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define CLIENT_FIELD_H #define CLIENT_FIELD_H
#include "config.h" #include "config.h"
#include "../ocgcore/mtrandom.h"
#include <vector> #include <vector>
#include <set> #include <set>
#include <map> #include <map>
...@@ -83,6 +84,7 @@ public: ...@@ -83,6 +84,7 @@ public:
bool deck_reversed; bool deck_reversed;
bool conti_selecting; bool conti_selecting;
bool cant_check_grave; bool cant_check_grave;
mt19937 rnd;
ClientField(); ClientField();
void Clear(); void Clear();
......
...@@ -2172,7 +2172,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2172,7 +2172,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
soundManager.PlaySoundEffect(SOUND_SHUFFLE); soundManager.PlaySoundEffect(SOUND_SHUFFLE);
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
for (auto cit = mainGame->dField.deck[player].begin(); cit != mainGame->dField.deck[player].end(); ++cit) { for (auto cit = mainGame->dField.deck[player].begin(); cit != mainGame->dField.deck[player].end(); ++cit) {
(*cit)->dPos = irr::core::vector3df(rand() * 0.4f / RAND_MAX - 0.2f, 0, 0); (*cit)->dPos = irr::core::vector3df(rnd.rand() * 0.4f / rnd.rand_max - 0.2f, 0, 0);
(*cit)->dRot = irr::core::vector3df(0, 0, 0); (*cit)->dRot = irr::core::vector3df(0, 0, 0);
(*cit)->is_moving = true; (*cit)->is_moving = true;
(*cit)->aniFrame = 3; (*cit)->aniFrame = 3;
...@@ -2244,7 +2244,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2244,7 +2244,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
for (auto cit = mainGame->dField.extra[player].begin(); cit != mainGame->dField.extra[player].end(); ++cit) { for (auto cit = mainGame->dField.extra[player].begin(); cit != mainGame->dField.extra[player].end(); ++cit) {
if(!((*cit)->position & POS_FACEUP)) { if(!((*cit)->position & POS_FACEUP)) {
(*cit)->dPos = irr::core::vector3df(rand() * 0.4f / RAND_MAX - 0.2f, 0, 0); (*cit)->dPos = irr::core::vector3df(rnd.rand() * 0.4f / rnd.rand_max - 0.2f, 0, 0);
(*cit)->dRot = irr::core::vector3df(0, 0, 0); (*cit)->dRot = irr::core::vector3df(0, 0, 0);
(*cit)->is_moving = true; (*cit)->is_moving = true;
(*cit)->aniFrame = 3; (*cit)->aniFrame = 3;
......
...@@ -11,6 +11,7 @@ bool SoundManager::Init() { ...@@ -11,6 +11,7 @@ bool SoundManager::Init() {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
bgm_scene = -1; bgm_scene = -1;
RefreshBGMList(); RefreshBGMList();
rnd.reset((unsigned int)time(nullptr));
engineSound = irrklang::createIrrKlangDevice(); engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice(); engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) { if(!engineSound || !engineMusic) {
...@@ -222,7 +223,7 @@ void SoundManager::PlayBGM(int scene) { ...@@ -222,7 +223,7 @@ void SoundManager::PlayBGM(int scene) {
if(count <= 0) if(count <= 0)
return; return;
bgm_scene = scene; bgm_scene = scene;
int bgm = rand() % count; int bgm = rnd.get_random_integer(0, count -1);
auto name = BGMList[scene][bgm].c_str(); auto name = BGMList[scene][bgm].c_str();
wchar_t fname[1024]; wchar_t fname[1024];
myswprintf(fname, L"./sound/BGM/%ls", name); myswprintf(fname, L"./sound/BGM/%ls", name);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define SOUNDMANAGER_H #define SOUNDMANAGER_H
#include "game.h" #include "game.h"
#include "../ocgcore/mtrandom.h"
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
#include <irrKlang.h> #include <irrKlang.h>
#endif #endif
...@@ -12,6 +13,7 @@ class SoundManager { ...@@ -12,6 +13,7 @@ class SoundManager {
private: private:
std::vector<std::wstring> BGMList[8]; std::vector<std::wstring> BGMList[8];
int bgm_scene; int bgm_scene;
mt19937 rnd;
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
irrklang::ISoundEngine* engineSound; irrklang::ISoundEngine* engineSound;
irrklang::ISoundEngine* engineMusic; irrklang::ISoundEngine* engineMusic;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment