Commit 638f68b4 authored by matteoserva's avatar matteoserva

Merge pull request #2 from Fluorohydride/master

merge
parents f489892d c6a5ebac
...@@ -159,7 +159,9 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) { ...@@ -159,7 +159,9 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
mainGame->btnJoinCancel->setEnabled(true); mainGame->btnJoinCancel->setEnabled(true);
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->is_building = false; mainGame->is_building = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
...@@ -498,7 +500,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { ...@@ -498,7 +500,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) {
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
...@@ -708,7 +712,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -708,7 +712,9 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
mainGame->actionSignal.Reset(); mainGame->actionSignal.Reset();
mainGame->actionSignal.Wait(); mainGame->actionSignal.Wait();
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true);
......
...@@ -100,7 +100,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) { ...@@ -100,7 +100,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
} }
if(mainGame->dInfo.player_type == 7) { if(mainGame->dInfo.player_type == 7) {
DuelClient::StopClient(); DuelClient::StopClient();
mainGame->CloseDuelWindow();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->btnCreateHost->setEnabled(true); mainGame->btnCreateHost->setEnabled(true);
......
...@@ -543,6 +543,8 @@ void Game::MainLoop() { ...@@ -543,6 +543,8 @@ void Game::MainLoop() {
} }
} }
driver->endScene(); driver->endScene();
if(closeSignal.Wait(0))
CloseDuelWindow();
fps++; fps++;
cur_time = timer->getTime(); cur_time = timer->getTime();
if(cur_time < fps * 17 - 20) if(cur_time < fps * 17 - 20)
...@@ -907,6 +909,7 @@ void Game::CloseDuelWindow() { ...@@ -907,6 +909,7 @@ void Game::CloseDuelWindow() {
lstHostList->clear(); lstHostList->clear();
DuelClient::hosts.clear(); DuelClient::hosts.clear();
ClearTextures(); ClearTextures();
closeDoneSignal.Set();
} }
int Game::LocalPlayer(int player) { int Game::LocalPlayer(int player) {
return dInfo.isFirst ? player : 1 - player; return dInfo.isFirst ? player : 1 - player;
......
...@@ -102,6 +102,8 @@ public: ...@@ -102,6 +102,8 @@ public:
Signal actionSignal; Signal actionSignal;
Signal replaySignal; Signal replaySignal;
Signal singleSignal; Signal singleSignal;
Signal closeSignal;
Signal closeDoneSignal;
Config gameConf; Config gameConf;
DuelInfo dInfo; DuelInfo dInfo;
......
...@@ -25,6 +25,11 @@ public: ...@@ -25,6 +25,11 @@ public:
return; return;
WaitForSingleObject(_event, INFINITE); WaitForSingleObject(_event, INFINITE);
} }
bool Wait(long milli) {
if(_nowait)
return false;
return WaitForSingleObject(_event, milli + 1) != WAIT_TIMEOUT;
}
void SetNoWait(bool nowait) { void SetNoWait(bool nowait) {
_nowait = nowait; _nowait = nowait;
} }
...@@ -83,6 +88,38 @@ public: ...@@ -83,6 +88,38 @@ public:
_state = false; _state = false;
pthread_mutex_unlock(&_mutex); pthread_mutex_unlock(&_mutex);
} }
bool Wait(long milliseconds)
{
if (_nowait || pthread_mutex_lock(&_mutex) != 0)
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;
}
}
_state = false;
pthread_mutex_unlock(&_mutex);
return rc == 0;
}
void SetNoWait(bool nowait) { void SetNoWait(bool nowait) {
_nowait = nowait; _nowait = nowait;
} }
......
...@@ -166,11 +166,13 @@ int ReplayMode::ReplayThread(void* param) { ...@@ -166,11 +166,13 @@ int ReplayMode::ReplayThread(void* param) {
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isReplay = false; mainGame->dInfo.isReplay = false;
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->ClearTextures(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wReplay); mainGame->ShowElement(mainGame->wReplay);
mainGame->gMutex.Unlock(); mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->closeSignal.Set();
} }
return 0; return 0;
} }
......
...@@ -92,11 +92,12 @@ int SingleMode::SinglePlayThread(void* param) { ...@@ -92,11 +92,12 @@ int SingleMode::SinglePlayThread(void* param) {
mainGame->gMutex.Lock(); mainGame->gMutex.Lock();
mainGame->dInfo.isStarted = false; mainGame->dInfo.isStarted = false;
mainGame->dInfo.isSingleMode = false; mainGame->dInfo.isSingleMode = false;
mainGame->CloseDuelWindow(); mainGame->closeDoneSignal.Reset();
mainGame->ClearTextures(); mainGame->closeSignal.Set();
mainGame->closeDoneSignal.Wait();
mainGame->ShowElement(mainGame->wSinglePlay); mainGame->ShowElement(mainGame->wSinglePlay);
mainGame->gMutex.Unlock();
mainGame->device->setEventReceiver(&mainGame->menuHandler); mainGame->device->setEventReceiver(&mainGame->menuHandler);
mainGame->gMutex.Unlock();
} }
return 0; return 0;
} }
......
...@@ -5,6 +5,7 @@ function c24082387.initial_effect(c) ...@@ -5,6 +5,7 @@ function c24082387.initial_effect(c)
e1:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DAMAGE) e1:SetCategory(CATEGORY_SPECIAL_SUMMON+CATEGORY_DAMAGE)
e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetType(EFFECT_TYPE_ACTIVATE)
e1:SetCode(EVENT_FREE_CHAIN) e1:SetCode(EVENT_FREE_CHAIN)
e1:SetHintTiming(0,TIMING_END_PHASE)
e1:SetLabel(0) e1:SetLabel(0)
e1:SetCost(c24082387.cost) e1:SetCost(c24082387.cost)
e1:SetTarget(c24082387.target) e1:SetTarget(c24082387.target)
......
...@@ -4,7 +4,7 @@ function c8323633.initial_effect(c) ...@@ -4,7 +4,7 @@ function c8323633.initial_effect(c)
local e1=Effect.CreateEffect(c) local e1=Effect.CreateEffect(c)
e1:SetType(EFFECT_TYPE_ACTIVATE) e1:SetType(EFFECT_TYPE_ACTIVATE)
e1:SetCode(EVENT_FREE_CHAIN) e1:SetCode(EVENT_FREE_CHAIN)
e1:SetTarget(c8323633.target) e1:SetOperation(c8323633.target)
c:RegisterEffect(e1) c:RegisterEffect(e1)
end end
function c8323633.target(e,tp,eg,ep,ev,re,r,rp,chk) function c8323633.target(e,tp,eg,ep,ev,re,r,rp,chk)
......
...@@ -76,23 +76,18 @@ end ...@@ -76,23 +76,18 @@ end
function c83438826.desop(e,tp,eg,ep,ev,re,r,rp) function c83438826.desop(e,tp,eg,ep,ev,re,r,rp)
local c=e:GetHandler() local c=e:GetHandler()
local tc=Duel.GetFirstTarget() local tc=Duel.GetFirstTarget()
if not c:IsRelateToEffect(e) or not tc:IsRelateToEffect(e) or tc:IsFaceup() then return end local eq=c:GetEquipTarget()
if c:GetFlagEffect(83438826)==0 then if not c:IsRelateToEffect(e) or not tc:IsRelateToEffect(e) or tc:IsFaceup() or
not eq:IsAttackAbove(500)
then return end
local e1=Effect.CreateEffect(c) local e1=Effect.CreateEffect(c)
e1:SetType(EFFECT_TYPE_EQUIP) e1:SetType(EFFECT_TYPE_SINGLE)
e1:SetCode(EFFECT_UPDATE_ATTACK) e1:SetCode(EFFECT_UPDATE_ATTACK)
e1:SetValue(-500) e1:SetValue(-500)
e1:SetReset(RESET_EVENT+0x1fe0000) e1:SetReset(RESET_EVENT+0x1fe0000)
c:RegisterEffect(e1) eq:RegisterEffect(e1)
c:RegisterFlagEffect(83438826,RESET_EVENT+0x1fe0000,0,0)
e:SetLabelObject(e1)
e:SetLabel(2)
else
local pe=e:GetLabelObject()
local ct=e:GetLabel()
e:SetLabel(ct+1)
pe:SetValue(ct*-500)
end
Duel.Destroy(tc,REASON_EFFECT) Duel.Destroy(tc,REASON_EFFECT)
end end
function c83438826.eqcon(e,tp,eg,ep,ev,re,r,rp) function c83438826.eqcon(e,tp,eg,ep,ev,re,r,rp)
......
...@@ -41,6 +41,12 @@ function c83746708.operation(e,tp,eg,ep,ev,re,r,rp) ...@@ -41,6 +41,12 @@ function c83746708.operation(e,tp,eg,ep,ev,re,r,rp)
Duel.Equip(tp,e:GetHandler(),tc) Duel.Equip(tp,e:GetHandler(),tc)
end end
end end
function c83746708.filter(c)
return c:IsType(TYPE_SPELL) or c:IsType(TYPE_TRAP)
end
function c83746708.value(e,c) function c83746708.value(e,c)
return Duel.GetFieldGroupCount(e:GetHandler():GetControler(),LOCATION_SZONE,0)*500 local g=Duel.GetMatchingGroup(c83746708.filter,tp,LOCATION_ONFIELD,0,nil)
return g:GetCount()*500
end end
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