From da3f8ceb8dad9d03d0f1032a7bd2fbced3c67163 Mon Sep 17 00:00:00 2001
From: toasterbabe <rollerorbital@gmail.com>
Date: Mon, 12 Feb 2018 18:23:57 +0000
Subject: [PATCH] * Move the non-mapping drawFill out of the source code
 function and into the Lua interface. * Add a drawFill fallback for COLORMAP
 too. * Correct a few index mishaps.

---
 src/lua_hudlib.c |  9 ++++++++-
 src/v_video.c    | 10 ++--------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index c592cc2f12..6991f00e70 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -683,15 +683,22 @@ static int libd_fadeScreen(lua_State *L)
 {
 	UINT16 color = luaL_checkinteger(L, 1);
 	UINT8 strength = luaL_checkinteger(L, 2);
-	const UINT8 maxstrength = ((color & 0xFF00) ? 31 : 9);
+	const UINT8 maxstrength = ((color & 0xFF00) ? 32 : 10);
 
 	HUDONLY
+
 	if (!strength)
 		return 0;
 
 	if (strength > maxstrength)
 		return luaL_error(L, "%s fade strength %d out of range (0 - %d)", ((color & 0xFF00) ? "COLORMAP" : "TRANSMAP"), strength, maxstrength);
 
+	if (strength == maxstrength) // Allow as a shortcut for drawfill...
+	{
+		V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, ((color & 0xFF00) ? 31 : color));
+		return 0;
+	}
+
 	V_DrawFadeScreen(color, strength);
 	return 0;
 }
diff --git a/src/v_video.c b/src/v_video.c
index daf0514d54..47142484db 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -1321,7 +1321,7 @@ void V_DrawPatchFill(patch_t *pat)
 //
 // Fade all the screen buffer, so that the menu is more readable,
 // especially now that we use the small hufont in the menus...
-// If color is 0x00 to 0xFF, draw transtable (strength range 0-10).
+// If color is 0x00 to 0xFF, draw transtable (strength range 0-9).
 // Else, use COLORMAP lump (strength range 0-31).
 // IF YOU ARE NOT CAREFUL, THIS CAN AND WILL CRASH!
 // I have kept the safety checks out of this function;
@@ -1332,12 +1332,6 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
 	if (!strength)
 		return;
 
-	if (!(color & 0xFF00) && strength == 10)
-	{
-		V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, color);
-		return;
-	}
-
 #ifdef HWRENDER
 	if (rendermode != render_soft && rendermode != render_none)
 	{
@@ -1349,7 +1343,7 @@ void V_DrawFadeScreen(UINT16 color, UINT8 strength)
 	{
 		const UINT8 *fadetable = ((color & 0xFF00) // Color is not palette index?
 		? ((UINT8 *)colormaps + strength*256) // Do COLORMAP fade.
-		: ((UINT8 *)transtables + ((10-strength)<<FF_TRANSSHIFT) + color*256)); // Else, do TRANSMAP** fade.
+		: ((UINT8 *)transtables + ((9-strength)<<FF_TRANSSHIFT) + color*256)); // Else, do TRANSMAP** fade.
 		const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
 		UINT8 *buf = screens[0];
 
-- 
GitLab