From 8775f8b28a5ad4403371577787131ff81f14332b Mon Sep 17 00:00:00 2001 From: Naios Date: Sun, 25 Sep 2016 15:36:58 +0200 Subject: Core/Grids: Allow arbitrary containers in grid searchers that support push_back * Makes it possible to use vector and dequeue with grid searchers. --- src/server/game/Grids/Notifiers/GridNotifiers.h | 70 +++++++++++++++------- .../game/Grids/Notifiers/GridNotifiersImpl.h | 20 +++---- 2 files changed, 60 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 8304054c663..317378dfa8b 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -170,6 +170,31 @@ namespace Trinity // WorldObject searchers & workers + // Generic base class to insert elements into arbitrary containers using push_back + template + class ContainerInserter { + using InserterType = void(*)(void*, Type&&); + + void* ref; + InserterType inserter; + + // MSVC workaround + template + static void InserterOf(void* ref, Type&& type) + { + static_cast(ref)->push_back(std::move(type)); + } + + protected: + template + ContainerInserter(T& ref_) : ref(&ref_), inserter(&InserterOf) { } + + void Insert(Type type) + { + inserter(ref, std::move(type)); + } + }; + template struct WorldObjectSearcher { @@ -211,15 +236,16 @@ namespace Trinity }; template - struct WorldObjectListSearcher + struct WorldObjectListSearcher : ContainerInserter { uint32 i_mapTypeMask; uint32 i_phaseMask; - std::list &i_objects; Check& i_check; - WorldObjectListSearcher(WorldObject const* searcher, std::list &objects, Check & check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL) - : i_mapTypeMask(mapTypeMask), i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) { } + template + WorldObjectListSearcher(WorldObject const* searcher, Container& container, Check & check, uint32 mapTypeMask = GRID_MAP_TYPE_MASK_ALL) + : ContainerInserter(container), + i_mapTypeMask(mapTypeMask), i_phaseMask(searcher->GetPhaseMask()), i_check(check) { } void Visit(PlayerMapType &m); void Visit(CreatureMapType &m); @@ -321,14 +347,15 @@ namespace Trinity }; template - struct GameObjectListSearcher + struct GameObjectListSearcher : ContainerInserter { uint32 i_phaseMask; - std::list &i_objects; Check& i_check; - GameObjectListSearcher(WorldObject const* searcher, std::list &objects, Check & check) - : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) { } + template + GameObjectListSearcher(WorldObject const* searcher, Container& container, Check & check) + : ContainerInserter(container), + i_phaseMask(searcher->GetPhaseMask()), i_check(check) { } void Visit(GameObjectMapType &m); @@ -393,14 +420,15 @@ namespace Trinity // All accepted by Check units if any template - struct UnitListSearcher + struct UnitListSearcher : ContainerInserter { uint32 i_phaseMask; - std::list &i_objects; Check& i_check; - UnitListSearcher(WorldObject const* searcher, std::list &objects, Check & check) - : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) { } + template + UnitListSearcher(WorldObject const* searcher, Container& container, Check& check) + : ContainerInserter(container), + i_phaseMask(searcher->GetPhaseMask()), i_check(check) { } void Visit(PlayerMapType &m); void Visit(CreatureMapType &m); @@ -442,14 +470,15 @@ namespace Trinity }; template - struct CreatureListSearcher + struct CreatureListSearcher : ContainerInserter { uint32 i_phaseMask; - std::list &i_objects; Check& i_check; - CreatureListSearcher(WorldObject const* searcher, std::list &objects, Check & check) - : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) { } + template + CreatureListSearcher(WorldObject const* searcher, Container& container, Check & check) + : ContainerInserter(container), + i_phaseMask(searcher->GetPhaseMask()), i_check(check) { } void Visit(CreatureMapType &m); @@ -493,14 +522,15 @@ namespace Trinity }; template - struct PlayerListSearcher + struct PlayerListSearcher : ContainerInserter { uint32 i_phaseMask; - std::list &i_objects; Check& i_check; - PlayerListSearcher(WorldObject const* searcher, std::list &objects, Check & check) - : i_phaseMask(searcher->GetPhaseMask()), i_objects(objects), i_check(check) { } + template + PlayerListSearcher(WorldObject const* searcher, Container& container, Check & check) + : ContainerInserter(container), + i_phaseMask(searcher->GetPhaseMask()), i_check(check) { } void Visit(PlayerMapType &m); diff --git a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h index 340531c5883..5a3f41e5351 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h +++ b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h @@ -246,7 +246,7 @@ void Trinity::WorldObjectListSearcher::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 @@ -257,7 +257,7 @@ void Trinity::WorldObjectListSearcher::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 @@ -268,7 +268,7 @@ void Trinity::WorldObjectListSearcher::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 @@ -279,7 +279,7 @@ void Trinity::WorldObjectListSearcher::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 @@ -290,7 +290,7 @@ void Trinity::WorldObjectListSearcher::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 @@ -334,7 +334,7 @@ void Trinity::GameObjectListSearcher::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 @@ -411,7 +411,7 @@ void Trinity::UnitListSearcher::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 @@ -420,7 +420,7 @@ void Trinity::UnitListSearcher::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 @@ -464,7 +464,7 @@ void Trinity::CreatureListSearcher::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 @@ -473,7 +473,7 @@ void Trinity::PlayerListSearcher::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 -- cgit v1.2.3