From: Martin Taibr Date: Tue, 6 Nov 2018 11:24:27 +0000 (+0100) Subject: use NaN instead of resetting to old value X-Git-Tag: xonotic-v0.8.5~1258^2~58 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=602c027252637b8fc3ee06cc7db3e55016a277b2;p=xonotic%2Fxonotic-data.pk3dir.git use NaN instead of resetting to old value --- diff --git a/qcsrc/client/csqcmodel_hooks.qc b/qcsrc/client/csqcmodel_hooks.qc index 961fc7757..86c672c23 100644 --- a/qcsrc/client/csqcmodel_hooks.qc +++ b/qcsrc/client/csqcmodel_hooks.qc @@ -541,7 +541,8 @@ void CSQCModel_Effects_Apply(entity this) if(this.csqcmodel_modelflags & MF_ROTATE) { this.renderflags |= RF_USEAXIS; - MAKEVECTORS(makevectors, this.angles + '0 100 0' * fmod(time, 3.6), v_forward, v_right, v_up); + makevectors(this.angles + '0 100 0' * fmod(time, 3.6)); + //MAKEVECTORS(makevectors, this.angles + '0 100 0' * fmod(time, 3.6), v_forward, v_right, v_up); } if(this.csqcmodel_modelflags & MF_TRACER) tref = EFFECT_TR_WIZSPIKE.m_id; diff --git a/qcsrc/lib/float.qh b/qcsrc/lib/float.qh index b4d1f0bd7..fa4ff77b5 100644 --- a/qcsrc/lib/float.qh +++ b/qcsrc/lib/float.qh @@ -2,3 +2,4 @@ const float FLOAT_MAX = 340282346638528859811704183484516925440.0f; const float FLOAT_EPSILON = 0.00000011920928955078125f; +const float FLOAT_NAN = 0.0 / 0.0; diff --git a/qcsrc/lib/vector.qh b/qcsrc/lib/vector.qh index 7e393e6e4..2900a0f90 100644 --- a/qcsrc/lib/vector.qh +++ b/qcsrc/lib/vector.qh @@ -1,5 +1,23 @@ #pragma once +#include "lib/float.qh" +#include "lib/misc.qh" +#include "lib/static.qh" + +//pseudo prototypes: +// vector vec2(vector v); // returns a vector with just the x and y components of the given vector +// vector vec2(float x, float y); // returns a vector with the given x and y components + +noref vector _vec2; +#define vec2(...) EVAL(OVERLOAD(vec2, __VA_ARGS__)) +#define vec2_1(v) (_vec2 = (v), _vec2.z = 0, _vec2) +#define vec2_2(x, y) (_vec2_x = (x), _vec2_y = (y), _vec2) + +noref vector _vec3; +#define vec3(_x, _y, _z) (_vec3.x = (_x), _vec3.y = (_y), _vec3.z = (_z), _vec3) + +#define VEC_NAN vec3(FLOAT_NAN, FLOAT_NAN, FLOAT_NAN); + noref vector _vlen2; #define vlen2(v) (_vlen2 = (v), dotproduct(_vlen2, _vlen2)) @@ -93,31 +111,27 @@ float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { ret #define YAW(v) ((v).y) #define ROLL(v) ((v).z) +#ifdef GAMEQC +STATIC_INIT(globals) { + // set to NaN to more easily detect uninitialized use + v_forward = VEC_NAN; + v_right = VEC_NAN; + v_up = VEC_NAN; +} +#endif + +// TODO when raw makevectors in not used anywhere else, assert that the global vectors are NaN before calling makevectors here +// to make sure nobody is accidentally using them #define MAKEVECTORS(f, angles, forward, right, up) MACRO_BEGIN { \ - vector old_forward = v_forward; \ - vector old_right = v_right; \ - vector old_up = v_up; \ f(angles); \ forward = v_forward; \ right = v_right; \ up = v_up; \ - v_forward = old_forward; \ - v_right = old_right; \ - v_up = old_up; \ + v_forward = VEC_NAN; \ + v_right = VEC_NAN; \ + v_up = VEC_NAN; \ } MACRO_END -//pseudo prototypes: -// vector vec2(vector v); // returns a vector with just the x and y components of the given vector -// vector vec2(float x, float y); // returns a vector with the given x and y components - -noref vector _vec2; -#define vec2(...) EVAL(OVERLOAD(vec2, __VA_ARGS__)) -#define vec2_1(v) (_vec2 = (v), _vec2.z = 0, _vec2) -#define vec2_2(x, y) (_vec2_x = (x), _vec2_y = (y), _vec2) - -noref vector _vec3; -#define vec3(_x, _y, _z) (_vec3.x = (_x), _vec3.y = (_y), _vec3.z = (_z), _vec3) - ERASEABLE vector Rotate(vector v, float a) {