]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/util-pre.qh
Merge branch 'terencehill/menu_weaponarena_selection_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util-pre.qh
index fbc43bdc5c8fb34c58391d9b0b7fba4eebf1bd20..b81fd2a6df81d409626458a4ba338a15273796f2 100644 (file)
     #define itos(i) ftos(i)
 #endif
 
-#ifndef QCC_SUPPORT_BOOL
-    #define bool float
+#define FOREACH_ARRAY(arr, start, end, cond, body) do { \
+    for (int i = start; i < end; ++i) {                 \
+        const noref entity it = arr[i];                 \
+        if (cond) { body }                              \
+    }                                                   \
+} while(0)
 
-    // Boolean Constants
-    const int true     = 1;
-    const int false = 0;
-#endif
-
-#ifndef QCC_SUPPORT_ENTITYCLASS
-    #define entityclass(name) typedef entity name
-    #define class(name)
-    #define new(class) spawn()
-#else
-    #define entityclass(name) entityclass name {}
-    #define class(name) [[class(name)]]
-    #define new(class) ((class) spawn())
-#endif
+#define FOREACH_LIST(list, next, cond, body) do {               \
+    noref int i = 0;                                            \
+    for (entity it = list##_first; it; (it = it.next, ++i)) {   \
+        if (cond) { body }                                      \
+    }                                                           \
+} while(0)
 
-// Transitional aliases
-[[deprecated("use true")]] [[alias("true")]] const bool TRUE;
-[[deprecated("use false")]] [[alias("false")]] const bool FALSE;
+#define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
 
 #ifdef GMQCC
     #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
@@ -58,6 +52,8 @@
     #define OVERLOAD(F, ...) OVERLOAD_(F,__VA_ARGS__,9,8,7,6,5,4,3,2,1)(__VA_ARGS__)
 #endif
 
+#define LAMBDA(...) { __VA_ARGS__ ; }
+
 #define MAP(f, ...) OVERLOAD(MAP, f, __VA_ARGS__)
 #define MAP_2(f, it) f(it)
 #define MAP_3(f, it, ...) f(it)MAP_2(f, __VA_ARGS__)
 #define MAP_19(f, it, ...) f(it)MAP_18(f, __VA_ARGS__)
 #define MAP_20(f, it, ...) f(it)MAP_19(f, __VA_ARGS__)
 
+#define IDENTITY(it) it
+
+#define UNWORDS(...) MAP(IDENTITY, __VA_ARGS__)
+
+#define APPLY(f, ...) f(__VA_ARGS__)
+
+#ifdef SVQC
+    #define SV(f, ...) f(__VA_ARGS__)
+#else
+    #define SV(f, ...)
+#endif
+
+#ifdef CSQC
+    #define CL(f, ...) f(__VA_ARGS__)
+#else
+    #define CL(f, ...)
+#endif
+
+#define IF(cond, f, ...) cond(f, __VA_ARGS__)
+
+#define GET(name) name##get
+#define GETTER(type, name) type GET(name)() { return name; }
+
 #define BIT(n) (1 << (n))
 #ifndef BRANCHLESS_BITSET
     #define BITSET(var, mask, flag) (flag ? (var) | (mask) : (var) &~ (mask))