shithub: qk1

Download patch

ref: 9ca8a4f708e2d532e60a8d5ecc53f5c773187a31
parent: 2753cf990df25e4fa0799719d324dabe5bb95a8a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Dec 28 19:38:37 EST 2023

cmd: add "hidden" field to mark commands as hidden from completion; mark Nehahra fog aliases as such

--- a/cmd.c
+++ b/cmd.c
@@ -298,14 +298,6 @@
 =============================================================================
 */
 
-typedef struct cmd_function_s
-{
-	struct cmd_function_s	*next;
-	char					*name;
-	xcommand_t				function;
-} cmd_function_t;
-
-
 #define	MAX_ARGS		80
 
 static	int			cmd_argc;
@@ -419,18 +411,19 @@
 Cmd_AddCommand
 ============
 */
-void	Cmd_AddCommand (char *cmd_name, xcommand_t function)
+cmd_function_t *
+Cmd_AddCommand (char *cmd_name, xcommand_t function)
 {
 	cmd_function_t	*cmd;
 
 	if (host_initialized)	// because hunk allocation would get stomped
-		fatal ("Cmd_AddCommand after host_initialized");
+		fatal("Cmd_AddCommand after host_initialized");
 
 	// fail if the command is a variable name
 	if (Cvar_VariableString(cmd_name)[0])
 	{
 		Con_Printf ("Cmd_AddCommand: %s already defined as a var\n", cmd_name);
-		return;
+		return nil;
 	}
 
 	// fail if the command already exists
@@ -439,7 +432,7 @@
 		if(strcmp(cmd_name, cmd->name) == 0)
 		{
 			Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
-			return;
+			return cmd;
 		}
 	}
 
@@ -448,6 +441,7 @@
 	cmd->function = function;
 	cmd->next = cmd_functions;
 	cmd_functions = cmd;
+	return cmd;
 }
 
 /*
@@ -487,7 +481,7 @@
 
 	// check functions
 	for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
-		if(strncmp(partial, cmd->name, len) == 0)
+		if(strncmp(partial, cmd->name, len) == 0 && !cmd->hidden)
 			return cmd->name;
 
 	return nil;
--- a/cmd.h
+++ b/cmd.h
@@ -48,6 +48,14 @@
 
 typedef void (*xcommand_t) (void);
 
+typedef struct cmd_function_s
+{
+	struct cmd_function_s	*next;
+	char					*name;
+	xcommand_t				function;
+	bool hidden;
+} cmd_function_t;
+
 typedef enum
 {
 	src_client,		// came in over a net connection as a clc_stringcmd
@@ -59,7 +67,7 @@
 
 void	Cmd_Init (void);
 
-void	Cmd_AddCommand (char *cmd_name, xcommand_t function);
+cmd_function_t *Cmd_AddCommand (char *cmd_name, xcommand_t function);
 // called by the init functions of other parts of the program to
 // register commands and functions to call for them.
 // The cmd_name is referenced later, so it should not be in temp memory
--- a/r_fog.c
+++ b/r_fog.c
@@ -101,21 +101,39 @@
 		pix = vid.buffer + i;
 		z = d_pzbuffer + i;
 		for(x = r_refdef.vrect.x; x < r_refdef.vrectright; x++, i++, pix++, z++)
-			*pix = R_BlendFog(*pix, *z);
+			*pix = blend_fog(*pix, *z);
 	}
 }
 
+static void
+r_fog_cb(cvar_t *var)
+{
+	r_fog_data.allowed = var->value > 0.0;
+}
+
+static void
+r_skyfog_cb(cvar_t *var)
+{
+	if(var->value > 0.0)
+		r_fog_data.enabled |= Enskyfog;
+	else
+		r_fog_data.enabled &= ~Enskyfog;
+	r_fog_data.sky = 255 * clamp(var->value, 0.0, 1.0);
+}
+
 void
 R_InitFog(void)
 {
+	r_fog.cb = r_fog_cb;
+	r_skyfog.cb = r_skyfog_cb;
 	Cmd_AddCommand("fog", fog);
 	Cvar_RegisterVariable(&r_fog);
 	Cvar_RegisterVariable(&r_skyfog);
 
 	// Nehahra
-	Cmd_AddCommand("gl_fogenable", fog);
-	Cmd_AddCommand("gl_fogdensity", fog);
-	Cmd_AddCommand("gl_fogred", fog);
-	Cmd_AddCommand("gl_foggreen", fog);
-	Cmd_AddCommand("gl_fogblue", fog);
+	Cmd_AddCommand("gl_fogenable", fog)->hidden = true;
+	Cmd_AddCommand("gl_fogdensity", fog)->hidden = true;
+	Cmd_AddCommand("gl_fogred", fog)->hidden = true;
+	Cmd_AddCommand("gl_foggreen", fog)->hidden = true;
+	Cmd_AddCommand("gl_fogblue", fog)->hidden = true;
 }