X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Flib%2Fdeglobalization.qh;h=3d7f82067440137e64db91a8bc7c78cf53c5ca37;hb=9dd628718378362a91d9a087d2e93746b502e4af;hp=c4969f5fc1343ede5cae8ecfb8aa44273f15f9e6;hpb=71d5e574432fcd7767520c2a9ad582d1652c37ab;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/deglobalization.qh b/qcsrc/lib/deglobalization.qh index c4969f5fc..3d7f82067 100644 --- a/qcsrc/lib/deglobalization.qh +++ b/qcsrc/lib/deglobalization.qh @@ -1,20 +1,23 @@ +#include "lib/float.qh" #include "lib/misc.qh" #include "lib/static.qh" #include "lib/vector.qh" // These macros wrap functions which use globals so mutation only occurs inside them and is not visible from outside. -// Functions for which all usages are replaced with these macros can be hidden inside our `*defs.qh` files -// to prevent anyone from using them accidentally. +// Functions for which all usages are replaced with these macros can be hidden by #defines inside our `*defs.qh` files +// to prevent anyone from using them accidentally in the future // TODO stuff in the engine that uses the v_forward/v_right/v_up globals and is not wrapped yet: // - RF_USEAXIS, addentities, predraw, // - 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) // - however RF_USEAXIS is only used if MF_ROTATE is used which is only set in one place // - e.camera_transform / CL_VM_TransformView (in engine) -// - adddynamiclight -// - makestatic -// - gettaginfo -// - getentity +// - this is the only used function that both sets and gets the globals (aim does too but isn't used in our code) + +// convenience for deglobalization code - don't use these just to hide that globals are still used +#define CLEAR_V_GLOBALS() v_forward = VEC_NAN; v_right = VEC_NAN; v_up = VEC_NAN +#define GET_V_GLOBALS(forward, right, up) forward = v_forward; right = v_right; up = v_up +#define SET_V_GLOBALS(forward, right, up) v_forward = forward; v_right = right; v_up = up #ifdef GAMEQC STATIC_INIT(globals) { @@ -24,71 +27,47 @@ STATIC_INIT(globals) { // and assert that the global vectors are NaN before calling the raw functions here // to make sure nobody (even builtins) is accidentally using them - NaN is the most likely value to expose remaining usages - // TODO make sure `isnan` actually works - potential compiler bug: - //LOG_INFOF("%f\n", 0.0/0.0 == 0.0/0.0); - //LOG_INFOF("%f\n", 0.0/0.0 != 0.0/0.0); - //float x = 0.0/0.0; - //LOG_INFOF("%f\n", x == x); - //LOG_INFOF("%f\n", x != x); - - v_forward = VEC_NAN; - v_right = VEC_NAN; - v_up = VEC_NAN; + CLEAR_V_GLOBALS(); } #endif /// Same as the `makevectors` builtin but uses the provided locals instead of the `v_*` globals. /// Always use this instead of raw `makevectors` to make the data flow clear. -#define MAKE_VECTORS(angles, forward, right, up) MACRO_BEGIN { \ +/// Note that you might prefer `FIXED_MAKE_VECTORS` for new code. +#define MAKE_VECTORS(angles, forward, right, up) MACRO_BEGIN \ _makevectors_hidden(angles); \ - forward = v_forward; \ - right = v_right; \ - up = v_up; \ - v_forward = VEC_NAN; \ - v_right = VEC_NAN; \ - v_up = VEC_NAN; \ -} MACRO_END - -/// Same as `MAKE_VECTORS` but also creates the locals for convenience. -#define MAKE_VECTORS_NEW(angles, forward, right, up) \ - vector forward = '0 0 0'; \ - vector right = '0 0 0'; \ - vector up = '0 0 0'; \ - MAKE_VECTORS(angles, forward, right, up); - -#define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN { \ - _vectorvectors_hidden(forward_in); \ - forward = v_forward; \ - right = v_right; \ - up = v_up; \ - v_forward = VEC_NAN; \ - v_right = VEC_NAN; \ - v_up = VEC_NAN; \ -} MACRO_END - -#define VECTOR_VECTORS_NEW(forward_in, forward, right, up) \ - vector forward = '0 0 0'; \ - vector right = '0 0 0'; \ - vector up = '0 0 0'; \ - VECTOR_VECTORS(forward_in, forward, right, up); + GET_V_GLOBALS(forward, right, up); \ + CLEAR_V_GLOBALS(); \ +MACRO_END /// Returns all 4 vectors by assigning to them (instead of returning a value) for consistency (and sanity) -#define SKEL_GET_BONE_ABS(skel, bonenum, forward, right, up, origin) MACRO_BEGIN { \ +#define SKEL_GET_BONE_ABS(skel, bonenum, forward, right, up, origin) MACRO_BEGIN \ origin = _skel_get_boneabs_hidden(skel, bonenum) \ - forward = v_forward; \ - right = v_right; \ - up = v_up; \ - v_forward = VEC_NAN; \ - v_right = VEC_NAN; \ - v_up = VEC_NAN; \ -} MACRO_END + GET_V_GLOBALS(forward, right, up); \ + CLEAR_V_GLOBALS(); \ +MACRO_END -#define SKEL_SET_BONE(skel, bonenum, org, forward, right, up) MACRO_BEGIN { \ - v_forward = forward; \ - v_right = right; \ - v_up = up; \ +#define SKEL_SET_BONE(skel, bonenum, org, forward, right, up) MACRO_BEGIN \ + SET_V_GLOBALS(forward, right, up); \ _skel_set_bone_hidden(skel, bonenum, org); \ - v_forward = VEC_NAN; \ - v_right = VEC_NAN; \ - v_up = VEC_NAN; \ -} MACRO_END + CLEAR_V_GLOBALS(); \ +MACRO_END + +#define ADD_DYNAMIC_LIGHT(org, radius, lightcolours, forward, right, up) MACRO_BEGIN \ + SET_V_GLOBALS(forward, right, up); \ + _adddynamiclight_hidden(org, radius, lightcolours); \ + CLEAR_V_GLOBALS(); \ +MACRO_END + +#define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN \ + _vectorvectors_hidden(forward_in); \ + GET_V_GLOBALS(forward, right, up); \ + CLEAR_V_GLOBALS(); \ +MACRO_END + +/// Note that this only avoids the v_* globals, not the gettaginfo_* ones +#define GET_TAG_INFO(ent, tagindex, forward, right, up, origin) MACRO_BEGIN \ + origin = _gettaginfo_hidden(ent, tagindex); \ + GET_V_GLOBALS(forward, right, up); \ + CLEAR_V_GLOBALS(); \ +MACRO_END