Commit c5297715 authored by Chen Bill's avatar Chen Bill

DataManager: change _strings to private

parent 4297cb3e
...@@ -33,6 +33,7 @@ struct CardString { ...@@ -33,6 +33,7 @@ struct CardString {
std::wstring desc[16]; std::wstring desc[16];
}; };
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer; typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
typedef std::unordered_map<unsigned int, CardString>::const_iterator string_pointer;
class ClientCard { class ClientCard {
public: public:
......
...@@ -1555,7 +1555,7 @@ void ClientField::UpdateDeclarableList() { ...@@ -1555,7 +1555,7 @@ void ClientField::UpdateDeclarableList() {
} }
mainGame->lstANCard->clear(); mainGame->lstANCard->clear();
ancard.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) { if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); auto cp = dataManager.GetCodePointer(cit->first);
if (cp == dataManager.datas_end) if (cp == dataManager.datas_end)
......
...@@ -85,6 +85,8 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -85,6 +85,8 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
spmemvfs_env_fini(); spmemvfs_env_fini();
datas_begin = _datas.begin(); datas_begin = _datas.begin();
datas_end = _datas.end(); datas_end = _datas.end();
strings_begin = _strings.begin();
strings_end = _strings.end();
return true; return true;
} }
bool DataManager::LoadStrings(const char* file) { bool DataManager::LoadStrings(const char* file) {
...@@ -170,9 +172,12 @@ bool DataManager::GetData(unsigned int code, CardData* pData) { ...@@ -170,9 +172,12 @@ bool DataManager::GetData(unsigned int code, CardData* pData) {
} }
return true; return true;
} }
code_pointer DataManager::GetCodePointer(int code) { code_pointer DataManager::GetCodePointer(unsigned int code) {
return _datas.find(code); return _datas.find(code);
} }
string_pointer DataManager::GetStringPointer(unsigned int code) {
return _strings.find(code);
}
bool DataManager::GetString(int code, CardString* pStr) { bool DataManager::GetString(int code, CardString* pStr) {
auto csit = _strings.find(code); auto csit = _strings.find(code);
if(csit == _strings.end()) { if(csit == _strings.end()) {
......
...@@ -11,14 +11,20 @@ namespace ygo { ...@@ -11,14 +11,20 @@ namespace ygo {
class DataManager { class DataManager {
public: 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 LoadDB(const wchar_t* wfile);
bool LoadStrings(const char* file); bool LoadStrings(const char* file);
bool LoadStrings(IReadFile* reader); bool LoadStrings(IReadFile* reader);
void ReadStringConfLine(const char* linebuf); void ReadStringConfLine(const char* linebuf);
bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0); bool Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(unsigned int code, CardData* pData); 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); bool GetString(int code, CardString* pStr);
const wchar_t* GetName(int code); const wchar_t* GetName(int code);
const wchar_t* GetText(int code); const wchar_t* GetText(int code);
...@@ -36,13 +42,14 @@ public: ...@@ -36,13 +42,14 @@ public:
const wchar_t* FormatSetName(unsigned long long setcode); const wchar_t* FormatSetName(unsigned long long setcode);
const wchar_t* FormatLinkMarker(int link_marker); const wchar_t* FormatLinkMarker(int link_marker);
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::wstring> _counterStrings; std::unordered_map<unsigned int, std::wstring> _counterStrings;
std::unordered_map<unsigned int, std::wstring> _victoryStrings; std::unordered_map<unsigned int, std::wstring> _victoryStrings;
std::unordered_map<unsigned int, std::wstring> _setnameStrings; std::unordered_map<unsigned int, std::wstring> _setnameStrings;
std::unordered_map<unsigned int, std::wstring> _sysStrings; std::unordered_map<unsigned int, std::wstring> _sysStrings;
code_pointer datas_begin; code_pointer datas_begin;
code_pointer datas_end; code_pointer datas_end;
string_pointer strings_begin;
string_pointer strings_end;
wchar_t numStrings[301][4]; wchar_t numStrings[301][4];
wchar_t numBuffer[6]; wchar_t numBuffer[6];
...@@ -61,6 +68,7 @@ public: ...@@ -61,6 +68,7 @@ public:
private: private:
std::unordered_map<unsigned int, CardDataC> _datas; std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
}; };
extern DataManager dataManager; extern DataManager dataManager;
......
...@@ -1423,9 +1423,11 @@ void DeckBuilder::FilterCards() { ...@@ -1423,9 +1423,11 @@ void DeckBuilder::FilterCards() {
query_elements.push_back(element); query_elements.push_back(element);
} }
} }
auto strpointer = dataManager._strings.begin(); for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr) {
for(code_pointer ptr = dataManager.datas_begin; ptr != dataManager.datas_end; ++ptr, ++strpointer) {
const CardDataC& data = ptr->second; const CardDataC& data = ptr->second;
auto strpointer = dataManager.GetStringPointer(ptr->first);
if (strpointer == dataManager.strings_end)
continue;
const CardString& text = strpointer->second; const CardString& text = strpointer->second;
if(data.type & TYPE_TOKEN) if(data.type & TYPE_TOKEN)
continue; continue;
......
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