mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Calculate sine and arctan tables, getting rid of TABLES.DAT dependency.
We're pulling stuff from math.h even in non-GL builds right now, so adding libc's sin() and atan() doesn't seem like a big deal. In the unlikely event that their accuracy is so bad that the calculated tables don't match the original ones, a warning is issued on little-endian platforms. git-svn-id: https://svn.eduke32.com/eduke32@2988 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
5bca5f59ad
commit
ee39d713e8
2 changed files with 39 additions and 18 deletions
|
@ -16,7 +16,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PI 3.14159265358979323
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
#define MAXSECTORSV8 4096
|
||||
#define MAXWALLSV8 16384
|
||||
|
|
|
@ -2262,7 +2262,6 @@ static int32_t globaly1, globalx2, globalzx;
|
|||
static int32_t globalx, globaly, globalz;
|
||||
|
||||
int16_t sectorborder[256], sectorbordercnt;
|
||||
static char tablesloaded = 0;
|
||||
int32_t ydim16, qsetmode = 0;
|
||||
int32_t startposx, startposy, startposz;
|
||||
int16_t startang, startsectnum;
|
||||
|
@ -7498,35 +7497,57 @@ static inline void calcbritable(void)
|
|||
}
|
||||
}
|
||||
|
||||
#define BANG2RAD (PI/1024.0)
|
||||
|
||||
static int32_t loadtables(void)
|
||||
{
|
||||
int32_t i, fil;
|
||||
static char tablesloaded = 0;
|
||||
|
||||
if (tablesloaded == 0)
|
||||
{
|
||||
int32_t i;
|
||||
|
||||
initksqrt();
|
||||
|
||||
for (i=0; i<2048; i++)
|
||||
reciptable[i] = divscale30(2048, i+2048);
|
||||
|
||||
if ((fil = kopen4load("tables.dat",0)) != -1)
|
||||
for (i=0; i<=512; i++)
|
||||
sintable[i] = 16384*sin(i*BANG2RAD);
|
||||
for (i=513; i<1024; i++)
|
||||
sintable[i] = sintable[1024-i];
|
||||
for (i=1024; i<2048; i++)
|
||||
sintable[i] = -sintable[i-1024];
|
||||
|
||||
for (i=0; i<640; i++)
|
||||
radarang[i] = -64*atan((640-0.5-i)/160)/BANG2RAD;
|
||||
for (i=0; i<640; i++)
|
||||
radarang[1279-i] = -radarang[i];
|
||||
|
||||
#ifdef B_LITTLE_ENDIAN
|
||||
i = 0;
|
||||
if (crc32once((uint8_t *)sintable, sizeof(sintable)) != 0xee1e7aba)
|
||||
i |= 1;
|
||||
if (crc32once((uint8_t *)radarang, 640*sizeof(radarang[0])) != 0xee893d92)
|
||||
i |= 2;
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
kread(fil,sintable,2048*2); for (i=2048-1; i>=0; i--) sintable[i] = B_LITTLE16(sintable[i]);
|
||||
kread(fil,radarang,640*2); for (i=640-1; i>=0; i--) radarang[i] = B_LITTLE16(radarang[i]);
|
||||
for (i=0; i<640; i++) radarang[1279-i] = -radarang[i];
|
||||
static const char *str[3] = { "sine table", "arctangent table",
|
||||
"sine and arctangent tables" };
|
||||
initprintf("WARNING: Calculated %s differ%s from original!\n",
|
||||
str[i-1], i==3 ? "" : "s");
|
||||
}
|
||||
#endif
|
||||
// TABLES.DAT format:
|
||||
//kread(fil,sintable,2048*2);
|
||||
//kread(fil,radarang,640*2);
|
||||
//kread(fil,textfont,1024);
|
||||
//kread(fil,smalltextfont,1024);
|
||||
//kread(fil,britable,1024);
|
||||
|
||||
calcbritable();
|
||||
|
||||
kclose(fil);
|
||||
}
|
||||
else
|
||||
{
|
||||
engineerrstr = "Failed to load \"tables.dat\"!";
|
||||
initprintf("ERROR: %s\n", engineerrstr);
|
||||
return 1;
|
||||
}
|
||||
tablesloaded = 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue