mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Game: Rewrote the ScriptMgr to support script reloading.
* Finally this commit enables dynamic script hotswapping and finished the PR #15671. * Split the storage layout to use optimized storages for database bound and unbound scripts. * Add several unload workers to reload scripts correctly -> Requires further investigation. * Fixes memory leaks in ScriptMgr when dropping invalid scripts. * Fixes VehicleScripts * Makes OutdoorPvP scripts reloadable * Makes InstanceMapScripts reloadable * Makes CommandScripts reloadable
This commit is contained in:
@@ -46,6 +46,7 @@ class InstanceMap;
|
||||
class InstanceScript;
|
||||
class Item;
|
||||
class Map;
|
||||
class ModuleReference;
|
||||
class OutdoorPvP;
|
||||
class Player;
|
||||
class Quest;
|
||||
@@ -156,14 +157,8 @@ class TC_GAME_API ScriptObject
|
||||
|
||||
protected:
|
||||
|
||||
ScriptObject(const char* name)
|
||||
: _name(name)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ScriptObject()
|
||||
{
|
||||
}
|
||||
ScriptObject(const char* name);
|
||||
virtual ~ScriptObject();
|
||||
|
||||
private:
|
||||
|
||||
@@ -337,7 +332,8 @@ class TC_GAME_API WorldMapScript : public ScriptObject, public MapScript<Map>
|
||||
WorldMapScript(const char* name, uint32 mapId);
|
||||
};
|
||||
|
||||
class TC_GAME_API InstanceMapScript : public ScriptObject, public MapScript<InstanceMap>
|
||||
class TC_GAME_API InstanceMapScript
|
||||
: public ScriptObject, public MapScript<InstanceMap>
|
||||
{
|
||||
protected:
|
||||
|
||||
@@ -833,13 +829,6 @@ class TC_GAME_API GroupScript : public ScriptObject
|
||||
virtual void OnDisband(Group* /*group*/) { }
|
||||
};
|
||||
|
||||
|
||||
// namespace
|
||||
// {
|
||||
typedef std::list<std::string> UnusedScriptNamesContainer;
|
||||
TC_GAME_API extern UnusedScriptNamesContainer UnusedScriptNames;
|
||||
// }
|
||||
|
||||
// Manages registration, loading, and execution of scripts.
|
||||
class TC_GAME_API ScriptMgr
|
||||
{
|
||||
@@ -852,14 +841,14 @@ class TC_GAME_API ScriptMgr
|
||||
void FillSpellSummary();
|
||||
void LoadDatabase();
|
||||
|
||||
void IncreaseScriptCount() { ++_scriptCount; }
|
||||
void DecreaseScriptCount() { --_scriptCount; }
|
||||
|
||||
public: /* Initialization */
|
||||
static ScriptMgr* instance();
|
||||
|
||||
void Initialize();
|
||||
|
||||
const char* ScriptsVersion() const { return "Integrated Trinity Scripts"; }
|
||||
|
||||
void IncrementScriptCount() { ++_scriptCount; }
|
||||
uint32 GetScriptCount() const { return _scriptCount; }
|
||||
|
||||
typedef void(*ScriptLoaderCallbackType)();
|
||||
@@ -872,10 +861,25 @@ class TC_GAME_API ScriptMgr
|
||||
}
|
||||
|
||||
public: /* Script contexts */
|
||||
void BeginScriptContext(std::string const& context);
|
||||
void FinishScriptContext();
|
||||
|
||||
/// Set the current script context, which allows the ScriptMgr
|
||||
/// to accept new scripts in this context.
|
||||
/// Requires a SwapScriptContext() call afterwards to load the new scripts.
|
||||
void SetScriptContext(std::string const& context);
|
||||
/// Returns the current script context.
|
||||
std::string const& GetCurrentScriptContext() const { return _currentContext; }
|
||||
/// Releases all scripts associated with the given script context immediately.
|
||||
/// Requires a SwapScriptContext() call afterwards to finish the unloading.
|
||||
void ReleaseScriptContext(std::string const& context);
|
||||
/// Executes all changed introduced by SetScriptContext and ReleaseScriptContext.
|
||||
/// It is possible to combine multiple SetScriptContext and ReleaseScriptContext
|
||||
/// calls for better performance (bulk changes).
|
||||
void SwapScriptContext(bool initialize = false);
|
||||
|
||||
/// Acquires a strong module reference to the module containing the given script name,
|
||||
/// which prevents the shared library which contains the script from unloading.
|
||||
/// The shared library is lazy unloaded as soon as all references to it are released.
|
||||
std::shared_ptr<ModuleReference> AcquireModuleReferenceOfScriptName(
|
||||
std::string const& scriptname) const;
|
||||
|
||||
public: /* Unloading */
|
||||
|
||||
@@ -885,7 +889,7 @@ class TC_GAME_API ScriptMgr
|
||||
|
||||
void CreateSpellScripts(uint32 spellId, std::list<SpellScript*>& scriptVector);
|
||||
void CreateAuraScripts(uint32 spellId, std::list<AuraScript*>& scriptVector);
|
||||
void CreateSpellScriptLoaders(uint32 spellId, std::vector<std::pair<SpellScriptLoader*, std::multimap<uint32, uint32>::iterator> >& scriptVector);
|
||||
SpellScriptLoader* GetSpellScriptLoader(uint32 scriptId);
|
||||
|
||||
public: /* ServerScript */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user