mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 09:17:36 +01:00
Core/Grids: Allow arbitrary containers in grid searchers that support…
… push_back * Makes it possible to use vector and dequeue with grid searchers.
This commit is contained in:
@@ -171,6 +171,31 @@ namespace Trinity
|
||||
|
||||
// WorldObject searchers & workers
|
||||
|
||||
// Generic base class to insert elements into arbitrary containers using push_back
|
||||
template<typename Type>
|
||||
class ContainerInserter {
|
||||
using InserterType = void(*)(void*, Type&&);
|
||||
|
||||
void* ref;
|
||||
InserterType inserter;
|
||||
|
||||
// MSVC workaround
|
||||
template<typename T>
|
||||
static void InserterOf(void* ref, Type&& type)
|
||||
{
|
||||
static_cast<T*>(ref)->push_back(std::move(type));
|
||||
}
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
ContainerInserter(T& ref_) : ref(&ref_), inserter(&InserterOf<T>) { }
|
||||
|
||||
void Insert(Type type)
|
||||
{
|
||||
inserter(ref, std::move(type));
|
||||
}
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct WorldObjectSearcher
|
||||
{
|
||||
@@ -214,15 +239,16 @@ namespace Trinity
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct WorldObjectListSearcher
|
||||
struct WorldObjectListSearcher : ContainerInserter<WorldObject*>
|
||||
{
|
||||
uint32 i_mapTypeMask;
|
||||
WorldObject const* _searcher;
|
||||
std::list<WorldObject*> &i_objects;
|
||||
Check& i_check;
|
||||
|
||||
WorldObjectListSearcher(WorldObject const* searcher, std::list<WorldObject*> &objects, Check & check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
|
||||
: i_mapTypeMask(mapTypeMask), _searcher(searcher), i_objects(objects), i_check(check) { }
|
||||
template<typename Container>
|
||||
WorldObjectListSearcher(WorldObject const* searcher, Container& container, Check & check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL)
|
||||
: ContainerInserter<WorldObject*>(container),
|
||||
i_mapTypeMask(mapTypeMask), i_phaseMask(searcher->GetPhaseMask()), i_check(check) { }
|
||||
|
||||
void Visit(PlayerMapType &m);
|
||||
void Visit(CreatureMapType &m);
|
||||
@@ -334,14 +360,15 @@ namespace Trinity
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct GameObjectListSearcher
|
||||
struct GameObjectListSearcher : ContainerInserter<GameObject*>
|
||||
{
|
||||
WorldObject const* _searcher;
|
||||
std::list<GameObject*> &i_objects;
|
||||
Check& i_check;
|
||||
|
||||
GameObjectListSearcher(WorldObject const* searcher, std::list<GameObject*> &objects, Check & check)
|
||||
: _searcher(searcher), i_objects(objects), i_check(check) { }
|
||||
template<typename Container>
|
||||
GameObjectListSearcher(WorldObject const* searcher, Container& container, Check & check)
|
||||
: ContainerInserter<GameObject*>(container),
|
||||
i_phaseMask(searcher->GetPhaseMask()), i_check(check) { }
|
||||
|
||||
void Visit(GameObjectMapType &m);
|
||||
|
||||
@@ -406,14 +433,15 @@ namespace Trinity
|
||||
|
||||
// All accepted by Check units if any
|
||||
template<class Check>
|
||||
struct UnitListSearcher
|
||||
struct UnitListSearcher : ContainerInserter<Unit*>
|
||||
{
|
||||
WorldObject const* _searcher;
|
||||
std::list<Unit*> &i_objects;
|
||||
Check& i_check;
|
||||
|
||||
UnitListSearcher(WorldObject const* searcher, std::list<Unit*> &objects, Check & check)
|
||||
: _searcher(searcher), i_objects(objects), i_check(check) { }
|
||||
template<typename Container>
|
||||
UnitListSearcher(WorldObject const* searcher, Container& container, Check& check)
|
||||
: ContainerInserter<Unit*>(container),
|
||||
i_phaseMask(searcher->GetPhaseMask()), i_check(check) { }
|
||||
|
||||
void Visit(PlayerMapType &m);
|
||||
void Visit(CreatureMapType &m);
|
||||
@@ -455,14 +483,15 @@ namespace Trinity
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct CreatureListSearcher
|
||||
struct CreatureListSearcher : ContainerInserter<Creature*>
|
||||
{
|
||||
WorldObject const* _searcher;
|
||||
std::list<Creature*> &i_objects;
|
||||
Check& i_check;
|
||||
|
||||
CreatureListSearcher(WorldObject const* searcher, std::list<Creature*> &objects, Check & check)
|
||||
: _searcher(searcher), i_objects(objects), i_check(check) { }
|
||||
template<typename Container>
|
||||
CreatureListSearcher(WorldObject const* searcher, Container& container, Check & check)
|
||||
: ContainerInserter<Creature*>(container),
|
||||
i_phaseMask(searcher->GetPhaseMask()), i_check(check) { }
|
||||
|
||||
void Visit(CreatureMapType &m);
|
||||
|
||||
@@ -506,14 +535,15 @@ namespace Trinity
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct PlayerListSearcher
|
||||
struct PlayerListSearcher : ContainerInserter<Player*>
|
||||
{
|
||||
WorldObject const* _searcher;
|
||||
std::list<Player*> &i_objects;
|
||||
Check& i_check;
|
||||
|
||||
PlayerListSearcher(WorldObject const* searcher, std::list<Player*> &objects, Check & check)
|
||||
: _searcher(searcher), i_objects(objects), i_check(check) { }
|
||||
template<typename Container>
|
||||
PlayerListSearcher(WorldObject const* searcher, Container& container, Check & check)
|
||||
: ContainerInserter<Player*>(container),
|
||||
i_phaseMask(searcher->GetPhaseMask()), i_check(check) { }
|
||||
|
||||
void Visit(PlayerMapType &m);
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(PlayerMapType &m)
|
||||
|
||||
for (PlayerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -295,7 +295,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(CreatureMapType &m)
|
||||
|
||||
for (CreatureMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -306,7 +306,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(CorpseMapType &m)
|
||||
|
||||
for (CorpseMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -317,7 +317,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(GameObjectMapType &m)
|
||||
|
||||
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -328,7 +328,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(DynamicObjectMapType &m)
|
||||
|
||||
for (DynamicObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -339,7 +339,7 @@ void Trinity::WorldObjectListSearcher<Check>::Visit(AreaTriggerMapType &m)
|
||||
|
||||
for (AreaTriggerMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
// Gameobject searchers
|
||||
@@ -383,7 +383,7 @@ void Trinity::GameObjectListSearcher<Check>::Visit(GameObjectMapType &m)
|
||||
for (GameObjectMapType::iterator itr=m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->IsInPhase(_searcher))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
// Unit searchers
|
||||
|
||||
Reference in New Issue
Block a user