- more float to double conversion.

In particular this removes all assignments of FIXED2FLOAT to double variables because they not only lose precision but also generate unnecessary code.
This commit is contained in:
Christoph Oelckers 2016-02-11 21:33:30 +01:00
parent 34255908b0
commit 158caf78a0
12 changed files with 60 additions and 64 deletions

View file

@ -2512,8 +2512,8 @@ void AM_rotate(fixed_t *xp, fixed_t *yp, angle_t a)
cosrot = cos(rot);
}
double x = FIXED2FLOAT(*xp);
double y = FIXED2FLOAT(*yp);
double x = FIXED2DBL(*xp);
double y = FIXED2DBL(*yp);
double tmpx = (x * cosrot) - (y * sinrot);
y = (x * sinrot) + (y * cosrot);
x = tmpx;

View file

@ -1084,7 +1084,7 @@ CCMD(currentpos)
if(mo)
{
Printf("Current player position: (%1.3f,%1.3f,%1.3f), angle: %1.3f, floorheight: %1.3f, sector:%d, lightlevel: %d\n",
FIXED2FLOAT(mo->X()), FIXED2FLOAT(mo->Y()), FIXED2FLOAT(mo->Z()), mo->angle/float(ANGLE_1), FIXED2FLOAT(mo->floorz), mo->Sector->sectornum, mo->Sector->lightlevel);
FIXED2DBL(mo->X()), FIXED2DBL(mo->Y()), FIXED2DBL(mo->Z()), ANGLE2DBL(mo->angle), FIXED2DBL(mo->floorz), mo->Sector->sectornum, mo->Sector->lightlevel);
}
else
{

View file

@ -165,8 +165,8 @@ public:
void Activate (AActor *activator);
void Deactivate (AActor *activator);
protected:
float Splerp (float p1, float p2, float p3, float p4);
float Lerp (float p1, float p2);
double Splerp (double p1, double p2, double p3, double p4);
double Lerp (double p1, double p2);
virtual bool Interpolate ();
virtual void NewNode ();
@ -191,10 +191,10 @@ void APathFollower::Serialize (FArchive &arc)
// Interpolate between p2 and p3 along a Catmull-Rom spline
// http://research.microsoft.com/~hollasch/cgindex/curves/catmull-rom.html
float APathFollower::Splerp (float p1, float p2, float p3, float p4)
double APathFollower::Splerp (double p1, double p2, double p3, double p4)
{
float t = Time;
float res = 2*p2;
double t = Time;
double res = 2*p2;
res += (p3 - p1) * Time;
t *= Time;
res += (2*p1 - 5*p2 + 4*p3 - p4) * t;
@ -204,7 +204,7 @@ float APathFollower::Splerp (float p1, float p2, float p3, float p4)
}
// Linearly interpolate between p1 and p2
float APathFollower::Lerp (float p1, float p2)
double APathFollower::Lerp (double p1, double p2)
{
return p1 + Time * (p2 - p1);
}
@ -325,7 +325,7 @@ void APathFollower::Tick ()
if (Interpolate ())
{
Time += 8.f / ((float)CurrNode->args[1] * (float)TICRATE);
Time += float(8.f / ((double)CurrNode->args[1] * (double)TICRATE));
if (Time > 1.f)
{
Time -= 1.f;
@ -371,20 +371,20 @@ bool APathFollower::Interpolate ()
fixed_t x, y, z;
if (args[2] & 1)
{ // linear
x = FLOAT2FIXED(Lerp (FIXED2FLOAT(CurrNode->X()), FIXED2FLOAT(CurrNode->Next->X())));
y = FLOAT2FIXED(Lerp (FIXED2FLOAT(CurrNode->Y()), FIXED2FLOAT(CurrNode->Next->Y())));
z = FLOAT2FIXED(Lerp (FIXED2FLOAT(CurrNode->Z()), FIXED2FLOAT(CurrNode->Next->Z())));
x = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->X()), FIXED2DBL(CurrNode->Next->X())));
y = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->Y()), FIXED2DBL(CurrNode->Next->Y())));
z = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->Z()), FIXED2DBL(CurrNode->Next->Z())));
}
else
{ // spline
if (CurrNode->Next->Next==NULL) return false;
x = FLOAT2FIXED(Splerp (FIXED2FLOAT(PrevNode->X()), FIXED2FLOAT(CurrNode->X()),
FIXED2FLOAT(CurrNode->Next->X()), FIXED2FLOAT(CurrNode->Next->Next->X())));
y = FLOAT2FIXED(Splerp (FIXED2FLOAT(PrevNode->Y()), FIXED2FLOAT(CurrNode->Y()),
FIXED2FLOAT(CurrNode->Next->Y()), FIXED2FLOAT(CurrNode->Next->Next->Y())));
z = FLOAT2FIXED(Splerp (FIXED2FLOAT(PrevNode->Z()), FIXED2FLOAT(CurrNode->Z()),
FIXED2FLOAT(CurrNode->Next->Z()), FIXED2FLOAT(CurrNode->Next->Next->Z())));
x = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->X()), FIXED2DBL(CurrNode->X()),
FIXED2DBL(CurrNode->Next->X()), FIXED2DBL(CurrNode->Next->Next->X())));
y = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->Y()), FIXED2DBL(CurrNode->Y()),
FIXED2DBL(CurrNode->Next->Y()), FIXED2DBL(CurrNode->Next->Next->Y())));
z = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->Z()), FIXED2DBL(CurrNode->Z()),
FIXED2DBL(CurrNode->Next->Z()), FIXED2DBL(CurrNode->Next->Next->Z())));
}
SetXYZ(x, y, z);
LinkToWorld ();
@ -442,11 +442,11 @@ bool APathFollower::Interpolate ()
{
if (args[2] & 2)
{ // interpolate angle
float angle1 = (float)CurrNode->angle;
float angle2 = (float)CurrNode->Next->angle;
double angle1 = (double)CurrNode->angle;
double angle2 = (double)CurrNode->Next->angle;
if (angle2 - angle1 <= -2147483648.f)
{
float lerped = Lerp (angle1, angle2 + 4294967296.f);
double lerped = Lerp (angle1, angle2 + 4294967296.f);
if (lerped >= 4294967296.f)
{
angle = xs_CRoundToUInt(lerped - 4294967296.f);
@ -458,7 +458,7 @@ bool APathFollower::Interpolate ()
}
else if (angle2 - angle1 >= 2147483648.f)
{
float lerped = Lerp (angle1, angle2 - 4294967296.f);
double lerped = Lerp (angle1, angle2 - 4294967296.f);
if (lerped < 0.f)
{
angle = xs_CRoundToUInt(lerped + 4294967296.f);
@ -477,15 +477,15 @@ bool APathFollower::Interpolate ()
{ // linear
if (args[2] & 4)
{ // interpolate pitch
pitch = FLOAT2FIXED(Lerp (FIXED2FLOAT(CurrNode->pitch), FIXED2FLOAT(CurrNode->Next->pitch)));
pitch = FLOAT2FIXED(Lerp (FIXED2DBL(CurrNode->pitch), FIXED2DBL(CurrNode->Next->pitch)));
}
}
else
{ // spline
if (args[2] & 4)
{ // interpolate pitch
pitch = FLOAT2FIXED(Splerp (FIXED2FLOAT(PrevNode->pitch), FIXED2FLOAT(CurrNode->pitch),
FIXED2FLOAT(CurrNode->Next->pitch), FIXED2FLOAT(CurrNode->Next->Next->pitch)));
pitch = FLOAT2FIXED(Splerp (FIXED2DBL(PrevNode->pitch), FIXED2DBL(CurrNode->pitch),
FIXED2DBL(CurrNode->Next->pitch), FIXED2DBL(CurrNode->Next->Next->pitch)));
}
}
}

View file

@ -310,8 +310,8 @@ class CommandDrawImage : public SBarInfoCommandFlowControl
if (applyscale)
{
spawnScaleX = FIXED2FLOAT(item->scaleX);
spawnScaleY = FIXED2FLOAT(item->scaleY);
spawnScaleX = FIXED2DBL(item->scaleX);
spawnScaleY = FIXED2DBL(item->scaleY);
}
texture = TexMan[icon];

View file

@ -4222,9 +4222,9 @@ void P_RailAttack(AActor *source, int damage, int offset_xy, fixed_t offset_z, i
rail_data.Caller = source;
rail_data.StopAtOne = !!(railflags & RAF_NOPIERCE);
start.X = FIXED2FLOAT(xy.x);
start.Y = FIXED2FLOAT(xy.y);
start.Z = FIXED2FLOAT(shootz);
start.X = FIXED2DBL(xy.x);
start.Y = FIXED2DBL(xy.y);
start.Z = FIXED2DBL(shootz);
int flags;

View file

@ -560,7 +560,7 @@ sector_t *AActor::LinkToWorldForMapThing ()
DPrintf ("%s at (%d,%d) lies on %s line %td, distance = %f\n",
this->GetClass()->TypeName.GetChars(), X()>>FRACBITS, Y()>>FRACBITS,
ldef->dx == 0? "vertical" : ldef->dy == 0? "horizontal" : "diagonal",
ldef-lines, FIXED2FLOAT(distance));
ldef-lines, FIXED2DBL(distance));
angle_t finean = R_PointToAngle2 (0, 0, ldef->dx, ldef->dy);
if (ldef->backsector != NULL && ldef->backsector == ssec->sector)
{

View file

@ -6507,7 +6507,7 @@ DDropItem *AActor::GetDropItems() const
fixed_t AActor::GetGravity() const
{
if (flags & MF_NOGRAVITY) return 0;
return fixed_t(level.gravity * Sector->gravity * FIXED2FLOAT(gravity) * 81.92);
return fixed_t(level.gravity * Sector->gravity * FIXED2DBL(gravity) * 81.92);
}
// killough 11/98:
@ -6631,13 +6631,13 @@ void PrintMiscActorInfo(AActor *query)
for (flagi = 0; flagi <= 31; flagi++)
if (query->flags7 & ActorFlags7::FromInt(1<<flagi)) Printf(" %s", FLAG_NAME(1<<flagi, flags7));
Printf("\nBounce flags: %x\nBounce factors: f:%f, w:%f",
query->BounceFlags.GetValue(), FIXED2FLOAT(query->bouncefactor),
FIXED2FLOAT(query->wallbouncefactor));
query->BounceFlags.GetValue(), FIXED2DBL(query->bouncefactor),
FIXED2DBL(query->wallbouncefactor));
/*for (flagi = 0; flagi < 31; flagi++)
if (query->BounceFlags & 1<<flagi) Printf(" %s", flagnamesb[flagi]);*/
Printf("\nRender style = %i:%s, alpha %f\nRender flags: %x",
querystyle, (querystyle < STYLE_Count ? renderstyles[querystyle] : "Unknown"),
FIXED2FLOAT(query->alpha), query->renderflags.GetValue());
FIXED2DBL(query->alpha), query->renderflags.GetValue());
/*for (flagi = 0; flagi < 31; flagi++)
if (query->renderflags & 1<<flagi) Printf(" %s", flagnamesr[flagi]);*/
Printf("\nSpecial+args: %s(%i, %i, %i, %i, %i)\nspecial1: %i, special2: %i.",
@ -6646,10 +6646,10 @@ void PrintMiscActorInfo(AActor *query)
query->args[4], query->special1, query->special2);
Printf("\nTID: %d", query->tid);
Printf("\nCoord= x: %f, y: %f, z:%f, floor:%f, ceiling:%f.",
FIXED2FLOAT(query->X()), FIXED2FLOAT(query->Y()), FIXED2FLOAT(query->Z()),
FIXED2FLOAT(query->floorz), FIXED2FLOAT(query->ceilingz));
FIXED2DBL(query->X()), FIXED2DBL(query->Y()), FIXED2DBL(query->Z()),
FIXED2DBL(query->floorz), FIXED2DBL(query->ceilingz));
Printf("\nSpeed= %f, velocity= x:%f, y:%f, z:%f, combined:%f.\n",
FIXED2FLOAT(query->Speed), FIXED2FLOAT(query->velx), FIXED2FLOAT(query->vely), FIXED2FLOAT(query->velz),
sqrt(pow(FIXED2FLOAT(query->velx), 2) + pow(FIXED2FLOAT(query->vely), 2) + pow(FIXED2FLOAT(query->velz), 2)));
FIXED2DBL(query->Speed), FIXED2DBL(query->velx), FIXED2DBL(query->vely), FIXED2DBL(query->velz),
sqrt(pow(FIXED2DBL(query->velx), 2) + pow(FIXED2DBL(query->vely), 2) + pow(FIXED2DBL(query->velz), 2)));
}
}

View file

@ -714,15 +714,15 @@ void R_EnterPortal (PortalDrawseg* pds, int depth)
{ // any mirror--use floats to avoid integer overflow
vertex_t *v2 = pds->src->v2;
float dx = FIXED2FLOAT(v2->x - v1->x);
float dy = FIXED2FLOAT(v2->y - v1->y);
float x1 = FIXED2FLOAT(v1->x);
float y1 = FIXED2FLOAT(v1->y);
float x = FIXED2FLOAT(startx);
float y = FIXED2FLOAT(starty);
double dx = FIXED2DBL(v2->x - v1->x);
double dy = FIXED2DBL(v2->y - v1->y);
double x1 = FIXED2DBL(v1->x);
double y1 = FIXED2DBL(v1->y);
double x = FIXED2DBL(startx);
double y = FIXED2DBL(starty);
// the above two cases catch len == 0
float r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy);
double r = ((x - x1)*dx + (y - y1)*dy) / (dx*dx + dy*dy);
viewx = FLOAT2FIXED((x1 + r * dx)*2 - x);
viewy = FLOAT2FIXED((y1 + r * dy)*2 - y);

View file

@ -1652,12 +1652,12 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
return;
}
double vx = FIXED2FLOAT(viewx);
double vy = FIXED2FLOAT(viewy);
double vz = FIXED2FLOAT(viewz);
double vx = FIXED2DBL(viewx);
double vy = FIXED2DBL(viewy);
double vz = FIXED2DBL(viewz);
lxscale = FIXED2FLOAT(pl->xscale) * ifloatpow2[ds_xbits];
lyscale = FIXED2FLOAT(pl->yscale) * ifloatpow2[ds_ybits];
lxscale = FIXED2DBL(pl->xscale) * ifloatpow2[ds_xbits];
lyscale = FIXED2DBL(pl->yscale) * ifloatpow2[ds_ybits];
xscale = 64.f / lxscale;
yscale = 64.f / lyscale;
zeroheight = pl->height.ZatPoint(vx, vy);

View file

@ -1631,8 +1631,8 @@ void R_DrawRemainingPlayerSprites()
screen->DrawTexture(vis->pic,
viewwindowx + VisPSpritesX1[i],
viewwindowy + viewheight/2 - (vis->texturemid / 65536.0) * (vis->yscale / 65536.0) - 0.5,
DTA_DestWidthF, FIXED2FLOAT(vis->pic->GetWidth() * vis->xscale),
DTA_DestHeightF, FIXED2FLOAT(vis->pic->GetHeight() * vis->yscale),
DTA_DestWidthF, FIXED2DBL(vis->pic->GetWidth() * vis->xscale),
DTA_DestHeightF, FIXED2DBL(vis->pic->GetHeight() * vis->yscale),
DTA_Translation, TranslationToTable(vis->Translation),
DTA_FlipX, flip,
DTA_TopOffset, 0,

View file

@ -63,10 +63,6 @@
#define O_BINARY 0
#endif
#ifndef FIXED2FLOAT
#define FIXED2FLOAT(f) (((float)(f))/(float)65536)
#endif
#define NORM_PITCH 128
#define NORM_PRIORITY 64
#define NORM_SEP 0

View file

@ -781,10 +781,10 @@ void DCanvas::VirtualToRealCoordsFixed(fixed_t &x, fixed_t &y, fixed_t &w, fixed
{
double dx, dy, dw, dh;
dx = FIXED2FLOAT(x);
dy = FIXED2FLOAT(y);
dw = FIXED2FLOAT(w);
dh = FIXED2FLOAT(h);
dx = FIXED2DBL(x);
dy = FIXED2DBL(y);
dw = FIXED2DBL(w);
dh = FIXED2DBL(h);
VirtualToRealCoords(dx, dy, dw, dh, vwidth, vheight, vbottom, handleaspect);
x = FLOAT2FIXED(dx);
y = FLOAT2FIXED(dy);
@ -1184,8 +1184,8 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
return;
}
scalex /= FIXED2FLOAT(tex->xScale);
scaley /= FIXED2FLOAT(tex->yScale);
scalex /= FIXED2DBL(tex->xScale);
scaley /= FIXED2DBL(tex->yScale);
cosrot = cos(rot);
sinrot = sin(rot);