Core/Game: Move scheduled map scripts counter methods into MapManager

* Since those have nothing to do with core scripts and are
  not wished inside the ScriptMgr
This commit is contained in:
Naios
2016-04-11 20:07:24 +02:00
parent 26dcde94b3
commit 59e3cf82ac
8 changed files with 21 additions and 22 deletions
+1 -1
View File
@@ -4587,7 +4587,7 @@ void ObjectMgr::LoadScripts(ScriptsType type)
if (tableName.empty())
return;
if (sScriptMgr->IsScriptScheduled()) // function cannot be called when scripts are in use.
if (sMapMgr->IsScriptScheduled()) // function cannot be called when scripts are in use.
return;
TC_LOG_INFO("server.loading", "Loading %s...", tableName.c_str());
+1 -1
View File
@@ -71,7 +71,7 @@ Map::~Map()
}
if (!m_scriptSchedule.empty())
sScriptMgr->DecreaseScheduledScriptCount(m_scriptSchedule.size());
sMapMgr->DecreaseScheduledScriptCount(m_scriptSchedule.size());
MMAP::MMapFactory::createOrGetMMapManager()->unloadMapInstance(GetId(), i_InstanceId);
}
+1 -1
View File
@@ -38,10 +38,10 @@
#include "MiscPackets.h"
MapManager::MapManager()
: _nextInstanceId(0), _scheduledScripts(0)
{
i_gridCleanUpDelay = sWorld->getIntConfig(CONFIG_INTERVAL_GRIDCLEAN);
i_timer.SetInterval(sWorld->getIntConfig(CONFIG_INTERVAL_MAPUPDATE));
_nextInstanceId = 0;
}
MapManager::~MapManager() { }
+9 -1
View File
@@ -126,7 +126,12 @@ class TC_GAME_API MapManager
template<typename Worker>
void DoForAllMapsWithMapId(uint32 mapId, Worker&& worker);
private:
uint32 IncreaseScheduledScriptsCount() { return ++_scheduledScripts; }
uint32 DecreaseScheduledScriptCount() { return --_scheduledScripts; }
uint32 DecreaseScheduledScriptCount(size_t count) { return _scheduledScripts -= count; }
bool IsScriptScheduled() const { return _scheduledScripts > 0; }
private:
typedef std::unordered_map<uint32, Map*> MapMapType;
typedef std::vector<bool> InstanceIds;
@@ -150,6 +155,9 @@ private:
InstanceIds _instanceIds;
uint32 _nextInstanceId;
MapUpdater m_updater;
// atomic op counter for active scripts amount
std::atomic<uint32> _scheduledScripts;
};
template<typename Worker>
+4 -3
View File
@@ -20,6 +20,7 @@
#include "GridNotifiers.h"
#include "GossipDef.h"
#include "Map.h"
#include "MapManager.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Item.h"
@@ -57,7 +58,7 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O
if (iter->first == 0)
immedScript = true;
sScriptMgr->IncreaseScheduledScriptsCount();
sMapMgr->IncreaseScheduledScriptsCount();
}
///- If one of the effects should be immediate, launch the script execution
if (/*start &&*/ immedScript && !i_scriptLock)
@@ -85,7 +86,7 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
sa.script = &script;
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + delay), sa));
sScriptMgr->IncreaseScheduledScriptsCount();
sMapMgr->IncreaseScheduledScriptsCount();
///- If effects should be immediate, launch the script execution
if (delay == 0 && !i_scriptLock)
@@ -902,6 +903,6 @@ void Map::ScriptsProcess()
m_scriptSchedule.erase(iter);
iter = m_scriptSchedule.begin();
sScriptMgr->DecreaseScheduledScriptCount();
sMapMgr->DecreaseScheduledScriptCount();
}
}
+1 -1
View File
@@ -241,7 +241,7 @@ struct TSpellSummary
} *SpellSummary;
ScriptMgr::ScriptMgr()
: _scriptCount(0), _scheduledScripts(0), _script_loader_callback(nullptr)
: _scriptCount(0), _script_loader_callback(nullptr)
{
}
-10
View File
@@ -1093,20 +1093,10 @@ class TC_GAME_API ScriptMgr
void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage);
void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage);
public: /* Scheduled scripts */
uint64 IncreaseScheduledScriptsCount() { return ++_scheduledScripts; }
uint64 DecreaseScheduledScriptCount() { return --_scheduledScripts; }
uint64 DecreaseScheduledScriptCount(uint64 count) { return _scheduledScripts -= count; }
bool IsScriptScheduled() const { return _scheduledScripts > 0; }
private:
uint32 _scriptCount;
//atomic op counter for active scripts amount
std::atomic<uint64> _scheduledScripts;
ScriptLoaderCallbackType _script_loader_callback;
};
+4 -4
View File
@@ -253,7 +253,7 @@ public:
static bool HandleReloadAllScriptsCommand(ChatHandler* handler, const char* /*args*/)
{
if (sScriptMgr->IsScriptScheduled())
if (sMapMgr->IsScriptScheduled())
{
handler->PSendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -883,7 +883,7 @@ public:
static bool HandleReloadEventScriptsCommand(ChatHandler* handler, const char* args)
{
if (sScriptMgr->IsScriptScheduled())
if (sMapMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -903,7 +903,7 @@ public:
static bool HandleReloadWpScriptsCommand(ChatHandler* handler, const char* args)
{
if (sScriptMgr->IsScriptScheduled())
if (sMapMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -936,7 +936,7 @@ public:
static bool HandleReloadSpellScriptsCommand(ChatHandler* handler, const char* args)
{
if (sScriptMgr->IsScriptScheduled())
if (sMapMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);