Commit 9dad9524 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master' into develop

parents f6954241 bf4d9cef
Pipeline #33577 passed with stages
in 6 minutes and 29 seconds
......@@ -13,23 +13,21 @@ DataManager::DataManager() : _datas(32768), _strings(32768) {
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
}
bool DataManager::ReadDB(sqlite3* pDB) {
sqlite3_stmt* pStmt{};
sqlite3_stmt* pStmt = nullptr;
const char* sql = "select * from datas,texts where datas.id=texts.id";
if (sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
return Error(pDB);
return Error(pDB, pStmt);
wchar_t strBuffer[4096];
int step = 0;
do {
CardDataC cd;
CardString cs;
step = sqlite3_step(pStmt);
if (step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
return Error(pDB, pStmt);
else if (step == SQLITE_ROW) {
if (step == SQLITE_ROW) {
cd.code = sqlite3_column_int(pStmt, 0);
cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2);
auto setcode = sqlite3_column_int64(pStmt, 3);
uint64_t setcode = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 3));
if (setcode) {
auto it = extra_setcode.find(cd.code);
if (it != extra_setcode.end()) {
......@@ -42,7 +40,7 @@ bool DataManager::ReadDB(sqlite3* pDB) {
else
cd.set_setcode(setcode);
}
cd.type = sqlite3_column_int(pStmt, 4);
cd.type = static_cast<decltype(cd.type)>(sqlite3_column_int64(pStmt, 4));
cd.attack = sqlite3_column_int(pStmt, 5);
cd.defense = sqlite3_column_int(pStmt, 6);
if (cd.type & TYPE_LINK) {
......@@ -51,13 +49,13 @@ bool DataManager::ReadDB(sqlite3* pDB) {
}
else
cd.link_marker = 0;
unsigned int level = sqlite3_column_int(pStmt, 7);
uint32_t level = static_cast<uint32_t>(sqlite3_column_int(pStmt, 7));
cd.level = level & 0xff;
cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff;
cd.race = sqlite3_column_int(pStmt, 8);
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
cd.race = static_cast<decltype(cd.race)>(sqlite3_column_int64(pStmt, 8));
cd.attribute = static_cast<decltype(cd.attribute)>(sqlite3_column_int64(pStmt, 9));
cd.category = static_cast<decltype(cd.category)>(sqlite3_column_int64(pStmt, 10));
_datas[cd.code] = cd;
if (const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer);
......@@ -76,7 +74,9 @@ bool DataManager::ReadDB(sqlite3* pDB) {
}
_strings[cd.code] = cs;
}
} while (step != SQLITE_DONE);
else if (step != SQLITE_DONE)
return Error(pDB, pStmt);
} while (step == SQLITE_ROW);
sqlite3_finalize(pStmt);
return true;
}
......
......@@ -69,7 +69,18 @@ void DeckBuilder::Initialize() {
mainGame->btnSideShuffle->setVisible(false);
mainGame->btnSideSort->setVisible(false);
mainGame->btnSideReload->setVisible(false);
filterList = &deckManager._lfList[mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : deckManager._lfList.size() - 1].content;
if (mainGame->gameConf.use_lflist) {
if (mainGame->gameConf.default_lflist >= 0 && mainGame->gameConf.default_lflist < (int)deckManager._lfList.size()) {
filterList = &deckManager._lfList[mainGame->gameConf.default_lflist];
}
else {
mainGame->gameConf.default_lflist = 0;
filterList = &deckManager._lfList.front();
}
}
else {
filterList = &deckManager._lfList.back();
}
ClearSearch();
rnd.reset((uint_fast32_t)std::time(nullptr));
mouse_pos.set(0, 0);
......@@ -1480,7 +1491,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).at(ptr->first) != filter_lm - 1))
if(filter_lm <= 3 && (!filterList->content.count(ptr->first) || filterList->content.at(ptr->first) != filter_lm - 1))
continue;
if(filter_lm == 4 && !(data.ot & AVAIL_OCG))
continue;
......@@ -1822,8 +1833,8 @@ void DeckBuilder::pop_side(int seq) {
bool DeckBuilder::check_limit(code_pointer pointer) {
unsigned int limitcode = pointer->second.alias ? pointer->second.alias : pointer->first;
int limit = 3;
auto flit = filterList->find(limitcode);
if(flit != filterList->end())
auto flit = filterList->content.find(limitcode);
if(flit != filterList->content.end())
limit = flit->second;
for(auto it = deckManager.current_deck.main.begin(); it != deckManager.current_deck.main.end(); ++it) {
if((*it)->first == limitcode || (*it)->second.alias == limitcode)
......
......@@ -5,6 +5,7 @@
#include <vector>
#include <irrlicht.h>
#include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
......@@ -81,7 +82,7 @@ public:
bool showing_pack{};
mt19937 rnd;
const std::unordered_map<int, int>* filterList;
const LFList* filterList{};
std::vector<code_pointer> results;
wchar_t result_string[8]{};
std::vector<std::wstring> expansionPacks;
......
......@@ -30,17 +30,14 @@ void DeckManager::LoadLFListSingle(const char* path) {
}
if (cur == _lfList.rend())
continue;
int code = 0;
unsigned int code = 0;
int count = -1;
if (std::sscanf(linebuf, "%9d%*[ ]%9d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
if (std::sscanf(linebuf, "%9u%*[ ]%9d", &code, &count) != 2)
continue;
if (count < 0 || count > 2)
continue;
unsigned int hcode = code;
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
cur->hash = cur->hash ^ ((code << 18) | (code >> 14)) ^ ((code << (27 + count)) | (code >> (5 - count)));
}
std::fclose(fp);
}
......@@ -53,7 +50,7 @@ void DeckManager::LoadLFList() {
nolimit.hash = 0;
_lfList.push_back(nolimit);
}
const wchar_t* DeckManager::GetLFListName(int lfhash) {
const wchar_t* DeckManager::GetLFListName(unsigned int lfhash) {
auto lit = std::find_if(_lfList.begin(), _lfList.end(), [lfhash](const ygo::LFList& list) {
return list.hash == lfhash;
});
......@@ -61,12 +58,12 @@ const wchar_t* DeckManager::GetLFListName(int lfhash) {
return lit->listName.c_str();
return dataManager.unknown_string;
}
const std::unordered_map<int, int>* DeckManager::GetLFListContent(int lfhash) {
const LFList* DeckManager::GetLFList(unsigned 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;
if (lit != _lfList.end())
return &(*lit);
return nullptr;
}
static unsigned int checkAvail(unsigned int ot, unsigned int avail) {
......@@ -87,9 +84,10 @@ unsigned int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
return (DECKERROR_EXTRACOUNT << 28) | (unsigned)deck.extra.size();
if(deck.side.size() > SIDE_MAX_SIZE)
return (DECKERROR_SIDECOUNT << 28) | (unsigned)deck.side.size();
auto list = GetLFListContent(lfhash);
if (!list)
auto lflist = GetLFList(lfhash);
if (!lflist)
return 0;
auto& list = lflist->content;
const unsigned int rule_map[6] = { AVAIL_OCG, AVAIL_TCG, AVAIL_SC, AVAIL_CUSTOM, AVAIL_OCGTCG, 0 };
unsigned int avail = 0;
if (rule >= 0 && rule < (int)(sizeof rule_map / sizeof rule_map[0]))
......@@ -105,8 +103,8 @@ unsigned int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
int dc = ccount[code];
if(dc > 3)
return (DECKERROR_CARDCOUNT << 28) | cit->first;
auto it = list->find(code);
if(it != list->end() && dc > it->second)
auto it = list.find(code);
if(it != list.end() && dc > it->second)
return (DECKERROR_LFLIST << 28) | cit->first;
}
for (auto& cit : deck.extra) {
......@@ -120,8 +118,8 @@ unsigned int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
int dc = ccount[code];
if(dc > 3)
return (DECKERROR_CARDCOUNT << 28) | cit->first;
auto it = list->find(code);
if(it != list->end() && dc > it->second)
auto it = list.find(code);
if(it != list.end() && dc > it->second)
return (DECKERROR_LFLIST << 28) | cit->first;
}
for (auto& cit : deck.side) {
......@@ -135,8 +133,8 @@ unsigned int DeckManager::CheckDeck(Deck& deck, int lfhash, int rule) {
int dc = ccount[code];
if(dc > 3)
return (DECKERROR_CARDCOUNT << 28) | cit->first;
auto it = list->find(code);
if(it != list->end() && dc > it->second)
auto it = list.find(code);
if(it != list.end() && dc > it->second)
return (DECKERROR_LFLIST << 28) | cit->first;
}
return 0;
......
......@@ -16,7 +16,7 @@ namespace ygo {
struct LFList {
unsigned int hash{};
std::wstring listName;
std::unordered_map<int, int> content;
std::unordered_map<unsigned int, int> content;
};
struct Deck {
std::vector<code_pointer> main;
......@@ -44,8 +44,8 @@ public:
void LoadLFListSingle(const char* path);
void LoadLFList();
const wchar_t* GetLFListName(int lfhash);
const std::unordered_map<int, int>* GetLFListContent(int lfhash);
const wchar_t* GetLFListName(unsigned int lfhash);
const LFList* GetLFList(unsigned int lfhash);
unsigned int CheckDeck(Deck& deck, int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
......
......@@ -1126,9 +1126,9 @@ void Game::WaitFrameSignal(int frame) {
signalFrame = (gameConf.quick_animation && frame >= 12) ? 12 : frame;
frameSignal.Wait();
}
void Game::DrawThumb(code_pointer cp, irr::core::vector2di pos, const std::unordered_map<int,int>* lflist, bool drag) {
void Game::DrawThumb(code_pointer cp, irr::core::vector2di pos, const LFList* lflist, bool drag) {
int code = cp->first;
int lcode = cp->second.alias;
auto lcode = cp->second.alias;
if(lcode == 0)
lcode = code;
irr::video::ITexture* img = imageManager.GetTextureThumb(code);
......@@ -1144,8 +1144,9 @@ void Game::DrawThumb(code_pointer cp, irr::core::vector2di pos, const std::unord
otloc = recti(pos.X + 7, pos.Y + 50 * mainGame->yScale, pos.X + 37 * mainGame->xScale, pos.Y + 65 * mainGame->yScale);
}
driver->draw2DImage(img, dragloc, rect<s32>(0, 0, size.Width, size.Height));
if(lflist->count(lcode)) {
switch((*lflist).at(lcode)) {
auto lfit = lflist->content.find(lcode);
if (lfit != lflist->content.end()) {
switch(lfit->second) {
case 0:
driver->draw2DImage(imageManager.tLim, limitloc, recti(0, 0, 64, 64), 0, 0, true);
break;
......
......@@ -500,9 +500,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
mainGame->dInfo.time_limit = pkt->info.time_limit;
mainGame->dInfo.time_left[0] = 0;
mainGame->dInfo.time_left[1] = 0;
mainGame->deckBuilder.filterList = deckManager.GetLFListContent(pkt->info.lflist);
mainGame->deckBuilder.filterList = deckManager.GetLFList(pkt->info.lflist);
if(mainGame->deckBuilder.filterList == nullptr)
mainGame->deckBuilder.filterList = &deckManager._lfList[0].content;
mainGame->deckBuilder.filterList = &deckManager._lfList[0];
mainGame->stHostPrepOB->setText(L"");
mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str());
mainGame->RefreshCategoryDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
......
......@@ -53,7 +53,7 @@ public:
bufferevent_write(client_bev, duel_client_write, 3);
}
template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) {
static void SendPacketToServer(unsigned char proto, const ST& st) {
auto p = duel_client_write;
if (sizeof(ST) > MAX_DATA_SIZE)
return;
......
......@@ -1939,7 +1939,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
mainGame->cbLFlist->setEnabled(mainGame->gameConf.use_lflist);
mainGame->cbLFlist->setSelected(mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : mainGame->cbLFlist->getItemCount() - 1);
mainGame->cbHostLFlist->setSelected(mainGame->gameConf.use_lflist ? mainGame->gameConf.default_lflist : mainGame->cbHostLFlist->getItemCount() - 1);
mainGame->deckBuilder.filterList = &deckManager._lfList[mainGame->cbLFlist->getSelected()].content;
mainGame->deckBuilder.filterList = &deckManager._lfList[mainGame->cbLFlist->getSelected()];
return true;
break;
}
......@@ -1951,7 +1951,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
case COMBOBOX_LFLIST: {
mainGame->gameConf.default_lflist = mainGame->cbLFlist->getSelected();
mainGame->cbHostLFlist->setSelected(mainGame->gameConf.default_lflist);
mainGame->deckBuilder.filterList = &deckManager._lfList[mainGame->gameConf.default_lflist].content;
mainGame->deckBuilder.filterList = &deckManager._lfList[mainGame->gameConf.default_lflist];
return true;
break;
}
......
......@@ -170,7 +170,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, irr::core::vector2di pos, const std::unordered_map<int,int>* lflist, bool drag = false);
void DrawThumb(code_pointer cp, irr::core::vector2di pos, const LFList* lflist, bool drag = false);
void DrawDeckBd();
void LoadConfig();
void SaveConfig();
......
......@@ -41,7 +41,7 @@ public:
bufferevent_write(dp->bev, net_server_write, 3);
}
template<typename ST>
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, ST& st) {
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, const ST& st) {
auto p = net_server_write;
if (sizeof(ST) > MAX_DATA_SIZE)
return;
......
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