diff --git a/src/common/models/model.cpp b/src/common/models/model.cpp index c4b184f0c..377de6117 100644 --- a/src/common/models/model.cpp +++ b/src/common/models/model.cpp @@ -151,7 +151,7 @@ int ModelFrameHash(FSpriteModelFrame * smf) // //=========================================================================== -unsigned FindModel(const char * path, const char * modelfile) +unsigned FindModel(const char * path, const char * modelfile, bool silent) { FModel * model = nullptr; FString fullname; diff --git a/src/common/models/model.h b/src/common/models/model.h index 025bb2329..3f613d6f4 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -83,6 +83,7 @@ public: IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } void DestroyVertexBuffer(); + bool hasSurfaces = false; FString mFileName; private: @@ -90,5 +91,5 @@ private: }; int ModelFrameHash(FSpriteModelFrame* smf); -unsigned FindModel(const char* path, const char* modelfile); +unsigned FindModel(const char* path, const char* modelfile, bool silent = false); diff --git a/src/common/models/models_md3.cpp b/src/common/models/models_md3.cpp index 512794293..e716a6f26 100644 --- a/src/common/models/models_md3.cpp +++ b/src/common/models/models_md3.cpp @@ -133,6 +133,7 @@ bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int le auto numFrames = LittleLong(hdr->Num_Frames); auto numSurfaces = LittleLong(hdr->Num_Surfaces); + hasSurfaces = numSurfaces > 1; numTags = LittleLong(hdr->Num_Tags); diff --git a/src/common/models/models_obj.cpp b/src/common/models/models_obj.cpp index 5d6892798..a79caa9e4 100644 --- a/src/common/models/models_obj.cpp +++ b/src/common/models/models_obj.cpp @@ -222,6 +222,8 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length curSurface->faceStart = aggSurfFaceCount; surfaces.Push(*curSurface); delete curSurface; + hasSurfaces = surfaces.Size() > 1; + if (uvs.Size() == 0) { // Needed so that OBJs without UVs can work diff --git a/src/common/models/models_ue1.cpp b/src/common/models/models_ue1.cpp index 416f9a391..70245bc45 100644 --- a/src/common/models/models_ue1.cpp +++ b/src/common/models/models_ue1.cpp @@ -48,6 +48,7 @@ float unpackuvert( uint32_t n, int c ) bool FUE1Model::Load( const char *filename, int lumpnum, const char *buffer, int length ) { int lumpnum2; + hasSurfaces = true; FString realfilename = fileSystem.GetFileFullName(lumpnum); if ( (size_t)realfilename.IndexOf("_d.3d") == realfilename.Len()-5 ) { diff --git a/src/common/models/voxels.h b/src/common/models/voxels.h index 7d02bba13..52299434a 100644 --- a/src/common/models/voxels.h +++ b/src/common/models/voxels.h @@ -4,7 +4,10 @@ #include // [RH] Voxels from Build -#define MAXVOXMIPS 5 +enum +{ + MAXVOXMIPS = 5, +}; struct kvxslab_t { diff --git a/src/common/utility/geometry.h b/src/common/utility/geometry.h index ff8d9ddf1..cbe0fc72d 100644 --- a/src/common/utility/geometry.h +++ b/src/common/utility/geometry.h @@ -51,12 +51,6 @@ inline double PointOnLineSide(double x, double y, double linex, double liney, do return (x - linex) * deltay - (y - liney) * deltax; } -template -inline double PointOnLineSide(const TVector2& pos, const TVector2& linestart, const TVector2& lineend) -{ - return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X); -} - //========================================================================== // // @@ -146,8 +140,11 @@ inline double InterceptLineSegments(double v2x, double v2y, double v2dx, double { double den = v1dy * v2dx - v1dx * v2dy; - if (den == 0 || (forcansee && den < 0)) // cansee does this added check here, aside from that its logic is virtually the same. - return 0; // parallel + if (den == 0) + return -2 * (double)FLT_MAX; // parallel (return a magic value different from everything else, just in case it needs to be handled) + + if (forcansee && den < 0) // cansee does this added check here, aside from that its logic is virtually the same. + return -1; // hitting the backside // perform the division first for better parallelization. den = 1 / den; @@ -175,3 +172,63 @@ inline double LinePlaneIntersect(const DVector3& start, const DVector3& trace, c return (dist - dotStart) / dotTrace; // we are only interested in the factor } +//========================================================================== +// +// BoxOnLineSide +// +// Based on Doom's, but rewritten to be standalone +// +//========================================================================== + +inline int BoxOnLineSide(const DVector2& boxtl, const DVector2& boxbr, const DVector2& start, const DVector2& delta) +{ + int p1; + int p2; + + if (delta.X == 0) + { + p1 = boxbr.X < start.X; + p2 = boxtl.X < start.X; + if (delta.Y < 0) + { + p1 ^= 1; + p2 ^= 1; + } + } + else if (delta.Y == 0) + { + p1 = boxtl.Y > start.Y; + p2 = boxbr.Y > start.Y; + if (delta.X < 0) + { + p1 ^= 1; + p2 ^= 1; + } + } + else if (delta.X * delta.Y <= 0) + { + p1 = PointOnLineSide(boxtl.X, boxtl.Y, start.X, start.Y, delta.X, delta.Y) > 0; + p2 = PointOnLineSide(boxbr.X, boxbr.Y, start.X, start.Y, delta.X, delta.Y) > 0; + } + else + { + p1 = PointOnLineSide(boxbr.X, boxtl.Y, start.X, start.Y, delta.X, delta.Y) > 0; + p2 = PointOnLineSide(boxtl.X, boxbr.Y, start.X, start.Y, delta.X, delta.Y) > 0; + } + + return (p1 == p2) ? p1 : -1; +} + +//========================================================================== +// +// BoxInRange +// +//========================================================================== + +inline bool BoxInRange(const DVector2& boxtl, const DVector2& boxbr, const DVector2& start, const DVector2& end) +{ + return boxtl.X < max(start.X, end.X) && + boxbr.X > min(start.X, end.X) && + boxtl.Y < max(start.Y, end.Y) && + boxbr.Y > min(start.Y, end.Y); +} diff --git a/src/common/utility/i_time.cpp b/src/common/utility/i_time.cpp index a901a66ae..d9117d8ea 100644 --- a/src/common/utility/i_time.cpp +++ b/src/common/utility/i_time.cpp @@ -68,7 +68,7 @@ static uint64_t GetClockTimeNS() { auto tp = GetTimePoint() - StartupTimeNS; if (TimeScale == 1.0) return tp; - else return tp / 1000 * TimeScale * 1000; + else return uint64_t(tp / 1000 * TimeScale * 1000); } static uint64_t MSToNS(unsigned int ms) diff --git a/src/common/utility/m_fixed.h b/src/common/utility/m_fixed.h index bf7778e79..09d297693 100644 --- a/src/common/utility/m_fixed.h +++ b/src/common/utility/m_fixed.h @@ -7,7 +7,6 @@ __forceinline constexpr int32_t MulScale(int32_t a, int32_t b, int32_t shift) { return (int32_t)(((int64_t)a * b) >> shift); } -__forceinline constexpr double MulScaleF(double a, double b, int32_t shift) { return (a * b) * (1. / (uint32_t(1) << shift)); } __forceinline constexpr int32_t DMulScale(int32_t a, int32_t b, int32_t c, int32_t d, int32_t shift) { return (int32_t)(((int64_t)a * b + (int64_t)c * d) >> shift); } __forceinline constexpr int32_t DivScale(int32_t a, int32_t b, int shift) { return (int32_t)(((int64_t)a << shift) / b); } __forceinline constexpr int64_t DivScaleL(int64_t a, int64_t b, int shift) { return ((a << shift) / b); } diff --git a/src/common/utility/tarray.h b/src/common/utility/tarray.h index 181a9e939..dbd63002b 100644 --- a/src/common/utility/tarray.h +++ b/src/common/utility/tarray.h @@ -332,7 +332,7 @@ public: unsigned IndexOf(const T* elem) const { - return elem - Array; + return unsigned(elem - Array); } unsigned int Find(const T& item) const diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index e65e69607..661acd742 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -271,6 +271,19 @@ struct TVector2 return *this; } + TVector2 Resized(double len) const + { + double vlen = Length(); + if (vlen != 0.) + { + double scale = len / vlen; + return{ vec_t(X * scale), vec_t(Y * scale) }; + } + else + { + return *this; + } + } // Dot product vec_t operator | (const TVector2 &other) const @@ -644,7 +657,7 @@ struct TVector3 return *this; } - TVector3 Resized(double len) + TVector3 Resized(double len) const { double vlen = Length(); if (vlen != 0.) @@ -974,7 +987,7 @@ struct TVector4 return *this; } - TVector4 Resized(double len) + TVector4 Resized(double len) const { double vlen = Length(); if (vlen != 0.) @@ -1287,12 +1300,7 @@ public: return TAngle(f * (90. / 0x40000000)); } - static constexpr TAngle fromBuild(int bang) - { - return TAngle(bang * (90. / 512)); - } - - static constexpr TAngle fromBuildf(double bang) + static constexpr TAngle fromBuild(double bang) { return TAngle(bang * (90. / 512)); } @@ -1349,6 +1357,11 @@ public: return Degrees_ * other; } + constexpr TAngle operator* (TAngle other) const + { + return Degrees_ * other.Degrees_; + } + constexpr TAngle operator/ (vec_t other) const { return Degrees_ / other; @@ -1736,6 +1749,7 @@ constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); constexpr FAngle nullFAngle = FAngle::fromDeg(0.); constexpr DAngle DAngle1 = DAngle::fromDeg(1); +constexpr DAngle DAngle15 = DAngle::fromDeg(15); constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); constexpr DAngle DAngle45 = DAngle::fromDeg(45); constexpr DAngle DAngle60 = DAngle::fromDeg(60);