mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
@@ -37,7 +37,6 @@
|
||||
|
||||
// namespace
|
||||
// {
|
||||
UnusedScriptContainer UnusedScripts;
|
||||
UnusedScriptNamesContainer UnusedScriptNames;
|
||||
// }
|
||||
|
||||
@@ -107,8 +106,9 @@ class ScriptRegistry
|
||||
// The actual list of scripts. This will be accessed concurrently, so it must not be modified
|
||||
// after server startup.
|
||||
static ScriptMap ScriptPointerList;
|
||||
static std::vector<TScript*> Scripts;
|
||||
|
||||
static void AddScript(TScript* const script)
|
||||
static void AddScript(TScript* const script, bool addToDeleteContainer = true)
|
||||
{
|
||||
ASSERT(script);
|
||||
|
||||
@@ -126,6 +126,8 @@ class ScriptRegistry
|
||||
}
|
||||
|
||||
AddScript(is_script_database_bound<TScript>{}, script);
|
||||
if (addToDeleteContainer)
|
||||
Scripts.push_back(script);
|
||||
}
|
||||
|
||||
// Gets a script by its ID (assigned by ObjectMgr).
|
||||
@@ -186,11 +188,6 @@ class ScriptRegistry
|
||||
{
|
||||
// The script uses a script name from database, but isn't assigned to anything.
|
||||
TC_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str());
|
||||
|
||||
// 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
|
||||
UnusedScripts.push_back(script);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +207,7 @@ class ScriptRegistry
|
||||
#define SCR_REG_MAP(T) ScriptRegistry<T>::ScriptMap
|
||||
#define SCR_REG_ITR(T) ScriptRegistry<T>::ScriptMapIterator
|
||||
#define SCR_REG_LST(T) ScriptRegistry<T>::ScriptPointerList
|
||||
#define SCR_REG_VEC(T) ScriptRegistry<T>::Scripts
|
||||
|
||||
// Utility macros for looping over scripts.
|
||||
#define FOR_SCRIPTS(T, C, E) \
|
||||
@@ -266,17 +264,15 @@ void ScriptMgr::Initialize()
|
||||
}
|
||||
#endif
|
||||
|
||||
UnloadUnusedScripts();
|
||||
|
||||
TC_LOG_INFO("server.loading", ">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void ScriptMgr::Unload()
|
||||
{
|
||||
#define SCR_CLEAR(T) \
|
||||
for (SCR_REG_ITR(T) itr = SCR_REG_LST(T).begin(); itr != SCR_REG_LST(T).end(); ++itr) \
|
||||
delete itr->second; \
|
||||
SCR_REG_LST(T).clear();
|
||||
for (T* scr : SCR_REG_VEC(T)) \
|
||||
delete scr; \
|
||||
SCR_REG_VEC(T).clear();
|
||||
|
||||
// Clear scripts for every script type.
|
||||
SCR_CLEAR(SpellScriptLoader);
|
||||
@@ -308,19 +304,10 @@ 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();
|
||||
@@ -1558,8 +1545,7 @@ FormulaScript::FormulaScript(const char* name)
|
||||
UnitScript::UnitScript(const char* name, bool addToScripts)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
if (addToScripts)
|
||||
ScriptRegistry<UnitScript>::AddScript(this);
|
||||
ScriptRegistry<UnitScript>::AddScript(this, addToScripts);
|
||||
}
|
||||
|
||||
WorldMapScript::WorldMapScript(const char* name, uint32 mapId)
|
||||
@@ -1699,6 +1685,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>::Scripts;
|
||||
template<class TScript> uint32 ScriptRegistry<TScript>::_scriptIdCounter = 0;
|
||||
|
||||
// Specialize for each script type class like so:
|
||||
|
||||
@@ -842,10 +842,7 @@ class GroupScript : public ScriptObject
|
||||
|
||||
// namespace
|
||||
// {
|
||||
typedef std::vector<ScriptObject*> UnusedScriptContainer;
|
||||
typedef std::list<std::string> UnusedScriptNamesContainer;
|
||||
|
||||
extern UnusedScriptContainer UnusedScripts;
|
||||
extern UnusedScriptNamesContainer UnusedScriptNames;
|
||||
// }
|
||||
|
||||
@@ -877,7 +874,6 @@ class ScriptMgr
|
||||
public: /* Unloading */
|
||||
|
||||
void Unload();
|
||||
void UnloadUnusedScripts();
|
||||
|
||||
public: /* SpellScriptLoader */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user