From 9a8f29066e4e3378ec4c8e07ee18739e27ab472c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 30 Jan 2022 08:28:52 +0100 Subject: [PATCH] - handle wall sprites on orthogonal walls better. This covers the case that a wall sprite may overlap two walls with a slight deviation in their position - always pick the closest one. --- source/core/rendering/scene/hw_walls.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index efa737648a3..f6017703309 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -50,13 +50,12 @@ DCoreActor* wall_to_sprite_actors[8]; // gets updated each frame. Todo: Encapsul static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos) { - const double maxorthdist = 3; // maximum orthogonal distance to be considered an attached sprite. - const double maxdistsq = (tspr->ang & 0x1ff)? 3 * 3 : 1; // lower tolerance for perfectly orthogonal sprites + double maxorthdist = 3; // maximum orthogonal distance to be considered an attached sprite. + double maxdistsq = 3 * 3; + walltype* best = nullptr; auto sect = tspr->sectp; - walltype* closest = nullptr; - int topz = (tspr->pos.Z - ((height * tspr->yrepeat) << 2)); for(auto& wal : wallsofsector(sect)) { // Intentionally include two sided walls. Even on them the sprite should be projected onto the wall for better results. @@ -72,16 +71,20 @@ 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. if (d.X == 0) { - if (fabs(tspr->pos.X - wal.pos.X) < maxorthdist) + double newdist = fabs(tspr->pos.X - wal.pos.X); + if (newdist < maxorthdist) { - return &wal; + maxorthdist = newdist; + best = &wal; } } else if (d.Y == 0) { - if (fabs(tspr->pos.Y - wal.pos.Y) < maxorthdist) + double newdist = fabs(tspr->pos.Y - wal.pos.Y); + if (newdist < maxorthdist) { - return &wal; + maxorthdist = newdist; + best = &wal; } } else @@ -94,7 +97,7 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos) } } } - return nullptr; + return best; } //==========================================================================