diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index cc59a5b2d..cca2d6636 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -46,7 +46,8 @@ class FSerializer; enum { - BAMUNIT = 1 << 21, + BAMBITS = 21, + BAMUNIT = 1 << BAMBITS, SINSHIFT = 14 }; @@ -92,6 +93,18 @@ inline double bcosf(const double& ang, const int8_t& shift = 0) } +//--------------------------------------------------------------------------- +// +// Shift a Build angle left by 21 bits. +// +//--------------------------------------------------------------------------- + +inline constexpr uint32_t BAngToBAM(int ang) +{ + return ang << BAMBITS; +} + + //--------------------------------------------------------------------------- // // @@ -164,7 +177,7 @@ public: inline constexpr binangle bamang(uint32_t v) { return binangle(v); } inline constexpr binangle q16ang(uint32_t v) { return binangle(v << 5); } -inline constexpr binangle buildang(uint32_t v) { return binangle(v << 21); } +inline constexpr binangle buildang(uint32_t v) { return binangle(v << BAMBITS); } inline binangle radang(double v) { return binangle(xs_CRoundToUInt(v * (0x80000000u / pi::pi()))); } inline binangle degang(double v) { return binangle(FloatToAngle(v)); } @@ -246,7 +259,7 @@ public: inline constexpr lookangle bamlook(int32_t v) { return lookangle(v); } inline constexpr lookangle q16look(int32_t v) { return lookangle(v << 5); } -inline constexpr lookangle buildlook(int32_t v) { return lookangle(v << 21); } +inline constexpr lookangle buildlook(int32_t v) { return lookangle(v << BAMBITS); } inline lookangle radlook(double v) { return lookangle(xs_CRoundToUInt(v * (0x80000000u / pi::pi()))); } inline lookangle deglook(double v) { return lookangle(FloatToAngle(v)); } diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 0e771b16e..dd6b5d503 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -40,17 +40,13 @@ int getincangle(int a, int na) a &= 2047; na &= 2047; - if(abs(a-na) < 1024) - return (na-a); - else + if(abs(a-na) >= 1024) { if(na > 1024) na -= 2048; if(a > 1024) a -= 2048; - - na -= 2048; - a -= 2048; - return (na-a); } + + return na-a; } fixed_t getincangleq16(fixed_t a, fixed_t na) @@ -58,17 +54,27 @@ fixed_t getincangleq16(fixed_t a, fixed_t na) a &= 0x7FFFFFF; na &= 0x7FFFFFF; - if(abs(a-na) < IntToFixed(1024)) - return (na-a); - else + if(abs(a-na) >= IntToFixed(1024)) { if(na > IntToFixed(1024)) na -= IntToFixed(2048); if(a > IntToFixed(1024)) a -= IntToFixed(2048); - - na -= IntToFixed(2048); - a -= IntToFixed(2048); - return (na-a); } + + return na-a; +} + +lookangle getincanglebam(binangle a, binangle na) +{ + int64_t cura = a.asbam() & 0xFFFFFFFF; + int64_t newa = na.asbam() & 0xFFFFFFFF; + + if(abs(cura-newa) >= BAngToBAM(1024)) + { + if(newa > BAngToBAM(1024)) newa -= BAngToBAM(2048); + if(cura > BAngToBAM(1024)) cura -= BAngToBAM(2048); + } + + return bamlook(newa-cura); } //--------------------------------------------------------------------------- diff --git a/source/core/gameinput.h b/source/core/gameinput.h index a0252e0cd..473be6581 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -5,8 +5,9 @@ #include "gamecvars.h" #include "packet.h" -int getincangle(int c, int n); -fixed_t getincangleq16(fixed_t c, fixed_t n); +int getincangle(int a, int na); +fixed_t getincangleq16(fixed_t a, fixed_t na); +lookangle getincanglebam(binangle a, binangle na); struct PlayerHorizon {