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