Update grid system. Try to fix some crashes and transport passengers (now they are despawned after a while).
This commit is contained in:
@@ -59,7 +59,7 @@ Map::~Map()
|
||||
while (!i_worldObjects.empty())
|
||||
{
|
||||
WorldObject* obj = *i_worldObjects.begin();
|
||||
ASSERT(obj->m_isWorldObject);
|
||||
ASSERT(obj->IsWorldObject());
|
||||
//ASSERT(obj->GetTypeId() == TYPEID_CORPSE);
|
||||
obj->RemoveFromWorld();
|
||||
obj->ResetMap();
|
||||
@@ -238,7 +238,7 @@ template<class T>
|
||||
void Map::AddToGrid(T* obj, Cell const& cell)
|
||||
{
|
||||
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
|
||||
if (obj->m_isWorldObject)
|
||||
if (obj->IsWorldObject())
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj);
|
||||
else
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj);
|
||||
@@ -248,7 +248,7 @@ template<>
|
||||
void Map::AddToGrid(Creature* obj, Cell const& cell)
|
||||
{
|
||||
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
|
||||
if (obj->m_isWorldObject)
|
||||
if (obj->IsWorldObject())
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).AddWorldObject(obj);
|
||||
else
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj);
|
||||
@@ -256,9 +256,9 @@ void Map::AddToGrid(Creature* obj, Cell const& cell)
|
||||
obj->SetCurrentCell(cell);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Map::SwitchGridContainers(T* obj, bool on)
|
||||
void Map::SwitchGridContainers(Creature* obj, bool on)
|
||||
{
|
||||
ASSERT(!obj->IsPermanentWorldObject());
|
||||
CellCoord p = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
@@ -278,15 +278,18 @@ void Map::SwitchGridContainers(T* obj, bool on)
|
||||
|
||||
obj->RemoveFromGrid(); //This step is not really necessary but we want to do ASSERT in remove/add
|
||||
if (on)
|
||||
grid.AddWorldObject<T>(obj);
|
||||
{
|
||||
grid.AddWorldObject(obj);
|
||||
AddWorldObject(obj);
|
||||
}
|
||||
else
|
||||
grid.AddGridObject<T>(obj);
|
||||
obj->m_isWorldObject = on;
|
||||
{
|
||||
grid.AddGridObject(obj);
|
||||
RemoveWorldObject(obj);
|
||||
}
|
||||
obj->m_isTempWorldObject = on;
|
||||
}
|
||||
|
||||
template void Map::SwitchGridContainers(Creature*, bool);
|
||||
//template void Map::SwitchGridContainers(DynamicObject*, bool);
|
||||
|
||||
template<class T>
|
||||
void Map::DeleteFromWorld(T* obj)
|
||||
{
|
||||
@@ -909,8 +912,15 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll)
|
||||
const uint32 y = ngrid.getY();
|
||||
|
||||
{
|
||||
if (!unloadAll && ActiveObjectsNearGrid(ngrid))
|
||||
return false;
|
||||
if (!unloadAll)
|
||||
{
|
||||
//pets, possessed creatures (must be active), transport passengers
|
||||
if (ngrid.GetWorldObjectCountInNGrid<Creature>())
|
||||
return false;
|
||||
|
||||
if (ActiveObjectsNearGrid(ngrid))
|
||||
return false;
|
||||
}
|
||||
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Unloading grid[%u, %u] for map %u", x, y, GetId());
|
||||
|
||||
@@ -1975,15 +1985,8 @@ void Map::RemoveAllObjectsInRemoveList()
|
||||
bool on = itr->second;
|
||||
i_objectsToSwitch.erase(itr);
|
||||
|
||||
switch (obj->GetTypeId())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
if (!obj->ToCreature()->isPet())
|
||||
SwitchGridContainers(obj->ToCreature(), on);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (obj->GetTypeId() == TYPEID_UNIT && !obj->IsPermanentWorldObject())
|
||||
SwitchGridContainers(obj->ToCreature(), on);
|
||||
}
|
||||
|
||||
//sLog->outDebug(LOG_FILTER_MAPS, "Object remover 1 check.");
|
||||
|
||||
@@ -405,7 +405,7 @@ class Map : public GridRefManager<NGridType>
|
||||
|
||||
void RemoveFromActive(Creature* obj);
|
||||
|
||||
template<class T> void SwitchGridContainers(T* obj, bool active);
|
||||
void SwitchGridContainers(Creature* creature, bool toWorldContainer);
|
||||
template<class NOTIFIER> void VisitAll(const float &x, const float &y, float radius, NOTIFIER ¬ifier);
|
||||
template<class NOTIFIER> void VisitFirstFound(const float &x, const float &y, float radius, NOTIFIER ¬ifier);
|
||||
template<class NOTIFIER> void VisitWorld(const float &x, const float &y, float radius, NOTIFIER ¬ifier);
|
||||
|
||||
Reference in New Issue
Block a user