- fixed last commit and optimized wall lookup code a bit.

No need to continue if a matching wall has been found.
This commit is contained in:
Christoph Oelckers 2022-01-14 20:20:47 +01:00
parent ef711f0b2d
commit 7b1d99373b

View file

@ -72,16 +72,16 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
// In Wanton Destruction's airplane level there's such a sprite assigned to the wrong sector. // In Wanton Destruction's airplane level there's such a sprite assigned to the wrong sector.
if (d.X == 0) if (d.X == 0)
{ {
if (fabs(tspr->pos.X - wal.pos.X) < maxorthdist); if (fabs(tspr->pos.X - wal.pos.X) < maxorthdist)
{ {
closest = &wal; return &wal;
} }
} }
else if (d.Y == 0) else if (d.Y == 0)
{ {
if (fabs(tspr->pos.Y - wal.pos.Y) < maxorthdist); if (fabs(tspr->pos.Y - wal.pos.Y) < maxorthdist)
{ {
closest = &wal; return &wal;
} }
} }
else else
@ -89,13 +89,12 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
double wdist = SquareDistToWall(tspr->pos.X, tspr->pos.Y, &wal, &outpos); double wdist = SquareDistToWall(tspr->pos.X, tspr->pos.Y, &wal, &outpos);
if (wdist <= maxdistsq) if (wdist <= maxdistsq)
{ {
closest = &wal; return &wal;
} }
} }
} }
} }
// todo: cache this in the sprite to avoid recalculation. return nullptr;
return closest;
} }
//========================================================================== //==========================================================================