From a4042cab4f3234a008073fa9ecd0e567913b97fc Mon Sep 17 00:00:00 2001
From: sphere <spherallic@gmail.com>
Date: Sat, 5 Jun 2021 14:43:46 +0200
Subject: [PATCH] Use blend mode constants instead of hardcoded action numbers.

---
 src/hardware/hw_main.c |  8 ++------
 src/p_setup.c          | 12 ++++++++++++
 src/r_defs.h           |  1 +
 src/r_segs.c           | 18 +++---------------
 4 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c
index 066822e8c7..5171ab435a 100644
--- a/src/hardware/hw_main.c
+++ b/src/hardware/hw_main.c
@@ -1494,12 +1494,8 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
 					transnum_t transtable = R_GetLinedefTransTable(gl_linedef);
 					if (transtable == NUMTRANSMAPS)
 						transtable = 0;
-					if (gl_linedef->special >= 910 && gl_linedef->special <= 919)
-						blend = AST_ADD;
-					else if (gl_linedef->special >= 920 && gl_linedef->special <= 929)
-						blend = AST_SUBTRACT;
-					else if (gl_linedef->special >= 930 && gl_linedef->special <= 939)
-						blend = AST_REVERSESUBTRACT;
+					if (gl_linedef->blendmode == AST_ADD || gl_linedef->blendmode == AST_SUBTRACT || gl_linedef->blendmode == AST_REVERSESUBTRACT)
+						blend = gl_linedef->blendmode;
 
 					blendmode = HWR_SurfaceBlend(blend, transtable, &Surf);
 					break;
diff --git a/src/p_setup.c b/src/p_setup.c
index 0ffc807f5f..744ec3c55f 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -3156,6 +3156,18 @@ static void P_ConvertBinaryMap(void)
 		if (lines[i].special >= 910 && lines[i].special <= 939)
 			lines[i].alpha = ((10 - lines[i].special % 10) << FRACBITS)/10;
 
+		if (lines[i].special >= 910 && lines[i].special <= 919) // additive
+			lines[i].blendmode = AST_ADD;
+
+		if (lines[i].special >= 920 && lines[i].special <= 929) // subtractive
+			lines[i].blendmode = AST_SUBTRACT;
+
+		if (lines[i].special >= 930 && lines[i].special <= 939) // reverse subtractive
+			lines[i].blendmode = AST_REVERSESUBTRACT;
+
+		if (lines[i].special == 940) // modulate
+			lines[i].blendmode = AST_MODULATE;
+
 		//Linedef executor delay
 		if (lines[i].special >= 400 && lines[i].special < 500)
 		{
diff --git a/src/r_defs.h b/src/r_defs.h
index 681bb36198..16912fca1e 100644
--- a/src/r_defs.h
+++ b/src/r_defs.h
@@ -398,6 +398,7 @@ typedef struct line_s
 	// Visual appearance: sidedefs.
 	UINT16 sidenum[2]; // sidenum[1] will be 0xffff if one-sided
 	fixed_t alpha; // translucency
+	UINT8 blendmode; // blendmode
 	INT32 executordelay;
 
 	fixed_t bbox[4]; // bounding box for the extent of the linedef
diff --git a/src/r_segs.c b/src/r_segs.c
index 209810059e..0b9c9a80ed 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -162,25 +162,13 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2)
 		return;
 
 	transtable = R_GetLinedefTransTable(ldef);
-	if (ldef->special >= 910 && ldef->special <= 919)
+	if (ldef->blendmode == AST_ADD || ldef->blendmode == AST_SUBTRACT || ldef->blendmode == AST_REVERSESUBTRACT)
 	{
 		if (transtable == NUMTRANSMAPS)
 			transtable = 0;
-		blendmode = AST_ADD;
+		blendmode = ldef->blendmode;
 	}
-	else if (ldef->special >= 920 && ldef->special <= 929)
-	{
-		if (transtable == NUMTRANSMAPS)
-			transtable = 0;
-		blendmode = AST_SUBTRACT;
-	}
-	else if (ldef->special >= 930 && ldef->special <= 939)
-	{
-		if (transtable == NUMTRANSMAPS)
-			transtable = 0;
-		blendmode = AST_REVERSESUBTRACT;
-	}
-	else if (ldef->special == 940)
+	else if (ldef->blendmode == AST_MODULATE)
 	{
 		transtable = 0;
 		blendmode = AST_MODULATE;
-- 
GitLab