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 // TODO stuff in the engine that uses the v_forward/v_right/v_up globals and is not wrapped:
10 // - RF_USEAXIS, addentities, predraw,
11 // CL_GetEntityMatrix (in engine but is called from other functions so transitively any of them can use the globals - e.g. V_CalcRefdef, maybe others)
12 // - e.camera_transform / CL_VM_TransformView (in engine)
17 // - skel_get_bonerel, skel_get_boneabs, skel_set_bone, skel_mul_bone, skel_mul_bones
21 STATIC_INIT(globals) {
22 // set to NaN to more easily detect uninitialized use
23 // TODO when all functions are wrapped and the raw functions are not used anymore,
24 // assert that the global vectors are NaN before calling the raw functions
25 // to make sure nobody (even builtins) is accidentally using them - NaN is the most likely value to expose remaining usages
32 /// Same as the `makevectors` builtin but uses the provided locals instead of the `v_*` globals.
33 /// Always use this instead of raw `makevectors` to make the data flow clear.
34 #define MAKE_VECTORS(angles, forward, right, up) MACRO_BEGIN { \
35 makevectors(angles); \
36 forward = v_forward; \
39 v_forward = VEC_NAN; \
44 /// Same as `MAKE_VECTORS` but also creates the locals for convenience.
45 #define MAKE_VECTORS_NEW(angles, forward, right, up) \
46 vector forward = '0 0 0'; \
47 vector right = '0 0 0'; \
48 vector up = '0 0 0'; \
49 MAKE_VECTORS(angles, forward, right, up);
51 #define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN { \
52 _vectorvectors_hidden(forward_in); \
53 forward = v_forward; \
56 v_forward = VEC_NAN; \
61 #define VECTOR_VECTORS_NEW(forward_in, forward, right, up) \
62 vector forward = '0 0 0'; \
63 vector right = '0 0 0'; \
64 vector up = '0 0 0'; \
65 VECTOR_VECTORS(forward_in, forward, right, up);