From 879e2f3ce432bece43350ee9c0660e0fceeceed7 Mon Sep 17 00:00:00 2001 From: Mitch Richters Date: Sat, 30 Oct 2021 17:21:27 +1100 Subject: [PATCH] - Build: Promote `sintable[]` array values to precision Blood uses in prep for replacing Blood's `costable[]`. --- source/build/include/build.h | 2 +- source/build/src/engine.cpp | 2 +- source/core/binaryangle.h | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/build/include/build.h b/source/build/include/build.h index faf9ab917..d1c7c05cc 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -28,7 +28,7 @@ static_assert('\xff' == 255, "Char must be unsigned!"); # define EXTERN extern #endif -EXTERN int16_t sintable[2048]; +EXTERN int sintable[2048]; #include "buildtiles.h" #include "c_cvars.h" diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 51c5c9160..cc6cb7bea 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -207,7 +207,7 @@ static int32_t engineLoadTables(void) int32_t i; for (i=0; i<=512; i++) - sintable[i] = bsinf(i); + sintable[i] = int(sin(i * BAngRadian) * SINTABLEUNIT); for (i=513; i<1024; i++) sintable[i] = sintable[1024-i]; for (i=1024; i<2048; i++) diff --git a/source/core/binaryangle.h b/source/core/binaryangle.h index 8a17a6495..456790560 100644 --- a/source/core/binaryangle.h +++ b/source/core/binaryangle.h @@ -41,7 +41,6 @@ #include "xs_Float.h" // needed for reliably overflowing float->int conversions. #include "serializer.h" #include "math/cmath.h" -#include "templates.h" class FSerializer; @@ -49,7 +48,10 @@ enum { BAMBITS = 21, BAMUNIT = 1 << BAMBITS, - SINSHIFT = 14 + SINTABLEBITS = 30, + SINTABLEUNIT = 1 << SINTABLEBITS, + BUILDSINBITS = 14, + BUILDSINSHIFT = SINTABLEBITS - BUILDSINBITS, }; //--------------------------------------------------------------------------- @@ -61,11 +63,11 @@ enum constexpr double BAngRadian = pi::pi() * (1. / 1024.); constexpr double BAngToDegree = 360. / 2048.; -extern int16_t sintable[2048]; +extern int sintable[2048]; inline constexpr double sinscale(const int shift) { - return shift >= -SINSHIFT ? uint64_t(1) << (SINSHIFT + shift) : 1. / (uint64_t(1) << abs(SINSHIFT + shift)); + return shift >= -BUILDSINBITS ? uint64_t(1) << (BUILDSINBITS + shift) : 1. / (uint64_t(1) << abs(BUILDSINBITS + shift)); } //--------------------------------------------------------------------------- @@ -74,9 +76,9 @@ inline constexpr double sinscale(const int shift) // //--------------------------------------------------------------------------- -inline int bsin(const int ang, const int shift = 0) +inline int bsin(const int ang, int shift = 0) { - return shift < 0 ? sintable[ang & 2047] >> abs(shift) : sintable[ang & 2047] << shift; + return (shift -= BUILDSINSHIFT) < 0 ? sintable[ang & 2047] >> abs(shift) : sintable[ang & 2047] << shift; } inline double bsinf(const double ang, const int shift = 0) { @@ -90,9 +92,9 @@ inline double bsinf(const double ang, const int shift = 0) // //--------------------------------------------------------------------------- -inline int bcos(const int ang, const int shift = 0) +inline int bcos(const int ang, int shift = 0) { - return shift < 0 ? sintable[(ang + 512) & 2047] >> abs(shift) : sintable[(ang + 512) & 2047] << shift; + return (shift -= BUILDSINSHIFT) < 0 ? sintable[(ang + 512) & 2047] >> abs(shift) : sintable[(ang + 512) & 2047] << shift; } inline double bcosf(const double ang, const int shift = 0) {