]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/deglobalization.qh
move deglob stuff to it's own file
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / deglobalization.qh
1 #include "lib/misc.qh"
2 #include "lib/static.qh"
3 #include "lib/vector.qh"
4
5 // These macros wrap functions which use globals so mutation only occurs inside them and is not visible from outside.
6 // Functions for which all usages are replaced with these macros can be hidden inside our `*defs.qh` files
7 // to prevent anyone from using them accidentally.
8
9 // FIXME MAKE_VECTORS because current naming sucks
10
11 #ifdef GAMEQC
12 STATIC_INIT(globals) {
13         // set to NaN to more easily detect uninitialized use
14     // TODO when all functions are wrapped and the raw functions are not used anymore,
15     // assert that the global vectors are NaN before calling the raw functions
16     // to make sure nobody (even builtins) is accidentally using them - NaN is the most likely value to expose remaining usages
17         v_forward = VEC_NAN;
18         v_right = VEC_NAN;
19         v_up = VEC_NAN;
20 }
21 #endif
22
23 /// Same as the `makevectors` builtin but uses the provided locals instead of the `v_*` globals.
24 /// Always use this instead of raw `makevectors` to make the data flow clear.
25 #define MAKEVECTORS(angles, forward, right, up) MACRO_BEGIN { \
26         makevectors(angles); \
27         forward = v_forward; \
28         right = v_right; \
29         up = v_up; \
30         v_forward = VEC_NAN; \
31         v_right = VEC_NAN; \
32         v_up = VEC_NAN; \
33 } MACRO_END
34
35 /// Same as `MAKEVECTORS` but also creates the locals for convenience.
36 #define MAKEVECTORS_NEW(angles, forward, right, up) \
37         vector forward = '0 0 0'; \
38         vector right = '0 0 0'; \
39         vector up = '0 0 0'; \
40         MAKEVECTORS(angles, forward, right, up);
41
42 #define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN { \
43         _vectorvectors_hidden(forward_in); \
44         forward = v_forward; \
45         right = v_right; \
46         up = v_up; \
47         v_forward = VEC_NAN; \
48         v_right = VEC_NAN; \
49         v_up = VEC_NAN; \
50 } MACRO_END
51
52 #define VECTOR_VECTORS_NEW(forward_in, forward, right, up) \
53         vector forward = '0 0 0'; \
54         vector right = '0 0 0'; \
55         vector up = '0 0 0'; \
56         VECTOR_VECTORS(forward_in, forward, right, up);