mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/DataStores: Removed the need to edit DB2Metadata automatically generated to account for non-localized string fields
This commit is contained in:
@@ -89,17 +89,6 @@ uint32 DB2Meta::GetDbFieldCount() const
|
||||
return fields;
|
||||
}
|
||||
|
||||
uint32 DB2Meta::GetStringFieldCount(bool localizedOnly) const
|
||||
{
|
||||
uint32 stringFields = 0;
|
||||
for (uint32 i = 0; i < FieldCount; ++i)
|
||||
if (Types[i] == FT_STRING || (Types[i] == FT_STRING_NOT_LOCALIZED && !localizedOnly))
|
||||
for (uint8 j = 0; j < ArraySizes[i]; ++j)
|
||||
++stringFields;
|
||||
|
||||
return stringFields;
|
||||
}
|
||||
|
||||
DB2FieldMeta::DB2FieldMeta(bool isSigned, DBCFormer type, char const* name)
|
||||
: IsSigned(isSigned), Type(type), Name(name)
|
||||
{
|
||||
|
||||
@@ -35,8 +35,6 @@ struct TC_COMMON_API DB2Meta
|
||||
uint32 GetDbIndexField() const;
|
||||
uint32 GetDbFieldCount() const;
|
||||
|
||||
uint32 GetStringFieldCount(bool localizedOnly) const;
|
||||
|
||||
int32 IndexField;
|
||||
uint32 FieldCount;
|
||||
uint32 LayoutHash;
|
||||
|
||||
@@ -252,7 +252,7 @@ inline void LoadDB2(uint32& availableDb2Locales, DB2StoreProblemList& errlist, D
|
||||
clientMetaString += loadInfo->Meta->Types[i];
|
||||
|
||||
for (std::size_t i = loadInfo->Meta->HasIndexFieldInData() ? 0 : 1; i < loadInfo->FieldCount; ++i)
|
||||
ourMetaString += char(loadInfo->Fields[i].Type);
|
||||
ourMetaString += char(std::tolower(loadInfo->Fields[i].Type));
|
||||
|
||||
ASSERT(clientMetaString == ourMetaString, "C++ structure fields %s do not match generated types from the client %s", ourMetaString.c_str(), clientMetaString.c_str());
|
||||
|
||||
|
||||
@@ -27,6 +27,19 @@ DB2LoadInfo::DB2LoadInfo() : Fields(nullptr), FieldCount(0), Meta(nullptr), Stat
|
||||
DB2LoadInfo::DB2LoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta, HotfixDatabaseStatements statement)
|
||||
: Fields(fields), FieldCount(fieldCount), Meta(meta), Statement(statement)
|
||||
{
|
||||
TypesString.reserve(FieldCount);
|
||||
for (std::size_t i = 0; i < FieldCount; ++i)
|
||||
TypesString += char(Fields[i].Type);
|
||||
}
|
||||
|
||||
uint32 DB2LoadInfo::GetStringFieldCount(bool localizedOnly) const
|
||||
{
|
||||
uint32 stringFields = 0;
|
||||
for (std::size_t i = 0; i < TypesString.length(); ++i)
|
||||
if (TypesString[i] == FT_STRING || (TypesString[i] == FT_STRING_NOT_LOCALIZED && !localizedOnly))
|
||||
++stringFields;
|
||||
|
||||
return stringFields;
|
||||
}
|
||||
|
||||
class DB2FileLoaderImpl
|
||||
@@ -309,8 +322,8 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& records, char**& indexTa
|
||||
char* dataTable = new char[(_header->RecordCount + (_header->CopyTableSize / 8)) * recordsize];
|
||||
|
||||
// we store flat holders pool as single memory block
|
||||
std::size_t stringFields = _loadInfo.Meta->GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.Meta->GetStringFieldCount(true);
|
||||
std::size_t stringFields = _loadInfo.GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.GetStringFieldCount(true);
|
||||
|
||||
// each string field at load have array of string for each locale
|
||||
std::size_t stringHoldersRecordPoolSize = localizedStringFields * sizeof(LocalizedString) + (stringFields - localizedStringFields) * sizeof(char*);
|
||||
@@ -350,7 +363,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceData(uint32& records, char**& indexTa
|
||||
{
|
||||
for (uint32 z = 0; z < _loadInfo.Meta->ArraySizes[x]; ++z)
|
||||
{
|
||||
switch (_loadInfo.Meta->Types[x])
|
||||
switch (_loadInfo.TypesString[fieldIndex])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
*((float*)(&dataTable[offset])) = rec.getFloat(x, z);
|
||||
@@ -423,14 +436,18 @@ char* DB2FileLoaderRegularImpl::AutoProduceStrings(char* dataTable, uint32 local
|
||||
|
||||
for (uint32 y = 0; y < _header->RecordCount; y++)
|
||||
{
|
||||
uint32 fieldIndex = 0;
|
||||
if (!_loadInfo.Meta->HasIndexFieldInData())
|
||||
{
|
||||
offset += 4;
|
||||
++fieldIndex;
|
||||
}
|
||||
|
||||
for (uint32 x = 0; x < _header->FieldCount; ++x)
|
||||
{
|
||||
for (uint32 z = 0; z < _loadInfo.Meta->ArraySizes[x]; ++z)
|
||||
{
|
||||
switch (_loadInfo.Meta->Types[x])
|
||||
switch (_loadInfo.TypesString[fieldIndex])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
case FT_INT:
|
||||
@@ -467,6 +484,7 @@ char* DB2FileLoaderRegularImpl::AutoProduceStrings(char* dataTable, uint32 local
|
||||
ASSERT(false, "Unknown format character '%c' found in %s meta", _loadInfo.Meta->Types[x], fileName);
|
||||
break;
|
||||
}
|
||||
++fieldIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -570,8 +588,8 @@ char* DB2FileLoaderSparseImpl::AutoProduceData(uint32& maxId, char**& indexTable
|
||||
char* dataTable = new char[records * recordsize];
|
||||
|
||||
// we store flat holders pool as single memory block
|
||||
std::size_t stringFields = _loadInfo.Meta->GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.Meta->GetStringFieldCount(true);
|
||||
std::size_t stringFields = _loadInfo.GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.GetStringFieldCount(true);
|
||||
|
||||
// each string field at load have array of string for each locale
|
||||
std::size_t stringHoldersRecordPoolSize = localizedStringFields * sizeof(LocalizedString) + (stringFields - localizedStringFields) * sizeof(char*);
|
||||
@@ -747,7 +765,7 @@ char* DB2FileLoaderSparseImpl::AutoProduceStrings(char* dataTable, uint32 locale
|
||||
++records;
|
||||
|
||||
uint32 recordsize = _loadInfo.Meta->GetRecordSize();
|
||||
std::size_t stringFields = _loadInfo.Meta->GetStringFieldCount(true);
|
||||
std::size_t stringFields = _loadInfo.GetStringFieldCount(true);
|
||||
char* stringTable = new char[_header->StringTableSize - dataStart - records * ((recordsize - (!_loadInfo.Meta->HasIndexFieldInData() ? 4 : 0)) - stringFields * sizeof(char*))];
|
||||
memset(stringTable, 0, _header->StringTableSize - dataStart - records * ((recordsize - (!_loadInfo.Meta->HasIndexFieldInData() ? 4 : 0)) - stringFields * sizeof(char*)));
|
||||
char* stringPtr = stringTable;
|
||||
@@ -827,8 +845,8 @@ char* DB2DatabaseLoader::Load(uint32& records, char**& indexTable, char*& string
|
||||
uint32 recordSize = _loadInfo.Meta->GetRecordSize();
|
||||
|
||||
// we store flat holders pool as single memory block
|
||||
std::size_t stringFields = _loadInfo.Meta->GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.Meta->GetStringFieldCount(true);
|
||||
std::size_t stringFields = _loadInfo.GetStringFieldCount(false);
|
||||
std::size_t localizedStringFields = _loadInfo.GetStringFieldCount(true);
|
||||
|
||||
// each string field at load have array of string for each locale
|
||||
std::size_t stringHoldersRecordPoolSize = localizedStringFields * sizeof(LocalizedString) + (stringFields - localizedStringFields) * sizeof(char*);
|
||||
@@ -893,7 +911,7 @@ char* DB2DatabaseLoader::Load(uint32& records, char**& indexTable, char*& string
|
||||
{
|
||||
for (uint32 z = 0; z < _loadInfo.Meta->ArraySizes[x]; ++z)
|
||||
{
|
||||
switch (_loadInfo.Meta->Types[x])
|
||||
switch (_loadInfo.TypesString[f])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
*((float*)(&dataValue[offset])) = fields[f].GetFloat();
|
||||
@@ -982,7 +1000,7 @@ void DB2DatabaseLoader::LoadStrings(uint32 locale, uint32 records, char** indexT
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
std::size_t stringFields = _loadInfo.Meta->GetStringFieldCount(true);
|
||||
std::size_t stringFields = _loadInfo.GetStringFieldCount(true);
|
||||
if (result->GetFieldCount() != stringFields + 1 /*ID*/)
|
||||
return;
|
||||
|
||||
@@ -1002,14 +1020,18 @@ void DB2DatabaseLoader::LoadStrings(uint32 locale, uint32 records, char** indexT
|
||||
// Attempt to overwrite existing data
|
||||
if (char* dataValue = indexTable[indexValue])
|
||||
{
|
||||
uint32 fieldIndex = 0;
|
||||
if (!_loadInfo.Meta->HasIndexFieldInData())
|
||||
{
|
||||
offset += 4;
|
||||
++fieldIndex;
|
||||
}
|
||||
|
||||
for (uint32 x = 0; x < fieldCount; ++x)
|
||||
{
|
||||
for (uint32 z = 0; z < _loadInfo.Meta->ArraySizes[x]; ++z)
|
||||
{
|
||||
switch (_loadInfo.Meta->Types[x])
|
||||
switch (_loadInfo.TypesString[fieldIndex])
|
||||
{
|
||||
case FT_FLOAT:
|
||||
case FT_INT:
|
||||
@@ -1040,6 +1062,7 @@ void DB2DatabaseLoader::LoadStrings(uint32 locale, uint32 records, char** indexT
|
||||
ASSERT(false, "Unknown format character '%c' found in %s meta", _loadInfo.Meta->Types[x], _storageName.c_str());
|
||||
break;
|
||||
}
|
||||
++fieldIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +49,13 @@ struct TC_SHARED_API DB2LoadInfo
|
||||
DB2LoadInfo();
|
||||
DB2LoadInfo(DB2FieldMeta const* fields, std::size_t fieldCount, DB2Meta const* meta, HotfixDatabaseStatements statement);
|
||||
|
||||
uint32 GetStringFieldCount(bool localizedOnly) const;
|
||||
|
||||
DB2FieldMeta const* Fields;
|
||||
std::size_t FieldCount;
|
||||
DB2Meta const* Meta;
|
||||
HotfixDatabaseStatements Statement;
|
||||
std::string TypesString;
|
||||
};
|
||||
|
||||
class TC_SHARED_API DB2FileLoader
|
||||
|
||||
@@ -187,7 +187,7 @@ public:
|
||||
return false;
|
||||
|
||||
// load strings from another locale db2 data
|
||||
if (_loadInfo.Meta->GetStringFieldCount(true))
|
||||
if (_loadInfo.GetStringFieldCount(true))
|
||||
if (char* stringBlock = db2.AutoProduceStrings(_dataTable, locale))
|
||||
_stringPool.push_back(stringBlock);
|
||||
return true;
|
||||
@@ -203,7 +203,7 @@ public:
|
||||
|
||||
void LoadStringsFromDB(uint32 locale) override
|
||||
{
|
||||
if (!_loadInfo.Meta->GetStringFieldCount(true))
|
||||
if (!_loadInfo.GetStringFieldCount(true))
|
||||
return;
|
||||
|
||||
DB2DatabaseLoader(_fileName, _loadInfo).LoadStrings(locale, _indexTableSize, _indexTable.AsChar, _stringPool);
|
||||
|
||||
Reference in New Issue
Block a user