diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 432b3c141..f0a8f6100 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -22,6 +22,39 @@ #include "WorldPacket.h" #include "Chat.h" +// Specialize for each script type class like so: +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; +template class ScriptRegistry; + +#include "ScriptMgrMacros.h" + // This is the global static registry of scripts. /*template class ScriptRegistry @@ -119,35 +152,6 @@ class ScriptRegistry static uint32 _scriptIdCounter; };*/ -// Utility macros to refer to the script registry. -#define SCR_REG_MAP(T) ScriptRegistry::ScriptMap -#define SCR_REG_ITR(T) ScriptRegistry::ScriptMapIterator -#define SCR_REG_LST(T) ScriptRegistry::ScriptPointerList - -// Utility macros for looping over scripts. -#define FOR_SCRIPTS(T, C, E) \ - if (!SCR_REG_LST(T).empty()) \ - for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \ - C != SCR_REG_LST(T).end(); ++C) -#define FOR_SCRIPTS_RET(T, C, E, R) \ - if (SCR_REG_LST(T).empty()) \ - return R; \ - for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \ - C != SCR_REG_LST(T).end(); ++C) -#define FOREACH_SCRIPT(T) \ - FOR_SCRIPTS(T, itr, end) \ - itr->second - -// Utility macros for finding specific scripts. -#define GET_SCRIPT(T, I, V) \ - T* V = ScriptRegistry::GetScriptById(I); \ - if (!V) \ - return; -#define GET_SCRIPT_RET(T, I, V, R) \ - T* V = ScriptRegistry::GetScriptById(I); \ - if (!V) \ - return R; - ScriptMgr::ScriptMgr() : _scriptCount(0), _scheduledScripts(0) { @@ -196,6 +200,8 @@ void ScriptMgr::Unload() SCR_CLEAR(PlayerScript); SCR_CLEAR(GuildScript); SCR_CLEAR(GroupScript); + SCR_CLEAR(GlobalScript); + SCR_CLEAR(ModuleScript); #undef SCR_CLEAR } @@ -1799,48 +1805,9 @@ GlobalScript::GlobalScript(const char* name) ScriptRegistry::AddScript(this); } -// Instantiate static members of ScriptRegistry. -template std::map ScriptRegistry::ScriptPointerList; -template std::vector ScriptRegistry::ALScripts; -template uint32 ScriptRegistry::_scriptIdCounter = 0; +ModuleScript::ModuleScript(const char* name) + : ScriptObject(name) +{ + ScriptRegistry::AddScript(this); +} -// Specialize for each script type class like so: -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; -template class ScriptRegistry; - -// Undefine utility macros. -#undef GET_SCRIPT_RET -#undef GET_SCRIPT -#undef FOREACH_SCRIPT -#undef FOR_SCRIPTS_RET -#undef FOR_SCRIPTS -#undef SCR_REG_LST -#undef SCR_REG_ITR -#undef SCR_REG_MAP diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 31ae6f6f5..3710d8d55 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -1017,6 +1017,15 @@ class GlobalScript : public ScriptObject virtual void OnBeforeUpdateArenaPoints(ArenaTeam* /*at*/, std::map & /*ap*/) { } }; +// this class can be used to be extended by Modules +// creating their own custom hooks inside module itself +class ModuleScript : public ScriptObject +{ + protected: + + ModuleScript(const char* name); +}; + // Placed here due to ScriptRegistry::AddScript dependency. #define sScriptMgr ACE_Singleton::instance() @@ -1460,4 +1469,9 @@ class ScriptRegistry static uint32 _scriptIdCounter; }; +// Instantiate static members of ScriptRegistry. +template std::map ScriptRegistry::ScriptPointerList; +template std::vector ScriptRegistry::ALScripts; +template uint32 ScriptRegistry::_scriptIdCounter = 0; + #endif diff --git a/src/server/game/Scripting/ScriptMgrMacros.h b/src/server/game/Scripting/ScriptMgrMacros.h new file mode 100644 index 000000000..7390e93b1 --- /dev/null +++ b/src/server/game/Scripting/ScriptMgrMacros.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2 + * Copyright (C) 2008-2016 TrinityCore + * Copyright (C) 2005-2009 MaNGOS + */ + +// Utility macros to refer to the script registry. +#define SCR_REG_MAP(T) ScriptRegistry::ScriptMap +#define SCR_REG_ITR(T) ScriptRegistry::ScriptMapIterator +#define SCR_REG_LST(T) ScriptRegistry::ScriptPointerList + +// Utility macros for looping over scripts. +#define FOR_SCRIPTS(T, C, E) \ + if (!SCR_REG_LST(T).empty()) \ + for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \ + C != SCR_REG_LST(T).end(); ++C) +#define FOR_SCRIPTS_RET(T, C, E, R) \ + if (SCR_REG_LST(T).empty()) \ + return R; \ + for (SCR_REG_ITR(T) C = SCR_REG_LST(T).begin(); \ + C != SCR_REG_LST(T).end(); ++C) +#define FOREACH_SCRIPT(T) \ + FOR_SCRIPTS(T, itr, end) \ + itr->second + +// Utility macros for finding specific scripts. +#define GET_SCRIPT(T, I, V) \ + T* V = ScriptRegistry::GetScriptById(I); \ + if (!V) \ + return; +#define GET_SCRIPT_RET(T, I, V, R) \ + T* V = ScriptRegistry::GetScriptById(I); \ + if (!V) \ + return R; +