Merge branch 'master' into Playerbot
This commit is contained in:
+12
-122
@@ -175,81 +175,6 @@ void Map::AddToGrid(Corpse* obj, Cell const& cell)
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::SwitchGridContainers(T* /*obj*/, bool /*on*/)
|
||||
{
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::SwitchGridContainers(Creature* obj, bool on)
|
||||
{
|
||||
ASSERT(!obj->IsPermanentWorldObject());
|
||||
CellCoord p = Acore::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
LOG_ERROR("maps", "Map::SwitchGridContainers: Object {} has invalid coordinates X:{} Y:{} grid cell [{}:{}]",
|
||||
obj->GetGUID().ToString(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
|
||||
return;
|
||||
}
|
||||
|
||||
Cell cell(p);
|
||||
if (!IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y)))
|
||||
return;
|
||||
|
||||
LOG_DEBUG("maps", "Switch object {} from grid[{}, {}] {}", obj->GetGUID().ToString(), cell.GridX(), cell.GridY(), on);
|
||||
MapGridType* grid = GetMapGrid(cell.GridX(), cell.GridY());
|
||||
ASSERT(grid);
|
||||
|
||||
obj->RemoveFromGrid(); //This step is not really necessary but we want to do ASSERT in remove/add
|
||||
|
||||
if (on)
|
||||
{
|
||||
grid->AddWorldObject(cell.CellX(), cell.CellY(), obj);
|
||||
AddWorldObject(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
grid->AddGridObject(cell.CellX(), cell.CellY(), obj);
|
||||
RemoveWorldObject(obj);
|
||||
}
|
||||
|
||||
obj->m_isTempWorldObject = on;
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::SwitchGridContainers(GameObject* obj, bool on)
|
||||
{
|
||||
ASSERT(!obj->IsPermanentWorldObject());
|
||||
CellCoord p = Acore::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
LOG_ERROR("maps", "Map::SwitchGridContainers: Object {} has invalid coordinates X:{} Y:{} grid cell [{}:{}]",
|
||||
obj->GetGUID().ToString(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord);
|
||||
return;
|
||||
}
|
||||
|
||||
Cell cell(p);
|
||||
if (!IsGridLoaded(GridCoord(cell.data.Part.grid_x, cell.data.Part.grid_y)))
|
||||
return;
|
||||
|
||||
//LOG_DEBUG(LOG_FILTER_MAPS, "Switch object {} from grid[{}, {}] {}", obj->GetGUID().ToString(), cell.data.Part.grid_x, cell.data.Part.grid_y, on);
|
||||
MapGridType* grid = GetMapGrid(cell.GridX(), cell.GridY());
|
||||
ASSERT(grid);
|
||||
|
||||
obj->RemoveFromGrid(); //This step is not really necessary but we want to do ASSERT in remove/add
|
||||
|
||||
if (on)
|
||||
{
|
||||
grid->AddWorldObject(cell.CellX(), cell.CellY(), obj);
|
||||
AddWorldObject(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
grid->AddGridObject(cell.CellX(), cell.CellY(), obj);
|
||||
RemoveWorldObject(obj);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::DeleteFromWorld(T* obj)
|
||||
{
|
||||
@@ -1108,7 +1033,7 @@ void Map::UnloadAll()
|
||||
|
||||
_transports.clear();
|
||||
|
||||
for (auto& cellCorpsePair : _corpsesByCell)
|
||||
for (auto& cellCorpsePair : _corpsesByGrid)
|
||||
{
|
||||
for (Corpse* corpse : cellCorpsePair.second)
|
||||
{
|
||||
@@ -1118,7 +1043,7 @@ void Map::UnloadAll()
|
||||
}
|
||||
}
|
||||
|
||||
_corpsesByCell.clear();
|
||||
_corpsesByGrid.clear();
|
||||
_corpsesByPlayer.clear();
|
||||
_corpseBones.clear();
|
||||
}
|
||||
@@ -1849,49 +1774,8 @@ void Map::AddObjectToRemoveList(WorldObject* obj)
|
||||
//LOG_DEBUG("maps", "Object ({}) added to removing list.", obj->GetGUID().ToString());
|
||||
}
|
||||
|
||||
void Map::AddObjectToSwitchList(WorldObject* obj, bool on)
|
||||
{
|
||||
ASSERT(obj->GetMapId() == GetId() && obj->GetInstanceId() == GetInstanceId());
|
||||
// i_objectsToSwitch is iterated only in Map::RemoveAllObjectsInRemoveList() and it uses
|
||||
// the contained objects only if IsCreature() , so we can return in all other cases
|
||||
if (!obj->IsCreature() && !obj->IsGameObject())
|
||||
return;
|
||||
|
||||
std::map<WorldObject*, bool>::iterator itr = i_objectsToSwitch.find(obj);
|
||||
if (itr == i_objectsToSwitch.end())
|
||||
i_objectsToSwitch.insert(itr, std::make_pair(obj, on));
|
||||
else if (itr->second != on)
|
||||
i_objectsToSwitch.erase(itr);
|
||||
else
|
||||
ABORT();
|
||||
}
|
||||
|
||||
void Map::RemoveAllObjectsInRemoveList()
|
||||
{
|
||||
while (!i_objectsToSwitch.empty())
|
||||
{
|
||||
std::map<WorldObject*, bool>::iterator itr = i_objectsToSwitch.begin();
|
||||
WorldObject* obj = itr->first;
|
||||
bool on = itr->second;
|
||||
i_objectsToSwitch.erase(itr);
|
||||
|
||||
if (!obj->IsPermanentWorldObject())
|
||||
{
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
SwitchGridContainers<Creature>(obj->ToCreature(), on);
|
||||
break;
|
||||
case TYPEID_GAMEOBJECT:
|
||||
SwitchGridContainers<GameObject>(obj->ToGameObject(), on);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//LOG_DEBUG("maps", "Object remover 1 check.");
|
||||
while (!i_objectsToRemove.empty())
|
||||
{
|
||||
std::unordered_set<WorldObject*>::iterator itr = i_objectsToRemove.begin();
|
||||
@@ -1929,8 +1813,6 @@ void Map::RemoveAllObjectsInRemoveList()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//LOG_DEBUG("maps", "Object remover 2 check.");
|
||||
}
|
||||
|
||||
uint32 Map::GetPlayersCountExceptGMs() const
|
||||
@@ -1972,6 +1854,12 @@ void Map::AddToActive(GameObject* d)
|
||||
AddToActiveHelper(d);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Map::AddToActive(Corpse* /*c*/)
|
||||
{
|
||||
// do nothing for corpses
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::RemoveFromActive(T* obj)
|
||||
{
|
||||
@@ -2791,7 +2679,8 @@ void Map::AddCorpse(Corpse* corpse)
|
||||
{
|
||||
corpse->SetMap(this);
|
||||
|
||||
_corpsesByCell[corpse->GetCellCoord().GetId()].insert(corpse);
|
||||
GridCoord const gridCoord = Acore::ComputeGridCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
_corpsesByGrid[gridCoord.GetId()].insert(corpse);
|
||||
if (corpse->GetType() != CORPSE_BONES)
|
||||
_corpsesByPlayer[corpse->GetOwnerGUID()] = corpse;
|
||||
else
|
||||
@@ -2801,6 +2690,7 @@ void Map::AddCorpse(Corpse* corpse)
|
||||
void Map::RemoveCorpse(Corpse* corpse)
|
||||
{
|
||||
ASSERT(corpse);
|
||||
GridCoord const gridCoord = Acore::ComputeGridCoord(corpse->GetPositionX(), corpse->GetPositionY());
|
||||
|
||||
corpse->DestroyForNearbyPlayers();
|
||||
if (corpse->IsInGrid())
|
||||
@@ -2811,7 +2701,7 @@ void Map::RemoveCorpse(Corpse* corpse)
|
||||
corpse->ResetMap();
|
||||
}
|
||||
|
||||
_corpsesByCell[corpse->GetCellCoord().GetId()].erase(corpse);
|
||||
_corpsesByGrid[gridCoord.GetId()].erase(corpse);
|
||||
if (corpse->GetType() != CORPSE_BONES)
|
||||
_corpsesByPlayer.erase(corpse->GetOwnerGUID());
|
||||
else
|
||||
|
||||
@@ -306,7 +306,6 @@ public:
|
||||
}
|
||||
|
||||
void AddObjectToRemoveList(WorldObject* obj);
|
||||
void AddObjectToSwitchList(WorldObject* obj, bool on);
|
||||
virtual void DelayedUpdate(const uint32 diff);
|
||||
|
||||
void resetMarkedCells() { marked_cells.reset(); }
|
||||
@@ -336,7 +335,6 @@ public:
|
||||
template<class T>
|
||||
void RemoveFromActive(T* obj);
|
||||
|
||||
template<class T> void SwitchGridContainers(T* obj, bool on);
|
||||
CreatureGroupHolderType CreatureGroupHolder;
|
||||
|
||||
void UpdateIteratorBack(Player* player);
|
||||
@@ -361,10 +359,10 @@ public:
|
||||
typedef std::unordered_multimap<ObjectGuid::LowType, GameObject*> GameObjectBySpawnIdContainer;
|
||||
GameObjectBySpawnIdContainer& GetGameObjectBySpawnIdStore() { return _gameobjectBySpawnIdStore; }
|
||||
|
||||
[[nodiscard]] std::unordered_set<Corpse*> const* GetCorpsesInCell(uint32 cellId) const
|
||||
[[nodiscard]] std::unordered_set<Corpse*> const* GetCorpsesInGrid(uint32 gridId) const
|
||||
{
|
||||
auto itr = _corpsesByCell.find(cellId);
|
||||
if (itr != _corpsesByCell.end())
|
||||
auto itr = _corpsesByGrid.find(gridId);
|
||||
if (itr != _corpsesByGrid.end())
|
||||
return &itr->second;
|
||||
|
||||
return nullptr;
|
||||
@@ -577,7 +575,6 @@ private:
|
||||
|
||||
bool i_scriptLock;
|
||||
std::unordered_set<WorldObject*> i_objectsToRemove;
|
||||
std::map<WorldObject*, bool> i_objectsToSwitch;
|
||||
std::unordered_set<WorldObject*> i_worldObjects;
|
||||
|
||||
typedef std::multimap<time_t, ScriptAction> ScriptScheduleMap;
|
||||
@@ -634,7 +631,7 @@ private:
|
||||
MapStoredObjectTypesContainer _objectsStore;
|
||||
CreatureBySpawnIdContainer _creatureBySpawnIdStore;
|
||||
GameObjectBySpawnIdContainer _gameobjectBySpawnIdStore;
|
||||
std::unordered_map<uint32/*cellId*/, std::unordered_set<Corpse*>> _corpsesByCell;
|
||||
std::unordered_map<uint32/*gridId*/, std::unordered_set<Corpse*>> _corpsesByGrid;
|
||||
std::unordered_map<ObjectGuid, Corpse*> _corpsesByPlayer;
|
||||
std::unordered_set<Corpse*> _corpseBones;
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ Map::EnterState MapMgr::PlayerCannotEnter(uint32 mapid, Player* player, bool log
|
||||
{
|
||||
uint32 destInstId = sInstanceSaveMgr->PlayerGetDestinationInstanceId(player, mapid, targetDifficulty);
|
||||
if (destInstId)
|
||||
if (Map* boundMap = sMapMgr->FindMap(mapid, destInstId))
|
||||
if (Map* boundMap = FindMap(mapid, destInstId))
|
||||
if (Map::EnterState denyReason = boundMap->CannotEnter(player, loginCheck))
|
||||
return denyReason;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user