]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/dpdefs/post.qh
wip
[xonotic/xonotic-data.pk3dir.git] / qcsrc / dpdefs / post.qh
1 #pragma once
2
3 #undef ChangeYaw
4 #undef checkclient
5 #undef droptofloor
6 #undef error
7 #undef movetogoal
8 #undef objerror
9 #undef remove
10 #undef walkmove
11 #undef setcolor
12
13 #ifdef MENUQC
14         #define NULL (RVALUE, null_entity)
15         #define world NULL
16 #else
17         #define NULL (RVALUE, world)
18 #endif
19
20 #include "lib/accumulate.qh"
21 #include "lib/misc.qh"
22 #include "lib/static.qh"
23 #include "lib/vector.qh"
24
25 void(vector) _vectorvectors;
26
27 #ifdef GAMEQC
28 STATIC_INIT(globals) {
29         _vectorvectors = vectorvectors;
30
31         // set to NaN to more easily detect uninitialized use
32         v_forward = VEC_NAN;
33         v_right = VEC_NAN;
34         v_up = VEC_NAN;
35 }
36
37 /// Same as the `makevectors` builtin but uses the provided locals instead of the `v_*` globals.
38 /// Always use this instead of raw `makevectors` to make the data flow clear.
39 /// It's 2018, they even teach that globals are bad at my uni... though for some reason they never explained why. Sigh.
40 #define MAKEVECTORS(angles, forward, right, up) MACRO_BEGIN { \
41         makevectors(angles); \
42         forward = v_forward; \
43         right = v_right; \
44         up = v_up; \
45         v_forward = VEC_NAN; \
46         v_right = VEC_NAN; \
47         v_up = VEC_NAN; \
48 } MACRO_END
49
50 // Same as `MAKEVECTORS` but also creates the locals for convenience.
51 #define MAKEVECTORS_NEW(angles, forward, right, up) \
52         vector forward = '0 0 0'; \
53         vector right = '0 0 0'; \
54         vector up = '0 0 0'; \
55         MAKEVECTORS(angles, forward, right, up);
56
57 #define VECTOR_VECTORS(forward_in, forward, right, up) MACRO_BEGIN { \
58         _vectorvectors(forward_in); \
59         forward = v_forward; \
60         right = v_right; \
61         up = v_up; \
62         v_forward = VEC_NAN; \
63         v_right = VEC_NAN; \
64         v_up = VEC_NAN; \
65 } MACRO_END
66
67 #define VECTOR_VECTORS_NEW(forward_in, forward, right, up) \
68         vector forward = '0 0 0'; \
69         vector right = '0 0 0'; \
70         vector up = '0 0 0'; \
71         VECTOR_VECTORS(forward_in, forward, right, up);
72
73 #define vectorvectors DO_NOT_USE_GLOBALS
74
75 // FIXME find a good place for this
76 // FIXME MAKE_VECTORS because current naming sucks
77 // FIXME ban vectorvectors
78
79 // TODO when raw makevectors and similar functions are not used anywhere else anymore,
80 // assert that the global vectors are NaN before calling makevectors in MAKEVECTORS
81 // to make sure nobody (even builtins) is accidentally using them - NaN is the most liekly value to expose values clearly
82 // also uncomment these:
83 //#define makevectors DO_NOT_USE_GLOBALS
84 //#define v_forward DO_NOT_USE_GLOBALS
85 //#define v_right DO_NOT_USE_GLOBALS
86 //#define v_up DO_NOT_USE_GLOBALS
87 // FIXME ^ won't work
88 #endif