Merge pull request #30 from theAsmodai/master

Fixed Vector constructors
This commit is contained in:
s1lentq 2016-04-24 20:01:11 +06:00
commit f3f72281ee
3 changed files with 37 additions and 32 deletions

View File

@ -120,6 +120,9 @@ void setupToolchain(NativeBinarySpec b)
cfg.compilerOptions.floatingPointModel = FloatingPointModel.PRECISE cfg.compilerOptions.floatingPointModel = FloatingPointModel.PRECISE
cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED cfg.compilerOptions.enhancedInstructionsSet = EnhancedInstructionsSet.DISABLED
} }
else {
cfg.compilerOptions.args '/Oi', '/GF', '/GR-', '/GS-'
}
if (mpLib) if (mpLib)
{ {

View File

@ -36,12 +36,9 @@ class Vector2D
{ {
public: public:
vec_t x, y; vec_t x, y;
Vector2D() : x(0.0), y(0.0) {} Vector2D() : x(), y() {}
Vector2D(float X, float Y) : x(0.0), y(0.0) Vector2D(float X, float Y) : x(X), y(Y) {}
{ Vector2D(const Vector2D &v) { *(int*)&x = *(int*)&v.x; *(int*)&y = *(int*)&v.y; }
x = X;
y = Y;
}
Vector2D operator+(const Vector2D &v) const Vector2D operator+(const Vector2D &v) const
{ {
return Vector2D(x + v.x, y + v.y); return Vector2D(x + v.x, y + v.y);
@ -151,25 +148,10 @@ class Vector
{ {
public: public:
vec_t x, y, z; vec_t x, y, z;
Vector() : x(0.0), y(0.0), z(0.0) {} Vector() : x(), y(), z() {}
Vector(float X, float Y, float Z) : x(0.0), y(0.0), z(0.0) 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; }
x = X; Vector(const float rgfl[3]) { *(int*)&x = *(int*)&rgfl[0]; *(int*)&y = *(int*)&rgfl[1]; *(int*)&z = *(int*)&rgfl[2]; }
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 operator-() const Vector operator-() const
{ {
return Vector(-x, -y, -z); return Vector(-x, -y, -z);
@ -219,9 +201,9 @@ public:
#endif // PLAY_GAMEDLL #endif // PLAY_GAMEDLL
void CopyToArray(float *rgfl) const void CopyToArray(float *rgfl) const
{ {
rgfl[0] = x; *(int*)&rgfl[0] = *(int*)&x;
rgfl[1] = y; *(int*)&rgfl[1] = *(int*)&y;
rgfl[2] = z; *(int*)&rgfl[2] = *(int*)&z;
} }
float_precision Length() const float_precision Length() const
{ {
@ -244,7 +226,7 @@ public:
return &x; return &x;
} }
#ifndef PLAY_GAMEDLL #ifndef PLAY_GAMEDLL
Vector Normalize() Vector Normalize() const
{ {
float flLen = Length(); float flLen = Length();
if (flLen == 0) if (flLen == 0)
@ -265,7 +247,7 @@ public:
} }
#endif // PLAY_GAMEDLL #endif // PLAY_GAMEDLL
// for out precision normalize // for out precision normalize
Vector NormalizePrecision() Vector NormalizePrecision() const
{ {
#ifndef PLAY_GAMEDLL #ifndef PLAY_GAMEDLL
return Normalize(); return Normalize();
@ -281,8 +263,8 @@ public:
Vector2D Make2D() const Vector2D Make2D() const
{ {
Vector2D Vec2; Vector2D Vec2;
Vec2.x = x; *(int*)&Vec2.x = *(int*)&x;
Vec2.y = y; *(int*)&Vec2.y = *(int*)&y;
return Vec2; return Vec2;
} }
float_precision Length2D() const float_precision Length2D() const

View File

@ -79,6 +79,21 @@ typedef struct incomingtransfer_s
#define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]); #define _strlwr(p) for (int i = 0; p[i] != 0; i++) p[i] = tolower(p[i]);
#endif // _WIN32 #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 printf2 _printf2
#define chatf _print_chat #define chatf _print_chat
@ -139,4 +154,9 @@ typedef struct incomingtransfer_s
#define Q_fprintf fprintf #define Q_fprintf fprintf
#define Q_fclose fclose #define Q_fclose fclose
#ifdef REGAMEDLL_FIXES
#undef Q_sqrt
#define Q_sqrt M_sqrt
#endif
#endif // COMMON_H #endif // COMMON_H