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