feat(Core/Maps): Multithread startup map preloading (#22580)

This commit is contained in:
Takenbacon
2025-07-29 05:10:46 -07:00
committed by GitHub
parent f31643c72c
commit 57dacae38b
3 changed files with 42 additions and 5 deletions

View File

@@ -18,7 +18,9 @@
#include "MapUpdater.h"
#include "DatabaseEnv.h"
#include "LFGMgr.h"
#include "Log.h"
#include "Map.h"
#include "MapMgr.h"
#include "Metric.h"
class UpdateRequest
@@ -52,6 +54,27 @@ private:
uint32 s_diff;
};
class MapPreloadRequest : public UpdateRequest
{
public:
MapPreloadRequest(uint32 mapId, MapUpdater& updater)
: _mapId(mapId), _updater(updater)
{
}
void call() override
{
Map* map = sMapMgr->CreateBaseMap(_mapId);
LOG_INFO("server.loading", ">> Loading All Grids For Map {} ({})", map->GetId(), map->GetMapName());
map->LoadAllGrids();
_updater.update_finished();
}
private:
uint32 _mapId;
MapUpdater& _updater;
};
class LFGUpdateRequest : public UpdateRequest
{
public:
@@ -120,6 +143,11 @@ void MapUpdater::schedule_update(Map& map, uint32 diff, uint32 s_diff)
schedule_task(new MapUpdateRequest(map, *this, diff, s_diff));
}
void MapUpdater::schedule_map_preload(uint32 mapid)
{
schedule_task(new MapPreloadRequest(mapid, *this));
}
void MapUpdater::schedule_lfg_update(uint32 diff)
{
schedule_task(new LFGUpdateRequest(*this, diff));

View File

@@ -35,6 +35,7 @@ public:
void schedule_task(UpdateRequest* request);
void schedule_update(Map& map, uint32 diff, uint32 s_diff);
void schedule_map_preload(uint32 mapid);
void schedule_lfg_update(uint32 diff);
void wait();
void activate(std::size_t num_threads);

View File

@@ -1010,15 +1010,23 @@ void World::SetInitialWorldSettings()
if (mapEntry && !mapEntry->Instanceable())
{
Map* map = sMapMgr->CreateBaseMap(mapEntry->MapID);
if (map)
if (sMapMgr->GetMapUpdater()->activated())
sMapMgr->GetMapUpdater()->schedule_map_preload(mapEntry->MapID);
else
{
LOG_INFO("server.loading", ">> Loading All Grids For Map {}", map->GetId());
map->LoadAllGrids();
Map* map = sMapMgr->CreateBaseMap(mapEntry->MapID);
if (map)
{
LOG_INFO("server.loading", ">> Loading All Grids For Map {}", map->GetId());
map->LoadAllGrids();
}
}
}
}
if (sMapMgr->GetMapUpdater()->activated())
sMapMgr->GetMapUpdater()->wait();
}
uint32 startupDuration = GetMSTimeDiffToNow(startupBegin);