mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna
This commit is contained in:
270
LuaEngine.h
270
LuaEngine.h
@@ -336,140 +336,9 @@ struct EventMgr
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct EventBind
|
||||
{
|
||||
typedef std::vector<int> ElunaBindingMap;
|
||||
typedef std::map<int, ElunaBindingMap> ElunaEntryMap;
|
||||
|
||||
Eluna& E;
|
||||
|
||||
EventBind(Eluna& _E): E(_E)
|
||||
{
|
||||
}
|
||||
|
||||
~EventBind()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
// unregisters all registered functions and clears all registered events from the bind std::maps (reset)
|
||||
void Clear()
|
||||
{
|
||||
for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (ElunaBindingMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, (*it));
|
||||
itr->second.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
|
||||
void Insert(int eventId, int funcRef) // Inserts a new registered event
|
||||
{
|
||||
Bindings[eventId].push_back(funcRef);
|
||||
}
|
||||
|
||||
// Gets the binding std::map containing all registered events with the function refs for the entry
|
||||
ElunaBindingMap* GetBindMap(T eventId)
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return NULL;
|
||||
ElunaEntryMap::iterator itr = Bindings.find(eventId);
|
||||
if (itr == Bindings.end())
|
||||
return NULL;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
// Checks if there are events for ID
|
||||
bool HasEvents(T eventId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return false;
|
||||
if (Bindings.find(eventId) == Bindings.end())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
ElunaEntryMap Bindings; // Binding store Bindings[eventId] = {funcRef};
|
||||
};
|
||||
|
||||
struct EventBind;
|
||||
template<typename T>
|
||||
struct EntryBind
|
||||
{
|
||||
typedef std::map<int, int> ElunaBindingMap;
|
||||
typedef UNORDERED_MAP<uint32, ElunaBindingMap> ElunaEntryMap;
|
||||
|
||||
Eluna& E;
|
||||
|
||||
EntryBind(Eluna& _E): E(_E)
|
||||
{
|
||||
}
|
||||
|
||||
~EntryBind()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear() // unregisters all registered functions and clears all registered events from the bind std::maps (reset)
|
||||
{
|
||||
for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (ElunaBindingMap::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, it->second);
|
||||
itr->second.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
|
||||
void Insert(uint32 entryId, int eventId, int funcRef) // Inserts a new registered event
|
||||
{
|
||||
if (Bindings[entryId][eventId])
|
||||
{
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, funcRef); // free the unused ref
|
||||
luaL_error(E.L, "A function is already registered for entry (%d) event (%d)", entryId, eventId);
|
||||
}
|
||||
else
|
||||
Bindings[entryId][eventId] = funcRef;
|
||||
}
|
||||
|
||||
// Gets the function ref of an entry for an event
|
||||
int GetBind(uint32 entryId, T eventId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return 0;
|
||||
ElunaEntryMap::const_iterator itr = Bindings.find(entryId);
|
||||
if (itr == Bindings.end() || itr->second.empty())
|
||||
return 0;
|
||||
ElunaBindingMap::const_iterator itr2 = itr->second.find(eventId);
|
||||
if (itr2 == itr->second.end())
|
||||
return 0;
|
||||
return itr2->second;
|
||||
}
|
||||
|
||||
// Gets the binding std::map containing all registered events with the function refs for the entry
|
||||
const ElunaBindingMap* GetBindMap(uint32 entryId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return NULL;
|
||||
ElunaEntryMap::const_iterator itr = Bindings.find(entryId);
|
||||
if (itr == Bindings.end())
|
||||
return NULL;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
// Returns true if the entry has registered binds
|
||||
bool HasBinds(uint32 entryId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return false;
|
||||
return Bindings.find(entryId) != Bindings.end();
|
||||
}
|
||||
|
||||
ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef;
|
||||
};
|
||||
|
||||
struct EntryBind;
|
||||
template<typename T>
|
||||
class ElunaTemplate;
|
||||
|
||||
@@ -814,6 +683,141 @@ template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error);
|
||||
|
||||
// #define ELUNA_GUARD() ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock);
|
||||
|
||||
template<typename T>
|
||||
struct EventBind
|
||||
{
|
||||
typedef std::vector<int> ElunaBindingMap;
|
||||
typedef std::map<int, ElunaBindingMap> ElunaEntryMap;
|
||||
|
||||
Eluna& E;
|
||||
|
||||
EventBind(Eluna& _E): E(_E)
|
||||
{
|
||||
}
|
||||
|
||||
~EventBind()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
// unregisters all registered functions and clears all registered events from the bind std::maps (reset)
|
||||
void Clear()
|
||||
{
|
||||
for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (ElunaBindingMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, (*it));
|
||||
itr->second.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
|
||||
void Insert(int eventId, int funcRef) // Inserts a new registered event
|
||||
{
|
||||
Bindings[eventId].push_back(funcRef);
|
||||
}
|
||||
|
||||
// Gets the binding std::map containing all registered events with the function refs for the entry
|
||||
ElunaBindingMap* GetBindMap(T eventId)
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return NULL;
|
||||
ElunaEntryMap::iterator itr = Bindings.find(eventId);
|
||||
if (itr == Bindings.end())
|
||||
return NULL;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
// Checks if there are events for ID
|
||||
bool HasEvents(T eventId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return false;
|
||||
if (Bindings.find(eventId) == Bindings.end())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
ElunaEntryMap Bindings; // Binding store Bindings[eventId] = {funcRef};
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct EntryBind
|
||||
{
|
||||
typedef std::map<int, int> ElunaBindingMap;
|
||||
typedef UNORDERED_MAP<uint32, ElunaBindingMap> ElunaEntryMap;
|
||||
|
||||
Eluna& E;
|
||||
|
||||
EntryBind(Eluna& _E): E(_E)
|
||||
{
|
||||
}
|
||||
|
||||
~EntryBind()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear() // unregisters all registered functions and clears all registered events from the bind std::maps (reset)
|
||||
{
|
||||
for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr)
|
||||
{
|
||||
for (ElunaBindingMap::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, it->second);
|
||||
itr->second.clear();
|
||||
}
|
||||
Bindings.clear();
|
||||
}
|
||||
|
||||
void Insert(uint32 entryId, int eventId, int funcRef) // Inserts a new registered event
|
||||
{
|
||||
if (Bindings[entryId][eventId])
|
||||
{
|
||||
luaL_unref(E.L, LUA_REGISTRYINDEX, funcRef); // free the unused ref
|
||||
luaL_error(E.L, "A function is already registered for entry (%d) event (%d)", entryId, eventId);
|
||||
}
|
||||
else
|
||||
Bindings[entryId][eventId] = funcRef;
|
||||
}
|
||||
|
||||
// Gets the function ref of an entry for an event
|
||||
int GetBind(uint32 entryId, T eventId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return 0;
|
||||
ElunaEntryMap::const_iterator itr = Bindings.find(entryId);
|
||||
if (itr == Bindings.end() || itr->second.empty())
|
||||
return 0;
|
||||
ElunaBindingMap::const_iterator itr2 = itr->second.find(eventId);
|
||||
if (itr2 == itr->second.end())
|
||||
return 0;
|
||||
return itr2->second;
|
||||
}
|
||||
|
||||
// Gets the binding std::map containing all registered events with the function refs for the entry
|
||||
const ElunaBindingMap* GetBindMap(uint32 entryId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return NULL;
|
||||
ElunaEntryMap::const_iterator itr = Bindings.find(entryId);
|
||||
if (itr == Bindings.end())
|
||||
return NULL;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
|
||||
// Returns true if the entry has registered binds
|
||||
bool HasBinds(uint32 entryId) const
|
||||
{
|
||||
if (Bindings.empty())
|
||||
return false;
|
||||
return Bindings.find(entryId) != Bindings.end();
|
||||
}
|
||||
|
||||
ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class ElunaTemplate
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user