]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/util-pre.qh
Remove more useless tooltips
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / util-pre.qh
1 #ifndef UTIL_PRE_H
2 #define UTIL_PRE_H
3
4 #ifndef NOCOMPAT
5     #define COMPAT_NO_MOD_IS_XONOTIC
6 #endif
7
8 #ifndef QCC_SUPPORT_ACCUMULATE
9     #ifdef GMQCC
10         #define QCC_SUPPORT_ACCUMULATE
11     #endif
12 #endif
13
14 #ifndef QCC_SUPPORT_NIL
15     #ifdef GMQCC
16         #define QCC_SUPPORT_NIL 1
17     #endif
18 #endif
19
20 #ifndef QCC_SUPPORT_INT
21     #define int float
22
23     #define stoi(s) stof(s)
24     #define stob(s) stof(s)
25     #define itos(i) ftos(i)
26 #else
27     #define stoi(s) ((int) stof(s))
28     #define stob(s) ((bool) stof(s))
29     #define itos(i) ftos(i)
30 #endif
31
32 #define FOREACH_ARRAY(arr, start, end, cond, body) do { \
33     for (int i = start; i < end; ++i) {                 \
34         const noref entity it = arr[i];                 \
35         if (cond) { body }                              \
36     }                                                   \
37 } while(0)
38
39 #define FOREACH_LIST(list, next, cond, body) do {               \
40     noref int i = 0;                                            \
41     for (entity it = list##_first; it; (it = it.next, ++i)) {   \
42         if (cond) { body }                                      \
43     }                                                           \
44 } while(0)
45
46 #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
47
48 #ifdef GMQCC
49     #define EVAL(...)           __VA_ARGS__
50
51     #define OVERLOAD_(F, ...)   F##_##__VA_COUNT__(__VA_ARGS__)
52     #define OVERLOAD(F, ...)    F##_##__VA_COUNT__(__VA_ARGS__)
53 #else
54     #define EMPTY()
55     #define DEFER(id) id EMPTY()
56
57     #define EVAL(...)  EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
58     #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
59     #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
60     #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
61     #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__)))
62     #define EVAL5(...) __VA_ARGS__
63
64     #define OVERLOAD___(F,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n
65     #define OVERLOAD__(F, ...)  OVERLOAD___(F,##__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
66     #define OVERLOAD_(...)      DEFER(OVERLOAD__(__VA_ARGS__))
67     #define OVERLOAD(F, ...)    OVERLOAD_(F,##__VA_ARGS__)(__VA_ARGS__)
68 #endif
69
70 #define LAMBDA(...) { __VA_ARGS__ ; }
71
72 #define MAP(f, ...) EVAL(OVERLOAD(MAP, f, __VA_ARGS__))
73 #define MAP_2(f, it) f(it)
74 #define MAP_3(f, it, ...) f(it)MAP_2(f, __VA_ARGS__)
75 #define MAP_4(f, it, ...) f(it)MAP_3(f, __VA_ARGS__)
76 #define MAP_5(f, it, ...) f(it)MAP_4(f, __VA_ARGS__)
77 #define MAP_6(f, it, ...) f(it)MAP_5(f, __VA_ARGS__)
78 #define MAP_7(f, it, ...) f(it)MAP_6(f, __VA_ARGS__)
79 #define MAP_8(f, it, ...) f(it)MAP_7(f, __VA_ARGS__)
80 #define MAP_9(f, it, ...) f(it)MAP_8(f, __VA_ARGS__)
81 #define MAP_10(f, it, ...) f(it)MAP_9(f, __VA_ARGS__)
82 #define MAP_11(f, it, ...) f(it)MAP_10(f, __VA_ARGS__)
83 #define MAP_12(f, it, ...) f(it)MAP_11(f, __VA_ARGS__)
84 #define MAP_13(f, it, ...) f(it)MAP_12(f, __VA_ARGS__)
85 #define MAP_14(f, it, ...) f(it)MAP_13(f, __VA_ARGS__)
86 #define MAP_15(f, it, ...) f(it)MAP_14(f, __VA_ARGS__)
87 #define MAP_16(f, it, ...) f(it)MAP_15(f, __VA_ARGS__)
88 #define MAP_17(f, it, ...) f(it)MAP_16(f, __VA_ARGS__)
89 #define MAP_18(f, it, ...) f(it)MAP_17(f, __VA_ARGS__)
90 #define MAP_19(f, it, ...) f(it)MAP_18(f, __VA_ARGS__)
91 #define MAP_20(f, it, ...) f(it)MAP_19(f, __VA_ARGS__)
92
93 #define IDENTITY(it) it
94
95 #define UNWORDS(...) MAP(IDENTITY, __VA_ARGS__)
96
97 #define APPLY(f, ...) f(__VA_ARGS__)
98
99 #ifdef SVQC
100     #define SV(f, ...) f(__VA_ARGS__)
101 #else
102     #define SV(f, ...)
103 #endif
104
105 #ifdef CSQC
106     #define CL(f, ...) f(__VA_ARGS__)
107 #else
108     #define CL(f, ...)
109 #endif
110
111 #define IF(cond, f, ...) cond(f, __VA_ARGS__)
112
113 #define GET(name) name##get
114 #define GETTER(type, name) type GET(name)() { return name; }
115
116 #define BIT(n) (1 << (n))
117 #ifndef BRANCHLESS_BITSET
118     #define BITSET(var, mask, flag) (flag ? (var) | (mask) : (var) &~ (mask))
119 #else
120     #define BITSET(var, mask, flag) ((var) ^ (-(flag) ^ (var)) & (mask))
121 #endif
122
123 #endif