diff --git a/src/am_map.cpp b/src/am_map.cpp index 0d841f5e9..ec3d32ead 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1742,10 +1742,10 @@ void DAutomap::drawMline (mline_t *ml, const AMColor &color) const int x2 = f_x + fl.b.x; const int y2 = f_y + fl.b.y; if (am_linethickness >= 2) { - twod->AddThickLine(x1, y1, x2, y2, am_linethickness, color.RGB, uint8_t(am_linealpha * 255)); + twod->AddThickLine(DVector2(x1, y1), DVector2(x2, y2), am_linethickness, color.RGB, uint8_t(am_linealpha * 255)); } else { // Use more efficient thin line drawing routine. - twod->AddLine(x1, y1, x2, y2, nullptr, color.RGB, uint8_t(am_linealpha * 255)); + twod->AddLine(DVector2(x1, y1), DVector2(x2, y2), nullptr, color.RGB, uint8_t(am_linealpha * 255)); } } } diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 367fdbc33..1316dfa86 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -1040,7 +1040,7 @@ void F2DDrawer::ClearScreen(PalEntry color) // //========================================================================== -void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha) +void F2DDrawer::AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha) { PalEntry p = (PalEntry)color; p.a = alpha; @@ -1064,8 +1064,8 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec dg.transform = this->transform; dg.transform.Cells[0][2] += offset.X; dg.transform.Cells[1][2] += offset.Y; - mVertices[dg.mVertIndex].Set(x1, y1, 0, 0, 0, p); - mVertices[dg.mVertIndex+1].Set(x2, y2, 0, 0, 0, p); + mVertices[dg.mVertIndex].Set(v1.X, v1.Y, 0, 0, 0, p); + mVertices[dg.mVertIndex+1].Set(v2.X, v2.Y, 0, 0, 0, p); AddCommand(&dg); } @@ -1075,23 +1075,20 @@ void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRec // //========================================================================== -void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha) +void F2DDrawer::AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha) { PalEntry p = (PalEntry)color; p.a = alpha; - DVector2 point0(x1, y1); - DVector2 point1(x2, y2); - - DVector2 delta = point1 - point0; - DVector2 perp(-delta.Y, delta.X); + DVector2 delta = v2 - v1; + DVector2 perp = delta.Rotated90CCW(); perp.MakeUnit(); perp *= thickness / 2; - DVector2 corner0 = point0 + perp; - DVector2 corner1 = point0 - perp; - DVector2 corner2 = point1 + perp; - DVector2 corner3 = point1 - perp; + DVector2 corner0 = v1 + perp; + DVector2 corner1 = v1 - perp; + DVector2 corner2 = v2 + perp; + DVector2 corner3 = v2 - perp; RenderCommand dg; diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 904b66820..82c8aeada 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -227,8 +227,8 @@ public: void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); - void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255); - void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255); + void AddLine(const DVector2& v1, const DVector2& v2, const IntRect* clip, uint32_t color, uint8_t alpha = 255); + void AddThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t color, uint8_t alpha = 255); void AddPixel(int x1, int y1, uint32_t color); void AddEnableStencil(bool on); diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index 3d56829ba..f740ce4b3 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -1555,10 +1555,10 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h, // //========================================================================== -static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha) +static void DrawLine(const DVector2& v1, const DVector2& v2, uint32_t realcolor, int alpha) { if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha); + twod->AddLine(v1, v2, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha); } DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine) @@ -1570,7 +1570,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine) PARAM_INT(y1); PARAM_INT(color); PARAM_INT(alpha); - DrawLine(x0, y0, x1, y1, color, alpha); + DrawLine(DVector2(x0, y0), DVector2(x1, y1), color, alpha); return 0; } @@ -1583,15 +1583,15 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine) PARAM_INT(y1); PARAM_INT(color); PARAM_INT(alpha); - self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha); + self->Drawer.AddLine(DVector2(x0, y0), DVector2(x1, y1), nullptr, color | MAKEARGB(255, 0, 0, 0), alpha); self->Tex->NeedUpdate(); return 0; } -static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor, int alpha) +static void DrawThickLine(const DVector2& v1, const DVector2& v2, double thickness, uint32_t realcolor, int alpha) { if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - twod->AddThickLine(x0, y0, x1, y1, thickness, realcolor, alpha); + twod->AddThickLine(v1, v2, thickness, realcolor, alpha); } DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine) @@ -1604,7 +1604,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine) PARAM_FLOAT(thickness); PARAM_INT(color); PARAM_INT(alpha); - DrawThickLine(x0, y0, x1, y1, thickness, color, alpha); + DrawThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha); return 0; } @@ -1618,7 +1618,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawThickLine) PARAM_FLOAT(thickness); PARAM_INT(color); PARAM_INT(alpha); - self->Drawer.AddThickLine(x0, y0, x1, y1, thickness, color, alpha); + self->Drawer.AddThickLine(DVector2(x0, y0), DVector2(x1, y1), thickness, color, alpha); self->Tex->NeedUpdate(); return 0; } diff --git a/src/common/audio/sound/i_sound.cpp b/src/common/audio/sound/i_sound.cpp index 5f828d985..829c942c5 100644 --- a/src/common/audio/sound/i_sound.cpp +++ b/src/common/audio/sound/i_sound.cpp @@ -302,6 +302,7 @@ const char *GetSampleTypeName(SampleType type) { case SampleType_UInt8: return "Unsigned 8-bit"; case SampleType_Int16: return "Signed 16-bit"; + default: break; } return "(invalid sample type)"; } diff --git a/src/common/audio/sound/oalsound.cpp b/src/common/audio/sound/oalsound.cpp index fd43bcd89..dd7af7485 100644 --- a/src/common/audio/sound/oalsound.cpp +++ b/src/common/audio/sound/oalsound.cpp @@ -328,7 +328,7 @@ public: virtual bool IsEnded() { return !Playing.load(); - } + } Position GetPlayPosition() override { diff --git a/src/common/utility/cmdlib.cpp b/src/common/utility/cmdlib.cpp index 0dd6f7750..02ab18959 100644 --- a/src/common/utility/cmdlib.cpp +++ b/src/common/utility/cmdlib.cpp @@ -986,7 +986,7 @@ bool IsAbsPath(const char *name) if (IsSeperator(name[0])) return true; #ifdef _WIN32 /* [A-Za-z]: (for Windows) */ - if (isalpha(name[0]) && name[1] == ':') return true; + if (isalpha((uint8_t)name[0]) && name[1] == ':') return true; #endif /* _WIN32 */ return 0; } diff --git a/src/common/utility/m_fixed.h b/src/common/utility/m_fixed.h index da1852e3b..08f2d420f 100644 --- a/src/common/utility/m_fixed.h +++ b/src/common/utility/m_fixed.h @@ -15,24 +15,28 @@ __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { ret #include "xs_Float.h" +template inline fixed_t FloatToFixed(double f) { - return xs_Fix<16>::ToFix(f); + return xs_Fix::ToFix(f); } +template inline constexpr fixed_t IntToFixed(int32_t f) { - return f << FRACBITS; + return f << b; } +template inline constexpr double FixedToFloat(fixed_t f) { - return f * (1/65536.); + return f * (1. / (1 << b)); } +template inline constexpr int32_t FixedToInt(fixed_t f) { - return (f + FRACUNIT/2) >> FRACBITS; + return (f + (1 << (b-1))) >> b; } inline unsigned FloatToAngle(double f) diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index 48bc6cfc6..073c946c7 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -47,6 +47,7 @@ #include "xs_Float.h" #include "math/cmath.h" #include "basics.h" +#include "cmdlib.h" #define EQUAL_EPSILON (1/65536.) @@ -275,7 +276,7 @@ struct TVector2 TAngle Angle() const; // Returns a rotated vector. angle is in degrees. - TVector2 Rotated (double angle) + TVector2 Rotated (double angle) const { double cosval = g_cosdeg (angle); double sinval = g_sindeg (angle); @@ -284,13 +285,19 @@ struct TVector2 // Returns a rotated vector. angle is in degrees. template - TVector2 Rotated(TAngle angle) + TVector2 Rotated(TAngle angle) const { double cosval = angle.Cos(); double sinval = angle.Sin(); return TVector2(X*cosval - Y*sinval, Y*cosval + X*sinval); } + // Returns a rotated vector. angle is in degrees. + TVector2 Rotated(const double cosval, const double sinval) const + { + return TVector2(X*cosval - Y*sinval, Y*cosval + X*sinval); + } + // Returns a vector rotated 90 degrees clockwise. TVector2 Rotated90CW() { @@ -1385,8 +1392,7 @@ public: int Sgn() const { - const auto normalized = (signed int)BAMs(); - return (normalized > 0) - (normalized < 0); + return ::Sgn(int(BAMs())); } }; @@ -1414,6 +1420,12 @@ inline TAngle absangle(const TAngle &a1, const TAngle &a2) return fabs((a1 - a2).Normalized180()); } +template +inline TAngle clamp(const TAngle &angle, const TAngle &min, const TAngle &max) +{ + return TAngle::fromDeg(clamp(angle.Degrees(), min.Degrees(), max.Degrees())); +} + inline TAngle VecToAngle(double x, double y) { return TAngle::fromRad(g_atan2(y, x)); @@ -1449,6 +1461,36 @@ TAngle TVector3::Pitch() const return -VecToAngle(TVector2(X, Y).Length(), Z); } +template +inline TVector2 clamp(const TVector2 &vec, const TVector2 &min, const TVector2 &max) +{ + return TVector2(clamp(vec.X, min.X, max.X), clamp(vec.Y, min.Y, max.Y)); +} + +template +inline TVector2 interpolatedvec2(const TVector2 &ovec, const TVector2 &vec, const double scale) +{ + return ovec + ((vec - ovec) * scale); +} + +template +inline TVector3 interpolatedvec3(const TVector3 &ovec, const TVector3 &vec, const double scale) +{ + return ovec + ((vec - ovec) * scale); +} + +template +inline TVector4 interpolatedvec4(const TVector4 &ovec, const TVector4 &vec, const double scale) +{ + return ovec + ((vec - ovec) * scale); +} + +template +inline TAngle interpolatedangle(const TAngle &oang, const TAngle &ang, const double scale) +{ + return oang + (deltaangle(oang, ang) * scale); +} + // Much of this is copied from TVector3. Is all that functionality really appropriate? template struct TRotator @@ -1458,7 +1500,6 @@ struct TRotator Angle Pitch; // up/down Angle Yaw; // left/right Angle Roll; // rotation about the forward axis. - Angle CamRoll; // Roll specific to actor cameras. Used by quakes. TRotator() = default; @@ -1635,7 +1676,9 @@ typedef TAngle DAngle; constexpr DAngle nullAngle = DAngle::fromDeg(0.); constexpr FAngle nullFAngle = FAngle::fromDeg(0.); +constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); constexpr DAngle DAngle45 = DAngle::fromDeg(45); +constexpr DAngle DAngle60 = DAngle::fromDeg(60); constexpr DAngle DAngle90 = DAngle::fromDeg(90); constexpr DAngle DAngle180 = DAngle::fromDeg(180); constexpr DAngle DAngle270 = DAngle::fromDeg(270);