Commit 32da865f authored by Chen Bill's avatar Chen Bill

setcode use array

parent 6192b5fd
...@@ -7,11 +7,15 @@ namespace ygo { ...@@ -7,11 +7,15 @@ namespace ygo {
const wchar_t* DataManager::unknown_string = L"???"; const wchar_t* DataManager::unknown_string = L"???";
byte DataManager::scriptBuffer[0x20000]; byte DataManager::scriptBuffer[0x20000];
IFileSystem* DataManager::FileSystem; IFileSystem* DataManager::FileSystem;
std::unordered_map<unsigned int, std::vector<uint16_t>> DataManager::extra_setcode{
{8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}},
};
DataManager dataManager; 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::LoadDB(const wchar_t* wfile) { bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256]; char file[256];
BufferIO::EncodeUTF8(wfile, file); BufferIO::EncodeUTF8(wfile, file);
...@@ -50,8 +54,13 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -50,8 +54,13 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
cd.ot = sqlite3_column_int(pStmt, 1); cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2); cd.alias = sqlite3_column_int(pStmt, 2);
auto it = extra_setcode.find(cd.code); auto it = extra_setcode.find(cd.code);
if (it != extra_setcode.end()) if (it != extra_setcode.end()) {
cd.setcode.assign(it->second.begin(), it->second.end()); int len = it->second.size();
if (len > SIZE_SETCODE)
len = SIZE_SETCODE;
if (len)
std::memcpy(cd.setcode, it->second.data(), len * sizeof(uint16_t));
}
else else
cd.set_setcode(sqlite3_column_int64(pStmt, 3)); cd.set_setcode(sqlite3_column_int64(pStmt, 3));
cd.type = sqlite3_column_int(pStmt, 4); cd.type = sqlite3_column_int(pStmt, 4);
...@@ -166,7 +175,7 @@ bool DataManager::GetData(unsigned int code, CardData* pData) { ...@@ -166,7 +175,7 @@ bool DataManager::GetData(unsigned int code, CardData* pData) {
if (pData) { if (pData) {
pData->code = data.code; pData->code = data.code;
pData->alias = data.alias; pData->alias = data.alias;
pData->setcode.assign(data.setcode.begin(), data.setcode.end()); std::memcpy(pData->setcode, data.setcode, SIZE_SETCODE);
pData->type = data.type; pData->type = data.type;
pData->level = data.level; pData->level = data.level;
pData->attribute = data.attribute; pData->attribute = data.attribute;
...@@ -336,12 +345,11 @@ const wchar_t* DataManager::FormatType(int type) { ...@@ -336,12 +345,11 @@ const wchar_t* DataManager::FormatType(int type) {
return unknown_string; return unknown_string;
return tpBuffer; return tpBuffer;
} }
const wchar_t* DataManager::FormatSetName(const std::vector<uint16_t>& setcode) { const wchar_t* DataManager::FormatSetName(const uint16_t setcode[]) {
wchar_t* p = scBuffer; wchar_t* p = scBuffer;
int len = setcode.size(); for(int i = 0; i < 10; ++i) {
if (len > 10) if (!setcode[i])
len = 10; break;
for(int i = 0; i < len; ++i) {
const wchar_t* setname = GetSetName(setcode[i]); const wchar_t* setname = GetSetName(setcode[i]);
if(setname) { if(setname) {
BufferIO::CopyWStrRef(setname, p, 32); BufferIO::CopyWStrRef(setname, p, 32);
......
...@@ -11,12 +11,7 @@ namespace ygo { ...@@ -11,12 +11,7 @@ namespace ygo {
class DataManager { class DataManager {
public: public:
DataManager(): _datas(16384), _strings(16384) { DataManager();
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);
...@@ -39,7 +34,7 @@ public: ...@@ -39,7 +34,7 @@ public:
const wchar_t* FormatAttribute(int attribute); const wchar_t* FormatAttribute(int attribute);
const wchar_t* FormatRace(int race); const wchar_t* FormatRace(int race);
const wchar_t* FormatType(int type); const wchar_t* FormatType(int type);
const wchar_t* FormatSetName(const std::vector<uint16_t>& setcode); const wchar_t* FormatSetName(const uint16_t setcode[]);
const wchar_t* FormatLinkMarker(int link_marker); const wchar_t* FormatLinkMarker(int link_marker);
std::unordered_map<unsigned int, std::wstring> _counterStrings; std::unordered_map<unsigned int, std::wstring> _counterStrings;
...@@ -65,11 +60,11 @@ public: ...@@ -65,11 +60,11 @@ public:
static byte* ScriptReaderEx(const char* script_name, int* slen); static byte* ScriptReaderEx(const char* script_name, int* slen);
static byte* ScriptReader(const char* script_name, int* slen); static byte* ScriptReader(const char* script_name, int* slen);
static IFileSystem* FileSystem; static IFileSystem* FileSystem;
static std::unordered_map<unsigned int, std::vector<uint16_t>> extra_setcode;
private: private:
std::unordered_map<unsigned int, CardDataC> _datas; std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings; std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, std::vector<uint16_t>> extra_setcode;
}; };
extern DataManager dataManager; extern DataManager dataManager;
......
...@@ -1540,7 +1540,7 @@ void Game::ShowCardInfo(int code, bool resize) { ...@@ -1540,7 +1540,7 @@ void Game::ShowCardInfo(int code, bool resize) {
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); target = dataManager.GetCodePointer(cd.alias);
} }
if (target->second.setcode.size()) { if (target->second.setcode[0]) {
offset = 23;// *yScale; offset = 23;// *yScale;
myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), dataManager.FormatSetName(target->second.setcode)); myswprintf(formatBuffer, L"%ls%ls", dataManager.GetSysString(1329), dataManager.FormatSetName(target->second.setcode));
stSetName->setText(formatBuffer); stSetName->setText(formatBuffer);
......
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