*Move cell visit into functions.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-12 23:54:02 -06:00
parent 032f5bc87d
commit 0ea36ed76e
2 changed files with 59 additions and 2 deletions

View File

@@ -253,6 +253,9 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
typedef MapRefManager PlayerList;
PlayerList const& GetPlayers() const { return m_mapRefManager; }
template<class T> void SwitchGridContainers(T* obj, bool active);
template<class NOTIFIER> void VisitAll(const float &x, const float &y, float radius, NOTIFIER &notifier);
template<class NOTIFIER> void VisitWorld(const float &x, const float &y, float radius, NOTIFIER &notifier);
template<class NOTIFIER> void VisitGrid(const float &x, const float &y, float radius, NOTIFIER &notifier);
private:
void LoadVMap(int pX, int pY);
void LoadMap(uint32 mapid, uint32 instanceid, int x,int y);
@@ -407,4 +410,51 @@ Map::Visit(const CellLock<LOCK_TYPE> &cell, TypeContainerVisitor<T, CONTAINER> &
getNGrid(x, y)->Visit(cell_x, cell_y, visitor);
}
}
template<class NOTIFIER>
inline void
Map::VisitAll(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
float x_off, y_off;
CellPair p(Trinity::ComputeCellPair(x, y, x_off, y_off));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell_lock->Visit(cell_lock, world_object_notifier, *this, radius, x_off, y_off);
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell_lock->Visit(cell_lock, grid_object_notifier, *this, radius, x_off, y_off);
}
template<class NOTIFIER>
inline void
Map::VisitWorld(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
float x_off, y_off;
CellPair p(Trinity::ComputeCellPair(x, y, x_off, y_off));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, WorldTypeMapContainer> world_object_notifier(notifier);
cell_lock->Visit(cell_lock, world_object_notifier, *this, radius, x_off, y_off);
}
template<class NOTIFIER>
inline void
Map::VisitGrid(const float &x, const float &y, float radius, NOTIFIER &notifier)
{
float x_off, y_off;
CellPair p(Trinity::ComputeCellPair(x, y, x_off, y_off));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
cell.SetNoCreate();
CellLock<GridReadGuard> cell_lock(cell, p);
TypeContainerVisitor<NOTIFIER, GridTypeMapContainer > grid_object_notifier(notifier);
cell_lock->Visit(cell_lock, grid_object_notifier, *this, radius, x_off, y_off);
}
#endif

View File

@@ -1473,7 +1473,14 @@ void Spell::SearchAreaTarget(std::list<Unit*> &TagUnitMap, float radius, const u
y = m_caster->GetPositionY();
}
float x_off, y_off;
Trinity::SpellNotifierCreatureAndPlayer notifier(*this, TagUnitMap, radius, type, TargetType, entry);
if((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_PLAYERS_ONLY)
|| TargetType == SPELL_TARGETS_ENTRY && !entry)
m_caster->GetMap()->VisitWorld(x, y, radius, notifier);
else
m_caster->GetMap()->VisitAll(x, y, radius, notifier);
/*float x_off, y_off;
CellPair p(Trinity::ComputeCellPair(x, y, x_off, y_off));
Cell cell(p);
cell.data.Part.reserved = ALL_DISTRICT;
@@ -1491,7 +1498,7 @@ void Spell::SearchAreaTarget(std::list<Unit*> &TagUnitMap, float radius, const u
{
TypeContainerVisitor<Trinity::SpellNotifierCreatureAndPlayer, GridTypeMapContainer > grid_object_notifier(notifier);
cell_lock->Visit(cell_lock, grid_object_notifier, *m_caster->GetMap(), radius, x_off, y_off);
}
}*/
}
Unit* Spell::SearchNearbyTarget(float radius, SpellTargets TargetType, uint32 entry)