Commit 3ce37cde authored by fallenstardust's avatar fallenstardust

use standard mutex library

parent 0b80fb71
...@@ -601,7 +601,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -601,7 +601,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 * mainGame->xScale) { if(mainGame->guiFont->getDimension(dataManager.GetDesc(option)).Width > 310 * mainGame->xScale) {
quickmode = false; quickmode = false;
...@@ -649,7 +649,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -649,7 +649,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]);
......
...@@ -85,10 +85,10 @@ inline int _wtoi(const wchar_t * s) { ...@@ -85,10 +85,10 @@ inline int _wtoi(const wchar_t * s) {
#include <thread> #include <thread>
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
#include <android/bufferio_android.h> #include <android/bufferio_android.h>
#else #include <mutex>
#include "bufferio.h" #include "bufferio.h"
#endif #endif
#include "mymutex.h" #include "myfilesystem.h"
#include "mysignal.h" #include "mysignal.h"
#include "../ocgcore/ocgapi.h" #include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h" #include "../ocgcore/common.h"
......
...@@ -139,10 +139,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -139,10 +139,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
switch(id) { switch(id) {
case BUTTON_CLEAR_DECK: { case BUTTON_CLEAR_DECK: {
mainGame->soundEffectPlayer->doPressButton(); mainGame->soundEffectPlayer->doPressButton();
mainGame->gMutex.Lock(); mainGame->gMutex.lock();
mainGame->SetStaticText(mainGame->stQMessage, 370, mainGame->textFont, dataManager.GetSysString(1339)); mainGame->SetStaticText(mainGame->stQMessage, 370, mainGame->textFont, 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;
} }
...@@ -198,11 +198,11 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -198,11 +198,11 @@ 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();
mainGame->wRenameDeck->setText(dataManager.GetSysString(1362)); mainGame->wRenameDeck->setText(dataManager.GetSysString(1362));
mainGame->ebREName->setText(mainGame->cbDBDecks->getItem(sel)); mainGame->ebREName->setText(mainGame->cbDBDecks->getItem(sel));
mainGame->PopupElement(mainGame->wRenameDeck); mainGame->PopupElement(mainGame->wRenameDeck);
mainGame->gMutex.Unlock(); mainGame->gMutex.unlock();
prev_operation = id; prev_operation = id;
prev_sel = sel; prev_sel = sel;
break; break;
...@@ -240,12 +240,12 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -240,12 +240,12 @@ 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, 370 * mainGame->xScale, mainGame->textFont, textBuffer); mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame->xScale, mainGame->textFont, 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;
mainGame->soundEffectPlayer->doDelete(); mainGame->soundEffectPlayer->doDelete();
...@@ -253,10 +253,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -253,10 +253,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
} }
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, 370 * mainGame->xScale, mainGame->textFont, 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;
} }
...@@ -432,10 +432,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) { ...@@ -432,10 +432,10 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
} }
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, 370 * mainGame-> xScale, mainGame->textFont, dataManager.GetSysString(1356)); mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame-> xScale, mainGame->textFont, 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;
} }
......
This diff is collapsed.
...@@ -1045,7 +1045,7 @@ void Game::MainLoop() { ...@@ -1045,7 +1045,7 @@ void Game::MainLoop() {
} }
driver->enableMaterial2D(false); driver->enableMaterial2D(false);
#endif #endif
gMutex.Lock(); gMutex.lock();
if(dInfo.isStarted) { if(dInfo.isStarted) {
DrawBackImage(imageManager.tBackGround); DrawBackImage(imageManager.tBackGround);
DrawBackGround(); DrawBackGround();
...@@ -1074,7 +1074,7 @@ void Game::MainLoop() { ...@@ -1074,7 +1074,7 @@ void Game::MainLoop() {
DrawGUI(); DrawGUI();
DrawSpec(); DrawSpec();
#endif #endif
gMutex.Unlock(); gMutex.unlock();
if(signalFrame > 0) { if(signalFrame > 0) {
signalFrame--; signalFrame--;
if(!signalFrame) if(!signalFrame)
......
...@@ -163,9 +163,7 @@ public: ...@@ -163,9 +163,7 @@ public:
return focus && focus->hasType(type); return focus && focus->hasType(type);
} }
// don't merge // don't merge
std::mutex gMutex;
Mutex gMutex;
Mutex gBuffer;
Signal frameSignal; Signal frameSignal;
Signal actionSignal; Signal actionSignal;
Signal replaySignal; Signal replaySignal;
......
...@@ -90,9 +90,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -90,9 +90,9 @@ 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();
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);
...@@ -266,12 +266,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -266,12 +266,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, 370 * mainGame->xScale, mainGame->textFont, textBuffer); mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame->xScale, mainGame->textFont, 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;
...@@ -280,11 +280,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -280,11 +280,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
...@@ -90,7 +90,7 @@ int ReplayMode::ReplayThread() { ...@@ -90,7 +90,7 @@ int ReplayMode::ReplayThread() {
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() { ...@@ -99,7 +99,7 @@ int ReplayMode::ReplayThread() {
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() { ...@@ -125,7 +125,7 @@ int ReplayMode::ReplayThread() {
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() { ...@@ -135,7 +135,7 @@ int ReplayMode::ReplayThread() {
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) {
......
...@@ -67,7 +67,7 @@ int SingleMode::SinglePlayThread() { ...@@ -67,7 +67,7 @@ int SingleMode::SinglePlayThread() {
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);
...@@ -81,7 +81,7 @@ int SingleMode::SinglePlayThread() { ...@@ -81,7 +81,7 @@ int SingleMode::SinglePlayThread() {
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;
...@@ -113,7 +113,7 @@ int SingleMode::SinglePlayThread() { ...@@ -113,7 +113,7 @@ int SingleMode::SinglePlayThread() {
} }
} }
last_replay.EndRecord(); last_replay.EndRecord();
mainGame->gMutex.Lock(); 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];
...@@ -122,7 +122,7 @@ int SingleMode::SinglePlayThread() { ...@@ -122,7 +122,7 @@ int SingleMode::SinglePlayThread() {
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 {
...@@ -131,26 +131,26 @@ int SingleMode::SinglePlayThread() { ...@@ -131,26 +131,26 @@ int SingleMode::SinglePlayThread() {
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();
mainGame->SaveConfig(); mainGame->SaveConfig();
if(exit_on_return) if(exit_on_return)
mainGame->device->closeDevice(); mainGame->device->closeDevice();
...@@ -721,9 +721,9 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) { ...@@ -721,9 +721,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: {
...@@ -745,10 +745,10 @@ bool SingleMode::SinglePlayAnalyze(char* msg, unsigned int len) { ...@@ -745,10 +745,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->xScale, mainGame->textFont, msg); mainGame->SetStaticText(mainGame->stMessage, 310 * mainGame->xScale, mainGame->textFont, 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;
......
...@@ -179,9 +179,9 @@ JNIEXPORT jbyteArray JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_native ...@@ -179,9 +179,9 @@ JNIEXPORT jbyteArray JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_native
static void* join_game_thread(void* param) { static void* join_game_thread(void* param) {
ygo::mainGame->externalSignal.Wait(); ygo::mainGame->externalSignal.Wait();
ygo::mainGame->gMutex.Lock(); ygo::mainGame->gMutex.lock();
if (ygo::mainGame->dInfo.isStarted) { if (ygo::mainGame->dInfo.isStarted) {
ygo::mainGame->gMutex.Unlock(); ygo::mainGame->gMutex.unlock();
return NULL; return NULL;
} }
irr::android::YGOGameOptions options = irr::android::YGOGameOptions(param); irr::android::YGOGameOptions options = irr::android::YGOGameOptions(param);
...@@ -219,7 +219,7 @@ static void* join_game_thread(void* param) { ...@@ -219,7 +219,7 @@ static void* join_game_thread(void* param) {
event.GUIEvent.Caller = ygo::mainGame->btnJoinHost; event.GUIEvent.Caller = ygo::mainGame->btnJoinHost;
ygo::mainGame->device->postEventFromUser(event); ygo::mainGame->device->postEventFromUser(event);
// } // }
exit: ygo::mainGame->gMutex.Unlock(); exit: ygo::mainGame->gMutex.unlock();
free(param); free(param);
return NULL; return NULL;
......
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