From 7a6039b44cea1d336284ac150c208b151d2df8ce Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Apr 2016 11:53:31 +0200 Subject: [PATCH] - floatified vertex coordinates. Making these double or float doesn't seem to matter at all performance-wise so they use the more precise double format. --- src/r_defs.h | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index d2202f4e7..d47e82386 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -102,55 +102,60 @@ typedef double vtype; struct vertex_t { private: - fixed_t x, y; + DVector2 p; public: void set(fixed_t x, fixed_t y) { - this->x = x; - this->y = y; + p.X = x / 65536.; + p.Y = y / 65536.; } void set(double x, double y) { - this->x = FLOAT2FIXED(x); - this->y = FLOAT2FIXED(y); + p.X = x; + p.Y = y; } double fX() const { - return FIXED2DBL(x); + return p.X; } double fY() const { - return FIXED2DBL(y); + return p.Y; } fixed_t fixX() const { - return x; + return FLOAT2FIXED(p.X); } fixed_t fixY() const { - return y; + return FLOAT2FIXED(p.Y); } DVector2 fPos() { - return{ fX(), fY() }; + return { p.X, p.Y }; } bool operator== (const vertex_t &other) { - return x == other.x && y == other.y; + return p == other.p; + } + + bool operator!= (const vertex_t &other) + { + return p != other.p; } void clear() { - x = y = 0; + p.Zero(); } }; @@ -366,12 +371,12 @@ public: // This is for the software renderer fixed_t ZatPointFixed(const DVector2 &pos) const { - return xs_CRoundToInt((d + a*pos.X + b*pos.Y) * ic / (-65536.0)); + return FLOAT2FIXED(ZatPoint(pos)); } fixed_t ZatPointFixed(const vertex_t *v) const { - return FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY())); + return FLOAT2FIXED(ZatPoint(v)); } @@ -389,7 +394,7 @@ public: double ZatPoint(const vertex_t *v) const { - return FIXED2DBL(FixedMul(ic, -d - DMulScale16(a, v->fixX(), b, v->fixY()))); + return (d + a*v->fX() + b*v->fY()) * ic / (-65536.0 * 65536.0); } double ZatPoint(const AActor *ac) const @@ -400,7 +405,7 @@ public: // Returns the value of z at vertex v if d is equal to dist double ZatPointDist(const vertex_t *v, double dist) { - return FIXED2DBL(FixedMul(ic, -FLOAT2FIXED(dist) - DMulScale16(a, v->fixX(), b, v->fixY()))); + return (dist + a*v->fX() + b*v->fY()) * ic / (-65536.0 * 65536.0); } // Flips the plane's vertical orientiation, so that if it pointed up, // it will point down, and vice versa.