Commit 5298b352 authored by mercury233's avatar mercury233

Merge branch 'master' of https://github.com/Fluorohydride/ygopro into server

parents 21229426 c5297715
......@@ -33,6 +33,7 @@ struct CardString {
std::wstring desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
typedef std::unordered_map<unsigned int, CardString>::const_iterator string_pointer;
class ClientCard {
public:
......
......@@ -1555,9 +1555,11 @@ void ClientField::UpdateDeclarableList() {
}
mainGame->lstANCard->clear();
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
for(auto cit = dataManager.strings_begin; cit != dataManager.strings_end; ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
auto cp = dataManager.GetCodePointer(cit->first);
if (cp == dataManager.datas_end)
continue;
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declare_opcodes)) {
if(pname == cit->second.name || trycode == cit->first) { //exact match or last used
......
......@@ -111,6 +111,10 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
spmemvfs_close_db(&db);
spmemvfs_env_fini();
#endif
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
return true;
}
bool DataManager::LoadStrings(const char* file) {
......@@ -209,9 +213,12 @@ bool DataManager::GetData(unsigned int code, CardData* pData) {
}
return true;
}
code_pointer DataManager::GetCodePointer(int code) {
code_pointer DataManager::GetCodePointer(unsigned int code) {
return _datas.find(code);
}
string_pointer DataManager::GetStringPointer(unsigned int code) {
return _strings.find(code);
}
bool DataManager::GetString(int code, CardString* pStr) {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
......
......@@ -13,7 +13,12 @@ namespace ygo {
class DataManager {
public:
DataManager(): _datas(16384), _strings(16384) {}
DataManager(): _datas(16384), _strings(16384) {
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
}
bool LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file);
#ifndef YGOPRO_SERVER_MODE
......@@ -26,7 +31,8 @@ public:
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
#endif //YGOPRO_SERVER_MODE
bool GetData(unsigned int code, CardData* pData);
code_pointer GetCodePointer(int code);
code_pointer GetCodePointer(unsigned int code);
string_pointer GetStringPointer(unsigned int code);
bool GetString(int code, CardString* pStr);
const wchar_t* GetName(int code);
const wchar_t* GetText(int code);
......@@ -44,12 +50,14 @@ public:
const wchar_t* FormatSetName(unsigned long long setcode);
const wchar_t* FormatLinkMarker(int link_marker);
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::wstring> _counterStrings;
std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings;
code_pointer datas_begin;
code_pointer datas_end;
string_pointer strings_begin;
string_pointer strings_end;
wchar_t numStrings[301][4];
wchar_t numBuffer[6];
......@@ -67,6 +75,10 @@ public:
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
static IFileSystem* FileSystem;
#endif
private:
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
};
extern DataManager dataManager;
......
......@@ -43,8 +43,8 @@ static int parse_filter(const wchar_t* pstr, unsigned int* type) {
static bool check_set_code(const CardDataC& data, int set_code) {
unsigned long long sc = data.setcode;
if (data.alias) {
auto aptr = dataManager._datas.find(data.alias);
if (aptr != dataManager._datas.end())
auto aptr = dataManager.GetCodePointer(data.alias);
if (aptr != dataManager.datas_end)
sc = aptr->second.setcode;
}
bool res = false;
......@@ -1030,7 +1030,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
dragx = event.MouseInput.X;
dragy = event.MouseInput.Y;
draging_pointer = dataManager.GetCodePointer(hovered_code);
if(draging_pointer == dataManager._datas.end())
if(draging_pointer == dataManager.datas_end)
break;
if(hovered_pos == 4) {
if(!check_limit(draging_pointer))
......@@ -1084,7 +1084,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(hovered_pos == 0 || hovered_seq == -1)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
if(pointer == dataManager.datas_end)
break;
soundManager.PlaySoundEffect(SOUND_CARD_DROP);
if(hovered_pos == 1) {
......@@ -1119,7 +1119,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
pop_side(hovered_seq);
} else {
auto pointer = dataManager.GetCodePointer(hovered_code);
if(pointer == dataManager._datas.end())
if(pointer == dataManager.datas_end)
break;
if(!check_limit(pointer))
break;
......@@ -1154,6 +1154,8 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if (is_draging)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if (pointer == dataManager.datas_end)
break;
if(!check_limit(pointer))
break;
soundManager.PlaySoundEffect(SOUND_CARD_PICK);
......@@ -1421,9 +1423,11 @@ void DeckBuilder::FilterCards() {
query_elements.push_back(element);
}
}
auto strpointer = dataManager._strings.begin();
for(code_pointer ptr = dataManager._datas.begin(); ptr != dataManager._datas.end(); ++ptr, ++strpointer) {
for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr) {
const CardDataC& data = ptr->second;
auto strpointer = dataManager.GetStringPointer(ptr->first);
if (strpointer == dataManager.strings_end)
continue;
const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN)
continue;
......
......@@ -166,7 +166,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) {
if(deck.extra.size() >= 15)
continue;
deck.extra.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.extra.push_back(dataManager.GetCodePointer(code));
} else if(deck.main.size() < 60) {
deck.main.push_back(dataManager.GetCodePointer(code));
}
......@@ -180,7 +180,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
if(cd.type & TYPE_TOKEN)
continue;
if(deck.side.size() < 15)
deck.side.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.side.push_back(dataManager.GetCodePointer(code));
}
return errorcode;
}
......
......@@ -1593,8 +1593,8 @@ void Game::ShowCardInfo(int code, bool resize) {
if(!gameConf.hide_setname) {
unsigned long long sc = cd.setcode;
if(cd.alias) {
auto aptr = dataManager._datas.find(cd.alias);
if(aptr != dataManager._datas.end())
auto aptr = dataManager.GetCodePointer(cd.alias);
if(aptr != dataManager.datas_end)
sc = aptr->second.setcode;
}
if(sc) {
......
......@@ -314,11 +314,17 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
for(int i = 0; i < max; ++i) {
int main = replay.ReadInt32();
Deck tmp_deck;
for(int j = 0; j < main; ++j)
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
for (int j = 0; j < main; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.main.push_back(card);
}
int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
for (int j = 0; j < extra; ++j) {
auto card = dataManager.GetCodePointer(replay.ReadInt32());
if (card != dataManager.datas_end)
tmp_deck.extra.push_back(card);
}
FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
......
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