From fb9d07b8ba7955af94c6325536c5e8549bb07953 Mon Sep 17 00:00:00 2001
From: RedEnchilada <redenchilada@derpymail.com>
Date: Thu, 21 May 2015 22:13:51 -0500
Subject: [PATCH] Bugfixes to sloped FOF plane clipping

---
 src/r_bsp.c  | 13 +++++++++++--
 src/r_segs.c | 38 ++++++++++++++++++++++----------------
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/src/r_bsp.c b/src/r_bsp.c
index 35f82f01cf..5474a4345f 100644
--- a/src/r_bsp.c
+++ b/src/r_bsp.c
@@ -908,6 +908,9 @@ static void R_Subsector(size_t num)
 		ceilingplane = NULL;
 
 	numffloors = 0;
+#ifdef ESLOPE
+	ffloor[numffloors].slope = NULL;
+#endif
 	ffloor[numffloors].plane = NULL;
 	ffloor[numffloors].polyobj = NULL;
 	if (frontsector->ffloors)
@@ -945,7 +948,7 @@ static void R_Subsector(size_t num)
 #ifdef ESLOPE
 				light = R_GetPlaneLight(frontsector,
 					*rover->b_slope ? P_GetZAt(*rover->b_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->bottomheight,
-					viewz < (*rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : *rover->bottomheight));
+					viewz < heightcheck);
 #else
 				light = R_GetPlaneLight(frontsector, *rover->bottomheight,
 					viewz < *rover->bottomheight);
@@ -993,7 +996,7 @@ static void R_Subsector(size_t num)
 #ifdef ESLOPE
 				light = R_GetPlaneLight(frontsector,
 					*rover->t_slope ? P_GetZAt(*rover->t_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->topheight,
-					viewz < (*rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : *rover->topheight));
+					viewz < heightcheck);
 #else
 				light = R_GetPlaneLight(frontsector, *rover->topheight, viewz < *rover->topheight);
 #endif
@@ -1079,6 +1082,9 @@ static void R_Subsector(size_t num)
 
 				ffloor[numffloors].height = polysec->floorheight;
 				ffloor[numffloors].polyobj = po;
+#ifdef ESLOPE
+				ffloor[numffloors].slope = NULL;
+#endif
 //				ffloor[numffloors].ffloor = rover;
 				po->visplane = ffloor[numffloors].plane;
 				numffloors++;
@@ -1120,6 +1126,9 @@ static void R_Subsector(size_t num)
 
 				ffloor[numffloors].polyobj = po;
 				ffloor[numffloors].height = polysec->ceilingheight;
+#ifdef ESLOPE
+				ffloor[numffloors].slope = NULL;
+#endif
 //				ffloor[numffloors].ffloor = rover;
 				po->visplane = ffloor[numffloors].plane;
 				numffloors++;
diff --git a/src/r_segs.c b/src/r_segs.c
index ce0260a637..2d41d702c2 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -2650,7 +2650,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (*rover->b_slope || *rover->t_slope)
 						backsector->hasslope = true;
 
-					rovertest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
+					rovertest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, backsector->soundorg.x, backsector->soundorg.y) : *rover->bottomheight) - viewz;
 					planevistest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : *rover->bottomheight);
 
 					if (rovertest>>4 <= worldhigh &&
@@ -2658,9 +2658,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					    ((viewz < planevistest && !(rover->flags & FF_INVERTPLANES)) ||
 					     (viewz > planevistest && (rover->flags & FF_BOTHPLANES))))
 					{
-						ffloor[i].slope = *rover->b_slope;
-						ffloor[i].b_pos = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
-						ffloor[i].b_pos_slope = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segright.x, segright.y) : *rover->bottomheight) - viewz;
+						//ffloor[i].slope = *rover->b_slope;
+						ffloor[i].b_pos = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
+						ffloor[i].b_pos_slope = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) - viewz;
 						ffloor[i].b_pos >>= 4;
 						ffloor[i].b_pos_slope >>= 4;
 						ffloor[i].b_frac = (centeryfrac >> 4) - FixedMul(ffloor[i].b_pos, rw_scale);
@@ -2672,7 +2672,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (i >= MAXFFLOORS)
 						break;
 
-					rovertest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
+					rovertest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, backsector->soundorg.x, backsector->soundorg.y) : *rover->topheight) - viewz;
 					planevistest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : *rover->topheight);
 
 					if (rovertest>>4 <= worldhigh &&
@@ -2680,9 +2680,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					    ((viewz > planevistest && !(rover->flags & FF_INVERTPLANES)) ||
 					     (viewz < planevistest && (rover->flags & FF_BOTHPLANES))))
 					{
-						ffloor[i].slope = *rover->t_slope;
-						ffloor[i].b_pos = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
-						ffloor[i].b_pos_slope = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segright.x, segright.y) : *rover->topheight) - viewz;
+						//ffloor[i].slope = *rover->t_slope;
+						ffloor[i].b_pos = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
+						ffloor[i].b_pos_slope = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) - viewz;
 						ffloor[i].b_pos >>= 4;
 						ffloor[i].b_pos_slope >>= 4;
 						ffloor[i].b_frac = (centeryfrac >> 4) - FixedMul(ffloor[i].b_pos, rw_scale);
@@ -2735,7 +2735,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (*rover->b_slope || *rover->t_slope)
 						frontsector->hasslope = true;
 
-					rovertest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
+					rovertest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->bottomheight) - viewz;
 					planevistest = (*rover->b_slope ? P_GetZAt(*rover->b_slope, viewx, viewy) : *rover->bottomheight);
 
 					if (rovertest>>4 <= worldtop &&
@@ -2743,9 +2743,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					    ((viewz < planevistest && !(rover->flags & FF_INVERTPLANES)) ||
 					     (viewz > planevistest && (rover->flags & FF_BOTHPLANES))))
 					{
-						ffloor[i].slope = *rover->b_slope;
-						ffloor[i].b_pos = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
-						ffloor[i].b_pos_slope = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segright.x, segright.y) : *rover->bottomheight) - viewz;
+						//ffloor[i].slope = *rover->b_slope;
+						ffloor[i].b_pos = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segleft.x, segleft.y) : *rover->bottomheight) - viewz;
+						ffloor[i].b_pos_slope = (*rover->b_slope ? P_GetZAt(*rover->b_slope, segright.x, segright.y) : *rover->bottomheight) - viewz;
 						ffloor[i].b_pos >>= 4;
 						ffloor[i].b_pos_slope >>= 4;
 						ffloor[i].b_frac = (centeryfrac >> 4) - FixedMul(ffloor[i].b_pos, rw_scale);
@@ -2757,7 +2757,7 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (i >= MAXFFLOORS)
 						break;
 
-					rovertest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
+					rovertest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, frontsector->soundorg.x, frontsector->soundorg.y) : *rover->topheight) - viewz;
 					planevistest = (*rover->t_slope ? P_GetZAt(*rover->t_slope, viewx, viewy) : *rover->topheight);
 
 					if (rovertest>>4 <= worldtop &&
@@ -2765,9 +2765,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					    ((viewz > planevistest && !(rover->flags & FF_INVERTPLANES)) ||
 					     (viewz < planevistest && (rover->flags & FF_BOTHPLANES))))
 					{
-						ffloor[i].slope = *rover->t_slope;
-						ffloor[i].b_pos = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
-						ffloor[i].b_pos_slope = (ffloor[i].slope ? P_GetZAt(ffloor[i].slope, segright.x, segright.y) : *rover->topheight) - viewz;
+						//ffloor[i].slope = *rover->t_slope;
+						ffloor[i].b_pos = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segleft.x, segleft.y) : *rover->topheight) - viewz;
+						ffloor[i].b_pos_slope = (*rover->t_slope ? P_GetZAt(*rover->t_slope, segright.x, segright.y) : *rover->topheight) - viewz;
 						ffloor[i].b_pos >>= 4;
 						ffloor[i].b_pos_slope >>= 4;
 						ffloor[i].b_frac = (centeryfrac >> 4) - FixedMul(ffloor[i].b_pos, rw_scale);
@@ -2817,6 +2817,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (ffloor[i].plane->maxx < ds_p->x2)
 						ffloor[i].plane->maxx = ds_p->x2;
 
+#ifdef ESLOPE
+					ffloor[i].slope = NULL;
+#endif
 					ffloor[i].b_pos = backsector->floorheight;
 					ffloor[i].b_pos = (ffloor[i].b_pos - viewz) >> 4;
 					ffloor[i].b_step = FixedMul(-rw_scalestep, ffloor[i].b_pos);
@@ -2833,6 +2836,9 @@ void R_StoreWallRange(INT32 start, INT32 stop)
 					if (ffloor[i].plane->maxx < ds_p->x2)
 						ffloor[i].plane->maxx = ds_p->x2;
 
+#ifdef ESLOPE
+					ffloor[i].slope = NULL;
+#endif
 					ffloor[i].b_pos = backsector->ceilingheight;
 					ffloor[i].b_pos = (ffloor[i].b_pos - viewz) >> 4;
 					ffloor[i].b_step = FixedMul(-rw_scalestep, ffloor[i].b_pos);
-- 
GitLab