From 23b3f16f3a4a27b7b24081b725666c5897fdbbee Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 10 Nov 2011 10:18:32 -0500 Subject: Add some ASSERT in add/remove obj to/from grid. --- src/server/game/Grids/Grid.h | 21 +++++++++++++-------- src/server/game/Grids/NGrid.h | 2 ++ src/server/game/Maps/Map.cpp | 5 +++-- 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/server/game/Grids/Grid.h b/src/server/game/Grids/Grid.h index a90915d49f0..cf6eb2471da 100755 --- a/src/server/game/Grids/Grid.h +++ b/src/server/game/Grids/Grid.h @@ -58,16 +58,19 @@ class Grid */ template void AddWorldObject(SPECIFIC_OBJECT *obj) { - if (!i_objects.template insert(obj)) - ASSERT(false); + ASSERT(!obj->GetGridRef().isValid()); + i_objects.template insert(obj); + ASSERT(obj->GetGridRef().isValid()); } /** an object of interested exits the grid */ + //Actually an unlink is enough, no need to go through the container template void RemoveWorldObject(SPECIFIC_OBJECT *obj) { - if (!i_objects.template remove(obj)) - ASSERT(false); + ASSERT(obj->GetGridRef().isValid()); + i_objects.template remove(obj); + ASSERT(!obj->GetGridRef().isValid()); } /** Refreshes/update the grid. This required for remote grids. @@ -104,16 +107,18 @@ class Grid */ template void AddGridObject(SPECIFIC_OBJECT *obj) { - if (!i_container.template insert(obj)) - ASSERT(false); + ASSERT(!obj->GetGridRef().isValid()); + i_container.template insert(obj); + ASSERT(obj->GetGridRef().isValid()); } /** Removes a containter type object from the grid */ template void RemoveGridObject(SPECIFIC_OBJECT *obj) { - if (!i_container.template remove(obj)) - ASSERT(false); + ASSERT(obj->GetGridRef().isValid()); + i_container.template remove(obj); + ASSERT(!obj->GetGridRef().isValid()); } /*bool NoWorldObjectInGrid() const diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index b814fd386a5..97a47f7d272 100755 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -120,6 +120,7 @@ class NGrid void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); } void UpdateTimeTracker(time_t diff) { i_GridInfo.UpdateTimeTracker(diff); } + /* template void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj) { GetGridType(x, y).AddWorldObject(obj); @@ -139,6 +140,7 @@ class NGrid { GetGridType(x, y).RemoveGridObject(obj); } + */ // Visit all Grids (cells) in NGrid (grid) template diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index e193325b72e..0c2a808f5c6 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -255,6 +255,7 @@ void Map::AddToGrid(Creature* obj, Cell const& cell) obj->SetCurrentCell(cell); } +//TODO: cell is not needed. Just an unlink is enough. template void Map::RemoveFromGrid(T* obj, Cell const& cell) { @@ -287,12 +288,12 @@ void Map::SwitchGridContainers(T* obj, bool on) if (on) { - grid.RemoveGridObject(obj); + grid.RemoveGridObject(obj); //not really necessary if there were no ASSERT in remove/add grid.AddWorldObject(obj); } else { - grid.RemoveWorldObject(obj); + grid.RemoveWorldObject(obj); //not really necessary if there were no ASSERT in remove/add grid.AddGridObject(obj); } obj->m_isWorldObject = on; -- cgit v1.2.3