Clean up grid system. Get rid of GridLoader. This patch should not change any logic, except the incorrect calculation of the number of loaded corpse (which only affects log).

This commit is contained in:
megamage
2011-10-18 14:31:34 -04:00
parent bb64e64463
commit 7231ab959f
8 changed files with 78 additions and 171 deletions
+9 -9
View File
@@ -72,26 +72,26 @@ class Grid
/** Refreshes/update the grid. This required for remote grids.
*/
void RefreshGrid(void) { /* TBI */}
//void RefreshGrid(void) { /* TBI */}
/** Locks a grid. Any object enters must wait until the grid is unlock.
*/
void LockGrid(void) { /* TBI */ }
//void LockGrid(void) { /* TBI */ }
/** Unlocks the grid.
*/
void UnlockGrid(void) { /* TBI */ }
//void UnlockGrid(void) { /* TBI */ }
/** Grid visitor for grid objects
*/
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
// Visit grid objects
template<class T>
void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
{
visitor.Visit(i_container);
}
/** Grid visitor for world objects
*/
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
// Visit world objects
template<class T>
void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
{
visitor.Visit(i_objects);
}
+7 -6
View File
@@ -30,6 +30,8 @@
GridLoader manages the grid (both local and remote).
*/
//I cannot see why this cannot be replaced by a Grid::Visit
/*
#include "Define.h"
#include "Grid.h"
#include "TypeContainerVisitor.h"
@@ -44,8 +46,7 @@ class GridLoader
{
public:
/** Loads the grid
*/
// Loads the grid
template<class LOADER>
void Load(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader)
{
@@ -54,8 +55,7 @@ class GridLoader
grid.UnlockGrid();
}
/** Stop the grid
*/
// Stop the grid
template<class STOPER>
void Stop(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper)
{
@@ -63,8 +63,8 @@ class GridLoader
stoper.Stop(grid);
grid.UnlockGrid();
}
/** Unloads the grid
*/
// Unloads the grid
template<class UNLOADER>
void Unload(Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader)
{
@@ -73,5 +73,6 @@ class GridLoader
grid.UnlockGrid();
}
};
*/
#endif
+3 -2
View File
@@ -35,8 +35,9 @@ ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 x, co
{
if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(x, y))
{
ObjectGridStoper stoper(grid);
stoper.StopN();
ObjectGridStoper worker;
TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer> visitor(worker);
grid.VisitAllGrids(visitor);
grid.SetGridState(GRID_STATE_IDLE);
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to IDLE state", x, y, m.GetId());
}
+9 -5
View File
@@ -69,7 +69,7 @@ typedef enum
template
<
unsigned int N,
uint32 N,
class ACTIVE_OBJECT,
class WORLD_OBJECT_TYPES,
class GRID_OBJECT_TYPES
@@ -131,14 +131,18 @@ class NGrid
getGridType(x, y).RemoveWorldObject(obj);
}
template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
// Visit all Grids (cells) in NGrid (grid)
template<class T, class TT>
void VisitAllGrids(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
{
for (unsigned int x=0; x < N; ++x)
for (unsigned int y=0; y < N; ++y)
for (uint32 x = 0; x < N; ++x)
for (uint32 y = 0; y < N; ++y)
getGridType(x, y).Visit(visitor);
}
template<class T, class TT> void Visit(const uint32 x, const uint32 y, TypeContainerVisitor<T, TypeMapContainer<TT> > &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);
}
+19 -79
View File
@@ -28,26 +28,7 @@
#include "CellImpl.h"
#include "CreatureAI.h"
class ObjectGridRespawnMover
{
public:
ObjectGridRespawnMover() {}
void Move(GridType &grid);
template<class T> void Visit(GridRefManager<T> &) {}
void Visit(CreatureMapType &m);
};
void
ObjectGridRespawnMover::Move(GridType &grid)
{
TypeContainerVisitor<ObjectGridRespawnMover, GridTypeMapContainer > mover(*this);
grid.Visit(mover);
}
void
ObjectGridRespawnMover::Visit(CreatureMapType &m)
void ObjectGridEvacuator::Visit(CreatureMapType &m)
{
// creature in unloading grid can have respawn point in another grid
// if it will be unloaded then it will not respawn in original grid until unload/load original grid
@@ -188,22 +169,6 @@ ObjectWorldLoader::Visit(CorpseMapType &m)
LoadHelper(cell_guids.corpses, cellCoord, m, i_corpses, i_map);
}
void
ObjectGridLoader::Load(GridType &grid)
{
{
TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer > loader(*this);
grid.Visit(loader);
}
{
ObjectWorldLoader wloader(*this);
TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer > loader(wloader);
grid.Visit(loader);
i_corpses = wloader.i_corpses;
}
}
void ObjectGridLoader::LoadN(void)
{
i_gameObjects = 0; i_creatures = 0; i_corpses = 0;
@@ -214,35 +179,27 @@ void ObjectGridLoader::LoadN(void)
for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
{
i_cell.data.Part.cell_y = y;
GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader;
loader.Load(i_grid(x, y), *this);
//Load creatures and game objects
{
TypeContainerVisitor<ObjectGridLoader, GridTypeMapContainer> visitor(*this);
i_grid.VisitGrid(x, y, visitor);
}
//Load corpses (not bones)
{
ObjectWorldLoader worker(*this);
TypeContainerVisitor<ObjectWorldLoader, WorldTypeMapContainer> visitor(worker);
i_grid.VisitGrid(x, y, visitor);
i_corpses += worker.i_corpses;
}
}
}
sLog->outDebug(LOG_FILTER_MAPS, "%u GameObjects, %u Creatures, and %u Corpses/Bones loaded for grid %u on map %u", i_gameObjects, i_creatures, i_corpses, i_grid.GetGridId(), i_map->GetId());
}
void ObjectGridUnloader::MoveToRespawnN()
{
for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
{
for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
{
ObjectGridRespawnMover mover;
mover.Move(i_grid(x, y));
}
}
}
void
ObjectGridUnloader::Unload(GridType &grid)
{
TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer > unloader(*this);
grid.Visit(unloader);
}
template<class T>
void
ObjectGridUnloader::Visit(GridRefManager<T> &m)
void ObjectGridUnloader::Visit(GridRefManager<T> &m)
{
while (!m.isEmpty())
{
@@ -255,15 +212,7 @@ ObjectGridUnloader::Visit(GridRefManager<T> &m)
}
}
void
ObjectGridStoper::Stop(GridType &grid)
{
TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer > stoper(*this);
grid.Visit(stoper);
}
void
ObjectGridStoper::Visit(CreatureMapType &m)
void ObjectGridStoper::Visit(CreatureMapType &m)
{
// stop any fights at grid de-activation and remove dynobjects created at cast by creatures
for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
@@ -278,23 +227,14 @@ ObjectGridStoper::Visit(CreatureMapType &m)
}
}
void
ObjectGridCleaner::Stop(GridType &grid)
{
TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer > stoper(*this);
grid.Visit(stoper);
}
void
ObjectGridCleaner::Visit(CreatureMapType &m)
void ObjectGridCleaner::Visit(CreatureMapType &m)
{
for (CreatureMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
iter->getSource()->CleanupsBeforeDelete();
}
template<class T>
void
ObjectGridCleaner::Visit(GridRefManager<T> &m)
void ObjectGridCleaner::Visit(GridRefManager<T> &m)
{
for (typename GridRefManager<T>::iterator iter = m.begin(); iter != m.end(); ++iter)
iter->getSource()->RemoveFromWorld();
+17 -63
View File
@@ -36,7 +36,6 @@ class ObjectGridLoader
: i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses (0)
{}
void Load(GridType &grid);
void Visit(GameObjectMapType &m);
void Visit(CreatureMapType &m);
void Visit(CorpseMapType &) const {}
@@ -55,79 +54,34 @@ class ObjectGridLoader
uint32 i_corpses;
};
class ObjectGridUnloader
{
public:
ObjectGridUnloader(NGridType &grid) : i_grid(grid) {}
void MoveToRespawnN();
void UnloadN()
{
for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
{
for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
{
GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader;
loader.Unload(i_grid(x, y), *this);
}
}
}
void Unload(GridType &grid);
template<class T> void Visit(GridRefManager<T> &m);
private:
NGridType &i_grid;
};
//Stop the creatures before unloading the NGrid
class ObjectGridStoper
{
public:
ObjectGridStoper(NGridType &grid) : i_grid(grid) {}
void StopN()
{
for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
{
for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
{
GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader;
loader.Stop(i_grid(x, y), *this);
}
}
}
void Stop(GridType &grid);
void Visit(CreatureMapType &m);
template<class NONACTIVE> void Visit(GridRefManager<NONACTIVE> &) {}
private:
NGridType &i_grid;
template<class T> void Visit(GridRefManager<T> &) {}
};
//Move the foreign creatures back to respawn positions before unloading the NGrid
class ObjectGridEvacuator
{
public:
void Visit(CreatureMapType &m);
template<class T> void Visit(GridRefManager<T> &) {}
};
//Clean up and remove from world
class ObjectGridCleaner
{
public:
ObjectGridCleaner(NGridType &grid) : i_grid(grid) {}
void CleanN()
{
for (unsigned int x=0; x < MAX_NUMBER_OF_CELLS; ++x)
{
for (unsigned int y=0; y < MAX_NUMBER_OF_CELLS; ++y)
{
GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> loader;
loader.Stop(i_grid(x, y), *this);
}
}
}
void Stop(GridType &grid);
void Visit(CreatureMapType &m);
template<class T> void Visit(GridRefManager<T> &);
private:
NGridType &i_grid;
};
typedef GridLoader<Player, AllWorldObjectTypes, AllGridObjectTypes> GridLoaderType;
//Delete objects before deleting NGrid
class ObjectGridUnloader
{
public:
template<class T> void Visit(GridRefManager<T> &m);
};
#endif
+13 -6
View File
@@ -962,8 +962,6 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
sLog->outDebug(LOG_FILTER_MAPS, "Unloading grid[%u, %u] for map %u", x, y, GetId());
ObjectGridUnloader unloader(*grid);
if (!unloadAll)
{
// Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
@@ -971,18 +969,27 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
MoveAllCreaturesInMoveList();
// move creatures to respawn grids if this is diff.grid or to remove list
unloader.MoveToRespawnN();
ObjectGridEvacuator worker;
TypeContainerVisitor<ObjectGridEvacuator, GridTypeMapContainer> visitor(worker);
grid->VisitAllGrids(visitor);
// Finish creature moves, remove and delete all creatures with delayed remove before unload
MoveAllCreaturesInMoveList();
}
ObjectGridCleaner cleaner(*grid);
cleaner.CleanN();
{
ObjectGridCleaner worker;
TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer> visitor(worker);
grid->VisitAllGrids(visitor);
}
RemoveAllObjectsInRemoveList();
unloader.UnloadN();
{
ObjectGridUnloader worker;
TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer> visitor(worker);
grid->VisitAllGrids(visitor);
}
ASSERT(i_objectsToRemove.empty());
+1 -1
View File
@@ -626,7 +626,7 @@ Map::Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor)
if (!cell.NoCreate() || IsGridLoaded(GridCoord(x, y)))
{
EnsureGridLoaded(cell);
getNGrid(x, y)->Visit(cell_x, cell_y, visitor);
getNGrid(x, y)->VisitGrid(cell_x, cell_y, visitor);
}
}