mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 13:46:24 +00:00
feat(Core/Grids): Allow arbitrary containers in grid searchers that support push_back
This commit is contained in:
committed by
GitHub
parent
fb890b3310
commit
759b945a13
@@ -165,6 +165,32 @@ namespace Acore
|
||||
|
||||
// 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
|
||||
{
|
||||
@@ -206,15 +232,16 @@ namespace Acore
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct WorldObjectListSearcher
|
||||
struct WorldObjectListSearcher : ContainerInserter<WorldObject*>
|
||||
{
|
||||
uint32 i_mapTypeMask;
|
||||
uint32 i_phaseMask;
|
||||
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), i_phaseMask(searcher->GetPhaseMask()), 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);
|
||||
@@ -316,14 +343,15 @@ namespace Acore
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct GameObjectListSearcher
|
||||
struct GameObjectListSearcher : ContainerInserter<GameObject*>
|
||||
{
|
||||
uint32 i_phaseMask;
|
||||
std::list<GameObject*>& i_objects;
|
||||
Check& i_check;
|
||||
|
||||
GameObjectListSearcher(WorldObject const* searcher, std::list<GameObject*>& objects, Check& check)
|
||||
: i_phaseMask(searcher->GetPhaseMask()), 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);
|
||||
|
||||
@@ -388,14 +416,15 @@ namespace Acore
|
||||
|
||||
// All accepted by Check units if any
|
||||
template<class Check>
|
||||
struct UnitListSearcher
|
||||
struct UnitListSearcher : ContainerInserter<Unit*>
|
||||
{
|
||||
uint32 i_phaseMask;
|
||||
std::list<Unit*>& i_objects;
|
||||
Check& i_check;
|
||||
|
||||
UnitListSearcher(WorldObject const* searcher, std::list<Unit*>& objects, Check& check)
|
||||
: i_phaseMask(searcher->GetPhaseMask()), 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);
|
||||
@@ -437,14 +466,15 @@ namespace Acore
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct CreatureListSearcher
|
||||
struct CreatureListSearcher : ContainerInserter<Creature*>
|
||||
{
|
||||
uint32 i_phaseMask;
|
||||
std::list<Creature*>& i_objects;
|
||||
Check& i_check;
|
||||
|
||||
CreatureListSearcher(WorldObject const* searcher, std::list<Creature*>& objects, Check& check)
|
||||
: i_phaseMask(searcher->GetPhaseMask()), 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);
|
||||
|
||||
@@ -488,14 +518,15 @@ namespace Acore
|
||||
};
|
||||
|
||||
template<class Check>
|
||||
struct PlayerListSearcher
|
||||
struct PlayerListSearcher : ContainerInserter<Player*>
|
||||
{
|
||||
uint32 i_phaseMask;
|
||||
std::list<Player*>& i_objects;
|
||||
Check& i_check;
|
||||
|
||||
PlayerListSearcher(WorldObject const* searcher, std::list<Player*>& objects, Check& check)
|
||||
: i_phaseMask(searcher->GetPhaseMask()), 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);
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ void Acore::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>
|
||||
@@ -264,7 +264,7 @@ void Acore::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>
|
||||
@@ -275,7 +275,7 @@ void Acore::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>
|
||||
@@ -286,7 +286,7 @@ void Acore::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>
|
||||
@@ -297,7 +297,7 @@ void Acore::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());
|
||||
}
|
||||
|
||||
// Gameobject searchers
|
||||
@@ -341,7 +341,7 @@ void Acore::GameObjectListSearcher<Check>::Visit(GameObjectMapType& m)
|
||||
for (GameObjectMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->InSamePhase(i_phaseMask))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
// Unit searchers
|
||||
@@ -418,7 +418,7 @@ void Acore::UnitListSearcher<Check>::Visit(PlayerMapType& m)
|
||||
for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->InSamePhase(i_phaseMask))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -427,7 +427,7 @@ void Acore::UnitListSearcher<Check>::Visit(CreatureMapType& m)
|
||||
for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->InSamePhase(i_phaseMask))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
// Creature searchers
|
||||
@@ -471,7 +471,7 @@ void Acore::CreatureListSearcher<Check>::Visit(CreatureMapType& m)
|
||||
for (CreatureMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->InSamePhase(i_phaseMask))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
@@ -480,7 +480,7 @@ void Acore::PlayerListSearcher<Check>::Visit(PlayerMapType& m)
|
||||
for (PlayerMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
if (itr->GetSource()->InSamePhase(i_phaseMask))
|
||||
if (i_check(itr->GetSource()))
|
||||
i_objects.push_back(itr->GetSource());
|
||||
Insert(itr->GetSource());
|
||||
}
|
||||
|
||||
template<class Check>
|
||||
|
||||
Reference in New Issue
Block a user