- Build: Promote sintable[] array values to precision Blood uses in prep for replacing Blood's costable[].

This commit is contained in:
Mitch Richters 2021-10-30 17:21:27 +11:00 committed by Christoph Oelckers
parent 9d3d8e747c
commit 879e2f3ce4
3 changed files with 12 additions and 10 deletions

View file

@ -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"

View file

@ -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++)

View file

@ -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)
{