Core/Grids: Decouple grid loading from searchers
This commit is contained in:
@@ -62,8 +62,13 @@ struct Cell
|
||||
uint32 CellY() const { return data.Part.cell_y; }
|
||||
uint32 GridX() const { return data.Part.grid_x; }
|
||||
uint32 GridY() const { return data.Part.grid_y; }
|
||||
bool NoCreate() const { return data.Part.nocreate; }
|
||||
void SetNoCreate() { data.Part.nocreate = 1; }
|
||||
|
||||
GridCoord GetGridCoord() const
|
||||
{
|
||||
return GridCoord(
|
||||
data.Part.grid_x,
|
||||
data.Part.grid_y);
|
||||
}
|
||||
|
||||
CellCoord GetCellCoord() const
|
||||
{
|
||||
@@ -81,9 +86,8 @@ struct Cell
|
||||
uint8 grid_y;
|
||||
uint8 cell_x;
|
||||
uint8 cell_y;
|
||||
uint8 nocreate;
|
||||
} Part;
|
||||
uint64 All;
|
||||
uint32 All;
|
||||
} data;
|
||||
|
||||
template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, WorldObject const& obj, float radius) const;
|
||||
@@ -91,13 +95,13 @@ struct Cell
|
||||
|
||||
static CellArea CalculateCellArea(float x, float y, float radius);
|
||||
|
||||
template<class T> static void VisitGridObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitAllObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitGridObjects(WorldObject const* obj, T& visitor, float radius);
|
||||
template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius);
|
||||
template<class T> static void VisitAllObjects(WorldObject const* obj, T& visitor, float radius);
|
||||
|
||||
template<class T> static void VisitGridObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitAllObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
|
||||
template<class T> static void VisitGridObjects(float x, float y, Map* map, T& visitor, float radius);
|
||||
template<class T> static void VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius);
|
||||
template<class T> static void VisitAllObjects(float x, float y, Map* map, T& visitor, float radius);
|
||||
|
||||
private:
|
||||
template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
|
||||
|
||||
@@ -82,7 +82,6 @@ inline void Cell::Visit(CellCoord const& standing_cell, TypeContainerVisitor<T,
|
||||
{
|
||||
CellCoord cellCoord(x, y);
|
||||
Cell r_zone(cellCoord);
|
||||
r_zone.data.Part.nocreate = this->data.Part.nocreate;
|
||||
map.Visit(r_zone, visitor);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +103,6 @@ inline void Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER>& visitor, Map&
|
||||
{
|
||||
CellCoord cellCoord(x, y);
|
||||
Cell r_zone(cellCoord);
|
||||
r_zone.data.Part.nocreate = this->data.Part.nocreate;
|
||||
map.Visit(r_zone, visitor);
|
||||
}
|
||||
}
|
||||
@@ -128,49 +126,41 @@ inline void Cell::VisitCircle(TypeContainerVisitor<T, CONTAINER>& visitor, Map&
|
||||
//e.g. filling 2 trapezoids after filling central cell strip...
|
||||
CellCoord cellCoord_left(x_start - step, y);
|
||||
Cell r_zone_left(cellCoord_left);
|
||||
r_zone_left.data.Part.nocreate = this->data.Part.nocreate;
|
||||
map.Visit(r_zone_left, visitor);
|
||||
|
||||
//right trapezoid cell visit
|
||||
CellCoord cellCoord_right(x_end + step, y);
|
||||
Cell r_zone_right(cellCoord_right);
|
||||
r_zone_right.data.Part.nocreate = this->data.Part.nocreate;
|
||||
map.Visit(r_zone_right, visitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitGridObjects(WorldObject const* center_obj, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitGridObjects(WorldObject const* center_obj, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, GridTypeMapContainer> gnotifier(visitor);
|
||||
cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitWorldObjects(WorldObject const* center_obj, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitWorldObjects(WorldObject const* center_obj, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, WorldTypeMapContainer> gnotifier(visitor);
|
||||
cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitAllObjects(WorldObject const* center_obj, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitAllObjects(WorldObject const* center_obj, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, WorldTypeMapContainer> wnotifier(visitor);
|
||||
cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
|
||||
@@ -179,36 +169,30 @@ inline void Cell::VisitAllObjects(WorldObject const* center_obj, T& visitor, flo
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitGridObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitGridObjects(float x, float y, Map* map, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(x, y));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, GridTypeMapContainer> gnotifier(visitor);
|
||||
cell.Visit(p, gnotifier, *map, x, y, radius);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(x, y));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, WorldTypeMapContainer> gnotifier(visitor);
|
||||
cell.Visit(p, gnotifier, *map, x, y, radius);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void Cell::VisitAllObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load)
|
||||
inline void Cell::VisitAllObjects(float x, float y, Map* map, T& visitor, float radius)
|
||||
{
|
||||
CellCoord p(Trinity::ComputeCellCoord(x, y));
|
||||
Cell cell(p);
|
||||
if (dont_load)
|
||||
cell.SetNoCreate();
|
||||
|
||||
TypeContainerVisitor<T, WorldTypeMapContainer> wnotifier(visitor);
|
||||
cell.Visit(p, wnotifier, *map, x, y, radius);
|
||||
|
||||
@@ -232,8 +232,10 @@ void DelayedUnitRelocation::Visit(PlayerMapType &m)
|
||||
if (player != viewPoint && !viewPoint->IsPositionValid())
|
||||
continue;
|
||||
|
||||
i_map.LoadGridsInRange(viewPoint->GetPositionX(), viewPoint->GetPositionY(), i_radius + viewPoint->GetCombatReach());
|
||||
|
||||
PlayerRelocationNotifier relocate(*player);
|
||||
Cell::VisitAllObjects(viewPoint, relocate, i_radius, false);
|
||||
Cell::VisitAllObjects(viewPoint, relocate, i_radius);
|
||||
relocate.SendToSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,6 +377,18 @@ void Map::LoadGridForActiveObject(float x, float y, WorldObject const* object)
|
||||
EnsureGridLoadedForActiveObject(Trinity::ComputeGridCoord(x, y), object);
|
||||
}
|
||||
|
||||
void Map::LoadGridsInRange(float x, float y, float radius)
|
||||
{
|
||||
CellArea area = Cell::CalculateCellArea(x, y, std::min(radius, SIZE_OF_GRIDS));
|
||||
|
||||
GridCoord gridAreaLow = Cell(area.low_bound).GetGridCoord();
|
||||
GridCoord gridAreaHigh = Cell(area.high_bound).GetGridCoord();
|
||||
|
||||
for (uint32 gx = gridAreaLow.x_coord; gx <= gridAreaHigh.x_coord; ++gx)
|
||||
for (uint32 gy = gridAreaLow.y_coord; gy <= gridAreaHigh.y_coord; ++gy)
|
||||
EnsureGridLoaded(GridCoord(gx, gy));
|
||||
}
|
||||
|
||||
bool Map::AddPlayerToMap(Player* player, bool initPlayer /*= true*/)
|
||||
{
|
||||
CellCoord cellCoord = Trinity::ComputeCellCoord(player->GetPositionX(), player->GetPositionY());
|
||||
@@ -627,7 +639,6 @@ void Map::VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::Obj
|
||||
markCell(cell_id);
|
||||
CellCoord pair(x, y);
|
||||
Cell cell(pair);
|
||||
cell.SetNoCreate();
|
||||
Visit(cell, gridVisitor);
|
||||
Visit(cell, worldVisitor);
|
||||
}
|
||||
@@ -862,7 +873,6 @@ void Map::ProcessRelocationNotifies(const uint32 diff)
|
||||
|
||||
CellCoord pair(x, y);
|
||||
Cell cell(pair);
|
||||
cell.SetNoCreate();
|
||||
|
||||
Trinity::DelayedUnitRelocation cell_relocation(cell, pair, *this, MAX_VISIBILITY_DISTANCE);
|
||||
TypeContainerVisitor<Trinity::DelayedUnitRelocation, GridTypeMapContainer > grid_object_relocation(cell_relocation);
|
||||
@@ -903,7 +913,6 @@ void Map::ProcessRelocationNotifies(const uint32 diff)
|
||||
|
||||
CellCoord pair(x, y);
|
||||
Cell cell(pair);
|
||||
cell.SetNoCreate();
|
||||
Visit(cell, grid_notifier);
|
||||
Visit(cell, world_notifier);
|
||||
}
|
||||
|
||||
@@ -282,6 +282,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
|
||||
void SetUnloadLock(GridCoord const& p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
|
||||
void LoadGrid(float x, float y);
|
||||
void LoadGridForActiveObject(float x, float y, WorldObject const* object);
|
||||
void LoadGridsInRange(float x, float y, float radius);
|
||||
void LoadAllGrids();
|
||||
bool UnloadGrid(NGridType& ngrid, bool pForce);
|
||||
void GridMarkNoUnload(uint32 x, uint32 y);
|
||||
@@ -961,9 +962,6 @@ inline void Map::Visit(Cell const& cell, TypeContainerVisitor<T, CONTAINER>& vis
|
||||
const uint32 cell_x = cell.CellX();
|
||||
const uint32 cell_y = cell.CellY();
|
||||
|
||||
if (!cell.NoCreate())
|
||||
EnsureGridLoaded(GridCoord(x, y));
|
||||
|
||||
NGridType* grid = getNGrid(x, y);
|
||||
if (grid && grid->isGridObjectDataLoaded())
|
||||
grid->VisitGrid(cell_x, cell_y, visitor);
|
||||
|
||||
@@ -2170,13 +2170,8 @@ void Spell::SearchTargets(SEARCHER& searcher, uint32 containerMask, WorldObject*
|
||||
bool searchInWorld = (containerMask & (GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER | GRID_MAP_TYPE_MASK_CORPSE)) != 0;
|
||||
if (searchInGrid || searchInWorld)
|
||||
{
|
||||
float x, y;
|
||||
x = pos->GetPositionX();
|
||||
y = pos->GetPositionY();
|
||||
|
||||
CellCoord p(Trinity::ComputeCellCoord(x, y));
|
||||
Cell cell(p);
|
||||
cell.SetNoCreate();
|
||||
float x = pos->GetPositionX();
|
||||
float y = pos->GetPositionY();
|
||||
|
||||
Map* map = referer->GetMap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user