]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Iter.qh: refactor
authorTimePath <andrew.hardaker1995@gmail.com>
Fri, 25 Mar 2016 07:12:25 +0000 (18:12 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Fri, 25 Mar 2016 07:24:44 +0000 (18:24 +1100)
qcsrc/lib/iter.qh
qcsrc/menu/command/menu_cmd.qc
qcsrc/menu/menu.qc
qcsrc/server/command/vote.qc

index eaac63f5eff415c8d7a5aec8fa815b70a3cbe433..fae834b49fa684b8f973ec9730c7047d0e6ae59b 100644 (file)
        } MACRO_END
 
 #if defined(CSQC)
+    entity(entity start, .string fld, string match) _findstring = #18;
        entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
+
+    entity(entity start, .entity fld, entity match) _findentity = #98;
        entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403;
+
+    entity(entity start, .float fld, float match) _findfloat = #98;
        entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
+
+       entity(entity start, .float fld, float match) _findflags = #449;
        entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
 #elif defined(SVQC)
+    entity(entity start, .string fld, string match) _findstring = #18;
        entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #402;
+
+    entity(entity start, .entity fld, entity match) _findentity = #98;
        entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #403;
+
+    entity(entity start, .float fld, float match) _findfloat = #98;
        entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #403;
+
+       entity(entity start, .float fld, float match) _findflags = #449;
        entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #450;
 #elif defined(MENUQC)
+    entity(entity start, .string fld, string match) _findstring = #24;
        entity(.string fld, string match, .entity tofield) _findchainstring_tofield = #26;
+
+    entity(entity start, .entity fld, entity match) _findentity = #25;
        entity(.entity fld, entity match, .entity tofield) _findchainentity_tofield = #27;
+
+    entity(entity start, .float fld, float match) _findfloat = #25;
        entity(.float fld, float match, .entity tofield) _findchainfloat_tofield = #27;
+
+       entity(entity start, .float fld, float match) _findflags = #87;
        entity(.float fld, float match, .entity tofield) _findchainflags_tofield = #88;
 #endif
 
 #define ORDERED(F) F##_UNORDERED
+#define _FOREACH_ENTITY_FIND_ORDERED(T, fld, match, cond, body) \
+    MACRO_BEGIN { \
+        int _i = 0; \
+        for (entity _it = NULL; (_it = _find##T(_it, fld, match)); ++_i) \
+        { \
+            const noref int i = _i; \
+            ITER_CONST noref entity it = _it; \
+            if (cond) LAMBDA(body) \
+        } \
+    } MACRO_END
+#define _FOREACH_ENTITY_FIND_UNORDERED(id, T, fld, match, cond, body) \
+       MACRO_BEGIN { \
+               if (_FOREACH_ENTITY_FIND_##T##_##id##mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_FIND_##T##_##id##mutex); \
+               _FOREACH_ENTITY_FIND_##T##_##id##mutex = __FUNC__; \
+               entity _foundchain_first = _findchain##T##_tofield(fld, match, _FOREACH_ENTITY_FIND_##T##_next##id); \
+               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_FIND_##T##_next##id, cond, body); \
+               _FOREACH_ENTITY_FIND_##T##_##id##mutex = string_null; \
+       } MACRO_END
 
 #define FOREACH_ENTITY(cond, body) ORDERED(FOREACH_ENTITY)(cond, body)
 #define FOREACH_ENTITY_ORDERED(cond, body) \
                { \
                        const noref int i = _i; \
                        ITER_CONST noref entity it = _it; \
-                       if (cond) { LAMBDA(body) } \
+                       if (cond) LAMBDA(body) \
                } \
        } MACRO_END
 /** marker field, always NULL */
 .entity _FOREACH_ENTITY_fld;
+.entity _FOREACH_ENTITY_FIND_entity_nextall; noref string _FOREACH_ENTITY_FIND_entity_allmutex;
+#define FOREACH_ENTITY_UNORDERED(cond, body) _FOREACH_ENTITY_FIND_UNORDERED(all, entity, _FOREACH_ENTITY_fld, NULL, cond, body)
 
-.entity _FOREACH_ENTITY_next;
-noref string _FOREACH_ENTITY_mutex;
-#define FOREACH_ENTITY_UNORDERED(cond, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_mutex); \
-               _FOREACH_ENTITY_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainentity_tofield(_FOREACH_ENTITY_fld, NULL, _FOREACH_ENTITY_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_next, cond, body); \
-               _FOREACH_ENTITY_mutex = string_null; \
-       } MACRO_END
-
+#define FOREACH_ENTITY_FLAGS(fld, match, body) ORDERED(FOREACH_ENTITY_FLAGS)(fld, match, body)
+#define FOREACH_ENTITY_FLAGS_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(flags, fld, match, true, body)
+.entity _FOREACH_ENTITY_FIND_flags_next; noref string _FOREACH_ENTITY_FIND_flags_mutex;
+#define FOREACH_ENTITY_FLAGS_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, flags, fld, match, true, body)
 
 #ifndef MENUQC
-entity(vector org, float rad, .entity tofield) _findradius_tofield = #22;
+entity(vector org, float rad, .entity tofield) _findchainradius_tofield = #22;
 #define FOREACH_ENTITY_RADIUS(org, dist, cond, body) FOREACH_ENTITY_RADIUS_UNORDERED(org, dist, cond, body)
-.entity _FOREACH_ENTITY_RADIUS_next;
-noref string _FOREACH_ENTITY_RADIUS_mutex;
-#define FOREACH_ENTITY_RADIUS_UNORDERED(org, dist, cond, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_RADIUS_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_RADIUS_mutex); \
-               _FOREACH_ENTITY_RADIUS_mutex = __FUNC__; \
-               entity _foundchain_first = _findradius_tofield(org, dist, _FOREACH_ENTITY_RADIUS_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_RADIUS_next, cond, body); \
-               _FOREACH_ENTITY_RADIUS_mutex = string_null; \
-       } MACRO_END
+.entity _FOREACH_ENTITY_FIND_radius_next; noref string _FOREACH_ENTITY_FIND_radius_mutex;
+#define FOREACH_ENTITY_RADIUS_UNORDERED(org, dist, cond, body) _FOREACH_ENTITY_FIND_UNORDERED(, radius, org, dist, cond, body)
 #endif
 
-
-#define FOREACH_ENTITY_CLASS(class, cond, body) ORDERED(FOREACH_ENTITY_CLASS)(class, cond, body)
-#define FOREACH_ENTITY_CLASS_ORDERED(class, cond, body) FOREACH_ENTITY_ORDERED(it.classname == class && (cond), body)
-.entity _FOREACH_ENTITY_CLASS_next;
-noref string _FOREACH_ENTITY_CLASS_mutex;
-#define FOREACH_ENTITY_CLASS_UNORDERED(class, cond, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_CLASS_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_CLASS_mutex); \
-               _FOREACH_ENTITY_CLASS_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainstring_tofield(classname, class, _FOREACH_ENTITY_CLASS_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_CLASS_next, cond, body); \
-               _FOREACH_ENTITY_CLASS_mutex = string_null; \
-       } MACRO_END
-
-
-
 #define FOREACH_ENTITY_FLOAT(fld, match, body) ORDERED(FOREACH_ENTITY_FLOAT)(fld, match, body)
-#define FOREACH_ENTITY_FLOAT_ORDERED(fld, match, body) FOREACH_ENTITY_ORDERED(it.fld == match, body)
-.entity _FOREACH_ENTITY_FLOAT_next;
-noref string _FOREACH_ENTITY_FLOAT_mutex;
-#define FOREACH_ENTITY_FLOAT_UNORDERED(fld, match, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_FLOAT_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_FLOAT_mutex); \
-               _FOREACH_ENTITY_FLOAT_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainfloat_tofield(fld, match, _FOREACH_ENTITY_FLOAT_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_FLOAT_next, true, body); \
-               _FOREACH_ENTITY_FLOAT_mutex = string_null; \
-       } MACRO_END
-
-
-
-#define FOREACH_ENTITY_FLAGS(fld, match, body) ORDERED(FOREACH_ENTITY_FLAGS)(fld, match, body)
-#define FOREACH_ENTITY_FLAGS_ORDERED(fld, match, body) FOREACH_ENTITY_ORDERED(it.fld & match, body)
-.entity _FOREACH_ENTITY_FLAGS_next;
-noref string _FOREACH_ENTITY_FLAGS_mutex;
-#define FOREACH_ENTITY_FLAGS_UNORDERED(fld, match, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_FLAGS_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_FLAGS_mutex); \
-               _FOREACH_ENTITY_FLAGS_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainflags_tofield(fld, match, _FOREACH_ENTITY_FLAGS_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_FLAGS_next, true, body); \
-               _FOREACH_ENTITY_FLAGS_mutex = string_null; \
-       } MACRO_END
-
-
+#define FOREACH_ENTITY_FLOAT_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(float, fld, match, true, body)
+.entity _FOREACH_ENTITY_FIND_float_next; noref string _FOREACH_ENTITY_FIND_float_mutex;
+#define FOREACH_ENTITY_FLOAT_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, float, fld, match, true, body)
 
 #define FOREACH_ENTITY_ENT(fld, match, body) ORDERED(FOREACH_ENTITY_ENT)(fld, match, body)
-#define FOREACH_ENTITY_ENT_ORDERED(fld, match, body) FOREACH_ENTITY_ORDERED(it.fld == match, body)
-.entity _FOREACH_ENTITY_ENT_next;
-noref string _FOREACH_ENTITY_ENT_mutex;
-#define FOREACH_ENTITY_ENT_UNORDERED(fld, match, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_ENT_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_ENT_mutex); \
-               _FOREACH_ENTITY_ENT_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainentity_tofield(fld, match, _FOREACH_ENTITY_ENT_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_ENT_next, true, body); \
-               _FOREACH_ENTITY_ENT_mutex = string_null; \
-       } MACRO_END
-
-
+#define FOREACH_ENTITY_ENT_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(entity, fld, match, true, body)
+.entity _FOREACH_ENTITY_FIND_entity_next; noref string _FOREACH_ENTITY_FIND_entity_mutex;
+#define FOREACH_ENTITY_ENT_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, entity, fld, match, true, body)
 
 #define FOREACH_ENTITY_STRING(fld, match, body) ORDERED(FOREACH_ENTITY_STRING)(fld, match, body)
-#define FOREACH_ENTITY_STRING_ORDERED(fld, match, body) FOREACH_ENTITY_ORDERED(it.fld == match, body)
-.entity _FOREACH_ENTITY_STRING_next;
-noref string _FOREACH_ENTITY_STRING_mutex;
-#define FOREACH_ENTITY_STRING_UNORDERED(fld, match, body) \
-       MACRO_BEGIN { \
-               if (_FOREACH_ENTITY_STRING_mutex) LOG_SEVEREF("Loop mutex held by %s", _FOREACH_ENTITY_STRING_mutex); \
-               _FOREACH_ENTITY_STRING_mutex = __FUNC__; \
-               entity _foundchain_first = _findchainstring_tofield(fld, match, _FOREACH_ENTITY_STRING_next); \
-               FOREACH_LIST(_foundchain, _FOREACH_ENTITY_STRING_next, true, body); \
-               _FOREACH_ENTITY_STRING_mutex = string_null; \
-       } MACRO_END
+#define FOREACH_ENTITY_STRING_ORDERED(fld, match, body) _FOREACH_ENTITY_FIND_ORDERED(string, fld, match, true, body)
+.entity _FOREACH_ENTITY_FIND_string_next; noref string _FOREACH_ENTITY_FIND_string_mutex;
+#define FOREACH_ENTITY_STRING_UNORDERED(fld, match, body) _FOREACH_ENTITY_FIND_UNORDERED(, string, fld, match, true, body)
+
+#define FOREACH_ENTITY_CLASS(class, cond, body) ORDERED(FOREACH_ENTITY_CLASS)(class, cond, body)
+#define FOREACH_ENTITY_CLASS_ORDERED(class, cond, body) _FOREACH_ENTITY_FIND_ORDERED(string, classname, class, cond, body)
+.entity _FOREACH_ENTITY_FIND_string_nextclazz; noref string _FOREACH_ENTITY_FIND_string_clazzmutex;
+#define FOREACH_ENTITY_CLASS_UNORDERED(class, cond, body) _FOREACH_ENTITY_FIND_UNORDERED(clazz, string, classname, class, cond, body)
index 6b944c90e419c1acf66357bbee5f009e1610986a..0f87cbb0959cb38df039f1cac70f796cabd0185b 100644 (file)
@@ -78,7 +78,7 @@ void GameCommand(string theCommand)
                {
                        LOG_INFO(_("Available options:\n"));
 
-                       FOREACH_ENTITY_ORDERED(it.name != "", LAMBDA(
+                       FOREACH_ENTITY_ORDERED(it.name != "", {
                                if (it.classname == "vtbl") continue;
                                string s = it.name;
                                if (filter)
@@ -87,7 +87,7 @@ void GameCommand(string theCommand)
                                        s = substring(s, strlen(filter), strlen(s) - strlen(filter));
                                }
                                LOG_INFOF(" %s\n", s);
-                       ));
+                       });
                }
                else if (argc == 2 && !isdemo())     // don't allow this command in demos
                {
index b75a48ab7e0e37dcfbbec35098004757def43e78..913cdbe34b43f6bb068c7e8748e301da57386397 100644 (file)
@@ -878,10 +878,10 @@ void m_toggle(int mode)
 void Shutdown()
 {
        m_hide();
-       FOREACH_ENTITY_ORDERED(it.destroy, LAMBDA(
+       FOREACH_ENTITY_ORDERED(it.destroy, {
                if (it.classname == "vtbl") continue;
                it.destroy(it);
-       ));
+       });
 }
 
 void m_focus_item_chain(entity outermost, entity innermost)
index 4cf5b7dc5145199bb8512a00d511d7b02d989f77..afc0fe4601e8f63d39d392ddcfddf49a7a45b4a2 100644 (file)
@@ -341,7 +341,7 @@ void reset_map(bool dorespawn)
 
        MUTATOR_CALLHOOK(reset_map_global);
 
-       FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), LAMBDA(
+       FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), {
                if (it.reset)
                {
                        WITH(entity, self, it, it.reset(it));
@@ -349,12 +349,12 @@ void reset_map(bool dorespawn)
                }
                if (it.team_saved) it.team = it.team_saved;
                if (it.flags & FL_PROJECTILE) remove(it);  // remove any projectiles left
-       ));
+       });
 
        // Waypoints and assault start come LAST
-       FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), LAMBDA(
+       FOREACH_ENTITY_ORDERED(IS_NOT_A_CLIENT(it), {
                if (it.reset2) WITH(entity, self, it, it.reset2());
-       ));
+       });
 
        FOREACH_CLIENT(IS_PLAYER(it) && STAT(FROZEN, it), LAMBDA(WITH(entity, self, it, Unfreeze(it))));