X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Funsafe.qh;h=60ad3d88da517e11174910a1a1d5da29085b5b15;hb=565754a35f9e84a3b8e6eac08635ec27145b369a;hp=f8fa38280dd709742bf96fc99c07cfb2be31a5b4;hpb=17e9fbaa18a08e3a84f67955da54527dbf2acee3;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/unsafe.qh b/qcsrc/lib/unsafe.qh index f8fa38280..60ad3d88d 100644 --- a/qcsrc/lib/unsafe.qh +++ b/qcsrc/lib/unsafe.qh @@ -1,15 +1,31 @@ -#ifndef UNSAFE_H -#define UNSAFE_H +#pragma once #define reinterpret_cast(T, it) _unsafe_cast_##T(0, it) -#define X(T) T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); } +#define X(T) \ + T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); } \ + USING(T##_fld, .T); T##_fld _unsafe_cast_##T##_fld(int dummy, ...) { return ...(0, T##_fld); } +X(bool) +X(int) X(float) +X(vector) X(entity) X(string) -typedef float(...) rawfunc; +USING(rawfunc, float(...)); X(rawfunc) #undef X -#define strid(s) etof(reinterpret_cast(entity, s)) +#define _strid(s) ITOF(reinterpret_cast(int, s)) +#define strid(s) stof(sprintf("%i", s)) -#endif +.int _unsafe_fld1, _unsafe_fld2; +int INTEGER_ONE; + +#define FTOI(f) ((f) * INTEGER_ONE) +#define ITOF(i) ((i) / INTEGER_ONE) + +STATIC_INIT(INTEGER_ONE) +{ + INTEGER_ONE = reinterpret_cast(int, _unsafe_fld2) - reinterpret_cast(int, _unsafe_fld1); +} + +#define ARRAY_INDEX(T, arr, idx) (reinterpret_cast(T##_fld, reinterpret_cast(int, arr[0]) + FTOI(idx)))