From d078b511b8705437529f8580b271afb98bbf7472 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 20 Apr 2021 00:28:52 +0200 Subject: [PATCH] - flip backwards oriented wall sprites before submitting them to the render list. Backwards orientation will break the translucent object sorter so this needs to be sorted out beforehand. --- source/core/gamefuncs.h | 6 ++++++ source/core/rendering/scene/hw_walls.cpp | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index f9f2432d9..2d0989aa1 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -91,6 +91,12 @@ inline double PointOnLineSide(const DVector2 &pos, const walltype *line) return (pos.X - WallStartX(line)) * WallDelta(line).Y - (pos.Y - WallStartY(line)) * WallDelta(line).X; } +template +inline double PointOnLineSide(const TVector2& pos, const TVector2& linestart, const TVector2& lineend) +{ + return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X); +} + inline int sectorofwall(int wallNum) { if ((unsigned)wallNum < (unsigned)numwalls) return wall[wallNum].sector; diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index 1d45dc2c4..d45ef6bfc 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -1089,7 +1089,6 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, spritetype* spr, sectortype* sect zbottom[0] = zbottom[1] = (sprz) * (1 / -256.); ztop[0] = ztop[1] = (sprz - ((height * spr->yrepeat) << 2)) * (1 / -256.); - // Clip sprites to ceilings/floors float origz = ztop[0]; float polyh = (zbottom[0] - origz); @@ -1113,5 +1112,16 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, spritetype* spr, sectortype* sect zbottom[0] = zbottom[1] = floorz; } } + + // If the sprite is backward, flip it around so that we have guaranteed orientation when this is about to be sorted. + if (PointOnLineSide(di->Viewpoint.Pos.XY(), DVector2(glseg.x1, glseg.y1), DVector2(glseg.x2, glseg.y2)) < 0) + { + std::swap(glseg.x1, glseg.x2); + std::swap(glseg.y1, glseg.y2); + // z is always the same on both sides. + std::swap(tcs[LOLFT], tcs[LORGT]); + std::swap(tcs[UPLFT], tcs[UPRGT]); + } + PutWall(di, spriteHasTranslucency(sprite)); } \ No newline at end of file