Commit 206d6c4e authored by mercury233's avatar mercury233

Merge branch 'master' of https://github.com/Fluorohydride/ygopro

parents 303137ef d0abf558
...@@ -595,7 +595,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -595,7 +595,7 @@ void ClientField::ShowSelectOption(int select_hint) {
wchar_t textBuffer[256]; wchar_t textBuffer[256];
int count = select_options.size(); int count = select_options.size();
bool quickmode = true; bool quickmode = true;
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
for(auto option : select_options) { for(auto option : select_options) {
if(mainGame->guiFont->getDimension(dataManager.GetDesc(option)).Width > 310) { if(mainGame->guiFont->getDimension(dataManager.GetDesc(option)).Width > 310) {
quickmode = false; quickmode = false;
...@@ -643,7 +643,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -643,7 +643,7 @@ void ClientField::ShowSelectOption(int select_hint) {
myswprintf(textBuffer, dataManager.GetSysString(555)); myswprintf(textBuffer, dataManager.GetSysString(555));
mainGame->wOptions->setText(textBuffer); mainGame->wOptions->setText(textBuffer);
mainGame->PopupElement(mainGame->wOptions); mainGame->PopupElement(mainGame->wOptions);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
void ClientField::ReplaySwap() { void ClientField::ReplaySwap() {
std::swap(deck[0], deck[1]); std::swap(deck[0], deck[1]);
......
...@@ -70,11 +70,11 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) { ...@@ -70,11 +70,11 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <time.h> #include <time.h>
#include <thread>
#include <mutex>
#include "bufferio.h" #include "bufferio.h"
#include "myfilesystem.h" #include "myfilesystem.h"
#include "mymutex.h"
#include "mysignal.h" #include "mysignal.h"
#include "mythread.h"
#include "../ocgcore/ocgapi.h" #include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h" #include "../ocgcore/common.h"
......
...@@ -74,7 +74,7 @@ void DeckBuilder::Initialize() { ...@@ -74,7 +74,7 @@ void DeckBuilder::Initialize() {
mainGame->btnSideShuffle->setVisible(false); mainGame->btnSideShuffle->setVisible(false);
mainGame->btnSideSort->setVisible(false); mainGame->btnSideSort->setVisible(false);
mainGame->btnSideReload->setVisible(false); mainGame->btnSideReload->setVisible(false);
filterList = deckManager._lfList[0].content; filterList = &deckManager._lfList[0].content;
mainGame->cbDBLFList->setSelected(0); mainGame->cbDBLFList->setSelected(0);
ClearSearch(); ClearSearch();
mouse_pos.set(0, 0); mouse_pos.set(0, 0);
...@@ -129,10 +129,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -129,10 +129,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
soundManager.PlaySoundEffect(SOUND_BUTTON); soundManager.PlaySoundEffect(SOUND_BUTTON);
switch(id) { switch(id) {
case BUTTON_CLEAR_DECK: { case BUTTON_CLEAR_DECK: {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1339)); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1339));
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
break; break;
} }
...@@ -183,22 +183,22 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -183,22 +183,22 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int sel = mainGame->cbDBDecks->getSelected(); int sel = mainGame->cbDBDecks->getSelected();
if(sel == -1) if(sel == -1)
break; break;
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
wchar_t textBuffer[256]; wchar_t textBuffer[256];
myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337)); myswprintf(textBuffer, L"%ls\n%ls", mainGame->cbDBDecks->getItem(sel), dataManager.GetSysString(1337));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
break; break;
} }
case BUTTON_LEAVE_GAME: { case BUTTON_LEAVE_GAME: {
if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) { if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356)); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
break; break;
} }
...@@ -363,15 +363,15 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -363,15 +363,15 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case irr::gui::EGET_COMBO_BOX_CHANGED: { case irr::gui::EGET_COMBO_BOX_CHANGED: {
switch(id) { switch(id) {
case COMBOBOX_DBLFLIST: { case COMBOBOX_DBLFLIST: {
filterList = deckManager._lfList[mainGame->cbDBLFList->getSelected()].content; filterList = &deckManager._lfList[mainGame->cbDBLFList->getSelected()].content;
break; break;
} }
case COMBOBOX_DBDECKS: { case COMBOBOX_DBDECKS: {
if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) { if(is_modified && !mainGame->chkIgnoreDeckChanges->isChecked()) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356)); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, dataManager.GetSysString(1356));
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
break; break;
} }
...@@ -917,7 +917,7 @@ void DeckBuilder::FilterCards() { ...@@ -917,7 +917,7 @@ void DeckBuilder::FilterCards() {
if(filter_marks && (data.link_marker & filter_marks)!= filter_marks) if(filter_marks && (data.link_marker & filter_marks)!= filter_marks)
continue; continue;
if(filter_lm) { if(filter_lm) {
if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList)[ptr->first] != filter_lm - 1)) if(filter_lm <= 3 && (!filterList->count(ptr->first) || (*filterList).at(ptr->first) != filter_lm - 1))
continue; continue;
if(filter_lm == 4 && data.ot != 1) if(filter_lm == 4 && data.ot != 1)
continue; continue;
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
int prev_sel; int prev_sel;
bool is_modified; bool is_modified;
std::unordered_map<int, int>* filterList; const std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results; std::vector<code_pointer> results;
wchar_t result_string[8]; wchar_t result_string[8];
}; };
......
...@@ -9,7 +9,7 @@ namespace ygo { ...@@ -9,7 +9,7 @@ namespace ygo {
DeckManager deckManager; DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) { void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = NULL; LFList* cur = nullptr;
FILE* fp = fopen(path, "r"); FILE* fp = fopen(path, "r");
char linebuf[256]; char linebuf[256];
wchar_t strBuffer[256]; wchar_t strBuffer[256];
...@@ -17,33 +17,32 @@ void DeckManager::LoadLFListSingle(const char* path) { ...@@ -17,33 +17,32 @@ void DeckManager::LoadLFListSingle(const char* path) {
while(fgets(linebuf, 256, fp)) { while(fgets(linebuf, 256, fp)) {
if(linebuf[0] == '#') if(linebuf[0] == '#')
continue; continue;
int p = 0, sa = 0, code, count;
if(linebuf[0] == '!') { if(linebuf[0] == '!') {
sa = BufferIO::DecodeUTF8((const char*)(&linebuf[1]), strBuffer); int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) sa--; while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) sa--;
strBuffer[sa] = 0;
LFList newlist; LFList newlist;
_lfList.push_back(newlist); _lfList.push_back(newlist);
cur = &_lfList[_lfList.size() - 1]; cur = &_lfList[_lfList.size() - 1];
memcpy(cur->listName, (const void*)strBuffer, 20 * sizeof(wchar_t)); cur->listName = strBuffer;
cur->listName[sa] = 0;
cur->content = new std::unordered_map<int, int>;
cur->hash = 0x7dfcee6a; cur->hash = 0x7dfcee6a;
continue; continue;
} }
int p = 0;
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++; while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
if(linebuf[p] == 0) if(linebuf[p] == 0)
continue; continue;
linebuf[p++] = 0; linebuf[p++] = 0;
sa = p; int sa = p;
code = atoi(linebuf); int code = atoi(linebuf);
if(code == 0) if(code == 0)
continue; continue;
while(linebuf[p] == ' ' || linebuf[p] == '\t') p++; while(linebuf[p] == ' ' || linebuf[p] == '\t') p++;
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++; while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
linebuf[p] = 0; linebuf[p] = 0;
count = atoi(&linebuf[sa]); int count = atoi(&linebuf[sa]);
if(cur == NULL) continue; if(!cur) continue;
(*cur->content)[code] = count; cur->content[code] = count;
cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count))); cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count)));
} }
fclose(fp); fclose(fp);
...@@ -53,28 +52,29 @@ void DeckManager::LoadLFList() { ...@@ -53,28 +52,29 @@ void DeckManager::LoadLFList() {
LoadLFListSingle("expansions/lflist.conf"); LoadLFListSingle("expansions/lflist.conf");
LoadLFListSingle("lflist.conf"); LoadLFListSingle("lflist.conf");
LFList nolimit; LFList nolimit;
myswprintf(nolimit.listName, L"N/A"); nolimit.listName = L"N/A";
nolimit.hash = 0; nolimit.hash = 0;
nolimit.content = new std::unordered_map<int, int>;
_lfList.push_back(nolimit); _lfList.push_back(nolimit);
} }
wchar_t* DeckManager::GetLFListName(int lfhash) { const wchar_t* DeckManager::GetLFListName(int lfhash) {
for(size_t i = 0; i < _lfList.size(); ++i) { auto lit = std::find_if(_lfList.begin(), _lfList.end(), [lfhash](const ygo::LFList& list) {
if(_lfList[i].hash == (unsigned int)lfhash) { return list.hash == lfhash;
return _lfList[i].listName; });
} if(lit != _lfList.end())
} return lit->listName.c_str();
return (wchar_t*)dataManager.unknown_string; return dataManager.unknown_string;
}
const std::unordered_map<int, int>* DeckManager::GetLFListContent(int lfhash) {
auto lit = std::find_if(_lfList.begin(), _lfList.end(), [lfhash](const ygo::LFList& list) {
return list.hash == lfhash;
});
if(lit != _lfList.end())
return &lit->content;
return nullptr;
} }
int DeckManager::CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg) { int DeckManager::CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg) {
std::unordered_map<int, int> ccount; std::unordered_map<int, int> ccount;
std::unordered_map<int, int>* list = 0; auto list = GetLFListContent(lfhash);
for(size_t i = 0; i < _lfList.size(); ++i) {
if(_lfList[i].hash == (unsigned int)lfhash) {
list = _lfList[i].content;
break;
}
}
if(!list) if(!list)
return 0; return 0;
int dc = 0; int dc = 0;
......
...@@ -10,8 +10,8 @@ namespace ygo { ...@@ -10,8 +10,8 @@ namespace ygo {
struct LFList { struct LFList {
unsigned int hash; unsigned int hash;
wchar_t listName[20]; std::wstring listName;
std::unordered_map<int, int>* content; std::unordered_map<int, int> content;
}; };
struct Deck { struct Deck {
std::vector<code_pointer> main; std::vector<code_pointer> main;
...@@ -37,7 +37,8 @@ public: ...@@ -37,7 +37,8 @@ public:
void LoadLFListSingle(const char* path); void LoadLFListSingle(const char* path);
void LoadLFList(); void LoadLFList();
wchar_t* GetLFListName(int lfhash); const wchar_t* GetLFListName(int lfhash);
const std::unordered_map<int, int>* GetLFListContent(int lfhash);
int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg); int CheckDeck(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec); int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec); bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
......
...@@ -1037,7 +1037,7 @@ void Game::WaitFrameSignal(int frame) { ...@@ -1037,7 +1037,7 @@ void Game::WaitFrameSignal(int frame) {
signalFrame = (gameConf.quick_animation && frame >= 12) ? 12 : frame; signalFrame = (gameConf.quick_animation && frame >= 12) ? 12 : frame;
frameSignal.Wait(); frameSignal.Wait();
} }
void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag) { void Game::DrawThumb(code_pointer cp, position2di pos, const std::unordered_map<int,int>* lflist, bool drag) {
int code = cp->first; int code = cp->first;
int lcode = cp->second.alias; int lcode = cp->second.alias;
if(lcode == 0) if(lcode == 0)
...@@ -1056,7 +1056,7 @@ void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, i ...@@ -1056,7 +1056,7 @@ void Game::DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, i
} }
driver->draw2DImage(img, dragloc, rect<s32>(0, 0, size.Width, size.Height)); driver->draw2DImage(img, dragloc, rect<s32>(0, 0, size.Width, size.Height));
if(lflist->count(lcode)) { if(lflist->count(lcode)) {
switch((*lflist)[lcode]) { switch((*lflist).at(lcode)) {
case 0: case 0:
driver->draw2DImage(imageManager.tLim, limitloc, recti(0, 0, 64, 64), 0, 0, true); driver->draw2DImage(imageManager.tLim, limitloc, recti(0, 0, 64, 64), 0, 0, true);
break; break;
...@@ -1142,8 +1142,8 @@ void Game::DrawDeckBd() { ...@@ -1142,8 +1142,8 @@ void Game::DrawDeckBd() {
driver->draw2DRectangleOutline(Resize(313 + i * dx, 563, 359 + i * dx, 629)); driver->draw2DRectangleOutline(Resize(313 + i * dx, 563, 359 + i * dx, 629));
} }
//search result //search result
driver->draw2DRectangle(Resize(805, 137, 915, 157), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000); driver->draw2DRectangle(Resize(805, 137, 926, 157), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
driver->draw2DRectangleOutline(Resize(804, 136, 915, 157)); driver->draw2DRectangleOutline(Resize(804, 136, 926, 157));
DrawShadowText(textFont, dataManager.GetSysString(1333), Resize(810, 137, 915, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true); DrawShadowText(textFont, dataManager.GetSysString(1333), Resize(810, 137, 915, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true); DrawShadowText(numFont, deckBuilder.result_string, Resize(875, 137, 935, 157), Resize(1, 1, 1, 1), 0xffffffff, 0xff000000, false, true);
driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000); driver->draw2DRectangle(Resize(805, 160, 1020, 630), 0x400000ff, 0x400000ff, 0x40000000, 0x40000000);
......
This diff is collapsed.
...@@ -33,7 +33,7 @@ private: ...@@ -33,7 +33,7 @@ private:
static int select_hint; static int select_hint;
static int select_unselect_hint; static int select_unselect_hint;
static int last_select_hint; static int last_select_hint;
static char last_successful_msg[2048]; static char last_successful_msg[0x2000];
static unsigned int last_successful_msg_length; static unsigned int last_successful_msg_length;
static wchar_t event_string[256]; static wchar_t event_string[256];
static mtrandom rnd; static mtrandom rnd;
...@@ -43,7 +43,7 @@ public: ...@@ -43,7 +43,7 @@ public:
static void StopClient(bool is_exiting = false); static void StopClient(bool is_exiting = false);
static void ClientRead(bufferevent* bev, void* ctx); static void ClientRead(bufferevent* bev, void* ctx);
static void ClientEvent(bufferevent *bev, short events, void *ctx); static void ClientEvent(bufferevent *bev, short events, void *ctx);
static int ClientThread(void* param); static int ClientThread();
static void HandleSTOCPacketLan(char* data, unsigned int len); static void HandleSTOCPacketLan(char* data, unsigned int len);
static int ClientAnalyze(char* msg, unsigned int len); static int ClientAnalyze(char* msg, unsigned int len);
static void SwapField(); static void SwapField();
...@@ -80,7 +80,7 @@ protected: ...@@ -80,7 +80,7 @@ protected:
public: public:
static std::vector<HostPacket> hosts; static std::vector<HostPacket> hosts;
static void BeginRefreshHost(); static void BeginRefreshHost();
static int RefreshThread(void* arg); static int RefreshThread(event_base* broadev);
static void BroadcastReply(evutil_socket_t fd, short events, void* arg); static void BroadcastReply(evutil_socket_t fd, short events, void* arg);
}; };
......
...@@ -1537,8 +1537,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1537,8 +1537,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
myswprintf(formatBuffer, L"%ls", dataManager.GetName(mcard->code)); myswprintf(formatBuffer, L"%ls", dataManager.GetName(mcard->code));
str.append(formatBuffer); str.append(formatBuffer);
if(mcard->type & TYPE_MONSTER) { if(mcard->type & TYPE_MONSTER) {
if(mcard->alias && (mcard->alias < mcard->code - 10 || mcard->alias > mcard->code + 10) if(mcard->alias && wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
&& wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias)); myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias));
str.append(formatBuffer); str.append(formatBuffer);
} }
...@@ -1560,7 +1559,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -1560,7 +1559,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
str.append(formatBuffer); str.append(formatBuffer);
} }
} else { } else {
if(mcard->alias && (mcard->alias < mcard->code - 10 || mcard->alias > mcard->code + 10)) { if(mcard->alias && wcscmp(dataManager.GetName(mcard->code), dataManager.GetName(mcard->alias))) {
myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias)); myswprintf(formatBuffer, L"\n(%ls)", dataManager.GetName(mcard->alias));
str.append(formatBuffer); str.append(formatBuffer);
} }
......
...@@ -131,7 +131,7 @@ bool Game::Initialize() { ...@@ -131,7 +131,7 @@ bool Game::Initialize() {
env->addStaticText(dataManager.GetSysString(1226), rect<s32>(20, 30, 220, 50), false, false, wCreateHost); env->addStaticText(dataManager.GetSysString(1226), rect<s32>(20, 30, 220, 50), false, false, wCreateHost);
cbLFlist = env->addComboBox(rect<s32>(140, 25, 300, 50), wCreateHost); cbLFlist = env->addComboBox(rect<s32>(140, 25, 300, 50), wCreateHost);
for(unsigned int i = 0; i < deckManager._lfList.size(); ++i) for(unsigned int i = 0; i < deckManager._lfList.size(); ++i)
cbLFlist->addItem(deckManager._lfList[i].listName, deckManager._lfList[i].hash); cbLFlist->addItem(deckManager._lfList[i].listName.c_str(), deckManager._lfList[i].hash);
env->addStaticText(dataManager.GetSysString(1225), rect<s32>(20, 60, 220, 80), false, false, wCreateHost); env->addStaticText(dataManager.GetSysString(1225), rect<s32>(20, 60, 220, 80), false, false, wCreateHost);
cbRule = env->addComboBox(rect<s32>(140, 55, 300, 80), wCreateHost); cbRule = env->addComboBox(rect<s32>(140, 55, 300, 80), wCreateHost);
cbRule->addItem(dataManager.GetSysString(1240)); cbRule->addItem(dataManager.GetSysString(1240));
...@@ -510,7 +510,7 @@ bool Game::Initialize() { ...@@ -510,7 +510,7 @@ bool Game::Initialize() {
cbDBDecks = env->addComboBox(rect<s32>(80, 35, 220, 60), wDeckEdit, COMBOBOX_DBDECKS); cbDBDecks = env->addComboBox(rect<s32>(80, 35, 220, 60), wDeckEdit, COMBOBOX_DBDECKS);
cbDBDecks->setMaxSelectionRows(15); cbDBDecks->setMaxSelectionRows(15);
for(unsigned int i = 0; i < deckManager._lfList.size(); ++i) for(unsigned int i = 0; i < deckManager._lfList.size(); ++i)
cbDBLFList->addItem(deckManager._lfList[i].listName); cbDBLFList->addItem(deckManager._lfList[i].listName.c_str());
btnSaveDeck = env->addButton(rect<s32>(225, 35, 290, 60), wDeckEdit, BUTTON_SAVE_DECK, dataManager.GetSysString(1302)); btnSaveDeck = env->addButton(rect<s32>(225, 35, 290, 60), wDeckEdit, BUTTON_SAVE_DECK, dataManager.GetSysString(1302));
ebDeckname = env->addEditBox(L"", rect<s32>(80, 65, 220, 90), true, wDeckEdit, -1); ebDeckname = env->addEditBox(L"", rect<s32>(80, 65, 220, 90), true, wDeckEdit, -1);
ebDeckname->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); ebDeckname->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
...@@ -791,7 +791,7 @@ void Game::MainLoop() { ...@@ -791,7 +791,7 @@ void Game::MainLoop() {
atkframe += 0.1f; atkframe += 0.1f;
atkdy = (float)sin(atkframe); atkdy = (float)sin(atkframe);
driver->beginScene(true, true, SColor(0, 0, 0, 0)); driver->beginScene(true, true, SColor(0, 0, 0, 0));
gMutex.Lock(); gMutex.lock();
if(dInfo.isStarted) { if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1) if(dInfo.isFinished && showcardcode == 1)
soundManager.PlayBGM(BGM_WIN); soundManager.PlayBGM(BGM_WIN);
...@@ -820,7 +820,7 @@ void Game::MainLoop() { ...@@ -820,7 +820,7 @@ void Game::MainLoop() {
} }
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
gMutex.Unlock(); gMutex.unlock();
if(signalFrame > 0) { if(signalFrame > 0) {
signalFrame--; signalFrame--;
if(!signalFrame) if(!signalFrame)
...@@ -837,16 +837,12 @@ void Game::MainLoop() { ...@@ -837,16 +837,12 @@ void Game::MainLoop() {
} }
} }
driver->endScene(); driver->endScene();
if(closeSignal.Wait(0)) if(closeSignal.Wait(1))
CloseDuelWindow(); CloseDuelWindow();
fps++; fps++;
cur_time = timer->getTime(); cur_time = timer->getTime();
if(cur_time < fps * 17 - 20) if(cur_time < fps * 17 - 20)
#ifdef _WIN32 std::this_thread::sleep_for(std::chrono::milliseconds(20));
Sleep(20);
#else
usleep(20000);
#endif
if(cur_time >= 1000) { if(cur_time >= 1000) {
myswprintf(cap, L"YGOPro FPS: %d", fps); myswprintf(cap, L"YGOPro FPS: %d", fps);
device->setWindowCaption(cap); device->setWindowCaption(cap);
...@@ -861,11 +857,7 @@ void Game::MainLoop() { ...@@ -861,11 +857,7 @@ void Game::MainLoop() {
DuelClient::StopClient(true); DuelClient::StopClient(true);
if(dInfo.isSingleMode) if(dInfo.isSingleMode)
SingleMode::StopPlay(true); SingleMode::StopPlay(true);
#ifdef _WIN32 std::this_thread::sleep_for(std::chrono::milliseconds(500));
Sleep(500);
#else
usleep(500000);
#endif
SaveConfig(); SaveConfig();
// device->drop(); // device->drop();
} }
......
...@@ -134,7 +134,7 @@ public: ...@@ -134,7 +134,7 @@ public:
void HideElement(irr::gui::IGUIElement* element, bool set_action = false); void HideElement(irr::gui::IGUIElement* element, bool set_action = false);
void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0); void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0);
void WaitFrameSignal(int frame); void WaitFrameSignal(int frame);
void DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag = false); void DrawThumb(code_pointer cp, position2di pos, const std::unordered_map<int,int>* lflist, bool drag = false);
void DrawDeckBd(); void DrawDeckBd();
void LoadConfig(); void LoadConfig();
void SaveConfig(); void SaveConfig();
...@@ -175,8 +175,7 @@ public: ...@@ -175,8 +175,7 @@ public:
void FlashWindow(); void FlashWindow();
void SetCursor(ECURSOR_ICON icon); void SetCursor(ECURSOR_ICON icon);
Mutex gMutex; std::mutex gMutex;
Mutex gBuffer;
Signal frameSignal; Signal frameSignal;
Signal actionSignal; Signal actionSignal;
Signal replaySignal; Signal replaySignal;
......
...@@ -80,10 +80,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -80,10 +80,10 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
hints.ai_flags = EVUTIL_AI_ADDRCONFIG; hints.ai_flags = EVUTIL_AI_ADDRCONFIG;
int status = evutil_getaddrinfo(hostname, port, &hints, &answer); int status = evutil_getaddrinfo(hostname, port, &hints, &answer);
if(status != 0) { if(status != 0) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
soundManager.PlaySoundEffect(SOUND_INFO); soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1412)); mainGame->env->addMessageBox(L"", dataManager.GetSysString(1412));
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
break; break;
} else { } else {
sockaddr_in * sin = ((struct sockaddr_in *)answer->ai_addr); sockaddr_in * sin = ((struct sockaddr_in *)answer->ai_addr);
...@@ -245,12 +245,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -245,12 +245,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int sel = mainGame->lstReplayList->getSelected(); int sel = mainGame->lstReplayList->getSelected();
if(sel == -1) if(sel == -1)
break; break;
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
wchar_t textBuffer[256]; wchar_t textBuffer[256];
myswprintf(textBuffer, L"%ls\n%ls", mainGame->lstReplayList->getListItem(sel), dataManager.GetSysString(1363)); myswprintf(textBuffer, L"%ls\n%ls", mainGame->lstReplayList->getListItem(sel), dataManager.GetSysString(1363));
mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, textBuffer); mainGame->SetStaticText(mainGame->stQMessage, 310, mainGame->guiFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery); mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
break; break;
...@@ -259,11 +259,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -259,11 +259,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int sel = mainGame->lstReplayList->getSelected(); int sel = mainGame->lstReplayList->getSelected();
if(sel == -1) if(sel == -1)
break; break;
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->wReplaySave->setText(dataManager.GetSysString(1364)); mainGame->wReplaySave->setText(dataManager.GetSysString(1364));
mainGame->ebRSName->setText(mainGame->lstReplayList->getListItem(sel)); mainGame->ebRSName->setText(mainGame->lstReplayList->getListItem(sel));
mainGame->PopupElement(mainGame->wReplaySave); mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
break; break;
......
#ifndef MUTEX_H
#define MUTEX_H
#ifdef _WIN32
#include <windows.h>
class Mutex {
public:
Mutex() {
InitializeCriticalSection(&_mutex);
}
~Mutex() {
DeleteCriticalSection(&_mutex);
}
void Lock() {
EnterCriticalSection(&_mutex);
}
void Unlock() {
LeaveCriticalSection(&_mutex);
}
bool TryLock() {
return TryEnterCriticalSection(&_mutex) == TRUE;
}
private:
CRITICAL_SECTION _mutex;
};
#else // _WIN32
#include <pthread.h>
class Mutex {
public:
Mutex() {
pthread_mutex_init(&mutex_t, NULL);
}
~Mutex() {
pthread_mutex_destroy(&mutex_t);
}
void Lock() {
pthread_mutex_lock(&mutex_t);
}
void Unlock() {
pthread_mutex_unlock(&mutex_t);
}
bool TryLock() {
return !pthread_mutex_trylock(&mutex_t);
}
private:
pthread_mutex_t mutex_t;
};
#endif // _WIN32
#endif // MUTEX_H
#ifndef SIGNAL_H #ifndef SIGNAL_H
#define SIGNAL_H #define SIGNAL_H
#ifdef _WIN32 #include <mutex>
#include <condition_variable>
#include <windows.h>
class Signal {
public:
Signal() {
_event = CreateEvent(0, FALSE, FALSE, 0);
_nowait = false;
}
~Signal() {
CloseHandle(_event);
}
void Set() {
SetEvent(_event);
}
void Reset() {
ResetEvent(_event);
}
void Wait() {
if(_nowait)
return;
WaitForSingleObject(_event, INFINITE);
}
bool Wait(long milli) {
if(_nowait)
return false;
return WaitForSingleObject(_event, milli + 1) != WAIT_TIMEOUT;
}
void SetNoWait(bool nowait) {
_nowait = nowait;
}
private:
HANDLE _event;
bool _nowait;
};
#else // _WIN32
#include <sys/time.h>
#include <pthread.h>
class Signal { class Signal {
public: public:
Signal() { Signal() {
_state = false; _state = false;
_nowait = false; _nowait = false;
pthread_mutex_init(&_mutex, NULL);
pthread_cond_init(&_cond, NULL);
} }
~Signal() { ~Signal() {
pthread_cond_destroy(&_cond);
pthread_mutex_destroy(&_mutex);
} }
void Set() { void Set() {
if(pthread_mutex_lock(&_mutex)) std::unique_lock<std::mutex> lock(_mutex);
return;
_state = true; _state = true;
if(pthread_cond_broadcast(&_cond)) _cond.notify_all();
{
pthread_mutex_unlock(&_mutex);
// ERROR Broadcasting event status!
return;
}
pthread_mutex_unlock(&_mutex);
} }
void Reset() { void Reset() {
if(pthread_mutex_lock(&_mutex)) std::unique_lock<std::mutex> lock(_mutex);
return;
_state = false; _state = false;
pthread_mutex_unlock(&_mutex);
} }
void Wait() { void Wait() {
if(_nowait || pthread_mutex_lock(&_mutex)) if(_nowait)
return; return;
while(!_state) std::unique_lock<std::mutex> lock(_mutex);
{ _cond.wait(lock, [this]() { return _state; });
if(pthread_cond_wait(&_cond, &_mutex))
{
pthread_mutex_unlock(&_mutex);
// ERROR Waiting events;
return;
}
}
_state = false; _state = false;
pthread_mutex_unlock(&_mutex);
} }
bool Wait(long milliseconds) bool Wait(long milliseconds) {
{ if(_nowait)
if (_nowait || pthread_mutex_lock(&_mutex) != 0)
return false; return false;
std::unique_lock<std::mutex> lock(_mutex);
int rc = 0; bool res = _cond.wait_for(lock, std::chrono::milliseconds(milliseconds), [this]() { return _state; });
struct timespec abstime;
struct timeval tv;
gettimeofday(&tv, NULL);
abstime.tv_sec = tv.tv_sec + milliseconds / 1000;
abstime.tv_nsec = tv.tv_usec*1000 + (milliseconds % 1000)*1000000;
if (abstime.tv_nsec >= 1000000000)
{
abstime.tv_nsec -= 1000000000;
abstime.tv_sec++;
}
while (!_state)
{
if ((rc = pthread_cond_timedwait(&_cond, &_mutex, &abstime)))
{
if (rc == ETIMEDOUT) break;
pthread_mutex_unlock(&_mutex);
return false;
}
}
_state = false; _state = false;
pthread_mutex_unlock(&_mutex); return res;
return rc == 0;
} }
void SetNoWait(bool nowait) { void SetNoWait(bool nowait) {
_nowait = nowait; _nowait = nowait;
} }
private: private:
pthread_mutex_t _mutex; std::mutex _mutex;
pthread_cond_t _cond; std::condition_variable _cond;
bool _state; bool _state;
bool _nowait; bool _nowait;
}; };
#endif // _WIN32
#endif // SIGNAL_H #endif // SIGNAL_H
#ifndef THREAD_H
#define THREAD_H
#ifdef _WIN32
#include <windows.h>
class Thread {
public:
static void NewThread(int (*thread_func)(void*), void* param) {
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_func, param, 0, 0);
}
};
#else // _WIN32
#include <pthread.h>
class Thread {
public:
static void NewThread(int (*thread_func)(void*), void* param) {
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_create(&thread, &attr, (void * (*)(void *))thread_func, param);
}
};
#endif // _WIN32
#endif // THREAD_H
...@@ -33,7 +33,7 @@ bool NetServer::StartServer(unsigned short port) { ...@@ -33,7 +33,7 @@ bool NetServer::StartServer(unsigned short port) {
return false; return false;
} }
evconnlistener_set_error_cb(listener, ServerAcceptError); evconnlistener_set_error_cb(listener, ServerAcceptError);
Thread::NewThread(ServerThread, net_evbase); std::thread(ServerThread).detach();
return true; return true;
} }
bool NetServer::StartBroadcast() { bool NetServer::StartBroadcast() {
...@@ -136,7 +136,7 @@ void NetServer::ServerEchoEvent(bufferevent* bev, short events, void* ctx) { ...@@ -136,7 +136,7 @@ void NetServer::ServerEchoEvent(bufferevent* bev, short events, void* ctx) {
else DisconnectPlayer(dp); else DisconnectPlayer(dp);
} }
} }
int NetServer::ServerThread(void* param) { int NetServer::ServerThread() {
event_base_dispatch(net_evbase); event_base_dispatch(net_evbase);
for(auto bit = users.begin(); bit != users.end(); ++bit) { for(auto bit = users.begin(); bit != users.end(); ++bit) {
bufferevent_disable(bit->first, EV_READ); bufferevent_disable(bit->first, EV_READ);
......
...@@ -33,7 +33,7 @@ public: ...@@ -33,7 +33,7 @@ public:
static void ServerAcceptError(evconnlistener *listener, void* ctx); static void ServerAcceptError(evconnlistener *listener, void* ctx);
static void ServerEchoRead(bufferevent* bev, void* ctx); static void ServerEchoRead(bufferevent* bev, void* ctx);
static void ServerEchoEvent(bufferevent* bev, short events, void* ctx); static void ServerEchoEvent(bufferevent* bev, short events, void* ctx);
static int ServerThread(void* param); static int ServerThread();
static void DisconnectPlayer(DuelPlayer* dp); static void DisconnectPlayer(DuelPlayer* dp);
static void HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len); static void HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len);
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto) { static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto) {
......
...@@ -24,7 +24,7 @@ bool ReplayMode::StartReplay(int skipturn) { ...@@ -24,7 +24,7 @@ bool ReplayMode::StartReplay(int skipturn) {
skip_turn = skipturn; skip_turn = skipturn;
if(skip_turn < 0) if(skip_turn < 0)
skip_turn = 0; skip_turn = 0;
Thread::NewThread(ReplayThread, 0); std::thread(ReplayThread).detach();
return true; return true;
} }
void ReplayMode::StopReplay(bool is_exiting) { void ReplayMode::StopReplay(bool is_exiting) {
...@@ -56,7 +56,7 @@ bool ReplayMode::ReadReplayResponse() { ...@@ -56,7 +56,7 @@ bool ReplayMode::ReadReplayResponse() {
set_responseb(pduel, resp); set_responseb(pduel, resp);
return result; return result;
} }
int ReplayMode::ReplayThread(void* param) { int ReplayMode::ReplayThread() {
const ReplayHeader& rh = cur_replay.pheader; const ReplayHeader& rh = cur_replay.pheader;
mainGame->dInfo.isFirst = true; mainGame->dInfo.isFirst = true;
mainGame->dInfo.isTag = !!(rh.flag & REPLAY_TAG); mainGame->dInfo.isTag = !!(rh.flag & REPLAY_TAG);
...@@ -90,7 +90,7 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -90,7 +90,7 @@ int ReplayMode::ReplayThread(void* param) {
exit_pending = false; exit_pending = false;
current_step = 0; current_step = 0;
if(mainGame->dInfo.isReplaySkiping) if(mainGame->dInfo.isReplaySkiping)
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
while (is_continuing && !exit_pending) { while (is_continuing && !exit_pending) {
int result = process(pduel); int result = process(pduel);
int len = result & 0xffff; int len = result & 0xffff;
...@@ -99,7 +99,7 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -99,7 +99,7 @@ int ReplayMode::ReplayThread(void* param) {
get_message(pduel, (byte*)engineBuffer); get_message(pduel, (byte*)engineBuffer);
is_continuing = ReplayAnalyze(engineBuffer, len); is_continuing = ReplayAnalyze(engineBuffer, len);
if(is_restarting) { if(is_restarting) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
is_restarting = false; is_restarting = false;
mainGame->dInfo.isReplaySkiping = true; mainGame->dInfo.isReplaySkiping = true;
Restart(false); Restart(false);
...@@ -125,7 +125,7 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -125,7 +125,7 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->dInfo.isFinished = false; mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
skip_step = step; skip_step = step;
current_step = 0; current_step = 0;
...@@ -135,7 +135,7 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -135,7 +135,7 @@ int ReplayMode::ReplayThread(void* param) {
if(mainGame->dInfo.isReplaySkiping) { if(mainGame->dInfo.isReplaySkiping) {
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
EndDuel(); EndDuel();
return 0; return 0;
...@@ -228,26 +228,26 @@ void ReplayMode::EndDuel() { ...@@ -228,26 +228,26 @@ void ReplayMode::EndDuel() {
end_duel(pduel); end_duel(pduel);
if(!is_closing) { if(!is_closing) {
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->stMessage->setText(dataManager.GetSysString(1501)); mainGame->stMessage->setText(dataManager.GetSysString(1501));
if(mainGame->wCardSelect->isVisible()) if(mainGame->wCardSelect->isVisible())
mainGame->HideElement(mainGame->wCardSelect); mainGame->HideElement(mainGame->wCardSelect);
mainGame->PopupElement(mainGame->wMessage); mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = true; mainGame->dInfo.isFinished = true;
mainGame->dInfo.isReplay = false; mainGame->dInfo.isReplay = false;
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->closeDoneSignal.Reset(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait(); mainGame->closeDoneSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->ShowElement(mainGame->wReplay); mainGame->ShowElement(mainGame->wReplay);
mainGame->stTip->setVisible(false); mainGame->stTip->setVisible(false);
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
if(exit_on_return) if(exit_on_return)
mainGame->device->closeDevice(); mainGame->device->closeDevice();
} }
...@@ -291,9 +291,9 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) { ...@@ -291,9 +291,9 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
return true; return true;
} }
if(is_swaping) { if(is_swaping) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->dField.ReplaySwap(); mainGame->dField.ReplaySwap();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
is_swaping = false; is_swaping = false;
} }
char* offset = pbuf; char* offset = pbuf;
...@@ -304,12 +304,12 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) { ...@@ -304,12 +304,12 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
if(mainGame->dInfo.isReplaySkiping) { if(mainGame->dInfo.isReplaySkiping) {
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->stMessage->setText(L"Error occurs."); mainGame->stMessage->setText(L"Error occurs.");
mainGame->PopupElement(mainGame->wMessage); mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
return false; return false;
...@@ -323,7 +323,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) { ...@@ -323,7 +323,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
if(mainGame->dInfo.isReplaySkiping) { if(mainGame->dInfo.isReplaySkiping) {
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
pbuf += 2; pbuf += 2;
DuelClient::ClientAnalyze(offset, pbuf - offset); DuelClient::ClientAnalyze(offset, pbuf - offset);
...@@ -505,7 +505,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) { ...@@ -505,7 +505,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
if(skip_turn == 0) { if(skip_turn == 0) {
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
} }
player = BufferIO::ReadInt8(pbuf); player = BufferIO::ReadInt8(pbuf);
...@@ -842,7 +842,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) { ...@@ -842,7 +842,7 @@ bool ReplayMode::ReplayAnalyze(char* msg, unsigned int len) {
mainGame->dInfo.isFinished = false; mainGame->dInfo.isFinished = false;
mainGame->dInfo.isReplaySkiping = false; mainGame->dInfo.isReplaySkiping = false;
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
} }
} }
if(is_pausing) { if(is_pausing) {
......
...@@ -32,7 +32,7 @@ public: ...@@ -32,7 +32,7 @@ public:
static void SwapField(); static void SwapField();
static void Pause(bool is_pause, bool is_step); static void Pause(bool is_pause, bool is_step);
static bool ReadReplayResponse(); static bool ReadReplayResponse();
static int ReplayThread(void* param); static int ReplayThread();
static bool StartDuel(); static bool StartDuel();
static void EndDuel(); static void EndDuel();
static void Restart(bool refresh); static void Restart(bool refresh);
......
...@@ -12,7 +12,7 @@ bool SingleMode::is_continuing = false; ...@@ -12,7 +12,7 @@ bool SingleMode::is_continuing = false;
Replay SingleMode::last_replay; Replay SingleMode::last_replay;
bool SingleMode::StartPlay() { bool SingleMode::StartPlay() {
Thread::NewThread(SinglePlayThread, 0); std::thread(SinglePlayThread).detach();
return true; return true;
} }
void SingleMode::StopPlay(bool is_exiting) { void SingleMode::StopPlay(bool is_exiting) {
...@@ -28,7 +28,7 @@ void SingleMode::SetResponse(unsigned char* resp, unsigned int len) { ...@@ -28,7 +28,7 @@ void SingleMode::SetResponse(unsigned char* resp, unsigned int len) {
last_replay.WriteData(resp, len); last_replay.WriteData(resp, len);
set_responseb(pduel, resp); set_responseb(pduel, resp);
} }
int SingleMode::SinglePlayThread(void* param) { int SingleMode::SinglePlayThread() {
const int start_lp = 8000; const int start_lp = 8000;
const int start_hand = 5; const int start_hand = 5;
const int draw_count = 1; const int draw_count = 1;
...@@ -79,7 +79,7 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -79,7 +79,7 @@ int SingleMode::SinglePlayThread(void* param) {
rh.version = PRO_VERSION; rh.version = PRO_VERSION;
rh.flag = REPLAY_SINGLE_MODE; rh.flag = REPLAY_SINGLE_MODE;
rh.seed = seed; rh.seed = seed;
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->HideElement(mainGame->wSinglePlay); mainGame->HideElement(mainGame->wSinglePlay);
mainGame->ClearCardInfo(); mainGame->ClearCardInfo();
mainGame->wCardImg->setVisible(true); mainGame->wCardImg->setVisible(true);
...@@ -93,7 +93,7 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -93,7 +93,7 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->dInfo.isFinished = false; mainGame->dInfo.isFinished = false;
mainGame->dInfo.isSingleMode = true; mainGame->dInfo.isSingleMode = true;
mainGame->device->setEventReceiver(&mainGame->dField); mainGame->device->setEventReceiver(&mainGame->dField);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
char engineBuffer[0x1000]; char engineBuffer[0x1000];
is_closing = false; is_closing = false;
is_continuing = true; is_continuing = true;
...@@ -125,6 +125,7 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -125,6 +125,7 @@ int SingleMode::SinglePlayThread(void* param) {
} }
} }
last_replay.EndRecord(); last_replay.EndRecord();
mainGame->gMutex.lock();
time_t nowtime = time(NULL); time_t nowtime = time(NULL);
tm* localedtime = localtime(&nowtime); tm* localedtime = localtime(&nowtime);
wchar_t timetext[40]; wchar_t timetext[40];
...@@ -133,7 +134,7 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -133,7 +134,7 @@ int SingleMode::SinglePlayThread(void* param) {
if(!mainGame->chkAutoSaveReplay->isChecked()) { if(!mainGame->chkAutoSaveReplay->isChecked()) {
mainGame->wReplaySave->setText(dataManager.GetSysString(1340)); mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
mainGame->PopupElement(mainGame->wReplaySave); mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->replaySignal.Reset(); mainGame->replaySignal.Reset();
mainGame->replaySignal.Wait(); mainGame->replaySignal.Wait();
} else { } else {
...@@ -142,26 +143,26 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -142,26 +143,26 @@ int SingleMode::SinglePlayThread(void* param) {
myswprintf(msgbuf, dataManager.GetSysString(1367), timetext); myswprintf(msgbuf, dataManager.GetSysString(1367), timetext);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf); mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf);
mainGame->PopupElement(mainGame->wACMessage, 20); mainGame->PopupElement(mainGame->wACMessage, 20);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->WaitFrameSignal(30); mainGame->WaitFrameSignal(30);
} }
if(mainGame->actionParam) if(mainGame->actionParam)
last_replay.SaveReplay(mainGame->ebRSName->getText()); last_replay.SaveReplay(mainGame->ebRSName->getText());
end_duel(pduel); end_duel(pduel);
if(!is_closing) { if(!is_closing) {
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isFinished = true; mainGame->dInfo.isFinished = true;
mainGame->dInfo.isSingleMode = false; mainGame->dInfo.isSingleMode = false;
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->closeDoneSignal.Reset(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait(); mainGame->closeDoneSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->ShowElement(mainGame->wSinglePlay); mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->stTip->setVisible(false); mainGame->stTip->setVisible(false);
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
if(exit_on_return) if(exit_on_return)
mainGame->device->closeDevice(); mainGame->device->closeDevice();
} }
...@@ -731,9 +732,9 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) { ...@@ -731,9 +732,9 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
pbuf++; pbuf++;
DuelClient::ClientAnalyze(offset, pbuf - offset); DuelClient::ClientAnalyze(offset, pbuf - offset);
SinglePlayReload(); SinglePlayReload();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->dField.RefreshAllCards(); mainGame->dField.RefreshAllCards();
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
break; break;
} }
case MSG_AI_NAME: { case MSG_AI_NAME: {
...@@ -755,10 +756,10 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) { ...@@ -755,10 +756,10 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) {
pbuf += len + 1; pbuf += len + 1;
memcpy(msgbuf, begin, len + 1); memcpy(msgbuf, begin, len + 1);
BufferIO::DecodeUTF8(msgbuf, msg); BufferIO::DecodeUTF8(msgbuf, msg);
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->guiFont, msg); mainGame->SetStaticText(mainGame->stMessage, 310, mainGame->guiFont, msg);
mainGame->PopupElement(mainGame->wMessage); mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
break; break;
......
...@@ -15,7 +15,7 @@ public: ...@@ -15,7 +15,7 @@ public:
static bool StartPlay(); static bool StartPlay();
static void StopPlay(bool is_exiting = false); static void StopPlay(bool is_exiting = false);
static void SetResponse(unsigned char* resp, unsigned int len); static void SetResponse(unsigned char* resp, unsigned int len);
static int SinglePlayThread(void* param); static int SinglePlayThread();
static bool SinglePlayAnalyze(char* msg, unsigned int len); static bool SinglePlayAnalyze(char* msg, unsigned int len);
static void SinglePlayRefresh(int flag = 0xf81fff); static void SinglePlayRefresh(int flag = 0xf81fff);
......
This diff is collapsed.
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
!system 5 特殊召唤成功 !system 5 特殊召唤成功
!system 6 反转召唤成功 !system 6 反转召唤成功
!system 7 发动 !system 7 发动
!system 10 除指示物 !system 10 除指示物
!system 11 支付基本分 !system 11 支付基本分
!system 12 除本身的素材 !system 12 除本身的素材
!system 20 抽卡阶段中 !system 20 抽卡阶段中
!system 21 准备阶段中 !system 21 准备阶段中
!system 22 主要阶段中 !system 22 主要阶段中
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
!system 201 此时没有可以发动的效果 !system 201 此时没有可以发动的效果
!system 202 是否要确认场上的情况? !system 202 是否要确认场上的情况?
!system 203 是否要进行连锁? !system 203 是否要进行连锁?
!system 204除%d个[%ls] !system 204除%d个[%ls]
!system 205 请选择排列顺序 !system 205 请选择排列顺序
!system 206 请选择连锁顺序 !system 206 请选择连锁顺序
!system 207 翻开卡组上方%d张卡: !system 207 翻开卡组上方%d张卡:
...@@ -335,7 +335,7 @@ ...@@ -335,7 +335,7 @@
!system 1294 可用时点 !system 1294 可用时点
!system 1295 取消操作 !system 1295 取消操作
!system 1296 完成选择 !system 1296 完成选择
!system 1297 切洗手卡 !system 1297 洗切手卡
!system 1298 辅助功能 !system 1298 辅助功能
!system 1299 加快动画效果 !system 1299 加快动画效果
!system 1300 禁限卡表: !system 1300 禁限卡表:
...@@ -474,7 +474,7 @@ ...@@ -474,7 +474,7 @@
!system 1615 我方回复%d基本分 !system 1615 我方回复%d基本分
!system 1616 对方回复%d基本分 !system 1616 对方回复%d基本分
!system 1617 [%ls]放置了%d个[%ls] !system 1617 [%ls]放置了%d个[%ls]
!system 1618 [%ls]除了%d个[%ls] !system 1618 [%ls]除了%d个[%ls]
!system 1619 [%ls]攻击[%ls] !system 1619 [%ls]攻击[%ls]
!system 1620 [%ls]直接攻击 !system 1620 [%ls]直接攻击
!system 1621 攻击被无效 !system 1621 攻击被无效
...@@ -582,6 +582,10 @@ ...@@ -582,6 +582,10 @@
!counter 0x104f 蛊指示物 !counter 0x104f 蛊指示物
!counter 0x50 指示物(娱乐伙伴 掉头跑骑兵) !counter 0x50 指示物(娱乐伙伴 掉头跑骑兵)
!counter 0x51 指示物(蜂军巢) !counter 0x51 指示物(蜂军巢)
!counter 0x52 指示物(防火龙·暗流体)
!counter 0x53 指示物(炽天蝶)
!counter 0x54 指示物(星遗物引导的前路)
!counter 0x55 指示物(隐居者的大釜)
#setnames, using tab for comment #setnames, using tab for comment
!setname 0x1 正义盟军 AOJ !setname 0x1 正义盟军 AOJ
!setname 0x2 次世代 ジェネクス !setname 0x2 次世代 ジェネクス
...@@ -970,3 +974,6 @@ ...@@ -970,3 +974,6 @@
!setname 0x12d 斯摩夫 シムルグ !setname 0x12d 斯摩夫 シムルグ
!setname 0x12e 占卜魔女 占い魔女 !setname 0x12e 占卜魔女 占い魔女
!setname 0x12f 蜂军 BF(ビー・フォース) !setname 0x12f 蜂军 BF(ビー・フォース)
!setname 0x130 破械
!setname 0x1130 破械神
!setname 0x131 梦镜 Dream Mirror
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