From a7e87c5de03adae017a4e7dd5f07fb90f4ca3b2c Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Wed, 4 Jun 2014 22:08:01 +0300 Subject: [PATCH] Eluna --- LuaEngine.h | 270 ++++++++++++++++++++++++++-------------------------- 1 file changed, 137 insertions(+), 133 deletions(-) diff --git a/LuaEngine.h b/LuaEngine.h index 92f547f..e63c20d 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -336,140 +336,9 @@ struct EventMgr }; template -struct EventBind -{ - typedef std::vector ElunaBindingMap; - typedef std::map 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 -struct EntryBind -{ - typedef std::map ElunaBindingMap; - typedef UNORDERED_MAP 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 class ElunaTemplate; @@ -814,6 +683,141 @@ template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); // #define ELUNA_GUARD() ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); +template +struct EventBind +{ + typedef std::vector ElunaBindingMap; + typedef std::map 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 +struct EntryBind +{ + typedef std::map ElunaBindingMap; + typedef UNORDERED_MAP 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 class ElunaTemplate {