Skip to content

Commit da1ac5a

Browse files
committed
Core/DataStores: Delay building all DB2Manager containers after loading hotfix data to ignore rows marked as deleted by hotfixes
1 parent debbed0 commit da1ac5a

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/server/game/DataStores/DB2Stores.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Timer.h"
3030
#include "Util.h"
3131
#include "World.h"
32+
#include <algorithm>
3233
#include <array>
3334
#include <bitset>
3435
#include <boost/filesystem/directory.hpp>
@@ -1030,6 +1031,15 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
10301031
return 0;
10311032
}
10321033

1034+
TC_LOG_INFO("server.loading", ">> Initialized {} DB2 data stores in {} ms", _stores.size(), GetMSTimeDiffToNow(oldMSTime));
1035+
1036+
return availableDb2Locales.to_ulong();
1037+
}
1038+
1039+
void DB2Manager::IndexLoadedStores()
1040+
{
1041+
uint32 oldMSTime = getMSTime();
1042+
10331043
for (AreaGroupMemberEntry const* areaGroupMember : sAreaGroupMemberStore)
10341044
_areaGroupMembers[areaGroupMember->AreaGroupID].push_back(areaGroupMember->AreaID);
10351045

@@ -1060,10 +1070,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
10601070
for (AzeriteItemMilestonePowerEntry const* azeriteItemMilestonePower : sAzeriteItemMilestonePowerStore)
10611071
_azeriteItemMilestonePowers.push_back(azeriteItemMilestonePower);
10621072

1063-
std::sort(_azeriteItemMilestonePowers.begin(), _azeriteItemMilestonePowers.end(), [](AzeriteItemMilestonePowerEntry const* a1, AzeriteItemMilestonePowerEntry const* a2)
1064-
{
1065-
return a1->RequiredLevel < a2->RequiredLevel;
1066-
});
1073+
std::ranges::sort(_azeriteItemMilestonePowers, {}, &AzeriteItemMilestonePowerEntry::RequiredLevel);
10671074

10681075
{
10691076
uint32 azeriteEssenceSlot = 0;
@@ -1120,8 +1127,8 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
11201127
for (ChrClassesXPowerTypesEntry const* power : sChrClassesXPowerTypesStore)
11211128
powers.insert(power);
11221129

1123-
for (std::size_t i = 0; i < _powersByClass.size(); ++i)
1124-
_powersByClass[i].fill(MAX_POWERS);
1130+
for (std::array<uint32, MAX_POWERS>& powersForClass : _powersByClass)
1131+
powersForClass.fill(MAX_POWERS);
11251132

11261133
for (ChrClassesXPowerTypesEntry const* power : powers)
11271134
{
@@ -1271,10 +1278,10 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
12711278

12721279
for (auto& [curveId, curvePoints] : unsortedPoints)
12731280
{
1274-
std::sort(curvePoints.begin(), curvePoints.end(), [](CurvePointEntry const* point1, CurvePointEntry const* point2) { return point1->OrderIndex < point2->OrderIndex; });
1281+
std::ranges::sort(curvePoints, {}, &CurvePointEntry::OrderIndex);
12751282
std::vector<DBCPosition2D>& points = _curvePoints[curveId];
12761283
points.resize(curvePoints.size());
1277-
std::transform(curvePoints.begin(), curvePoints.end(), points.begin(), [](CurvePointEntry const* point) { return point->Pos; });
1284+
std::ranges::transform(curvePoints, points.begin(), &CurvePointEntry::Pos);
12781285
}
12791286
}
12801287

@@ -1355,10 +1362,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
13551362
for (MapDifficultyXConditionEntry const* mapDifficultyCondition : sMapDifficultyXConditionStore)
13561363
mapDifficultyConditions.push_back(mapDifficultyCondition);
13571364

1358-
std::sort(mapDifficultyConditions.begin(), mapDifficultyConditions.end(), [](MapDifficultyXConditionEntry const* left, MapDifficultyXConditionEntry const* right)
1359-
{
1360-
return left->OrderIndex < right->OrderIndex;
1361-
});
1365+
std::ranges::sort(mapDifficultyConditions, {}, &MapDifficultyXConditionEntry::OrderIndex);
13621366

13631367
for (MapDifficultyXConditionEntry const* mapDifficultyCondition : mapDifficultyConditions)
13641368
if (PlayerConditionEntry const* playerCondition = sPlayerConditionStore.LookupEntry(mapDifficultyCondition->PlayerConditionID))
@@ -1549,8 +1553,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
15491553
std::vector<uint32> pathLength;
15501554
pathLength.resize(pathCount); // 0 and some other indexes not used
15511555
for (TaxiPathNodeEntry const* entry : sTaxiPathNodeStore)
1552-
if (pathLength[entry->PathID] < entry->NodeIndex + 1u)
1553-
pathLength[entry->PathID] = entry->NodeIndex + 1u;
1556+
pathLength[entry->PathID] = std::max(pathLength[entry->PathID], entry->NodeIndex + 1u);
15541557

15551558
// Set path length
15561559
sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used
@@ -1709,9 +1712,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
17091712
for (PVPStatEntry const* pvpStat : sPVPStatStore)
17101713
_pvpStatIdsByMap[pvpStat->MapID].insert(pvpStat->ID);
17111714

1712-
TC_LOG_INFO("server.loading", ">> Initialized {} DB2 data stores in {} ms", _stores.size(), GetMSTimeDiffToNow(oldMSTime));
1713-
1714-
return availableDb2Locales.to_ulong();
1715+
TC_LOG_INFO("server.loading", ">> Indexed DB2 data stores in {} ms", GetMSTimeDiffToNow(oldMSTime));
17151716
}
17161717

17171718
DB2StorageBase const* DB2Manager::GetStorage(uint32 type) const

src/server/game/DataStores/DB2Stores.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class TC_GAME_API DB2Manager
421421
static DB2Manager& Instance();
422422

423423
uint32 LoadStores(std::string const& dataPath, LocaleConstant defaultLocale);
424+
void IndexLoadedStores();
424425
DB2StorageBase const* GetStorage(uint32 type) const;
425426

426427
void LoadHotfixData(uint32 localeMask);

src/server/game/World/World.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,13 @@ bool World::SetInitialWorldSettings()
17851785

17861786
LoginDatabase.PExecute("UPDATE realmlist SET icon = {}, timezone = {} WHERE id = '{}'", server_type, realm_zone, sRealmList->GetCurrentRealmId().Realm); // One-time query
17871787

1788+
TC_LOG_INFO("server.loading", "Loading GameObject models...");
1789+
if (!LoadGameObjectModelList(m_dataPath))
1790+
{
1791+
TC_LOG_FATAL("server.loading", "Unable to load gameobject models (part of vmaps), objects using WMO models will crash the client - server shutting down!");
1792+
return false;
1793+
}
1794+
17881795
TC_LOG_INFO("server.loading", "Initialize data stores...");
17891796
///- Load DB2s
17901797
m_availableDbcLocaleMask = sDB2Manager.LoadStores(m_dataPath, m_defaultDbcLocale);
@@ -1794,19 +1801,14 @@ bool World::SetInitialWorldSettings()
17941801
return false;
17951802
}
17961803

1797-
TC_LOG_INFO("server.loading", "Loading GameObject models...");
1798-
if (!LoadGameObjectModelList(m_dataPath))
1799-
{
1800-
TC_LOG_FATAL("server.loading", "Unable to load gameobject models (part of vmaps), objects using WMO models will crash the client - server shutting down!");
1801-
return false;
1802-
}
1803-
18041804
TC_LOG_INFO("misc", "Loading hotfix blobs...");
18051805
sDB2Manager.LoadHotfixBlob(m_availableDbcLocaleMask);
18061806
TC_LOG_INFO("misc", "Loading hotfix info...");
18071807
sDB2Manager.LoadHotfixData(m_availableDbcLocaleMask);
18081808
TC_LOG_INFO("misc", "Loading hotfix optional data...");
18091809
sDB2Manager.LoadHotfixOptionalData(m_availableDbcLocaleMask);
1810+
TC_LOG_INFO("misc", "Indexing loaded data stores...");
1811+
sDB2Manager.IndexLoadedStores();
18101812
///- Load M2 fly by cameras
18111813
LoadM2Cameras(m_dataPath);
18121814
///- Load GameTables

0 commit comments

Comments
 (0)