Get rid of Trinity Singleton and Threading patterns and replace them with ACE_Singletons and ACE_GUARD_x macro´s with ACE_Thread_Mutex´es respectively.
Also get rid of unused CountedReference class that used Trinity threading pattern. --HG-- branch : trunk
This commit is contained in:
@@ -53,7 +53,7 @@ static void CorpsesEraseCallBack(QueryResult_AutoPtr result, bool bones)
|
||||
/// Resurrectable - convert corpses to bones
|
||||
if (!bones)
|
||||
{
|
||||
if (!ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid))
|
||||
if (!sObjectAccessor.ConvertCorpseForPlayer(player_guid))
|
||||
{
|
||||
sLog.outDebug("Corpse %u not found in world or bones creating forbidden. Delete from DB.",guidlow);
|
||||
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
|
||||
@@ -62,7 +62,7 @@ static void CorpsesEraseCallBack(QueryResult_AutoPtr result, bool bones)
|
||||
else
|
||||
///- or delete bones
|
||||
{
|
||||
MapManager::Instance().RemoveBonesFromMap(mapid, guid, positionX, positionY);
|
||||
sMapMgr.RemoveBonesFromMap(mapid, guid, positionX, positionY);
|
||||
|
||||
///- remove bones from the database
|
||||
CharacterDatabase.PExecute("DELETE FROM corpse WHERE guid = '%u'",guidlow);
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "SingletonImp.h"
|
||||
|
||||
#include "Player.h"
|
||||
#include "Creature.h"
|
||||
#include "GameObject.h"
|
||||
@@ -41,10 +41,6 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#define CLASS_LOCK Trinity::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex>
|
||||
INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK);
|
||||
INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ACE_Thread_Mutex);
|
||||
|
||||
ObjectAccessor::ObjectAccessor()
|
||||
{
|
||||
}
|
||||
@@ -151,7 +147,7 @@ Player* ObjectAccessor::FindPlayer(uint64 guid)
|
||||
|
||||
Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||
{
|
||||
Guard guard(*HashMapHolder<Player>::GetLock());
|
||||
ACE_GUARD_RETURN(LockType, g, *HashMapHolder<Player>::GetLock(), NULL);
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
for (HashMapHolder<Player>::MapType::iterator iter = m.begin(); iter != m.end(); ++iter)
|
||||
if (iter->second->IsInWorld() && strcmp(name, iter->second->GetName()) == 0)
|
||||
@@ -162,7 +158,7 @@ Player* ObjectAccessor::FindPlayerByName(const char* name)
|
||||
|
||||
void ObjectAccessor::SaveAllPlayers()
|
||||
{
|
||||
Guard guard(*HashMapHolder<Player>::GetLock());
|
||||
ACE_GUARD(LockType, g, *HashMapHolder<Player>::GetLock());
|
||||
HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
|
||||
for (HashMapHolder<Player>::MapType::iterator itr = m.begin(); itr != m.end(); ++itr)
|
||||
itr->second->SaveToDB();
|
||||
@@ -175,7 +171,7 @@ Pet* ObjectAccessor::GetPet(uint64 guid)
|
||||
|
||||
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
|
||||
{
|
||||
Guard guard(i_corpseGuard);
|
||||
ACE_GUARD_RETURN(LockType, guard, i_corpseGuard, NULL);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
|
||||
if (iter == i_player2corpse.end())
|
||||
@@ -197,7 +193,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
Guard guard(i_corpseGuard);
|
||||
ACE_GUARD(LockType, g, i_corpseGuard);
|
||||
|
||||
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
|
||||
if (iter == i_player2corpse.end()) // TODO: Fix this
|
||||
@@ -219,7 +215,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
Guard guard(i_corpseGuard);
|
||||
ACE_GUARD(LockType, g, i_corpseGuard);
|
||||
|
||||
assert(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
|
||||
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
|
||||
@@ -234,7 +230,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
|
||||
|
||||
void ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map)
|
||||
{
|
||||
Guard guard(i_corpseGuard);
|
||||
ACE_GUARD(LockType, g, i_corpseGuard);
|
||||
|
||||
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
|
||||
{
|
||||
@@ -274,7 +270,7 @@ Corpse* ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool /*insign
|
||||
// done in removecorpse
|
||||
// remove resurrectable corpse from grid object registry (loaded state checked into call)
|
||||
// do not load the map if it's not loaded
|
||||
//Map *map = MapManager::Instance().FindMap(corpse->GetMapId(), corpse->GetInstanceId());
|
||||
//Map *map = sMapMgr.FindMap(corpse->GetMapId(), corpse->GetInstanceId());
|
||||
//if (map)
|
||||
// map->Remove(corpse, false);
|
||||
|
||||
@@ -333,7 +329,7 @@ void ObjectAccessor::Update(uint32 /*diff*/)
|
||||
|
||||
// Critical section
|
||||
{
|
||||
Guard guard(i_updateGuard);
|
||||
ACE_GUARD(LockType, g, i_updateGuard);
|
||||
|
||||
while (!i_objects.empty())
|
||||
{
|
||||
|
||||
@@ -22,10 +22,9 @@
|
||||
#define TRINITY_OBJECTACCESSOR_H
|
||||
|
||||
#include "Define.h"
|
||||
#include "Singleton.h"
|
||||
#include <ace/Singleton.h>
|
||||
#include <ace/Thread_Mutex.h>
|
||||
#include "UnorderedMap.h"
|
||||
#include "ThreadingModel.h"
|
||||
|
||||
#include "UpdateData.h"
|
||||
|
||||
@@ -50,23 +49,22 @@ class HashMapHolder
|
||||
|
||||
typedef UNORDERED_MAP<uint64, T*> MapType;
|
||||
typedef ACE_Thread_Mutex LockType;
|
||||
typedef Trinity::GeneralLock<LockType> Guard;
|
||||
|
||||
static void Insert(T* o)
|
||||
{
|
||||
Guard guard(i_lock);
|
||||
ACE_GUARD(LockType, Guard, i_lock);
|
||||
m_objectMap[o->GetGUID()] = o;
|
||||
}
|
||||
|
||||
static void Remove(T* o)
|
||||
{
|
||||
Guard guard(i_lock);
|
||||
ACE_GUARD(LockType, Guard, i_lock);
|
||||
m_objectMap.erase(o->GetGUID());
|
||||
}
|
||||
|
||||
static T* Find(uint64 guid)
|
||||
{
|
||||
Guard guard(i_lock);
|
||||
ACE_GUARD_RETURN(LockType, Guard, i_lock, NULL);
|
||||
typename MapType::iterator itr = m_objectMap.find(guid);
|
||||
return (itr != m_objectMap.end()) ? itr->second : NULL;
|
||||
}
|
||||
@@ -84,9 +82,9 @@ class HashMapHolder
|
||||
static MapType m_objectMap;
|
||||
};
|
||||
|
||||
class ObjectAccessor : public Trinity::Singleton<ObjectAccessor, Trinity::ClassLevelLockable<ObjectAccessor, ACE_Thread_Mutex> >
|
||||
class ObjectAccessor
|
||||
{
|
||||
friend class Trinity::OperatorNew<ObjectAccessor>;
|
||||
friend class ACE_Singleton<ObjectAccessor, ACE_Thread_Mutex>;
|
||||
ObjectAccessor();
|
||||
~ObjectAccessor();
|
||||
ObjectAccessor(const ObjectAccessor&);
|
||||
@@ -220,13 +218,13 @@ class ObjectAccessor : public Trinity::Singleton<ObjectAccessor, Trinity::ClassL
|
||||
|
||||
void AddUpdateObject(Object* obj)
|
||||
{
|
||||
Guard guard(i_updateGuard);
|
||||
ACE_GUARD(LockType, Guard, i_updateGuard);
|
||||
i_objects.insert(obj);
|
||||
}
|
||||
|
||||
void RemoveUpdateObject(Object* obj)
|
||||
{
|
||||
Guard guard(i_updateGuard);
|
||||
ACE_GUARD(LockType, Guard, i_updateGuard);
|
||||
i_objects.erase(obj);
|
||||
}
|
||||
|
||||
@@ -239,7 +237,6 @@ class ObjectAccessor : public Trinity::Singleton<ObjectAccessor, Trinity::ClassL
|
||||
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);
|
||||
|
||||
typedef ACE_Thread_Mutex LockType;
|
||||
typedef Trinity::GeneralLock<LockType> Guard;
|
||||
|
||||
private:
|
||||
|
||||
@@ -254,4 +251,6 @@ class ObjectAccessor : public Trinity::Singleton<ObjectAccessor, Trinity::ClassL
|
||||
LockType i_updateGuard;
|
||||
LockType i_corpseGuard;
|
||||
};
|
||||
|
||||
#define sObjectAccessor (*ACE_Singleton<ObjectAccessor, ACE_Thread_Mutex>::instance())
|
||||
#endif
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include "DatabaseEnv.h"
|
||||
#include "SQLStorage.h"
|
||||
#include "SQLStorageImpl.h"
|
||||
#include "SingletonImp.h"
|
||||
|
||||
#include "Log.h"
|
||||
#include "MapManager.h"
|
||||
#include "ObjectMgr.h"
|
||||
@@ -48,8 +46,6 @@
|
||||
#include "Vehicle.h"
|
||||
#include "AchievementMgr.h"
|
||||
|
||||
INSTANTIATE_SINGLETON_1(ObjectMgr);
|
||||
|
||||
ScriptMapMap sQuestEndScripts;
|
||||
ScriptMapMap sQuestStartScripts;
|
||||
ScriptMapMap sSpellScripts;
|
||||
@@ -1412,7 +1408,7 @@ uint32 ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, float y, float
|
||||
if (!goinfo)
|
||||
return 0;
|
||||
|
||||
Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(mapId));
|
||||
Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(mapId));
|
||||
if (!map)
|
||||
return 0;
|
||||
|
||||
@@ -1473,7 +1469,7 @@ bool ObjectMgr::MoveCreData(uint32 guid, uint32 mapId, Position pos)
|
||||
AddCreatureToGrid(guid, &data);
|
||||
|
||||
// Spawn if necessary (loaded grids only)
|
||||
if (Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(mapId)))
|
||||
if (Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(mapId)))
|
||||
{
|
||||
// We use spawn coords to spawn
|
||||
if (!map->Instanceable() && map->IsLoaded(data.posX, data.posY))
|
||||
@@ -1524,7 +1520,7 @@ uint32 ObjectMgr::AddCreData(uint32 entry, uint32 /*team*/, uint32 mapId, float
|
||||
AddCreatureToGrid(guid, &data);
|
||||
|
||||
// Spawn if necessary (loaded grids only)
|
||||
if (Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(mapId)))
|
||||
if (Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(mapId)))
|
||||
{
|
||||
// We use spawn coords to spawn
|
||||
if (!map->Instanceable() && !map->IsRemovalGrid(x, y))
|
||||
@@ -5547,7 +5543,7 @@ void ObjectMgr::LoadGraveyardZones()
|
||||
WorldSafeLocsEntry const *ObjectMgr::GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team)
|
||||
{
|
||||
// search for zone associated closest graveyard
|
||||
uint32 zoneId = MapManager::Instance().GetZoneId(MapId,x,y,z);
|
||||
uint32 zoneId = sMapMgr.GetZoneId(MapId,x,y,z);
|
||||
|
||||
// Simulate std. algorithm:
|
||||
// found some graveyard associated to (ghost_zone,ghost_map)
|
||||
@@ -6608,7 +6604,7 @@ void ObjectMgr::LoadCorpses()
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectAccessor::Instance().AddCorpse(corpse);
|
||||
sObjectAccessor.AddCorpse(corpse);
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "Map.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectDefines.h"
|
||||
#include "Singleton.h"
|
||||
#include "ace/Singleton.h"
|
||||
#include "SQLStorage.h"
|
||||
#include "Vehicle.h"
|
||||
#include "ObjectMgr.h"
|
||||
@@ -354,11 +354,11 @@ class PlayerDumpReader;
|
||||
class ObjectMgr
|
||||
{
|
||||
friend class PlayerDumpReader;
|
||||
|
||||
friend class ACE_Singleton<ObjectMgr, ACE_Null_Mutex>;
|
||||
ObjectMgr();
|
||||
~ObjectMgr();
|
||||
|
||||
public:
|
||||
ObjectMgr();
|
||||
~ObjectMgr();
|
||||
|
||||
typedef UNORDERED_MAP<uint32, Item*> ItemMap;
|
||||
|
||||
typedef std::set< Group * > GroupSet;
|
||||
@@ -382,7 +382,7 @@ class ObjectMgr
|
||||
|
||||
typedef std::vector<std::string> ScriptNameMap;
|
||||
|
||||
Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
|
||||
Player* GetPlayer(const char* name) const { return sObjectAccessor.FindPlayerByName(name);}
|
||||
Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
|
||||
|
||||
static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
|
||||
@@ -1083,7 +1083,7 @@ class ObjectMgr
|
||||
|
||||
};
|
||||
|
||||
#define objmgr Trinity::Singleton<ObjectMgr>::Instance()
|
||||
#define objmgr (*ACE_Singleton<ObjectMgr, ACE_Null_Mutex>::instance())
|
||||
|
||||
// scripting access functions
|
||||
bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = MAX_CREATURE_AI_TEXT_STRING_ID, int32 end_value = std::numeric_limits<int32>::min());
|
||||
|
||||
Reference in New Issue
Block a user