]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/accumulate.qh
#pragma once
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / accumulate.qh
1 #pragma once
2
3 #ifdef QCC_SUPPORT_ACCUMULATE
4         #define ACCUMULATE_FUNCTION(func, otherfunc) \
5                 [[accumulate]] void func() \
6                 { \
7                         otherfunc(); \
8                 }
9         #define CALL_ACCUMULATED_FUNCTION(func) \
10                 func()
11 #else
12         #ifdef HAVE_YO_DAWG_CPP
13 // TODO make ascii art pic of xzibit
14 // YO DAWG!
15 // I HERD YO LIEK MACROS
16 // SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION
17 // SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS
18                 #define ACCUMULATE_FUNCTION(func, otherfunc) \
19                         #ifdef func \
20                         void __merge__##otherfunc() \
21                         { \
22                                 func(); otherfunc(); \
23                         } \
24                         #undef func \
25                         #define func __merge__##otherfunc \
26                         #else \
27                                 #define func otherfunc \
28                                 #endif
29                 #define CALL_ACCUMULATED_FUNCTION(func) \
30                         func()
31         #else
32                 #define ACCUMULATE_FUNCTION(func, otherfunc) \
33                         .float _ACCUMULATE_##func##__##otherfunc;
34                 void ACCUMULATE_call(string func)
35                 {
36                         float i;
37                         float n = numentityfields();
38                         string funcprefix = strcat("_ACCUMULATE_", func, "__");
39                         float funcprefixlen = strlen(funcprefix);
40                         for (i = 0; i < n; ++i)
41                         {
42                                 string name = entityfieldname(i);
43                                 if (substring(name, 0, funcprefixlen) == funcprefix) callfunction(substring(name, funcprefixlen, -1));
44                         }
45                 }
46                 #define CALL_ACCUMULATED_FUNCTION(func) \
47                         ACCUMULATE_call( #func)
48         #endif
49 #endif
50
51 // used for simplifying ACCUMULATE_FUNCTIONs
52 #define SET_FIRST_OR_LAST(input, first, count) \
53         if (!input) { input = (first + count); }
54 #define SET_FIELD_COUNT(field, first, count) \
55         if (!field) { field = (first + count); ++count; }
56 #define CHECK_MAX_COUNT(name, max, count, type) \
57         if (count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }