Core/DataStores: Simplified string memory allocation in db2 files, dropped unneccessary level of indirection

This commit is contained in:
Shauren
2020-06-27 13:33:17 +02:00
parent eccc015ce7
commit deca201f77
38 changed files with 333 additions and 380 deletions

View File

@@ -279,7 +279,7 @@ public:
if (titleInfo && target->HasTitle(titleInfo))
{
std::string name = (target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[handler->GetSessionDbcLocale()];
std::string name = (target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()];
if (name.empty())
continue;
@@ -647,7 +647,7 @@ public:
{
FactionState const& faction = itr->second;
FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction.ID);
char const* factionName = factionEntry ? factionEntry->Name->Str[loc] : "#Not found#";
char const* factionName = factionEntry ? factionEntry->Name[loc] : "#Not found#";
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = handler->GetTrinityString(ReputationRankStrIndex[rank]);
std::ostringstream ss;

View File

@@ -510,7 +510,7 @@ public:
if (map->Instanceable())
{
handler->PSendSysMessage(LANG_INVALID_ZONE_MAP, areaId, areaEntry->AreaName->Str[handler->GetSessionDbcLocale()], map->GetId(), map->GetMapName());
handler->PSendSysMessage(LANG_INVALID_ZONE_MAP, areaId, areaEntry->AreaName[handler->GetSessionDbcLocale()], map->GetId(), map->GetMapName());
handler->SetSentErrorMessage(true);
return false;
}

View File

@@ -361,7 +361,7 @@ public:
{
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(area->ParentAreaID);
if (zone)
zoneName = zone->AreaName->Str[handler->GetSessionDbcLocale()];
zoneName = zone->AreaName[handler->GetSessionDbcLocale()];
}
}
else

View File

@@ -370,20 +370,20 @@ public:
!skillInfo->CanLink) // only prof with recipes have set
continue;
int locale = handler->GetSessionDbcLocale();
name = skillInfo->DisplayName->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
name = skillInfo->DisplayName[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, namePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = skillInfo->DisplayName->Str[locale];
name = skillInfo->DisplayName[locale];
if (name.empty())
continue;

View File

@@ -108,20 +108,20 @@ public:
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(i);
if (areaEntry)
{
int32 locale = handler->GetSessionDbcLocale();
std::string name = areaEntry->AreaName->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = areaEntry->AreaName[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = areaEntry->AreaName->Str[locale];
name = areaEntry->AreaName[locale];
if (name.empty())
continue;
@@ -320,20 +320,20 @@ public:
{
FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
int locale = handler->GetSessionDbcLocale();
std::string name = factionEntry->Name->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = factionEntry->Name[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = factionEntry->Name->Str[locale];
name = factionEntry->Name[locale];
if (name.empty())
continue;
@@ -468,20 +468,20 @@ public:
ItemSetEntry const* set = sItemSetStore.LookupEntry(id);
if (set)
{
int32 locale = handler->GetSessionDbcLocale();
std::string name = set->Name->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = set->Name[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = set->Name->Str[locale];
name = set->Name[locale];
if (name.empty())
continue;
@@ -757,20 +757,20 @@ public:
SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id);
if (skillInfo)
{
int locale = handler->GetSessionDbcLocale();
std::string name = skillInfo->DisplayName->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = skillInfo->DisplayName[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = skillInfo->DisplayName->Str[locale];
name = skillInfo->DisplayName[locale];
if (name.empty())
continue;
@@ -844,15 +844,15 @@ public:
{
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellName->ID, DIFFICULTY_NONE))
{
int locale = handler->GetSessionDbcLocale();
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = spellInfo->SpellName->Str[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
@@ -939,7 +939,7 @@ public:
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id, DIFFICULTY_NONE))
{
int locale = handler->GetSessionDbcLocale();
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = spellInfo->SpellName->Str[locale];
if (name.empty())
{
@@ -1014,12 +1014,12 @@ public:
bool found = false;
uint32 count = 0;
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
int32 locale = handler->GetSessionDbcLocale();
LocaleConstant locale = handler->GetSessionDbcLocale();
// Search in TaxiNodes.dbc
for (TaxiNodesEntry const* nodeEntry : sTaxiNodesStore)
{
std::string name = nodeEntry->Name->Str[locale];
std::string name = nodeEntry->Name[locale];
if (name.empty())
continue;
@@ -1141,21 +1141,21 @@ public:
if (target && target->getGender() != gender)
continue;
int32 locale = handler->GetSessionDbcLocale();
std::string name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart))
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[locale];
name = (gender == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[locale];
if (name.empty())
continue;
@@ -1218,20 +1218,20 @@ public:
{
if (MapEntry const* mapInfo = sMapStore.LookupEntry(id))
{
int32 locale = handler->GetSessionDbcLocale();
std::string name = mapInfo->MapName->Str[locale];
LocaleConstant locale = handler->GetSessionDbcLocale();
std::string name = mapInfo->MapName[locale];
if (name.empty())
continue;
if (!Utf8FitTo(name, wNamePart) && handler->GetSession())
{
locale = 0;
for (; locale < TOTAL_LOCALES; ++locale)
locale = LOCALE_enUS;
for (; locale < TOTAL_LOCALES; locale = LocaleConstant(locale + 1))
{
if (locale == handler->GetSessionDbcLocale())
continue;
name = mapInfo->MapName->Str[locale];
name = mapInfo->MapName[locale];
if (name.empty())
continue;

View File

@@ -83,7 +83,7 @@ public:
if (!channelEntry)
continue;
if (strstr(channelEntry->Name->Str[handler->GetSessionDbcLocale()], channelStr))
if (strstr(channelEntry->Name[handler->GetSessionDbcLocale()], channelStr))
{
channelId = i;
break;
@@ -97,7 +97,7 @@ public:
if (!entry)
continue;
if (strstr(entry->AreaName->Str[handler->GetSessionDbcLocale()], channelStr))
if (strstr(entry->AreaName[handler->GetSessionDbcLocale()], channelStr))
{
zoneEntry = entry;
break;

View File

@@ -285,9 +285,9 @@ public:
char const* unknown = handler->GetTrinityString(LANG_UNKNOWN);
handler->PSendSysMessage(LANG_MAP_POSITION,
mapId, (mapEntry ? mapEntry->MapName->Str[handler->GetSessionDbcLocale()] : unknown),
zoneId, (zoneEntry ? zoneEntry->AreaName->Str[handler->GetSessionDbcLocale()] : unknown),
areaId, (areaEntry ? areaEntry->AreaName->Str[handler->GetSessionDbcLocale()] : unknown),
mapId, (mapEntry ? mapEntry->MapName[handler->GetSessionDbcLocale()] : unknown),
zoneId, (zoneEntry ? zoneEntry->AreaName[handler->GetSessionDbcLocale()] : unknown),
areaId, (areaEntry ? areaEntry->AreaName[handler->GetSessionDbcLocale()] : unknown),
object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), object->GetOrientation());
if (Transport* transport = object->GetTransport())
handler->PSendSysMessage(LANG_TRANSPORT_POSITION,
@@ -1269,8 +1269,8 @@ public:
std::string itemName = itemNameStr+1;
auto itr = std::find_if(sItemSparseStore.begin(), sItemSparseStore.end(), [&itemName](ItemSparseEntry const* sparse)
{
for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
if (itemName == sparse->Display->Str[i])
for (LocaleConstant i = LOCALE_enUS; i < TOTAL_LOCALES; i = LocaleConstant(i + 1))
if (itemName == sparse->Display[i])
return true;
return false;
});
@@ -1549,7 +1549,7 @@ public:
// add the skill to the player's book with step 1 (which is the first rank, in most cases something
// like 'Apprentice <skill>'.
target->SetSkill(skill, targetHasSkill ? target->GetSkillStep(skill) : 1, level, max);
handler->PSendSysMessage(LANG_SET_SKILL, skill, skillLine->DisplayName->Str[handler->GetSessionDbcLocale()], handler->GetNameLink(target).c_str(), level, max);
handler->PSendSysMessage(LANG_SET_SKILL, skill, skillLine->DisplayName[handler->GetSessionDbcLocale()], handler->GetNameLink(target).c_str(), level, max);
return true;
}
@@ -1887,15 +1887,15 @@ public:
AreaTableEntry const* area = sAreaTableStore.LookupEntry(areaId);
if (area)
{
areaName = area->AreaName->Str[handler->GetSessionDbcLocale()];
areaName = area->AreaName[handler->GetSessionDbcLocale()];
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(area->ParentAreaID);
if (zone)
zoneName = zone->AreaName->Str[handler->GetSessionDbcLocale()];
zoneName = zone->AreaName[handler->GetSessionDbcLocale()];
}
if (target)
handler->PSendSysMessage(LANG_PINFO_CHR_MAP, map->MapName->Str[handler->GetSessionDbcLocale()],
handler->PSendSysMessage(LANG_PINFO_CHR_MAP, map->MapName[handler->GetSessionDbcLocale()],
(!zoneName.empty() ? zoneName.c_str() : handler->GetTrinityString(LANG_UNKNOWN)),
(!areaName.empty() ? areaName.c_str() : handler->GetTrinityString(LANG_UNKNOWN)));

View File

@@ -742,14 +742,14 @@ public:
if (factionEntry->ReputationIndex < 0)
{
handler->PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR, factionEntry->Name->Str[handler->GetSessionDbcLocale()], factionId);
handler->PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR, factionEntry->Name[handler->GetSessionDbcLocale()], factionId);
handler->SetSentErrorMessage(true);
return false;
}
target->GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false);
target->GetReputationMgr().SendState(target->GetReputationMgr().GetState(factionEntry));
handler->PSendSysMessage(LANG_COMMAND_MODIFY_REP, factionEntry->Name->Str[handler->GetSessionDbcLocale()], factionId,
handler->PSendSysMessage(LANG_COMMAND_MODIFY_REP, factionEntry->Name[handler->GetSessionDbcLocale()], factionId,
handler->GetNameLink(target).c_str(), target->GetReputationMgr().GetReputation(factionEntry));
return true;
}

View File

@@ -96,7 +96,7 @@ public:
target->SetChosenTitle(titleInfo->MaskID);
handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id,
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[handler->GetSessionDbcLocale()],
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
tNameLink.c_str());
return true;
}
@@ -139,7 +139,7 @@ public:
std::string tNameLink = handler->GetNameLink(target);
std::string titleNameStr = Trinity::StringFormat(
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[handler->GetSessionDbcLocale()],
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
target->GetName().c_str()
);
@@ -189,7 +189,7 @@ public:
std::string tNameLink = handler->GetNameLink(target);
std::string titleNameStr = Trinity::StringFormat(
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)->Str[handler->GetSessionDbcLocale()],
(target->getGender() == GENDER_MALE ? titleInfo->Name : titleInfo->Name1)[handler->GetSessionDbcLocale()],
target->GetName().c_str()
);