]> git.lizzy.rs Git - minetest.git/blobdiff - src/event_manager.h
Fix item and wield meshes (#6596)
[minetest.git] / src / event_manager.h
index 33d99b28cc3757ed9c989248c097daa878e73e58..f64d05869ab80dfabb93e0cc0e3888abc86a3668 100644 (file)
@@ -17,8 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef EVENT_MANAGER_HEADER
-#define EVENT_MANAGER_HEADER
+#pragma once
 
 #include "event.h"
 #include <list>
@@ -44,17 +43,15 @@ class EventManager: public MtEventManager
        std::map<std::string, Dest> m_dest;
 
 public:
-       ~EventManager()
-       {
-       }
+       ~EventManager() = default;
+
        void put(MtEvent *e)
        {
                std::map<std::string, Dest>::iterator i = m_dest.find(e->getType());
                if(i != m_dest.end()){
                        std::list<FuncSpec> &funcs = i->second.funcs;
-                       for(std::list<FuncSpec>::iterator i = funcs.begin();
-                                       i != funcs.end(); i++){
-                               (*(i->f))(e, i->d);
+                       for (FuncSpec &func : funcs) {
+                               (*(func.f))(e, func.d);
                        }
                }
                delete e;
@@ -63,11 +60,11 @@ class EventManager: public MtEventManager
        {
                std::map<std::string, Dest>::iterator i = m_dest.find(type);
                if(i != m_dest.end()){
-                       i->second.funcs.push_back(FuncSpec(f, data));
+                       i->second.funcs.emplace_back(f, data);
                } else{
                        std::list<FuncSpec> funcs;
                        Dest dest;
-                       dest.funcs.push_back(FuncSpec(f, data));
+                       dest.funcs.emplace_back(f, data);
                        m_dest[type] = dest;
                }
        }
@@ -83,20 +80,19 @@ class EventManager: public MtEventManager
                                        if(remove)
                                                funcs.erase(j++);
                                        else
-                                               j++;
+                                               ++j;
                                }
                        }
                } else{
-                       for(std::map<std::string, Dest>::iterator
-                                       i = m_dest.begin(); i != m_dest.end(); i++){
-                               std::list<FuncSpec> &funcs = i->second.funcs;
+                       for (auto &dest : m_dest) {
+                               std::list<FuncSpec> &funcs = dest.second.funcs;
                                std::list<FuncSpec>::iterator j = funcs.begin();
                                while(j != funcs.end()){
                                        bool remove = (j->f == f && (!data || j->d == data));
                                        if(remove)
                                                funcs.erase(j++);
                                        else
-                                               j++;
+                                               ++j;
                                }
                        }
                }
@@ -110,6 +106,3 @@ class EventManager: public MtEventManager
                dereg(type, EventManager::receiverReceive, r);
        }
 };
-
-#endif
-