From 032b1f7346b76672da8eccfaffb35ecdd2d09f1d Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Wed, 6 May 2020 11:50:34 +0800 Subject: [PATCH 1/7] always show chain mark (#2294) --- gframe/drawing.cpp | 42 ++++++++++++++++++++---------------------- gframe/duelclient.cpp | 16 +++++++--------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index 0bae66d52c..d262dd4e5d 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -457,28 +457,26 @@ void Game::DrawMisc() { driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } - if(dField.chains.size() > 1) { - for(size_t i = 0; i < dField.chains.size(); ++i) { - if(dField.chains[i].solved) - break; - matManager.mTRTexture.setTexture(0, imageManager.tChain); - matManager.mTRTexture.AmbientColor = 0xffffff00; - ic.setRotationRadians(act_rot); - ic.setTranslation(dField.chains[i].chain_pos); - driver->setMaterial(matManager.mTRTexture); - driver->setTransform(irr::video::ETS_WORLD, ic); - driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2); - it.setScale(0.6f); - it.setTranslation(dField.chains[i].chain_pos); - matManager.mTRTexture.setTexture(0, imageManager.tNumber); - matManager.vChainNum[0].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5)); - matManager.vChainNum[1].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5)); - matManager.vChainNum[2].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5 + 1)); - matManager.vChainNum[3].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5 + 1)); - driver->setMaterial(matManager.mTRTexture); - driver->setTransform(irr::video::ETS_WORLD, it); - driver->drawVertexPrimitiveList(matManager.vChainNum, 4, matManager.iRectangle, 2); - } + for(size_t i = 0; i < dField.chains.size(); ++i) { + if(dField.chains[i].solved) + break; + matManager.mTRTexture.setTexture(0, imageManager.tChain); + matManager.mTRTexture.AmbientColor = 0xffffff00; + ic.setRotationRadians(act_rot); + ic.setTranslation(dField.chains[i].chain_pos); + driver->setMaterial(matManager.mTRTexture); + driver->setTransform(irr::video::ETS_WORLD, ic); + driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2); + it.setScale(0.6f); + it.setTranslation(dField.chains[i].chain_pos); + matManager.mTRTexture.setTexture(0, imageManager.tNumber); + matManager.vChainNum[0].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5)); + matManager.vChainNum[1].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5)); + matManager.vChainNum[2].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5 + 1)); + matManager.vChainNum[3].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5 + 1)); + driver->setMaterial(matManager.mTRTexture); + driver->setTransform(irr::video::ETS_WORLD, it); + driver->drawVertexPrimitiveList(matManager.vChainNum, 4, matManager.iRectangle, 2); } //finish button if(btnCancelOrFinish->isVisible() && dField.select_ready) diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index ca5c2a1427..f7123a2a1f 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -2906,15 +2906,13 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { int ct = BufferIO::ReadInt8(pbuf); if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping) return true; - if (mainGame->dField.chains.size() > 1) { - if (mainGame->dField.last_chain) - mainGame->WaitFrameSignal(11); - for(int i = 0; i < 5; ++i) { - mainGame->dField.chains[ct - 1].solved = false; - mainGame->WaitFrameSignal(3); - mainGame->dField.chains[ct - 1].solved = true; - mainGame->WaitFrameSignal(3); - } + if(mainGame->dField.last_chain) + mainGame->WaitFrameSignal(11); + for(int i = 0; i < 5; ++i) { + mainGame->dField.chains[ct - 1].solved = false; + mainGame->WaitFrameSignal(3); + mainGame->dField.chains[ct - 1].solved = true; + mainGame->WaitFrameSignal(3); } mainGame->dField.last_chain = false; return true; From 5009c68eafa73853bbed352ad9d4e049e1ca1637 Mon Sep 17 00:00:00 2001 From: DailyShana Date: Mon, 11 May 2020 12:30:15 +0800 Subject: [PATCH 2/7] cmake: make lua as a dependency of ocgcore --- gframe/CMakeLists.txt | 3 +-- ocgcore | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gframe/CMakeLists.txt b/gframe/CMakeLists.txt index ebcb6ba0e2..ee5e027826 100644 --- a/gframe/CMakeLists.txt +++ b/gframe/CMakeLists.txt @@ -28,7 +28,7 @@ endif () target_link_libraries (ygopro ocgcore clzma) if (MSVC) - target_link_libraries (ygopro irrlicht freetype sqlite3 event lua) + target_link_libraries (ygopro irrlicht freetype sqlite3 event) include_directories ( "../irrlicht/include" "../freetype/include" "../event/include" "../sqlite3" ) else () target_link_libraries (ygopro @@ -36,7 +36,6 @@ else () ${FREETYPE_LIBRARIES} ${SQLITE_LIBRARIES} ${LIBEVENT_LIBRARIES} - ${LUA_LIBRARIES} ${OPENGL_gl_LIBRARY} ) include_directories ( diff --git a/ocgcore b/ocgcore index ea542f3300..4d2e360374 160000 --- a/ocgcore +++ b/ocgcore @@ -1 +1 @@ -Subproject commit ea542f3300ff627c02c6e1729f9a5e94e957694a +Subproject commit 4d2e3603745b8e92ab0248c9ff49174d0cbb4f5a From be988d54dd3ea49418b2b5d92de4a14f935f827e Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Thu, 21 May 2020 13:52:35 +0800 Subject: [PATCH 3/7] Revert "always show chain mark (#2294)" (#2301) --- gframe/drawing.cpp | 42 ++++++++++++++++++++++-------------------- gframe/duelclient.cpp | 16 +++++++++------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index d262dd4e5d..0bae66d52c 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -457,26 +457,28 @@ void Game::DrawMisc() { driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } - for(size_t i = 0; i < dField.chains.size(); ++i) { - if(dField.chains[i].solved) - break; - matManager.mTRTexture.setTexture(0, imageManager.tChain); - matManager.mTRTexture.AmbientColor = 0xffffff00; - ic.setRotationRadians(act_rot); - ic.setTranslation(dField.chains[i].chain_pos); - driver->setMaterial(matManager.mTRTexture); - driver->setTransform(irr::video::ETS_WORLD, ic); - driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2); - it.setScale(0.6f); - it.setTranslation(dField.chains[i].chain_pos); - matManager.mTRTexture.setTexture(0, imageManager.tNumber); - matManager.vChainNum[0].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5)); - matManager.vChainNum[1].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5)); - matManager.vChainNum[2].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5 + 1)); - matManager.vChainNum[3].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5 + 1)); - driver->setMaterial(matManager.mTRTexture); - driver->setTransform(irr::video::ETS_WORLD, it); - driver->drawVertexPrimitiveList(matManager.vChainNum, 4, matManager.iRectangle, 2); + if(dField.chains.size() > 1) { + for(size_t i = 0; i < dField.chains.size(); ++i) { + if(dField.chains[i].solved) + break; + matManager.mTRTexture.setTexture(0, imageManager.tChain); + matManager.mTRTexture.AmbientColor = 0xffffff00; + ic.setRotationRadians(act_rot); + ic.setTranslation(dField.chains[i].chain_pos); + driver->setMaterial(matManager.mTRTexture); + driver->setTransform(irr::video::ETS_WORLD, ic); + driver->drawVertexPrimitiveList(matManager.vSymbol, 4, matManager.iRectangle, 2); + it.setScale(0.6f); + it.setTranslation(dField.chains[i].chain_pos); + matManager.mTRTexture.setTexture(0, imageManager.tNumber); + matManager.vChainNum[0].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5)); + matManager.vChainNum[1].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5)); + matManager.vChainNum[2].TCoords = vector2df(0.19375f * (i % 5), 0.2421875f * (i / 5 + 1)); + matManager.vChainNum[3].TCoords = vector2df(0.19375f * (i % 5 + 1), 0.2421875f * (i / 5 + 1)); + driver->setMaterial(matManager.mTRTexture); + driver->setTransform(irr::video::ETS_WORLD, it); + driver->drawVertexPrimitiveList(matManager.vChainNum, 4, matManager.iRectangle, 2); + } } //finish button if(btnCancelOrFinish->isVisible() && dField.select_ready) diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index f7123a2a1f..ca5c2a1427 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -2906,13 +2906,15 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { int ct = BufferIO::ReadInt8(pbuf); if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping) return true; - if(mainGame->dField.last_chain) - mainGame->WaitFrameSignal(11); - for(int i = 0; i < 5; ++i) { - mainGame->dField.chains[ct - 1].solved = false; - mainGame->WaitFrameSignal(3); - mainGame->dField.chains[ct - 1].solved = true; - mainGame->WaitFrameSignal(3); + if (mainGame->dField.chains.size() > 1) { + if (mainGame->dField.last_chain) + mainGame->WaitFrameSignal(11); + for(int i = 0; i < 5; ++i) { + mainGame->dField.chains[ct - 1].solved = false; + mainGame->WaitFrameSignal(3); + mainGame->dField.chains[ct - 1].solved = true; + mainGame->WaitFrameSignal(3); + } } mainGame->dField.last_chain = false; return true; From a4ee4586843bdd03a5bfeb1ca23aebd68a604241 Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Sun, 24 May 2020 18:07:19 +0800 Subject: [PATCH 4/7] add setting for drawing single chain (#2300) --- gframe/drawing.cpp | 2 +- gframe/duelclient.cpp | 2 +- gframe/event_handler.cpp | 5 +++++ gframe/game.cpp | 7 +++++++ gframe/game.h | 3 +++ strings.conf | 1 + 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index 0bae66d52c..d0d64bdc7a 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -457,7 +457,7 @@ void Game::DrawMisc() { driver->setTransform(irr::video::ETS_WORLD, im); driver->drawVertexPrimitiveList(matManager.vActivate, 4, matManager.iRectangle, 2); } - if(dField.chains.size() > 1) { + if(dField.chains.size() > 1 || mainGame->gameConf.draw_single_chain) { for(size_t i = 0; i < dField.chains.size(); ++i) { if(dField.chains[i].solved) break; diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index ca5c2a1427..57bd97fb4b 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -2906,7 +2906,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { int ct = BufferIO::ReadInt8(pbuf); if(mainGame->dInfo.isReplay && mainGame->dInfo.isReplaySkiping) return true; - if (mainGame->dField.chains.size() > 1) { + if(mainGame->dField.chains.size() > 1 || mainGame->gameConf.draw_single_chain) { if (mainGame->dField.last_chain) mainGame->WaitFrameSignal(11); for(int i = 0; i < 5; ++i) { diff --git a/gframe/event_handler.cpp b/gframe/event_handler.cpp index 6dcfb9da5e..c4cbfeea0a 100644 --- a/gframe/event_handler.cpp +++ b/gframe/event_handler.cpp @@ -1877,6 +1877,11 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) { return true; break; } + case CHECKBOX_DRAW_SINGLE_CHAIN: { + mainGame->gameConf.draw_single_chain = mainGame->chkDrawSingleChain->isChecked() ? 1 : 0; + return true; + break; + } case CHECKBOX_PREFER_EXPANSION: { mainGame->gameConf.prefer_expansion_script = mainGame->chkPreferExpansionScript->isChecked() ? 1 : 0; return true; diff --git a/gframe/game.cpp b/gframe/game.cpp index ff90e52a48..a51786ef48 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -286,6 +286,9 @@ bool Game::Initialize() { chkQuickAnimation = env->addCheckBox(false, rect(posX, posY, posX + 260, posY + 25), tabHelper, CHECKBOX_QUICK_ANIMATION, dataManager.GetSysString(1299)); chkQuickAnimation->setChecked(gameConf.quick_animation != 0); posY += 30; + chkDrawSingleChain = env->addCheckBox(false, rect(posX, posY, posX + 260, posY + 25), tabHelper, CHECKBOX_DRAW_SINGLE_CHAIN, dataManager.GetSysString(1287)); + chkDrawSingleChain->setChecked(gameConf.draw_single_chain != 0); + posY += 30; chkAutoSaveReplay = env->addCheckBox(false, rect(posX, posY, posX + 260, posY + 25), tabHelper, -1, dataManager.GetSysString(1366)); chkAutoSaveReplay->setChecked(gameConf.auto_save_replay != 0); elmTabHelperLast = chkAutoSaveReplay; @@ -1090,6 +1093,7 @@ void Game::LoadConfig() { gameConf.enable_bot_mode = 0; gameConf.quick_animation = 0; gameConf.auto_save_replay = 0; + gameConf.draw_single_chain = 0; gameConf.prefer_expansion_script = 0; gameConf.enable_sound = true; gameConf.sound_volume = 0.5; @@ -1172,6 +1176,8 @@ void Game::LoadConfig() { gameConf.quick_animation = atoi(valbuf); } else if(!strcmp(strbuf, "auto_save_replay")) { gameConf.auto_save_replay = atoi(valbuf); + } else if(!strcmp(strbuf, "draw_single_chain")) { + gameConf.draw_single_chain = atoi(valbuf); } else if(!strcmp(strbuf, "prefer_expansion_script")) { gameConf.prefer_expansion_script = atoi(valbuf); } else if(!strcmp(strbuf, "window_maximized")) { @@ -1259,6 +1265,7 @@ void Game::SaveConfig() { fprintf(fp, "enable_bot_mode = %d\n", gameConf.enable_bot_mode); fprintf(fp, "quick_animation = %d\n", gameConf.quick_animation); fprintf(fp, "auto_save_replay = %d\n", (chkAutoSaveReplay->isChecked() ? 1 : 0)); + fprintf(fp, "draw_single_chain = %d\n", gameConf.draw_single_chain); fprintf(fp, "prefer_expansion_script = %d\n", gameConf.prefer_expansion_script); fprintf(fp, "window_maximized = %d\n", (gameConf.window_maximized ? 1 : 0)); fprintf(fp, "window_width = %d\n", gameConf.window_width); diff --git a/gframe/game.h b/gframe/game.h index e2cab924ca..dcc9b955e5 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -46,6 +46,7 @@ struct Config { int enable_bot_mode; int quick_animation; int auto_save_replay; + int draw_single_chain; int prefer_expansion_script; bool enable_sound; bool enable_music; @@ -282,6 +283,7 @@ class Game { irr::gui::IGUICheckBox* chkWaitChain; irr::gui::IGUICheckBox* chkQuickAnimation; irr::gui::IGUICheckBox* chkAutoSaveReplay; + irr::gui::IGUICheckBox* chkDrawSingleChain; irr::gui::IGUIWindow* tabSystem; irr::gui::IGUIElement* elmTabSystemLast; irr::gui::IGUIScrollBar* scrTabSystem; @@ -723,6 +725,7 @@ extern Game* mainGame; #define SCROLL_TAB_SYSTEM 371 #define CHECKBOX_MULTI_KEYWORDS 372 #define CHECKBOX_PREFER_EXPANSION 373 +#define CHECKBOX_DRAW_SINGLE_CHAIN 374 #define DEFAULT_DUEL_RULE 5 diff --git a/strings.conf b/strings.conf index 8ae16d97ed..a7d4f9f96f 100644 --- a/strings.conf +++ b/strings.conf @@ -334,6 +334,7 @@ !system 1284 中 !system 1285 大 !system 1286 特大 +!system 1287 只有连锁1也显示连锁动画 !system 1290 禁用聊天功能 !system 1291 忽略观战者发言 !system 1292 忽略时点 From 697a6f7a2536352dd961c3744ac4514733041748 Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Sun, 24 May 2020 18:08:01 +0800 Subject: [PATCH 5/7] update & fix hiding elements (#2295) --- gframe/drawing.cpp | 2 ++ gframe/duelclient.cpp | 39 +++++++++------------------------------ gframe/event_handler.cpp | 11 ++--------- gframe/game.cpp | 28 ++++++++++++++++++---------- gframe/game.h | 4 +++- gframe/replay_mode.cpp | 3 +-- 6 files changed, 35 insertions(+), 52 deletions(-) diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index d0d64bdc7a..bb24a5c33b 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -992,6 +992,8 @@ void Game::ShowElement(irr::gui::IGUIElement * win, int autoframe) { fadingList.push_back(fu); } void Game::HideElement(irr::gui::IGUIElement * win, bool set_action) { + if(!win->isVisible() && !set_action) + return; FadingUnit fu; fu.fadingSize = win->getRelativePosition(); for(auto fit = fadingList.begin(); fit != fadingList.end(); ++fit) diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index 57bd97fb4b..bb5f684a2f 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -369,24 +369,17 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { mainGame->dField.Clear(); mainGame->is_building = true; mainGame->is_siding = true; + mainGame->CloseGameWindow(); mainGame->wChat->setVisible(false); - mainGame->wPhase->setVisible(false); mainGame->wDeckEdit->setVisible(false); mainGame->wFilter->setVisible(false); mainGame->wSort->setVisible(false); - mainGame->stTip->setVisible(false); + if(mainGame->dInfo.player_type < 7) + mainGame->btnLeaveGame->setVisible(false); mainGame->btnSideOK->setVisible(true); mainGame->btnSideShuffle->setVisible(true); mainGame->btnSideSort->setVisible(true); mainGame->btnSideReload->setVisible(true); - if(mainGame->dInfo.player_type < 7) - mainGame->btnLeaveGame->setVisible(false); - mainGame->btnSpectatorSwap->setVisible(false); - mainGame->btnChainIgnore->setVisible(false); - mainGame->btnChainAlways->setVisible(false); - mainGame->btnChainWhenAvail->setVisible(false); - mainGame->btnCancelOrFinish->setVisible(false); - mainGame->btnShuffle->setVisible(false); mainGame->deckBuilder.result_string[0] = L'0'; mainGame->deckBuilder.result_string[1] = 0; mainGame->deckBuilder.results.clear(); @@ -486,12 +479,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str()); mainGame->RefreshDeck(mainGame->cbDeckSelect); mainGame->cbDeckSelect->setEnabled(true); - if(mainGame->wCreateHost->isVisible()) - mainGame->HideElement(mainGame->wCreateHost); - else if(mainGame->wLanWindow->isVisible()) - mainGame->HideElement(mainGame->wLanWindow); - else if(mainGame->wSinglePlay->isVisible()) - mainGame->HideElement(mainGame->wSinglePlay); + mainGame->HideElement(mainGame->wCreateHost); + mainGame->HideElement(mainGame->wLanWindow); + mainGame->HideElement(mainGame->wSinglePlay); mainGame->ShowElement(mainGame->wHostPrepare); if(!mainGame->chkIgnore1->isChecked()) mainGame->wChat->setVisible(true); @@ -649,12 +639,7 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { mainGame->gMutex.lock(); if(mainGame->dInfo.player_type < 7) mainGame->btnLeaveGame->setVisible(false); - mainGame->btnSpectatorSwap->setVisible(false); - mainGame->btnChainIgnore->setVisible(false); - mainGame->btnChainAlways->setVisible(false); - mainGame->btnChainWhenAvail->setVisible(false); - mainGame->btnCancelOrFinish->setVisible(false); - mainGame->wSurrender->setVisible(false); + mainGame->CloseGameButtons(); mainGame->stMessage->setText(dataManager.GetSysString(1500)); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.unlock(); @@ -688,14 +673,9 @@ void DuelClient::HandleSTOCPacketLan(char* data, unsigned int len) { case STOC_REPLAY: { mainGame->gMutex.lock(); mainGame->wPhase->setVisible(false); - mainGame->wSurrender->setVisible(false); if(mainGame->dInfo.player_type < 7) mainGame->btnLeaveGame->setVisible(false); - mainGame->btnChainIgnore->setVisible(false); - mainGame->btnChainAlways->setVisible(false); - mainGame->btnChainWhenAvail->setVisible(false); - mainGame->btnCancelOrFinish->setVisible(false); - mainGame->btnShuffle->setVisible(false); + mainGame->CloseGameButtons(); char* prep = pdata; Replay new_replay; memcpy(&new_replay.pheader, prep, sizeof(ReplayHeader)); @@ -2390,8 +2370,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { mainGame->btnLeaveGame->setText(dataManager.GetSysString(1351)); mainGame->btnLeaveGame->setVisible(true); } - if(mainGame->wSurrender->isVisible()) - mainGame->HideElement(mainGame->wSurrender); + mainGame->HideElement(mainGame->wSurrender); if(!mainGame->dInfo.isReplay && mainGame->dInfo.player_type < 7) { if(mainGame->gameConf.control_mode == 0) { mainGame->btnChainIgnore->setVisible(true); diff --git a/gframe/event_handler.cpp b/gframe/event_handler.cpp index c4cbfeea0a..d02c2d7f6c 100644 --- a/gframe/event_handler.cpp +++ b/gframe/event_handler.cpp @@ -129,13 +129,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { mainGame->dInfo.isStarted = false; mainGame->dInfo.isFinished = false; mainGame->device->setEventReceiver(&mainGame->menuHandler); - mainGame->stTip->setVisible(false); - mainGame->wCardImg->setVisible(false); - mainGame->wInfos->setVisible(false); - mainGame->wPhase->setVisible(false); - mainGame->btnLeaveGame->setVisible(false); - mainGame->btnSpectatorSwap->setVisible(false); - mainGame->wChat->setVisible(false); + mainGame->CloseDuelWindow(); mainGame->btnCreateHost->setEnabled(true); mainGame->btnJoinHost->setEnabled(true); mainGame->btnJoinCancel->setEnabled(true); @@ -1459,8 +1453,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) { mainGame->chain_when_avail = false; UpdateChainButtons(); } - if(mainGame->wSurrender->isVisible()) - mainGame->HideElement(mainGame->wSurrender); + mainGame->HideElement(mainGame->wSurrender); mainGame->wCmdMenu->setVisible(false); if(mainGame->fadingList.size()) break; diff --git a/gframe/game.cpp b/gframe/game.cpp index a51786ef48..54417a2e41 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -1478,7 +1478,17 @@ void Game::ClearTextures() { } imageManager.ClearTexture(); } -void Game::CloseDuelWindow() { +void Game::CloseGameButtons() { + btnChainIgnore->setVisible(false); + btnChainAlways->setVisible(false); + btnChainWhenAvail->setVisible(false); + btnCancelOrFinish->setVisible(false); + btnSpectatorSwap->setVisible(false); + btnShuffle->setVisible(false); + wSurrender->setVisible(false); +} +void Game::CloseGameWindow() { + CloseGameButtons(); for(auto wit = fadingList.begin(); wit != fadingList.end(); ++wit) { if(wit->isFadein) wit->autoFadeoutFrame = 1; @@ -1488,34 +1498,32 @@ void Game::CloseDuelWindow() { wANCard->setVisible(false); wANNumber->setVisible(false); wANRace->setVisible(false); - wCardImg->setVisible(false); wCardSelect->setVisible(false); wCardDisplay->setVisible(false); wCmdMenu->setVisible(false); wFTSelect->setVisible(false); wHand->setVisible(false); - wInfos->setVisible(false); wMessage->setVisible(false); wOptions->setVisible(false); wPhase->setVisible(false); wPosSelect->setVisible(false); wQuery->setVisible(false); - wSurrender->setVisible(false); wReplayControl->setVisible(false); wReplaySave->setVisible(false); stHintMsg->setVisible(false); + stTip->setVisible(false); +} +void Game::CloseDuelWindow() { + CloseGameWindow(); + wCardImg->setVisible(false); + wInfos->setVisible(false); + wChat->setVisible(false); btnSideOK->setVisible(false); btnSideShuffle->setVisible(false); btnSideSort->setVisible(false); btnSideReload->setVisible(false); btnLeaveGame->setVisible(false); btnSpectatorSwap->setVisible(false); - btnChainIgnore->setVisible(false); - btnChainAlways->setVisible(false); - btnChainWhenAvail->setVisible(false); - btnCancelOrFinish->setVisible(false); - btnShuffle->setVisible(false); - wChat->setVisible(false); lstLog->clear(); logParam.clear(); lstHostList->clear(); diff --git a/gframe/game.h b/gframe/game.h index dcc9b955e5..9a822191d0 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -148,7 +148,9 @@ class Game { void ClearChatMsg(); void AddDebugMsg(const char* msgbuf); void ErrorLog(const char* msgbuf); - void ClearTextures(); + void ClearTextures(); + void CloseGameButtons(); + void CloseGameWindow(); void CloseDuelWindow(); int LocalPlayer(int player); diff --git a/gframe/replay_mode.cpp b/gframe/replay_mode.cpp index 350854f33d..09d47617b0 100644 --- a/gframe/replay_mode.cpp +++ b/gframe/replay_mode.cpp @@ -230,8 +230,7 @@ void ReplayMode::EndDuel() { mainGame->actionSignal.Reset(); mainGame->gMutex.lock(); mainGame->stMessage->setText(dataManager.GetSysString(1501)); - if(mainGame->wCardSelect->isVisible()) - mainGame->HideElement(mainGame->wCardSelect); + mainGame->HideElement(mainGame->wCardSelect); mainGame->PopupElement(mainGame->wMessage); mainGame->gMutex.unlock(); mainGame->actionSignal.Wait(); From 805ec687dcadae0fbe62a3be73e0f6793527ffd6 Mon Sep 17 00:00:00 2001 From: Mercury233 Date: Mon, 25 May 2020 09:10:53 +0800 Subject: [PATCH 6/7] use multi-thread in loading thumbnails (#2207) --- gframe/drawing.cpp | 7 ++- gframe/image_manager.cpp | 102 +++++++++++++++++++++++++++++++++------ gframe/image_manager.h | 7 +++ 3 files changed, 99 insertions(+), 17 deletions(-) diff --git a/gframe/drawing.cpp b/gframe/drawing.cpp index bb24a5c33b..b3caa9655d 100644 --- a/gframe/drawing.cpp +++ b/gframe/drawing.cpp @@ -1157,8 +1157,13 @@ void Game::DrawDeckBd() { 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->draw2DRectangleOutline(Resize(804, 159, 1020, 630)); - for(size_t i = 0; i < 7 && i + scrFilter->getPos() < deckBuilder.results.size(); ++i) { + for(size_t i = 0; i < 9 && i + scrFilter->getPos() < deckBuilder.results.size(); ++i) { code_pointer ptr = deckBuilder.results[i + scrFilter->getPos()]; + if(i >= 7) + { + imageManager.GetTextureThumb(ptr->second.code); + break; + } if(deckBuilder.hovered_pos == 4 && deckBuilder.hovered_seq == (int)i) driver->draw2DRectangle(0x80000000, Resize(806, 164 + i * 66, 1019, 230 + i * 66)); DrawThumb(ptr, position2di(810, 165 + i * 66), deckBuilder.filterList); diff --git a/gframe/image_manager.cpp b/gframe/image_manager.cpp index 5c9fc0e920..4eba47578d 100644 --- a/gframe/image_manager.cpp +++ b/gframe/image_manager.cpp @@ -15,6 +15,8 @@ bool ImageManager::Initial() { tUnknown = NULL; tUnknownFit = NULL; tUnknownThumb = NULL; + tLoading = NULL; + tThumbLoadingThreadRunning = false; tAct = driver->getTexture("textures/act.png"); tAttack = driver->getTexture("textures/attack.png"); tChain = driver->getTexture("textures/chain.png"); @@ -55,12 +57,18 @@ void ImageManager::ClearTexture() { driver->removeTexture(tit->second); } for(auto tit = tThumb.begin(); tit != tThumb.end(); ++tit) { - if(tit->second) + if(tit->second && tit->second != tLoading) driver->removeTexture(tit->second); } tMap[0].clear(); tMap[1].clear(); tThumb.clear(); + tThumbLoadingMutex.lock(); + tThumbLoading.clear(); + while(!tThumbLoadingCodes.empty()) + tThumbLoadingCodes.pop(); + tThumbLoadingThreadRunning = false; + tThumbLoadingMutex.unlock(); tFields.clear(); } void ImageManager::RemoveTexture(int code) { @@ -96,9 +104,11 @@ void ImageManager::ResizeTexture() { driver->removeTexture(tUnknown); driver->removeTexture(tUnknownFit); driver->removeTexture(tUnknownThumb); + driver->removeTexture(tLoading); tUnknown = GetTextureFromFile("textures/unknown.jpg", CARD_IMG_WIDTH, CARD_IMG_HEIGHT); tUnknownFit = GetTextureFromFile("textures/unknown.jpg", imgWidthFit, imgHeightFit); tUnknownThumb = GetTextureFromFile("textures/unknown.jpg", imgWidthThumb, imgHeightThumb); + tLoading = GetTextureFromFile("textures/cover.jpg", imgWidthThumb, imgHeightThumb); driver->removeTexture(tBackGround); tBackGround = GetTextureFromFile("textures/bg.jpg", bgWidth, bgHeight); driver->removeTexture(tBackGround_menu); @@ -236,30 +246,90 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) { else return mainGame->gameConf.use_image_scale ? (fit ? tUnknownFit : tUnknown) : GetTextureThumb(code); } -irr::video::ITexture* ImageManager::GetTextureThumb(int code) { - if(code == 0) - return tUnknownThumb; - auto tit = tThumb.find(code); - int width = CARD_THUMB_WIDTH * mainGame->xScale; - int height = CARD_THUMB_HEIGHT * mainGame->yScale; - if(tit == tThumb.end()) { +int ImageManager::LoadThumbThread() { + while(true) { + imageManager.tThumbLoadingMutex.lock(); + int code = imageManager.tThumbLoadingCodes.front(); + imageManager.tThumbLoadingCodes.pop(); + imageManager.tThumbLoadingMutex.unlock(); char file[256]; sprintf(file, "expansions/pics/thumbnail/%d.jpg", code); - irr::video::ITexture* img = GetTextureFromFile(file, width, height); + irr::video::IImage* img = imageManager.driver->createImageFromFile(file); if(img == NULL) { sprintf(file, "pics/thumbnail/%d.jpg", code); - img = GetTextureFromFile(file, width, height); + img = imageManager.driver->createImageFromFile(file); } if(img == NULL && mainGame->gameConf.use_image_scale) { sprintf(file, "expansions/pics/%d.jpg", code); - img = GetTextureFromFile(file, width, height); - if(img == NULL) { - sprintf(file, "pics/%d.jpg", code); - img = GetTextureFromFile(file, width, height); + img = imageManager.driver->createImageFromFile(file); + } + if(img == NULL && mainGame->gameConf.use_image_scale) { + sprintf(file, "pics/%d.jpg", code); + img = imageManager.driver->createImageFromFile(file); + } + if(img != NULL) { + int width = CARD_THUMB_WIDTH * mainGame->xScale; + int height = CARD_THUMB_HEIGHT * mainGame->yScale; + if(img->getDimension() == irr::core::dimension2d(width, height)) { + img->grab(); + imageManager.tThumbLoadingMutex.lock(); + if(imageManager.tThumbLoadingThreadRunning) + imageManager.tThumbLoading[code] = img; + imageManager.tThumbLoadingMutex.unlock(); + } else { + irr::video::IImage *destimg = imageManager.driver->createImage(img->getColorFormat(), irr::core::dimension2d(width, height)); + imageScaleNNAA(img, destimg); + img->drop(); + destimg->grab(); + imageManager.tThumbLoadingMutex.lock(); + if(imageManager.tThumbLoadingThreadRunning) + imageManager.tThumbLoading[code] = destimg; + imageManager.tThumbLoadingMutex.unlock(); } + } else { + imageManager.tThumbLoadingMutex.lock(); + if(imageManager.tThumbLoadingThreadRunning) + imageManager.tThumbLoading[code] = NULL; + imageManager.tThumbLoadingMutex.unlock(); + } + imageManager.tThumbLoadingMutex.lock(); + imageManager.tThumbLoadingThreadRunning = !imageManager.tThumbLoadingCodes.empty(); + if(!imageManager.tThumbLoadingThreadRunning) + break; + imageManager.tThumbLoadingMutex.unlock(); + } + imageManager.tThumbLoadingMutex.unlock(); + return 0; +} +irr::video::ITexture* ImageManager::GetTextureThumb(int code) { + if(code == 0) + return tUnknownThumb; + imageManager.tThumbLoadingMutex.lock(); + auto lit = tThumbLoading.find(code); + if(lit != tThumbLoading.end()) { + if(lit->second != NULL) { + char file[256]; + sprintf(file, "pics/thumbnail/%d.jpg", code); + irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL + lit->second->drop(); + tThumb[code] = texture; + } else { + tThumb[code] = NULL; + } + tThumbLoading.erase(lit); + } + imageManager.tThumbLoadingMutex.unlock(); + auto tit = tThumb.find(code); + if(tit == tThumb.end()) { + tThumb[code] = tLoading; + imageManager.tThumbLoadingMutex.lock(); + tThumbLoadingCodes.push(code); + if(!tThumbLoadingThreadRunning) { + tThumbLoadingThreadRunning = true; + std::thread(LoadThumbThread).detach(); } - tThumb[code] = img; - return (img == NULL) ? tUnknownThumb : img; + imageManager.tThumbLoadingMutex.unlock(); + return tLoading; } if(tit->second) return tit->second; diff --git a/gframe/image_manager.h b/gframe/image_manager.h index 971e2412ee..442ae58157 100644 --- a/gframe/image_manager.h +++ b/gframe/image_manager.h @@ -4,6 +4,7 @@ #include "config.h" #include "data_manager.h" #include +#include namespace ygo { @@ -18,16 +19,22 @@ class ImageManager { irr::video::ITexture* GetTexture(int code, bool fit = false); irr::video::ITexture* GetTextureThumb(int code); irr::video::ITexture* GetTextureField(int code); + static int LoadThumbThread(); std::unordered_map tMap[2]; std::unordered_map tThumb; std::unordered_map tFields; + std::unordered_map tThumbLoading; + std::queue tThumbLoadingCodes; + std::mutex tThumbLoadingMutex; + bool tThumbLoadingThreadRunning; irr::IrrlichtDevice* device; irr::video::IVideoDriver* driver; irr::video::ITexture* tCover[4]; irr::video::ITexture* tUnknown; irr::video::ITexture* tUnknownFit; irr::video::ITexture* tUnknownThumb; + irr::video::ITexture* tLoading; irr::video::ITexture* tAct; irr::video::ITexture* tAttack; irr::video::ITexture* tNegated; From 3aeb7721707e8eee36ba811a946e63c2b8f11df8 Mon Sep 17 00:00:00 2001 From: mercury233 Date: Mon, 25 May 2020 11:38:48 +0800 Subject: [PATCH 7/7] update default config --- gframe/game.h | 4 +-- system.conf | 88 ++++++++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/gframe/game.h b/gframe/game.h index 9a822191d0..3e32f03409 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -148,8 +148,8 @@ class Game { void ClearChatMsg(); void AddDebugMsg(const char* msgbuf); void ErrorLog(const char* msgbuf); - void ClearTextures(); - void CloseGameButtons(); + void ClearTextures(); + void CloseGameButtons(); void CloseGameWindow(); void CloseDuelWindow(); diff --git a/system.conf b/system.conf index 4edd74aa48..84df8baa93 100644 --- a/system.conf +++ b/system.conf @@ -1,39 +1,49 @@ -#config file -#nickname & gamename should be less than 20 characters -use_d3d = 0 -use_image_scale = 1 -antialias = 2 -errorlog = 3 -nickname = Player -gamename = Game -lastdeck = new -textfont = c:/windows/fonts/simsun.ttc 14 -numfont = c:/windows/fonts/arialbd.ttf -serverport = 7911 -lasthost = 127.0.0.1 -lastport = 7911 -automonsterpos = 0 -autospellpos = 0 -randompos = 0 -autochain = 0 -waitchain = 0 -mute_opponent = 0 -mute_spectators = 0 -default_rule = 0 -hide_setname = 0 -hide_hint_button = 0 -#control_mode = 0: Key A/S/D/R Chain Buttons. control_mode = 1: MouseLeft/MouseRight/NULL/F9 Without Chain Buttons -control_mode = 0 -draw_field_spell = 1 -separate_clear_button = 1 -#auto_search_limit >= 0: Start search automatically when the user enters N chars -auto_search_limit = -1 -ignore_deck_changes = 0 -default_ot = 1 -enable_bot_mode = 0 -enable_sound = 1 -enable_music = 1 -#Volume of sound and music, between 0 and 100 -sound_volume = 50 -music_volume = 50 -music_mode = 1 +#config file +#nickname & gamename should be less than 20 characters +use_d3d = 0 +use_image_scale = 1 +antialias = 2 +errorlog = 3 +nickname = Player +gamename = Game +lastdeck = new +textfont = c:/windows/fonts/simsun.ttc 14 +numfont = c:/windows/fonts/arialbd.ttf +serverport = 7911 +lasthost = 127.0.0.1 +lastport = 7911 +automonsterpos = 0 +autospellpos = 0 +randompos = 0 +autochain = 0 +waitchain = 0 +mute_opponent = 0 +mute_spectators = 0 +default_rule = 0 +hide_setname = 0 +hide_hint_button = 0 +#control_mode = 0: Key A/S/D/R Chain Buttons. control_mode = 1: MouseLeft/MouseRight/NULL/F9 Without Chain Buttons +control_mode = 0 +draw_field_spell = 1 +separate_clear_button = 1 +#auto_search_limit >= 0: Start search automatically when the user enters N chars +auto_search_limit = -1 +#search_multiple_keywords = 0: Disable. 1: Search mutiple keywords with separator " ". 2: with separator "+" +search_multiple_keywords = 1 +ignore_deck_changes = 0 +default_ot = 1 +enable_bot_mode = 0 +quick_animation = 0 +auto_save_replay = 0 +draw_single_chain = 0 +prefer_expansion_script = 0 +window_maximized = 0 +window_width = 1280 +window_height = 800 +resize_popup_menu = 0 +enable_sound = 1 +enable_music = 1 +#Volume of sound and music, between 0 and 100 +sound_volume = 50 +music_volume = 50 +music_mode = 1