]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/util-pre.qh
Cleanup OO macros
[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
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 #ifndef QCC_SUPPORT_BOOL
33     #define bool float
34
35     // Boolean Constants
36     const int true      = 1;
37     const int false = 0;
38 #endif
39
40 // Transitional aliases
41 [[deprecated("use true")]] [[alias("true")]] const bool TRUE;
42 [[deprecated("use false")]] [[alias("false")]] const bool FALSE;
43
44 #ifdef GMQCC
45     #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
46 #else
47     #define OVERLOAD_(F,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n
48     #define OVERLOAD(F, ...) OVERLOAD_(F,__VA_ARGS__,9,8,7,6,5,4,3,2,1)(__VA_ARGS__)
49 #endif
50
51 #define LAMBDA(...) { __VA_ARGS__ ; }
52
53 #define MAP(f, ...) OVERLOAD(MAP, f, __VA_ARGS__)
54 #define MAP_2(f, it) f(it)
55 #define MAP_3(f, it, ...) f(it)MAP_2(f, __VA_ARGS__)
56 #define MAP_4(f, it, ...) f(it)MAP_3(f, __VA_ARGS__)
57 #define MAP_5(f, it, ...) f(it)MAP_4(f, __VA_ARGS__)
58 #define MAP_6(f, it, ...) f(it)MAP_5(f, __VA_ARGS__)
59 #define MAP_7(f, it, ...) f(it)MAP_6(f, __VA_ARGS__)
60 #define MAP_8(f, it, ...) f(it)MAP_7(f, __VA_ARGS__)
61 #define MAP_9(f, it, ...) f(it)MAP_8(f, __VA_ARGS__)
62 #define MAP_10(f, it, ...) f(it)MAP_9(f, __VA_ARGS__)
63 #define MAP_11(f, it, ...) f(it)MAP_10(f, __VA_ARGS__)
64 #define MAP_12(f, it, ...) f(it)MAP_11(f, __VA_ARGS__)
65 #define MAP_13(f, it, ...) f(it)MAP_12(f, __VA_ARGS__)
66 #define MAP_14(f, it, ...) f(it)MAP_13(f, __VA_ARGS__)
67 #define MAP_15(f, it, ...) f(it)MAP_14(f, __VA_ARGS__)
68 #define MAP_16(f, it, ...) f(it)MAP_15(f, __VA_ARGS__)
69 #define MAP_17(f, it, ...) f(it)MAP_16(f, __VA_ARGS__)
70 #define MAP_18(f, it, ...) f(it)MAP_17(f, __VA_ARGS__)
71 #define MAP_19(f, it, ...) f(it)MAP_18(f, __VA_ARGS__)
72 #define MAP_20(f, it, ...) f(it)MAP_19(f, __VA_ARGS__)
73
74 #define IDENTITY(it) it
75
76 #define UNWORDS(...) MAP(IDENTITY, __VA_ARGS__)
77
78 #define APPLY(f, ...) f(__VA_ARGS__)
79
80 #ifdef SVQC
81     #define SV(f, ...) f(__VA_ARGS__)
82 #else
83     #define SV(f, ...)
84 #endif
85
86 #ifdef CSQC
87     #define CL(f, ...) f(__VA_ARGS__)
88 #else
89     #define CL(f, ...)
90 #endif
91
92 #define IF(cond, f, ...) cond(f, __VA_ARGS__)
93
94 #define GET(name) name##get
95 #define GETTER(type, name) type GET(name)() { return name; }
96
97 #define BIT(n) (1 << (n))
98 #ifndef BRANCHLESS_BITSET
99     #define BITSET(var, mask, flag) (flag ? (var) | (mask) : (var) &~ (mask))
100 #else
101     #define BITSET(var, mask, flag) ((var) ^ (-(flag) ^ (var)) & (mask))
102 #endif
103
104 #endif