diff --git a/regamedll/build.gradle b/regamedll/build.gradle index 2c3297ef..335b1288 100644 --- a/regamedll/build.gradle +++ b/regamedll/build.gradle @@ -120,6 +120,9 @@ void setupToolchain(NativeBinarySpec b) cfg.compilerOptions.floatingPointModel = FloatingPointModel.PRECISE cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED } + else { + cfg.compilerOptions.args '/Oi', '/GF', '/GS-' + } if (mpLib) { diff --git a/regamedll/dlls/vector.h b/regamedll/dlls/vector.h index 3b24df99..12f71b00 100644 --- a/regamedll/dlls/vector.h +++ b/regamedll/dlls/vector.h @@ -36,12 +36,9 @@ class Vector2D { public: vec_t x, y; - Vector2D() : x(0.0), y(0.0) {} - Vector2D(float X, float Y) : x(0.0), y(0.0) - { - x = X; - y = Y; - } + Vector2D() : x(), y() {} + Vector2D(float X, float Y) : x(X), y(Y) {} + Vector2D(const Vector2D &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; } Vector2D operator+(const Vector2D &v) const { return Vector2D(x + v.x, y + v.y); @@ -151,25 +148,10 @@ class Vector { public: vec_t x, y, z; - Vector() : x(0.0), y(0.0), z(0.0) {} - Vector(float X, float Y, float Z) : x(0.0), y(0.0), z(0.0) - { - x = X; - y = Y; - z = Z; - } - Vector(const Vector &v) : x(0.0), y(0.0), z(0.0) - { - x = v.x; - y = v.y; - z = v.z; - } - Vector(const float rgfl[3]) : x(0.0), y(0.0), z(0.0) - { - x = rgfl[0]; - y = rgfl[1]; - z = rgfl[2]; - } + Vector() : x(), y(), z() {} + Vector(float X, float Y, float Z) : x(X), y(Y), z(Z) {} + Vector(const Vector &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; *(int*)&z = *(int*)&v.z; } + Vector(const float rgfl[3]) { *(int*)&x = *(int*)&rgfl[0]; *(int*)&y = *(int*)&rgfl[1]; *(int*)&z = *(int*)&rgfl[2]; } Vector operator-() const { return Vector(-x, -y, -z); @@ -219,9 +201,9 @@ public: #endif // PLAY_GAMEDLL void CopyToArray(float *rgfl) const { - rgfl[0] = x; - rgfl[1] = y; - rgfl[2] = z; + *(int*)&rgfl[0] = *(int*)&x; + *(int*)&rgfl[1] = *(int*)&y; + *(int*)&rgfl[2] = *(int*)&z; } float_precision Length() const { @@ -244,7 +226,7 @@ public: return &x; } #ifndef PLAY_GAMEDLL - Vector Normalize() + Vector Normalize() const { float flLen = Length(); if (flLen == 0) @@ -265,7 +247,7 @@ public: } #endif // PLAY_GAMEDLL // for out precision normalize - Vector NormalizePrecision() + Vector NormalizePrecision() const { #ifndef PLAY_GAMEDLL return Normalize(); @@ -281,8 +263,8 @@ public: Vector2D Make2D() const { Vector2D Vec2; - Vec2.x = x; - Vec2.y = y; + *(int*)&Vec2.x = *(int*)&x; + *(int*)&Vec2.y = *(int*)&y; return Vec2; } float_precision Length2D() const diff --git a/regamedll/engine/common.h b/regamedll/engine/common.h index 8254c3f1..68708e33 100644 --- a/regamedll/engine/common.h +++ b/regamedll/engine/common.h @@ -79,6 +79,21 @@ typedef struct incomingtransfer_s #define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]); #endif // _WIN32 +inline double M_sqrt(int value) { + return sqrt(value); +} + +inline float M_sqrt(float value) { + return _mm_cvtss_f32(_mm_sqrt_ss(_mm_load_ss(&value))); +} + +inline double M_sqrt(double value) { + double ret; + auto v = _mm_load_sd(&value); + _mm_store_sd(&ret, _mm_sqrt_sd(v, v)); + return ret; +} + #define printf2 _printf2 #define chatf _print_chat @@ -139,4 +154,9 @@ typedef struct incomingtransfer_s #define Q_fprintf fprintf #define Q_fclose fclose +#ifdef REGAMEDLL_FIXES +#undef Q_sqrt +#define Q_sqrt M_sqrt +#endif + #endif // COMMON_H