X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fiter.qh;h=4eae6d5d393ccc6e9e33453a33b0658c1a557c80;hb=f785b8a76c2336cb00e78fe9e738d55512a086f5;hp=7183e90feab6bad7a26ce4ba98f8e01886ea8bca;hpb=9185b58da6fe5f2b095d7066577e1e024b4d2798;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/iter.qh b/qcsrc/lib/iter.qh index 7183e90fe..4eae6d5d3 100644 --- a/qcsrc/lib/iter.qh +++ b/qcsrc/lib/iter.qh @@ -8,20 +8,18 @@ #define FOREACH_ARRAY(arr, start, end, cond, body) \ MACRO_BEGIN \ - { \ for (int _i = start; _i < end; ++_i) \ { \ const noref int i = _i; \ ITER_CONST noref entity it = arr[i]; \ if (cond) { LAMBDA(body) } \ } \ - } MACRO_END + MACRO_END #define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body) #define FOREACH_LIST(list, next, cond, body) \ MACRO_BEGIN \ - { \ int _i = 0; \ for (entity _it = list##_first, _next = NULL; _it; (_it = _next, ++_i)) \ { \ @@ -30,11 +28,10 @@ _next = _it.next; \ if (cond) { LAMBDA(body) } \ } \ - } MACRO_END + MACRO_END #define FOREACH_WORD(words, cond, body) \ MACRO_BEGIN \ - { \ string _words = words; \ int _i = 0; \ for (string _it; (_it = car(_words)); (_words = cdr(_words), ++_i)) \ @@ -43,17 +40,17 @@ const noref string it = _it; \ if (cond) { LAMBDA(body) } \ } \ - } MACRO_END + MACRO_END #define STRING_ITERATOR(this, s, i) \ string this##_s = s; \ int this##_i = i #define STRING_ITERATOR_SET(this, s, i) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ this##_s = s; \ this##_i = i; \ - } MACRO_END + MACRO_END #define STRING_ITERATOR_GET(this) str2chr(this##_s, this##_i++) #define STRING_ITERATOR_PEEK(this) str2chr(this##_s, this##_i) @@ -64,7 +61,6 @@ #define FOREACH_CHAR(s, cond, body) \ MACRO_BEGIN \ - { \ STRING_ITERATOR(iter, s, 0); \ int _it; \ while ((_it = STRING_ITERATOR_GET(iter)) > 0) \ @@ -72,7 +68,7 @@ const noref int it = _it; \ if (cond) { LAMBDA(body) } \ } \ - } MACRO_END + MACRO_END #if defined(CSQC) entity(entity start, .string fld, string match) _findstring = #18; @@ -114,7 +110,7 @@ #define ORDERED(F) F##_UNORDERED #define _FOREACH_ENTITY_FIND_ORDERED(T, fld, match, cond, body) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ int _i = 0; \ for (entity _it = NULL; (_it = _find##T(_it, fld, match)); ++_i) \ { \ @@ -122,7 +118,7 @@ ITER_CONST noref entity it = _it; \ if (cond) LAMBDA(body) \ } \ - } MACRO_END + MACRO_END #define MUTEX_LOCK(this) MACRO_BEGIN \ if (this) LOG_SEVEREF("Loop mutex held by %s", this); \ this = __FUNC__; \ @@ -131,16 +127,16 @@ MACRO_END this = string_null; \ MACRO_END #define _FOREACH_ENTITY_FIND_UNORDERED(id, T, fld, match, cond, body) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ MUTEX_LOCK(_FOREACH_ENTITY_FIND_##T##_##id##mutex); \ 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); \ MUTEX_UNLOCK(_FOREACH_ENTITY_FIND_##T##_##id##mutex); \ - } MACRO_END + MACRO_END #define FOREACH_ENTITY(cond, body) ORDERED(FOREACH_ENTITY)(cond, body) #define FOREACH_ENTITY_ORDERED(cond, body) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ int _i = 0; \ for (entity _it = NULL; (_it = nextent(_it)); ++_i) \ { \ @@ -148,7 +144,7 @@ MACRO_END ITER_CONST noref entity it = _it; \ if (cond) LAMBDA(body) \ } \ - } MACRO_END + MACRO_END /** marker field, always NULL */ .entity _FOREACH_ENTITY_fld; .entity _FOREACH_ENTITY_FIND_entity_nextall; noref string _FOREACH_ENTITY_FIND_entity_allmutex; @@ -159,7 +155,7 @@ MACRO_END .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 +#ifdef GAMEQC entity(vector org, float rad, .entity tofield) _findchainradius_tofield = #22; #define FOREACH_ENTITY_RADIUS(org, dist, cond, body) ORDERED(FOREACH_ENTITY_RADIUS)(org, dist, cond, body) .entity _FOREACH_ENTITY_FIND_radius_next; noref string _FOREACH_ENTITY_FIND_radius_mutex;