diff options
author | Yehonal <yehonal.azeroth@gmail.com> | 2016-08-07 12:28:17 +0200 |
---|---|---|
committer | Yehonal <yehonal.azeroth@gmail.com> | 2016-08-07 12:28:17 +0200 |
commit | 5b824569a9f80cc08c98dbae3e2c8be3b3b587fc (patch) | |
tree | 438f2cb15537a17e618a53e99fde50d6829686e5 /src/server/game/Scripting/ScriptMgr.cpp | |
parent | e5f8ecd7ecd70a413d27dab6c375647a3f6b0a12 (diff) |
[CORE] Rewritten ScriptMgr to be initialized before server load
Now ScriptMgr can be initialized before config allowing
to create scripts that can change the behaviour of
server before loading anything
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.cpp')
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 3e448ae84c..80bbaa9e0c 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -163,6 +163,7 @@ class ScriptRegistry ScriptMgr::ScriptMgr() : _scriptCount(0), _scheduledScripts(0) { + } ScriptMgr::~ScriptMgr() @@ -171,18 +172,8 @@ ScriptMgr::~ScriptMgr() void ScriptMgr::Initialize() { - uint32 oldMSTime = getMSTime(); - - LoadDatabase(); - - sLog->outString("Loading C++ scripts"); - - FillSpellSummary(); AddScripts(); - CheckIfScriptsInDatabaseExist(); - - sLog->outString(">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime)); - sLog->outString(); + sLog->outString("Loading C++ scripts"); } void ScriptMgr::Unload() @@ -223,7 +214,32 @@ void ScriptMgr::Unload() void ScriptMgr::LoadDatabase() { + uint32 oldMSTime = getMSTime(); + sScriptSystemMgr->LoadScriptWaypoints(); + + // Add all scripts that must be loaded after db/maps + ScriptRegistry<WorldMapScript>::AddALScripts(); + ScriptRegistry<BattlegroundMapScript>::AddALScripts(); + ScriptRegistry<InstanceMapScript>::AddALScripts(); + ScriptRegistry<SpellScriptLoader>::AddALScripts(); + ScriptRegistry<ItemScript>::AddALScripts(); + ScriptRegistry<CreatureScript>::AddALScripts(); + ScriptRegistry<GameObjectScript>::AddALScripts(); + ScriptRegistry<AreaTriggerScript>::AddALScripts(); + ScriptRegistry<BattlegroundScript>::AddALScripts(); + ScriptRegistry<OutdoorPvPScript>::AddALScripts(); + ScriptRegistry<WeatherScript>::AddALScripts(); + ScriptRegistry<ConditionScript>::AddALScripts(); + ScriptRegistry<TransportScript>::AddALScripts(); + ScriptRegistry<AchievementCriteriaScript>::AddALScripts(); + + FillSpellSummary(); + + CheckIfScriptsInDatabaseExist(); + + sLog->outString(">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); } struct TSpellSummary @@ -437,9 +453,14 @@ void ScriptMgr::OnOpenStateChange(bool open) FOREACH_SCRIPT(WorldScript)->OnOpenStateChange(open); } -void ScriptMgr::OnConfigLoad(bool reload) +void ScriptMgr::OnBeforeConfigLoad(bool reload) +{ + FOREACH_SCRIPT(WorldScript)->OnBeforeConfigLoad(reload); +} + +void ScriptMgr::OnAfterConfigLoad(bool reload) { - FOREACH_SCRIPT(WorldScript)->OnConfigLoad(reload); + FOREACH_SCRIPT(WorldScript)->OnAfterConfigLoad(reload); } void ScriptMgr::OnMotdChange(std::string& newMotd) @@ -1326,27 +1347,18 @@ FormulaScript::FormulaScript(const char* name) WorldMapScript::WorldMapScript(const char* name, uint32 mapId) : ScriptObject(name), MapScript<Map>(mapId) { - if (GetEntry() && !GetEntry()->IsWorldMap()) - sLog->outError("WorldMapScript for map %u is invalid.", mapId); - ScriptRegistry<WorldMapScript>::AddScript(this); } InstanceMapScript::InstanceMapScript(const char* name, uint32 mapId) : ScriptObject(name), MapScript<InstanceMap>(mapId) { - if (GetEntry() && !GetEntry()->IsDungeon()) - sLog->outError("InstanceMapScript for map %u is invalid.", mapId); - ScriptRegistry<InstanceMapScript>::AddScript(this); } BattlegroundMapScript::BattlegroundMapScript(const char* name, uint32 mapId) : ScriptObject(name), MapScript<BattlegroundMap>(mapId) { - if (GetEntry() && !GetEntry()->IsBattleground()) - sLog->outError("BattlegroundMapScript for map %u is invalid.", mapId); - ScriptRegistry<BattlegroundMapScript>::AddScript(this); } @@ -1454,6 +1466,7 @@ GroupScript::GroupScript(const char* name) // 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; // Specialize for each script type class like so: |