- floatified p_trace, p_slopes and p_udmf.cpp.

- major cleanup of unused code.
This commit is contained in:
Christoph Oelckers 2016-03-30 16:30:22 +02:00
parent ced30e7bbb
commit 66929cbaff
35 changed files with 350 additions and 529 deletions

View file

@ -850,11 +850,7 @@ public:
return VecToAngle(otherpos - Pos().XY());
}
DAngle AngleTo(AActor *other, fixed_t oxofs, fixed_t oyofs, bool absolute = false) const
{
fixedvec3 otherpos = absolute ? other->_f_Pos() : other->_f_PosRelative(this);
return VecToAngle(otherpos.x + oxofs - _f_X(), otherpos.y + oyofs - _f_Y());
}
DAngle AngleTo(AActor *other, fixed_t oxofs, fixed_t oyofs, bool absolute = false) const = delete;
DAngle AngleTo(AActor *other, double oxofs, double oyofs, bool absolute = false) const
{
@ -1008,12 +1004,6 @@ public:
double Speed;
double FloatSpeed;
// intentionally stange names so that searching for them is easier.
angle_t _f_angle() { return FLOAT2ANGLE(Angles.Yaw.Degrees); }
int _f_pitch() { return FLOAT2ANGLE(Angles.Pitch.Degrees); }
fixed_t _f_speed() { return FLOAT2FIXED(Speed); }
WORD sprite; // used to find patch_t and flip value
BYTE frame; // sprite frame to draw
DVector2 Scale; // Scaling values; 1 is normal size
@ -1310,11 +1300,6 @@ public:
return fabs(Z() - checkz) < Z_Epsilon;
}
fixedvec3 _f_PosRelative(int grp) const;
fixedvec3 _f_PosRelative(const AActor *other) const;
fixedvec3 _f_PosRelative(sector_t *sec) const;
fixedvec3 _f_PosRelative(line_t *line) const;
DVector3 PosRelative(int grp) const;
DVector3 PosRelative(const AActor *other) const;
DVector3 PosRelative(sector_t *sec) const;

View file

@ -2533,8 +2533,8 @@ void AM_rotate(double *xp, double *yp, DAngle a)
if (angle_saved != a)
{
angle_saved = a;
sinrot = sin(ToRadians(a));
cosrot = cos(ToRadians(a));
sinrot = sin(a.Radians());
cosrot = cos(a.Radians());
}
double x = *xp;

View file

@ -350,7 +350,7 @@ void DBot::Pitch (AActor *target)
diff = target->Z() - player->mo->Z();
aim = g_atan(diff / player->mo->Distance2D(target));
player->mo->Angles.Pitch = ToDegrees(aim);
player->mo->Angles.Pitch = DAngle::ToDegrees(aim);
}
//Checks if a sector is dangerous.

View file

@ -1244,9 +1244,9 @@ CCMD(angleconvtest)
Printf("Testing degrees to angle conversion:\n");
for (double ang = -5 * 180.; ang < 5 * 180.; ang += 45.)
{
angle_t ang1 = FLOAT2ANGLE(ang);
angle_t ang2 = (angle_t)(ang * (ANGLE_90 / 90.));
angle_t ang3 = (angle_t)(int)(ang * (ANGLE_90 / 90.));
unsigned ang1 = DAngle(ang).BAMs();
unsigned ang2 = (unsigned)(ang * (0x40000000 / 90.));
unsigned ang3 = (unsigned)(int)(ang * (0x40000000 / 90.));
Printf("Angle = %.5f: xs_RoundToInt = %08x, unsigned cast = %08x, signed cast = %08x\n",
ang, ang1, ang2, ang3);
}

View file

@ -435,10 +435,6 @@ struct FPlayerStart
angle(mthing->angle),
type(pnum)
{ }
fixed_t _f_X() { return FLOAT2FIXED(pos.X); }
fixed_t _f_Y() { return FLOAT2FIXED(pos.Y); }
fixed_t _f_Z() { return FLOAT2FIXED(pos.Z); }
};
// Player spawn spots for deathmatch.
extern TArray<FPlayerStart> deathmatchstarts;

View file

@ -269,12 +269,13 @@ bool wipe_doBurn (int ticks)
}
// Draw the screen
fixed_t xstep, ystep, firex, firey;
int xstep, ystep, firex, firey;
int x, y;
BYTE *to, *fromold, *fromnew;
const int SHIFT = 16;
xstep = (FIREWIDTH * FRACUNIT) / SCREENWIDTH;
ystep = (FIREHEIGHT * FRACUNIT) / SCREENHEIGHT;
xstep = (FIREWIDTH << SHIFT) / SCREENWIDTH;
ystep = (FIREHEIGHT << SHIFT) / SCREENHEIGHT;
to = screen->GetBuffer();
fromold = (BYTE *)wipe_scr_start;
fromnew = (BYTE *)wipe_scr_end;
@ -285,7 +286,7 @@ bool wipe_doBurn (int ticks)
{
int fglevel;
fglevel = burnarray[(firex>>FRACBITS)+(firey>>FRACBITS)*FIREWIDTH] / 2;
fglevel = burnarray[(firex>>SHIFT)+(firey>>SHIFT)*FIREWIDTH] / 2;
if (fglevel >= 63)
{
to[x] = fromnew[x];
@ -340,7 +341,7 @@ bool wipe_doFade (int ticks)
else
{
int x, y;
fixed_t bglevel = 64 - fade;
int bglevel = 64 - fade;
DWORD *fg2rgb = Col2RGB8[fade];
DWORD *bg2rgb = Col2RGB8[bglevel];
BYTE *fromnew = (BYTE *)wipe_scr_end;

View file

@ -136,17 +136,30 @@ inline SDWORD ModDiv (SDWORD num, SDWORD den, SDWORD *dmval)
return num % den;
}
inline fixed_t FloatToFixed(double f)
{
return xs_Fix<16>::ToFix(f);
}
#define FLOAT2FIXED(f) ((fixed_t)xs_Fix<16>::ToFix(f))
#define FIXED2FLOAT(f) ((f) / float(65536))
#define FIXED2DBL(f) ((f) / double(65536))
inline double FixedToFloat(fixed_t f)
{
return f / 65536.;
}
#define ANGLE2DBL(f) ((f) * (90./ANGLE_90))
#define ANGLE2FLOAT(f) (float((f) * (90./ANGLE_90)))
#define FLOAT2ANGLE(f) ((angle_t)xs_CRoundToInt((f) * (ANGLE_90/90.)))
inline unsigned FloatToAngle(double f)
{
return xs_CRoundToInt((f)* (0x40000000 / 90.));
}
#define ANGLE2RAD(f) ((f) * (M_PI/ANGLE_180))
#define ANGLE2RADF(f) ((f) * float(M_PI/ANGLE_180))
#define RAD2ANGLE(f) ((angle_t)xs_CRoundToInt((f) * (ANGLE_180/M_PI)))
inline double AngleToFloat(unsigned f)
{
return f * (90. / 0x40000000);
}
#define FLOAT2FIXED(f) FloatToFixed(f)
#define FIXED2FLOAT(f) float(FixedToFloat(f))
#define FIXED2DBL(f) FixedToFloat(f)
#define ANGLE2DBL(f) AngleToFloat(f)
#endif

View file

@ -4949,7 +4949,7 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
return GetUDMFInt(UDMF_Line, LineFromID(args[0]), FBehavior::StaticLookupString(args[1]));
case ACSF_GetLineUDMFFixed:
return GetUDMFFixed(UDMF_Line, LineFromID(args[0]), FBehavior::StaticLookupString(args[1]));
return DoubleToACS(GetUDMFFloat(UDMF_Line, LineFromID(args[0]), FBehavior::StaticLookupString(args[1])));
case ACSF_GetThingUDMFInt:
case ACSF_GetThingUDMFFixed:
@ -4959,13 +4959,13 @@ int DLevelScript::CallFunction(int argCount, int funcIndex, SDWORD *args)
return GetUDMFInt(UDMF_Sector, P_FindFirstSectorFromTag(args[0]), FBehavior::StaticLookupString(args[1]));
case ACSF_GetSectorUDMFFixed:
return GetUDMFFixed(UDMF_Sector, P_FindFirstSectorFromTag(args[0]), FBehavior::StaticLookupString(args[1]));
return DoubleToACS(GetUDMFFloat(UDMF_Sector, P_FindFirstSectorFromTag(args[0]), FBehavior::StaticLookupString(args[1])));
case ACSF_GetSideUDMFInt:
return GetUDMFInt(UDMF_Side, SideFromID(args[0], args[1]), FBehavior::StaticLookupString(args[2]));
case ACSF_GetSideUDMFFixed:
return GetUDMFFixed(UDMF_Side, SideFromID(args[0], args[1]), FBehavior::StaticLookupString(args[2]));
return DoubleToACS(GetUDMFFloat(UDMF_Side, SideFromID(args[0], args[1]), FBehavior::StaticLookupString(args[2])));
case ACSF_GetActorVelX:
actor = SingleActorFromTID(args[0], activator);

View file

@ -883,9 +883,9 @@ void P_DisconnectEffect (AActor *actor)
break;
fixed_t xo = ((M_Random() - 128) << 9) * (actor->_f_radius() >> FRACBITS);
fixed_t yo = ((M_Random() - 128) << 9) * (actor->_f_radius() >> FRACBITS);
fixed_t zo = (M_Random() << 8) * (actor->_f_height() >> FRACBITS);
fixed_t xo = ((M_Random() - 128) << 9) * int(actor->radius);
fixed_t yo = ((M_Random() - 128) << 9) * int(actor->radius);
fixed_t zo = (M_Random() << 8) * int(actor->Height);
fixedvec3 pos = actor->Vec3Offset(xo, yo, zo);
p->x = pos.x;
p->y = pos.y;

View file

@ -2874,7 +2874,7 @@ void A_Face(AActor *self, AActor *other, DAngle max_turn, DAngle max_pitch, DAng
double dist_z = target_z - source_z;
double ddist = g_sqrt(dist.X*dist.X + dist.Y*dist.Y + dist_z*dist_z);
DAngle other_pitch = DAngle(ToDegrees(g_asin(dist_z / ddist))).Normalized180();
DAngle other_pitch = DAngle::ToDegrees(g_asin(dist_z / ddist)).Normalized180();
if (max_pitch != 0)
{

View file

@ -293,10 +293,7 @@ enum
void P_FindFloorCeiling (AActor *actor, int flags=0);
bool P_ChangeSector (sector_t* sector, int crunch, double amt, int floorOrCeil, bool isreset);
inline bool P_ChangeSector(sector_t* sector, int crunch, int amt, int floorOrCeil, bool isreset)
{
return P_ChangeSector(sector, crunch, FIXED2DBL(amt), floorOrCeil, isreset);
}
inline bool P_ChangeSector(sector_t* sector, int crunch, int amt, int floorOrCeil, bool isreset) = delete;
DAngle P_AimLineAttack(AActor *t1, DAngle angle, double distance, FTranslatedLineTarget *pLineTarget = NULL, DAngle vrange = 0., int flags = 0, AActor *target = NULL, AActor *friender = NULL);
@ -328,11 +325,7 @@ void P_TraceBleed(int damage, FTranslatedLineTarget *t, AActor *puff); // hitsc
void P_TraceBleed (int damage, AActor *target); // random direction version
bool P_HitFloor (AActor *thing);
bool P_HitWater (AActor *thing, sector_t *sec, const DVector3 &pos, bool checkabove = false, bool alert = true, bool force = false);
inline bool P_HitWater(AActor *thing, sector_t *sec, const fixedvec3 &pos, bool checkabove = false, bool alert = true, bool force = false)
{
DVector3 fpos(FIXED2DBL(pos.x), FIXED2DBL(pos.y), FIXED2DBL(pos.z));
return P_HitWater(thing, sec, fpos, checkabove, alert, force);
}
inline bool P_HitWater(AActor *thing, sector_t *sec, const fixedvec3 &pos, bool checkabove = false, bool alert = true, bool force = false) = delete;
void P_CheckSplash(AActor *self, double distance);
struct FRailParams
@ -396,14 +389,7 @@ bool Check_Sides(AActor *, int, int); // phares
// [RH]
const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move);
inline const secplane_t * P_CheckSlopeWalk(AActor *actor, fixed_t &xmove, fixed_t &ymove)
{
DVector2 move = { FIXED2DBL(xmove), FIXED2DBL(ymove) };
const secplane_t *ret = P_CheckSlopeWalk(actor, move);
xmove = FLOAT2FIXED(move.X);
ymove = FLOAT2FIXED(move.Y);
return ret;
}
inline const secplane_t * P_CheckSlopeWalk(AActor *actor, fixed_t &xmove, fixed_t &ymove) = delete;
//
// P_SETUP

View file

@ -4411,7 +4411,7 @@ void P_TraceBleed(int damage, AActor *target, AActor *missile)
double aim;
aim = g_atan(missile->Vel.Z / target->Distance2D(missile));
pitch = -ToDegrees(aim);
pitch = -DAngle::ToDegrees(aim);
}
else
{

View file

@ -427,7 +427,7 @@ bool AActor::FixMapthingPos()
DPrintf("%s at (%f,%f) lies on %s line %td, distance = %f\n",
this->GetClass()->TypeName.GetChars(), X(), Y(),
ldef->Delta().X == 0 ? "vertical" : ldef->Delta().Y == 0 ? "horizontal" : "diagonal",
ldef - lines, FIXED2DBL(distance));
ldef - lines, distance);
DAngle ang = ldef->Delta().Angle();
if (ldef->backsector != NULL && ldef->backsector == secstart)
{
@ -519,7 +519,8 @@ void AActor::LinkToWorld(bool spawningmapthing, sector_t *sector)
for (int i = -1; i < (int)check.Size(); i++)
{
fixedvec3 pos = i==-1? _f_Pos() : _f_PosRelative(check[i]);
DVector3 _pos = i==-1? Pos() : PosRelative(check[i]);
fixedvec3 pos = { FLOAT2FIXED(_pos.X), FLOAT2FIXED(_pos.Y),FLOAT2FIXED(_pos.Z) };
int x1 = GetSafeBlockX(pos.x - _f_radius() - bmaporgx);
int x2 = GetSafeBlockX(pos.x + _f_radius() - bmaporgx);

View file

@ -119,7 +119,7 @@ void P_TranslateLineDef (line_t *ld, maplinedef_t *mld, int lineindexforid = -1)
int P_TranslateSectorSpecial (int);
int GetUDMFInt(int type, int index, const char *key);
fixed_t GetUDMFFixed(int type, int index, const char *key);
double GetUDMFFloat(int type, int index, const char *key);
bool P_LoadGLNodes(MapData * map);
bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime);

View file

@ -45,7 +45,7 @@
//
//===========================================================================
static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, bool slopeCeil)
static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil)
{
int linenum;
@ -56,7 +56,7 @@ static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, boo
sector_t *sec;
secplane_t *plane;
if (P_PointOnLineSidePrecise (x, y, line) == 0)
if (P_PointOnLineSidePrecise (pos, line) == 0)
{
sec = line->frontsector;
}
@ -85,15 +85,15 @@ static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, boo
v1[0] = line->Delta().X;
v1[1] = line->Delta().Y;
v1[2] = plane->ZatPoint (line->v2) - p[2];
v2[0] = FIXED2DBL (x) - p[0];
v2[1] = FIXED2DBL (y) - p[1];
v2[2] = FIXED2DBL (z) - p[2];
v2[0] = pos.X - p[0];
v2[1] = pos.Y - p[1];
v2[2] = pos.Z - p[2];
cross = v1 ^ v2;
double len = cross.Length();
if (len == 0)
{
Printf ("Slope thing at (%d,%d) lies directly on its target line.\n", int(x>>16), int(y>>16));
Printf ("Slope thing at (%f,%f) lies directly on its target line.\n", pos.X, pos.Y);
return;
}
cross /= len;
@ -103,10 +103,8 @@ static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, boo
cross = -cross;
}
plane->set(cross[0], cross[1], cross[2], 0.);
plane->setD(-TMulScale16 (plane->fixA(), x,
plane->fixB(), y,
plane->fixC(), z));
double dist = -cross[0] * pos.X - cross[1] * pos.Y - cross[2] * pos.Z;
plane->set(cross[0], cross[1], cross[2], dist);
}
}
@ -120,7 +118,6 @@ static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil)
{
sector_t *source;
int secnum;
size_t planeofs;
secnum = P_FindFirstSectorFromTag (tag);
if (secnum == -1)
@ -132,18 +129,17 @@ static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil)
if (copyCeil)
{
planeofs = myoffsetof(sector_t, ceilingplane);
dest->ceilingplane = source->ceilingplane;
}
else
{
planeofs = myoffsetof(sector_t, floorplane);
dest->floorplane = source->floorplane;
}
*(secplane_t *)((BYTE *)dest + planeofs) = *(secplane_t *)((BYTE *)source + planeofs);
}
static void P_CopyPlane (int tag, fixed_t x, fixed_t y, bool copyCeil)
static void P_CopyPlane (int tag, const DVector2 &pos, bool copyCeil)
{
sector_t *dest = P_PointInSector (x, y);
sector_t *dest = P_PointInSector (pos);
P_CopyPlane(tag, dest, copyCeil);
}
@ -153,54 +149,47 @@ static void P_CopyPlane (int tag, fixed_t x, fixed_t y, bool copyCeil)
//
//===========================================================================
void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi,
fixed_t x, fixed_t y, fixed_t z)
void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos)
{
angle_t xyang;
angle_t zang;
DAngle xyang;
DAngle zang;
if (zangi >= 180)
{
zang = ANGLE_180-ANGLE_1;
zang = 179.;
}
else if (zangi <= 0)
{
zang = ANGLE_1;
zang = 1.;
}
else
{
zang = Scale (zangi, ANGLE_90, 90);
zang = (double)zangi;
}
if (setCeil)
{
zang += ANGLE_180;
zang += 180.;
}
zang >>= ANGLETOFINESHIFT;
// Sanitize xyangi to [0,360) range
xyangi = xyangi % 360;
if (xyangi < 0)
{
xyangi = 360 + xyangi;
}
xyang = (angle_t)Scale (xyangi, ANGLE_90, 90 << ANGLETOFINESHIFT);
xyang = (double)xyangi;
DVector3 norm;
if (ib_compatflags & BCOMPATF_SETSLOPEOVERFLOW)
{
norm[0] = double(finecosine[zang] * finecosine[xyang]);
norm[1] = double(finecosine[zang] * finesine[xyang]);
// We have to consider an integer multiplication overflow here.
norm[0] = FixedToFloat(FloatToFixed(zang.Cos()) * FloatToFixed(xyang.Cos()));
norm[1] = FixedToFloat(FloatToFixed(zang.Cos()) * FloatToFixed(xyang.Sin()));
}
else
{
norm[0] = double(finecosine[zang]) * double(finecosine[xyang]);
norm[1] = double(finecosine[zang]) * double(finesine[xyang]);
norm[0] = zang.Cos() * xyang.Cos();
norm[1] = zang.Cos() * xyang.Sin();
}
norm[2] = double(finesine[zang]) * 65536.f;
norm[2] = zang.Sin();
norm.MakeUnit();
plane->set(norm[0], norm[1], norm[2], 0.);
plane->setD(-TMulScale16(plane->fixA(), x, plane->fixB(), y, plane->fixC(), z));
double dist = -norm[0] * pos.X - norm[1] * pos.Y - norm[2] * pos.Z;
plane->set(norm[0], norm[1], norm[2], dist);
}
@ -210,7 +199,7 @@ void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi,
//
//===========================================================================
void P_VavoomSlope(sector_t * sec, int id, fixed_t x, fixed_t y, fixed_t z, int which)
void P_VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which)
{
for (int i=0;i<sec->linecount;i++)
{
@ -220,21 +209,21 @@ void P_VavoomSlope(sector_t * sec, int id, fixed_t x, fixed_t y, fixed_t z, int
{
DVector3 v1, v2, cross;
secplane_t *srcplane = (which == 0) ? &sec->floorplane : &sec->ceilingplane;
fixed_t srcheight = (which == 0) ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
double srcheight = (which == 0) ? sec->GetPlaneTexZF(sector_t::floor) : sec->GetPlaneTexZF(sector_t::ceiling);
v1[0] = FIXED2DBL (x - l->v2->fixX());
v1[1] = FIXED2DBL (y - l->v2->fixY());
v1[2] = FIXED2DBL (z - srcheight);
v1[0] = pos.X - l->v2->fX();
v1[1] = pos.Y - l->v2->fY();
v1[2] = pos.Z - srcheight;
v2[0] = FIXED2DBL (x - l->v1->fixX());
v2[1] = FIXED2DBL (y - l->v1->fixY());
v2[2] = FIXED2DBL (z - srcheight);
v2[0] = pos.X - l->v1->fX();
v2[1] = pos.Y - l->v1->fY();
v2[2] = pos.Z - srcheight;
cross = v1 ^ v2;
double len = cross.Length();
if (len == 0)
{
Printf ("Slope thing at (%d,%d) lies directly on its target line.\n", int(x>>16), int(y>>16));
Printf ("Slope thing at (%f,%f) lies directly on its target line.\n", pos.X, pos.Y);
return;
}
cross /= len;
@ -245,8 +234,8 @@ void P_VavoomSlope(sector_t * sec, int id, fixed_t x, fixed_t y, fixed_t z, int
cross = -cross;
}
srcplane->set(cross[0], cross[1], cross[2], 0.);
srcplane->setD(-TMulScale16(srcplane->fixA(), x, srcplane->fixB(), y, srcplane->fixC(), z));
double dist = -cross[0] * pos.X - cross[1] * pos.Y - cross[2] * pos.Z;
srcplane->set(cross[0], cross[1], cross[2], dist);
return;
}
}
@ -337,13 +326,13 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
double *h1 = vt_heights[j].CheckKey(vi1);
double *h2 = vt_heights[j].CheckKey(vi2);
double *h3 = vt_heights[j].CheckKey(vi3);
if (h1==NULL && h2==NULL && h3==NULL) continue;
if (h1 == NULL && h2 == NULL && h3 == NULL) continue;
vt1.Z = h1? *h1 : j==0? sec->GetPlaneTexZF(sector_t::floor) : sec->GetPlaneTexZF(sector_t::ceiling);
vt2.Z = h2? *h2 : j==0? sec->GetPlaneTexZF(sector_t::floor) : sec->GetPlaneTexZF(sector_t::ceiling);
vt3.Z = h3? *h3 : j==0? sec->GetPlaneTexZF(sector_t::floor) : sec->GetPlaneTexZF(sector_t::ceiling);
if (P_PointOnLineSidePrecise(vertexes[vi3].fixX(), vertexes[vi3].fixY(), sec->lines[0]) == 0)
if (P_PointOnLineSidePrecise(vertexes[vi3].fX(), vertexes[vi3].fY(), sec->lines[0]) == 0)
{
vec1 = vt2 - vt3;
vec2 = vt1 - vt3;
@ -373,10 +362,8 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
secplane_t *plane = j==0? &sec->floorplane : &sec->ceilingplane;
plane->set(cross[0], cross[1], cross[2], 0.);
plane->setD(-TMulScale16 (plane->fixA(), vertexes[vi3].fixX(),
plane->fixB(), vertexes[vi3].fixY(),
plane->fixC(), FLOAT2FIXED(vt3.Z)));
double dist = -cross[0] * vertexes[vi3].fX() - cross[1] * vertexes[vi3].fY() - cross[2] * vt3.Z;
plane->set(cross[0], cross[1], cross[2], dist);
}
}
}
@ -415,21 +402,17 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
}
pos.Z = refplane->ZatPoint (mt->pos) + mt->pos.Z;
fixed_t x = FLOAT2FIXED(pos.X);
fixed_t y = FLOAT2FIXED(pos.Y);
fixed_t z = FLOAT2FIXED(pos.Z);
if (mt->info->Special <= SMT_SlopeCeilingPointLine)
{ // SlopeFloorPointLine and SlopCeilingPointLine
P_SlopeLineToPoint (mt->args[0], x, y, z, ceiling);
P_SlopeLineToPoint (mt->args[0], pos, ceiling);
}
else if (mt->info->Special <= SMT_SetCeilingSlope)
{ // SetFloorSlope and SetCeilingSlope
P_SetSlope (refplane, ceiling, mt->angle, mt->args[0], x, y, z);
P_SetSlope (refplane, ceiling, mt->angle, mt->args[0], pos);
}
else
{ // VavoomFloor and VavoomCeiling
P_VavoomSlope(sec, mt->thingid, x, y, FLOAT2FIXED(mt->pos.Z), ceiling);
{ // VavoomFloor and VavoomCeiling (these do not perform any sector height adjustment - z is absolute)
P_VavoomSlope(sec, mt->thingid, mt->pos, ceiling);
}
mt->EdNum = 0;
}
@ -440,7 +423,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
if (mt->info != NULL && mt->info->Type == NULL &&
(mt->info->Special == SMT_CopyFloorPlane || mt->info->Special == SMT_CopyCeilingPlane))
{
P_CopyPlane (mt->args[0], FLOAT2FIXED(mt->pos.X), FLOAT2FIXED(mt->pos.Y), mt->info->Special == SMT_CopyCeilingPlane);
P_CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane);
mt->EdNum = 0;
}
}
@ -464,7 +447,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
//
//===========================================================================
static void P_AlignPlane (sector_t *sec, line_t *line, int which)
static void P_AlignPlane(sector_t *sec, line_t *line, int which)
{
sector_t *refsec;
double bestdist;
@ -478,7 +461,7 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
// Find furthest vertex from the reference line. It, along with the two ends
// of the line, will define the plane.
bestdist = 0;
for (i = sec->linecount*2, probe = sec->lines; i > 0; i--)
for (i = sec->linecount * 2, probe = sec->lines; i > 0; i--)
{
double dist;
vertex_t *vert;
@ -487,8 +470,8 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
vert = (*probe++)->v2;
else
vert = (*probe)->v1;
dist = fabs((double(line->v1->fixY()) - vert->fixY()) * line->fixDx() -
(double(line->v1->fixX()) - vert->fixX()) * line->fixDy());
dist = fabs((line->v1->fY() - vert->fY()) * line->Delta().X -
(line->v1->fX() - vert->fX()) * line->Delta().Y);
if (dist > bestdist)
{
@ -502,21 +485,21 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
DVector3 p, v1, v2, cross;
secplane_t *srcplane;
fixed_t srcheight, destheight;
double srcheight, destheight;
srcplane = (which == 0) ? &sec->floorplane : &sec->ceilingplane;
srcheight = (which == 0) ? sec->GetPlaneTexZ(sector_t::floor) : sec->GetPlaneTexZ(sector_t::ceiling);
destheight = (which == 0) ? refsec->GetPlaneTexZ(sector_t::floor) : refsec->GetPlaneTexZ(sector_t::ceiling);
srcheight = (which == 0) ? sec->GetPlaneTexZF(sector_t::floor) : sec->GetPlaneTexZF(sector_t::ceiling);
destheight = (which == 0) ? refsec->GetPlaneTexZF(sector_t::floor) : refsec->GetPlaneTexZF(sector_t::ceiling);
p[0] = line->v1->fX();
p[1] = line->v1->fY();
p[2] = FIXED2DBL(destheight);
p[2] = destheight;
v1[0] = line->Delta().X;
v1[1] = line->Delta().Y;
v1[2] = 0;
v2[0] = refvert->fX() - line->v1->fX();
v2[1] = refvert->fY() - line->v1->fY();
v2[2] = FIXED2DBL(srcheight - destheight);
v2[2] = srcheight - destheight;
cross = (v1 ^ v2).Unit();
@ -526,10 +509,8 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
cross = -cross;
}
srcplane->set(cross[0], cross[1], cross[2], 0.);
srcplane->setD(-TMulScale16 (srcplane->fixA(), line->v1->fixX(),
srcplane->fixB(), line->v1->fixY(),
srcplane->fixC(), destheight));
double dist = -cross[0] * line->v1->fX() - cross[1] * line->v1->fY() - cross[2] * destheight;
srcplane->set(cross[0], cross[1], cross[2], dist);
}
//===========================================================================
@ -618,4 +599,3 @@ void P_CopySlopes()
}
}
}

View file

@ -49,23 +49,23 @@
struct FTraceInfo
{
fixed_t StartX, StartY, StartZ;
fixed_t Vx, Vy, Vz;
DVector3 Start;
DVector3 Vec;
ActorFlags ActorMask;
DWORD WallMask;
AActor *IgnoreThis;
FTraceResults *Results;
FTraceResults *TempResults;
sector_t *CurSector;
fixed_t MaxDist;
fixed_t EnterDist;
double MaxDist;
double EnterDist;
ETraceStatus (*TraceCallback)(FTraceResults &res, void *data);
void *TraceCallbackData;
DWORD TraceFlags;
int inshootthrough;
fixed_t startfrac;
double startfrac;
int aimdir;
fixed_t limitz;
double limitz;
// These are required for 3D-floor checking
// to create a fake sector with a floor
@ -78,8 +78,8 @@ struct FTraceInfo
bool ThingCheck(intercept_t *in);
bool TraceTraverse (int ptflags);
bool CheckPlane(const secplane_t &plane);
int EnterLinePortal(line_t *li, fixed_t frac);
void EnterSectorPortal(int position, fixed_t frac, sector_t *entersec);
int EnterLinePortal(line_t *li, double frac);
void EnterSectorPortal(int position, double frac, sector_t *entersec);
bool CheckSectorPlane(const sector_t *sector, bool checkFloor)
@ -94,8 +94,8 @@ struct FTraceInfo
void SetSourcePosition()
{
Results->SrcFromTarget = { FIXED2DBL(StartX), FIXED2DBL(StartY), FIXED2DBL(StartZ) };
Results->HitVector = { FIXED2DBL(Vx), FIXED2DBL(Vy), FIXED2DBL(Vz) };
Results->SrcFromTarget = Start;
Results->HitVector = Vec;
Results->SrcAngleFromTarget = Results->HitVector.Angle();
}
@ -111,11 +111,9 @@ static bool EditTraceResult (DWORD flags, FTraceResults &res);
//
//==========================================================================
bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
fixed_t vx, fixed_t vy, fixed_t vz, fixed_t maxDist,
ActorFlags actorMask, DWORD wallMask, AActor *ignore,
FTraceResults &res,
DWORD flags, ETraceStatus (*callback)(FTraceResults &res, void *), void *callbackdata)
bool Trace(const DVector3 &start, sector_t *sector, const DVector3 &direction, double maxDist,
ActorFlags actorMask, DWORD wallMask, AActor *ignore, FTraceResults &res, DWORD flags,
ETraceStatus(*callback)(FTraceResults &res, void *), void *callbackdata)
{
int ptflags;
FTraceInfo inf;
@ -126,12 +124,8 @@ bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
ptflags = actorMask ? PT_ADDLINES|PT_ADDTHINGS|PT_COMPATIBLE : PT_ADDLINES;
inf.StartX = x;
inf.StartY = y;
inf.StartZ = z;
inf.Vx = vx;
inf.Vy = vy;
inf.Vz = vz;
inf.Start = start;
inf.Vec = direction;
inf.ActorMask = actorMask;
inf.WallMask = wallMask;
inf.IgnoreThis = ignore;
@ -149,30 +143,6 @@ bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
inf.startfrac = 0;
memset(&res, 0, sizeof(res));
// check for overflows and clip if necessary
SQWORD xd = (SQWORD)x + ((SQWORD(vx) * SQWORD(maxDist)) >> 16);
if (xd>SQWORD(32767)*FRACUNIT)
{
inf.MaxDist = FixedDiv(FIXED_MAX - x, vx);
}
else if (xd<-SQWORD(32767)*FRACUNIT)
{
inf.MaxDist = FixedDiv(FIXED_MIN - x, vx);
}
SQWORD yd = (SQWORD)y + ((SQWORD(vy) * SQWORD(maxDist)) >> 16);
if (yd>SQWORD(32767)*FRACUNIT)
{
inf.MaxDist = FixedDiv(FIXED_MAX - y, vy);
}
else if (yd<-SQWORD(32767)*FRACUNIT)
{
inf.MaxDist = FixedDiv(FIXED_MIN - y, vy);
}
if (inf.TraceTraverse (ptflags))
{
return flags ? EditTraceResult(flags, res) : true;
@ -190,7 +160,7 @@ bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
//
//============================================================================
void FTraceInfo::EnterSectorPortal(int position, fixed_t frac, sector_t *entersec)
void FTraceInfo::EnterSectorPortal(int position, double frac, sector_t *entersec)
{
if (aimdir != -1 && aimdir != position) return;
AActor *portal = entersec->SkyBoxes[position];
@ -203,24 +173,19 @@ void FTraceInfo::EnterSectorPortal(int position, fixed_t frac, sector_t *enterse
memset(&results, 0, sizeof(results));
newtrace.StartX = StartX + FLOAT2FIXED(portal->Scale.X);
newtrace.StartY = StartY + FLOAT2FIXED(portal->Scale.Y);
newtrace.StartZ = StartZ;
newtrace.Start += portal->Scale;
frac += FixedDiv(FRACUNIT, MaxDist);
fixed_t enterdist = FixedMul(MaxDist, frac);
fixed_t enterX = newtrace.StartX + FixedMul(enterdist, Vx);
fixed_t enterY = newtrace.StartY + FixedMul(enterdist, Vy);
frac += 1 / MaxDist;
double enterdist = MaxDist * frac;
DVector2 enter = newtrace.Start.XY() + enterdist * Vec.XY();
newtrace.Vx = Vx;
newtrace.Vy = Vy;
newtrace.Vz = Vz;
newtrace.Vec = Vec;
newtrace.ActorMask = ActorMask;
newtrace.WallMask = WallMask;
newtrace.IgnoreThis = IgnoreThis;
newtrace.Results = &results;
newtrace.TempResults = TempResults;
newtrace.CurSector = P_PointInSector(enterX ,enterY);
newtrace.CurSector = P_PointInSector(enter);
newtrace.MaxDist = MaxDist;
newtrace.EnterDist = EnterDist;
newtrace.TraceCallback = TraceCallback;
@ -229,7 +194,7 @@ void FTraceInfo::EnterSectorPortal(int position, fixed_t frac, sector_t *enterse
newtrace.inshootthrough = true;
newtrace.startfrac = frac;
newtrace.aimdir = position;
newtrace.limitz = FLOAT2FIXED(portal->specialf1);
newtrace.limitz = portal->specialf1;
newtrace.sectorsel = 0;
if (newtrace.TraceTraverse(ActorMask ? PT_ADDLINES | PT_ADDTHINGS | PT_COMPATIBLE : PT_ADDLINES))
@ -244,7 +209,7 @@ void FTraceInfo::EnterSectorPortal(int position, fixed_t frac, sector_t *enterse
//
//============================================================================
int FTraceInfo::EnterLinePortal(line_t *li, fixed_t frac)
int FTraceInfo::EnterLinePortal(line_t *li, double frac)
{
FLinePortal *port = li->getPortal();
@ -253,28 +218,23 @@ int FTraceInfo::EnterLinePortal(line_t *li, fixed_t frac)
FTraceInfo newtrace;
newtrace.StartX = StartX;
newtrace.StartY = StartY;
newtrace.StartZ = StartZ;
newtrace.Vx = Vx;
newtrace.Vy = Vy;
newtrace.Vz = Vz;
newtrace.Start = Start;
newtrace.Vec = Vec;
P_TranslatePortalXY(li, newtrace.StartX, newtrace.StartY);
P_TranslatePortalZ(li, newtrace.StartZ);
P_TranslatePortalVXVY(li, newtrace.Vx, newtrace.Vy);
P_TranslatePortalXY(li, newtrace.Start.X, newtrace.Start.Y);
P_TranslatePortalZ(li, newtrace.Start.Z);
P_TranslatePortalVXVY(li, newtrace.Vec.X, newtrace.Vec.Y);
frac += FixedDiv(FRACUNIT, MaxDist);
fixed_t enterdist = FixedMul(MaxDist, frac);
fixed_t enterX = newtrace.StartX + FixedMul(enterdist, Vx);
fixed_t enterY = newtrace.StartY + FixedMul(enterdist, Vy);
frac += 1 / MaxDist;
double enterdist = MaxDist / frac;
DVector2 enter = newtrace.Start.XY() + enterdist * Vec.XY();
newtrace.ActorMask = ActorMask;
newtrace.WallMask = WallMask;
newtrace.IgnoreThis = IgnoreThis;
newtrace.Results = Results;
newtrace.TempResults = TempResults;
newtrace.CurSector = P_PointInSector(enterX, enterY);
newtrace.CurSector = P_PointInSector(enter);
newtrace.MaxDist = MaxDist;
newtrace.EnterDist = EnterDist;
newtrace.TraceCallback = TraceCallback;
@ -306,14 +266,12 @@ void FTraceInfo::Setup3DFloors()
CurSector = &DummySector[0];
sectorsel = 1;
fixed_t sdist = FixedMul(MaxDist, startfrac);
fixed_t x = StartX + FixedMul(Vx, sdist);
fixed_t y = StartY + FixedMul(Vy, sdist);
fixed_t z = StartZ + FixedMul(Vz, sdist);
double sdist = MaxDist * startfrac;
DVector3 pos = Start + Vec * sdist;
fixed_t bf = CurSector->floorplane.ZatPoint(x, y);
fixed_t bc = CurSector->ceilingplane.ZatPoint(x, y);
double bf = CurSector->floorplane.ZatPoint(pos);
double bc = CurSector->ceilingplane.ZatPoint(pos);
for (auto rover : ff)
{
@ -331,10 +289,10 @@ void FTraceInfo::Setup3DFloors()
if (!(rover->flags&FF_SHOOTTHROUGH))
{
fixed_t ff_bottom = rover->bottom.plane->ZatPoint(x, y);
fixed_t ff_top = rover->top.plane->ZatPoint(x, y);
double ff_bottom = rover->bottom.plane->ZatPoint(pos);
double ff_top = rover->top.plane->ZatPoint(pos);
// clip to the part of the sector we are in
if (z > ff_top)
if (pos.Z > ff_top)
{
// above
if (bf < ff_top)
@ -345,7 +303,7 @@ void FTraceInfo::Setup3DFloors()
bf = ff_top;
}
}
else if (z < ff_bottom)
else if (pos.Z < ff_bottom)
{
//below
if (bc > ff_bottom)
@ -401,12 +359,10 @@ bool FTraceInfo::LineCheck(intercept_t *in)
int lineside;
sector_t *entersector;
fixed_t dist = FixedMul(MaxDist, in->frac);
fixed_t hitx = StartX + FixedMul(Vx, dist);
fixed_t hity = StartY + FixedMul(Vy, dist);
fixed_t hitz = StartZ + FixedMul(Vz, dist);
double dist = MaxDist * in->Frac;
DVector3 hit = Start + Vec * dist;
fixed_t ff, fc, bf = 0, bc = 0;
double ff, fc, bf = 0, bc = 0;
if (in->d.line->frontsector->sectornum == CurSector->sectornum)
{
@ -425,7 +381,7 @@ bool FTraceInfo::LineCheck(intercept_t *in)
}
else
{
lineside = P_PointOnLineSide(StartX, StartY, in->d.line);
lineside = P_PointOnLineSide(Start, in->d.line);
CurSector = lineside ? in->d.line->backsector : in->d.line->frontsector;
}
}
@ -455,20 +411,20 @@ bool FTraceInfo::LineCheck(intercept_t *in)
}
}
ff = CurSector->floorplane.ZatPoint(hitx, hity);
fc = CurSector->ceilingplane.ZatPoint(hitx, hity);
ff = CurSector->floorplane.ZatPoint(hit);
fc = CurSector->ceilingplane.ZatPoint(hit);
if (entersector != NULL)
{
bf = entersector->floorplane.ZatPoint(hitx, hity);
bc = entersector->ceilingplane.ZatPoint(hitx, hity);
bf = entersector->floorplane.ZatPoint(hit);
bc = entersector->ceilingplane.ZatPoint(hit);
}
sector_t *hsec = CurSector->GetHeightSec();
if (Results->CrossedWater == NULL &&
hsec != NULL &&
//CurSector->heightsec->waterzone &&
hitz <= hsec->floorplane.ZatPoint(hitx, hity))
hit.Z <= hsec->floorplane.ZatPoint(hit))
{
// hit crossed a water plane
if (CheckSectorPlane(hsec, true))
@ -478,7 +434,7 @@ bool FTraceInfo::LineCheck(intercept_t *in)
}
}
if (hitz <= ff)
if (hit.Z <= ff)
{
if (CurSector->PortalBlocksMovement(sector_t::floor))
{
@ -493,7 +449,7 @@ bool FTraceInfo::LineCheck(intercept_t *in)
return false;
}
}
else if (hitz >= fc)
else if (hit.Z >= fc)
{
if (CurSector->PortalBlocksMovement(sector_t::ceiling))
{
@ -510,9 +466,9 @@ bool FTraceInfo::LineCheck(intercept_t *in)
}
else if (in->d.line->isLinePortal())
{
if (entersector == NULL || (hitz >= bf && hitz <= bc))
if (entersector == NULL || (hit.Z >= bf && hit.Z <= bc))
{
int res = EnterLinePortal(in->d.line, in->frac);
int res = EnterLinePortal(in->d.line, in->Frac);
if (res != -1)
{
aimdir = INT_MAX; // flag for ending the traverse
@ -522,7 +478,7 @@ bool FTraceInfo::LineCheck(intercept_t *in)
goto normalline; // hit upper or lower tier.
}
else if (entersector == NULL ||
hitz < bf || hitz > bc ||
hit.Z < bf || hit.Z > bc ||
in->d.line->flags & WallMask)
{
normalline:
@ -530,8 +486,8 @@ normalline:
Results->HitType = TRACE_HitWall;
Results->Tier =
entersector == NULL ? TIER_Middle :
hitz <= bf ? TIER_Lower :
hitz >= bc ? TIER_Upper : TIER_Middle;
hit.Z <= bf ? TIER_Lower :
hit.Z >= bc ? TIER_Upper : TIER_Middle;
if (TraceFlags & TRACE_Impact)
{
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
@ -552,11 +508,11 @@ normalline:
if (entershootthrough != inshootthrough && rover->flags&FF_EXISTS)
{
fixed_t ff_bottom = rover->bottom.plane->ZatPoint(hitx, hity);
fixed_t ff_top = rover->top.plane->ZatPoint(hitx, hity);
double ff_bottom = rover->bottom.plane->ZatPoint(hit);
double ff_top = rover->top.plane->ZatPoint(hit);
// clip to the part of the sector we are in
if (hitz > ff_top)
if (hit.Z > ff_top)
{
// above
if (bf < ff_top)
@ -567,7 +523,7 @@ normalline:
bf = ff_top;
}
}
else if (hitz < ff_bottom)
else if (hit.Z < ff_bottom)
{
//below
if (bc > ff_bottom)
@ -631,12 +587,12 @@ cont:
}
else
{
if (hitz <= bf || hitz >= bc)
if (hit.Z <= bf || hit.Z >= bc)
{
Results->HitType = TRACE_HitWall;
Results->Tier =
hitz <= bf ? TIER_Lower :
hitz >= bc ? TIER_Upper : TIER_Middle;
hit.Z <= bf ? TIER_Lower :
hit.Z >= bc ? TIER_Upper : TIER_Middle;
}
else
{
@ -651,10 +607,10 @@ cont:
if (Results->HitType == TRACE_HitWall)
{
Results->HitPos = { FIXED2DBL(hitx), FIXED2DBL(hity), FIXED2DBL(hitz) };
Results->HitPos = hit;
SetSourcePosition();
Results->Distance = FIXED2DBL(dist);
Results->Fraction = FIXED2DBL(in->frac);
Results->Distance = dist;
Results->Fraction = in->Frac;
Results->Line = in->d.line;
Results->Side = lineside;
}
@ -692,60 +648,54 @@ cont:
bool FTraceInfo::ThingCheck(intercept_t *in)
{
fixed_t dist = FixedMul(MaxDist, in->frac);
fixed_t hitx = StartX + FixedMul(Vx, dist);
fixed_t hity = StartY + FixedMul(Vy, dist);
fixed_t hitz = StartZ + FixedMul(Vz, dist);
double dist = MaxDist * in->Frac;
DVector3 hit = Start + Vec * dist;
if (hitz > in->d.thing->_f_Top())
if (hit.Z > in->d.thing->Top())
{
// trace enters above actor
if (Vz >= 0) return true; // Going up: can't hit
if (Vec.Z >= 0) return true; // Going up: can't hit
// Does it hit the top of the actor?
dist = FixedDiv(in->d.thing->_f_Top() - StartZ, Vz);
dist = (in->d.thing->Top() - Start.Z) / Vec.Z;
if (dist > MaxDist) return true;
in->frac = FixedDiv(dist, MaxDist);
in->Frac = dist / MaxDist;
hitx = StartX + FixedMul(Vx, dist);
hity = StartY + FixedMul(Vy, dist);
hitz = StartZ + FixedMul(Vz, dist);
hit = Start + Vec * dist;
// calculated coordinate is outside the actor's bounding box
if (abs(hitx - in->d.thing->_f_X()) > in->d.thing->_f_radius() ||
abs(hity - in->d.thing->_f_Y()) > in->d.thing->_f_radius()) return true;
if (fabs(hit.X - in->d.thing->X()) > in->d.thing->radius ||
fabs(hit.Y - in->d.thing->Y()) > in->d.thing->radius) return true;
}
else if (hitz < in->d.thing->_f_Z())
else if (hit.Z < in->d.thing->Z())
{ // trace enters below actor
if (Vz <= 0) return true; // Going down: can't hit
if (Vec.Z <= 0) return true; // Going down: can't hit
// Does it hit the bottom of the actor?
dist = FixedDiv(in->d.thing->_f_Z() - StartZ, Vz);
dist = (in->d.thing->Z() - Start.Z) / Vec.Z;
if (dist > MaxDist) return true;
in->frac = FixedDiv(dist, MaxDist);
in->Frac = dist / MaxDist;
hitx = StartX + FixedMul(Vx, dist);
hity = StartY + FixedMul(Vy, dist);
hitz = StartZ + FixedMul(Vz, dist);
hit = Start + Vec * dist;
// calculated coordinate is outside the actor's bounding box
if (abs(hitx - in->d.thing->_f_X()) > in->d.thing->_f_radius() ||
abs(hity - in->d.thing->_f_Y()) > in->d.thing->_f_radius()) return true;
if (fabs(hit.X - in->d.thing->X()) > in->d.thing->radius ||
fabs(hit.Y - in->d.thing->Y()) > in->d.thing->radius) return true;
}
if (CurSector->e->XFloor.ffloors.Size())
{
// check for 3D floor hits first.
fixed_t ff_floor = CurSector->floorplane.ZatPoint(hitx, hity);
fixed_t ff_ceiling = CurSector->ceilingplane.ZatPoint(hitx, hity);
double ff_floor = CurSector->floorplane.ZatPoint(hit);
double ff_ceiling = CurSector->ceilingplane.ZatPoint(hit);
if (hitz > ff_ceiling && CurSector->PortalBlocksMovement(sector_t::ceiling)) // actor is hit above the current ceiling
if (hit.Z > ff_ceiling && CurSector->PortalBlocksMovement(sector_t::ceiling)) // actor is hit above the current ceiling
{
Results->HitType = TRACE_HitCeiling;
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
}
else if (hitz < ff_floor && CurSector->PortalBlocksMovement(sector_t::floor)) // actor is hit below the current floor
else if (hit.Z < ff_floor && CurSector->PortalBlocksMovement(sector_t::floor)) // actor is hit below the current floor
{
Results->HitType = TRACE_HitFloor;
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
@ -778,10 +728,10 @@ cont1:
Results->HitType = TRACE_HitActor;
Results->HitPos = { FIXED2DBL(hitx), FIXED2DBL(hity), FIXED2DBL(hitz) };
Results->HitPos = hit;
SetSourcePosition();
Results->Distance = FIXED2DBL(dist);
Results->Fraction = FIXED2DBL(in->frac);
Results->Distance = dist;
Results->Fraction = in->Frac;
Results->Actor = in->d.thing;
if (TraceCallback != NULL)
@ -811,7 +761,7 @@ bool FTraceInfo::TraceTraverse (int ptflags)
// Do a 3D floor check in the starting sector
Setup3DFloors();
FPathTraverse it(StartX, StartY, FixedMul (Vx, MaxDist), FixedMul (Vy, MaxDist), ptflags | PT_DELTA, startfrac);
FPathTraverse it(Start.X, Start.Y, Vec.X * MaxDist, Vec.Y * MaxDist, ptflags | PT_DELTA, startfrac);
intercept_t *in;
int lastsplashsector = -1;
@ -911,12 +861,9 @@ bool FTraceInfo::TraceTraverse (int ptflags)
}
if (Results->HitType == TRACE_HitNone && Results->Distance == 0)
{
Results->HitPos = {
FIXED2DBL(StartX + FixedMul(Vx, MaxDist)),
FIXED2DBL(StartY + FixedMul(Vy, MaxDist)),
FIXED2DBL(StartZ + FixedMul(Vz, MaxDist)) };
Results->HitPos = Start + Vec * MaxDist;
SetSourcePosition();
Results->Distance = FIXED2DBL(MaxDist);
Results->Distance = MaxDist;
Results->Fraction = 1.;
}
return Results->HitType != TRACE_HitNone;
@ -930,25 +877,20 @@ bool FTraceInfo::TraceTraverse (int ptflags)
bool FTraceInfo::CheckPlane (const secplane_t &plane)
{
fixed_t den = TMulScale16 (plane.fixA(), Vx, plane.fixB(), Vy, plane.fixC(), Vz);
double den = plane.fA() * Vec.X + plane.fB() * Vec.Y + plane.fC() * Vec.Z;
if (den != 0)
{
fixed_t num = TMulScale16 (plane.fixA(), StartX,
plane.fixB(), StartY,
plane.fixC(), StartZ) + plane.fixD();
double num = plane.fA() * Start.X + plane.fB() * Start.Y + plane.fC() * Start.Z + plane.fD();
fixed_t hitdist = FixedDiv (-num, den);
double hitdist = -num / den;
if (hitdist > EnterDist && hitdist < MaxDist)
{
Results->HitPos = {
FIXED2DBL(StartX + FixedMul(Vx, hitdist)),
FIXED2DBL(StartY + FixedMul(Vy, hitdist)),
FIXED2DBL(StartZ + FixedMul(Vz, hitdist)) };
Results->HitPos = Start + Vec * hitdist;
SetSourcePosition();
Results->Distance = FIXED2DBL(hitdist);
Results->Fraction = FIXED2DBL(FixedDiv (hitdist, MaxDist));
Results->Distance = hitdist;
Results->Fraction = hitdist / MaxDist;
return true;
}
}

View file

@ -124,20 +124,8 @@ enum ETraceStatus
TRACE_Abort, // stop the trace, returning no hits
};
bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
fixed_t vx, fixed_t vy, fixed_t vz, fixed_t maxDist,
ActorFlags ActorMask, DWORD WallMask, AActor *ignore,
FTraceResults &res,
DWORD traceFlags=0,
ETraceStatus (*callback)(FTraceResults &res, void *)=NULL, void *callbackdata=NULL);
inline bool Trace(const DVector3 &start, sector_t *sector, const DVector3 &direction, double maxDist,
bool Trace(const DVector3 &start, sector_t *sector, const DVector3 &direction, double maxDist,
ActorFlags ActorMask, DWORD WallMask, AActor *ignore, FTraceResults &res, DWORD traceFlags = 0,
ETraceStatus(*callback)(FTraceResults &res, void *) = NULL, void *callbackdata = NULL)
{
return Trace(FLOAT2FIXED(start.X), FLOAT2FIXED(start.Y), FLOAT2FIXED(start.Z), sector,
FLOAT2FIXED(direction.X), FLOAT2FIXED(direction.Y), FLOAT2FIXED(direction.Z), FLOAT2FIXED(maxDist),
ActorMask, WallMask, ignore, res, traceFlags, callback, callbackdata);
}
ETraceStatus(*callback)(FTraceResults &res, void *) = NULL, void *callbackdata = NULL);
#endif //__P_TRACE_H__

View file

@ -252,14 +252,9 @@ double UDMFParserBase::CheckFloat(const char *key)
return sc.Float;
}
fixed_t UDMFParserBase::CheckFixed(const char *key)
DAngle UDMFParserBase::CheckAngle(const char *key)
{
return FLOAT2FIXED(CheckFloat(key));
}
angle_t UDMFParserBase::CheckAngle(const char *key)
{
return FLOAT2ANGLE(CheckFloat(key));
return DAngle(CheckFloat(key)).Normalized360();
}
bool UDMFParserBase::CheckBool(const char *key)
@ -358,7 +353,7 @@ int GetUDMFInt(int type, int index, const char *key)
return 0;
}
fixed_t GetUDMFFixed(int type, int index, const char *key)
double GetUDMFFloat(int type, int index, const char *key)
{
assert(type >=0 && type <=3);
@ -369,7 +364,7 @@ fixed_t GetUDMFFixed(int type, int index, const char *key)
FUDMFKey *pKey = pKeys->Find(key);
if (pKey != NULL)
{
return FLOAT2FIXED(pKey->FloatVal);
return pKey->FloatVal;
}
}
return 0;
@ -970,7 +965,7 @@ public:
if (namespace_bits & (Zd|Zdt|Va)) switch(key)
{
case NAME_Alpha:
ld->Alpha = CheckFixed(key);
ld->setAlpha(CheckFloat(key));
continue;
case NAME_Renderstyle:
@ -1096,7 +1091,7 @@ public:
{
ld->Alpha = TRANSLUC75;
}
if (strifetrans2 && ld->Alpha == FRACUNIT)
if (strifetrans2 && ld->Alpha == OPAQUE)
{
ld->Alpha = TRANSLUC25;
}
@ -1127,14 +1122,14 @@ public:
void ParseSidedef(side_t *sd, intmapsidedef_t *sdt, int index)
{
fixed_t texofs[2]={0,0};
double texOfs[2]={0,0};
memset(sd, 0, sizeof(*sd));
sdt->bottomtexture = "-";
sdt->toptexture = "-";
sdt->midtexture = "-";
sd->SetTextureXScale(FRACUNIT);
sd->SetTextureYScale(FRACUNIT);
sd->SetTextureXScale(1.);
sd->SetTextureYScale(1.);
sd->Index = index;
sc.MustGetToken('{');
@ -1144,11 +1139,11 @@ public:
switch(key)
{
case NAME_Offsetx:
texofs[0] = CheckInt(key) << FRACBITS;
texOfs[0] = CheckInt(key);
continue;
case NAME_Offsety:
texofs[1] = CheckInt(key) << FRACBITS;
texOfs[1] = CheckInt(key);
continue;
case NAME_Texturetop:
@ -1174,51 +1169,51 @@ public:
if (namespace_bits & (Zd|Zdt|Va)) switch(key)
{
case NAME_offsetx_top:
sd->SetTextureXOffset(side_t::top, CheckFixed(key));
sd->SetTextureXOffset(side_t::top, CheckFloat(key));
continue;
case NAME_offsety_top:
sd->SetTextureYOffset(side_t::top, CheckFixed(key));
sd->SetTextureYOffset(side_t::top, CheckFloat(key));
continue;
case NAME_offsetx_mid:
sd->SetTextureXOffset(side_t::mid, CheckFixed(key));
sd->SetTextureXOffset(side_t::mid, CheckFloat(key));
continue;
case NAME_offsety_mid:
sd->SetTextureYOffset(side_t::mid, CheckFixed(key));
sd->SetTextureYOffset(side_t::mid, CheckFloat(key));
continue;
case NAME_offsetx_bottom:
sd->SetTextureXOffset(side_t::bottom, CheckFixed(key));
sd->SetTextureXOffset(side_t::bottom, CheckFloat(key));
continue;
case NAME_offsety_bottom:
sd->SetTextureYOffset(side_t::bottom, CheckFixed(key));
sd->SetTextureYOffset(side_t::bottom, CheckFloat(key));
continue;
case NAME_scalex_top:
sd->SetTextureXScale(side_t::top, CheckFixed(key));
sd->SetTextureXScale(side_t::top, CheckFloat(key));
continue;
case NAME_scaley_top:
sd->SetTextureYScale(side_t::top, CheckFixed(key));
sd->SetTextureYScale(side_t::top, CheckFloat(key));
continue;
case NAME_scalex_mid:
sd->SetTextureXScale(side_t::mid, CheckFixed(key));
sd->SetTextureXScale(side_t::mid, CheckFloat(key));
continue;
case NAME_scaley_mid:
sd->SetTextureYScale(side_t::mid, CheckFixed(key));
sd->SetTextureYScale(side_t::mid, CheckFloat(key));
continue;
case NAME_scalex_bottom:
sd->SetTextureXScale(side_t::bottom, CheckFixed(key));
sd->SetTextureXScale(side_t::bottom, CheckFloat(key));
continue;
case NAME_scaley_bottom:
sd->SetTextureYScale(side_t::bottom, CheckFixed(key));
sd->SetTextureYScale(side_t::bottom, CheckFloat(key));
continue;
case NAME_light:
@ -1263,12 +1258,12 @@ public:
}
}
// initialization of these is delayed to allow separate offsets and add them with the global ones.
sd->AddTextureXOffset(side_t::top, texofs[0]);
sd->AddTextureXOffset(side_t::mid, texofs[0]);
sd->AddTextureXOffset(side_t::bottom, texofs[0]);
sd->AddTextureYOffset(side_t::top, texofs[1]);
sd->AddTextureYOffset(side_t::mid, texofs[1]);
sd->AddTextureYOffset(side_t::bottom, texofs[1]);
sd->AddTextureXOffset(side_t::top, texOfs[0]);
sd->AddTextureXOffset(side_t::mid, texOfs[0]);
sd->AddTextureXOffset(side_t::bottom, texOfs[0]);
sd->AddTextureYOffset(side_t::top, texOfs[1]);
sd->AddTextureYOffset(side_t::mid, texOfs[1]);
sd->AddTextureYOffset(side_t::bottom, texOfs[1]);
}
//===========================================================================
@ -1288,12 +1283,12 @@ public:
memset(sec, 0, sizeof(*sec));
sec->lightlevel = 160;
sec->SetXScale(sector_t::floor, FRACUNIT); // [RH] floor and ceiling scaling
sec->SetYScale(sector_t::floor, FRACUNIT);
sec->SetXScale(sector_t::ceiling, FRACUNIT);
sec->SetYScale(sector_t::ceiling, FRACUNIT);
sec->SetAlpha(sector_t::floor, OPAQUE);
sec->SetAlpha(sector_t::ceiling, OPAQUE);
sec->SetXScale(sector_t::floor, 1.); // [RH] floor and ceiling scaling
sec->SetYScale(sector_t::floor, 1.);
sec->SetXScale(sector_t::ceiling, 1.);
sec->SetYScale(sector_t::ceiling, 1.);
sec->SetAlpha(sector_t::floor, 1.);
sec->SetAlpha(sector_t::ceiling, 1.);
sec->thinglist = NULL;
sec->touching_thinglist = NULL; // phares 3/14/98
sec->seqType = (level.flags & LEVEL_SNDSEQTOTALCTRL) ? 0 : -1;
@ -1320,11 +1315,11 @@ public:
switch(key)
{
case NAME_Heightfloor:
sec->SetPlaneTexZ(sector_t::floor, CheckInt(key) << FRACBITS);
sec->SetPlaneTexZ(sector_t::floor, CheckFloat(key));
continue;
case NAME_Heightceiling:
sec->SetPlaneTexZ(sector_t::ceiling, CheckInt(key) << FRACBITS);
sec->SetPlaneTexZ(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Texturefloor:
@ -1360,35 +1355,35 @@ public:
if (namespace_bits & (Zd|Zdt|Va)) switch(key)
{
case NAME_Xpanningfloor:
sec->SetXOffset(sector_t::floor, CheckFixed(key));
sec->SetXOffset(sector_t::floor, CheckFloat(key));
continue;
case NAME_Ypanningfloor:
sec->SetYOffset(sector_t::floor, CheckFixed(key));
sec->SetYOffset(sector_t::floor, CheckFloat(key));
continue;
case NAME_Xpanningceiling:
sec->SetXOffset(sector_t::ceiling, CheckFixed(key));
sec->SetXOffset(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Ypanningceiling:
sec->SetYOffset(sector_t::ceiling, CheckFixed(key));
sec->SetYOffset(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Xscalefloor:
sec->SetXScale(sector_t::floor, CheckFixed(key));
sec->SetXScale(sector_t::floor, CheckFloat(key));
continue;
case NAME_Yscalefloor:
sec->SetYScale(sector_t::floor, CheckFixed(key));
sec->SetYScale(sector_t::floor, CheckFloat(key));
continue;
case NAME_Xscaleceiling:
sec->SetXScale(sector_t::ceiling, CheckFixed(key));
sec->SetXScale(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Yscaleceiling:
sec->SetYScale(sector_t::ceiling, CheckFixed(key));
sec->SetYScale(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Rotationfloor:
@ -1408,11 +1403,11 @@ public:
continue;
case NAME_Alphafloor:
sec->SetAlpha(sector_t::floor, CheckFixed(key));
sec->SetAlpha(sector_t::floor, CheckFloat(key));
continue;
case NAME_Alphaceiling:
sec->SetAlpha(sector_t::ceiling, CheckFixed(key));
sec->SetAlpha(sector_t::ceiling, CheckFloat(key));
continue;
case NAME_Renderstylefloor:
@ -1600,7 +1595,7 @@ public:
// Reset the planes to their defaults if not all of the plane equation's parameters were found.
if (fplaneflags != 15)
{
sec->floorplane.set(0, 0, FRACUNIT, -sec->GetPlaneTexZ(sector_t::floor));
sec->floorplane.SetAtHeight(sec->GetPlaneTexZF(sector_t::floor), sector_t::floor);
}
else
{
@ -1610,7 +1605,7 @@ public:
}
if (cplaneflags != 15)
{
sec->ceilingplane.set(0, 0, -FRACUNIT, sec->GetPlaneTexZ(sector_t::ceiling));
sec->ceilingplane.SetAtHeight(sec->GetPlaneTexZF(sector_t::ceiling), sector_t::ceiling);
}
else
{
@ -1663,18 +1658,18 @@ public:
vd->zCeiling = vd->zFloor = vd->flags = 0;
sc.MustGetToken('{');
fixed_t x, y;
double x, y;
while (!sc.CheckToken('}'))
{
FName key = ParseKey();
switch (key)
{
case NAME_X:
x = CheckFixed(key);
x = CheckFloat(key);
break;
case NAME_Y:
y = CheckFixed(key);
y = CheckFloat(key);
break;
case NAME_ZCeiling:
@ -1714,7 +1709,7 @@ public:
I_Error ("Line %d has invalid vertices: %zd and/or %zd.\nThe map only contains %d vertices.", i+skipped, v1i, v2i, numvertexes);
}
else if (v1i == v2i ||
(vertexes[v1i].fixX() == vertexes[v2i].fixX() && vertexes[v1i].fixY() == vertexes[v2i].fixY()))
(vertexes[v1i].fX() == vertexes[v2i].fX() && vertexes[v1i].fY() == vertexes[v2i].fY()))
{
Printf ("Removing 0-length line %d\n", i+skipped);
ParsedLines.Delete(i);

View file

@ -17,8 +17,7 @@ protected:
FName ParseKey(bool checkblock = false, bool *isblock = NULL);
int CheckInt(const char *key);
double CheckFloat(const char *key);
fixed_t CheckFixed(const char *key);
angle_t CheckAngle(const char *key);
DAngle CheckAngle(const char *key);
bool CheckBool(const char *key);
const char *CheckString(const char *key);

View file

@ -2500,7 +2500,6 @@ void P_PlayerThink (player_t *player)
}
if (player->centering)
{
player->mo->Angles.Pitch.Normalize180(); // make sure we are in the proper range here for the following code.
if (fabs(player->mo->Angles.Pitch) > 2.)
{
player->mo->Angles.Pitch *= (2. / 3.);

View file

@ -867,7 +867,7 @@ void FPolyObj::ThrustMobj (AActor *actor, side_t *side)
}
vertex_t *v1 = side->V1();
vertex_t *v2 = side->V2();
thrustAngle = VecToAngle(v2->fixX() - v1->fixX(), v2->fixY() - v1->fixY()) - 90.;
thrustAngle = (v2->fPos() - v1->fPos()).Angle() - 90.;
pe = static_cast<DPolyAction *>(specialdata);
if (pe)

View file

@ -55,8 +55,8 @@ void R_3D_AddHeight(secplane_t *add, sector_t *sec)
fixed_t height;
height = add->ZatPoint(viewx, viewy);
if(height >= sec->_f_CenterCeiling()) return;
if(height <= sec->_f_CenterFloor()) return;
if(height >= FLOAT2FIXED(sec->CenterCeiling())) return;
if(height <= FLOAT2FIXED(sec->CenterFloor())) return;
fakeActive = 1;

View file

@ -1345,11 +1345,11 @@ void R_Subsector (subsector_t *sub)
fakeFloor->validcount = validcount;
R_3D_NewClip();
}
if (frontsector->_f_CenterFloor() >= backsector->_f_CenterFloor())
if (frontsector->CenterFloor() >= backsector->CenterFloor())
{
fake3D |= FAKE3D_CLIPBOTFRONT;
}
if (frontsector->_f_CenterCeiling() <= backsector->_f_CenterCeiling())
if (frontsector->CenterCeiling() <= backsector->CenterCeiling())
{
fake3D |= FAKE3D_CLIPTOPFRONT;
}

View file

@ -1096,8 +1096,6 @@ struct sector_t
}
// Member variables
fixed_t _f_CenterFloor () const { return floorplane.ZatPoint (_f_centerspot()); }
fixed_t _f_CenterCeiling () const { return ceilingplane.ZatPoint (_f_centerspot()); }
double CenterFloor() const { return floorplane.ZatPoint(centerspot); }
double CenterCeiling() const { return ceilingplane.ZatPoint(centerspot); }
@ -1345,6 +1343,10 @@ struct side_t
{
textures[which].xscale = scale == 0 ? FRACUNIT : scale;
}
void SetTextureXScale(int which, double scale)
{
textures[which].xscale = scale == 0 ? FRACUNIT : FLOAT2FIXED(scale);
}
void SetTextureXScale(fixed_t scale)
{
textures[top].xscale = textures[mid].xscale = textures[bottom].xscale = scale == 0 ? FRACUNIT : scale;
@ -1644,31 +1646,6 @@ inline sector_t *P_PointInSector(double X, double Y)
return P_PointInSubsector(FLOAT2FIXED(X), FLOAT2FIXED(Y))->sector;
}
inline fixedvec3 AActor::_f_PosRelative(int portalgroup) const
{
return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, portalgroup);
}
inline fixedvec3 AActor::_f_PosRelative(const AActor *other) const
{
return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, other->Sector->PortalGroup);
}
inline fixedvec3 AActor::_f_PosRelative(sector_t *sec) const
{
return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, sec->PortalGroup);
}
inline fixedvec3 AActor::_f_PosRelative(line_t *line) const
{
return _f_Pos() + Displacements._f_getOffset(Sector->PortalGroup, line->frontsector->PortalGroup);
}
inline fixedvec3 _f_PosRelative(const fixedvec3 &pos, line_t *line, sector_t *refsec = NULL)
{
return pos + Displacements._f_getOffset(refsec->PortalGroup, line->frontsector->PortalGroup);
}
inline DVector3 AActor::PosRelative(int portalgroup) const
{
return Pos() + Displacements.getOffset(Sector->PortalGroup, portalgroup);

View file

@ -1071,7 +1071,7 @@ void R_DrawSpanP_C (void)
#ifdef RANGECHECK
if (ds_x2 < ds_x1 || ds_x1 < 0
|| ds_x2 >= screen->width || ds_y > screen->_f_height())
|| ds_x2 >= screen->width || ds_y > screen->height)
{
I_Error ("R_DrawSpan: %i to %i at %i", ds_x1, ds_x2, ds_y);
}

View file

@ -1531,7 +1531,7 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
yscale = pl->yscale << (16 - ds_ybits);
if (planeang != 0)
{
double rad = ANGLE2RAD(planeang);
double rad = planeang * (M_PI / ANGLE_180);
double cosine = cos(rad), sine = sin(rad);
pviewx = xs_RoundToInt(pl->xoffs + viewx * cosine - viewy * sine);
@ -1668,29 +1668,29 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
// p is the texture origin in view space
// Don't add in the offsets at this stage, because doing so can result in
// errors if the flat is rotated.
ang = ANGLE2RAD(ANG270 - viewangle);
ang = (ANG270 - viewangle) * (M_PI / ANGLE_180);
p[0] = vx * cos(ang) - vy * sin(ang);
p[2] = vx * sin(ang) + vy * cos(ang);
p[1] = pl->height.ZatPoint(0.0, 0.0) - vz;
// m is the v direction vector in view space
ang = ANGLE2RAD(ANG180 - viewangle - pl->angle);
ang = (ANG180 - viewangle - pl->angle) * (M_PI / ANGLE_180);
m[0] = yscale * cos(ang);
m[2] = yscale * sin(ang);
// m[1] = FIXED2FLOAT(pl->height.ZatPoint (0, iyscale) - pl->height.ZatPoint (0,0));
// m[1] = pl->height.ZatPointF (0, iyscale) - pl->height.ZatPointF (0,0));
// VectorScale2 (m, 64.f/VectorLength(m));
// n is the u direction vector in view space
ang += PI/2;
n[0] = -xscale * cos(ang);
n[2] = -xscale * sin(ang);
// n[1] = FIXED2FLOAT(pl->height.ZatPoint (ixscale, 0) - pl->height.ZatPoint (0,0));
// n[1] = pl->height.ZatPointF (ixscale, 0) - pl->height.ZatPointF (0,0));
// VectorScale2 (n, 64.f/VectorLength(n));
// This code keeps the texture coordinates constant across the x,y plane no matter
// how much you slope the surface. Use the commented-out code above instead to keep
// the textures a constant size across the surface's plane instead.
ang = ANGLE2RAD(pl->angle);
ang = pl->angle * (M_PI / ANGLE_180);
m[1] = pl->height.ZatPoint(vx + yscale * sin(ang), vy + yscale * cos(ang)) - zeroheight;
ang += PI/2;
n[1] = pl->height.ZatPoint(vx + xscale * sin(ang), vy + xscale * cos(ang)) - zeroheight;

View file

@ -687,16 +687,16 @@ void R_RenderFakeWallRange (drawseg_t *ds, int x1, int x2)
frontsector = sec;
}
floorheight = backsector->_f_CenterFloor();
ceilingheight = backsector->_f_CenterCeiling();
floorheight = FLOAT2FIXED(backsector->CenterFloor());
ceilingheight = FLOAT2FIXED(backsector->CenterCeiling());
// maybe fix clipheights
if (!(fake3D & FAKE3D_CLIPBOTTOM)) sclipBottom = floorheight;
if (!(fake3D & FAKE3D_CLIPTOP)) sclipTop = ceilingheight;
// maybe not visible
if (sclipBottom >= frontsector->_f_CenterCeiling()) return;
if (sclipTop <= frontsector->_f_CenterFloor()) return;
if (sclipBottom >= FLOAT2FIXED(frontsector->CenterCeiling())) return;
if (sclipTop <= FLOAT2FIXED(frontsector->CenterFloor())) return;
if (fake3D & FAKE3D_DOWN2UP)
{ // bottom to viewz

View file

@ -763,7 +763,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
// [ZZ] Or less definitely not visible (hue)
// [ZZ] 10.01.2016: don't try to clip stuff inside a skybox against the current portal.
if (!CurrentPortalInSkybox && CurrentPortal && !!P_PointOnLineSidePrecise(thing->_f_X(), thing->_f_Y(), CurrentPortal->dst))
if (!CurrentPortalInSkybox && CurrentPortal && !!P_PointOnLineSidePrecise(thing->Pos(), CurrentPortal->dst))
return;
// [RH] Interpolate the sprite's position to make it look smooth
@ -806,11 +806,11 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1])
{
rot = (ang - thing->_f_angle() + (angle_t)(ANGLE_45/2)*9) >> 28;
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9) >> 28;
}
else
{
rot = (ang - thing->_f_angle() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28;
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28;
}
picnum = sprframe->Texture[rot];
if (sprframe->Flip & (1 << rot))
@ -845,11 +845,11 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
angle_t rot;
if (sprframe->Texture[0] == sprframe->Texture[1])
{
rot = (ang - thing->_f_angle() + (angle_t)(ANGLE_45/2)*9) >> 28;
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9) >> 28;
}
else
{
rot = (ang - thing->_f_angle() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28;
rot = (ang - thing->Angles.Yaw.BAMs() + (angle_t)(ANGLE_45/2)*9-(angle_t)(ANGLE_180/16)) >> 28;
}
picnum = sprframe->Texture[rot];
if (sprframe->Flip & (1 << rot))
@ -1001,7 +1001,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
vis->texturemid = (tex->TopOffset << FRACBITS) - FixedDiv (viewz - fz + FLOAT2FIXED(thing->Floorclip), yscale);
vis->x1 = x1 < WindowLeft ? WindowLeft : x1;
vis->x2 = x2 > WindowRight ? WindowRight : x2;
vis->angle = thing->_f_angle();
vis->angle = thing->Angles.Yaw.BAMs();
if (renderflags & RF_XFLIP)
{
@ -1036,8 +1036,8 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
int voxelspin = (thing->flags & MF_DROPPED) ? voxel->DroppedSpin : voxel->PlacedSpin;
if (voxelspin != 0)
{
double ang = double(I_FPSTime()) * voxelspin / 1000;
vis->angle -= FLOAT2ANGLE(ang);
DAngle ang = double(I_FPSTime()) * voxelspin / 1000;
vis->angle -= ang.BAMs();
}
vis->vx = viewx;
@ -1151,7 +1151,7 @@ static void R_ProjectWallSprite(AActor *thing, fixed_t fx, fixed_t fy, fixed_t f
fixed_t lx1, lx2, ly1, ly2;
fixed_t gzb, gzt, tz;
FTexture *pic = TexMan(picnum, true);
angle_t ang = (thing->_f_angle() + ANGLE_90) >> ANGLETOFINESHIFT;
angle_t ang = (thing->Angles.Yaw.BAMs() + ANGLE_90) >> ANGLETOFINESHIFT;
vissprite_t *vis;
// Determine left and right edges of sprite. The sprite's angle is its normal,
@ -1256,12 +1256,12 @@ void R_AddSprites (sector_t *sec, int lightlevel, int fakeside)
{
if(!rover->top.plane->isSlope())
{
if(rover->top.plane->Zat0() <= thing->_f_Z()) fakefloor = rover;
if(rover->top.plane->ZatPoint(0., 0.) <= thing->Z()) fakefloor = rover;
}
}
if(!rover->bottom.plane->isSlope())
{
if(rover->bottom.plane->Zat0() >= thing->_f_Top()) fakeceiling = rover;
if(rover->bottom.plane->ZatPoint(0., 0.) >= thing->Top()) fakeceiling = rover;
}
}
R_ProjectSprite (thing, fakeside, fakefloor, fakeceiling);

View file

@ -105,6 +105,7 @@ fixed_t viewx;
fixed_t viewy;
fixed_t viewz;
int viewpitch;
angle_t viewangle;
extern "C"
{
@ -117,7 +118,6 @@ extern "C"
int otic;
angle_t viewangle;
sector_t *viewsector;
fixed_t viewcos, viewtancos;
@ -619,7 +619,7 @@ void R_InterpolateView (player_t *player, fixed_t frac, InterpolationViewer *ivi
DVector3a &end = InterpolationPath[i];
pathlen += FLOAT2FIXED((end.pos-start.pos).Length());
totalzdiff += FLOAT2FIXED(start.pos.Z);
totaladiff += FLOAT2ANGLE(start.angle.Degrees);
totaladiff += start.angle.BAMs();
}
fixed_t interpolatedlen = FixedMul(frac, pathlen);
@ -629,7 +629,7 @@ void R_InterpolateView (player_t *player, fixed_t frac, InterpolationViewer *ivi
DVector3a &end = InterpolationPath[i];
fixed_t fraglen = FLOAT2FIXED((end.pos - start.pos).Length());
zdiff += FLOAT2FIXED(start.pos.Z);
adiff += FLOAT2ANGLE(start.angle.Degrees);
adiff += start.angle.BAMs();
if (fraglen <= interpolatedlen)
{
interpolatedlen -= fraglen;
@ -683,11 +683,11 @@ void R_InterpolateView (player_t *player, fixed_t frac, InterpolationViewer *ivi
// Avoid overflowing viewpitch (can happen when a netgame is stalled)
if (viewpitch > INT_MAX - delta)
{
viewpitch = FLOAT2ANGLE(player->MaxPitch.Degrees);
viewpitch = player->MaxPitch.BAMs();
}
else
{
viewpitch = MIN<int>(viewpitch + delta, FLOAT2ANGLE(player->MaxPitch.Degrees));
viewpitch = MIN<int>(viewpitch + delta, player->MaxPitch.BAMs());
}
}
else if (delta < 0)
@ -695,11 +695,11 @@ void R_InterpolateView (player_t *player, fixed_t frac, InterpolationViewer *ivi
// Avoid overflowing viewpitch (can happen when a netgame is stalled)
if (viewpitch < INT_MIN - delta)
{
viewpitch = FLOAT2ANGLE(player->MinPitch.Degrees);
viewpitch = player->MinPitch.BAMs();
}
else
{
viewpitch = MAX<int>(viewpitch + delta, FLOAT2ANGLE(player->MinPitch.Degrees));
viewpitch = MAX<int>(viewpitch + delta, player->MinPitch.BAMs());
}
}
}
@ -994,13 +994,13 @@ void R_SetupFrame (AActor *actor)
viewsector = camera->Sector;
r_showviewer = false;
}
iview->nviewpitch = camera->_f_pitch();
iview->nviewpitch = camera->Angles.Pitch.BAMs();
if (camera->player != 0)
{
player = camera->player;
}
iview->nviewangle = camera->_f_angle();
iview->nviewangle = camera->Angles.Yaw.BAMs();
if (iview->otic == -1 || r_NoInterpolate)
{
R_ResetViewInterpolation ();

View file

@ -34,6 +34,7 @@
#define GetCommand(a) ((a) & 255)
#define GetData(a) (SDWORD(a) >> 8 )
#define GetFloatData(a) float((SDWORD(a) >> 8 )/65536.f)
#define MakeCommand(a,b) ((a) | ((b) << 8))
#define HexenPlatSeq(a) (a)
#define HexenDoorSeq(a) ((a) | 0x40)
@ -675,18 +676,18 @@ void S_ParseSndSeq (int levellump)
case SS_STRING_VOLUME: // volume is in range 0..100
sc.MustGetFloat ();
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUME, int(sc.Float * (FRACUNIT/100.f))));
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUME, int(sc.Float * (65536.f / 100.f))));
break;
case SS_STRING_VOLUMEREL:
sc.MustGetFloat ();
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMEREL, int(sc.Float * (FRACUNIT/100.f))));
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMEREL, int(sc.Float * (65536.f / 100.f))));
break;
case SS_STRING_VOLUMERAND:
sc.MustGetFloat ();
volumebase = float(sc.Float);
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMERAND, int(sc.Float * (FRACUNIT/100.f))));
ScriptTemp.Push(MakeCommand(SS_CMD_VOLUMERAND, int(sc.Float * (65536.f / 100.f))));
sc.MustGetFloat ();
ScriptTemp.Push(int((sc.Float - volumebase) * (256/100.f)));
break;
@ -705,12 +706,12 @@ void S_ParseSndSeq (int levellump)
case SS_STRING_ATTENUATION:
if (sc.CheckFloat())
{
val = FLOAT2FIXED(sc.Float);
val = int(sc.Float*65536.);
}
else
{
sc.MustGetString ();
val = sc.MustMatchString(&Attenuations[0].name, sizeof(Attenuations[0])) << FRACBITS;
val = sc.MustMatchString(&Attenuations[0].name, sizeof(Attenuations[0])) * 65536;
}
ScriptTemp.Push(MakeCommand(SS_CMD_ATTENUATION, val));
break;
@ -1179,19 +1180,19 @@ void DSeqNode::Tick ()
return;
case SS_CMD_VOLUME:
m_Volume = GetData(*m_SequencePtr) / float(FRACUNIT);
m_Volume = GetFloatData(*m_SequencePtr);
m_SequencePtr++;
break;
case SS_CMD_VOLUMEREL:
// like SS_CMD_VOLUME, but the new volume is added to the old volume
m_Volume += GetData(*m_SequencePtr) / float(FRACUNIT);
m_Volume += GetFloatData(*m_SequencePtr);
m_SequencePtr++;
break;
case SS_CMD_VOLUMERAND:
// like SS_CMD_VOLUME, but the new volume is chosen randomly from a range
m_Volume = GetData(m_SequencePtr[0]) / float(FRACUNIT) + (pr_sndseq() % m_SequencePtr[1]) / 255.f;
m_Volume = GetFloatData(m_SequencePtr[0]) + (pr_sndseq() % m_SequencePtr[1]) / 255.f;
m_SequencePtr += 2;
break;
@ -1200,7 +1201,7 @@ void DSeqNode::Tick ()
return;
case SS_CMD_ATTENUATION:
m_Atten = FIXED2FLOAT(GetData(*m_SequencePtr));
m_Atten = GetFloatData(*m_SequencePtr);
m_SequencePtr++;
break;

View file

@ -1952,7 +1952,7 @@ static void S_SetListener(SoundListener &listener, AActor *listenactor)
{
if (listenactor != NULL)
{
listener.angle = (float)ToRadians(listenactor->Angles.Yaw);
listener.angle = (float)listenactor->Angles.Yaw.Radians();
/*
listener.velocity.X = listenactor->vel.x * (TICRATE/65536.f);
listener.velocity.Y = listenactor->vel.z * (TICRATE/65536.f);

View file

@ -1,6 +1,7 @@
#ifndef __TEXTURES_H
#define __TEXTURES_H
#include "doomtype.h"
#include "vectors.h"
class FBitmap;

View file

@ -1205,8 +1205,8 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
scaley /= tex->Scale.Y;
// Use the CRT's functions here.
cosrot = cos(ToRadians(rotation));
sinrot = sin(ToRadians(rotation));
cosrot = cos(rotation.Radians());
sinrot = sin(rotation.Radians());
// Setup constant texture mapping parameters.
R_SetupSpanBits(tex);

View file

@ -42,16 +42,19 @@
#include <math.h>
#include <string.h>
#include "m_fixed.h"
#include "tables.h"
#include "xs_Float.h"
#include "math/cmath.h"
#define EQUAL_EPSILON (1/65536.f)
// make this a local inline function to avoid any dependencies on other headers and not pollute the global namespace
namespace pi
{
inline double pi() { return 3.14159265358979323846; }
}
//#define DEG2RAD(d) ((d)*M_PI/180.)
//#define RAD2DEG(r) ((r)*180./M_PI)
template<class vec_t> struct TVector3;
template<class vec_t> struct TRotator;
@ -783,6 +786,10 @@ struct TAngle
{
vec_t Degrees;
private:
const double BAM_FACTOR = (90. / 0x40000000);
public:
// This is to catch any accidental attempt to assign an angle_t to this type. Any explicit exception will require a type cast.
TAngle(int) = delete;
@ -990,51 +997,27 @@ struct TAngle
}
// Ensure the angle is between [0.0,360.0) degrees
TAngle &Normalize360()
TAngle Normalized360() const
{
// Normalizing the angle converts it to a BAM, which masks it, and converts it back to a float.
// Note: We MUST use xs_Float here because it is the only method that guarantees reliable wraparound.
Degrees = (vec_t)ANGLE2DBL((unsigned int)FLOAT2ANGLE(Degrees));
return *this;
}
// Ensures the angle is between (-180.0,180.0] degrees
TAngle &Normalize180()
{
Degrees = (vec_t)ANGLE2DBL((signed int)FLOAT2ANGLE(Degrees));
return *this;
}
// Same as above but doesn't alter the calling object itself
// Ensure the angle is between [0.0,360.0) degrees
TAngle Normalized360() const
{
return (vec_t)ANGLE2DBL((unsigned int)FLOAT2ANGLE(Degrees));
return (vec_t)(BAM_FACTOR * BAMs());
}
// Ensures the angle is between (-180.0,180.0] degrees
TAngle Normalized180() const
{
return (vec_t)ANGLE2DBL((signed int)FLOAT2ANGLE(Degrees));
}
// Like Normalize360(), except the integer value is not converted back to a float.
// The steps parameter must be a power of 2.
int Quantize(int steps) const
{
return xs_CRoundToInt((Degrees * (steps/360.0)) & (steps-1));
return (vec_t)(BAM_FACTOR * (signed int)BAMs());
}
vec_t Radians() const
{
return Degrees * (M_PI / 180.0);
return Degrees * (pi::pi() / 180.0);
}
unsigned BAMs() const
{
return FLOAT2ANGLE(Degrees);
return xs_CRoundToInt(Degrees * (0x40000000 / 90.));
}
TVector2<vec_t> ToVector(vec_t length = 1) const
@ -1054,7 +1037,7 @@ struct TAngle
double Tan() const
{
return g_tan(Degrees * (M_PI / 180.));
return g_tan(Degrees * (pi::pi() / 180.));
}
// This is for calculating vertical velocity. For high pitches the tangent will become too large to be useful.
@ -1063,20 +1046,13 @@ struct TAngle
return clamp(Tan(), -max, max);
}
static inline TAngle ToDegrees(double rad)
{
return TAngle(double(rad * (180.0 / pi::pi())));
}
};
template<class T>
inline double ToRadians (const TAngle<T> &deg)
{
return double(deg.Degrees * (M_PI / 180.0));
}
// If this gets templated there will be countless instantiation errors.
inline TAngle<double> ToDegrees (double rad)
{
return TAngle<double> (double(rad * (180.0 / M_PI)));
}
// Emulates the old floatbob offset table with direct calls to trig functions.
inline double BobSin(double fb)
{
@ -1092,48 +1068,48 @@ inline TAngle<T> fabs (const TAngle<T> &deg)
template<class T>
inline TAngle<T> deltaangle(const TAngle<T> &a1, const TAngle<T> &a2)
{
return (a2 - a1).Normalize180();
return (a2 - a1).Normalized180();
}
template<class T>
inline TAngle<T> deltaangle(const TAngle<T> &a1, double a2)
{
return (a2 - a1).Normalize180();
return (a2 - a1).Normalized180();
}
template<class T>
inline TAngle<T> deltaangle(double a1, const TAngle<T> &a2)
{
return (a2 - a1).Normalize180();
return (a2 - a1).Normalized180();
}
template<class T>
inline TAngle<T> absangle(const TAngle<T> &a1, const TAngle<T> &a2)
{
return fabs((a1 - a2).Normalize180());
return fabs((a1 - a2).Normalized180());
}
template<class T>
inline TAngle<T> absangle(const TAngle<T> &a1, double a2)
{
return fabs((a1 - a2).Normalize180());
return fabs((a1 - a2).Normalized180());
}
inline TAngle<double> VecToAngle(double x, double y)
{
return g_atan2(y, x) * (180.0 / M_PI);
return g_atan2(y, x) * (180.0 / pi::pi());
}
template<class T>
inline TAngle<T> VecToAngle (const TVector2<T> &vec)
{
return (T)g_atan2(vec.Y, vec.X) * (180.0 / M_PI);
return (T)g_atan2(vec.Y, vec.X) * (180.0 / pi::pi());
}
template<class T>
inline TAngle<T> VecToAngle (const TVector3<T> &vec)
{
return (T)g_atan2(vec.Y, vec.X) * (180.0 / M_PI);
return (T)g_atan2(vec.Y, vec.X) * (180.0 / pi::pi());
}
template<class T>
@ -1296,25 +1272,6 @@ struct TRotator
{
return TRotator(Pitch - other.Pitch, Yaw - other.Yaw, Roll - other.Roll);
}
// Normalize each component
TRotator &Normalize180 ()
{
for (int i = -3; i; ++i)
{
(*this)[i+3].Normalize180();
}
return *this;
}
TRotator &Normalize360 ()
{
for (int i = -3; i; ++i)
{
(*this)[i+3].Normalize360();
}
return *this;
}
};
// Create a forward vector from a rotation (ignoring roll)

View file

@ -3105,8 +3105,8 @@ void D3DFB::FillSimplePoly(FTexture *texture, FVector2 *points, int npoints,
return;
}
cosrot = (float)cos(ToRadians(rotation));
sinrot = (float)sin(ToRadians(rotation));
cosrot = (float)cos(rotation.Radians());
sinrot = (float)sin(rotation.Radians());
CheckQuadBatch(npoints - 2, npoints);
quad = &QuadExtra[QuadBatchPos];