diff options
109 files changed, 349 insertions, 1221 deletions
diff --git a/src/server/game/AI/CreatureAISelector.cpp b/src/server/game/AI/CreatureAISelector.cpp index 79977fab5b1..8283baf87f9 100644 --- a/src/server/game/AI/CreatureAISelector.cpp +++ b/src/server/game/AI/CreatureAISelector.cpp @@ -21,22 +21,19 @@ #include "Creature.h" #include "CreatureAISelector.h" #include "PassiveAI.h" -#include "SingletonImp.h" + #include "MovementGenerator.h" #include "Pet.h" #include "TemporarySummon.h" #include "CreatureAIFactory.h" #include "ScriptMgr.h" -INSTANTIATE_SINGLETON_1(CreatureAIRegistry); -INSTANTIATE_SINGLETON_1(MovementGeneratorRegistry); - namespace FactorySelector { CreatureAI* selectAI(Creature *creature) { const CreatureAICreator *ai_factory = NULL; - CreatureAIRegistry &ai_registry(CreatureAIRepository::Instance()); + CreatureAIRegistry& ai_registry(*CreatureAIRepository::instance()); if (creature->isPet()) ai_factory = ai_registry.GetRegistryItem("PetAI"); @@ -106,7 +103,7 @@ namespace FactorySelector MovementGenerator* selectMovementGenerator(Creature *creature) { - MovementGeneratorRegistry &mv_registry(MovementGeneratorRepository::Instance()); + MovementGeneratorRegistry& mv_registry(*MovementGeneratorRepository::instance()); assert(creature->GetCreatureInfo() != NULL); const MovementGeneratorCreator *mv_factory = mv_registry.GetRegistryItem(creature->GetDefaultMovementType()); diff --git a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp index 8c71f5e5765..9f4105050ae 100644 --- a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp +++ b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp @@ -23,13 +23,10 @@ #include "CreatureEventAIMgr.h" #include "ObjectMgr.h" #include "ProgressBar.h" -#include "SingletonImp.h" #include "ObjectDefines.h" #include "GridDefines.h" #include "ConditionMgr.h" -INSTANTIATE_SINGLETON_1(CreatureEventAIMgr); - // ------------------- void CreatureEventAIMgr::LoadCreatureEventAI_Texts() { diff --git a/src/server/game/AI/EventAI/CreatureEventAIMgr.h b/src/server/game/AI/EventAI/CreatureEventAIMgr.h index ef191b22463..3c8181e9e74 100644 --- a/src/server/game/AI/EventAI/CreatureEventAIMgr.h +++ b/src/server/game/AI/EventAI/CreatureEventAIMgr.h @@ -24,8 +24,9 @@ class CreatureEventAIMgr { + friend class ACE_Singleton<CreatureEventAIMgr, ACE_Null_Mutex>; + CreatureEventAIMgr(){}; public: - CreatureEventAIMgr(){}; ~CreatureEventAIMgr(){}; void LoadCreatureEventAI_Texts(); @@ -42,5 +43,5 @@ class CreatureEventAIMgr CreatureEventAI_TextMap m_CreatureEventAI_TextMap; }; -#define CreatureEAI_Mgr Trinity::Singleton<CreatureEventAIMgr>::Instance() +#define CreatureEAI_Mgr (*ACE_Singleton<CreatureEventAIMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 18372677120..54f80114131 100644 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -19,7 +19,7 @@ */ #include "DatabaseEnv.h" -#include "SingletonImp.h" + #include "AccountMgr.h" #include "ObjectAccessor.h" @@ -29,8 +29,6 @@ extern DatabaseType LoginDatabase; -INSTANTIATE_SINGLETON_1(AccountMgr); - AccountMgr::AccountMgr() {} diff --git a/src/server/game/Accounts/AccountMgr.h b/src/server/game/Accounts/AccountMgr.h index f770e24d902..a0e181cf4a0 100644 --- a/src/server/game/Accounts/AccountMgr.h +++ b/src/server/game/Accounts/AccountMgr.h @@ -24,7 +24,6 @@ #include <string> #include "Common.h" -#include "Singleton.h" enum AccountOpResult { @@ -59,6 +58,6 @@ class AccountMgr static bool normalizeString(std::string& utf8str); }; -#define accmgr Trinity::Singleton<AccountMgr>::Instance() +#define accmgr (*ACE_Singleton<AccountMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index 41b9acfff2c..137c22634fa 100644 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -22,7 +22,7 @@ #include "World.h" #include "WorldPacket.h" #include "DatabaseEnv.h" -#include "SingletonImp.h" + #include "AchievementMgr.h" #include "ArenaTeam.h" @@ -41,8 +41,6 @@ #include "Map.h" #include "InstanceData.h" -INSTANTIATE_SINGLETON_1(AchievementGlobalMgr); - namespace Trinity { class AchievementChatBuilder @@ -965,7 +963,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui if (!miscvalue1) continue; - Map const* map = GetPlayer()->IsInWorld() ? GetPlayer()->GetMap() : MapManager::Instance().FindMap(GetPlayer()->GetMapId(), GetPlayer()->GetInstanceId()); + Map const* map = GetPlayer()->IsInWorld() ? GetPlayer()->GetMap() : sMapMgr.FindMap(GetPlayer()->GetMapId(), GetPlayer()->GetInstanceId()); if (!map || !map->IsDungeon()) continue; diff --git a/src/server/game/Achievements/AchievementMgr.h b/src/server/game/Achievements/AchievementMgr.h index 97dbc86396e..0eedf971c20 100644 --- a/src/server/game/Achievements/AchievementMgr.h +++ b/src/server/game/Achievements/AchievementMgr.h @@ -22,7 +22,7 @@ #include <string> #include "Common.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "DatabaseEnv.h" #include "DBCEnums.h" #include "DBCStores.h" @@ -342,6 +342,6 @@ class AchievementGlobalMgr AchievementRewardLocales m_achievementRewardLocales; }; -#define achievementmgr Trinity::Singleton<AchievementGlobalMgr>::Instance() +#define achievementmgr (*ACE_Singleton<AchievementGlobalMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Addons/AddonMgr.cpp b/src/server/game/Addons/AddonMgr.cpp index b7b1d2e9333..9bc28f845ac 100644 --- a/src/server/game/Addons/AddonMgr.cpp +++ b/src/server/game/Addons/AddonMgr.cpp @@ -19,7 +19,7 @@ */ #include "DatabaseEnv.h" -#include "SingletonImp.h" + #include "AddonMgr.h" #include "ObjectAccessor.h" @@ -30,8 +30,6 @@ extern DatabaseType LoginDatabase; -INSTANTIATE_SINGLETON_1(AddonMgr); - AddonMgr::AddonMgr() { } diff --git a/src/server/game/Addons/AddonMgr.h b/src/server/game/Addons/AddonMgr.h index 0d648794416..90232cc3f2b 100644 --- a/src/server/game/Addons/AddonMgr.h +++ b/src/server/game/Addons/AddonMgr.h @@ -22,7 +22,7 @@ #define _ADDONMGR_H #include "Common.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include <string> @@ -68,9 +68,10 @@ typedef std::list<SavedAddon> SavedAddonsList; class AddonMgr { + friend class ACE_Singleton<AddonMgr, ACE_Null_Mutex>; + AddonMgr(); public: - AddonMgr(); ~AddonMgr(); void LoadFromDB(); @@ -83,7 +84,7 @@ class AddonMgr SavedAddonsList m_knownAddons; // Known addons. }; -#define sAddonMgr Trinity::Singleton<AddonMgr>::Instance() +#define sAddonMgr (*ACE_Singleton<AddonMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.cpp b/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.cpp index e9cf8f21ab2..ce621e689cd 100644 --- a/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.cpp @@ -3,8 +3,7 @@ #include "AuctionHouseBot.h" #include <vector> -#include "SingletonImp.h" -INSTANTIATE_SINGLETON_1(AuctionHouseBot); + using namespace std; vector<uint32> npcItems; @@ -693,7 +692,7 @@ void AuctionHouseBot::Update() WorldSession _session(AHBplayerAccount, NULL, SEC_PLAYER, true, 0, LOCALE_enUS); Player _AHBplayer(&_session); _AHBplayer.Initialize(AHBplayerGUID); - ObjectAccessor::Instance().AddObject(&_AHBplayer); + sObjectAccessor.AddObject(&_AHBplayer); // Add New Bids if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) @@ -725,7 +724,7 @@ void AuctionHouseBot::Update() addNewAuctionBuyerBotBid(&_AHBplayer, &NeutralConfig, &_session); _lastrun_n = _newrun; } - ObjectAccessor::Instance().RemoveObject(&_AHBplayer); + sObjectAccessor.RemoveObject(&_AHBplayer); } void AuctionHouseBot::Initialize() diff --git a/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.h b/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.h index f29a8762513..853955a43a0 100644 --- a/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.h +++ b/src/server/game/AuctionHouse/AuctionHouseBot/AuctionHouseBot.h @@ -1207,9 +1207,11 @@ private: inline uint32 minValue(uint32 a, uint32 b) { return a <= b ? a : b; }; void addNewAuctions(Player *AHBplayer, AHBConfig *config); void addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *config, WorldSession *session); + + friend class ACE_Singleton<AuctionHouseBot, ACE_Null_Mutex>; + AuctionHouseBot(); public: - AuctionHouseBot(); ~AuctionHouseBot(); void Update(); void Initialize(); @@ -1220,6 +1222,6 @@ public: uint32 GetAHBplayerGUID() { return AHBplayerGUID; }; }; -#define auctionbot Trinity::Singleton<AuctionHouseBot>::Instance() +#define auctionbot (*ACE_Singleton<AuctionHouseBot, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp index 744df2cb6e7..38874336cc4 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp @@ -24,7 +24,7 @@ #include "WorldSession.h" #include "DatabaseEnv.h" #include "SQLStorage.h" -#include "SingletonImp.h" + #include "DBCStores.h" #include "AccountMgr.h" @@ -35,8 +35,6 @@ #include "ProgressBar.h" #include <vector> -INSTANTIATE_SINGLETON_1(AuctionHouseMgr); - using namespace std; AuctionHouseMgr::AuctionHouseMgr() diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index 7048e419c36..f0eda8f4fc4 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -21,7 +21,7 @@ #ifndef _AUCTION_HOUSE_MGR_H #define _AUCTION_HOUSE_MGR_H -#include "Singleton.h" +#include "ace/Singleton.h" #include "SharedDefines.h" @@ -121,51 +121,53 @@ class AuctionHouseObject class AuctionHouseMgr { - public: + friend class ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>; AuctionHouseMgr(); - ~AuctionHouseMgr(); + + public: + ~AuctionHouseMgr(); - typedef UNORDERED_MAP<uint32, Item*> ItemMap; + typedef UNORDERED_MAP<uint32, Item*> ItemMap; - AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId); - AuctionHouseObject* GetBidsMap(uint32 factionTemplateId); + AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId); + AuctionHouseObject* GetBidsMap(uint32 factionTemplateId); - Item* GetAItem(uint32 id) - { - ItemMap::const_iterator itr = mAitems.find(id); - if (itr != mAitems.end()) + Item* GetAItem(uint32 id) { - return itr->second; + ItemMap::const_iterator itr = mAitems.find(id); + if (itr != mAitems.end()) + { + return itr->second; + } + return NULL; } - return NULL; - } - //auction messages - void SendAuctionWonMail(AuctionEntry * auction); - void SendAuctionSalePendingMail(AuctionEntry * auction); - void SendAuctionSuccessfulMail(AuctionEntry * auction); - void SendAuctionExpiredMail(AuctionEntry * auction); - static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem); - static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId); + //auction messages + void SendAuctionWonMail(AuctionEntry * auction); + void SendAuctionSalePendingMail(AuctionEntry * auction); + void SendAuctionSuccessfulMail(AuctionEntry * auction); + void SendAuctionExpiredMail(AuctionEntry * auction); + static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem); + static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId); - public: + public: //load first auction items, because of check if item exists, when loading - void LoadAuctionItems(); - void LoadAuctions(); + void LoadAuctionItems(); + void LoadAuctions(); - void AddAItem(Item* it); - bool RemoveAItem(uint32 id); + void AddAItem(Item* it); + bool RemoveAItem(uint32 id); - void Update(); + void Update(); - private: - AuctionHouseObject mHordeAuctions; - AuctionHouseObject mAllianceAuctions; - AuctionHouseObject mNeutralAuctions; + private: + AuctionHouseObject mHordeAuctions; + AuctionHouseObject mAllianceAuctions; + AuctionHouseObject mNeutralAuctions; - ItemMap mAitems; + ItemMap mAitems; }; -#define auctionmgr Trinity::Singleton<AuctionHouseMgr>::Instance() +#define auctionmgr (*ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/BattleGrounds/BattleGround.cpp b/src/server/game/BattleGrounds/BattleGround.cpp index 591417c8fea..86125ac5bfe 100644 --- a/src/server/game/BattleGrounds/BattleGround.cpp +++ b/src/server/game/BattleGrounds/BattleGround.cpp @@ -323,7 +323,7 @@ void BattleGround::Update(uint32 diff) plr->ResurrectPlayer(1.0f); plr->CastSpell(plr, 6962, true); plr->CastSpell(plr, SPELL_SPIRIT_HEAL_MANA, true); - ObjectAccessor::Instance().ConvertCorpseForPlayer(*itr); + sObjectAccessor.ConvertCorpseForPlayer(*itr); } m_ResurrectQueue.clear(); } @@ -1525,7 +1525,7 @@ Creature* BattleGround::AddCreature(uint32 entry, uint32 type, uint32 teamval, f /* void BattleGround::SpawnBGCreature(uint32 type, uint32 respawntime) { - Map * map = MapManager::Instance().FindMap(GetMapId(),GetInstanceId()); + Map * map = sMapMgr.FindMap(GetMapId(),GetInstanceId()); if (!map) return false; diff --git a/src/server/game/BattleGrounds/BattleGroundMgr.cpp b/src/server/game/BattleGrounds/BattleGroundMgr.cpp index ea2d0c2f920..84891dcf2df 100644 --- a/src/server/game/BattleGrounds/BattleGroundMgr.cpp +++ b/src/server/game/BattleGrounds/BattleGroundMgr.cpp @@ -22,7 +22,7 @@ #include "ObjectMgr.h" #include "World.h" #include "WorldPacket.h" -#include "SingletonImp.h" + #include "ArenaTeam.h" #include "BattleGroundMgr.h" @@ -49,8 +49,6 @@ #include "SharedDefines.h" #include "Formulas.h" -INSTANTIATE_SINGLETON_1(BattleGroundMgr); - /*********************************************************/ /*** BATTLEGROUND QUEUE SYSTEM ***/ /*********************************************************/ @@ -1630,7 +1628,7 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI } // generate a new instance id - bg->SetInstanceID(MapManager::Instance().GenerateInstanceId()); // set instance id + bg->SetInstanceID(sMapMgr.GenerateInstanceId()); // set instance id bg->SetClientInstanceID(CreateClientVisibleInstanceId(isRandom ? BATTLEGROUND_RB : bgTypeId, bracketEntry->GetBracketId())); // reset the new bg (set status to status_wait_queue from status_none) diff --git a/src/server/game/BattleGrounds/BattleGroundMgr.h b/src/server/game/BattleGrounds/BattleGroundMgr.h index 5319ce85752..40dfc39b5e5 100644 --- a/src/server/game/BattleGrounds/BattleGroundMgr.h +++ b/src/server/game/BattleGrounds/BattleGroundMgr.h @@ -22,7 +22,7 @@ #define __BATTLEGROUNDMGR_H #include "Common.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "DBCEnums.h" #include "BattleGround.h" @@ -180,9 +180,12 @@ class BGQueueRemoveEvent : public BasicEvent class BattleGroundMgr { + /// Todo: Thread safety? + /* Construction */ + friend class ACE_Singleton<BattleGroundMgr, ACE_Null_Mutex>; + BattleGroundMgr(); + public: - /* Construction */ - BattleGroundMgr(); ~BattleGroundMgr(); void Update(uint32 diff); @@ -271,6 +274,6 @@ class BattleGroundMgr bool m_Testing; }; -#define sBattleGroundMgr Trinity::Singleton<BattleGroundMgr>::Instance() +#define sBattleGroundMgr (*ACE_Singleton<BattleGroundMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Chat/Channels/ChannelMgr.cpp b/src/server/game/Chat/Channels/ChannelMgr.cpp index b26a42aa2b1..b72a2698d3a 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.cpp +++ b/src/server/game/Chat/Channels/ChannelMgr.cpp @@ -17,21 +17,18 @@ */ #include "ChannelMgr.h" -#include "SingletonImp.h" -#include "World.h" -INSTANTIATE_SINGLETON_1(AllianceChannelMgr); -INSTANTIATE_SINGLETON_1(HordeChannelMgr); +#include "World.h" ChannelMgr* channelMgr(uint32 team) { if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) - return &Trinity::Singleton<AllianceChannelMgr>::Instance(); // cross-faction + return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance(); // cross-faction if (team == ALLIANCE) - return &Trinity::Singleton<AllianceChannelMgr>::Instance(); + return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance(); if (team == HORDE) - return &Trinity::Singleton<HordeChannelMgr>::Instance(); + return ACE_Singleton<HordeChannelMgr, ACE_Null_Mutex>::instance(); return NULL; } diff --git a/src/server/game/Chat/Channels/ChannelMgr.h b/src/server/game/Chat/Channels/ChannelMgr.h index 1997eb76108..c4e872de6b6 100644 --- a/src/server/game/Chat/Channels/ChannelMgr.h +++ b/src/server/game/Chat/Channels/ChannelMgr.h @@ -22,7 +22,7 @@ #include "Common.h" #include "Channel.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include <map> #include <string> diff --git a/src/server/game/Chat/Commands/Level0.cpp b/src/server/game/Chat/Commands/Level0.cpp index bed8e3ee23f..53f2341c5af 100644 --- a/src/server/game/Chat/Commands/Level0.cpp +++ b/src/server/game/Chat/Commands/Level0.cpp @@ -165,8 +165,8 @@ bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/) { bool first = true; - ObjectAccessor::Guard guard(*HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType &m = ObjectAccessor::Instance().GetPlayers(); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true); + HashMapHolder<Player>::MapType &m = sObjectAccessor.GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { AccountTypes itr_sec = itr->second->GetSession()->GetSecurity(); diff --git a/src/server/game/Chat/Commands/Level1.cpp b/src/server/game/Chat/Commands/Level1.cpp index a9f1e7d9c15..771339645fe 100644 --- a/src/server/game/Chat/Commands/Level1.cpp +++ b/src/server/game/Chat/Commands/Level1.cpp @@ -2381,7 +2381,7 @@ bool ChatHandler::HandleWhispersCommand(const char* args) //Save all players in the world bool ChatHandler::HandleSaveAllCommand(const char* /*args*/) { - ObjectAccessor::Instance().SaveAllPlayers(); + sObjectAccessor.SaveAllPlayers(); SendSysMessage(LANG_PLAYERS_SAVED); return true; } @@ -2502,7 +2502,7 @@ bool ChatHandler::HandleTeleNameCommand(const char * args) PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetTrinityString(LANG_OFFLINE), tele->name.c_str()); Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation, - MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid); + sMapMgr.GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid); } return true; @@ -2768,7 +2768,7 @@ bool ChatHandler::HandleGoXYCommand(const char* args) else _player->SaveRecallPosition(); - Map const *map = MapManager::Instance().CreateBaseMap(mapid); + Map const *map = sMapMgr.CreateBaseMap(mapid); float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y)); _player->TeleportTo(mapid, x, y, z, _player->GetOrientation()); @@ -2861,7 +2861,7 @@ bool ChatHandler::HandleGoZoneXYCommand(const char* args) // update to parent zone if exist (client map show only zones without parents) AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry; - Map const *map = MapManager::Instance().CreateBaseMap(zoneEntry->mapid); + Map const *map = sMapMgr.CreateBaseMap(zoneEntry->mapid); if (map->Instanceable()) { @@ -2936,7 +2936,7 @@ bool ChatHandler::HandleGoGridCommand(const char* args) else _player->SaveRecallPosition(); - Map const *map = MapManager::Instance().CreateBaseMap(mapid); + Map const *map = sMapMgr.CreateBaseMap(mapid); float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y)); _player->TeleportTo(mapid, x, y, z, _player->GetOrientation()); diff --git a/src/server/game/Chat/Commands/Level2.cpp b/src/server/game/Chat/Commands/Level2.cpp index 5d67ec06660..90c7d5ef8ae 100644 --- a/src/server/game/Chat/Commands/Level2.cpp +++ b/src/server/game/Chat/Commands/Level2.cpp @@ -2844,7 +2844,7 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); wpCreature2->LoadFromDB(wpCreature2->GetDBTableGUIDLow(), map); map->Add(wpCreature2); - //MapManager::Instance().GetMap(npcCreature->GetMapId())->Add(wpCreature2); + //sMapMgr.GetMap(npcCreature->GetMapId())->Add(wpCreature2); } WorldDatabase.PExecuteLog("UPDATE waypoint_data SET position_x = '%f',position_y = '%f',position_z = '%f' where id = '%u' AND point='%u'", diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 009a4483f83..3ddf9b84365 100644 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -689,7 +689,7 @@ bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/) { sLog.outString("Re-Loading config settings..."); sWorld.LoadConfigSettings(true); - MapManager::Instance().InitializeVisibilityDistanceInfo(); + sMapMgr.InitializeVisibilityDistanceInfo(); SendGlobalGMSysMessage("World config settings reloaded."); return true; } @@ -4513,7 +4513,7 @@ bool ChatHandler::HandleReviveCommand(const char *args) } else // will resurrected at login without corpse - ObjectAccessor::Instance().ConvertCorpseForPlayer(target_guid); + sObjectAccessor.ConvertCorpseForPlayer(target_guid); return true; } @@ -5533,8 +5533,8 @@ bool ChatHandler::HandleResetAllCommand(const char * args) CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin); - ObjectAccessor::Guard guard(*HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers(); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, *HashMapHolder<Player>::GetLock(), true); + HashMapHolder<Player>::MapType const& plist = sObjectAccessor.GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr) itr->second->SetAtLoginFlag(atLogin); @@ -7020,8 +7020,8 @@ bool ChatHandler::HandleInstanceUnbindCommand(const char *args) bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/) { - PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances()); - PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances()); + PSendSysMessage("instances loaded: %d", sMapMgr.GetNumInstances()); + PSendSysMessage("players in instances: %d", sMapMgr.GetNumPlayersInInstances()); PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves()); PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal()); PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal()); diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index cb35d35c63f..2e81aad1859 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -19,7 +19,7 @@ */ -#include "SingletonImp.h" + #include "Player.h" #include "SpellAuras.h" #include "SpellMgr.h" @@ -29,8 +29,6 @@ #include "InstanceData.h" #include "ConditionMgr.h" -INSTANTIATE_SINGLETON_1(ConditionMgr); - // Checks if player meets the condition // Can have CONDITION_SOURCE_TYPE_NONE && !mReferenceId if called from a special event (ie: eventAI) bool Condition::Meets(Player * player, Unit* targetOverride) diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h index 2c7c44ecf7f..bb9fc2708fa 100644 --- a/src/server/game/Conditions/ConditionMgr.h +++ b/src/server/game/Conditions/ConditionMgr.h @@ -121,8 +121,10 @@ typedef std::map<uint32, ConditionList > ConditionReferenceMap;//only used for r class ConditionMgr { + friend class ACE_Singleton<ConditionMgr, ACE_Null_Mutex>; + ConditionMgr(); + public: - ConditionMgr(); ~ConditionMgr(); void LoadConditions(bool isReload = false); @@ -165,6 +167,6 @@ class ConditionMgr std::list<Condition*> m_AllocatedMemory; // some garbage collection :) }; -#define sConditionMgr Trinity::Singleton<ConditionMgr>::Instance() +#define sConditionMgr (*ACE_Singleton<ConditionMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index dc5a5b831fd..bc127cb309c 100755 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -19,7 +19,7 @@ */ #include "DBCStores.h" -#include "SingletonImp.h" + #include "Logging/Log.h" #include "ProgressBar.h" #include "SharedDefines.h" diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp index 1a2c9c9767c..6c089a83bc3 100644 --- a/src/server/game/DungeonFinding/LFGMgr.cpp +++ b/src/server/game/DungeonFinding/LFGMgr.cpp @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "SingletonImp.h" + #include "Common.h" #include "SharedDefines.h" #include "Group.h" @@ -24,8 +24,6 @@ #include "ObjectMgr.h" #include "WorldPacket.h" -INSTANTIATE_SINGLETON_1(LFGMgr); - /*********************************************************/ /*** LFG QUEUES ***/ /*********************************************************/ diff --git a/src/server/game/DungeonFinding/LFGMgr.h b/src/server/game/DungeonFinding/LFGMgr.h index a3d6fedc695..88d33743fa9 100644 --- a/src/server/game/DungeonFinding/LFGMgr.h +++ b/src/server/game/DungeonFinding/LFGMgr.h @@ -20,7 +20,7 @@ #define _LFGMGR_H #include "Common.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "Group.h" #include "LFG.h" @@ -237,43 +237,44 @@ typedef std::map<uint8, LFGQueue *> LFGQueueMap; class LFGMgr { -public: + friend class ACE_Singleton<LFGMgr, ACE_Null_Mutex>; LFGMgr(); - ~LFGMgr(); + public: + ~LFGMgr(); - void InitLFG(); - void SendLfgPlayerInfo(Player *plr); - void SendLfgPartyInfo(Player *plr); - void Join(Player *plr); - void Leave(Player *plr, Group *grp = NULL); - void UpdateRoleCheck(Group *grp, Player *plr = NULL); - void Update(uint32 diff); + void InitLFG(); + void SendLfgPlayerInfo(Player *plr); + void SendLfgPartyInfo(Player *plr); + void Join(Player *plr); + void Leave(Player *plr, Group *grp = NULL); + void UpdateRoleCheck(Group *grp, Player *plr = NULL); + void Update(uint32 diff); -private: - void BuildLfgRoleCheck(WorldPacket &data, LfgRoleCheck *pRoleCheck); - void BuildAvailableRandomDungeonList(WorldPacket &data, Player *plr); - void BuildRewardBlock(WorldPacket &data, uint32 dungeon, Player *plr); - void BuildPlayerLockDungeonBlock(WorldPacket &data, LfgLockStatusSet *lockSet); - void BuildPartyLockDungeonBlock(WorldPacket &data, LfgLockStatusMap *lockMap); - bool CheckGroupRoles(LfgRolesMap &groles, bool removeLeaderFlag = true); + private: + void BuildLfgRoleCheck(WorldPacket &data, LfgRoleCheck *pRoleCheck); + void BuildAvailableRandomDungeonList(WorldPacket &data, Player *plr); + void BuildRewardBlock(WorldPacket &data, uint32 dungeon, Player *plr); + void BuildPlayerLockDungeonBlock(WorldPacket &data, LfgLockStatusSet *lockSet); + void BuildPartyLockDungeonBlock(WorldPacket &data, LfgLockStatusMap *lockMap); + bool CheckGroupRoles(LfgRolesMap &groles, bool removeLeaderFlag = true); - LfgLockStatusMap* GetPartyLockStatusDungeons(Player *plr, LfgDungeonSet *dungeons); - LfgLockStatusSet* GetPlayerLockStatusDungeons(Player *plr, LfgDungeonSet *dungeons); - LfgDungeonSet* GetRandomDungeons(uint8 level, uint8 expansion); - LfgDungeonSet* GetDungeonsByRandom(uint32 randomdungeon); - LfgDungeonSet* GetAllDungeons(); - LfgReward* GetRandomDungeonReward(uint32 dungeon, bool done, uint8 level); - uint8 GetDungeonGroupType(uint32 dungeon); + LfgLockStatusMap* GetPartyLockStatusDungeons(Player *plr, LfgDungeonSet *dungeons); + LfgLockStatusSet* GetPlayerLockStatusDungeons(Player *plr, LfgDungeonSet *dungeons); + LfgDungeonSet* GetRandomDungeons(uint8 level, uint8 expansion); + LfgDungeonSet* GetDungeonsByRandom(uint32 randomdungeon); + LfgDungeonSet* GetAllDungeons(); + LfgReward* GetRandomDungeonReward(uint32 dungeon, bool done, uint8 level); + uint8 GetDungeonGroupType(uint32 dungeon); - LfgRewardList m_RewardList; - LfgRewardList m_RewardDoneList; - LfgDungeonMap m_DungeonsMap; + LfgRewardList m_RewardList; + LfgRewardList m_RewardDoneList; + LfgDungeonMap m_DungeonsMap; - LFGQueueMap m_Queues; - LfgRoleCheckMap m_RoleChecks; - uint32 m_QueueTimer; - bool m_update; + LFGQueueMap m_Queues; + LfgRoleCheckMap m_RoleChecks; + uint32 m_QueueTimer; + bool m_update; }; -#define sLFGMgr Trinity::Singleton<LFGMgr>::Instance() +#define sLFGMgr (*ACE_Singleton<LFGMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Entities/Corpse/Corpse.cpp b/src/server/game/Entities/Corpse/Corpse.cpp index 6d9e11104ab..2811cfa129f 100644 --- a/src/server/game/Entities/Corpse/Corpse.cpp +++ b/src/server/game/Entities/Corpse/Corpse.cpp @@ -54,7 +54,7 @@ void Corpse::AddToWorld() { ///- Register the corpse for guid lookup if (!IsInWorld()) - ObjectAccessor::Instance().AddObject(this); + sObjectAccessor.AddObject(this); Object::AddToWorld(); } @@ -63,7 +63,7 @@ void Corpse::RemoveFromWorld() { ///- Remove the corpse from the accessor if (IsInWorld()) - ObjectAccessor::Instance().RemoveObject(this); + sObjectAccessor.RemoveObject(this); Object::RemoveFromWorld(); } diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 62300e43a39..6570a418be9 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -49,7 +49,7 @@ #include "Vehicle.h" #include "SpellAuraEffects.h" // apply implementation of the singletons -#include "SingletonImp.h" + TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const { @@ -185,7 +185,7 @@ void Creature::AddToWorld() { if (m_zoneScript) m_zoneScript->OnCreatureCreate(this, true); - ObjectAccessor::Instance().AddObject(this); + sObjectAccessor.AddObject(this); Unit::AddToWorld(); SearchFormation(); AIM_Initialize(); @@ -203,7 +203,7 @@ void Creature::RemoveFromWorld() if (m_formation) formation_mgr.RemoveCreatureFromGroup(m_formation, this); Unit::RemoveFromWorld(); - ObjectAccessor::Instance().RemoveObject(this); + sObjectAccessor.RemoveObject(this); } } @@ -2410,7 +2410,7 @@ time_t Creature::GetLinkedCreatureRespawnTime() const if (data->mapid == GetMapId()) // look up on the same map targetMap = GetMap(); else // it shouldn't be instanceable map here - targetMap = MapManager::Instance().FindMap(data->mapid); + targetMap = sMapMgr.FindMap(data->mapid); } if (targetMap) return objmgr.GetCreatureRespawnTime(targetGuid,targetMap->GetInstanceId()); diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index a7c17561516..ae37ba56fd3 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -700,7 +700,7 @@ class Creature : public Unit, public GridObject<Creature> bool DisableReputationGain; - CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from ObjMgr::GetCreatureTemplate(GetEntry()) + CreatureInfo const* m_creatureInfo; // in difficulty mode > 0 can different from objmgr.::GetCreatureTemplate(GetEntry()) CreatureData const* m_creatureData; uint16 m_LootMode; // bitmask, default LOOT_MODE_DEFAULT, determines what loot will be lootable diff --git a/src/server/game/Entities/Creature/CreatureGroups.cpp b/src/server/game/Entities/Creature/CreatureGroups.cpp index 25aab942916..7bd05123ec5 100644 --- a/src/server/game/Entities/Creature/CreatureGroups.cpp +++ b/src/server/game/Entities/Creature/CreatureGroups.cpp @@ -22,13 +22,11 @@ #include "CreatureGroups.h" #include "ObjectMgr.h" #include "ProgressBar.h" -#include "SingletonImp.h" + #include "CreatureAI.h" #define MAX_DESYNC 5.0f -INSTANTIATE_SINGLETON_1(CreatureGroupManager); - CreatureGroupInfoType CreatureGroupMap; void CreatureGroupManager::AddCreatureToGroup(uint32 groupId, Creature *member) diff --git a/src/server/game/Entities/Creature/CreatureGroups.h b/src/server/game/Entities/Creature/CreatureGroups.h index 521586b7457..4aa49571b5d 100644 --- a/src/server/game/Entities/Creature/CreatureGroups.h +++ b/src/server/game/Entities/Creature/CreatureGroups.h @@ -35,12 +35,15 @@ struct FormationInfo class CreatureGroupManager { + friend class ACE_Singleton<CreatureGroupManager, ACE_Null_Mutex>; public: void AddCreatureToGroup(uint32 group_id, Creature *creature); void RemoveCreatureFromGroup(CreatureGroup *group, Creature *creature); void LoadCreatureFormations(); }; +#define formation_mgr (*ACE_Singleton<CreatureGroupManager, ACE_Null_Mutex>::instance()) + typedef UNORDERED_MAP<uint32/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType; extern CreatureGroupInfoType CreatureGroupMap; @@ -73,6 +76,4 @@ class CreatureGroup void MemberAttackStart(Creature* member, Unit *target); }; -#define formation_mgr Trinity::Singleton<CreatureGroupManager>::Instance() - #endif diff --git a/src/server/game/Entities/DynamicObject/DynamicObject.cpp b/src/server/game/Entities/DynamicObject/DynamicObject.cpp index 5c13fe47cb7..529710eda90 100644 --- a/src/server/game/Entities/DynamicObject/DynamicObject.cpp +++ b/src/server/game/Entities/DynamicObject/DynamicObject.cpp @@ -46,7 +46,7 @@ void DynamicObject::AddToWorld() ///- Register the dynamicObject for guid lookup if (!IsInWorld()) { - ObjectAccessor::Instance().AddObject(this); + sObjectAccessor.AddObject(this); WorldObject::AddToWorld(); } } @@ -69,7 +69,7 @@ void DynamicObject::RemoveFromWorld() } } WorldObject::RemoveFromWorld(); - ObjectAccessor::Instance().RemoveObject(this); + sObjectAccessor.RemoveObject(this); } } diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 364bc8ec29c..8783a8b5199 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -117,7 +117,7 @@ void GameObject::AddToWorld() if (m_zoneScript) m_zoneScript->OnGameObjectCreate(this, true); - ObjectAccessor::Instance().AddObject(this); + sObjectAccessor.AddObject(this); WorldObject::AddToWorld(); } } @@ -139,7 +139,7 @@ void GameObject::RemoveFromWorld() sLog.outError("Delete GameObject (GUID: %u Entry: %u) that have references in not found creature %u GO list. Crash possible later.",GetGUIDLow(),GetGOInfo()->id,GUID_LOPART(owner_guid)); } WorldObject::RemoveFromWorld(); - ObjectAccessor::Instance().RemoveObject(this); + sObjectAccessor.RemoveObject(this); } } diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 4e32b48d6b8..fe4b8673b8f 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -110,7 +110,7 @@ Object::~Object() { sLog.outCrash("Object::~Object - guid="UI64FMTD", typeid=%d, entry=%u deleted but still in update list!!", GetGUID(), GetTypeId(), GetEntry()); assert(false); - ObjectAccessor::Instance().RemoveUpdateObject(this); + sObjectAccessor.RemoveUpdateObject(this); } delete [] m_uint32Values; @@ -731,7 +731,7 @@ void Object::ClearUpdateMask(bool remove) if (m_objectUpdated) { if (remove) - ObjectAccessor::Instance().RemoveUpdateObject(this); + sObjectAccessor.RemoveUpdateObject(this); m_objectUpdated = false; } } @@ -804,7 +804,7 @@ void Object::SetInt32Value(uint16 index, int32 value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -823,7 +823,7 @@ void Object::SetUInt32Value(uint16 index, uint32 value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -849,7 +849,7 @@ void Object::SetUInt64Value(uint16 index, const uint64 &value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -868,7 +868,7 @@ bool Object::AddUInt64Value(uint16 index, const uint64 &value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -889,7 +889,7 @@ bool Object::RemoveUInt64Value(uint16 index, const uint64 &value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -910,7 +910,7 @@ void Object::SetFloatValue(uint16 index, float value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -936,7 +936,7 @@ void Object::SetByteValue(uint16 index, uint8 offset, uint8 value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -962,7 +962,7 @@ void Object::SetUInt16Value(uint16 index, uint8 offset, uint16 value) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -1031,7 +1031,7 @@ void Object::SetFlag(uint16 index, uint32 newFlag) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -1052,7 +1052,7 @@ void Object::RemoveFlag(uint16 index, uint32 oldFlag) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -1077,7 +1077,7 @@ void Object::SetByteFlag(uint16 index, uint8 offset, uint8 newFlag) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -1102,7 +1102,7 @@ void Object::RemoveByteFlag(uint16 index, uint8 offset, uint8 oldFlag) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } @@ -1502,7 +1502,7 @@ void Object::ForceValuesUpdateAtIndex(uint32 i) { if (!m_objectUpdated) { - ObjectAccessor::Instance().AddUpdateObject(this); + sObjectAccessor.AddUpdateObject(this); m_objectUpdated = true; } } diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index ed4bd4d6f96..3e3eea67cca 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -74,7 +74,7 @@ void Pet::AddToWorld() if (!IsInWorld()) { ///- Register the pet for guid lookup - ObjectAccessor::Instance().AddObject(this); + sObjectAccessor.AddObject(this); Unit::AddToWorld(); AIM_Initialize(); } @@ -98,7 +98,7 @@ void Pet::RemoveFromWorld() { ///- Don't call the function for Creature, normal mobs + totems go in a different storage Unit::RemoveFromWorld(); - ObjectAccessor::Instance().RemoveObject(this); + sObjectAccessor.RemoveObject(this); } } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 56d22c7b49e..e3ddcd81f0b 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -587,7 +587,7 @@ bool Player::Create(uint32 guidlow, const std::string& name, uint8 race, uint8 c return false; } - SetMap(MapManager::Instance().CreateMap(info->mapId, this, 0)); + SetMap(sMapMgr.CreateMap(info->mapId, this, 0)); uint8 powertype = cEntry->powerType; @@ -1822,12 +1822,12 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati // Check enter rights before map getting to avoid creating instance copy for player // this check not dependent from map instance copy and same for all instance copies of selected map - if (!MapManager::Instance().CanPlayerEnter(mapid, this, false)) + if (!sMapMgr.CanPlayerEnter(mapid, this, false)) return false; // If the map is not created, assume it is possible to enter it. // It will be created in the WorldPortAck. - Map *map = MapManager::Instance().FindMap(mapid); + Map *map = sMapMgr.FindMap(mapid); if (!map || map->CanEnter(this)) { //lets reset near teleport flag if it wasn't reset during chained teleports @@ -4255,7 +4255,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC // convert corpse to bones if exist (to prevent exiting Corpse in World without DB entry) // bones will be deleted by corpse/bones deleting thread shortly - ObjectAccessor::Instance().ConvertCorpseForPlayer(playerguid); + sObjectAccessor.ConvertCorpseForPlayer(playerguid); // remove from guild uint32 guildId = GetGuildIdFromDB(playerguid); @@ -4684,19 +4684,19 @@ void Player::CreateCorpse() corpse->SaveToDB(); // register for player, but not show - ObjectAccessor::Instance().AddCorpse(corpse); + sObjectAccessor.AddCorpse(corpse); } void Player::SpawnCorpseBones() { - if (ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID())) + if (sObjectAccessor.ConvertCorpseForPlayer(GetGUID())) if (!GetSession()->PlayerLogoutWithSave()) // at logout we will already store the player SaveToDB(); // prevent loading as ghost without corpse } Corpse* Player::GetCorpse() const { - return ObjectAccessor::Instance().GetCorpseForPlayerGUID(GetGUID()); + return sObjectAccessor.GetCorpseForPlayerGUID(GetGUID()); } void Player::DurabilityLossAll(double percent, bool inventory) @@ -6758,7 +6758,7 @@ uint32 Player::GetZoneIdFromDB(uint64 guid) float posy = fields[2].GetFloat(); float posz = fields[3].GetFloat(); - zone = MapManager::Instance().GetZoneId(map,posx,posy,posz); + zone = sMapMgr.GetZoneId(map,posx,posy,posz); if (zone > 0) CharacterDatabase.PExecute("UPDATE characters SET zone='%u' WHERE guid='%u'", zone, guidLow); @@ -8013,7 +8013,7 @@ void Player::RemovedInsignia(Player* looterPlr) // We have to convert player corpse to bones, not to be able to resurrect there // SpawnCorpseBones isn't handy, 'cos it saves player while he in BG - Corpse *bones = ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID(),true); + Corpse *bones = sObjectAccessor.ConvertCorpseForPlayer(GetGUID(),true); if (!bones) return; @@ -13680,7 +13680,7 @@ void Player::PrepareQuestMenu(uint64 guid) { //we should obtain map pointer from GetMap() in 99% of cases. Special case //only for quests which cast teleport spells on player - Map * _map = IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId()); + Map * _map = IsInWorld() ? GetMap() : sMapMgr.FindMap(GetMapId(), GetInstanceId()); ASSERT(_map); GameObject *pGameObject = _map->GetGameObject(guid); if (pGameObject) @@ -13855,7 +13855,7 @@ Quest const * Player::GetNextQuest(uint64 guid, Quest const *pQuest) { //we should obtain map pointer from GetMap() in 99% of cases. Special case //only for quests which cast teleport spells on player - Map * _map = IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId()); + Map * _map = IsInWorld() ? GetMap() : sMapMgr.FindMap(GetMapId(), GetInstanceId()); ASSERT(_map); GameObject *pGameObject = _map->GetGameObject(guid); if (pGameObject) @@ -15955,7 +15955,7 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder) } else { - for (MapManager::TransportSet::iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter) + for (MapManager::TransportSet::iterator iter = sMapMgr.m_Transports.begin(); iter != sMapMgr.m_Transports.end(); ++iter) { if ((*iter)->GetGUIDLow() == transGUID) { @@ -16038,7 +16038,7 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder) // NOW player must have valid map // load the player's map here if it's not already loaded - Map *map = MapManager::Instance().CreateMap(mapId, this, instanceId); + Map *map = sMapMgr.CreateMap(mapId, this, instanceId); if (!map) { @@ -16056,14 +16056,14 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder) RelocateToHomebind(); } - map = MapManager::Instance().CreateMap(mapId, this, 0); + map = sMapMgr.CreateMap(mapId, this, 0); if (!map) { PlayerInfo const *info = objmgr.GetPlayerInfo(getRace(), getClass()); mapId = info->mapId; Relocate(info->positionX,info->positionY,info->positionZ,0.0f); sLog.outError("ERROR: Player (guidlow %d) have invalid coordinates (X: %f Y: %f Z: %f O: %f). Teleport to default race/class locations.",guid,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - map = MapManager::Instance().CreateMap(mapId, this, 0); + map = sMapMgr.CreateMap(mapId, this, 0); if (!map) { sLog.outError("ERROR: Player (guidlow %d) has invalid default map coordinates (X: %f Y: %f Z: %f O: %f). or instance couldn't be created",guid,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); @@ -16532,7 +16532,7 @@ void Player::_LoadGlyphAuras() void Player::LoadCorpse() { if (isAlive()) - ObjectAccessor::Instance().ConvertCorpseForPlayer(GetGUID()); + sObjectAccessor.ConvertCorpseForPlayer(GetGUID()); else { if (Corpse *corpse = GetCorpse()) @@ -17446,7 +17446,7 @@ bool Player::CheckInstanceLoginValid() } // do checks for satisfy accessreqs, instance full, encounter in progress (raid), perm bind group != perm bind player - return MapManager::Instance().CanPlayerEnter(GetMap()->GetId(), this, true); + return sMapMgr.CanPlayerEnter(GetMap()->GetId(), this, true); } bool Player::_LoadHomeBind(QueryResult_AutoPtr result) @@ -18285,7 +18285,7 @@ void Player::ResetInstances(uint8 method, bool isRaid) } // if the map is loaded, reset it - Map *map = MapManager::Instance().FindMap(p->GetMapId(), p->GetInstanceId()); + Map *map = sMapMgr.FindMap(p->GetMapId(), p->GetInstanceId()); if (map && map->IsDungeon()) if (!((InstanceMap*)map)->Reset(method)) { diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp index a64692895a3..0de95352d19 100644 --- a/src/server/game/Entities/Player/SocialMgr.cpp +++ b/src/server/game/Entities/Player/SocialMgr.cpp @@ -19,7 +19,7 @@ */ #include "SocialMgr.h" -#include "SingletonImp.h" + #include "DatabaseEnv.h" #include "Opcodes.h" #include "WorldPacket.h" @@ -28,8 +28,6 @@ #include "World.h" #include "Util.h" -INSTANTIATE_SINGLETON_1(SocialMgr); - PlayerSocial::PlayerSocial() { m_playerGUID = 0; diff --git a/src/server/game/Entities/Player/SocialMgr.h b/src/server/game/Entities/Player/SocialMgr.h index 092ab09dc15..dbed6e93006 100644 --- a/src/server/game/Entities/Player/SocialMgr.h +++ b/src/server/game/Entities/Player/SocialMgr.h @@ -21,7 +21,7 @@ #ifndef __TRINITY_SOCIALMGR_H #define __TRINITY_SOCIALMGR_H -#include "Singleton.h" +#include "ace/Singleton.h" #include "DatabaseEnv.h" #include "Common.h" @@ -139,8 +139,9 @@ class PlayerSocial class SocialMgr { + friend class ACE_Singleton<SocialMgr, ACE_Null_Mutex>; + SocialMgr(); public: - SocialMgr(); ~SocialMgr(); // Misc void RemovePlayerSocial(uint32 guid) { m_socialMap.erase(guid); } @@ -156,6 +157,6 @@ class SocialMgr SocialMap m_socialMap; }; -#define sSocialMgr Trinity::Singleton<SocialMgr>::Instance() +#define sSocialMgr (*ACE_Singleton<SocialMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index e1577237125..2a82b5c33df 100644 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -106,7 +106,7 @@ void MapManager::LoadTransports() m_TransportsByMap[*i].insert(t); //If we someday decide to use the grid to track transports, here: - t->SetMap(MapManager::Instance().CreateMap(mapid, t, 0)); + t->SetMap(sMapMgr.CreateMap(mapid, t, 0)); //t->GetMap()->Add<GameObject>((GameObject *)t); ++count; @@ -455,7 +455,7 @@ void Transport::TeleportTransport(uint32 newMapid, float x, float y, float z) //yes, you're right ResetMap(); - Map * newMap = MapManager::Instance().CreateMap(newMapid, this, 0); + Map * newMap = sMapMgr.CreateMap(newMapid, this, 0); SetMap(newMap); assert (GetMap()); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 0ee16010393..9d0bce23fd5 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -14062,7 +14062,7 @@ void Unit::StopMoving() // send explicit stop packet // rely on vmaps here because for example stormwind is in air - //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); + //float z = sMapMgr.GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); //if (fabs(GetPositionZ() - z) < 2.0f) // Relocate(GetPositionX(), GetPositionY(), z); //Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 25cd624b3c5..f22db3c8187 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -27,13 +27,10 @@ #include "Language.h" #include "Log.h" #include "MapManager.h" -#include "SingletonImp.h" #include "GossipDef.h" #include "Player.h" #include "BattleGroundMgr.h" -INSTANTIATE_SINGLETON_1(GameEventMgr); - bool GameEventMgr::CheckOneGameEvent(uint16 entry) const { switch(mGameEvent[entry].state) @@ -1270,7 +1267,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id) objmgr.AddCreatureToGrid(*itr, data); // Spawn if necessary (loaded grids only) - Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(data->mapid)); + Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use spawn coords to spawn if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { @@ -1298,7 +1295,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id) objmgr.AddGameobjectToGrid(*itr, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed - Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(data->mapid)); + Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { @@ -1345,7 +1342,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id) { objmgr.RemoveCreatureFromGrid(*itr, data); - if (Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT), (Creature*)NULL)) + if (Creature* pCreature = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT), (Creature*)NULL)) pCreature->AddObjectToRemoveList(); } } @@ -1366,7 +1363,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id) { objmgr.RemoveGameobjectFromGrid(*itr, data); - if (GameObject* pGameobject = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) + if (GameObject* pGameobject = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) pGameobject->AddObjectToRemoveList(); } } @@ -1392,7 +1389,7 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate) continue; // Update if spawned - Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(itr->first, data->id,HIGHGUID_UNIT), (Creature*)NULL); + Creature* pCreature = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(itr->first, data->id,HIGHGUID_UNIT), (Creature*)NULL); if (pCreature) { if (activate) diff --git a/src/server/game/Events/GameEventMgr.h b/src/server/game/Events/GameEventMgr.h index 21178805859..656be331edc 100644 --- a/src/server/game/Events/GameEventMgr.h +++ b/src/server/game/Events/GameEventMgr.h @@ -24,7 +24,7 @@ #include "Common.h" #include "SharedDefines.h" #include "Define.h" -#include "Singleton.h" +#include "ace/Singleton.h" #define max_ge_check_delay DAY // 1 day in seconds @@ -92,9 +92,11 @@ class Creature; class GameEventMgr { + friend class ACE_Singleton<GameEventMgr, ACE_Null_Mutex>; + GameEventMgr(); public: - GameEventMgr(); ~GameEventMgr() {}; + typedef std::set<uint16> ActiveEvents; typedef std::vector<GameEventData> GameEventDataMap; ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; } @@ -172,7 +174,7 @@ class GameEventMgr GameEventGuidMap mGameEventGameobjectGuids; }; -#define gameeventmgr Trinity::Singleton<GameEventMgr>::Instance() +#define gameeventmgr (*ACE_Singleton<GameEventMgr, ACE_Null_Mutex>::instance()) bool IsHolidayActive(HolidayIds id); bool IsEventActive(uint16 event_id); diff --git a/src/server/game/Globals/GlobalEvents.cpp b/src/server/game/Globals/GlobalEvents.cpp index acdd91248bc..e83441cf3bb 100644 --- a/src/server/game/Globals/GlobalEvents.cpp +++ b/src/server/game/Globals/GlobalEvents.cpp @@ -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); diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index 73aca9865f8..b82944d8327 100644 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -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()) { diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h index e3295428505..fc128d6a4e0 100644 --- a/src/server/game/Globals/ObjectAccessor.h +++ b/src/server/game/Globals/ObjectAccessor.h @@ -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 diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index bab1add0132..00fbc83244c 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -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; } diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index b1a5bd0e1cd..320bf12cb21 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -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()); diff --git a/src/server/game/Grids/Grid.h b/src/server/game/Grids/Grid.h index fd2cc28c184..2e300ac5e38 100644 --- a/src/server/game/Grids/Grid.h +++ b/src/server/game/Grids/Grid.h @@ -33,7 +33,6 @@ */ #include "Define.h" -#include "ThreadingModel.h" #include "TypeContainer.h" #include "TypeContainerVisitor.h" @@ -44,8 +43,7 @@ template < class ACTIVE_OBJECT, class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES, -class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT> +class GRID_OBJECT_TYPES > class Grid { @@ -131,9 +129,6 @@ class Grid }*/ private: - typedef typename ThreadModel::Lock Guard; - typedef typename ThreadModel::VolatileType VolatileType; - TypeMapContainer<GRID_OBJECT_TYPES> i_container; TypeMapContainer<WORLD_OBJECT_TYPES> i_objects; //typedef std::set<void*> ActiveGridObjects; diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index 8c539519211..1411ac71c4a 100644 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -74,14 +74,13 @@ template unsigned int N, class ACTIVE_OBJECT, class WORLD_OBJECT_TYPES, -class GRID_OBJECT_TYPES, -class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT> +class GRID_OBJECT_TYPES > class NGrid { public: - typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> GridType; + typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType; NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) : i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false) { @@ -109,7 +108,7 @@ class NGrid int32 getX() const { return i_x; } int32 getY() const { return i_y; } - void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> >* pTo) + void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> >* pTo) { i_Reference.link(pTo, this); } @@ -178,7 +177,7 @@ class NGrid uint32 i_gridId; GridInfo i_GridInfo; - GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> > i_Reference; + GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> > i_Reference; int32 i_x; int32 i_y; grid_state_t i_cellstate; diff --git a/src/server/game/Grids/ObjectGridLoader.cpp b/src/server/game/Grids/ObjectGridLoader.cpp index ab69d9a966b..f0da10975ac 100644 --- a/src/server/game/Grids/ObjectGridLoader.cpp +++ b/src/server/game/Grids/ObjectGridLoader.cpp @@ -151,7 +151,7 @@ void LoadHelper(CellCorpseSet const& cell_corpses, CellPair &cell, CorpseMapType uint32 player_guid = itr->first; - Corpse *obj = ObjectAccessor::Instance().GetCorpseForPlayerGUID(player_guid); + Corpse *obj = sObjectAccessor.GetCorpseForPlayerGUID(player_guid); if (!obj) continue; diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 53fa9a3ecdb..2977515959b 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -1724,7 +1724,7 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) bool isEmpty = true; // if the map is loaded, reset it - Map *map = MapManager::Instance().FindMap(p->GetMapId(), p->GetInstanceId()); + Map *map = sMapMgr.FindMap(p->GetMapId(), p->GetInstanceId()); if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !p->CanReset())) { if (p->CanReset()) diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index c62038cfbf0..7b5ccf1c46a 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -21,7 +21,6 @@ #include "Common.h" #include "SQLStorage.h" - #include "Player.h" #include "GridNotifiers.h" #include "Log.h" @@ -40,14 +39,7 @@ #include "Group.h" #include "InstanceData.h" #include "ProgressBar.h" -#include "Singleton.h" -#include "SingletonImp.h" - -INSTANTIATE_SINGLETON_1(InstanceSaveManager); -InstanceSaveManager::InstanceSaveManager() : lock_instLists(false) -{ -} InstanceSaveManager::~InstanceSaveManager() { @@ -173,7 +165,7 @@ void InstanceSave::SaveToDB() // save instance data too std::string data; - Map *map = MapManager::Instance().FindMap(GetMapId(),m_instanceid); + Map *map = sMapMgr.FindMap(GetMapId(),m_instanceid); if (map) { assert(map->IsDungeon()); @@ -615,7 +607,7 @@ void InstanceSaveManager::_ResetSave(InstanceSaveHashMap::iterator &itr) void InstanceSaveManager::_ResetInstance(uint32 mapid, uint32 instanceId) { sLog.outDebug("InstanceSaveMgr::_ResetInstance %u, %u", mapid, instanceId); - Map *map = (MapInstanced*)MapManager::Instance().CreateBaseMap(mapid); + Map *map = (MapInstanced*)sMapMgr.CreateBaseMap(mapid); if (!map->Instanceable()) return; @@ -679,7 +671,7 @@ void InstanceSaveManager::_ResetOrWarnAll(uint32 mapid, Difficulty difficulty, b } // note: this isn't fast but it's meant to be executed very rarely - Map const *map = MapManager::Instance().CreateBaseMap(mapid); // _not_ include difficulty + Map const *map = sMapMgr.CreateBaseMap(mapid); // _not_ include difficulty MapInstanced::InstancedMaps &instMaps = ((MapInstanced*)map)->GetInstancedMaps(); MapInstanced::InstancedMaps::iterator mitr; for (mitr = instMaps.begin(); mitr != instMaps.end(); ++mitr) diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h index 3d8bfb70ebf..66751cc4f10 100644 --- a/src/server/game/Instances/InstanceSaveMgr.h +++ b/src/server/game/Instances/InstanceSaveMgr.h @@ -23,7 +23,7 @@ #define __InstanceSaveMgr_H #include "Define.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "ace/Thread_Mutex.h" #include <list> #include <map> @@ -117,13 +117,14 @@ class InstanceSave typedef UNORDERED_MAP<uint32 /*PAIR32(map,difficulty)*/,time_t /*resetTime*/> ResetTimeByMapDifficultyMap; -class InstanceSaveManager : public Trinity::Singleton<InstanceSaveManager, Trinity::ClassLevelLockable<InstanceSaveManager, ACE_Thread_Mutex> > +class InstanceSaveManager { + friend class ACE_Singleton<InstanceSaveManager, ACE_Null_Mutex>; friend class InstanceSave; public: - InstanceSaveManager(); + InstanceSaveManager() : lock_instLists(false) {}; ~InstanceSaveManager(); - + typedef UNORDERED_MAP<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveHashMap; typedef UNORDERED_MAP<uint32 /*mapId*/, InstanceSaveHashMap> InstanceSaveMapMap; @@ -176,6 +177,7 @@ class InstanceSaveManager : public Trinity::Singleton<InstanceSaveManager, Trini uint32 GetNumBoundGroupsTotal(); private: + void _ResetOrWarnAll(uint32 mapid, Difficulty difficulty, bool warn, uint32 timeleft); void _ResetInstance(uint32 mapid, uint32 instanceId); void _ResetSave(InstanceSaveHashMap::iterator &itr); @@ -189,5 +191,5 @@ class InstanceSaveManager : public Trinity::Singleton<InstanceSaveManager, Trini ResetTimeQueue m_resetTimeQueue; }; -#define sInstanceSaveManager Trinity::Singleton<InstanceSaveManager>::Instance() +#define sInstanceSaveManager (*ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>::instance()) #endif diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index a0656bee38c..960e1e4cef4 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -325,7 +325,7 @@ void Map::DeleteFromWorld(T* obj) template<> void Map::DeleteFromWorld(Player* pl) { - ObjectAccessor::Instance().RemoveObject(pl); + sObjectAccessor.RemoveObject(pl); delete pl; } @@ -334,7 +334,7 @@ Map::EnsureGridCreated(const GridPair &p) { if (!getNGrid(p.x_coord, p.y_coord)) { - Guard guard(*this); + ACE_GUARD(ACE_Thread_Mutex, Guard, Lock); if (!getNGrid(p.x_coord, p.y_coord)) { sLog.outDebug("Creating grid[%u,%u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); @@ -395,7 +395,7 @@ bool Map::EnsureGridLoaded(const Cell &cell) loader.LoadN(); // Add resurrectable corpses to world object list in grid - ObjectAccessor::Instance().AddCorpsesToGrid(GridPair(cell.GridX(),cell.GridY()),(*grid)(cell.CellX(), cell.CellY()), this); + sObjectAccessor.AddCorpsesToGrid(GridPair(cell.GridX(),cell.GridY()),(*grid)(cell.CellX(), cell.CellY()), this); setGridObjectDataLoaded(true,cell.GridX(), cell.GridY()); return true; @@ -828,7 +828,7 @@ bool Map::RemoveBones(uint64 guid, float x, float y) { if (IsRemovalGrid(x, y)) { - Corpse * corpse = ObjectAccessor::Instance().GetObjectInWorld(GetId(), x, y, guid, (Corpse*)NULL); + Corpse * corpse = sObjectAccessor.GetObjectInWorld(GetId(), x, y, guid, (Corpse*)NULL); if (corpse && corpse->GetTypeId() == TYPEID_CORPSE && corpse->GetType() == CORPSE_BONES) corpse->DeleteBonesFromWorld(); else @@ -2069,7 +2069,7 @@ void Map::SendInitSelf(Player * player) void Map::SendInitTransports(Player * player) { // Hack to send out transports - MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; + MapManager::TransportMap& tmap = sMapMgr.m_TransportsByMap; // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) @@ -2096,7 +2096,7 @@ void Map::SendInitTransports(Player * player) void Map::SendRemoveTransports(Player * player) { // Hack to send out transports - MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; + MapManager::TransportMap& tmap = sMapMgr.m_TransportsByMap; // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) @@ -2196,7 +2196,7 @@ void Map::RemoveAllObjectsInRemoveList() { case TYPEID_CORPSE: { - Corpse* corpse = ObjectAccessor::Instance().GetCorpse(*obj, obj->GetGUID()); + Corpse* corpse = sObjectAccessor.GetCorpse(*obj, obj->GetGUID()); if (!corpse) sLog.outError("Tried to delete corpse/bones %u that is not in map.", obj->GetGUIDLow()); else @@ -2408,7 +2408,7 @@ bool InstanceMap::Add(Player *player) // Is it needed? { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, Lock, false); // Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if (!CanEnter(player)) //return false; @@ -2733,7 +2733,7 @@ bool BattleGroundMap::CanEnter(Player * player) bool BattleGroundMap::Add(Player * player) { { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, Lock, false); //Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if (!CanEnter(player)) //return false; @@ -2877,7 +2877,7 @@ void Map::ScriptsProcess() source = HashMapHolder<Corpse>::Find(step.sourceGUID); break; case HIGHGUID_MO_TRANSPORT: - for (MapManager::TransportSet::iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter) + for (MapManager::TransportSet::iterator iter = sMapMgr.m_Transports.begin(); iter != sMapMgr.m_Transports.end(); ++iter) { if ((*iter)->GetGUID() == step.sourceGUID) { diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index d17dc10ec07..4d25381fbe1 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -22,7 +22,6 @@ #define TRINITY_MAP_H #include "Define.h" -#include "ThreadingModel.h" #include "ace/RW_Thread_Mutex.h" #include "ace/Thread_Mutex.h" @@ -239,7 +238,7 @@ typedef UNORDERED_MAP<Creature*, CreatureMover> CreatureMoveList; typedef std::map<uint32/*leaderDBGUID*/, CreatureGroup*> CreatureGroupHolderType; -class Map : public GridRefManager<NGridType>, public Trinity::ObjectLevelLockable<Map, ACE_Thread_Mutex> +class Map : public GridRefManager<NGridType> { friend class MapReference; public: @@ -490,7 +489,7 @@ class Map : public GridRefManager<NGridType>, public Trinity::ObjectLevelLockabl protected: void SetUnloadReferenceLock(const GridPair &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); } - typedef Trinity::ObjectLevelLockable<Map, ACE_Thread_Mutex>::Lock Guard; + ACE_Thread_Mutex Lock; MapEntry const* i_mapEntry; uint8 i_spawnMode; diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index 0736bfa6fb3..008baeb79d9 100644 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -170,7 +170,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) { // if no instanceId via group members or instance saves is found // the instance will be created for the first time - NewInstanceId = MapManager::Instance().GenerateInstanceId(); + NewInstanceId = sMapMgr.GenerateInstanceId(); Difficulty diff = player->GetGroup() ? player->GetGroup()->GetDifficulty(IsRaid()) : player->GetDifficulty(IsRaid()); map = CreateInstance(NewInstanceId, NULL, diff); @@ -183,7 +183,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty) { // load/create a map - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); // make sure we have a valid map id const MapEntry* entry = sMapStore.LookupEntry(GetId()); @@ -219,7 +219,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save, BattleGroundMap* MapInstanced::CreateBattleGround(uint32 InstanceId, BattleGround* bg) { // load/create a map - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); sLog.outDebug("MapInstanced::CreateBattleGround: map bg %d for %d created.", InstanceId, GetId()); diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index 42233db4a9a..46b604388c5 100644 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -20,7 +20,6 @@ #include "MapManager.h" #include "InstanceSaveMgr.h" -#include "SingletonImp.h" #include "DatabaseEnv.h" #include "Log.h" #include "ObjectAccessor.h" @@ -37,10 +36,6 @@ #include "Language.h" #include "WorldPacket.h" -#define CLASS_LOCK Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex> -INSTANTIATE_SINGLETON_2(MapManager, CLASS_LOCK); -INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex); - extern GridState* si_GridStates[]; // debugging code, should be deleted some day MapManager::MapManager() @@ -116,7 +111,7 @@ Map* MapManager::_createBaseMap(uint32 id) if (m == NULL) { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); const MapEntry* entry = sMapStore.LookupEntry(id); if (entry && entry->Instanceable()) @@ -236,7 +231,7 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player, bool loginCheck) InstanceGroupBind* boundedInstance = pGroup->GetBoundInstance(player); if (boundedInstance && boundedInstance->save) { - if (Map *boundedMap = MapManager::Instance().FindMap(mapid,boundedInstance->save->GetInstanceId())) + if (Map *boundedMap = sMapMgr.FindMap(mapid,boundedInstance->save->GetInstanceId())) { // Player permanently bounded to different instance than groups one InstancePlayerBind* playerBoundedInstance = player->GetBoundInstance(mapid, player->GetDungeonDifficulty()); @@ -307,7 +302,7 @@ void MapManager::Update(uint32 diff) for (iter = i_maps.begin(); iter != i_maps.end(); ++iter) iter->second->DelayedUpdate(i_timer.GetCurrent()); - ObjectAccessor::Instance().Update(i_timer.GetCurrent()); + sObjectAccessor.Update(i_timer.GetCurrent()); for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter) (*iter)->Update(i_timer.GetCurrent()); @@ -361,7 +356,7 @@ void MapManager::InitMaxInstanceId() uint32 MapManager::GetNumInstances() { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); uint32 ret = 0; for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) @@ -378,7 +373,7 @@ uint32 MapManager::GetNumInstances() uint32 MapManager::GetNumPlayersInInstances() { - Guard guard(*this); + ACE_GUARD_RETURN(ACE_Thread_Mutex, Guard, Lock, NULL); uint32 ret = 0; for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr) diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index c3380811c18..47cb9d2f795 100644 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -22,7 +22,7 @@ #define TRINITY_MAPMANAGER_H #include "Define.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "ace/Thread_Mutex.h" #include "Common.h" #include "Map.h" @@ -31,10 +31,9 @@ class Transport; -class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex> > +class MapManager { - - friend class Trinity::OperatorNew<MapManager>; + friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>; typedef UNORDERED_MAP<uint32, Map*> MapMapType; typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair; @@ -162,7 +161,7 @@ class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLock return (iter == i_maps.end() ? NULL : iter->second); } - typedef Trinity::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard; + ACE_Thread_Mutex Lock; uint32 i_gridCleanUpDelay; MapMapType i_maps; IntervalTimer i_timer; @@ -170,4 +169,5 @@ class MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLock uint32 i_MaxInstanceId; MapUpdater m_updater; }; +#define sMapMgr (*ACE_Singleton<MapManager, ACE_Thread_Mutex>::instance()) #endif diff --git a/src/server/game/Movement/MovementGenerator.h b/src/server/game/Movement/MovementGenerator.h index 650b4fc3196..9699f6951c2 100644 --- a/src/server/game/Movement/MovementGenerator.h +++ b/src/server/game/Movement/MovementGenerator.h @@ -22,7 +22,7 @@ #define TRINITY_MOVEMENTGENERATOR_H #include "Define.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "ObjectRegistry.h" #include "FactoryHolder.h" #include "Common.h" diff --git a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp index 4cadfe1cfb6..416b775ef7e 100644 --- a/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp @@ -343,7 +343,7 @@ void FlightPathMovementGenerator::InitEndGridInfo() void FlightPathMovementGenerator::PreloadEndGrid() { // used to preload the final grid where the flightmaster is - Map *endMap = MapManager::Instance().FindMap(m_endMapId); + Map *endMap = sMapMgr.FindMap(m_endMapId); // Load the grid if (endMap) diff --git a/src/server/game/OutdoorPvP/OutdoorPvP.cpp b/src/server/game/OutdoorPvP/OutdoorPvP.cpp index 71659a20be7..b19dc01ccd9 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvP.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvP.cpp @@ -165,7 +165,7 @@ bool OPvPCapturePoint::DelCreature(uint32 type) // explicit removal from map // beats me why this is needed, but with the recent removal "cleanup" some creatures stay in the map if "properly" deleted // so this is a big fat workaround, if AddObjectToRemoveList and DoDelayedMovesAndRemoves worked correctly, this wouldn't be needed - //if (Map * map = MapManager::Instance().FindMap(cr->GetMapId())) + //if (Map * map = sMapMgr.FindMap(cr->GetMapId())) // map->Remove(cr,false); // delete respawn time for this creature WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u'", guid); diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp index f9dbedb30dc..1ec2bcb6a9c 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp +++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.cpp @@ -25,9 +25,6 @@ #include "OutdoorPvPEP.h" #include "ObjectMgr.h" #include "Player.h" -#include "SingletonImp.h" - -INSTANTIATE_SINGLETON_1(OutdoorPvPMgr); OutdoorPvPMgr::OutdoorPvPMgr() { diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h index a78583100ec..2a18a602da9 100644 --- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h +++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h @@ -22,7 +22,7 @@ #define OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL 1000 #include "OutdoorPvP.h" -#include "Singleton.h" +#include "ace/Singleton.h" class Player; class GameObject; @@ -79,7 +79,7 @@ private: uint32 m_UpdateTimer; }; -#define sOutdoorPvPMgr Trinity::Singleton<OutdoorPvPMgr>::Instance() +#define sOutdoorPvPMgr (*ACE_Singleton<OutdoorPvPMgr, ACE_Null_Mutex>::instance()) #endif /*OUTDOOR_PVP_MGR_H_*/ diff --git a/src/server/game/Pools/PoolHandler.cpp b/src/server/game/Pools/PoolHandler.cpp index 731d71c6b19..4a7c99216bd 100644 --- a/src/server/game/Pools/PoolHandler.cpp +++ b/src/server/game/Pools/PoolHandler.cpp @@ -21,9 +21,6 @@ #include "ProgressBar.h" #include "Log.h" #include "MapManager.h" -#include "SingletonImp.h" - -INSTANTIATE_SINGLETON_1(PoolHandler); //////////////////////////////////////////////////////////// // template class SpawnedPoolData @@ -201,7 +198,7 @@ void PoolGroup<Creature>::Despawn1Object(uint32 guid) { objmgr.RemoveCreatureFromGrid(guid, data); - if (Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_UNIT), (Creature*)NULL)) + if (Creature* pCreature = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_UNIT), (Creature*)NULL)) pCreature->AddObjectToRemoveList(); } } @@ -214,7 +211,7 @@ void PoolGroup<GameObject>::Despawn1Object(uint32 guid) { objmgr.RemoveGameobjectFromGrid(guid, data); - if (GameObject* pGameobject = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) + if (GameObject* pGameobject = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) pGameobject->AddObjectToRemoveList(); } } @@ -297,7 +294,7 @@ void PoolGroup<Creature>::Spawn1Object(PoolObject* obj) objmgr.AddCreatureToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) - Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(data->mapid)); + Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use spawn coords to spawn if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { @@ -323,7 +320,7 @@ void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj) objmgr.AddGameobjectToGrid(obj->guid, data); // Spawn if necessary (loaded grids only) // this base map checked as non-instanced and then only existed - Map* map = const_cast<Map*>(MapManager::Instance().CreateBaseMap(data->mapid)); + Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid)); // We use current coords to unspawn, not spawn coords since creature can have changed grid if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY)) { @@ -355,7 +352,7 @@ template <> void PoolGroup<Creature>::ReSpawn1Object(PoolObject* obj) { if (CreatureData const* data = objmgr.GetCreatureData(obj->guid)) - if (Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_UNIT), (Creature*)NULL)) + if (Creature* pCreature = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_UNIT), (Creature*)NULL)) pCreature->GetMap()->Add(pCreature); } @@ -364,7 +361,7 @@ template <> void PoolGroup<GameObject>::ReSpawn1Object(PoolObject* obj) { if (GameObjectData const* data = objmgr.GetGOData(obj->guid)) - if (GameObject* pGameobject = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) + if (GameObject* pGameobject = sObjectAccessor.GetObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL)) pGameobject->GetMap()->Add(pGameobject); } diff --git a/src/server/game/Pools/PoolHandler.h b/src/server/game/Pools/PoolHandler.h index df62badd9c8..156bc47a2a9 100644 --- a/src/server/game/Pools/PoolHandler.h +++ b/src/server/game/Pools/PoolHandler.h @@ -20,7 +20,7 @@ #define TRINITY_POOLHANDLER_H #include "Define.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "Creature.h" #include "GameObject.h" @@ -89,10 +89,11 @@ class PoolGroup class PoolHandler { - public: - PoolHandler(); - ~PoolHandler() {}; + friend class ACE_Singleton<PoolHandler, ACE_Null_Mutex>; + PoolHandler(); + ~PoolHandler() {}; + public: void LoadFromDB(); void Initialize(); @@ -134,7 +135,7 @@ class PoolHandler SpawnedPoolData mSpawnedData; }; -#define poolhandler Trinity::Singleton<PoolHandler>::Instance() +#define poolhandler (*ACE_Singleton<PoolHandler, ACE_Null_Mutex>::instance()) // Method that tell if the creature is part of a pool and return the pool id if yes template<> diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 88e5b7284c0..70b1ff6be64 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -10,9 +10,6 @@ #include "ProgressBar.h" #include "ScriptLoader.h" #include "ScriptSystem.h" -#include "SingletonImp.h" - -INSTANTIATE_SINGLETON_1(ScriptMgr); int num_sc_scripts; Script *m_scripts[MAX_SCRIPTS]; diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 250bbf5526a..bcb26381809 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -94,8 +94,9 @@ struct Script class ScriptMgr { + friend class ACE_Singleton<ScriptMgr, ACE_Null_Mutex>; + ScriptMgr(); public: - ScriptMgr(); ~ScriptMgr(); void ScriptsInit(); @@ -158,6 +159,6 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit *pTarget = NULL); #define FUNC_PTR(name, callconvention, returntype, parameters) typedef returntype(callconvention *name)parameters; #endif -#define sScriptMgr Trinity::Singleton<ScriptMgr>::Instance() +#define sScriptMgr (*ACE_Singleton<ScriptMgr, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/game/Server/Protocol/Handlers/AddonHandler.cpp b/src/server/game/Server/Protocol/Handlers/AddonHandler.cpp index b54c119270f..13fbd266ea4 100644 --- a/src/server/game/Server/Protocol/Handlers/AddonHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/AddonHandler.cpp @@ -19,16 +19,11 @@ */ #include "zlib.h" - #include "AddonHandler.h" #include "DatabaseEnv.h" -#include "SingletonImp.h" #include "Opcodes.h" - #include "Log.h" -INSTANTIATE_SINGLETON_1( AddonHandler ); - AddonHandler::AddonHandler() { } diff --git a/src/server/game/Server/Protocol/Handlers/AddonHandler.h b/src/server/game/Server/Protocol/Handlers/AddonHandler.h index 2c9394c947d..68620751da3 100644 --- a/src/server/game/Server/Protocol/Handlers/AddonHandler.h +++ b/src/server/game/Server/Protocol/Handlers/AddonHandler.h @@ -23,19 +23,20 @@ #include "Common.h" #include "ConfigEnv.h" -#include "Singleton.h" - +#include "ace/Singleton.h" #include "WorldPacket.h" class AddonHandler { + /* Construction */ + friend class ACE_Singleton<AddonHandler, ACE_Null_Mutex>; + AddonHandler(); + public: - /* Construction */ - AddonHandler(); ~AddonHandler(); - //built addon packet + //build addon packet bool BuildAddonPacket(WorldPacket* Source, WorldPacket* Target); }; -#define sAddOnHandler Trinity::Singleton<AddonHandler>::Instance() +#define sAddOnHandler ACE_Singleton<AddonHandler, ACE_Null_Mutex>::instance() #endif diff --git a/src/server/game/Server/Protocol/Handlers/ArenaTeamHandler.cpp b/src/server/game/Server/Protocol/Handlers/ArenaTeamHandler.cpp index 1d93090d255..3c26e17bddd 100644 --- a/src/server/game/Server/Protocol/Handlers/ArenaTeamHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/ArenaTeamHandler.cpp @@ -91,7 +91,7 @@ void WorldSession::HandleArenaTeamInviteOpcode(WorldPacket & recv_data) if (!normalizePlayerName(Invitedname)) return; - player = ObjectAccessor::Instance().FindPlayerByName(Invitedname.c_str()); + player = sObjectAccessor.FindPlayerByName(Invitedname.c_str()); } if (!player) diff --git a/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp b/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp index 73f01f46c4c..442fe55b194 100644 --- a/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp @@ -18,8 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "SingletonImp.h" - #include "ObjectMgr.h" // for normalizePlayerName #include "ChannelMgr.h" diff --git a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp index 141f3605ee2..ca08d197c3f 100644 --- a/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/CharacterHandler.cpp @@ -719,7 +719,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) pCurrChar->TeleportTo(pCurrChar->m_homebindMapId, pCurrChar->m_homebindX, pCurrChar->m_homebindY, pCurrChar->m_homebindZ, pCurrChar->GetOrientation()); } - ObjectAccessor::Instance().AddObject(pCurrChar); + sObjectAccessor.AddObject(pCurrChar); //sLog.outDebug("Player %s added to Map.",pCurrChar->GetName()); pCurrChar->SendInitialPacketsAfterAddToMap(); diff --git a/src/server/game/Server/Protocol/Handlers/GuildHandler.cpp b/src/server/game/Server/Protocol/Handlers/GuildHandler.cpp index 6803fe63a86..4db1961e7af 100644 --- a/src/server/game/Server/Protocol/Handlers/GuildHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/GuildHandler.cpp @@ -75,7 +75,7 @@ void WorldSession::HandleGuildInviteOpcode(WorldPacket& recvPacket) recvPacket >> Invitedname; if (normalizePlayerName(Invitedname)) - player = ObjectAccessor::Instance().FindPlayerByName(Invitedname.c_str()); + player = sObjectAccessor.FindPlayerByName(Invitedname.c_str()); if (!player) { diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp index e4d329e6afc..3bc5e8d507f 100644 --- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp @@ -232,8 +232,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket & recv_data) data << uint32(clientcount); // clientcount place holder, listed count data << uint32(clientcount); // clientcount place holder, online count - ObjectAccessor::Guard guard(*HashMapHolder<Player>::GetLock()); - HashMapHolder<Player>::MapType& m = ObjectAccessor::Instance().GetPlayers(); + ACE_GUARD(ACE_Thread_Mutex, g, *HashMapHolder<Player>::GetLock()); + HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers(); for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { if (security == SEC_PLAYER) @@ -935,7 +935,7 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket & recv_data) return; // check if player can enter instance : instance not full, and raid instance not in encounter fight - if (!MapManager::Instance().CanPlayerEnter(at->target_mapId, GetPlayer(), false)) + if (!sMapMgr.CanPlayerEnter(at->target_mapId, GetPlayer(), false)) return; GetPlayer()->TeleportTo(at->target_mapId,at->target_X,at->target_Y,at->target_Z,at->target_Orientation,TELE_TO_NOT_LEAVE_TRANSPORT); diff --git a/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp b/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp index 1b850434726..56a8c9cd6da 100644 --- a/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/MovementHandler.cpp @@ -75,7 +75,7 @@ void WorldSession::HandleMoveWorldportAckOpcode() } // relocate the player to the teleport destination - Map * newMap = MapManager::Instance().CreateMap(loc.GetMapId(), GetPlayer(), 0); + Map * newMap = sMapMgr.CreateMap(loc.GetMapId(), GetPlayer(), 0); // the CanEnter checks are done in TeleporTo but conditions may change // while the player is in transit, for example the map may get full if (!newMap || !newMap->CanEnter(GetPlayer())) @@ -302,7 +302,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket & recv_data) if (plMover && !plMover->GetTransport()) { // elevators also cause the client to send MOVEMENTFLAG_ONTRANSPORT - just unmount if the guid can be found in the transport list - for (MapManager::TransportSet::const_iterator iter = MapManager::Instance().m_Transports.begin(); iter != MapManager::Instance().m_Transports.end(); ++iter) + for (MapManager::TransportSet::const_iterator iter = sMapMgr.m_Transports.begin(); iter != sMapMgr.m_Transports.end(); ++iter) { if ((*iter)->GetGUID() == movementInfo.t_guid) { diff --git a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp index 05cbcf81f2f..fc2c3baf735 100644 --- a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp +++ b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp @@ -302,7 +302,7 @@ void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recv_data*/) if (corpseMapEntry->IsDungeon() && corpseMapEntry->entrance_map >= 0) { // if corpse map have entrance - if (Map const* entranceMap = MapManager::Instance().CreateBaseMap(corpseMapEntry->entrance_map)) + if (Map const* entranceMap = sMapMgr.CreateBaseMap(corpseMapEntry->entrance_map)) { mapid = corpseMapEntry->entrance_map; x = corpseMapEntry->entrance_x; diff --git a/src/server/game/Server/Protocol/WorldLog.cpp b/src/server/game/Server/Protocol/WorldLog.cpp index a9000f8e65c..e66bff0b504 100644 --- a/src/server/game/Server/Protocol/WorldLog.cpp +++ b/src/server/game/Server/Protocol/WorldLog.cpp @@ -23,14 +23,9 @@ */ #include "WorldLog.h" -#include "SingletonImp.h" #include "ConfigEnv.h" #include "Log.h" -#define CLASS_LOCK Trinity::ClassLevelLockable<WorldLog, ACE_Thread_Mutex> -INSTANTIATE_SINGLETON_2(WorldLog, CLASS_LOCK); -INSTANTIATE_CLASS_MUTEX(WorldLog, ACE_Thread_Mutex); - WorldLog::WorldLog() : i_file(NULL) { Initialize(); @@ -67,7 +62,7 @@ void WorldLog::outTimestampLog(char const *fmt, ...) { if (LogWorld()) { - Guard guard(*this); + ACE_GUARD(ACE_Thread_Mutex, Guard, Lock); ASSERT(i_file); Log::outTimestamp(i_file); @@ -95,7 +90,7 @@ void WorldLog::outLog(char const *fmt, ...) { if (LogWorld()) { - Guard guard(*this); + ACE_GUARD(ACE_Thread_Mutex, Guard, Lock); ASSERT(i_file); va_list args; @@ -117,6 +112,3 @@ void WorldLog::outLog(char const *fmt, ...) va_end(ap2); } } - -#define sWorldLog WorldLog::Instance() - diff --git a/src/server/game/Server/Protocol/WorldLog.h b/src/server/game/Server/Protocol/WorldLog.h index 8a3c96b3b15..fd228ce4559 100644 --- a/src/server/game/Server/Protocol/WorldLog.h +++ b/src/server/game/Server/Protocol/WorldLog.h @@ -26,19 +26,19 @@ #define TRINITY_WORLDLOG_H #include "Common.h" -#include "Singleton.h" +#include "ace/Singleton.h" #include "Errors.h" #include <stdarg.h> /// %Log packets to a file -class WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable<WorldLog, ACE_Thread_Mutex> > +class WorldLog { - friend class Trinity::OperatorNew<WorldLog>; + friend class ACE_Singleton<WorldLog, ACE_Thread_Mutex>; WorldLog(); WorldLog(const WorldLog &); WorldLog& operator=(const WorldLog &); - typedef Trinity::ClassLevelLockable<WorldLog, ACE_Thread_Mutex>::Lock Guard; + ACE_Thread_Mutex Lock; /// Close the file in destructor ~WorldLog(); @@ -57,7 +57,7 @@ class WorldLog : public Trinity::Singleton<WorldLog, Trinity::ClassLevelLockable bool m_dbWorld; }; -#define sWorldLog WorldLog::Instance() +#define sWorldLog (*ACE_Singleton<WorldLog, ACE_Thread_Mutex>::instance()) #endif /// @} diff --git a/src/server/game/Skills/SkillDiscovery.cpp b/src/server/game/Skills/SkillDiscovery.cpp index f0bfb5bc0ba..fb34cff150c 100644 --- a/src/server/game/Skills/SkillDiscovery.cpp +++ b/src/server/game/Skills/SkillDiscovery.cpp @@ -21,7 +21,6 @@ #include "DatabaseEnv.h" #include "Log.h" #include "ProgressBar.h" -#include "SingletonImp.h" #include "World.h" #include "Util.h" #include "SkillDiscovery.h" diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 7a975f021ff..a62e602fe49 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -41,7 +41,6 @@ #include "MapManager.h" #include "ObjectAccessor.h" #include "CellImpl.h" -#include "SingletonImp.h" #include "SharedDefines.h" #include "LootMgr.h" #include "VMapFactory.h" diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index f89a0650729..19702f1b8f7 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -1164,7 +1164,7 @@ void SpellMgr::LoadSpellTargetPositions() // additional requirements if (spellInfo->Effect[i]==SPELL_EFFECT_BIND && spellInfo->EffectMiscValue[i]) { - uint32 area_id = MapManager::Instance().GetAreaId(st.target_mapId, st.target_X, st.target_Y, st.target_Z); + uint32 area_id = sMapMgr.GetAreaId(st.target_mapId, st.target_X, st.target_Y, st.target_Z); if (area_id != uint32(spellInfo->EffectMiscValue[i])) { sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` expected point to zone %u bit point to zone %u.",Spell_ID, spellInfo->EffectMiscValue[i], area_id); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 2b6f84fbc1e..7d0b91e38de 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -48,7 +48,6 @@ #include "ItemEnchantmentMgr.h" #include "MapManager.h" #include "CreatureAIRegistry.h" -#include "SingletonImp.h" #include "BattleGroundMgr.h" #include "OutdoorPvPMgr.h" #include "TemporarySummon.h" @@ -72,8 +71,6 @@ #include "LFGMgr.h" #include "ConditionMgr.h" -INSTANTIATE_SINGLETON_1(World); - volatile bool World::m_stopEvent = false; uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; volatile uint32 World::m_worldLoopCounter = 0; @@ -635,7 +632,7 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_INTERVAL_GRIDCLEAN] = MIN_GRID_DELAY; } if (reload) - MapManager::Instance().SetGridCleanUpDelay(m_configs[CONFIG_INTERVAL_GRIDCLEAN]); + sMapMgr.SetGridCleanUpDelay(m_configs[CONFIG_INTERVAL_GRIDCLEAN]); m_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfig.GetIntDefault("MapUpdateInterval", 100); if (m_configs[CONFIG_INTERVAL_MAPUPDATE] < MIN_MAP_UPDATE_DELAY) @@ -644,7 +641,7 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_INTERVAL_MAPUPDATE] = MIN_MAP_UPDATE_DELAY; } if (reload) - MapManager::Instance().SetMapUpdateInterval(m_configs[CONFIG_INTERVAL_MAPUPDATE]); + sMapMgr.SetMapUpdateInterval(m_configs[CONFIG_INTERVAL_MAPUPDATE]); m_configs[CONFIG_INTERVAL_CHANGEWEATHER] = sConfig.GetIntDefault("ChangeWeatherInterval", 10 * MINUTE * IN_MILISECONDS); @@ -1666,7 +1663,7 @@ void World::SetInitialWorldSettings() ///- Initialize MapManager sLog.outString("Starting Map System"); - MapManager::Instance().Initialize(); + sMapMgr.Initialize(); sLog.outString("Starting Game Event system..."); uint32 nextGameEvent = gameeventmgr.Initialize(); @@ -1693,7 +1690,7 @@ void World::SetInitialWorldSettings() //Not sure if this can be moved up in the sequence (with static data loading) as it uses MapManager sLog.outString("Loading Transports..."); - MapManager::Instance().LoadTransports(); + sMapMgr.LoadTransports(); sLog.outString("Deleting expired bans..."); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate <= UNIX_TIMESTAMP() AND unbandate<>bandate"); @@ -1945,12 +1942,12 @@ void World::Update(uint32 diff) /// <li> Handle all other objects ///- Update objects when the timer has passed (maps, transport, creatures,...) - MapManager::Instance().Update(diff); // As interval = 0 + sMapMgr.Update(diff); // As interval = 0 /*if (m_timers[WUPDATE_OBJECTS].Passed()) { m_timers[WUPDATE_OBJECTS].Reset(); - MapManager::Instance().DoDelayedMovesAndRemoves(); + sMapMgr.DoDelayedMovesAndRemoves(); }*/ static uint32 autobroadcaston = 0; diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index c53cab1124f..7266cf7e770 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -27,7 +27,7 @@ #include "Common.h" #include "Timer.h" -#include "Singleton.h" +#include <ace/Singleton.h> #include "SharedDefines.h" #include "ace/Atomic_Op.h" #include "QueryResult.h" @@ -779,6 +779,6 @@ class World extern uint32 realmID; -#define sWorld Trinity::Singleton<World>::Instance() +#define sWorld (*ACE_Singleton<World, ACE_Null_Mutex>::instance()) #endif /// @} diff --git a/src/server/scripts/EasternKingdoms/BlackwingLair/boss_victor_nefarius.cpp b/src/server/scripts/EasternKingdoms/BlackwingLair/boss_victor_nefarius.cpp index b079dd94a58..f611c21e2bf 100644 --- a/src/server/scripts/EasternKingdoms/BlackwingLair/boss_victor_nefarius.cpp +++ b/src/server/scripts/EasternKingdoms/BlackwingLair/boss_victor_nefarius.cpp @@ -189,9 +189,9 @@ struct boss_victor_nefariusAI : public ScriptedAI //Trinity::Singleton<MapManager>::Instance().GetMap(me->GetMapId(), me)->GetPlayers().begin(); /* - list <Player*>::const_iterator i = MapManager::Instance().GetMap(me->GetMapId(), me)->GetPlayers().begin(); + list <Player*>::const_iterator i = sMapMgr.GetMap(me->GetMapId(), me)->GetPlayers().begin(); - for (i = MapManager::Instance().GetMap(me->GetMapId(), me)->GetPlayers().begin(); i != MapManager::Instance().GetMap(me->GetMapId(), me)->GetPlayers().end(); ++i) + for (i = sMapMgr.GetMap(me->GetMapId(), me)->GetPlayers().begin(); i != sMapMgr.GetMap(me->GetMapId(), me)->GetPlayers().end(); ++i) { AttackStart((*i)); } @@ -288,7 +288,7 @@ struct boss_victor_nefariusAI : public ScriptedAI if (SpawnedAdds >= 42) { //Teleport Victor Nefarius way out of the map - //MapManager::Instance().GetMap(me->GetMapId(), me)->CreatureRelocation(me,0,0,-5000,0); + //sMapMgr.GetMap(me->GetMapId(), me)->CreatureRelocation(me,0,0,-5000,0); //Inturrupt any spell casting me->InterruptNonMeleeSpells(false); diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt index 04fbfbea60f..0fd58e63588 100644 --- a/src/server/shared/CMakeLists.txt +++ b/src/server/shared/CMakeLists.txt @@ -12,7 +12,6 @@ set(shared_STAT_SRCS Logging/Log.cpp - Policies/ObjectLifeTime.cpp Threading/DelayExecutor.cpp Threading/Threading.cpp Utilities/ProgressBar.cpp @@ -37,7 +36,6 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic ${CMAKE_SOURCE_DIR}/src/server/shared/Logging ${CMAKE_SOURCE_DIR}/src/server/shared/Packets - ${CMAKE_SOURCE_DIR}/src/server/shared/Policies ${CMAKE_SOURCE_DIR}/src/server/shared/Threading ${CMAKE_SOURCE_DIR}/src/server/shared/Utilities ${MYSQL_INCLUDE_DIR} diff --git a/src/server/shared/Configuration/Config.cpp b/src/server/shared/Configuration/Config.cpp index 39830104a7c..3979cbc36aa 100644 --- a/src/server/shared/Configuration/Config.cpp +++ b/src/server/shared/Configuration/Config.cpp @@ -19,9 +19,6 @@ */ #include "ConfigEnv.h" -#include "Policies/SingletonImp.h" - -INSTANTIATE_SINGLETON_1(Config); Config::Config() : mIgnoreCase(true), mConf(NULL) { diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h index bfcb324ee62..50cd4609b25 100644 --- a/src/server/shared/Configuration/Config.h +++ b/src/server/shared/Configuration/Config.h @@ -21,15 +21,16 @@ #ifndef CONFIG_H #define CONFIG_H -#include <Policies/Singleton.h> +#include <ace/Singleton.h> #include "Define.h" class DOTCONFDocument; class Config { + friend class ACE_Singleton<Config, ACE_Null_Mutex>; + Config(); public: - Config(); ~Config(); bool SetSource(const char *file, bool ignorecase = true); @@ -47,7 +48,7 @@ class Config DOTCONFDocument *mConf; }; -#define sConfig Trinity::Singleton<Config>::Instance() +#define sConfig (*ACE_Singleton<Config, ACE_Null_Mutex>::instance()) #endif diff --git a/src/server/shared/Database/Database.cpp b/src/server/shared/Database/Database.cpp index 2dd2f9bbda4..1fb2f831a9f 100644 --- a/src/server/shared/Database/Database.cpp +++ b/src/server/shared/Database/Database.cpp @@ -25,7 +25,6 @@ #include "Updates/UpdateFields.h" #include "Utilities/Util.h" -#include "Policies/SingletonImp.h" #include "Define.h" #include "Threading/Threading.h" #include "Database/SqlDelayThread.h" diff --git a/src/server/shared/Database/Database.h b/src/server/shared/Database/Database.h index 655479c85fe..762abfd2ede 100644 --- a/src/server/shared/Database/Database.h +++ b/src/server/shared/Database/Database.h @@ -24,7 +24,6 @@ #include "Threading/Threading.h" #include "Dynamic/UnorderedMap.h" #include "Database/SqlDelayThread.h" -#include "Policies/Singleton.h" #include "ace/Thread_Mutex.h" #include "ace/Guard_T.h" diff --git a/src/server/shared/Debugging/MemoryLeaks.cpp b/src/server/shared/Debugging/MemoryLeaks.cpp index ef7e36c3b57..c591dabb866 100644 --- a/src/server/shared/Debugging/MemoryLeaks.cpp +++ b/src/server/shared/Debugging/MemoryLeaks.cpp @@ -17,9 +17,6 @@ */ #include "MemoryLeaks.h" -#include "Policies/SingletonImp.h" - -INSTANTIATE_SINGLETON_1( MemoryManager ) ; MemoryManager::MemoryManager( ) { diff --git a/src/server/shared/Debugging/MemoryLeaks.h b/src/server/shared/Debugging/MemoryLeaks.h index bc722f241bd..4b13e4d3d90 100644 --- a/src/server/shared/Debugging/MemoryLeaks.h +++ b/src/server/shared/Debugging/MemoryLeaks.h @@ -39,10 +39,11 @@ #endif -#include "Policies/Singleton.h" +#include "ace/Singleton.h" -struct MemoryManager : public Trinity::Singleton < MemoryManager > +struct MemoryManager { MemoryManager(); }; +#define sMemoryManager ACE_Singleton<MemoryManager, ACE_Null_Mutex>::instance() #endif diff --git a/src/server/shared/Dynamic/CountedReference/Reference.h b/src/server/shared/Dynamic/CountedReference/Reference.h deleted file mode 100644 index bdc06a572c9..00000000000 --- a/src/server/shared/Dynamic/CountedReference/Reference.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCE_H -#define TRINITY_REFERENCE_H - -/** - * Referencer<T> - * Referencer is an object that holds a reference holder that hold a reference - * counted object. When an object's reference count drop to zero, it removes - * the object. This is a non intrusive mechanism and any object at any point - * in time can be referenced. When and object is reference counted, do not - * pass the object directly to other methods but rather, pass its - * reference around. Objects can be reference counted in both single threaded - * model and multi-threaded model - */ - -#include <stdexcept> -#include "Define.h" -#include "ThreadingModel.h" -#include "ReferenceHolder.h" - -template -< -typename T, -class THREADING_MODEL = Trinity::SingleThreaded<T> -> -class Referencer -{ - typedef typename THREADING_MODEL::Lock Lock; - typedef ReferenceHolder<T, THREADING_MODEL> ReferenceeHolder; - public: - - /// Constructs a referencer. - Referencer(T *ref = NULL); - - /// Copy constructor - Referencer(const Referencer &obj) : i_holder(NULL) { *this = obj; } - - /// Destructor - ~Referencer(); - - /// Referencee accessor - T* referencee(void) { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T* referencee(void) const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - //T& referencee(void){ return _referencee(); } - //const T& referencee(void) const { return const_cast<Referencer *>(this)->_referencee(); } - operator T&(void) { return _referencee(); } - operator const T&(void) const { return *const_cast<Referencer *>(this)->_referencee(); } - - /// cast operators - T* operator*() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - T const * operator*() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// overload operators - T* operator->() { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - const T * operator->() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); } - - /// operator = - Referencer& operator=(const Referencer &obj); - Referencer& operator=(T *); - - /// returns true if i_referencee is null - bool isNull(void) const { return i_holder == NULL; } - - private: - - T& _referencee(void) - { - if( i_holder == NULL ) - throw std::runtime_error("Invalid access to null pointer"); - return *i_holder->i_referencee; - } - - void deReference(ReferenceeHolder *); - void addReference(ReferenceeHolder *); - - // private data - ReferenceeHolder *i_holder; -}; -#endif - diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h b/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h deleted file mode 100644 index 597e9854be0..00000000000 --- a/src/server/shared/Dynamic/CountedReference/ReferenceHolder.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEHOLDER_H -#define TRINITY_REFERENCEHOLDER_H - -/** ReferenceHolder holds the actualy referenced obejct as well the refence - count. The ReferenecHolder implements as a policy base object and - will decided by the Reference class to be consnsitent. - */ - -template -< -typename T, -class THREADING_MODEL -> -struct ReferenceHolder : public THREADING_MODEL -{ - explicit ReferenceHolder(T *ref) : i_referencee(ref), i_referenceCount(0) {} - T *i_referencee; - unsigned int i_referenceCount; - typedef typename THREADING_MODEL::Lock Lock; -}; -#endif - diff --git a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h b/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h deleted file mode 100644 index cde330179e3..00000000000 --- a/src/server/shared/Dynamic/CountedReference/ReferenceImpl.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_REFERENCEIMPL_H -#define TRINITY_REFERENCEIMPL_H - -#include "Reference.h" - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::Referencer(T *ref) -: i_holder(NULL) -{ - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>::~Referencer() -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &obj) -{ - if( i_holder != NULL ) - deReference(i_holder); - if( obj.i_holder != NULL ) - addReference(obj.i_holder); - i_holder = obj.i_holder; - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -Referencer<T, THREADING_MODEL>& -Referencer<T, THREADING_MODEL>::operator=(T *ref) -{ - if( i_holder != NULL ) - deReference(i_holder); - i_holder = NULL; - if( ref != NULL ) - { - i_holder = new ReferenceeHolder(ref); - ++i_holder->i_referenceCount; - } - - return *this; -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( holder != NULL && holder->i_referenceCount > 0); - bool delete_object = false; - - { - // The guard is within the scope due to the guard - // must release earlier than expected. - Lock guard(*holder); - Guard(&guard); - - --holder->i_referenceCount; - if( holder->i_referenceCount == 0 ) - delete_object = true; - } - - if( delete_object ) - { - delete holder->i_referencee; - delete holder; - } -} - -template -< -typename T, -class THREADING_MODEL -> -void -Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL> *holder) -{ - assert( i_holder != NULL ); - Lock guard(*holder); - Guard(&guard); - - ++holder->i_referenceCount; -} -#endif - diff --git a/src/server/shared/Dynamic/FactoryHolder.h b/src/server/shared/Dynamic/FactoryHolder.h index fd5925f5f75..096bdad1783 100644 --- a/src/server/shared/Dynamic/FactoryHolder.h +++ b/src/server/shared/Dynamic/FactoryHolder.h @@ -24,7 +24,6 @@ #include "Define.h" #include "Dynamic/TypeList.h" #include "ObjectRegistry.h" -#include "Policies/SingletonImp.h" /** FactoryHolder holds a factory object of a specific type */ @@ -33,14 +32,15 @@ class FactoryHolder { public: typedef ObjectRegistry<FactoryHolder<T, Key >, Key > FactoryHolderRegistry; - typedef Trinity::Singleton<FactoryHolderRegistry > FactoryHolderRepository; + friend class ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex>; + typedef ACE_Singleton<FactoryHolderRegistry, ACE_Null_Mutex> FactoryHolderRepository; FactoryHolder(Key k) : i_key(k) {} virtual ~FactoryHolder() {} inline Key key() const { return i_key; } - void RegisterSelf(void) { FactoryHolderRepository::Instance().InsertItem(this, i_key); } - void DeregisterSelf(void) { FactoryHolderRepository::Instance().RemoveItem(this, false); } + void RegisterSelf(void) { FactoryHolderRepository::instance()->InsertItem(this, i_key); } + void DeregisterSelf(void) { FactoryHolderRepository::instance()->RemoveItem(this, false); } /// Abstract Factory create method virtual T* Create(void *data = NULL) const = 0; diff --git a/src/server/shared/Dynamic/ObjectRegistry.h b/src/server/shared/Dynamic/ObjectRegistry.h index eaf8e1acd2d..11052a9f0a7 100644 --- a/src/server/shared/Dynamic/ObjectRegistry.h +++ b/src/server/shared/Dynamic/ObjectRegistry.h @@ -23,7 +23,7 @@ #include "Define.h" #include "Dynamic/UnorderedMap.h" -#include "Policies/Singleton.h" +#include "ace/Singleton.h" #include <string> #include <vector> @@ -94,11 +94,6 @@ class ObjectRegistry return i_registeredObjects; } - private: - RegistryMapType i_registeredObjects; - friend class Trinity::OperatorNew<ObjectRegistry<T, Key> >; - - // protected for friend use since it should be a singleton ObjectRegistry() {} ~ObjectRegistry() { @@ -106,6 +101,9 @@ class ObjectRegistry delete iter->second; i_registeredObjects.clear(); } + private: + RegistryMapType i_registeredObjects; + }; #endif diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 0f27400dce2..7a34eaa0c0d 100644 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -20,15 +20,12 @@ #include "Common.h" #include "Log.h" -#include "Policies/SingletonImp.h" #include "Configuration/ConfigEnv.h" #include "Util.h" #include <stdarg.h> #include <stdio.h> -INSTANTIATE_SINGLETON_1( Log ); - Log::Log() : raLogfile(NULL), logfile(NULL), gmLogfile(NULL), charLogfile(NULL), dberLogfile(NULL), chatLogfile(NULL), m_gmlog_per_account(false), diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 53ce4e601b5..fb584d42c27 100644 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -22,7 +22,7 @@ #define TRINITYCORE_LOG_H #include "Common.h" -#include "Policies/Singleton.h" +#include <ace/Singleton.h> #include "Database/DatabaseEnv.h" class Config; @@ -82,9 +82,9 @@ enum ColorTypes const int Colors = int(WHITE)+1; -class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_Thread_Mutex> > +class Log { - friend class Trinity::OperatorNew<Log>; + friend class ACE_Singleton<Log, ACE_Thread_Mutex>; Log(); ~Log(); @@ -172,10 +172,10 @@ class Log : public Trinity::Singleton<Log, Trinity::ClassLevelLockable<Log, ACE_ std::string m_dumpsDir; }; -#define sLog Trinity::Singleton<Log>::Instance() +#define sLog (*ACE_Singleton<Log, ACE_Thread_Mutex>::instance()) #ifdef TRINITY_DEBUG -#define DEBUG_LOG Trinity::Singleton<Log>::Instance().outDebug +#define DEBUG_LOG sLog.outDebug #else #define DEBUG_LOG #endif diff --git a/src/server/shared/Policies/CreationPolicy.h b/src/server/shared/Policies/CreationPolicy.h deleted file mode 100644 index cc38d704e99..00000000000 --- a/src/server/shared/Policies/CreationPolicy.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_CREATIONPOLICY_H -#define TRINITY_CREATIONPOLICY_H - -#include <stdlib.h> -#include "Define.h" - -namespace Trinity -{ - /** - * OperatorNew policy creates an object on the heap using new. - */ - template <class T> - class OperatorNew - { - public: - static T* Create(void) { return (new T); } - static void Destroy(T *obj) { delete obj; } - }; - - /** - * LocalStaticCreation policy creates an object on the stack - * the first time call Create. - */ - template <class T> - class LocalStaticCreation - { - union MaxAlign - { - char t_[sizeof(T)]; - short int shortInt_; - int int_; - long int longInt_; - float float_; - double double_; - long double longDouble_; - struct Test; - int Test::* pMember_; - int (Test::*pMemberFn_)(int); - }; - public: - static T* Create(void) - { - static MaxAlign si_localStatic; - return new(&si_localStatic) T; - } - - static void Destroy(T *obj) { obj->~T(); } - }; - - /** - * CreateUsingMalloc by pass the memory manger. - */ - template<class T> - class CreateUsingMalloc - { - public: - static T* Create() - { - void* p = ::malloc(sizeof(T)); - if (!p) return 0; - return new(p) T; - } - - static void Destroy(T* p) - { - p->~T(); - ::free(p); - } - }; - - /** - * CreateOnCallBack creates the object base on the call back. - */ - template<class T, class CALL_BACK> - class CreateOnCallBack - { - public: - static T* Create() - { - return CALL_BACK::createCallBack(); - } - - static void Destroy(T *p) - { - CALL_BACK::destroyCallBack(p); - } - }; -} -#endif - diff --git a/src/server/shared/Policies/ObjectLifeTime.cpp b/src/server/shared/Policies/ObjectLifeTime.cpp deleted file mode 100644 index fd16873ae92..00000000000 --- a/src/server/shared/Policies/ObjectLifeTime.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <cstdlib> -#include "ObjectLifeTime.h" - -namespace Trinity -{ - extern "C" void external_wrapper(void *p) - { - std::atexit( (void (*)())p ); - } - - void at_exit( void (*func)() ) - { - external_wrapper((void*)func); - } -} - diff --git a/src/server/shared/Policies/ObjectLifeTime.h b/src/server/shared/Policies/ObjectLifeTime.h deleted file mode 100644 index 205434cb613..00000000000 --- a/src/server/shared/Policies/ObjectLifeTime.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_OBJECTLIFETIME_H -#define TRINITY_OBJECTLIFETIME_H - -#include <stdexcept> -#include "Define.h" - -typedef void (* Destroyer)(void); - -namespace Trinity -{ - void at_exit( void (*func)() ); - - template <class T> - class ObjectLifeTime - { - public: - static void ScheduleCall(void (*destroyer)() ) - { - at_exit( destroyer ); - } - - DECLSPEC_NORETURN static void OnDeadReference(void) ATTR_NORETURN; - - }; - - template <class T> - void ObjectLifeTime<T>::OnDeadReference(void) // We don't handle Dead Reference for now - { - throw std::runtime_error("Dead Reference"); - } -} -#endif - diff --git a/src/server/shared/Policies/Singleton.h b/src/server/shared/Policies/Singleton.h deleted file mode 100644 index da898558ca5..00000000000 --- a/src/server/shared/Policies/Singleton.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETON_H -#define TRINITY_SINGLETON_H - -/** - * @brief class Singleton - */ - -#include "CreationPolicy.h" -#include "ThreadingModel.h" -#include "ObjectLifeTime.h" - -namespace Trinity -{ - template - < - typename T, - class ThreadingModel = Trinity::SingleThreaded<T>, - class CreatePolicy = Trinity::OperatorNew<T>, - class LifeTimePolicy = Trinity::ObjectLifeTime<T> - > - class Singleton - { - public: - static T& Instance(); - - protected: - Singleton() {}; - - private: - - // Prohibited actions...this does not prevent hijacking. - Singleton(const Singleton &); - Singleton& operator=(const Singleton &); - - // Singleton Helpers - static void DestroySingleton(); - - // data structure - typedef typename ThreadingModel::Lock Guard; - static T *si_instance; - static bool si_destroyed; - }; -} -#endif - diff --git a/src/server/shared/Policies/SingletonImp.h b/src/server/shared/Policies/SingletonImp.h deleted file mode 100644 index 3e985cd5c64..00000000000 --- a/src/server/shared/Policies/SingletonImp.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_SINGLETONIMPL_H -#define TRINITY_SINGLETONIMPL_H - -#include "Singleton.h" - -// avoid the using namespace here cuz -// its a .h file afterall - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -T& -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy >::Instance() -{ - if( !si_instance ) - { - // double-checked Locking pattern - Guard(); - if( !si_instance ) - { - if( si_destroyed ) - { - si_destroyed = false; - LifeTimePolicy::OnDeadReference(); - } - si_instance = CreatePolicy::Create(); - LifeTimePolicy::ScheduleCall(&DestroySingleton); - } - } - - return *si_instance; -} - -template -< -typename T, -class ThreadingModel, -class CreatePolicy, -class LifeTimePolicy -> -void -Trinity::Singleton<T, ThreadingModel, CreatePolicy, LifeTimePolicy>::DestroySingleton() -{ - CreatePolicy::Destroy(si_instance); - si_instance = NULL; - si_destroyed = true; -} - -#define INSTANTIATE_SINGLETON_1(TYPE) \ - template class Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, Trinity::SingleThreaded<TYPE>, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_2(TYPE, THREADINGMODEL) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, Trinity::OperatorNew<TYPE>, Trinity::ObjectLifeTime<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_3(TYPE, THREADINGMODEL, CREATIONPOLICY ) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeTime<TYPE> >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, Trinity::ObjectLifeType<TYPE> >::si_destroyed = false - -#define INSTANTIATE_SINGLETON_4(TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME) \ - template class Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >; \ - template<> TYPE* Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_instance = 0; \ - template<> bool Trinity::Singleton<TYPE, THREADINGMODEL, CREATIONPOLICY, OBJECTLIFETIME >::si_destroyed = false -#endif - diff --git a/src/server/shared/Policies/ThreadingModel.h b/src/server/shared/Policies/ThreadingModel.h deleted file mode 100644 index a792bf1b7d7..00000000000 --- a/src/server/shared/Policies/ThreadingModel.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITY_THREADINGMODEL_H -#define TRINITY_THREADINGMODEL_H - -/** - * @class ThreadingModel<T> - * - */ - -#include "Define.h" - -namespace Trinity -{ - inline void Guard(void *) {} - - template<typename MUTEX> class GeneralLock - { - public: - GeneralLock(MUTEX &m) : i_mutex(m) - { - i_mutex.acquire(); - } - - ~GeneralLock() - { - i_mutex.release(); - } - private: - GeneralLock(const GeneralLock &); - GeneralLock& operator=(const GeneralLock &); - MUTEX &i_mutex; - }; - - template <class T> - class SingleThreaded - { - public: - - struct Lock // empty object - { - Lock() {} - Lock(const T &) {} - Lock(const SingleThreaded<T> &) // for single threaded we ignore this - { - } - }; - - typedef T VolatileType; - }; - - // object level lockable - template<class T, class MUTEX> - class ObjectLevelLockable - { - public: - ObjectLevelLockable() : i_mtx() {} - - friend class Lock; - - class Lock - { - public: - Lock(ObjectLevelLockable<T, MUTEX> &host) : i_lock(host.i_mtx) - { - } - - private: - GeneralLock<MUTEX> i_lock; - }; - - typedef volatile T VolatileType; - - private: - // prevent the compiler creating a copy construct - ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX> &); - ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX> &); - - MUTEX i_mtx; - }; - - template<class T, class MUTEX> - class ClassLevelLockable - { - public: - class Lock; - friend class Lock; - typedef volatile T VolatileType; - - ClassLevelLockable() {} - - class Lock - { - public: - Lock(T& /*host*/) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock(ClassLevelLockable<T, MUTEX> &) { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.acquire(); } - ~Lock() { ClassLevelLockable<T, MUTEX>::si_mtx.release(); } - }; - - private: - static MUTEX si_mtx; - }; - -} - -template<class T, class MUTEX> MUTEX Trinity::ClassLevelLockable<T, MUTEX>::si_mtx; - -#define INSTANTIATE_CLASS_MUTEX(CTYPE,MUTEX) \ - template class Trinity::ClassLevelLockable<CTYPE, MUTEX > -#endif - diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index 332a607dcad..fb2d828e284 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -33,7 +33,6 @@ #include "WorldSocketMgr.h" #include "Configuration/ConfigEnv.h" #include "Database/DatabaseEnv.h" -#include "SingletonImp.h" #include "CliRunnable.h" #include "Log.h" @@ -58,8 +57,6 @@ extern int m_ServiceStatus; /// \todo Warning disabling not useful under VC++2005. Can somebody say on which compiler it is useful? #pragma warning(disable:4305) -INSTANTIATE_SINGLETON_1( Master ); - volatile uint32 Master::m_masterLoopCounter = 0; /// Handle cored's termination signals diff --git a/src/server/worldserver/Master.h b/src/server/worldserver/Master.h index 76ff2af1457..00628827e2a 100644 --- a/src/server/worldserver/Master.h +++ b/src/server/worldserver/Master.h @@ -26,7 +26,6 @@ #define _MASTER_H #include "Common.h" -#include "Policies/Singleton.h" /// Start the server class Master @@ -43,6 +42,6 @@ class Master void clearOnlineAccounts(); }; -#define sMaster Trinity::Singleton<Master>::Instance() +#define sMaster (*ACE_Singleton<Master, ACE_Null_Mutex>::instance()) #endif /// @} diff --git a/src/server/worldserver/WorldThread/WorldRunnable.cpp b/src/server/worldserver/WorldThread/WorldRunnable.cpp index 3531873ec0c..69639da62fa 100644 --- a/src/server/worldserver/WorldThread/WorldRunnable.cpp +++ b/src/server/worldserver/WorldThread/WorldRunnable.cpp @@ -90,7 +90,7 @@ void WorldRunnable::run() sWorldSocketMgr->StopNetwork(); - MapManager::Instance().UnloadAll(); // unload all grids (including locked in memory) + sMapMgr.UnloadAll(); // unload all grids (including locked in memory) ///- End the database thread WorldDatabase.ThreadEnd(); // free mySQL thread resources diff --git a/win/VC90/shared.vcproj b/win/VC90/shared.vcproj index 2c7310a7929..536939f9d5a 100644 --- a/win/VC90/shared.vcproj +++ b/win/VC90/shared.vcproj @@ -589,22 +589,6 @@ > </File> <Filter - Name="CountedReference" - > - <File - RelativePath="..\..\src\server\shared\Dynamic\CountedReference\Reference.h" - > - </File> - <File - RelativePath="..\..\src\server\shared\Dynamic\CountedReference\ReferenceHolder.h" - > - </File> - <File - RelativePath="..\..\src\server\shared\Dynamic\CountedReference\ReferenceImpl.h" - > - </File> - </Filter> - <Filter Name="LinkedReference" > <File @@ -642,14 +626,6 @@ </File> </Filter> <Filter - Name="Policies" - > - <File - RelativePath="..\..\src\server\shared\Policies\ObjectLifeTime.cpp" - > - </File> - </Filter> - <Filter Name="Threading" > <File |