mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 01:59:09 +00:00
feat(Core/Scripts): Optimize PlayerScripts by calling only overridden/implemented functions. (#18672)
* feat(Core/Scripts): Optimize PlayerScripts by calling only overridden/implemented functions. * Fix codestyle. * Fix typo * PLAYERHOOK_END is not a hook * Address code review feedback. Co-authored-by: Winfidonarleyan <dowlandtop@yandex.com> * Codestyle fixes * Fix typo Co-authored-by: PkllonG --------- Co-authored-by: Winfidonarleyan <dowlandtop@yandex.com>
This commit is contained in:
committed by
GitHub
parent
fd029f81aa
commit
f792b0d708
@@ -710,30 +710,42 @@ public:
|
||||
typedef std::map<uint32, TScript*> ScriptMap;
|
||||
typedef typename ScriptMap::iterator ScriptMapIterator;
|
||||
|
||||
typedef std::vector<TScript*> ScriptVector;
|
||||
typedef std::vector<std::pair<TScript*,std::vector<uint16>>> ScriptVector;
|
||||
typedef typename ScriptVector::iterator ScriptVectorIterator;
|
||||
|
||||
typedef std::vector<std::vector<TScript*>> EnabledHooksVector;
|
||||
typedef typename EnabledHooksVector::iterator EnabledHooksVectorIterator;
|
||||
|
||||
// The actual list of scripts. This will be accessed concurrently, so it must not be modified
|
||||
// after server startup.
|
||||
static ScriptMap ScriptPointerList;
|
||||
// After database load scripts
|
||||
static ScriptVector ALScripts;
|
||||
// The list of hook types with the list of enabled scripts for this specific hook.
|
||||
// With this approach, we wouldn't call all available hooks in case if we override just one hook.
|
||||
static EnabledHooksVector EnabledHooks;
|
||||
|
||||
static void AddScript(TScript* const script)
|
||||
static void AddScript(TScript* const script, std::vector<uint16> enabledHooks = {})
|
||||
{
|
||||
ASSERT(script);
|
||||
|
||||
if (!_checkMemory(script))
|
||||
return;
|
||||
|
||||
if (EnabledHooks.empty())
|
||||
EnabledHooks.resize(script->GetTotalAvailableHooks());
|
||||
|
||||
if (script->isAfterLoadScript())
|
||||
{
|
||||
ALScripts.push_back(script);
|
||||
ALScripts.emplace_back(script, std::move(enabledHooks));
|
||||
}
|
||||
else
|
||||
{
|
||||
script->checkValidity();
|
||||
|
||||
for (uint16 v : enabledHooks)
|
||||
EnabledHooks[v].emplace_back(script);
|
||||
|
||||
// We're dealing with a code-only script; just add it.
|
||||
ScriptPointerList[_scriptIdCounter++] = script;
|
||||
sScriptMgr->IncreaseScriptCount();
|
||||
@@ -742,9 +754,9 @@ public:
|
||||
|
||||
static void AddALScripts()
|
||||
{
|
||||
for(ScriptVectorIterator it = ALScripts.begin(); it != ALScripts.end(); ++it)
|
||||
for (ScriptVectorIterator it = ALScripts.begin(); it != ALScripts.end(); ++it)
|
||||
{
|
||||
TScript* const script = *it;
|
||||
TScript* const script = (*it).first;
|
||||
|
||||
script->checkValidity();
|
||||
|
||||
@@ -776,6 +788,14 @@ public:
|
||||
// If the script is already assigned -> delete it!
|
||||
if (oldScript)
|
||||
{
|
||||
for (auto& vIt : EnabledHooks)
|
||||
for (size_t i = 0; i < vIt.size(); ++i)
|
||||
if (vIt[i] == oldScript)
|
||||
{
|
||||
vIt.erase(vIt.begin() + i);
|
||||
break;
|
||||
}
|
||||
|
||||
delete oldScript;
|
||||
}
|
||||
|
||||
@@ -798,6 +818,9 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
for (uint16 v : (*it).second)
|
||||
EnabledHooks[v].emplace_back(script);
|
||||
|
||||
// We're dealing with a code-only script; just add it.
|
||||
ScriptPointerList[_scriptIdCounter++] = script;
|
||||
sScriptMgr->IncreaseScriptCount();
|
||||
@@ -842,7 +865,8 @@ private:
|
||||
|
||||
// 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> std::vector<std::pair<TScript*,std::vector<uint16>>> ScriptRegistry<TScript>::ALScripts;
|
||||
template<class TScript> std::vector<std::vector<TScript*>> ScriptRegistry<TScript>::EnabledHooks;
|
||||
template<class TScript> uint32 ScriptRegistry<TScript>::_scriptIdCounter = 0;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user