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