From e4b04b16f90e1ce3525c0466cc2ef9541c177c8e Mon Sep 17 00:00:00 2001
From: Sky Dusk <47698279+Ace-Lite@users.noreply.github.com>
Date: Wed, 5 Feb 2025 20:39:59 +0100
Subject: [PATCH 1/3] HUD ONLY removed and copy functions into hudlib. We are
 testing this, no guardrails.

---
 src/lua_hudlib.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index c8327658a6..b8833bf721 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -461,14 +461,12 @@ static int camera_set(lua_State *L)
 
 static int libd_patchExists(lua_State *L)
 {
-	HUDONLY
 	lua_pushboolean(L, W_LumpExists(luaL_checkstring(L, 1)));
 	return 1;
 }
 
 static int libd_cachePatch(lua_State *L)
 {
-	HUDONLY
 	LUA_PushUserdata(L, W_CachePatchLongName(luaL_checkstring(L, 1), PU_PATCH), META_PATCH);
 	return 1;
 }
@@ -481,7 +479,6 @@ static int libd_getSpritePatch(lua_State *L)
 	UINT8 angle = 0;
 	spritedef_t *sprdef;
 	spriteframe_t *sprframe;
-	HUDONLY
 
 	if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK
 	{
@@ -555,7 +552,6 @@ static int libd_getSprite2Patch(lua_State *L)
 	spritedef_t *sprdef;
 	spriteframe_t *sprframe;
 	boolean super = false; // add SPR2F_SUPER to sprite2 if true
-	HUDONLY
 
 	// get skin first!
 	if (lua_isnumber(L, 1)) // find skin by number
@@ -1135,8 +1131,6 @@ static int libd_getColormap(lua_State *L)
 	UINT8* colormap = NULL;
 	int translation_id = -1;
 
-	HUDONLY
-
 	if (lua_isnoneornil(L, 1))
 		; // defaults to TC_DEFAULT
 	else if (lua_type(L, 1) == LUA_TNUMBER) // skin number
@@ -1178,7 +1172,7 @@ static int libd_getStringColormap(lua_State *L)
 {
 	INT32 flags = luaL_checkinteger(L, 1);
 	UINT8* colormap = NULL;
-	HUDONLY
+
 	colormap = V_GetStringColormap(flags & V_CHARCOLORMASK);
 	if (colormap) {
 		LUA_PushUserdata(L, colormap, META_COLORMAP); // push as META_COLORMAP userdata, specifically for patches to use!
@@ -1264,21 +1258,18 @@ static int libd_fadeScreen(lua_State *L)
 
 static int libd_width(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, vid.width); // push screen width
 	return 1;
 }
 
 static int libd_height(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, vid.height); // push screen height
 	return 1;
 }
 
 static int libd_dup(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, vid.dup); // push integral scale (patch scale)
 	lua_pushfixed(L, vid.fdup); // push fixed point scale (position scale)
 	return 2;
@@ -1286,7 +1277,6 @@ static int libd_dup(lua_State *L)
 
 static int libd_renderer(lua_State *L)
 {
-	HUDONLY
 	switch (rendermode) {
 		case render_opengl: lua_pushliteral(L, "opengl");   break; // OpenGL renderer
 		case render_soft:   lua_pushliteral(L, "software"); break; // Software renderer
@@ -1300,14 +1290,12 @@ static int libd_renderer(lua_State *L)
 
 static int libd_RandomFixed(lua_State *L)
 {
-	HUDONLY
 	lua_pushfixed(L, M_RandomFixed());
 	return 1;
 }
 
 static int libd_RandomByte(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, M_RandomByte());
 	return 1;
 }
@@ -1316,7 +1304,6 @@ static int libd_RandomKey(lua_State *L)
 {
 	INT32 a = (INT32)luaL_checkinteger(L, 1);
 
-	HUDONLY
 	lua_pushinteger(L, M_RandomKey(a));
 	return 1;
 }
@@ -1326,7 +1313,6 @@ static int libd_RandomRange(lua_State *L)
 	INT32 a = (INT32)luaL_checkinteger(L, 1);
 	INT32 b = (INT32)luaL_checkinteger(L, 2);
 
-	HUDONLY
 	lua_pushinteger(L, M_RandomRange(a, b));
 	return 1;
 }
@@ -1334,7 +1320,6 @@ static int libd_RandomRange(lua_State *L)
 // Macros.
 static int libd_SignedRandom(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, M_SignedRandom());
 	return 1;
 }
@@ -1342,7 +1327,6 @@ static int libd_SignedRandom(lua_State *L)
 static int libd_RandomChance(lua_State *L)
 {
 	fixed_t p = luaL_checkfixed(L, 1);
-	HUDONLY
 	lua_pushboolean(L, M_RandomChance(p));
 	return 1;
 }
@@ -1351,7 +1335,6 @@ static int libd_RandomChance(lua_State *L)
 // Could as well be thrown in global vars for ease of access but I guess it makes sense for it to be a HUD fn
 static int libd_getlocaltransflag(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, (10-st_translucency)*V_10TRANS);
 	return 1;
 }
@@ -1359,7 +1342,6 @@ static int libd_getlocaltransflag(lua_State *L)
 // Get cv_translucenthud's value for HUD rendering as a normal V_xxTRANS int
 static int libd_getusertransflag(lua_State *L)
 {
-	HUDONLY
 	lua_pushinteger(L, (10-cv_translucenthud.value)*V_10TRANS);	// A bit weird that it's called "translucenthud" yet 10 is fully opaque :V
 	return 1;
 }
@@ -1452,6 +1434,24 @@ static luaL_Reg lib_hud[] = {
 	{"disable", lib_huddisable},
 	{"enabled", lib_hudenabled},
 	{"add", lib_hudadd},
+	{"patchExists", libd_patchExists},
+	{"cachePatch", libd_cachePatch},
+	{"getSpritePatch", libd_getSpritePatch},
+	{"getSprite2Patch", libd_getSprite2Patch},
+	{"getColormap", libd_getColormap},
+	{"getStringColormap", libd_getStringColormap},
+	{"width", libd_width},
+	{"height", libd_height},
+	{"scale", libd_dup},
+	{"renderer", libd_renderer},
+	{"RandomFixed",libd_RandomFixed},
+	{"RandomByte",libd_RandomByte},
+	{"RandomKey",libd_RandomKey},
+	{"RandomRange",libd_RandomRange},
+	{"SignedRandom",libd_SignedRandom}, // MACRO
+	{"RandomChance",libd_RandomChance}, // MACRO
+	{"localTransFlag", libd_getlocaltransflag},
+	{"userTransFlag", libd_getusertransflag},
 	{NULL, NULL}
 };
 
-- 
GitLab


From d4179f9a808b2ca89d0affb6b04e13d3bae07659 Mon Sep 17 00:00:00 2001
From: Sky Dusk <47698279+Ace-Lite@users.noreply.github.com>
Date: Wed, 5 Feb 2025 21:29:36 +0100
Subject: [PATCH 2/3] Moving stuff to brand new random library.

---
 src/lua_hudlib.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index b8833bf721..ce686b2451 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -1444,14 +1444,18 @@ static luaL_Reg lib_hud[] = {
 	{"height", libd_height},
 	{"scale", libd_dup},
 	{"renderer", libd_renderer},
-	{"RandomFixed",libd_RandomFixed},
-	{"RandomByte",libd_RandomByte},
-	{"RandomKey",libd_RandomKey},
-	{"RandomRange",libd_RandomRange},
-	{"SignedRandom",libd_SignedRandom}, // MACRO
-	{"RandomChance",libd_RandomChance}, // MACRO
-	{"localTransFlag", libd_getlocaltransflag},
-	{"userTransFlag", libd_getusertransflag},
+	{NULL, NULL}
+};
+
+// globalized client_side random functions.
+static luaL_Reg lib_randomclient[] = {
+	// m_random
+	{"localfixed",libd_RandomFixed},
+	{"localbyte",libd_RandomByte},
+	{"localkey",libd_RandomKey},
+	{"localrange",libd_RandomRange},
+	{"localsignedrandom",libd_SignedRandom}, // MACRO
+	{"localchance",libd_RandomChance}, // MACRO
 	{NULL, NULL}
 };
 
@@ -1478,6 +1482,7 @@ int LUA_HudLib(lua_State *L)
 	LUA_RegisterGlobalUserdata(L, "hudinfo", lib_getHudInfo, NULL, lib_hudinfolen);
 
 	luaL_register(L, "hud", lib_hud);
+	luaL_register(L, "random", lib_randomclient);
 	return 0;
 }
 
-- 
GitLab


From 9132f690619d16051cf194f42bf6384612224685 Mon Sep 17 00:00:00 2001
From: Skydusk <lightacecz@gmail.com>
Date: Sat, 5 Apr 2025 20:05:15 +0000
Subject: [PATCH 3/3] Removed getColormap && getStringColormap from hud library
 (not draw library).

---
 src/lua_hudlib.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index ce686b2451..9bcbcce4fe 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -1126,6 +1126,7 @@ static int libd_levelTitleHeight(lua_State *L)
 
 static int libd_getColormap(lua_State *L)
 {
+	HUDONLY
 	INT32 skinnum = TC_DEFAULT;
 	skincolornum_t color = luaL_optinteger(L, 2, 0);
 	UINT8* colormap = NULL;
@@ -1170,6 +1171,7 @@ static int libd_getColormap(lua_State *L)
 
 static int libd_getStringColormap(lua_State *L)
 {
+	HUDONLY
 	INT32 flags = luaL_checkinteger(L, 1);
 	UINT8* colormap = NULL;
 
@@ -1183,6 +1185,7 @@ static int libd_getStringColormap(lua_State *L)
 
 static int libd_getSectorColormap(lua_State *L)
 {
+	HUDONLY
 	boolean has_sector = false;
 	sector_t *sector = NULL;
 	if (!lua_isnoneornil(L, 1))
@@ -1438,8 +1441,6 @@ static luaL_Reg lib_hud[] = {
 	{"cachePatch", libd_cachePatch},
 	{"getSpritePatch", libd_getSpritePatch},
 	{"getSprite2Patch", libd_getSprite2Patch},
-	{"getColormap", libd_getColormap},
-	{"getStringColormap", libd_getStringColormap},
 	{"width", libd_width},
 	{"height", libd_height},
 	{"scale", libd_dup},
-- 
GitLab