Commit b0e0ca3c authored by Chen Bill's avatar Chen Bill Committed by GitHub

add datas_begin(), strings_begin() (#2607)

* reorder

* DataManager: add datas_begin(), strings_begin()

* replace
parent cf135ac0
......@@ -1548,10 +1548,10 @@ 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);
if (cp == dataManager.datas_end)
if (cp == dataManager.datas_end())
continue;
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declare_opcodes)) {
......
......@@ -10,10 +10,6 @@ IFileSystem* DataManager::FileSystem;
DataManager dataManager;
DataManager::DataManager() : _datas(16384), _strings(16384) {
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
}
bool DataManager::ReadDB(sqlite3* pDB) {
......@@ -80,10 +76,6 @@ bool DataManager::ReadDB(sqlite3* pDB) {
_strings[cd.code] = cs;
}
} while (step != SQLITE_DONE);
datas_begin = _datas.begin();
datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
sqlite3_finalize(pStmt);
return true;
}
......@@ -180,6 +172,24 @@ bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
sqlite3_finalize(pStmt);
return false;
}
code_pointer DataManager::GetCodePointer(unsigned int code) const {
return _datas.find(code);
}
string_pointer DataManager::GetStringPointer(unsigned int code) const {
return _strings.find(code);
}
code_pointer DataManager::datas_begin() {
return _datas.cbegin();
}
code_pointer DataManager::datas_end() {
return _datas.cend();
}
string_pointer DataManager::strings_begin() {
return _strings.cbegin();
}
string_pointer DataManager::strings_end() {
return _strings.cend();
}
bool DataManager::GetData(unsigned int code, CardData* pData) const {
auto cdit = _datas.find(code);
if(cdit == _datas.end())
......@@ -189,12 +199,6 @@ bool DataManager::GetData(unsigned int code, CardData* pData) const {
}
return true;
}
code_pointer DataManager::GetCodePointer(unsigned int code) const {
return _datas.find(code);
}
string_pointer DataManager::GetStringPointer(unsigned int code) const {
return _strings.find(code);
}
bool DataManager::GetString(unsigned int code, CardString* pStr) const {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
......
......@@ -21,9 +21,13 @@ public:
void ReadStringConfLine(const char* linebuf);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = nullptr);
bool GetData(unsigned int code, CardData* pData) const;
code_pointer GetCodePointer(unsigned int code) const;
string_pointer GetStringPointer(unsigned int code) const;
code_pointer datas_begin();
code_pointer datas_end();
string_pointer strings_begin();
string_pointer strings_end();
bool GetData(unsigned int code, CardData* pData) const;
bool GetString(unsigned int code, CardString* pStr) const;
const wchar_t* GetName(unsigned int code) const;
const wchar_t* GetText(unsigned int code) const;
......@@ -45,10 +49,6 @@ public:
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;
char errmsg[512]{};
wchar_t numStrings[301][4]{};
......
......@@ -1015,7 +1015,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))
......@@ -1069,7 +1069,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) {
......@@ -1104,7 +1104,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;
......@@ -1139,7 +1139,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if (is_draging)
break;
auto pointer = dataManager.GetCodePointer(hovered_code);
if (pointer == dataManager.datas_end)
if (pointer == dataManager.datas_end())
break;
if(!check_limit(pointer))
break;
......@@ -1409,10 +1409,10 @@ void DeckBuilder::FilterCards() {
query_elements.push_back(element);
}
}
for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr) {
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)
if (strpointer == dataManager.strings_end())
continue;
const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN)
......
......@@ -1541,7 +1541,7 @@ void Game::ShowCardInfo(int code, bool resize) {
return;
wchar_t formatBuffer[256];
auto cit = dataManager.GetCodePointer(code);
bool is_valid = (cit != dataManager.datas_end);
bool is_valid = (cit != dataManager.datas_end());
imgCard->setImage(imageManager.GetTexture(code, true));
if (is_valid) {
auto& cd = cit->second;
......@@ -1558,7 +1558,7 @@ void Game::ShowCardInfo(int code, bool resize) {
if (is_valid && !gameConf.hide_setname) {
auto& cd = cit->second;
auto target = cit;
if (cd.alias && dataManager.GetCodePointer(cd.alias) != dataManager.datas_end) {
if (cd.alias && dataManager.GetCodePointer(cd.alias) != dataManager.datas_end()) {
target = dataManager.GetCodePointer(cd.alias);
}
if (target->second.setcode[0]) {
......
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