mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Fix bug in previous commit that caused temporary bindings to die early.
Instead of decrementing all their counters every time an event occurs, only the counters of the bindings being executed will be decremented. `_LuaTemporariesDied` is a small optimization to prevent unnecessary calls to `UpdateTemporaryBindings`. It will only be called when a temporary binding has run out of shots and needs to be cleaned up.
This commit is contained in:
25
HookMgr.cpp
25
HookMgr.cpp
@@ -51,8 +51,17 @@ using namespace HookMgr;
|
||||
const char* _LuaBindType = this->BINDMAP->groupName; \
|
||||
uint32 _LuaEvent = EVENT; \
|
||||
int _LuaStackTop = lua_gettop(L); \
|
||||
bool _LuaTemporariesDied = false; \
|
||||
for (size_t i = 0; i < this->BINDMAP->Bindings[_LuaEvent].size(); ++i) \
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[_LuaEvent][i].first)); \
|
||||
{ \
|
||||
if (this->BINDMAP->Bindings[_LuaEvent][i].isTemporary) \
|
||||
{ \
|
||||
this->BINDMAP->Bindings[_LuaEvent][i].remainingShots--; \
|
||||
if (this->BINDMAP->Bindings[_LuaEvent][i].remainingShots == 0) \
|
||||
_LuaTemporariesDied = true; \
|
||||
} \
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[_LuaEvent][i].functionReference)); \
|
||||
} \
|
||||
int _LuaFuncTop = lua_gettop(L); \
|
||||
int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \
|
||||
Eluna::Push(L, _LuaEvent);
|
||||
@@ -86,8 +95,17 @@ using namespace HookMgr;
|
||||
const char* _LuaBindType = _LuaBind->groupName; \
|
||||
uint32 _LuaEvent = EVENT; \
|
||||
int _LuaStackTop = lua_gettop(L); \
|
||||
bool _LuaTemporariesDied = false; \
|
||||
for (size_t i = 0; i < this->BINDMAP->Bindings[ENTRY][_LuaEvent].size(); ++i) \
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].first)); \
|
||||
{ \
|
||||
if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].isTemporary) \
|
||||
{ \
|
||||
this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots--; \
|
||||
if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots == 0) \
|
||||
_LuaTemporariesDied = true; \
|
||||
} \
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].functionReference)); \
|
||||
} \
|
||||
int _LuaFuncTop = lua_gettop(L); \
|
||||
int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \
|
||||
Eluna::Push(L, _LuaEvent);
|
||||
@@ -123,7 +141,8 @@ using namespace HookMgr;
|
||||
ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be between %i and %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop, _LuaStackTop + _LuaFuncCount * _LuaReturnValues); \
|
||||
} \
|
||||
lua_settop(L, _LuaStackTop); \
|
||||
_LuaBind->UpdateTemporaryBindings(); \
|
||||
if (_LuaTemporariesDied) \
|
||||
_LuaBind->UpdateTemporaryBindings(); \
|
||||
if (!this->event_level) \
|
||||
this->InvalidateObjects(); // Invalidate objects on outermost hook call
|
||||
|
||||
|
||||
Reference in New Issue
Block a user