]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Remove code duplication in messagemodes and commandmode
authorbones_was_here <bones_was_here@xonotic.au>
Sat, 14 Jan 2023 08:40:37 +0000 (18:40 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 14 Jan 2023 08:40:37 +0000 (18:40 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
console.c
keys.c
keys.h

index 83b969dd65f8ba293ed8246a72f1895fb159fd0c..58409bef3164a3b9e012ea42b43a04ae8b5ae51d 100644 (file)
--- a/console.c
+++ b/console.c
@@ -711,18 +711,12 @@ void Con_ClearNotify (void)
                        CON_LINES(i).mask |= CON_MASK_HIDENOTIFY;
 }
 
-
-/*
-================
-Con_MessageMode_f
-================
-*/
-static void Con_MessageMode_f(cmd_state_t *cmd)
+static void Con_MsgCmdMode(cmd_state_t *cmd, signed char mode)
 {
-       if (cls.demoplayback)
+       if (cls.demoplayback && mode >= 0)
                return;
        key_dest = key_message;
-       chat_mode = 0; // "say"
+       chat_mode = mode;
        if(Cmd_Argc(cmd) > 1)
        {
                dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
@@ -730,23 +724,28 @@ static void Con_MessageMode_f(cmd_state_t *cmd)
        }
 }
 
+/*
+================
+Con_MessageMode_f
+
+"say"
+================
+*/
+static void Con_MessageMode_f(cmd_state_t *cmd)
+{
+       Con_MsgCmdMode(cmd, 0);
+}
 
 /*
 ================
 Con_MessageMode2_f
+
+"say_team"
 ================
 */
 static void Con_MessageMode2_f(cmd_state_t *cmd)
 {
-       if (cls.demoplayback)
-               return;
-       key_dest = key_message;
-       chat_mode = 1; // "say_team"
-       if(Cmd_Argc(cmd) > 1)
-       {
-               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
-               chat_bufferpos = (unsigned int)strlen(chat_buffer);
-       }
+       Con_MsgCmdMode(cmd, 1);
 }
 
 /*
@@ -756,13 +755,7 @@ Con_CommandMode_f
 */
 static void Con_CommandMode_f(cmd_state_t *cmd)
 {
-       key_dest = key_message;
-       if(Cmd_Argc(cmd) > 1)
-       {
-               dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args(cmd));
-               chat_bufferpos = (unsigned int)strlen(chat_buffer);
-       }
-       chat_mode = -1; // command
+       Con_MsgCmdMode(cmd, -1);
 }
 
 /*
diff --git a/keys.c b/keys.c
index cef9dc91d2e21286aed5e1d02702230b34fb9e74..bcf1c916f0826eed2f9f61748a5876392886bd37 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -694,7 +694,7 @@ Interactive line editing and console scrollback
 ====================
 */
 
-int chat_mode; // 0 for say, 1 for say_team, -1 for command
+signed char chat_mode; // 0 for say, 1 for say_team, -1 for command
 char chat_buffer[MAX_INPUTLINE];
 int chat_bufferpos = 0;
 
diff --git a/keys.h b/keys.h
index f6b78cd0c841a385efea99dee7988d09c72530cd..57ec1702c909bf8cf1cbf50a61cb0c0436b3ee44 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -371,7 +371,7 @@ extern      keydest_t       key_dest;
 extern int                     key_consoleactive;
 extern char            *keybindings[MAX_BINDMAPS][MAX_KEYS];
 
-extern int chat_mode; // 0 for say, 1 for say_team, -1 for command
+extern signed char chat_mode; // 0 for say, 1 for say_team, -1 for command
 extern char chat_buffer[MAX_INPUTLINE];
 extern int     chat_bufferpos;