Core/Misc: move scheduled scripts counter to ScriptMgr (which is more logical, isn't it?)

This commit is contained in:
zergtmn
2011-04-13 12:07:20 +06:00
committed by Azazel
parent e196dd80bd
commit 1551b8a011
9 changed files with 34 additions and 33 deletions
+2 -2
View File
@@ -4907,12 +4907,12 @@ void ObjectMgr::LoadScripts(ScriptsType type)
if (tableName.empty())
return;
if (sWorld->IsScriptScheduled()) // function don't must be called in time scripts use.
if (sScriptMgr->IsScriptScheduled()) // function cannot be called when scripts are in use.
return;
sLog->outString("Loading %s...", tableName.c_str());
scripts->clear(); // need for reload support
scripts->clear(); // need for reload support
bool isSpellScriptTable = (type == SCRIPTS_SPELL);
char buff[125];
+1 -1
View File
@@ -53,7 +53,7 @@ Map::~Map()
}
if (!m_scriptSchedule.empty())
sWorld->DecreaseScheduledScriptCount(m_scriptSchedule.size());
sScriptMgr->DecreaseScheduledScriptCount(m_scriptSchedule.size());
}
bool Map::ExistMap(uint32 mapid,int gx,int gy)
+3 -1
View File
@@ -533,7 +533,9 @@ class Map : public GridRefManager<NGridType>
std::set<WorldObject *> i_objectsToRemove;
std::map<WorldObject*, bool> i_objectsToSwitch;
std::set<WorldObject*> i_worldObjects;
std::multimap<time_t, ScriptAction> m_scriptSchedule;
typedef std::multimap<time_t, ScriptAction> ScriptScheduleMap;
ScriptScheduleMap m_scriptSchedule;
// Type specific code for add/remove to/from grid
template<class T>
+7 -7
View File
@@ -28,6 +28,7 @@
#include "MapManager.h"
#include "ObjectMgr.h"
#include "MapRefManager.h"
#include "ScriptMgr.h"
/// Put scripts in the execution queue
void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, Object* target)
@@ -53,11 +54,11 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O
sa.ownerGUID = ownerGUID;
sa.script = &iter->second;
m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld->GetGameTime() + iter->first), sa));
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + iter->first), sa));
if (iter->first == 0)
immedScript = true;
sWorld->IncreaseScheduledScriptsCount();
sScriptMgr->IncreaseScheduledScriptsCount();
}
///- If one of the effects should be immediate, launch the script execution
if (/*start &&*/ immedScript && !i_scriptLock)
@@ -83,9 +84,9 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
sa.ownerGUID = ownerGUID;
sa.script = &script;
m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld->GetGameTime() + delay), sa));
m_scriptSchedule.insert(ScriptScheduleMap::value_type(time_t(sWorld->GetGameTime() + delay), sa));
sWorld->IncreaseScheduledScriptsCount();
sScriptMgr->IncreaseScheduledScriptsCount();
///- If effects should be immediate, launch the script execution
if (delay == 0 && !i_scriptLock)
@@ -289,7 +290,7 @@ void Map::ScriptsProcess()
return;
///- Process overdue queued scripts
std::multimap<time_t, ScriptAction>::iterator iter = m_scriptSchedule.begin();
ScriptScheduleMap::iterator iter = m_scriptSchedule.begin();
// ok as multimap is a *sorted* associative container
while (!m_scriptSchedule.empty() && (iter->first <= sWorld->GetGameTime()))
{
@@ -923,8 +924,7 @@ void Map::ScriptsProcess()
}
m_scriptSchedule.erase(iter);
sWorld->DecreaseScheduledScriptCount();
iter = m_scriptSchedule.begin();
sScriptMgr->DecreaseScheduledScriptCount();
}
}
+1 -1
View File
@@ -135,7 +135,7 @@ void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget)
}
ScriptMgr::ScriptMgr()
: _scriptCount(0)
: _scriptCount(0), _scheduledScripts(0)
{
}
+10
View File
@@ -21,6 +21,7 @@
#include "Common.h"
#include <ace/Singleton.h>
#include <ace/Atomic_Op.h>
#include "DBCStores.h"
#include "Player.h"
@@ -766,6 +767,9 @@ class ScriptMgr
uint32 _scriptCount;
//atomic op counter for active scripts amount
ACE_Atomic_Op<ACE_Thread_Mutex, long> _scheduledScripts;
public: /* Initialization */
void Initialize();
@@ -971,6 +975,12 @@ class ScriptMgr
void OnGroupChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid);
void OnGroupDisband(Group* group);
public: /* Scheduled scripts */
uint32 IncreaseScheduledScriptsCount() { return uint32(++_scheduledScripts); }
uint32 DecreaseScheduledScriptCount() { return uint32(--_scheduledScripts); }
uint32 DecreaseScheduledScriptCount(size_t count) { return uint32(_scheduledScripts -= count); }
bool IsScriptScheduled() const { return _scheduledScripts > 0; }
public: /* ScriptRegistry */
// This is the global static registry of scripts.
+2 -3
View File
@@ -92,15 +92,14 @@ World::World()
m_allowMovement = true;
m_ShutdownMask = 0;
m_ShutdownTimer = 0;
m_gameTime=time(NULL);
m_startTime=m_gameTime;
m_gameTime = time(NULL);
m_startTime = m_gameTime;
m_maxActiveSessionCount = 0;
m_maxQueuedSessionCount = 0;
m_PlayerCount = 0;
m_MaxPlayerCount = 0;
m_NextDailyQuestReset = 0;
m_NextWeeklyQuestReset = 0;
m_scheduledScripts = 0;
m_defaultDbcLocale = LOCALE_enUS;
m_availableDbcLocaleMask = 0;
-10
View File
@@ -27,7 +27,6 @@
#include "Timer.h"
#include <ace/Singleton.h>
#include "SharedDefines.h"
#include <ace/Atomic_Op.h>
#include "QueryResult.h"
#include "Callback.h"
@@ -39,7 +38,6 @@ class Object;
class WorldPacket;
class WorldSession;
class Player;
struct ScriptInfo;
class WorldSocket;
class SystemMgr;
@@ -697,11 +695,6 @@ class World
BanReturn BanCharacter(std::string name, std::string duration, std::string reason, std::string author);
bool RemoveBanCharacter(std::string name);
uint32 IncreaseScheduledScriptsCount() { return (uint32)++m_scheduledScripts; }
uint32 DecreaseScheduledScriptCount() { return (uint32)--m_scheduledScripts; }
uint32 DecreaseScheduledScriptCount(size_t count) { return (uint32)(m_scheduledScripts -= count); }
bool IsScriptScheduled() const { return m_scheduledScripts > 0; }
// for max speed access
static float GetMaxVisibleDistanceOnContinents() { return m_MaxVisibleDistanceOnContinents; }
static float GetMaxVisibleDistanceInInstances() { return m_MaxVisibleDistanceInInstances; }
@@ -760,9 +753,6 @@ class World
bool m_isClosed;
//atomic op counter for active scripts amount
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_scheduledScripts;
time_t m_startTime;
time_t m_gameTime;
IntervalTimer m_timers[WUPDATE_COUNT];
+8 -8
View File
@@ -248,7 +248,7 @@ public:
static bool HandleReloadAllScriptsCommand(ChatHandler* handler, const char* /*args*/)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->PSendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -946,7 +946,7 @@ public:
static bool HandleReloadGossipScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -966,7 +966,7 @@ public:
static bool HandleReloadGameObjectScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -986,7 +986,7 @@ public:
static bool HandleReloadEventScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -1006,7 +1006,7 @@ public:
static bool HandleReloadWpScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -1051,7 +1051,7 @@ public:
static bool HandleReloadQuestEndScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -1071,7 +1071,7 @@ public:
static bool HandleReloadQuestStartScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);
@@ -1091,7 +1091,7 @@ public:
static bool HandleReloadSpellScriptsCommand(ChatHandler* handler, const char* args)
{
if (sWorld->IsScriptScheduled())
if (sScriptMgr->IsScriptScheduled())
{
handler->SendSysMessage("DB scripts used currently, please attempt reload later.");
handler->SetSentErrorMessage(true);