2 #include "lib/static.qh"
3 #include "lib/vector.qh"
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.
9 // FIXME MAKE_VECTORS because current naming sucks
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
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; \
30 v_forward = VEC_NAN; \
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);
42 #define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN { \
43 _vectorvectors_hidden(forward_in); \
44 forward = v_forward; \
47 v_forward = VEC_NAN; \
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);