From badcce45d83a73ed4edf49a661736c25b80a8bd0 Mon Sep 17 00:00:00 2001 From: horn Date: Tue, 26 Feb 2013 02:33:08 +0100 Subject: Core/Summons: Pack the TempSummonGroupKey structure so it is being compared correctly and make the second parameter of SummonCreatureGroup() optional --- src/server/game/Entities/Object/Object.cpp | 10 +++++--- src/server/game/Entities/Object/Object.h | 2 +- src/server/game/Globals/ObjectMgr.h | 39 +++++++++++++++--------------- src/server/game/Maps/Map.h | 2 +- 4 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 79bf656c318..cd8ae5056ba 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2322,7 +2322,7 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert * @param list List to store pointers to summoned creatures. */ -void Map::SummonCreatureGroup(uint8 group, std::list& list) +void Map::SummonCreatureGroup(uint8 group, std::list* list /*= NULL*/) { std::vector const* data = sObjectMgr->GetSummonGroup(GetId(), SUMMONER_TYPE_MAP, group); if (!data) @@ -2330,7 +2330,8 @@ void Map::SummonCreatureGroup(uint8 group, std::list& list) for (std::vector::const_iterator itr = data->begin(); itr != data->end(); ++itr) if (TempSummon* summon = SummonCreature(itr->entry, itr->pos, NULL, itr->time)) - list.push_back(summon); + if (list) + list->push_back(summon); } void WorldObject::SetZoneScript() @@ -2418,7 +2419,7 @@ Creature* WorldObject::SummonTrigger(float x, float y, float z, float ang, uint3 * @param group Id of group to summon. * @param list List to store pointers to summoned creatures. */ -void WorldObject::SummonCreatureGroup(uint8 group, std::list& list) +void WorldObject::SummonCreatureGroup(uint8 group, std::list* list /*= NULL*/) { ASSERT((GetTypeId() == TYPEID_GAMEOBJECT || GetTypeId() == TYPEID_UNIT) && "Only GOs and creatures can summon npc groups!"); @@ -2428,7 +2429,8 @@ void WorldObject::SummonCreatureGroup(uint8 group, std::list& list) for (std::vector::const_iterator itr = data->begin(); itr != data->end(); ++itr) if (TempSummon* summon = SummonCreature(itr->entry, itr->pos, itr->type, itr->time)) - list.push_back(summon); + if (list) + list->push_back(summon); } Creature* WorldObject::FindNearestCreature(uint32 entry, float range, bool alive) const diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index ae788621368..dfd2ff73ae9 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -793,7 +793,7 @@ class WorldObject : public Object, public WorldLocation } GameObject* SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime); Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL); - void SummonCreatureGroup(uint8 group, std::list& list); + void SummonCreatureGroup(uint8 group, std::list* list = NULL); Creature* FindNearestCreature(uint32 entry, float range, bool alive = true) const; GameObject* FindNearestGameObject(uint32 entry, float range) const; diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 5b13a4daf0d..0a5b878e8fa 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -63,6 +63,26 @@ struct PageText uint16 NextPage; }; +/// Key for storing temp summon data in TempSummonDataContainer +struct TempSummonGroupKey +{ + TempSummonGroupKey(uint32 summonerEntry, SummonerType summonerType, uint8 group) + : _summonerEntry(summonerEntry), _summonerType(summonerType), _summonGroup(group) + { + } + + bool operator<(TempSummonGroupKey const& rhs) const + { + // memcmp is only reliable if struct doesn't have any padding (packed) + return memcmp(this, &rhs, sizeof(TempSummonGroupKey)) < 0; + } + +private: + uint32 _summonerEntry; ///< Summoner's entry + SummonerType _summonerType; ///< Summoner's type, see SummonerType for available types + uint8 _summonGroup; ///< Summon's group id +}; + // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform #if defined(__GNUC__) #pragma pack() @@ -417,25 +437,6 @@ struct TrinityStringLocale StringVector Content; }; -/// Key for storing temp summon data in TempSummonDataContainer -struct TempSummonGroupKey -{ - TempSummonGroupKey(uint32 summonerEntry, SummonerType summonerType, uint8 group) - : _summonerEntry(summonerEntry), _summonerType(summonerType), _summonGroup(group) - { - } - - bool operator<(TempSummonGroupKey const& rhs) const - { - return memcmp(this, &rhs, sizeof(TempSummonGroupKey)) < 0; - } - -private: - uint32 _summonerEntry; ///< Summoner's entry - SummonerType _summonerType; ///< Summoner's type, see SummonerType for available types - uint8 _summonGroup; ///< Summon's group id -}; - typedef std::map LinkedRespawnContainer; typedef UNORDERED_MAP CreatureDataContainer; typedef UNORDERED_MAP GameObjectDataContainer; diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index cc47f053827..3deeb4e04b1 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -435,7 +435,7 @@ class Map : public GridRefManager void UpdateIteratorBack(Player* player); TempSummon* SummonCreature(uint32 entry, Position const& pos, SummonPropertiesEntry const* properties = NULL, uint32 duration = 0, Unit* summoner = NULL, uint32 spellId = 0, uint32 vehId = 0); - void SummonCreatureGroup(uint8 group, std::list& list); + void SummonCreatureGroup(uint8 group, std::list* list = NULL); Creature* GetCreature(uint64 guid); GameObject* GetGameObject(uint64 guid); DynamicObject* GetDynamicObject(uint64 guid); -- cgit v1.2.3