mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-30 00:53:46 +00:00
refactor(Core/Game): restyle game lib with astyle (#3466)
This commit is contained in:
@@ -31,41 +31,41 @@ class MotionTransport;
|
||||
template <class T>
|
||||
class HashMapHolder
|
||||
{
|
||||
public:
|
||||
public:
|
||||
|
||||
typedef std::unordered_map<uint64, T*> MapType;
|
||||
typedef ACE_RW_Thread_Mutex LockType;
|
||||
typedef std::unordered_map<uint64, T*> MapType;
|
||||
typedef ACE_RW_Thread_Mutex LockType;
|
||||
|
||||
static void Insert(T* o)
|
||||
{
|
||||
ACORE_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
static void Insert(T* o)
|
||||
{
|
||||
ACORE_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
static void Remove(T* o)
|
||||
{
|
||||
ACORE_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
static void Remove(T* o)
|
||||
{
|
||||
ACORE_WRITE_GUARD(LockType, i_lock);
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
|
||||
static T* Find(uint64 guid)
|
||||
{
|
||||
ACORE_READ_GUARD(LockType, i_lock);
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : nullptr;
|
||||
}
|
||||
static T* Find(uint64 guid)
|
||||
{
|
||||
ACORE_READ_GUARD(LockType, i_lock);
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
static MapType& GetContainer() { return m_objectMap; }
|
||||
static MapType& GetContainer() { return m_objectMap; }
|
||||
|
||||
static LockType* GetLock() { return &i_lock; }
|
||||
static LockType* GetLock() { return &i_lock; }
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
//Non instanceable only static
|
||||
HashMapHolder() {}
|
||||
//Non instanceable only static
|
||||
HashMapHolder() {}
|
||||
|
||||
static LockType i_lock;
|
||||
static MapType m_objectMap;
|
||||
static LockType i_lock;
|
||||
static MapType m_objectMap;
|
||||
};
|
||||
|
||||
/// Define the static members of HashMapHolder
|
||||
@@ -86,196 +86,196 @@ public:
|
||||
|
||||
class ObjectAccessor
|
||||
{
|
||||
private:
|
||||
ObjectAccessor();
|
||||
~ObjectAccessor();
|
||||
ObjectAccessor(const ObjectAccessor&);
|
||||
ObjectAccessor& operator=(const ObjectAccessor&);
|
||||
private:
|
||||
ObjectAccessor();
|
||||
~ObjectAccessor();
|
||||
ObjectAccessor(const ObjectAccessor&);
|
||||
ObjectAccessor& operator=(const ObjectAccessor&);
|
||||
|
||||
public:
|
||||
static ObjectAccessor* instance();
|
||||
// TODO: override these template functions for each holder type and add assertions
|
||||
public:
|
||||
static ObjectAccessor* instance();
|
||||
// TODO: override these template functions for each holder type and add assertions
|
||||
|
||||
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
static Unit* GetObjectInOrOutOfWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Player*)NULL);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Pet*)NULL);
|
||||
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Creature*)NULL);
|
||||
}
|
||||
|
||||
// returns object if is in world
|
||||
template<class T> static T* GetObjectInWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
// Player may be not in world while in ObjectAccessor
|
||||
static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/);
|
||||
|
||||
static Unit* GetObjectInWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Player*)NULL);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Pet*)NULL);
|
||||
|
||||
return (Unit*)GetObjectInWorld(guid, (Creature*)NULL);
|
||||
}
|
||||
|
||||
// returns object if is in map
|
||||
template<class T> static T* GetObjectInMap(uint64 guid, Map* map, T* /*typeSpecifier*/)
|
||||
{
|
||||
ASSERT(map);
|
||||
if (T* obj = GetObjectInWorld(guid, (T*)NULL))
|
||||
if (obj->GetMap() == map)
|
||||
return obj;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class T> static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/)
|
||||
{
|
||||
T* obj = HashMapHolder<T>::Find(guid);
|
||||
if (!obj || obj->GetMapId() != mapid)
|
||||
return nullptr;
|
||||
|
||||
CellCoord p = acore::ComputeCellCoord(x, y);
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
static Unit* GetObjectInOrOutOfWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Player*)NULL);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Pet*)NULL);
|
||||
|
||||
return (Unit*)GetObjectInOrOutOfWorld(guid, (Creature*)NULL);
|
||||
}
|
||||
|
||||
// returns object if is in world
|
||||
template<class T> static T* GetObjectInWorld(uint64 guid, T* /*typeSpecifier*/)
|
||||
{
|
||||
return HashMapHolder<T>::Find(guid);
|
||||
}
|
||||
|
||||
// Player may be not in world while in ObjectAccessor
|
||||
static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/);
|
||||
|
||||
static Unit* GetObjectInWorld(uint64 guid, Unit* /*typeSpecifier*/)
|
||||
{
|
||||
if (IS_PLAYER_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Player*)NULL);
|
||||
|
||||
if (IS_PET_GUID(guid))
|
||||
return (Unit*)GetObjectInWorld(guid, (Pet*)NULL);
|
||||
|
||||
return (Unit*)GetObjectInWorld(guid, (Creature*)NULL);
|
||||
}
|
||||
|
||||
// returns object if is in map
|
||||
template<class T> static T* GetObjectInMap(uint64 guid, Map* map, T* /*typeSpecifier*/)
|
||||
{
|
||||
ASSERT(map);
|
||||
if (T * obj = GetObjectInWorld(guid, (T*)NULL))
|
||||
if (obj->GetMap() == map)
|
||||
return obj;
|
||||
sLog->outError("ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<class T> static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/)
|
||||
CellCoord q = acore::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!q.IsCoordValid())
|
||||
{
|
||||
T* obj = HashMapHolder<T>::Find(guid);
|
||||
if (!obj || obj->GetMapId() != mapid)
|
||||
return nullptr;
|
||||
|
||||
CellCoord p = acore::ComputeCellCoord(x, y);
|
||||
if (!p.IsCoordValid())
|
||||
{
|
||||
sLog->outError("ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CellCoord q = acore::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY());
|
||||
if (!q.IsCoordValid())
|
||||
{
|
||||
sLog->outError("ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32 dx = int32(p.x_coord) - int32(q.x_coord);
|
||||
int32 dy = int32(p.y_coord) - int32(q.y_coord);
|
||||
|
||||
if (dx > -2 && dx < 2 && dy > -2 && dy < 2)
|
||||
return obj;
|
||||
else
|
||||
return nullptr;
|
||||
sLog->outError("ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// these functions return objects only if in map of specified object
|
||||
static WorldObject* GetWorldObject(WorldObject const&, uint64);
|
||||
static Object* GetObjectByTypeMask(WorldObject const&, uint64, uint32 typemask);
|
||||
static Corpse* GetCorpse(WorldObject const& u, uint64 guid);
|
||||
static GameObject* GetGameObject(WorldObject const& u, uint64 guid);
|
||||
static Transport* GetTransport(WorldObject const& u, uint64 guid);
|
||||
static DynamicObject* GetDynamicObject(WorldObject const& u, uint64 guid);
|
||||
static Unit* GetUnit(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreature(WorldObject const& u, uint64 guid);
|
||||
static Pet* GetPet(WorldObject const&, uint64 guid);
|
||||
static Player* GetPlayer(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreatureOrPetOrVehicle(WorldObject const&, uint64);
|
||||
int32 dx = int32(p.x_coord) - int32(q.x_coord);
|
||||
int32 dy = int32(p.y_coord) - int32(q.y_coord);
|
||||
|
||||
// these functions return objects if found in whole world
|
||||
// ACCESS LIKE THAT IS NOT THREAD SAFE
|
||||
static Pet* FindPet(uint64);
|
||||
static Player* FindPlayer(uint64);
|
||||
static Player* FindPlayerInOrOutOfWorld(uint64 m_guid);
|
||||
if (dx > -2 && dx < 2 && dy > -2 && dy < 2)
|
||||
return obj;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static Unit* FindUnit(uint64);
|
||||
static Player* FindConnectedPlayer(uint64 const&);
|
||||
static Player* FindPlayerByName(std::string const& name, bool checkInWorld = true);
|
||||
static std::map<std::string, Player*> playerNameToPlayerPointer; // pussywizard: optimization
|
||||
// these functions return objects only if in map of specified object
|
||||
static WorldObject* GetWorldObject(WorldObject const&, uint64);
|
||||
static Object* GetObjectByTypeMask(WorldObject const&, uint64, uint32 typemask);
|
||||
static Corpse* GetCorpse(WorldObject const& u, uint64 guid);
|
||||
static GameObject* GetGameObject(WorldObject const& u, uint64 guid);
|
||||
static Transport* GetTransport(WorldObject const& u, uint64 guid);
|
||||
static DynamicObject* GetDynamicObject(WorldObject const& u, uint64 guid);
|
||||
static Unit* GetUnit(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreature(WorldObject const& u, uint64 guid);
|
||||
static Pet* GetPet(WorldObject const&, uint64 guid);
|
||||
static Player* GetPlayer(WorldObject const&, uint64 guid);
|
||||
static Creature* GetCreatureOrPetOrVehicle(WorldObject const&, uint64);
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Player>::MapType const& GetPlayers()
|
||||
{
|
||||
return HashMapHolder<Player>::GetContainer();
|
||||
}
|
||||
// these functions return objects if found in whole world
|
||||
// ACCESS LIKE THAT IS NOT THREAD SAFE
|
||||
static Pet* FindPet(uint64);
|
||||
static Player* FindPlayer(uint64);
|
||||
static Player* FindPlayerInOrOutOfWorld(uint64 m_guid);
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Creature>::MapType const& GetCreatures()
|
||||
{
|
||||
return HashMapHolder<Creature>::GetContainer();
|
||||
}
|
||||
static Unit* FindUnit(uint64);
|
||||
static Player* FindConnectedPlayer(uint64 const&);
|
||||
static Player* FindPlayerByName(std::string const& name, bool checkInWorld = true);
|
||||
static std::map<std::string, Player*> playerNameToPlayerPointer; // pussywizard: optimization
|
||||
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<GameObject>::MapType const& GetGameObjects()
|
||||
{
|
||||
return HashMapHolder<GameObject>::GetContainer();
|
||||
}
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Player>::MapType const& GetPlayers()
|
||||
{
|
||||
return HashMapHolder<Player>::GetContainer();
|
||||
}
|
||||
|
||||
template<class T> static void AddObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Insert(object);
|
||||
}
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<Creature>::MapType const& GetCreatures()
|
||||
{
|
||||
return HashMapHolder<Creature>::GetContainer();
|
||||
}
|
||||
|
||||
template<class T> static void RemoveObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Remove(object);
|
||||
}
|
||||
// when using this, you must use the hashmapholder's lock
|
||||
static HashMapHolder<GameObject>::MapType const& GetGameObjects()
|
||||
{
|
||||
return HashMapHolder<GameObject>::GetContainer();
|
||||
}
|
||||
|
||||
static void SaveAllPlayers();
|
||||
template<class T> static void AddObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Insert(object);
|
||||
}
|
||||
|
||||
//non-static functions
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.insert(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.insert(obj);
|
||||
}
|
||||
template<class T> static void RemoveObject(T* object)
|
||||
{
|
||||
HashMapHolder<T>::Remove(object);
|
||||
}
|
||||
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.erase(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.erase(obj);
|
||||
}
|
||||
static void SaveAllPlayers();
|
||||
|
||||
//Thread safe
|
||||
Corpse* GetCorpseForPlayerGUID(uint64 guid);
|
||||
void RemoveCorpse(Corpse* corpse, bool final = false);
|
||||
void AddCorpse(Corpse* corpse);
|
||||
void AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map);
|
||||
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
|
||||
//non-static functions
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.insert(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.insert(obj);
|
||||
}
|
||||
|
||||
//Thread unsafe
|
||||
void Update(uint32 diff);
|
||||
void RemoveOldCorpses();
|
||||
void UnloadAll();
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
ACORE_GUARD(ACE_Thread_Mutex, i_objectLock);
|
||||
if (obj->GetTypeId() < TYPEID_UNIT) // these are not in map: TYPEID_OBJECT, TYPEID_ITEM, TYPEID_CONTAINER
|
||||
i_objects.erase(obj);
|
||||
else
|
||||
((WorldObject*)obj)->FindMap()->i_objectsToUpdate.erase(obj);
|
||||
}
|
||||
|
||||
// pussywizard: crashfix for corpses
|
||||
void AddDelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId = 0, uint32 instanceId = 0);
|
||||
void ProcessDelayedCorpseActions();
|
||||
//Thread safe
|
||||
Corpse* GetCorpseForPlayerGUID(uint64 guid);
|
||||
void RemoveCorpse(Corpse* corpse, bool final = false);
|
||||
void AddCorpse(Corpse* corpse);
|
||||
void AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map);
|
||||
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
|
||||
|
||||
private:
|
||||
static void _buildChangeObjectForPlayer(WorldObject*, UpdateDataMapType&);
|
||||
static void _buildPacket(Player*, Object*, UpdateDataMapType&);
|
||||
void _update();
|
||||
//Thread unsafe
|
||||
void Update(uint32 diff);
|
||||
void RemoveOldCorpses();
|
||||
void UnloadAll();
|
||||
|
||||
typedef std::unordered_map<uint64, Corpse*> Player2CorpsesMapType;
|
||||
typedef std::unordered_map<Player*, UpdateData>::value_type UpdateDataValueType;
|
||||
// pussywizard: crashfix for corpses
|
||||
void AddDelayedCorpseAction(Corpse* corpse, uint8 action, uint32 mapId = 0, uint32 instanceId = 0);
|
||||
void ProcessDelayedCorpseActions();
|
||||
|
||||
std::unordered_set<Object*> i_objects;
|
||||
Player2CorpsesMapType i_player2corpse;
|
||||
std::list<uint64> i_playerBones;
|
||||
private:
|
||||
static void _buildChangeObjectForPlayer(WorldObject*, UpdateDataMapType&);
|
||||
static void _buildPacket(Player*, Object*, UpdateDataMapType&);
|
||||
void _update();
|
||||
|
||||
ACE_Thread_Mutex i_objectLock;
|
||||
ACE_RW_Thread_Mutex i_corpseLock;
|
||||
std::list<DelayedCorpseAction> i_delayedCorpseActions;
|
||||
mutable ACE_Thread_Mutex DelayedCorpseLock;
|
||||
typedef std::unordered_map<uint64, Corpse*> Player2CorpsesMapType;
|
||||
typedef std::unordered_map<Player*, UpdateData>::value_type UpdateDataValueType;
|
||||
|
||||
std::unordered_set<Object*> i_objects;
|
||||
Player2CorpsesMapType i_player2corpse;
|
||||
std::list<uint64> i_playerBones;
|
||||
|
||||
ACE_Thread_Mutex i_objectLock;
|
||||
ACE_RW_Thread_Mutex i_corpseLock;
|
||||
std::list<DelayedCorpseAction> i_delayedCorpseActions;
|
||||
mutable ACE_Thread_Mutex DelayedCorpseLock;
|
||||
};
|
||||
|
||||
#define sObjectAccessor ObjectAccessor::instance()
|
||||
|
||||
Reference in New Issue
Block a user