]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/unsafe.qh
Merge branch 'terencehill/cl_forceplayercolors_3' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / unsafe.qh
1 #pragma once
2
3 #define reinterpret_cast(T, it) _unsafe_cast_##T(0, it)
4 #define X(T) \
5     T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); } \
6     USING(T##_fld, .T); T##_fld _unsafe_cast_##T##_fld(int dummy, ...) { return ...(0, T##_fld); }
7 X(bool)
8 X(int)
9 X(float)
10 X(vector)
11 X(entity)
12 X(string)
13 USING(rawfunc, float(...));
14 X(rawfunc)
15 #undef X
16
17 #define _strid(s) ITOF(reinterpret_cast(int, s))
18 #define strid(s) stof(sprintf("%i", s))
19
20 .int _unsafe_fld1, _unsafe_fld2;
21 int INTEGER_ONE;
22
23 #define FTOI(f) ((f) * INTEGER_ONE)
24 #define ITOF(i) ((i) / INTEGER_ONE)
25
26 STATIC_INIT(INTEGER_ONE)
27 {
28     INTEGER_ONE = reinterpret_cast(int, _unsafe_fld2) - reinterpret_cast(int, _unsafe_fld1);
29 }
30
31 #define ARRAY_INDEX(T, arr, idx) (reinterpret_cast(T##_fld, reinterpret_cast(int, arr[0]) + FTOI(idx)))