More cleanup of grid system.
This commit is contained in:
@@ -22,24 +22,24 @@
|
||||
#include "Log.h"
|
||||
|
||||
void
|
||||
InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 /*x*/, const uint32 /*y*/, const uint32) const
|
||||
InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32) const
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 x, const uint32 y, const uint32 t_diff) const
|
||||
ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 t_diff) const
|
||||
{
|
||||
// Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
|
||||
info.UpdateTimeTracker(t_diff);
|
||||
if (info.getTimeTracker().Passed())
|
||||
{
|
||||
if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(x, y))
|
||||
if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(grid))
|
||||
{
|
||||
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());
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to IDLE state", grid.getX(), grid.getY(), m.GetId());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -49,24 +49,24 @@ ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 x, co
|
||||
}
|
||||
|
||||
void
|
||||
IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32 x, const uint32 y, const uint32) const
|
||||
IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32) const
|
||||
{
|
||||
m.ResetGridExpiry(grid);
|
||||
grid.SetGridState(GRID_STATE_REMOVAL);
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to REMOVAL state", x, y, m.GetId());
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to REMOVAL state", grid.getX(), grid.getY(), m.GetId());
|
||||
}
|
||||
|
||||
void
|
||||
RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 x, const uint32 y, const uint32 t_diff) const
|
||||
RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 t_diff) const
|
||||
{
|
||||
if (!info.getUnloadLock())
|
||||
{
|
||||
info.UpdateTimeTracker(t_diff);
|
||||
if (info.getTimeTracker().Passed())
|
||||
{
|
||||
if (!m.UnloadGrid(x, y, false))
|
||||
if (!m.UnloadGrid(grid, false))
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", x, y, m.GetId());
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", grid.getX(), grid.getY(), m.GetId());
|
||||
m.ResetGridExpiry(grid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,35 +40,31 @@ class GridState
|
||||
void setMagic() { i_Magic = MAGIC_TESTVAL; }
|
||||
unsigned int i_Magic;
|
||||
#endif
|
||||
virtual void Update(Map &, NGridType&, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const = 0;
|
||||
virtual void Update(Map &, NGridType&, GridInfo &, const uint32 t_diff) const = 0;
|
||||
};
|
||||
|
||||
class InvalidState : public GridState
|
||||
{
|
||||
public:
|
||||
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const;
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const;
|
||||
};
|
||||
|
||||
class ActiveState : public GridState
|
||||
{
|
||||
public:
|
||||
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const;
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const;
|
||||
};
|
||||
|
||||
class IdleState : public GridState
|
||||
{
|
||||
public:
|
||||
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const;
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const;
|
||||
};
|
||||
|
||||
class RemovalState : public GridState
|
||||
{
|
||||
public:
|
||||
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 x, const uint32 y, const uint32 t_diff) const;
|
||||
void Update(Map &, NGridType &, GridInfo &, const uint32 t_diff) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -934,13 +934,13 @@ bool Map::CreatureRespawnRelocation(Creature* c, bool diffGridOnly)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
|
||||
bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll)
|
||||
{
|
||||
NGridType *grid = getNGrid(x, y);
|
||||
ASSERT(grid != NULL);
|
||||
const uint32 x = ngrid.getX();
|
||||
const uint32 y = ngrid.getY();
|
||||
|
||||
{
|
||||
if (!unloadAll && ActiveObjectsNearGrid(x, y))
|
||||
if (!unloadAll && ActiveObjectsNearGrid(ngrid))
|
||||
return false;
|
||||
|
||||
sLog->outDebug(LOG_FILTER_MAPS, "Unloading grid[%u, %u] for map %u", x, y, GetId());
|
||||
@@ -954,7 +954,7 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
|
||||
// move creatures to respawn grids if this is diff.grid or to remove list
|
||||
ObjectGridEvacuator worker;
|
||||
TypeContainerVisitor<ObjectGridEvacuator, GridTypeMapContainer> visitor(worker);
|
||||
grid->VisitAllGrids(visitor);
|
||||
ngrid.VisitAllGrids(visitor);
|
||||
|
||||
// Finish creature moves, remove and delete all creatures with delayed remove before unload
|
||||
MoveAllCreaturesInMoveList();
|
||||
@@ -963,7 +963,7 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
|
||||
{
|
||||
ObjectGridCleaner worker;
|
||||
TypeContainerVisitor<ObjectGridCleaner, GridTypeMapContainer> visitor(worker);
|
||||
grid->VisitAllGrids(visitor);
|
||||
ngrid.VisitAllGrids(visitor);
|
||||
}
|
||||
|
||||
RemoveAllObjectsInRemoveList();
|
||||
@@ -971,12 +971,12 @@ bool Map::UnloadGrid(const uint32 x, const uint32 y, bool unloadAll)
|
||||
{
|
||||
ObjectGridUnloader worker;
|
||||
TypeContainerVisitor<ObjectGridUnloader, GridTypeMapContainer> visitor(worker);
|
||||
grid->VisitAllGrids(visitor);
|
||||
ngrid.VisitAllGrids(visitor);
|
||||
}
|
||||
|
||||
ASSERT(i_objectsToRemove.empty());
|
||||
|
||||
delete grid;
|
||||
delete &ngrid;
|
||||
setNGrid(NULL, x, y);
|
||||
}
|
||||
int gx = (MAX_NUMBER_OF_GRIDS - 1) - x;
|
||||
@@ -1030,7 +1030,7 @@ void Map::UnloadAll()
|
||||
{
|
||||
NGridType &grid(*i->getSource());
|
||||
++i;
|
||||
UnloadGrid(grid.getX(), grid.getY(), true); // deletes the grid and removes it from the GridRefManager
|
||||
UnloadGrid(grid, true); // deletes the grid and removes it from the GridRefManager
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1989,7 +1989,7 @@ void Map::DelayedUpdate(const uint32 t_diff)
|
||||
GridInfo* info = i->getSource()->getGridInfoRef();
|
||||
++i; // The update might delete the map and we need the next map before the iterator gets invalid
|
||||
ASSERT(grid->GetGridState() >= 0 && grid->GetGridState() < MAX_GRID_STATE);
|
||||
si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, grid->getX(), grid->getY(), t_diff);
|
||||
si_GridStates[grid->GetGridState()]->Update(*this, *grid, *info, t_diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2092,11 +2092,9 @@ void Map::SendToPlayers(WorldPacket const* data) const
|
||||
itr->getSource()->GetSession()->SendPacket(data);
|
||||
}
|
||||
|
||||
bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const
|
||||
bool Map::ActiveObjectsNearGrid(NGridType const& ngrid) const
|
||||
{
|
||||
ASSERT(x < MAX_NUMBER_OF_GRIDS && y < MAX_NUMBER_OF_GRIDS);
|
||||
|
||||
CellCoord cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS);
|
||||
CellCoord cell_min(ngrid.getX() * MAX_NUMBER_OF_CELLS, ngrid.getY() * MAX_NUMBER_OF_CELLS);
|
||||
CellCoord cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS);
|
||||
|
||||
//we must find visible range in cells so we unload only non-visible cells...
|
||||
|
||||
@@ -275,7 +275,7 @@ class Map : public GridRefManager<NGridType>
|
||||
bool GetUnloadLock(const GridCoord &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
|
||||
void SetUnloadLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
|
||||
void LoadGrid(float x, float y);
|
||||
bool UnloadGrid(const uint32 x, const uint32 y, bool pForce);
|
||||
bool UnloadGrid(NGridType& ngrid, bool pForce);
|
||||
virtual void UnloadAll();
|
||||
|
||||
void ResetGridExpiry(NGridType &grid, float factor = 1) const
|
||||
@@ -379,7 +379,7 @@ class Map : public GridRefManager<NGridType>
|
||||
|
||||
bool HavePlayers() const { return !m_mapRefManager.isEmpty(); }
|
||||
uint32 GetPlayersCountExceptGMs() const;
|
||||
bool ActiveObjectsNearGrid(uint32 x, uint32 y) const;
|
||||
bool ActiveObjectsNearGrid(NGridType const& ngrid) const;
|
||||
|
||||
void AddWorldObject(WorldObject* obj) { i_worldObjects.insert(obj); }
|
||||
void RemoveWorldObject(WorldObject* obj) { i_worldObjects.erase(obj); }
|
||||
|
||||
Reference in New Issue
Block a user