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