- Because entryway timed it, here is a new version of R_PointToAngle2 that is

closer to the original. The old code was shorter but a little slower. The
  new code is a bit faster than the original with VC++ and about the same
  with GCC. Interestingly, GCC produces code for Killough's version that
  performs about the same as the original, but when compiled with VC++,
  Killough's is notably worse.


SVN r1813 (trunk)
This commit is contained in:
Randy Heit 2009-09-08 23:48:34 +00:00
parent 93166b86b3
commit 12576d2eb5
3 changed files with 43 additions and 38 deletions

View file

@ -1,3 +1,11 @@
September 8, 2009
- Because entryway timed it, here is a new version of R_PointToAngle2 that is
closer to the original. The old code was shorter but a little slower. The
new code is a bit faster than the original with VC++ and about the same
with GCC. Interestingly, GCC produces code for Killough's version that
performs about the same as the original, but when compiled with VC++,
Killough's is notably worse.
September 8, 2009 (Changes by Graf Zahl)
- moved ENDOOM lump name definition into gameinfo.
- moved default item drop style into gameinfo.

View file

@ -221,6 +221,27 @@ static bool NoInterpolateView;
// CODE --------------------------------------------------------------------
//==========================================================================
//
// SlopeDiv
//
// Utility function, called by R_PointToAngle.
//
//==========================================================================
angle_t SlopeDiv (unsigned int num, unsigned den)
{
unsigned int ans;
if (den < 512)
return (ANG45 - 1); //tantoangle[SLOPERANGE]
ans = (num << 3) / (den >> 8);
return ans <= SLOPERANGE ? tantoangle[ans] : (ANG45 - 1);
}
//==========================================================================
//
// R_PointToAngle
@ -242,65 +263,56 @@ angle_t R_PointToAngle2 (fixed_t x1, fixed_t y1, fixed_t x, fixed_t y)
return 0;
}
fixed_t ax = abs (x);
fixed_t ay = abs (y);
int div;
angle_t angle;
if (ax > ay)
{
swap (ax, ay);
}
div = SlopeDiv (ax, ay);
angle = tantoangle[div];
if (x >= 0)
{
if (y >= 0)
{
if (x > y)
{ // octant 0
return angle;
return SlopeDiv(y, x);
}
else
{ // octant 1
return ANG90 - 1 - angle;
return ANG90 - 1 - SlopeDiv(x, y);
}
}
else // y < 0
{
if (x > -y)
y = -y;
if (x > y)
{ // octant 8
return (angle_t)-(SDWORD)angle;
return 0 - SlopeDiv(y, x);
}
else
{ // octant 7
return ANG270 + angle;
return ANG270 + SlopeDiv(x, y);
}
}
}
else // x < 0
{
x = -x;
if (y >= 0)
{
if (-x > y)
if (x > y)
{ // octant 3
return ANG180 - 1 - angle;
return ANG180 - 1 - SlopeDiv(y, x);
}
else
{ // octant 2
return ANG90 + angle;
return ANG90 + SlopeDiv(x, y);
}
}
else // y < 0
{
if (x < y)
y = -y;
if (x > y)
{ // octant 4
return ANG180 + angle;
return ANG180 + SlopeDiv(y, x);
}
else
{ // octant 5
return ANG270 - 1 - angle;
return ANG270 - 1 - SlopeDiv(x, y);
}
}
}

View file

@ -105,21 +105,6 @@ inline angle_t abs (angle_t ang)
// without additional checking.
extern angle_t tantoangle[SLOPERANGE+1];
// Utility function,
// called by R_PointToAngle.
inline int SlopeDiv (unsigned int num, unsigned den)
{
unsigned int ans;
if (den < 512)
return SLOPERANGE;
ans = (num << 3) / (den >> 8);
return ans <= SLOPERANGE ? ans : SLOPERANGE;
}
inline double bam2rad(angle_t ang)
{
return double(ang >> 1) * (PI / ANGLE_90);