mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
Moved ScriptMgr macros to separated header and created ModuleScript
it will allow Modules to create their own Hooks inside the module itself, to customize/extend their functionalities. An example of its usage will be available in VAS Module: You'll be able to disable VAS with custom conditions from other modules.
This commit is contained in:
@@ -22,6 +22,39 @@
|
||||
#include "WorldPacket.h"
|
||||
#include "Chat.h"
|
||||
|
||||
// Specialize for each script type class like so:
|
||||
template class ScriptRegistry<SpellScriptLoader>;
|
||||
template class ScriptRegistry<ServerScript>;
|
||||
template class ScriptRegistry<WorldScript>;
|
||||
template class ScriptRegistry<FormulaScript>;
|
||||
template class ScriptRegistry<WorldMapScript>;
|
||||
template class ScriptRegistry<InstanceMapScript>;
|
||||
template class ScriptRegistry<BattlegroundMapScript>;
|
||||
template class ScriptRegistry<ItemScript>;
|
||||
template class ScriptRegistry<CreatureScript>;
|
||||
template class ScriptRegistry<GameObjectScript>;
|
||||
template class ScriptRegistry<AreaTriggerScript>;
|
||||
template class ScriptRegistry<BattlegroundScript>;
|
||||
template class ScriptRegistry<OutdoorPvPScript>;
|
||||
template class ScriptRegistry<CommandScript>;
|
||||
template class ScriptRegistry<WeatherScript>;
|
||||
template class ScriptRegistry<AuctionHouseScript>;
|
||||
template class ScriptRegistry<ConditionScript>;
|
||||
template class ScriptRegistry<VehicleScript>;
|
||||
template class ScriptRegistry<DynamicObjectScript>;
|
||||
template class ScriptRegistry<TransportScript>;
|
||||
template class ScriptRegistry<AchievementCriteriaScript>;
|
||||
template class ScriptRegistry<PlayerScript>;
|
||||
template class ScriptRegistry<GuildScript>;
|
||||
template class ScriptRegistry<GroupScript>;
|
||||
template class ScriptRegistry<GlobalScript>;
|
||||
template class ScriptRegistry<UnitScript>;
|
||||
template class ScriptRegistry<AllCreatureScript>;
|
||||
template class ScriptRegistry<AllMapScript>;
|
||||
template class ScriptRegistry<MovementHandlerScript>;
|
||||
|
||||
#include "ScriptMgrMacros.h"
|
||||
|
||||
// This is the global static registry of scripts.
|
||||
/*template<class TScript>
|
||||
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<T>::ScriptMap
|
||||
#define SCR_REG_ITR(T) ScriptRegistry<T>::ScriptMapIterator
|
||||
#define SCR_REG_LST(T) ScriptRegistry<T>::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<T>::GetScriptById(I); \
|
||||
if (!V) \
|
||||
return;
|
||||
#define GET_SCRIPT_RET(T, I, V, R) \
|
||||
T* V = ScriptRegistry<T>::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<GlobalScript>::AddScript(this);
|
||||
}
|
||||
|
||||
// Instantiate static members of ScriptRegistry.
|
||||
template<class TScript> std::map<uint32, TScript*> ScriptRegistry<TScript>::ScriptPointerList;
|
||||
template<class TScript> std::vector<TScript*> ScriptRegistry<TScript>::ALScripts;
|
||||
template<class TScript> uint32 ScriptRegistry<TScript>::_scriptIdCounter = 0;
|
||||
ModuleScript::ModuleScript(const char* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
ScriptRegistry<ModuleScript>::AddScript(this);
|
||||
}
|
||||
|
||||
// Specialize for each script type class like so:
|
||||
template class ScriptRegistry<SpellScriptLoader>;
|
||||
template class ScriptRegistry<ServerScript>;
|
||||
template class ScriptRegistry<WorldScript>;
|
||||
template class ScriptRegistry<FormulaScript>;
|
||||
template class ScriptRegistry<WorldMapScript>;
|
||||
template class ScriptRegistry<InstanceMapScript>;
|
||||
template class ScriptRegistry<BattlegroundMapScript>;
|
||||
template class ScriptRegistry<ItemScript>;
|
||||
template class ScriptRegistry<CreatureScript>;
|
||||
template class ScriptRegistry<GameObjectScript>;
|
||||
template class ScriptRegistry<AreaTriggerScript>;
|
||||
template class ScriptRegistry<BattlegroundScript>;
|
||||
template class ScriptRegistry<OutdoorPvPScript>;
|
||||
template class ScriptRegistry<CommandScript>;
|
||||
template class ScriptRegistry<WeatherScript>;
|
||||
template class ScriptRegistry<AuctionHouseScript>;
|
||||
template class ScriptRegistry<ConditionScript>;
|
||||
template class ScriptRegistry<VehicleScript>;
|
||||
template class ScriptRegistry<DynamicObjectScript>;
|
||||
template class ScriptRegistry<TransportScript>;
|
||||
template class ScriptRegistry<AchievementCriteriaScript>;
|
||||
template class ScriptRegistry<PlayerScript>;
|
||||
template class ScriptRegistry<GuildScript>;
|
||||
template class ScriptRegistry<GroupScript>;
|
||||
template class ScriptRegistry<GlobalScript>;
|
||||
template class ScriptRegistry<UnitScript>;
|
||||
template class ScriptRegistry<AllCreatureScript>;
|
||||
template class ScriptRegistry<AllMapScript>;
|
||||
template class ScriptRegistry<MovementHandlerScript>;
|
||||
|
||||
// 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
|
||||
|
||||
@@ -1017,6 +1017,15 @@ class GlobalScript : public ScriptObject
|
||||
virtual void OnBeforeUpdateArenaPoints(ArenaTeam* /*at*/, std::map<uint32, uint32> & /*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<ScriptMgr, ACE_Null_Mutex>::instance()
|
||||
|
||||
@@ -1460,4 +1469,9 @@ class ScriptRegistry
|
||||
static uint32 _scriptIdCounter;
|
||||
};
|
||||
|
||||
// Instantiate static members of ScriptRegistry.
|
||||
template<class TScript> std::map<uint32, TScript*> ScriptRegistry<TScript>::ScriptPointerList;
|
||||
template<class TScript> std::vector<TScript*> ScriptRegistry<TScript>::ALScripts;
|
||||
template<class TScript> uint32 ScriptRegistry<TScript>::_scriptIdCounter = 0;
|
||||
|
||||
#endif
|
||||
|
||||
35
src/server/game/Scripting/ScriptMgrMacros.h
Normal file
35
src/server/game/Scripting/ScriptMgrMacros.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
// Utility macros to refer to the script registry.
|
||||
#define SCR_REG_MAP(T) ScriptRegistry<T>::ScriptMap
|
||||
#define SCR_REG_ITR(T) ScriptRegistry<T>::ScriptMapIterator
|
||||
#define SCR_REG_LST(T) ScriptRegistry<T>::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<T>::GetScriptById(I); \
|
||||
if (!V) \
|
||||
return;
|
||||
#define GET_SCRIPT_RET(T, I, V, R) \
|
||||
T* V = ScriptRegistry<T>::GetScriptById(I); \
|
||||
if (!V) \
|
||||
return R;
|
||||
|
||||
Reference in New Issue
Block a user