From 6fcb8f7a6aa000efa563b1124bf2ad387855dd95 Mon Sep 17 00:00:00 2001 From: NY00123 Date: Fri, 17 Apr 2020 16:21:22 +0300 Subject: [PATCH] Add gethiq16angle and the getq16angle wrapper to the engine --- source/build/include/build.h | 6 ++++++ source/build/src/engine.cpp | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/source/build/include/build.h b/source/build/include/build.h index 622957fea..f2d84bc73 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -935,6 +935,12 @@ int32_t krand(void); int32_t ksqrt(uint32_t num); int32_t LUNATIC_FASTCALL getangle(int32_t xvect, int32_t yvect); +fix16_t LUNATIC_FASTCALL gethiq16angle(int32_t xvect, int32_t yvect); + +static FORCE_INLINE fix16_t LUNATIC_FASTCALL getq16angle(int32_t xvect, int32_t yvect) +{ + return fix16_from_int(getangle(xvect, yvect)); +} static FORCE_INLINE CONSTEXPR uint32_t uhypsq(int32_t const dx, int32_t const dy) { diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 36c9527bf..7109dc665 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -4023,6 +4023,27 @@ int32_t LUNATIC_FASTCALL getangle(int32_t xvect, int32_t yvect) return rv; } +fix16_t LUNATIC_FASTCALL gethiq16angle(int32_t xvect, int32_t yvect) +{ + fix16_t rv; + + if ((xvect | yvect) == 0) + rv = 0; + else if (xvect == 0) + rv = fix16_from_int(512 + ((yvect < 0) << 10)); + else if (yvect == 0) + rv = fix16_from_int(((xvect < 0) << 10)); + else if (xvect == yvect) + rv = fix16_from_int(256 + ((xvect < 0) << 10)); + else if (xvect == -yvect) + rv = fix16_from_int(768 + ((xvect > 0) << 10)); + else if (klabs(xvect) > klabs(yvect)) + rv = ((qradarang[5120 + scale(1280, yvect, xvect)] >> 6) + fix16_from_int(((xvect < 0) << 10))) & 0x7FFFFFF; + else rv = ((qradarang[5120 - scale(1280, xvect, yvect)] >> 6) + fix16_from_int(512 + ((yvect < 0) << 10))) & 0x7FFFFFF; + + return rv; +} + // // ksqrt //