]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/accumulate.qh
Small optimization
[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                         {
41                                 string name = entityfieldname(i);
42                                 if (substring(name, 0, funcprefixlen) == funcprefix) callfunction(substring(name, funcprefixlen, -1));
43                         }
44                 }
45                 #define CALL_ACCUMULATED_FUNCTION(func) \
46                         ACCUMULATE_call( #func)
47         #endif
48 #endif
49
50 // used for simplifying ACCUMULATE_FUNCTIONs
51 #define SET_FIRST_OR_LAST(input, first, count) \
52         if (!input) { input = (first + count); }
53 #define SET_FIELD_COUNT(field, first, count) \
54         if (!field) { field = (first + count); ++count; }
55 #define CHECK_MAX_COUNT(name, max, count, type) \
56         if (count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }