mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
- started refactoring p_map.cpp
- added AActor::Top function to replace the frequent occurences of actor->z + actor->height.
This commit is contained in:
parent
b735138332
commit
43314f0c0d
7 changed files with 51 additions and 50 deletions
53
src/actor.h
53
src/actor.h
|
@ -847,7 +847,7 @@ public:
|
|||
bool intersects(AActor *other) const
|
||||
{
|
||||
fixed_t blockdist = radius + other->radius;
|
||||
return ( abs(pos.x - other->pos.x) < blockdist && abs(pos.y - other->pos.y) < blockdist);
|
||||
return ( abs(x - other->x) < blockdist && abs(y - other->y) < blockdist);
|
||||
}
|
||||
|
||||
PalEntry GetBloodColor() const
|
||||
|
@ -888,84 +888,84 @@ public:
|
|||
// to distinguish between portal-aware and portal-unaware distance calculation.
|
||||
fixed_t AproxDistance(AActor *other, bool absolute = false)
|
||||
{
|
||||
return P_AproxDistance(pos.x - other->pos.x, pos.y - other->pos.y);
|
||||
return P_AproxDistance(x - other->x, y - other->y);
|
||||
}
|
||||
|
||||
// same with 'ref' here.
|
||||
fixed_t AproxDistance(fixed_t otherx, fixed_t othery, AActor *ref = NULL)
|
||||
{
|
||||
return P_AproxDistance(pos.x - otherx, pos.y - othery);
|
||||
return P_AproxDistance(x - otherx, y - othery);
|
||||
}
|
||||
|
||||
fixed_t AproxDistance(AActor *other, fixed_t xadd, fixed_t yadd, bool absolute = false)
|
||||
{
|
||||
return P_AproxDistance(pos.x - other->pos.x + xadd, pos.y - other->pos.y + yadd);
|
||||
return P_AproxDistance(x - other->x + xadd, y - other->y + yadd);
|
||||
}
|
||||
|
||||
fixed_t AproxDistance3D(AActor *other, bool absolute = false)
|
||||
{
|
||||
return P_AproxDistance(AproxDistance(other), pos.z - other->pos.z);
|
||||
return P_AproxDistance(AproxDistance(other), z - other->z);
|
||||
}
|
||||
|
||||
// more precise, but slower version, being used in a few places
|
||||
fixed_t Distance2D(AActor *other, bool absolute = false)
|
||||
{
|
||||
return xs_RoundToInt(FVector2(pos.x - other->pos.x, pos.y - other->pos.y).Length());
|
||||
return xs_RoundToInt(FVector2(x - other->x, y - other->y).Length());
|
||||
}
|
||||
|
||||
// a full 3D version of the above
|
||||
fixed_t Distance3D(AActor *other, bool absolute = false)
|
||||
{
|
||||
return xs_RoundToInt(FVector3(pos.x - other->pos.x, pos.y - other->pos.y, pos.z - other->pos.z).Length());
|
||||
return xs_RoundToInt(FVector3(x - other->x, y - other->y, z - other->z).Length());
|
||||
}
|
||||
|
||||
angle_t AngleTo(AActor *other, bool absolute = false) const
|
||||
{
|
||||
return R_PointToAngle2(pos.x, pos.y, other->pos.x, other->pos.y);
|
||||
return R_PointToAngle2(x, y, other->x, other->y);
|
||||
}
|
||||
|
||||
angle_t AngleTo(AActor *other, fixed_t oxofs, fixed_t oyofs, bool absolute = false) const
|
||||
{
|
||||
return R_PointToAngle2(pos.x, pos.y, other->pos.x + oxofs, other->pos.y + oyofs);
|
||||
return R_PointToAngle2(x, y, other->x + oxofs, other->y + oyofs);
|
||||
}
|
||||
|
||||
fixed_t AngleTo(fixed_t otherx, fixed_t othery, AActor *ref = NULL)
|
||||
{
|
||||
return R_PointToAngle2(pos.x, pos.y, otherx, othery);
|
||||
return R_PointToAngle2(x, y, otherx, othery);
|
||||
}
|
||||
|
||||
fixed_t AngleXYTo(fixed_t myx, fixed_t myy, AActor *other, bool absolute = false)
|
||||
{
|
||||
return R_PointToAngle2(myx, myy, other->pos.x, other->pos.y);
|
||||
return R_PointToAngle2(myx, myy, other->x, other->y);
|
||||
}
|
||||
|
||||
fixedvec2 Vec2To(AActor *other) const
|
||||
{
|
||||
fixedvec2 ret = { other->pos.x - pos.x, other->pos.y - pos.y };
|
||||
fixedvec2 ret = { other->x - x, other->y - y };
|
||||
return ret;
|
||||
}
|
||||
|
||||
fixedvec3 Vec3To(AActor *other) const
|
||||
{
|
||||
fixedvec3 ret = { other->pos.x - pos.x, other->pos.y - pos.y, other->pos.z - pos.z };
|
||||
fixedvec3 ret = { other->x - x, other->y - y, other->z - z };
|
||||
return ret;
|
||||
}
|
||||
|
||||
fixedvec2 Vec2Offset(fixed_t dx, fixed_t dy, bool absolute = false) const
|
||||
{
|
||||
fixedvec2 ret = { pos.x + dx, pos.y + dy };
|
||||
fixedvec2 ret = { x + dx, y + dy };
|
||||
return ret;
|
||||
}
|
||||
|
||||
fixedvec3 Vec3Offset(fixed_t dx, fixed_t dy, fixed_t dz, bool absolute = false) const
|
||||
{
|
||||
fixedvec3 ret = { pos.x + dx, pos.y + dy, pos.z + dz };
|
||||
fixedvec3 ret = { x + dx, y + dy, z + dz };
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Move(fixed_t dx, fixed_t dy, fixed_t dz)
|
||||
{
|
||||
SetOrigin(pos.x + dx, pos.y + dy, pos.z + dz, true);
|
||||
SetOrigin(x + dx, y + dy, z + dz, true);
|
||||
}
|
||||
|
||||
inline void SetFriendPlayer(player_t *player);
|
||||
|
@ -987,10 +987,7 @@ public:
|
|||
|
||||
// info for drawing
|
||||
// NOTE: The first member variable *must* be x.
|
||||
private:
|
||||
fixedvec3 pos;
|
||||
public:
|
||||
//fixed_t x,y,z;
|
||||
fixed_t x,y,z;
|
||||
AActor *snext, **sprev; // links in sector (if needed)
|
||||
angle_t angle;
|
||||
WORD sprite; // used to find patch_t and flip value
|
||||
|
@ -1188,7 +1185,7 @@ public:
|
|||
void LinkToWorld (sector_t *sector);
|
||||
void UnlinkFromWorld ();
|
||||
void AdjustFloorClip ();
|
||||
void SetOrigin (fixed_t x, fixed_t y, fixed_t z, bool moving);
|
||||
void SetOrigin (fixed_t x, fixed_t y, fixed_t z, bool moving = false);
|
||||
bool InStateSequence(FState * newstate, FState * basestate);
|
||||
int GetTics(FState * newstate);
|
||||
bool SetState (FState *newstate, bool nofunction=false);
|
||||
|
@ -1220,19 +1217,23 @@ public:
|
|||
|
||||
fixed_t X() const
|
||||
{
|
||||
return pos.x;
|
||||
return x;
|
||||
}
|
||||
fixed_t Y() const
|
||||
{
|
||||
return pos.y;
|
||||
return y;
|
||||
}
|
||||
fixed_t Z() const
|
||||
{
|
||||
return pos.z;
|
||||
return z;
|
||||
}
|
||||
void SetZ(fixed_t newz)
|
||||
fixed_t Top() const
|
||||
{
|
||||
pos.z = newz;
|
||||
return z + height;
|
||||
}
|
||||
void SetZ(fixed_t newz, bool moving = true)
|
||||
{
|
||||
z = newz;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -2376,7 +2376,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
|
|||
s = ReadString (stream);
|
||||
|
||||
if (Trace (players[player].mo->X(), players[player].mo->Y(),
|
||||
players[player].mo->Z() + players[player].mo->height - (players[player].mo->height>>2),
|
||||
players[player].mo->Top() - (players[player].mo->height>>2),
|
||||
players[player].mo->Sector,
|
||||
vx, vy, vz, 172*FRACUNIT, 0, ML_BLOCKEVERYTHING, players[player].mo,
|
||||
trace, TRACE_NoSky))
|
||||
|
|
|
@ -337,7 +337,7 @@ void P_PlayerOnSpecial3DFloor(player_t* player)
|
|||
{
|
||||
//Water and DEATH FOG!!! heh
|
||||
if (player->mo->Z() > rover->top.plane->ZatPoint(player->mo) ||
|
||||
(player->mo->Z() + player->mo->height) < rover->bottom.plane->ZatPoint(player->mo))
|
||||
player->mo->Top() < rover->bottom.plane->ZatPoint(player->mo))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -4158,7 +4158,7 @@ bool DLevelScript::DoCheckActorTexture(int tid, AActor *activator, int string, b
|
|||
}
|
||||
else
|
||||
{
|
||||
fixed_t z = actor->Z() + actor->height;
|
||||
fixed_t z = actor->Top();
|
||||
// Looking through planes from bottom to top
|
||||
for (i = numff-1; i >= 0; --i)
|
||||
{
|
||||
|
|
|
@ -243,9 +243,9 @@ bool AActor::CheckMeleeRange ()
|
|||
// [RH] Don't melee things too far above or below actor.
|
||||
if (!(flags5 & MF5_NOVERTICALMELEERANGE))
|
||||
{
|
||||
if (pl->Z() > Z() + height)
|
||||
if (pl->Z() > Top())
|
||||
return false;
|
||||
if (pl->Z() + pl->height < Z())
|
||||
if (pl->Top() < Z())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -280,11 +280,11 @@ bool P_CheckMeleeRange2 (AActor *actor)
|
|||
{
|
||||
return false;
|
||||
}
|
||||
if (mo->Z() > actor->Z()+actor->height)
|
||||
if (mo->Z() > actor->Top())
|
||||
{ // Target is higher than the attacker
|
||||
return false;
|
||||
}
|
||||
else if (actor->Z() > mo->Z()+mo->height)
|
||||
else if (actor->Z() > mo->Top())
|
||||
{ // Attacker is higher
|
||||
return false;
|
||||
}
|
||||
|
@ -2787,7 +2787,7 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
|
|||
|
||||
// If the target z is above the target's head, reposition to the middle of
|
||||
// its body.
|
||||
if (target_z >= other->Z() + other->height)
|
||||
if (target_z >= other->Top())
|
||||
{
|
||||
target_z = other->Z() + (other->height / 2);
|
||||
}
|
||||
|
|
|
@ -3107,7 +3107,7 @@ FUNC(LS_GlassBreak)
|
|||
{
|
||||
glass = Spawn("GlassJunk", x, y, ONFLOORZ, ALLOW_REPLACE);
|
||||
|
||||
glass->SetZ(glass->z + 24 * FRACUNIT);
|
||||
glass->SetZ(glass->Z() + 24 * FRACUNIT);
|
||||
glass->SetState (glass->SpawnState + (pr_glass() % glass->health));
|
||||
an = pr_glass() << (32-8);
|
||||
glass->angle = an;
|
||||
|
|
|
@ -190,7 +190,7 @@ static bool PIT_FindFloorCeiling(line_t *ld, const FBoundingBox &box, FCheckPosi
|
|||
}
|
||||
else if (r >= (1 << 24))
|
||||
{
|
||||
P_LineOpening(open, tmf.thing, ld, sx = ld->v2->x, sy = ld->v2->y, tmf.thing->x, tmf.thing->y, flags);
|
||||
P_LineOpening(open, tmf.thing, ld, sx = ld->v2->x, sy = ld->v2->y, tmf.thing->X(), tmf.thing->Y(), flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -288,9 +288,9 @@ void P_FindFloorCeiling(AActor *actor, int flags)
|
|||
FCheckPosition tmf;
|
||||
|
||||
tmf.thing = actor;
|
||||
tmf.x = actor->x;
|
||||
tmf.y = actor->y;
|
||||
tmf.z = actor->z;
|
||||
tmf.x = actor->X();
|
||||
tmf.y = actor->Y();
|
||||
tmf.z = actor->Z();
|
||||
|
||||
if (flags & FFCF_ONLYSPAWNPOS)
|
||||
{
|
||||
|
@ -336,7 +336,7 @@ void P_FindFloorCeiling(AActor *actor, int flags)
|
|||
|
||||
if (tmf.touchmidtex) tmf.dropoffz = tmf.floorz;
|
||||
|
||||
if (!(flags & FFCF_ONLYSPAWNPOS) || (tmf.abovemidtex && (tmf.floorz <= actor->z)))
|
||||
if (!(flags & FFCF_ONLYSPAWNPOS) || (tmf.abovemidtex && (tmf.floorz <= actor->Z())))
|
||||
{
|
||||
actor->floorz = tmf.floorz;
|
||||
actor->dropoffz = tmf.dropoffz;
|
||||
|
@ -404,13 +404,13 @@ bool P_TeleportMove(AActor *thing, fixed_t x, fixed_t y, fixed_t z, bool telefra
|
|||
line_t *ld;
|
||||
|
||||
// P_LineOpening requires the thing's z to be the destination z in order to work.
|
||||
fixed_t savedz = thing->z;
|
||||
thing->z = z;
|
||||
fixed_t savedz = thing->Z();
|
||||
thing->SetZ(z);
|
||||
while ((ld = it.Next()))
|
||||
{
|
||||
PIT_FindFloorCeiling(ld, box, tmf, 0);
|
||||
}
|
||||
thing->z = savedz;
|
||||
thing->SetZ(savedz);
|
||||
|
||||
if (tmf.touchmidtex) tmf.dropoffz = tmf.floorz;
|
||||
|
||||
|
@ -427,7 +427,7 @@ bool P_TeleportMove(AActor *thing, fixed_t x, fixed_t y, fixed_t z, bool telefra
|
|||
continue;
|
||||
|
||||
fixed_t blockdist = th->radius + tmf.thing->radius;
|
||||
if (abs(th->x - tmf.x) >= blockdist || abs(th->y - tmf.y) >= blockdist)
|
||||
if (abs(th->X() - tmf.x) >= blockdist || abs(th->Y() - tmf.y) >= blockdist)
|
||||
continue;
|
||||
|
||||
// [RH] Z-Check
|
||||
|
@ -437,8 +437,8 @@ bool P_TeleportMove(AActor *thing, fixed_t x, fixed_t y, fixed_t z, bool telefra
|
|||
{
|
||||
if (!(th->flags3 & thing->flags3 & MF3_DONTOVERLAP))
|
||||
{
|
||||
if (z > th->z + th->height || // overhead
|
||||
z + thing->height < th->z) // underneath
|
||||
if (z > th->Top() || // overhead
|
||||
z + thing->height < th->Z()) // underneath
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -459,7 +459,7 @@ bool P_TeleportMove(AActor *thing, fixed_t x, fixed_t y, fixed_t z, bool telefra
|
|||
if (modifyactor)
|
||||
{
|
||||
// the move is ok, so link the thing into its new position
|
||||
thing->SetOrigin(x, y, z);
|
||||
thing->SetOrigin(x, y, z, false);
|
||||
thing->floorz = tmf.floorz;
|
||||
thing->ceilingz = tmf.ceilingz;
|
||||
thing->floorsector = tmf.floorsector;
|
||||
|
@ -507,7 +507,7 @@ bool P_TeleportMove(AActor *thing, fixed_t x, fixed_t y, fixed_t z, bool telefra
|
|||
void P_PlayerStartStomp(AActor *actor)
|
||||
{
|
||||
AActor *th;
|
||||
FBlockThingsIterator it(FBoundingBox(actor->x, actor->y, actor->radius));
|
||||
FBlockThingsIterator it(FBoundingBox(actor->X(), actor->Y(), actor->radius));
|
||||
|
||||
while ((th = it.Next()))
|
||||
{
|
||||
|
@ -525,9 +525,9 @@ void P_PlayerStartStomp(AActor *actor)
|
|||
if (th->player == NULL && !(th->flags3 & MF3_ISMONSTER))
|
||||
continue;
|
||||
|
||||
if (actor->z > th->z + th->height)
|
||||
if (actor->Z() > th->Top())
|
||||
continue; // overhead
|
||||
if (actor->z + actor->height < th->z)
|
||||
if (actor->Top() < th->Z())
|
||||
continue; // underneath
|
||||
|
||||
P_DamageMobj(th, actor, actor, TELEFRAG_DAMAGE, NAME_Telefrag);
|
||||
|
|
Loading…
Reference in a new issue