X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Futil-pre.qh;h=dfb407160c339f91f851f13b4c73343d42257b16;hb=7029c1b56f76ec1efa593c4509dffee0c393a2a9;hp=9d60ae0a9ae2797bfdaedea9632237e81554f564;hpb=125d619e9ab2a307b15b7ee1a2ededed32c7e84d;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/util-pre.qh b/qcsrc/common/util-pre.qh index 9d60ae0a9..dfb407160 100644 --- a/qcsrc/common/util-pre.qh +++ b/qcsrc/common/util-pre.qh @@ -13,7 +13,7 @@ #ifndef QCC_SUPPORT_NIL #ifdef GMQCC - #define QCC_SUPPORT_NIL + #define QCC_SUPPORT_NIL 1 #endif #endif @@ -29,38 +29,47 @@ #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__) + #define EVAL(...) __VA_ARGS__ + + #define OVERLOAD_(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) + #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__) #else - #define OVERLOAD_(F,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n - #define OVERLOAD(F, ...) OVERLOAD_(F,__VA_ARGS__,9,8,7,6,5,4,3,2,1)(__VA_ARGS__) + #define EMPTY() + #define DEFER(id) id EMPTY() + + #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__))) + #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__))) + #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__))) + #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__))) + #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__))) + #define EVAL5(...) __VA_ARGS__ + + #define OVERLOAD___(F,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n + #define OVERLOAD__(F, ...) OVERLOAD___(F,##__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) + #define OVERLOAD_(...) DEFER(OVERLOAD__(__VA_ARGS__)) + #define OVERLOAD(F, ...) OVERLOAD_(F,##__VA_ARGS__)(__VA_ARGS__) #endif #define LAMBDA(...) { __VA_ARGS__ ; } -#define MAP(f, ...) OVERLOAD(MAP, f, __VA_ARGS__) +#define MAP(f, ...) EVAL(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_4(f, it, ...) f(it)MAP_3(f, __VA_ARGS__) @@ -104,11 +113,4 @@ #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)) -#else - #define BITSET(var, mask, flag) ((var) ^ (-(flag) ^ (var)) & (mask)) -#endif - #endif