Core/Game: Add a dynamic script reloader which reloads scripts modules on changes.

* is responsible for registering plain modules.
* requires compilation with the `WITH_DYNAMIC_LINKING` flag.
* requires further support of the ScriptMgr.
This commit is contained in:
Aokromes committed 2016-08-10 03:29:20 +02:00
1 parent 3d25c14e74
commit e8e164e28f
8 files changed
+1669 -6

No files matched your search

+22
View File
@@ -263,12 +263,19 @@ void ScriptMgr::Initialize()
FillSpellSummary();
// Load core script systems
// SmartAI
BeginScriptContext("core scripts");
AddSC_SmartScripts();
FinishScriptContext();
// Load all static linked scripts through the script loader function.
BeginScriptContext("static scripts");
ASSERT(_script_loader_callback,
"Script loader callback wasn't registered!");
_script_loader_callback();
FinishScriptContext();
#ifdef SCRIPTS
for (std::string const& scriptName : UnusedScriptNames)
@@ -280,6 +287,21 @@ void ScriptMgr::Initialize()
TC_LOG_INFO("server.loading", ">> Loaded %u C++ scripts in %u ms", GetScriptCount(), GetMSTimeDiffToNow(oldMSTime));
}
void ScriptMgr::BeginScriptContext(std::string const& context)
{
_currentContext = context;
}
void ScriptMgr::FinishScriptContext()
{
_currentContext.clear();
}
void ScriptMgr::ReleaseScriptContext(std::string const& /*context*/)
{
// ToDo
}
void ScriptMgr::Unload()
{
#define SCR_CLEAR(T) \
+13 -6
View File
@@ -837,9 +837,6 @@ class TC_GAME_API GroupScript : public ScriptObject
virtual void OnDisband(Group* /*group*/) { }
};
// Placed here due to ScriptRegistry::AddScript dependency.
#define sScriptMgr ScriptMgr::instance()
// namespace
// {
typedef std::list<std::string> UnusedScriptNamesContainer;
@@ -855,12 +852,13 @@ class TC_GAME_API ScriptMgr
ScriptMgr();
virtual ~ScriptMgr();
void FillSpellSummary();
void LoadDatabase();
public: /* Initialization */
static ScriptMgr* instance();
void Initialize();
void LoadDatabase();
void FillSpellSummary();
const char* ScriptsVersion() const { return "Integrated Trinity Scripts"; }
@@ -876,6 +874,12 @@ class TC_GAME_API ScriptMgr
_script_loader_callback = script_loader_callback;
}
public: /* Script contexts */
void BeginScriptContext(std::string const& context);
void FinishScriptContext();
void ReleaseScriptContext(std::string const& context);
public: /* Unloading */
void Unload();
@@ -1106,13 +1110,16 @@ class TC_GAME_API ScriptMgr
bool IsScriptScheduled() const { return _scheduledScripts > 0; }
private:
uint32 _scriptCount;
//atomic op counter for active scripts amount
std::atomic<uint32> _scheduledScripts;
ScriptLoaderCallbackType _script_loader_callback;
std::string _currentContext;
};
#define sScriptMgr ScriptMgr::instance()
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCRIPT_RELOADER_H
#define SCRIPT_RELOADER_H
#include <memory>
#include <string>
#include "Define.h"
#include <boost/filesystem/path.hpp>
/// Represents a strong reference to a dynamic library which
/// provides C++ scripts. As long as one reference to the library exists
/// the library is kept loaded in the server, which makes it possible to lazy
/// unload several script types on demand (like SpellScripts), and to
/// provide multiple versions of the same script to the script factories.
///
/// Acquire a new reference through using:
/// `ScriptReloadMgr::AcquireModuleReferenceOfContext`
class ModuleReference
{
public:
virtual ~ModuleReference() { }
/// Returns the git revision hash of the referenced script module
virtual char const* GetScriptModuleRevisionHash() const = 0;
/// Returns the name of the referenced script module
virtual char const* GetScriptModule() const = 0;
/// Returns the path to the script module
virtual boost::filesystem::path const& GetModulePath() const = 0;
};
/// Provides the whole physical dynamic library unloading capability.
/// Loads, Reloads and Unloads dynamic libraries on changes and
/// informs the ScriptMgr about changes which were made.
/// The ScriptReloadMgr is also responsible for watching the source directory
/// and to invoke a build on changes.
class TC_GAME_API ScriptReloadMgr
{
protected:
ScriptReloadMgr() { }
public:
virtual ~ScriptReloadMgr() { }
/// Initializes the ScriptReloadMgr
virtual void Initialize() { }
/// Needs to be called periodically to check for updates on script modules.
/// Expects to be invoked in a thread safe way which means it's required that
/// the current thread is the only one which accesses the world data.
virtual void Update() { }
/// Unloads the ScriptReloadMgr
virtual void Unload() { }
/// Returns an owning reference to the current module of the given context
static std::shared_ptr<ModuleReference> AcquireModuleReferenceOfContext(
std::string const& context);
/// Returns the unique ScriptReloadMgr singleton instance
static ScriptReloadMgr* instance();
};
#define sScriptReloadMgr ScriptReloadMgr::instance()
#endif // SCRIPT_RELOADER_H