Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gframe/client_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ClientField::ClientField() {
mzone[p].resize(7, 0);
szone[p].resize(8, 0);
}
rnd.reset((uint_fast32_t)std::random_device()());
rnd.seed(std::random_device()());
}
ClientField::~ClientField() {
for (int i = 0; i < 2; ++i) {
Expand Down Expand Up @@ -413,7 +413,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
}
}
if(has_card_in_grave) {
rnd.shuffle_vector(selectable_cards);
std::shuffle(selectable_cards.begin(), selectable_cards.end(), rnd);
}
}
int startpos;
Expand Down
4 changes: 2 additions & 2 deletions gframe/client_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CLIENT_FIELD_H

#include "config.h"
#include "../ocgcore/mtrandom.h"
#include <random>
#include <vector>
#include <set>
#include <map>
Expand Down Expand Up @@ -90,7 +90,7 @@ class ClientField: public irr::IEventReceiver {
bool cant_check_grave{ false };
bool tag_surrender{ false };
bool tag_teammate_surrender{ false };
mt19937 rnd;
std::mt19937 rnd;

ClientField();
~ClientField();
Expand Down
14 changes: 10 additions & 4 deletions gframe/deck_con.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <array>
#include "config.h"
#include "deck_con.h"
#include "myfilesystem.h"
#include "data_manager.h"
#include "deck_manager.h"
#include "image_manager.h"
#include "sound_manager.h"
#include "game.h"
Expand Down Expand Up @@ -54,6 +53,14 @@ static inline void load_current_deck(irr::gui::IGUIComboBox* cbCategory, irr::gu
deckManager.LoadCurrentDeck(cbCategory->getSelected(), cbCategory->getText(), cbDeck->getText());
}

DeckBuilder::DeckBuilder() {
std::random_device rd;
std::array<uint32_t, 8> seed{};
for (auto& x : seed)
x = rd();
std::seed_seq seq(seed.begin(), seed.end());
rnd.seed(seq);
}
void DeckBuilder::Initialize() {
mainGame->is_building = true;
mainGame->is_siding = false;
Expand Down Expand Up @@ -82,7 +89,6 @@ void DeckBuilder::Initialize() {
filterList = &deckManager._lfList.back();
}
ClearSearch();
rnd.reset((uint_fast32_t)std::time(nullptr));
mouse_pos.set(0, 0);
hovered_code = 0;
hovered_pos = 0;
Expand Down Expand Up @@ -175,7 +181,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SHUFFLE_DECK: {
rnd.shuffle_vector(deckManager.current_deck.main);
std::shuffle(deckManager.current_deck.main.begin(), deckManager.current_deck.main.end(), rnd);
break;
}
case BUTTON_SAVE_DECK: {
Expand Down
5 changes: 3 additions & 2 deletions gframe/deck_con.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

#include <unordered_map>
#include <vector>
#include <random>
#include <irrlicht.h>
#include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h"

namespace ygo {

class DeckBuilder: public irr::IEventReceiver {
public:
DeckBuilder();
bool OnEvent(const irr::SEvent& event) override;
void Initialize();
void Terminate();
Expand Down Expand Up @@ -80,7 +81,7 @@ class DeckBuilder: public irr::IEventReceiver {
bool is_modified{};
bool readonly{};
bool showing_pack{};
mt19937 rnd;
std::mt19937 rnd;

const LFList* filterList{};
std::vector<code_pointer> results;
Expand Down
16 changes: 9 additions & 7 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ int DuelClient::last_select_hint = 0;
unsigned char DuelClient::last_successful_msg[SIZE_NETWORK_BUFFER];
size_t DuelClient::last_successful_msg_length = 0;
wchar_t DuelClient::event_string[256];
mt19937 DuelClient::rnd;
std::mt19937 DuelClient::rnd;
std::uniform_real_distribution<float> DuelClient::real_dist;

bool DuelClient::is_refreshing = false;
int DuelClient::match_kill = 0;
Expand Down Expand Up @@ -58,7 +59,7 @@ bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_g
return false;
}
connect_state = 0x1;
rnd.reset((uint_fast32_t)std::random_device()());
rnd.seed(std::random_device()());
if(!create_game) {
timeval timeout = {5, 0};
event* timeout_event = event_new(client_base, 0, EV_TIMEOUT, ConnectTimeout, 0);
Expand Down Expand Up @@ -1753,7 +1754,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
SetResponseI(-1);
mainGame->dField.ClearChainSelect();
if(mainGame->chkWaitChain->isChecked() && !mainGame->ignore_chain) {
mainGame->WaitFrameSignal(rnd.get_random_integer(20, 40));
mainGame->WaitFrameSignal(std::uniform_int_distribution<>(20, 40)(rnd));
}
DuelClient::SendResponse();
return true;
Expand Down Expand Up @@ -1852,9 +1853,10 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
}
if(!pzone) {
if(mainGame->chkRandomPos->isChecked()) {
std::uniform_int_distribution<> dist(0, 6);
do {
respbuf[2] = rnd.get_random_integer(0, 6);
} while(!(filter & (1 << respbuf[2])));
respbuf[2] = dist(rnd);
} while(!(filter & (0x1U << respbuf[2])));
} else {
if (filter & 0x40) respbuf[2] = 6;
else if (filter & 0x20) respbuf[2] = 5;
Expand Down Expand Up @@ -2259,7 +2261,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
soundManager.PlaySoundEffect(SOUND_SHUFFLE);
for (int i = 0; i < 5; ++i) {
for (auto cit = mainGame->dField.deck[player].begin(); cit != mainGame->dField.deck[player].end(); ++cit) {
(*cit)->dPos = irr::core::vector3df(rnd.rand() * 0.4f / rnd.rand_max - 0.2f, 0, 0);
(*cit)->dPos = irr::core::vector3df(real_dist(rnd) * 0.4f - 0.2f, 0, 0);
(*cit)->dRot = irr::core::vector3df(0, 0, 0);
(*cit)->is_moving = true;
(*cit)->aniFrame = 3;
Expand Down Expand Up @@ -2331,7 +2333,7 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
for (int i = 0; i < 5; ++i) {
for (auto cit = mainGame->dField.extra[player].begin(); cit != mainGame->dField.extra[player].end(); ++cit) {
if(!((*cit)->position & POS_FACEUP)) {
(*cit)->dPos = irr::core::vector3df(rnd.rand() * 0.4f / rnd.rand_max - 0.2f, 0, 0);
(*cit)->dPos = irr::core::vector3df(real_dist(rnd) * 0.4f - 0.2f, 0, 0);
(*cit)->dRot = irr::core::vector3df(0, 0, 0);
(*cit)->is_moving = true;
(*cit)->aniFrame = 3;
Expand Down
5 changes: 3 additions & 2 deletions gframe/duelclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <vector>
#include <set>
#include <random>
#include "network.h"
#include "../ocgcore/mtrandom.h"

namespace ygo {

Expand All @@ -26,7 +26,8 @@ class DuelClient {
static unsigned char last_successful_msg[SIZE_NETWORK_BUFFER];
static size_t last_successful_msg_length;
static wchar_t event_string[256];
static mt19937 rnd;
static std::mt19937 rnd;
static std::uniform_real_distribution<float> real_dist;
static bool is_refreshing;
static int match_kill;
static event* resp_event;
Expand Down
2 changes: 1 addition & 1 deletion gframe/replay_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "duelclient.h"
#include "game.h"
#include "data_manager.h"
#include "../ocgcore/mtrandom.h"
#include <random>
#include <thread>

namespace ygo {
Expand Down
4 changes: 2 additions & 2 deletions gframe/sound_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool SoundManager::Init() {
#ifdef YGOPRO_USE_AUDIO
bgm_scene = -1;
RefreshBGMList();
rnd.reset((unsigned int)std::time(nullptr));
rnd.seed(std::random_device()());
#ifdef YGOPRO_USE_MINIAUDIO
engineConfig = ma_engine_config_init();
#ifdef YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS
Expand Down Expand Up @@ -302,7 +302,7 @@ void SoundManager::PlayBGM(int scene) {
if(count <= 0)
return;
bgm_scene = scene;
int bgm = rnd.get_random_integer(0, count -1);
int bgm = (count > 1) ? std::uniform_int_distribution<>(0, count - 1)(rnd) : 0;
auto name = BGMList[scene][bgm].c_str();
wchar_t BGMName[1024];
myswprintf(BGMName, L"./sound/BGM/%ls", name);
Expand Down
4 changes: 2 additions & 2 deletions gframe/sound_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SOUNDMANAGER_H

#include "game.h"
#include "../ocgcore/mtrandom.h"
#include <random>
#ifdef YGOPRO_USE_MINIAUDIO
#include <miniaudio.h>
#endif
Expand All @@ -16,7 +16,7 @@ class SoundManager {
private:
std::vector<std::wstring> BGMList[8];
int bgm_scene{};
mt19937 rnd;
std::mt19937 rnd;
#ifdef YGOPRO_USE_MINIAUDIO
ma_engine_config engineConfig;
#ifdef YGOPRO_MINIAUDIO_SUPPORT_OPUS_VORBIS
Expand Down