From d67ea859e3a680c5f5a0d1028cbacacfe980369a Mon Sep 17 00:00:00 2001
From: Sryder <sryder13@gmail.com>
Date: Mon, 24 Jun 2019 20:06:53 +0100
Subject: [PATCH] Match CheckClip to software's clipping check in R_AddLine Has
 the added benefit of fixing noclip camera for opengl Unfortunately SkyWalls
 are kinda broken with this. I'll be looking into them shortly.

---
 src/hardware/hw_main.c | 75 +++++++++++++++++-------------------------
 1 file changed, 30 insertions(+), 45 deletions(-)

diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index 8863de931..ef623d9b9 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -2421,62 +2421,47 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks
 		backc1 = backc2 = abacksector->ceilingheight;
 	}
 
-	// now check for closed sectors!
-	if (backc1 <= frontf1 && backc2 <= frontf2)
+	if (viewsector != abacksector && viewsector != afrontsector)
 	{
-		checkforemptylines = false;
-		if (!seg->sidedef->toptexture)
-			return false;
-
-		if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum)
-			return false;
-
-		return true;
-	}
-
-	if (backf1 >= frontc1 && backf2 >= frontc2)
-	{
-		checkforemptylines = false;
-		if (!seg->sidedef->bottomtexture)
-			return false;
+		boolean mydoorclosed = false; // My door? Closed!? (doorclosed is actually otherwise unused in openGL)
 
-		// properly render skies (consider door "open" if both floors are sky):
-		if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum)
-			return false;
-
-		return true;
-	}
-
-	if (backc1 <= backf1 && backc2 <= backf2)
-	{
-		checkforemptylines = false;
-		// preserve a kind of transparent door/lift special effect:
-		if (backc1 < frontc1 || backc2 < frontc2)
+		// If the sector behind the line blocks all kinds of view past it
+		// (back ceiling is lower than close floor, or back floor is higher than close ceiling)
+		if ((backc1 <= frontf1 && backc2 <= frontf2)
+			|| (backf1 >= frontc1 && backf2 >= frontc2))
 		{
-			if (!seg->sidedef->toptexture)
-				return false;
+			checkforemptylines = false;
+			return true;
 		}
-		if (backf1 > frontf1 || backf2 > frontf2)
+
+		// The door is closed if:
+		// backsector is 0 height or less and
+		// back ceiling is higher than close ceiling or we need to render a top texture and
+		// back floor is lower than close floor or we need to render a bottom texture and
+		// neither front or back sectors are using the sky ceiling
+		mydoorclosed = (backc1 <= backf1 && backc2 <= backf2
+		&& ((backc1 >= frontc1 && backc2 >= frontc2) || seg->sidedef->toptexture)
+		&& ((backf1 <= frontf1 && backf2 >= frontf2) || seg->sidedef->bottomtexture)
+		&& (abacksector->ceilingpic != skyflatnum || afrontsector->ceilingpic != skyflatnum));
+
+		if (mydoorclosed)
 		{
-			if (!seg->sidedef->bottomtexture)
-				return false;
+			checkforemptylines = false;
+			return true;
 		}
-		if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum)
-			return false;
-
-		if (abacksector->floorpic == skyflatnum && afrontsector->floorpic == skyflatnum)
-			return false;
-
-		return true;
 	}
 
+	// Window.
+	// We know it's a window when the above isn't true and the back and front sectors don't match
 	if (backc1 != frontc1 || backc2 != frontc2
 		|| backf1 != frontf1 || backf2 != frontf2)
-		{
-			checkforemptylines = false;
-			return false;
-		}
+	{
+		checkforemptylines = false;
+		return false;
+	}
 
+	// In this case we just need to check whether there is actually a need to render any lines, so checkforempty lines
+	// stays true
 	return false;
 }
 #else
-- 
GitLab