From 0bd1399c52afedd8d0da7a14526219fda35e48fe Mon Sep 17 00:00:00 2001
From: toaster <rollerorbital@gmail.com>
Date: Sat, 7 Dec 2019 10:22:10 +0000
Subject: [PATCH] Revert paperprojection, but keep it as a #define in case
 someone fixes it in a patch.

---
 src/p_mobj.c   |  2 +-
 src/r_things.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/src/p_mobj.c b/src/p_mobj.c
index c50ffe478..dea4a7a4d 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -7087,7 +7087,7 @@ static void P_SpawnMinecartSegments(mobj_t *mobj, boolean mode)
 		seg = P_SpawnMobj(x, y, z, MT_MINECARTSEG);
 		P_SetMobjState(seg, (statenum_t)(S_MINECARTSEG_FRONT + i));
 		if (i >= 2)
-			seg->extravalue1 = (i == 2) ? -20 : 20;
+			seg->extravalue1 = (i == 2) ? -18 : 18; // make -20/20 when papersprite projection fixed
 		else
 		{
 			seg->extravalue2 = (i == 0) ? 24 : -24;
diff --git a/src/r_things.c b/src/r_things.c
index 372368e85..3ba104ccd 100644
--- a/src/r_things.c
+++ b/src/r_things.c
@@ -1082,6 +1082,8 @@ static void R_SplitSprite(vissprite_t *sprite)
 	}
 }
 
+//#define PROPERPAPER // This was reverted less than 7 hours before 2.2's release because of very strange, frequent crashes.
+
 //
 // R_ProjectSprite
 // Generates a vissprite for a thing
@@ -1137,6 +1139,10 @@ static void R_ProjectSprite(mobj_t *thing)
 	UINT32 rollangle = AngleFixed(arollangle)>>FRACBITS;
 #endif
 
+#ifndef PROPERPAPER
+	fixed_t ang_scale = FRACUNIT;
+#endif
+
 	// transform the origin point
 	tr_x = thing->x - viewx;
 	tr_y = thing->y - viewy;
@@ -1221,6 +1227,10 @@ static void R_ProjectSprite(mobj_t *thing)
 	if (sprframe->rotate != SRF_SINGLE || papersprite)
 	{
 		ang = R_PointToAngle (thing->x, thing->y) - (thing->player ? thing->player->drawangle : thing->angle);
+#ifndef PROPERPAPER
+		if (papersprite)
+			ang_scale = abs(FINESINE(ang>>ANGLETOFINESHIFT));
+#endif
 	}
 
 	if (sprframe->rotate == SRF_SINGLE)
@@ -1282,11 +1292,31 @@ static void R_ProjectSprite(mobj_t *thing)
 	else
 		offset = -spr_offset;
 	offset = FixedMul(offset, this_scale);
+#ifndef PROPERPAPER
+	tx += FixedMul(offset, ang_scale);
+	x1 = (centerxfrac + FixedMul (tx,xscale)) >>FRACBITS;
+
+	// off the right side?
+	if (x1 > viewwidth)
+		return;
+#endif
 	offset2 = FixedMul(spr_width, this_scale);
+#ifndef PROPERPAPER
+	tx += FixedMul(offset2, ang_scale);
+	x2 = ((centerxfrac + FixedMul (tx,xscale)) >> FRACBITS) - (papersprite ? 2 : 1);
+
+	// off the left side
+	if (x2 < 0)
+		return;
+#endif
 
 	if (papersprite)
 	{
-		fixed_t xscale2, yscale2, cosmul, sinmul, tz2;
+		fixed_t
+#ifdef PROPERPAPER
+			xscale2,
+#endif
+					yscale2, cosmul, sinmul, tz2;
 		INT32 range;
 
 		if (ang >= ANGLE_180)
@@ -1306,6 +1336,7 @@ static void R_ProjectSprite(mobj_t *thing)
 		yscale = FixedDiv(projectiony, tz);
 		if (yscale < 64) return; // Fix some funky visuals
 
+#ifdef PROPERPAPER
 		gxt = -FixedMul(tr_x, viewsin);
 		gyt = FixedMul(tr_y, viewcos);
 		tx = -(gyt + gxt);
@@ -1315,6 +1346,7 @@ static void R_ProjectSprite(mobj_t *thing)
 		// off the right side?
 		if (x1 > viewwidth)
 			return;
+#endif
 
 		tr_x += FixedMul(offset2, cosmul);
 		tr_y += FixedMul(offset2, sinmul);
@@ -1324,6 +1356,7 @@ static void R_ProjectSprite(mobj_t *thing)
 		yscale2 = FixedDiv(projectiony, tz2);
 		if (yscale2 < 64) return; // ditto
 
+#ifdef PROPERPAPER
 		gxt = -FixedMul(tr_x, viewsin);
 		gyt = FixedMul(tr_y, viewcos);
 		tx = -(gyt + gxt);
@@ -1333,6 +1366,7 @@ static void R_ProjectSprite(mobj_t *thing)
 		// off the left side
 		if (x2 < 0)
 			return;
+#endif
 
 		if (max(tz, tz2) < FixedMul(MINZ, this_scale)) // non-papersprite clipping is handled earlier
 			return;
@@ -1340,10 +1374,18 @@ static void R_ProjectSprite(mobj_t *thing)
 		if ((range = x2 - x1) <= 0)
 			return;
 
+#ifdef PROPERPAPER
 		range++; // fencepost problem
+#endif
 
 		scalestep = (yscale2 - yscale)/range;
-		xscale = FixedDiv(range<<FRACBITS, abs(offset2));
+		xscale =
+#ifdef PROPERPAPER
+		FixedDiv(range<<FRACBITS, abs(offset2))+1
+#else
+		FixedMul(xscale, ang_scale)
+#endif
+		;
 
 		// The following two are alternate sorting methods which might be more applicable in some circumstances. TODO - maybe enable via MF2?
 		// sortscale = max(yscale, yscale2);
@@ -1353,6 +1395,7 @@ static void R_ProjectSprite(mobj_t *thing)
 	{
 		scalestep = 0;
 		yscale = sortscale;
+#ifdef PROPERPAPER
 		tx += offset;
 		x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS;
 
@@ -1366,6 +1409,7 @@ static void R_ProjectSprite(mobj_t *thing)
 		// off the left side
 		if (x2 < 0)
 			return;
+#endif
 	}
 
 	if ((thing->flags2 & MF2_LINKDRAW) && thing->tracer) // toast 16/09/16 (SYMMETRY)
-- 
GitLab