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

setcode use array

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