Some cleanup of grid system.
This commit is contained in:
@@ -77,7 +77,6 @@ class GRID_OBJECT_TYPES
|
||||
class NGrid
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType;
|
||||
NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true)
|
||||
: i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false)
|
||||
@@ -85,13 +84,13 @@ class NGrid
|
||||
i_GridInfo = GridInfo(expiry, unload);
|
||||
}
|
||||
|
||||
const GridType& operator()(unsigned short x, unsigned short y) const
|
||||
GridType& GetGridType(const uint32 x, const uint32 y)
|
||||
{
|
||||
ASSERT(x < N && y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
GridType& operator()(unsigned short x, unsigned short y)
|
||||
GridType const& GetGridType(const uint32 x, const uint32 y) const
|
||||
{
|
||||
ASSERT(x < N && y < N);
|
||||
return i_cells[x][y];
|
||||
@@ -123,12 +122,22 @@ class NGrid
|
||||
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).AddWorldObject(obj);
|
||||
GetGridType(x, y).AddWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).RemoveWorldObject(obj);
|
||||
GetGridType(x, y).RemoveWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
GetGridType(x, y).AddGridObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
GetGridType(x, y).RemoveGridObject(obj);
|
||||
}
|
||||
|
||||
// Visit all Grids (cells) in NGrid (grid)
|
||||
@@ -137,14 +146,14 @@ class NGrid
|
||||
{
|
||||
for (uint32 x = 0; x < N; ++x)
|
||||
for (uint32 y = 0; y < N; ++y)
|
||||
getGridType(x, y).Visit(visitor);
|
||||
GetGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
// Visit a single Grid (cell) in NGrid (grid)
|
||||
template<class T, class TT>
|
||||
void VisitGrid(const uint32 x, const uint32 y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
{
|
||||
getGridType(x, y).Visit(visitor);
|
||||
GetGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
unsigned int ActiveObjectsInGrid(void) const
|
||||
@@ -156,24 +165,7 @@ class NGrid
|
||||
return count;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).AddGridObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).RemoveGridObject(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
GridType& getGridType(const uint32 x, const uint32 y)
|
||||
{
|
||||
ASSERT(x < N && y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
uint32 i_gridId;
|
||||
GridInfo i_GridInfo;
|
||||
GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> > i_Reference;
|
||||
|
||||
@@ -238,9 +238,9 @@ void Map::AddToGrid(T* obj, Cell const& cell)
|
||||
{
|
||||
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
|
||||
if (obj->m_isWorldObject)
|
||||
(*grid)(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template AddWorldObject<T>(obj);
|
||||
else
|
||||
(*grid)(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj);
|
||||
}
|
||||
|
||||
template<>
|
||||
@@ -248,9 +248,9 @@ void Map::AddToGrid(Creature* obj, Cell const& cell)
|
||||
{
|
||||
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
|
||||
if (obj->m_isWorldObject)
|
||||
(*grid)(cell.CellX(), cell.CellY()).AddWorldObject(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).AddWorldObject(obj);
|
||||
else
|
||||
(*grid)(cell.CellX(), cell.CellY()).AddGridObject(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).AddGridObject(obj);
|
||||
|
||||
obj->SetCurrentCell(cell);
|
||||
}
|
||||
@@ -260,9 +260,9 @@ void Map::RemoveFromGrid(T* obj, Cell const& cell)
|
||||
{
|
||||
NGridType* grid = getNGrid(cell.GridX(), cell.GridY());
|
||||
if (obj->m_isWorldObject)
|
||||
(*grid)(cell.CellX(), cell.CellY()).template RemoveWorldObject<T>(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template RemoveWorldObject<T>(obj);
|
||||
else
|
||||
(*grid)(cell.CellX(), cell.CellY()).template RemoveGridObject<T>(obj);
|
||||
grid->GetGridType(cell.CellX(), cell.CellY()).template RemoveGridObject<T>(obj);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -283,27 +283,17 @@ void Map::SwitchGridContainers(T* obj, bool on)
|
||||
NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY());
|
||||
ASSERT(ngrid != NULL);
|
||||
|
||||
GridType &grid = (*ngrid)(cell.CellX(), cell.CellY());
|
||||
GridType &grid = ngrid->GetGridType(cell.CellX(), cell.CellY());
|
||||
|
||||
if (on)
|
||||
{
|
||||
grid.RemoveGridObject<T>(obj);
|
||||
grid.AddWorldObject<T>(obj);
|
||||
/*if (!grid.RemoveGridObject<T>(obj, obj->GetGUID())
|
||||
|| !grid.AddWorldObject<T>(obj, obj->GetGUID()))
|
||||
{
|
||||
ASSERT(false);
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
grid.RemoveWorldObject<T>(obj);
|
||||
grid.AddGridObject<T>(obj);
|
||||
/*if (!grid.RemoveWorldObject<T>(obj, obj->GetGUID())
|
||||
|| !grid.AddGridObject<T>(obj, obj->GetGUID()))
|
||||
{
|
||||
ASSERT(false);
|
||||
}*/
|
||||
}
|
||||
obj->m_isWorldObject = on;
|
||||
}
|
||||
@@ -387,7 +377,7 @@ bool Map::EnsureGridLoaded(const Cell &cell)
|
||||
loader.LoadN();
|
||||
|
||||
// Add resurrectable corpses to world object list in grid
|
||||
sObjectAccessor->AddCorpsesToGrid(GridCoord(cell.GridX(), cell.GridY()), (*grid)(cell.CellX(), cell.CellY()), this);
|
||||
sObjectAccessor->AddCorpsesToGrid(GridCoord(cell.GridX(), cell.GridY()), grid->GetGridType(cell.CellX(), cell.CellY()), this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user