From 23640988dbccca885de66d4ed951fb024bed09ce Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Sat, 3 Dec 2022 15:01:21 +0100
Subject: [PATCH] - define several of RR's fullbright decorative sprites via
 spawnclasses remapping.

---
 source/core/maptypes.h                        |  1 +
 source/core/rendering/scene/hw_drawinfo.cpp   |  2 +
 source/games/duke/src/animatesprites_r.cpp    | 43 -------------------
 source/games/duke/src/gameexec.cpp            |  1 +
 source/games/duke/src/spawn.cpp               |  5 +++
 .../redneck.ridesagain/engine/engine.def      | 10 ++++-
 .../static/filter/redneck/engine/engine.def   | 35 ++++++++++++++-
 7 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/source/core/maptypes.h b/source/core/maptypes.h
index 19f564a5a..ca3ca0fcf 100644
--- a/source/core/maptypes.h
+++ b/source/core/maptypes.h
@@ -184,6 +184,7 @@ enum ESpriteBits2
 	CSTAT2_SPRITE_MAPPED = 2,		// sprite was mapped for automap
 	CSTAT2_SPRITE_NOSHADOW = 4,		// cast no shadow.
 	CSTAT2_SPRITE_DECAL = 8,		// always attached to a wall.
+	CSTAT2_SPRITE_FULLBRIGHT = 16,	// always draw fullbright with shade -127
 };
 
 // tsprite flags use the otherwise unused clipdist field.
diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp
index 02a788e58..44eb2f0fc 100644
--- a/source/core/rendering/scene/hw_drawinfo.cpp
+++ b/source/core/rendering/scene/hw_drawinfo.cpp
@@ -285,6 +285,8 @@ void HWDrawInfo::DispatchSprites()
 
 		if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB)
 			tileUpdatePicnum(&tilenum, false, (actor->GetIndex() & 16383));
+		if (tspr->cstat2 & CSTAT2_SPRITE_FULLBRIGHT)
+			tspr->shade = -127;
 		tspr->picnum = tilenum;
 		gotpic.Set(tilenum);
 
diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp
index cd1e2827c..cf4501ae7 100644
--- a/source/games/duke/src/animatesprites_r.cpp
+++ b/source/games/duke/src/animatesprites_r.cpp
@@ -552,49 +552,6 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi
 				t->pos.Z = t->sectp->floorz;
 			t->shade = -127;
 			break;
-		case WALLLIGHT3:
-		case WALLLIGHT1:
-
-			// none of these are active
-		case RRTILE3668:
-		case RRTILE3795:
-		case RRTILE7505:
-		case RRTILE7506:
-			if (!isRRRA()) break;
-			[[fallthrough]];
-		case RRTILE1878:
-		case RRTILE1952:
-		case RRTILE1953:
-		case RRTILE1990:
-		case RRTILE2050:
-		case RRTILE2056:
-		case RRTILE2072:
-		case RRTILE2075:
-		case RRTILE2083:
-		case RRTILE2097:
-		case RRTILE2357:
-		case RRTILE2564:
-		case RRTILE2573:
-		case RRTILE2574:
-		case RRTILE2583:
-		case RRTILE2604:
-		case RRTILE2689:
-		case RRTILE2893:
-		case RRTILE2894:
-		case RRTILE2915:
-		case RRTILE2945:
-		case RRTILE2946:
-		case RRTILE2947:
-		case RRTILE2948:
-		case RRTILE2949:
-		case RRTILE2977:
-		case RRTILE2978:
-		case RRTILE3116:
-		case RRTILE3171:
-		case RRTILE3216:
-		case RRTILE3720:
-			t->shade = -127;
-			break;
 		case CHEER:
 			if (!isRRRA()) break;
 			if (t->picnum >= CHEER + 102 && t->picnum <= CHEER + 151)
diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp
index 98ee5ae82..2aa4824ed 100644
--- a/source/games/duke/src/gameexec.cpp
+++ b/source/games/duke/src/gameexec.cpp
@@ -3672,6 +3672,7 @@ void LoadActor(DDukeActor *actor, int p, int x)
 	s.g_ac = actor;
 	s.g_t = &s.g_ac->temp_data[0];	// Sprite's 'extra' data
 
+	if (actor->spr.picnum < 0 || actor->spr.picnum >= MAXTILES) return;
 	auto addr = gs.tileinfo[actor->spr.picnum].loadeventscriptptr;
 	if (addr == 0) return;
 
diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp
index a3d447a21..90b7c8c71 100644
--- a/source/games/duke/src/spawn.cpp
+++ b/source/games/duke/src/spawn.cpp
@@ -59,6 +59,11 @@ void setFromSpawnRec(DDukeActor* act, SpawnRec* info)
 			act->spr.inittype = info->flags;
 			if (info->clipdist > 0) act->spr.clipdist = info->clipdist;
 		}
+		else
+		{
+			if (info->basetex >= 0 && info->basetex < MAXTILES) act->spr.picnum = info->basetex;
+			if (info->fullbright & 1) act->spr.cstat2 |= CSTAT2_SPRITE_FULLBRIGHT;
+		}
 	}
 }
 
diff --git a/wadsrc/static/filter/redneck.ridesagain/engine/engine.def b/wadsrc/static/filter/redneck.ridesagain/engine/engine.def
index cb87f7e93..da5fc3a59 100644
--- a/wadsrc/static/filter/redneck.ridesagain/engine/engine.def
+++ b/wadsrc/static/filter/redneck.ridesagain/engine/engine.def
@@ -150,6 +150,13 @@ spawnclasses
 	8462 = DukeGenericDestructible, "RRTILE8462", "RRTILE5074", "GLASS_HEAVYBREAK"
 	8682 = DukeGenericDestructible, "RRTILE8682", "RRTILE8683", "GLASS_HEAVYBREAK"
 	1824 = DukeGenericDestructible, "YELLOWBOTTLE", "", "GLASS_HEAVYBREAK", spawnglass2
+	244 = DukeActor, "*WALLLIGHT3"
+	246 = DukeActor, "*WALLLIGHT1"
+	3668 = DukeActor, "*RRTILE3668"
+	3795 = DukeActor, "*RRTILE3795"
+	7505 = DukeActor, "*RRTILE7505"
+	7506 = DukeActor, "*RRTILE7506"
+
 }
 
 tileflag TFLAG_WALLSWITCH {
@@ -181,4 +188,5 @@ tileflag TFLAG_BLOCKDOOR {
 	RRTILE8380
 	RRTILE8565
 	RRTILE8605
-	}
\ No newline at end of file
+	}
+	
\ No newline at end of file
diff --git a/wadsrc/static/filter/redneck/engine/engine.def b/wadsrc/static/filter/redneck/engine/engine.def
index 5deb51a0d..b34a2814f 100644
--- a/wadsrc/static/filter/redneck/engine/engine.def
+++ b/wadsrc/static/filter/redneck/engine/engine.def
@@ -227,6 +227,39 @@ spawnclasses
 	2654 = DukeGenericDestructible, "RRTILE2654", "", "GLASS_BREAKING", spawnglass
 	2656 = DukeGenericDestructible, "RRTILE2656", "", "GLASS_BREAKING", spawnglass
 	3172 = DukeGenericDestructible, "RRTILE3172", "", "GLASS_BREAKING", spawnglass
+	
+	1878 = DukeActor, "*RRTILE1878"
+	1952 = DukeActor, "*RRTILE1952"
+	1953 = DukeActor, "*RRTILE1953"
+	1990 = DukeActor, "*RRTILE1990"
+	2050 = DukeActor, "*RRTILE2050"
+	2056 = DukeActor, "*RRTILE2056"
+	2072 = DukeActor, "*RRTILE2072"
+	2075 = DukeActor, "*RRTILE2075"
+	2083 = DukeActor, "*RRTILE2083"
+	2097 = DukeActor, "*RRTILE2097"
+	2357 = DukeActor, "*RRTILE2357"
+	2564 = DukeActor, "*RRTILE2564"
+	2573 = DukeActor, "*RRTILE2573"
+	2574 = DukeActor, "*RRTILE2574"
+	2583 = DukeActor, "*RRTILE2583"
+	2604 = DukeActor, "*RRTILE2604"
+	2689 = DukeActor, "*RRTILE2689"
+	2893 = DukeActor, "*RRTILE2893"
+	2894 = DukeActor, "*RRTILE2894"
+	2915 = DukeActor, "*RRTILE2915"
+	2945 = DukeActor, "*RRTILE2945"
+	2946 = DukeActor, "*RRTILE2946"
+	2947 = DukeActor, "*RRTILE2947"
+	2948 = DukeActor, "*RRTILE2948"
+	2949 = DukeActor, "*RRTILE2949"
+	2977 = DukeActor, "*RRTILE2977"
+	2978 = DukeActor, "*RRTILE2978"
+	3116 = DukeActor, "*RRTILE3116"
+	3171 = DukeActor, "*RRTILE3171"
+	3216 = DukeActor, "*RRTILE3216"
+	3720 = DukeActor, "*RRTILE3720"
+	
 }
 
 
@@ -392,4 +425,4 @@ tileflag TFLAG_BLOCKDOOR {
 	}
 
 tileflag TFLAG_MUDDY { MUDDY MUDDYPATH }
-	
\ No newline at end of file
+