Core/Misc: Fixed thread-unsafe access to list of objects that should be spawned in a cell

This commit is contained in:
Shauren authored and Ovahlord committed 2023-10-18 22:00:01 +02:00
1 parent 7b4371e25d
commit 2e2a928204
4 files changed
+35 -27

No files matched your search

@@ -549,22 +549,23 @@ void Transport::UpdatePosition(float x, float y, float z, float o)
void Transport::LoadStaticPassengers()
{
if (uint32 mapId = GetGOInfo()->moTransport.SpawnMap)
{
CellObjectGuidsMap const& cells = sObjectMgr->GetMapObjectGuids(mapId, GetMap()->GetSpawnMode());
CellGuidSet::const_iterator guidEnd;
for (CellObjectGuidsMap::const_iterator cellItr = cells.begin(); cellItr != cells.end(); ++cellItr)
{
// Creatures on transport
guidEnd = cellItr->second.creatures.end();
for (CellGuidSet::const_iterator guidItr = cellItr->second.creatures.begin(); guidItr != guidEnd; ++guidItr)
CreateNPCPassenger(*guidItr, sObjectMgr->GetCreatureData(*guidItr));
uint32 mapId = GetGOInfo()->moTransport.SpawnMap;
if (!mapId)
return;
// GameObjects on transport
guidEnd = cellItr->second.gameobjects.end();
for (CellGuidSet::const_iterator guidItr = cellItr->second.gameobjects.begin(); guidItr != guidEnd; ++guidItr)
CreateGOPassenger(*guidItr, sObjectMgr->GetGameObjectData(*guidItr));
}
CellObjectGuidsMap const* cells = sObjectMgr->GetMapObjectGuids(mapId, GetMap()->GetDifficulty());
if (!cells)
return;
for (auto const& [cellId, guids] : *cells)
{
// GameObjects on transport
for (ObjectGuid::LowType spawnId : guids.gameobjects)
CreateGOPassenger(spawnId, sObjectMgr->GetGameObjectData(spawnId));
// Creatures on transport
for (ObjectGuid::LowType spawnId : guids.creatures)
CreateNPCPassenger(spawnId, sObjectMgr->GetCreatureData(spawnId));
}
}
+13
View File
@@ -2263,6 +2263,19 @@ void ObjectMgr::LoadCreatures()
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " creatures in %u ms", _creatureDataStore.size(), GetMSTimeDiffToNow(oldMSTime));
}
CellObjectGuids const* ObjectMgr::GetCellObjectGuids(uint32 mapid, uint8 spawnMode, uint32 cell_id)
{
if (CellObjectGuidsMap const* mapGuids = Trinity::Containers::MapGetValuePtr(_mapObjectGuidsStore, MAKE_PAIR32(mapid, spawnMode)))
return Trinity::Containers::MapGetValuePtr(*mapGuids, cell_id);
return nullptr;
}
CellObjectGuidsMap const* ObjectMgr::GetMapObjectGuids(uint32 mapid, uint8 spawnMode)
{
return Trinity::Containers::MapGetValuePtr(_mapObjectGuidsStore, MAKE_PAIR32(mapid, spawnMode));
}
void ObjectMgr::AddCreatureToGrid(ObjectGuid::LowType guid, CreatureData const* data)
{
uint8 mask = data->spawnMask;
+2 -8
View File
@@ -1325,15 +1325,9 @@ class TC_GAME_API ObjectMgr
return nullptr;
}
CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
{
return _mapObjectGuidsStore[MAKE_PAIR32(mapid, spawnMode)][cell_id];
}
CellObjectGuids const* GetCellObjectGuids(uint32 mapid, uint8 spawnMode, uint32 cell_id);
CellObjectGuidsMap const& GetMapObjectGuids(uint16 mapid, uint8 spawnMode)
{
return _mapObjectGuidsStore[MAKE_PAIR32(mapid, spawnMode)];
}
CellObjectGuidsMap const* GetMapObjectGuids(uint32 mapid, uint8 spawnMode);
/**
* Gets temp summon data for all creatures of specified group.
+4 -4
View File
@@ -122,15 +122,15 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord &cell, GridRefManager<T>
void ObjectGridLoader::Visit(GameObjectMapType &m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId());
LoadHelper(cell_guids.gameobjects, cellCoord, m, i_gameObjects, i_map);
if (CellObjectGuids const* cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId()))
LoadHelper(cell_guids->gameobjects, cellCoord, m, i_gameObjects, i_map);
}
void ObjectGridLoader::Visit(CreatureMapType &m)
{
CellCoord cellCoord = i_cell.GetCellCoord();
CellObjectGuids const& cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId());
LoadHelper(cell_guids.creatures, cellCoord, m, i_creatures, i_map);
if (CellObjectGuids const* cell_guids = sObjectMgr->GetCellObjectGuids(i_map->GetId(), i_map->GetSpawnMode(), cellCoord.GetId()))
LoadHelper(cell_guids->creatures, cellCoord, m, i_creatures, i_map);
}
void ObjectWorldLoader::Visit(CorpseMapType& /*m*/)