aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none.none>2011-10-22 09:36:05 -0400
committermegamage <none@none.none>2011-10-22 09:36:05 -0400
commit80a18b9e56d17d62677a2c3427fab459667b9dd8 (patch)
tree46b11ee94883001a9a9799214082633d2cd3df58 /src
parent3b4ff9ee513c845d9e79655bda9d670ff157bc55 (diff)
Some cleanup of grid system.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/game/Grids/NGrid.h40
-rwxr-xr-xsrc/server/game/Maps/Map.cpp26
2 files changed, 24 insertions, 42 deletions
diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h
index bcd03edb2b8..b814fd386a5 100755
--- a/src/server/game/Grids/NGrid.h
+++ b/src/server/game/Grids/NGrid.h
@@ -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;
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 425a31fc38a..288cf02f821 100755
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -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;
}