From 70df4446607f9349d2892246ade25fc7de4aecef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 20 Oct 2022 20:12:06 +0200 Subject: [PATCH] - Backend update from Raze * fix for serializing vector arrays. * a few adjustments for asan on Windows. * NOMUSICCUTOFF flag for movie player. * a bit of cleanup. --- src/common/engine/serializer.h | 2 +- src/common/objects/autosegs.h | 14 +++++++--- src/common/objects/dobjtype.cpp | 2 +- src/common/utility/i_time.cpp | 11 +------- src/common/utility/m_fixed.h | 4 +-- src/common/utility/vectors.h | 33 +++++++++++------------ wadsrc/static/zscript/engine/screenjob.zs | 3 ++- 7 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/common/engine/serializer.h b/src/common/engine/serializer.h index 086e118a1..d98798f95 100644 --- a/src/common/engine/serializer.h +++ b/src/common/engine/serializer.h @@ -159,7 +159,7 @@ public: template FSerializer &Array(const char *key, T *obj, T *def, int count, bool fullcompare = false) { - if (!save_full && fullcompare && isWriting() && def != nullptr && !memcmp(obj, def, count * sizeof(T))) + if (!save_full && fullcompare && isWriting() && key != nullptr && def != nullptr && !memcmp(obj, def, count * sizeof(T))) { return *this; } diff --git a/src/common/objects/autosegs.h b/src/common/objects/autosegs.h index df996d2f0..91b404ad4 100644 --- a/src/common/objects/autosegs.h +++ b/src/common/objects/autosegs.h @@ -47,6 +47,12 @@ #define NO_SANITIZE #endif +#if defined _MSC_VER +#define NO_SANITIZE_M __declspec(no_sanitize_address) +#else +#define NO_SANITIZE_M +#endif + class FAutoSeg { const char *name; @@ -102,14 +108,14 @@ public: } template - void ForEach(Func func, std::enable_if_t> * = nullptr) + void NO_SANITIZE_M ForEach(Func func, std::enable_if_t> * = nullptr) { using CallableType = decltype(&Func::operator()); using ArgType = typename ArgumentType::Type; for (void **it = begin; it < end; ++it) { - if (*it) + if (intptr_t(it) > 0xffff && *it && intptr_t(*it) > 0xffff) { func(reinterpret_cast(*it)); } @@ -117,14 +123,14 @@ public: } template - void ForEach(Func func, std::enable_if_t> * = nullptr) + void NO_SANITIZE_M ForEach(Func func, std::enable_if_t> * = nullptr) { using CallableType = decltype(&Func::operator()); using ArgType = typename ArgumentType::Type; for (void **it = begin; it < end; ++it) { - if (*it) + if (intptr_t(it) > 0xffff && *it && intptr_t(*it) > 0xffff) { if (!func(reinterpret_cast(*it))) { diff --git a/src/common/objects/dobjtype.cpp b/src/common/objects/dobjtype.cpp index b74820ed4..250dccbdd 100644 --- a/src/common/objects/dobjtype.cpp +++ b/src/common/objects/dobjtype.cpp @@ -187,7 +187,7 @@ bool PClass::ReadAllFields(FSerializer &ar, void *addr) const // //========================================================================== -static int cregcmp (const void *a, const void *b) NO_SANITIZE +static NO_SANITIZE_M int cregcmp (const void *a, const void *b) NO_SANITIZE { const PClass *class1 = *(const PClass **)a; const PClass *class2 = *(const PClass **)b; diff --git a/src/common/utility/i_time.cpp b/src/common/utility/i_time.cpp index 51ad0359d..a901a66ae 100644 --- a/src/common/utility/i_time.cpp +++ b/src/common/utility/i_time.cpp @@ -217,16 +217,7 @@ double I_GetInputFrac(bool const synchronised) const double now = I_msTimeF(); const double result = (now - lastinputtime) * GameTicRate * (1. / 1000.); lastinputtime = now; - - if (result < 1) - { - // Calculate an amplification to apply to the result before returning, - // factoring in the game's ticrate and the value of the result. - // This rectifies a deviation of 100+ ms or more depending on the length - // of the operation to be within 1-2 ms of synchronised input - // from 60 fps to at least 1000 fps at ticrates of 30 and 40 Hz. - return result * (1. + 0.35 * (1. - GameTicRate * (1. / 50.)) * (1. - result)); - } + return result; } return 1; diff --git a/src/common/utility/m_fixed.h b/src/common/utility/m_fixed.h index 08f2d420f..e4dd17bf9 100644 --- a/src/common/utility/m_fixed.h +++ b/src/common/utility/m_fixed.h @@ -16,9 +16,9 @@ __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) +constexpr fixed_t FloatToFixed(double f) { - return xs_Fix::ToFix(f); + return int(f * (1 << b)); } template diff --git a/src/common/utility/vectors.h b/src/common/utility/vectors.h index 017d1a520..b8a563ca8 100644 --- a/src/common/utility/vectors.h +++ b/src/common/utility/vectors.h @@ -272,6 +272,11 @@ struct TVector2 return X*other.X + Y*other.Y; } + vec_t dot(const TVector2 &other) const + { + return X*other.X + Y*other.Y; + } + // Returns the angle that the ray (0,0)-(X,Y) faces TAngle Angle() const; @@ -1307,6 +1312,11 @@ public: return Degrees_ / other; } + constexpr double operator/ (TAngle other) const + { + return Degrees_ / other.Degrees_; + } + // Should the comparisons consider an epsilon value? constexpr bool operator< (TAngle other) const { @@ -1486,27 +1496,15 @@ inline TVector2 clamp(const TVector2 &vec, const TVector2 &min, const T } template -inline TVector2 interpolatedvec2(const TVector2 &ovec, const TVector2 &vec, const double scale) +inline TAngle interpolatedvalue(const TAngle &oang, const TAngle &ang, const double interpfrac) { - return ovec + ((vec - ovec) * scale); + return oang + (deltaangle(oang, ang) * interpfrac); } -template -inline TVector3 interpolatedvec3(const TVector3 &ovec, const TVector3 &vec, const double scale) +template +inline T interpolatedvalue(const T& oval, const T& val, const double interpfrac) { - 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); + return T(oval + (val - oval) * interpfrac); } // Much of this is copied from TVector3. Is all that functionality really appropriate? @@ -1692,6 +1690,7 @@ typedef TMatrix3x3 DMatrix3x3; typedef TAngle DAngle; constexpr DAngle nullAngle = DAngle::fromDeg(0.); +constexpr DAngle minAngle = DAngle::fromDeg(1. / 65536.); constexpr FAngle nullFAngle = FAngle::fromDeg(0.); constexpr DAngle DAngle22_5 = DAngle::fromDeg(22.5); diff --git a/wadsrc/static/zscript/engine/screenjob.zs b/wadsrc/static/zscript/engine/screenjob.zs index ded06689d..e3fdc044d 100644 --- a/wadsrc/static/zscript/engine/screenjob.zs +++ b/wadsrc/static/zscript/engine/screenjob.zs @@ -204,6 +204,7 @@ struct MoviePlayer native { NOSOUNDCUTOFF = 1, FIXEDVIEWPORT = 2, // Forces fixed 640x480 screen size like for Blood's intros. + NOMUSICCUTOFF = 4, } native static MoviePlayer Create(String filename, Array soundinfo, int flags, int frametime, int firstframetime, int lastframetime); @@ -236,7 +237,7 @@ class MoviePlayerJob : SkippableScreenJob override void Start() { - System.StopMusic(); + if (!(flag & MoviePlayer.NOMUSICCUTOFF)) System.StopMusic(); }