Preprocessor purge round 5: M_PI

This commit is contained in:
Tamás Bálint Misius 2023-01-04 12:21:19 +01:00
parent 3eb1609934
commit fdfa206a3c
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
10 changed files with 34 additions and 29 deletions

View File

@ -19,13 +19,20 @@
#include <type_traits>
#include <utility>
#define _USE_MATH_DEFINES
#include <cmath>
//some compatibility stuff for non-standard compilers
#if defined(WIN) && !defined(strcasecmp)
#define strcasecmp stricmp
#endif
#ifndef M_PI
#define M_PI 3.14159265f
#ifdef M_PI
constexpr float TPT_PI_FLT = float(M_PI);
constexpr double TPT_PI_DBL = double(M_PI);
#else
constexpr float TPT_PI_FLT = 3.14159265f;
constexpr double TPT_PI_DBL = 3.14159265358979323846;
#endif
typedef unsigned short Uint16;

View File

@ -791,8 +791,8 @@ void Renderer::render_parts()
gradv = 3.1415/(2*elements[t].HighTemperature-(elements[t].HighTemperature-800.0f));
auto caddress = int((sim->parts[i].temp>elements[t].HighTemperature)?elements[t].HighTemperature-(elements[t].HighTemperature-800.0f):sim->parts[i].temp-(elements[t].HighTemperature-800.0f));
colr += int(sin(gradv*caddress) * 226);
colg += int(sin(gradv*caddress*4.55 +3.14) * 34);
colb += int(sin(gradv*caddress*2.22 +3.14) * 64);
colg += int(sin(gradv*caddress*4.55 +TPT_PI_DBL) * 34);
colb += int(sin(gradv*caddress*2.22 +TPT_PI_DBL) * 64);
}
if((pixel_mode & FIRE_ADD) && !(render_mode & FIRE_ADD))
@ -1181,7 +1181,7 @@ void Renderer::render_parts()
sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for (r = 0; r < 4; r++) {
ddist = ((float)orbd[r])/16.0f;
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
drad = (TPT_PI_FLT * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(drad));
nyo = (int)(ddist*sin(drad));
if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && TYP(sim->pmap[ny+nyo][nx+nxo]) != PT_PRTI)
@ -1198,7 +1198,7 @@ void Renderer::render_parts()
sim->orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
for (r = 0; r < 4; r++) {
ddist = ((float)orbd[r])/16.0f;
drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
drad = (TPT_PI_FLT * ((float)orbl[r]) / 180.0f)*1.41f;
nxo = (int)(ddist*cos(drad));
nyo = (int)(ddist*sin(drad));
if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && TYP(sim->pmap[ny+nyo][nx+nxo]) != PT_PRTO)

View File

@ -41,9 +41,7 @@ static inline int resampler_range_check(int v, int h) { (void)h; resampler_asser
#define RESAMPLER_DEBUG 0
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "common/tpt-compat.h"
// Float to int cast with truncation.
static inline int cast_to_int(Resample_Real i)
@ -218,7 +216,7 @@ static Resample_Real catmull_rom_filter(Resample_Real t)
static double sinc(double x)
{
x = (x * M_PI);
x = (x * TPT_PI_DBL);
if ((x < 0.01f) && (x > -0.01f))
return 1.0f + x*x*(-1.0f/6.0f + x*x*1.0f/120.0f);
@ -236,12 +234,12 @@ static Resample_Real clean(double t)
//static double blackman_window(double x)
//{
// return .42f + .50f * cos(M_PI*x) + .08f * cos(2.0f*M_PI*x);
// return .42f + .50f * cos(TPT_PI_DBL*x) + .08f * cos(2.0f*TPT_PI_DBL*x);
//}
static double blackman_exact_window(double x)
{
return 0.42659071f + 0.49656062f * cos(M_PI*x) + 0.07684867f * cos(2.0f*M_PI*x);
return 0.42659071f + 0.49656062f * cos(TPT_PI_DBL*x) + 0.07684867f * cos(2.0f*TPT_PI_DBL*x);
}
#define BLACKMAN_SUPPORT (3.0f)
@ -263,7 +261,7 @@ static Resample_Real gaussian_filter(Resample_Real t) // with blackman window
if (t < 0)
t = -t;
if (t < GAUSSIAN_SUPPORT)
return clean(exp(-2.0f * t * t) * sqrt(2.0f / M_PI) * blackman_exact_window(t / GAUSSIAN_SUPPORT));
return clean(exp(-2.0f * t * t) * sqrt(2.0f / TPT_PI_DBL) * blackman_exact_window(t / GAUSSIAN_SUPPORT));
else
return 0.0f;
}

View File

@ -5030,7 +5030,7 @@ void Simulation::BeforeSim()
if (elementRecount)
std::fill(elementCount, elementCount+PT_NUM, 0);
}
sandcolour = (int)(20.0f*sin((float)sandcolour_frame*(M_PI/180.0f)));
sandcolour = (int)(20.0f*sin((float)sandcolour_frame*(TPT_PI_FLT/180.0f)));
sandcolour_frame = (sandcolour_frame+1)%360;
if (gravWallChanged)

View File

@ -97,8 +97,8 @@ int Element_COAL_graphics(GRAPHICS_FUNC_ARGS)
auto q = int((cpart->temp > 595.15f) ? 200.0f : cpart->temp - 395.15f);
*colr += int(sin(FREQUENCY*q) * 226);
*colg += int(sin(FREQUENCY*q*4.55 + 3.14) * 34);
*colb += int(sin(FREQUENCY*q*2.22 + 3.14) * 64);
*colg += int(sin(FREQUENCY*q*4.55 + TPT_PI_DBL) * 34);
*colb += int(sin(FREQUENCY*q*2.22 + TPT_PI_DBL) * 64);
}
return 0;
}

View File

@ -169,14 +169,14 @@ static int update(UPDATE_FUNC_ARGS)
}
angle = float((parts[i].tmp + RNG::Ref().between(-30, 30)) % 360);
multipler = int(parts[i].life * 1.5) + RNG::Ref().between(0, parts[i].life);
rx=int(cos(angle*M_PI/180)*multipler);
ry=int(-sin(angle*M_PI/180)*multipler);
rx=int(cos(angle*TPT_PI_FLT/180)*multipler);
ry=int(-sin(angle*TPT_PI_FLT/180)*multipler);
create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle), parts[i].tmp2, i);
if (parts[i].tmp2 == 2)// && pNear == -1)
{
angle2 = float(((int)angle + RNG::Ref().between(-100, 100)) % 360);
rx=int(cos(angle2*M_PI/180)*multipler);
ry=int(-sin(angle2*M_PI/180)*multipler);
rx=int(cos(angle2*TPT_PI_FLT/180)*multipler);
ry=int(-sin(angle2*TPT_PI_FLT/180)*multipler);
create_line_par(sim, x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, int(angle2), parts[i].tmp2, i);
}
@ -321,6 +321,6 @@ static void create(ELEMENT_CREATE_FUNC_ARGS)
gx += cosf(angle) * (0.04f - gsize);
gy += sinf(angle) * (0.04f - gsize);
}
sim->parts[i].tmp = (static_cast<int>(atan2f(-gy, gx) * (180.0f / M_PI)) + RNG::Ref().between(-20, 20) + 360) % 360;
sim->parts[i].tmp = (static_cast<int>(atan2f(-gy, gx) * (180.0f / TPT_PI_FLT)) + RNG::Ref().between(-20, 20) + 360) % 360;
sim->parts[i].tmp2 = 4;
}

View File

@ -77,7 +77,7 @@ static int update(UPDATE_FUNC_ARGS)
}
}
spawncount = std::abs(parts[i].tmp);
spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*M_PI);
spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*TPT_PI_FLT);
for (int j = 0;j < spawncount; j++)
{
switch (RNG::Ref().gen() % 3)
@ -95,7 +95,7 @@ static int update(UPDATE_FUNC_ARGS)
if (nb!=-1) {
parts[nb].life = RNG::Ref().between(0, 299);
parts[nb].temp = MAX_TEMP/2;
angle = RNG::Ref().uniform01()*2.0f*M_PI;
angle = RNG::Ref().uniform01()*2.0f*TPT_PI_FLT;
v = RNG::Ref().uniform01()*5.0f;
parts[nb].vx = v*cosf(angle);
parts[nb].vy = v*sinf(angle);

View File

@ -132,7 +132,7 @@ static int update(UPDATE_FUNC_ARGS)
parts[i].life=60;
parts[p].temp=parts[p].life*parts[i].tmp/2.5;
parts[p].tmp2=1;
parts[p].tmp=int(atan2(-ry, (float)rx)/M_PI*360);
parts[p].tmp=int(atan2(-ry, (float)rx)/TPT_PI_FLT*360);
parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling
if (fabs(sim->pv[y/CELL][x/CELL])!=0.0f)
{

View File

@ -499,7 +499,7 @@ int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS)
int angle;
int power = 100;
if (gvx!=0 || gvy!=0)
angle = int(atan2(mvx, mvy)*180.0f/M_PI);
angle = int(atan2(mvx, mvy)*180.0f/TPT_PI_FLT);
else
angle = RNG::Ref().between(0, 359);
if (((int)playerp->pcomm)&0x01)

View File

@ -111,11 +111,11 @@ static int graphics(GRAPHICS_FUNC_ARGS)
{
const float MELTING_POINT = ren->sim->elements[PT_TUNG].HighTemperature;
double startTemp = (MELTING_POINT - 1500.0);
double tempOver = (((cpart->temp - startTemp)/1500.0)*M_PI) - (M_PI/2.0);
if(tempOver > -(M_PI/2.0))
double tempOver = (((cpart->temp - startTemp)/1500.0)*TPT_PI_FLT) - (TPT_PI_FLT/2.0);
if(tempOver > -(TPT_PI_FLT/2.0))
{
if(tempOver > (M_PI/2.0))
tempOver = (M_PI/2.0);
if(tempOver > (TPT_PI_FLT/2.0))
tempOver = (TPT_PI_FLT/2.0);
double gradv = sin(tempOver) + 1.0;
*firer = (int)(gradv * 258.0);
*fireg = (int)(gradv * 156.0);