diff options
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 87 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 5 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 33 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 10 |
4 files changed, 87 insertions, 48 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 82f7ece4477..fb696a13352 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -2618,7 +2618,7 @@ void ObjectMgr::LoadItemTemplates() continue; ItemTemplate& itemTemplate = itemItr->second; - + ItemEffect effect; effect.SpellID = effectEntry->SpellID; effect.Trigger = effectEntry->Trigger; @@ -5715,35 +5715,32 @@ void ObjectMgr::LoadAreaTriggerScripts() uint32 oldMSTime = getMSTime(); _areaTriggerScriptStore.clear(); // need for reload case - QueryResult result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts"); + QueryResult result = WorldDatabase.Query("SELECT entry, ScriptName FROM areatrigger_scripts"); if (!result) { TC_LOG_INFO("server.loading", ">> Loaded 0 areatrigger scripts. DB table `areatrigger_scripts` is empty."); return; } - uint32 count = 0; - do { - ++count; - Field* fields = result->Fetch(); - uint32 Trigger_ID = fields[0].GetUInt32(); - const char *scriptName = fields[1].GetCString(); + uint32 triggerId = fields[0].GetUInt32(); + char const* scriptName = fields[1].GetCString(); - AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); + AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(triggerId); if (!atEntry) { - TC_LOG_ERROR("sql.sql", "Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.", Trigger_ID); + TC_LOG_ERROR("sql.sql", "AreaTrigger (ID: %u) does not exist in `AreaTrigger.dbc`.", triggerId); continue; } - _areaTriggerScriptStore[Trigger_ID] = GetScriptId(scriptName); - } while (result->NextRow()); + _areaTriggerScriptStore[triggerId] = GetScriptId(scriptName); + } + while (result->NextRow()); - TC_LOG_INFO("server.loading", ">> Loaded %u areatrigger scripts in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " areatrigger scripts in %u ms", _areaTriggerScriptStore.size(), GetMSTimeDiffToNow(oldMSTime)); } uint32 ObjectMgr::GetNearestTaxiNode(float x, float y, float z, uint32 mapid, uint32 team) @@ -8557,31 +8554,32 @@ void ObjectMgr::LoadScriptNames() { uint32 oldMSTime = getMSTime(); - _scriptNamesStore.push_back(""); + _scriptNamesStore.emplace_back(""); + QueryResult result = WorldDatabase.Query( - "SELECT DISTINCT(ScriptName) FROM achievement_criteria_data WHERE ScriptName <> '' AND type = 11 " - "UNION " - "SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM item_script_names WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM spell_script_names WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM transports WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM game_weather WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM conditions WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(ScriptName) FROM outdoorpvp_template WHERE ScriptName <> '' " - "UNION " - "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''"); + "SELECT DISTINCT(ScriptName) FROM achievement_criteria_data WHERE ScriptName <> '' AND type = 11 " + "UNION " + "SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM item_script_names WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM spell_script_names WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM transports WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM game_weather WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM conditions WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM outdoorpvp_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''"); if (!result) { @@ -8589,20 +8587,23 @@ void ObjectMgr::LoadScriptNames() return; } - uint32 count = 1; - do { - _scriptNamesStore.push_back((*result)[0].GetString()); - ++count; + _scriptNamesStore.emplace_back((*result)[0].GetCString()); } while (result->NextRow()); std::sort(_scriptNamesStore.begin(), _scriptNamesStore.end()); - TC_LOG_INFO("server.loading", ">> Loaded %d Script Names in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + +#ifdef SCRIPTS + for (size_t i = 1; i < _scriptNamesStore.size(); ++i) + UnusedScriptNames.push_back(_scriptNamesStore[i]); +#endif + + TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " ScriptNames in %u ms", _scriptNamesStore.size(), GetMSTimeDiffToNow(oldMSTime)); } -uint32 ObjectMgr::GetScriptId(const char *name) +uint32 ObjectMgr::GetScriptId(char const* name) { // use binary search to find the script name in the sorted vector // assume "" is the first element diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index e7191735ca1..14f845dcd1b 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -1286,9 +1286,8 @@ class ObjectMgr bool IsVendorItemValid(uint32 vendor_entry, uint32 id, int32 maxcount, uint32 ptime, uint32 ExtendedCost, uint8 type, Player* player = NULL, std::set<uint32>* skip_vendors = NULL, uint32 ORnpcflag = 0) const; void LoadScriptNames(); - ScriptNameContainer &GetScriptNames() { return _scriptNamesStore; } - const char * GetScriptName(uint32 id) const { return id < _scriptNamesStore.size() ? _scriptNamesStore[id].c_str() : ""; } - uint32 GetScriptId(const char *name); + char const* GetScriptName(uint32 id) const { return id < _scriptNamesStore.size() ? _scriptNamesStore[id].c_str() : ""; } + uint32 GetScriptId(char const* name); SpellClickInfoMapBounds GetSpellClickInfoMapBounds(uint32 creature_id) const { diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index ac0b5bbf2e6..055a7a52310 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -34,6 +34,12 @@ #include "WorldPacket.h" #include "WorldSession.h" +// namespace +// { + UnusedScriptContainer UnusedScripts; + UnusedScriptNamesContainer UnusedScriptNames; +// } + // This is the global static registry of scripts. template<class TScript> class ScriptRegistry @@ -89,6 +95,12 @@ class ScriptRegistry { ScriptPointerList[id] = script; sScriptMgr->IncrementScriptCount(); + + #ifdef SCRIPTS + UnusedScriptNamesContainer::const_iterator itr = std::lower_bound(UnusedScriptNames.begin(), UnusedScriptNames.end(), script->GetName()); + if (itr != UnusedScriptNames.end() && *itr == script->GetName()) + UnusedScriptNames.erase(itr); + #endif } else { @@ -106,8 +118,7 @@ class ScriptRegistry // Avoid calling "delete script;" because we are currently in the script constructor // In a valid scenario this will not happen because every script has a name assigned in the database - // If that happens, it's acceptable to just leak a few bytes - + UnusedScripts.push_back(script); return; } } @@ -189,6 +200,15 @@ void ScriptMgr::Initialize() FillSpellSummary(); AddScripts(); +#ifdef SCRIPTS + for (std::string const& scriptName : UnusedScriptNames) + { + TC_LOG_ERROR("sql.sql", "ScriptName '%s' exists in database, but no core script found!", scriptName.c_str()); + } +#endif + + UnloadUnusedScripts(); + TC_LOG_INFO("server.loading", ">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime)); } @@ -229,10 +249,19 @@ void ScriptMgr::Unload() #undef SCR_CLEAR + UnloadUnusedScripts(); + delete[] SpellSummary; delete[] UnitAI::AISpellInfo; } +void ScriptMgr::UnloadUnusedScripts() +{ + for (size_t i = 0; i < UnusedScripts.size(); ++i) + delete UnusedScripts[i]; + UnusedScripts.clear(); +} + void ScriptMgr::LoadDatabase() { sScriptSystemMgr->LoadScriptWaypoints(); diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 5957f3a511a..4431f710976 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -872,6 +872,15 @@ class GroupScript : public ScriptObject // Placed here due to ScriptRegistry::AddScript dependency. #define sScriptMgr ScriptMgr::instance() +// namespace +// { + typedef std::vector<ScriptObject*> UnusedScriptContainer; + typedef std::list<std::string> UnusedScriptNamesContainer; + + extern UnusedScriptContainer UnusedScripts; + extern UnusedScriptNamesContainer UnusedScriptNames; +// } + // Manages registration, loading, and execution of scripts. class ScriptMgr { @@ -900,6 +909,7 @@ class ScriptMgr public: /* Unloading */ void Unload(); + void UnloadUnusedScripts(); public: /* SpellScriptLoader */ |