]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
do not TOTALLY block translation with csprogs, but restrict it to globals named dotra...
[xonotic/darkplaces.git] / console.c
index 7d49db566f31d90ca975b8283319db867feec2e1..6a59b970f4a1d72c830cd4017343ac7fc5ee1276 100644 (file)
--- a/console.c
+++ b/console.c
@@ -26,10 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #endif
 #include <time.h>
 
-float con_cursorspeed = 4;
+// for u8_encodech
+#include "ft2.h"
 
-#define                CON_TEXTSIZE    1048576
-#define                CON_MAXLINES      16384
+float con_cursorspeed = 4;
 
 // lines up from bottom to display
 int con_backscroll;
@@ -51,6 +51,7 @@ cvar_t con_chatwidth = {CVAR_SAVE, "con_chatwidth","1.0", "relative chat window
 cvar_t con_textsize = {CVAR_SAVE, "con_textsize","8", "console text size in virtual 2D pixels"};
 cvar_t con_notifysize = {CVAR_SAVE, "con_notifysize","8", "notify text size in virtual 2D pixels"};
 cvar_t con_chatsize = {CVAR_SAVE, "con_chatsize","8", "chat text size in virtual 2D pixels (if con_chat is enabled)"};
+cvar_t con_chatsound = {CVAR_SAVE, "con_chatsound","1", "enables chat sound to play on message"};
 
 
 cvar_t sys_specialcharactertranslation = {0, "sys_specialcharactertranslation", "1", "terminal console conchars to ASCII translation (set to 0 if your conchars.tga is for an 8bit character set or if you want raw output)"};
@@ -94,6 +95,7 @@ char rcon_redirect_buffer[1400];
 
 void ConBuffer_Init(conbuffer_t *buf, int textsize, int maxlines, mempool_t *mempool)
 {
+       buf->active = true;
        buf->textsize = textsize;
        buf->text = (char *) Mem_Alloc(mempool, textsize);
        buf->maxlines = maxlines;
@@ -119,6 +121,7 @@ ConBuffer_Shutdown
 */
 void ConBuffer_Shutdown(conbuffer_t *buf)
 {
+       buf->active = false;
        Mem_Free(buf->text);
        Mem_Free(buf->lines);
        buf->text = NULL;
@@ -229,6 +232,10 @@ void ConBuffer_AddLine(conbuffer_t *buf, const char *line, int len, int mask)
        char *putpos;
        con_lineinfo_t *p;
 
+       // developer_memory 1 during shutdown prints while conbuffer_t is being freed
+       if (!buf->active)
+               return;
+
        ConBuffer_FixTimes(buf);
 
        if(len >= buf->textsize)
@@ -309,6 +316,8 @@ LOGGING
 ==============================================================================
 */
 
+/// \name Logging
+//@{
 cvar_t log_file = {0, "log_file","", "filename to log messages to"};
 cvar_t log_dest_udp = {0, "log_dest_udp","", "UDP address to log messages to (in QW rcon compatible format); multiple destinations can be separated by spaces; DO NOT SPECIFY DNS NAMES HERE"};
 char log_dest_buffer[1400]; // UDP packet
@@ -322,13 +331,13 @@ size_t logq_ind = 0;
 size_t logq_size = 0;
 
 void Log_ConPrint (const char *msg);
-
+//@}
 /*
 ====================
 Log_DestBuffer_Init
 ====================
 */
-static void Log_DestBuffer_Init()
+static void Log_DestBuffer_Init(void)
 {
        memcpy(log_dest_buffer, "\377\377\377\377n", 5); // QW rcon print
        log_dest_buffer_pos = 5;
@@ -339,7 +348,7 @@ static void Log_DestBuffer_Init()
 Log_DestBuffer_Flush
 ====================
 */
-void Log_DestBuffer_Flush()
+void Log_DestBuffer_Flush(void)
 {
        lhnetaddress_t log_dest_addr;
        lhnetsocket_t *log_dest_socket;
@@ -589,8 +598,6 @@ void Con_ToggleConsole_f (void)
 /*
 ================
 Con_ClearNotify
-
-Clear all notify lines.
 ================
 */
 void Con_ClearNotify (void)
@@ -647,8 +654,6 @@ void Con_CommandMode_f (void)
 /*
 ================
 Con_CheckResize
-
-If the line width has changed, reformat the buffer.
 ================
 */
 void Con_CheckResize (void)
@@ -713,7 +718,7 @@ void Con_ConDump_f (void)
        FS_Close(file);
 }
 
-void Con_Clear_f ()
+void Con_Clear_f (void)
 {
        ConBuffer_Clear(&con);
 }
@@ -755,6 +760,7 @@ void Con_Init (void)
        Cvar_RegisterVariable (&con_notifysize);
        Cvar_RegisterVariable (&con_notifytime);
        Cvar_RegisterVariable (&con_textsize);
+       Cvar_RegisterVariable (&con_chatsound);
 
        // --blub
        Cvar_RegisterVariable (&con_nickcompletion);
@@ -836,7 +842,7 @@ void Con_PrintToHistory(const char *txt, int mask)
        }
 }
 
-/* The translation table between the graphical font and plain ASCII  --KB */
+/*! The translation table between the graphical font and plain ASCII  --KB */
 static char qfont_table[256] = {
        '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
        '#',  9,    10,   '#',  ' ',  13,   '.',  '.',
@@ -881,7 +887,7 @@ void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest)
        rcon_redirect_bufferpos = 5;
 }
 
-void Con_Rcon_Redirect_Flush()
+void Con_Rcon_Redirect_Flush(void)
 {
        rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
        NetConn_WriteString(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_dest);
@@ -889,14 +895,14 @@ void Con_Rcon_Redirect_Flush()
        rcon_redirect_bufferpos = 5;
 }
 
-void Con_Rcon_Redirect_End()
+void Con_Rcon_Redirect_End(void)
 {
        Con_Rcon_Redirect_Flush();
        rcon_redirect_dest = NULL;
        rcon_redirect_sock = NULL;
 }
 
-void Con_Rcon_Redirect_Abort()
+void Con_Rcon_Redirect_Abort(void)
 {
        rcon_redirect_dest = NULL;
        rcon_redirect_sock = NULL;
@@ -905,10 +911,9 @@ void Con_Rcon_Redirect_Abort()
 /*
 ================
 Con_Rcon_AddChar
-
-Adds a character to the rcon buffer
 ================
 */
+/// Adds a character to the rcon buffer.
 void Con_Rcon_AddChar(int c)
 {
        if(log_dest_buffer_appending)
@@ -1004,8 +1009,6 @@ static char Sys_Con_NearestColor(const unsigned char _r, const unsigned char _g,
 /*
 ================
 Con_Print
-
-Prints to all appropriate console targets, and adds timestamps
 ================
 */
 extern cvar_t timestamps;
@@ -1036,19 +1039,22 @@ void Con_Print(const char *msg)
                                // play talk wav
                                if (*msg == 1)
                                {
-                                       if(gamemode == GAME_NEXUIZ)
+                                       if (con_chatsound.value)
                                        {
-                                               if(msg[1] == '\r' && cl.foundtalk2wav)
-                                                       S_LocalSound ("sound/misc/talk2.wav");
-                                               else
-                                                       S_LocalSound ("sound/misc/talk.wav");
-                                       }
-                                       else
-                                       {
-                                               if (msg[1] == '(' && cl.foundtalk2wav)
-                                                       S_LocalSound ("sound/misc/talk2.wav");
+                                               if(gamemode == GAME_NEXUIZ)
+                                               {
+                                                       if(msg[1] == '\r' && cl.foundtalk2wav)
+                                                               S_LocalSound ("sound/misc/talk2.wav");
+                                                       else
+                                                               S_LocalSound ("sound/misc/talk.wav");
+                                               }
                                                else
-                                                       S_LocalSound ("sound/misc/talk.wav");
+                                               {
+                                                       if (msg[1] == '(' && cl.foundtalk2wav)
+                                                               S_LocalSound ("sound/misc/talk2.wav");
+                                                       else
+                                                               S_LocalSound ("sound/misc/talk.wav");
+                                               }
                                        }
                                        mask = CON_MASK_CHAT;
                                }
@@ -1270,8 +1276,6 @@ void Con_Print(const char *msg)
 /*
 ================
 Con_Printf
-
-Prints to all appropriate console targets
 ================
 */
 void Con_Printf(const char *fmt, ...)
@@ -1289,8 +1293,6 @@ void Con_Printf(const char *fmt, ...)
 /*
 ================
 Con_DPrint
-
-A Con_Print that only shows up if the "developer" cvar is set
 ================
 */
 void Con_DPrint(const char *msg)
@@ -1303,8 +1305,6 @@ void Con_DPrint(const char *msg)
 /*
 ================
 Con_DPrintf
-
-A Con_Printf that only shows up if the "developer" cvar is set
 ================
 */
 void Con_DPrintf(const char *fmt, ...)
@@ -1366,7 +1366,24 @@ void Con_DrawInput (void)
 
        // add the cursor frame
        if ((int)(realtime*con_cursorspeed) & 1)                // cursor is visible
-               text[key_linepos] = 11 + 130 * key_insert;      // either solid or triangle facing right
+       {
+               if (!utf8_enable.integer)
+                       text[key_linepos] = 11 + 130 * key_insert;      // either solid or triangle facing right
+               else if (y + 3 < (int)sizeof(editlinecopy)-1)
+               {
+                       int ofs = u8_bytelen(text + key_linepos, 1);
+                       size_t len;
+                       const char *curbuf;
+                       curbuf = u8_encodech(0xE000 + 11 + 130 * key_insert, &len);
+
+                       if (curbuf)
+                       {
+                               memmove(text + key_linepos + len, text + key_linepos + ofs, sizeof(editlinecopy) - key_linepos - len);
+                               memcpy(text + key_linepos, curbuf, len);
+                       }
+               } else
+                       text[key_linepos] = '-' + ('+' - '-') * key_insert;
+       }
 
 //     text[key_linepos + 1] = 0;
 
@@ -1405,10 +1422,16 @@ float Con_WordWidthFunc(void *passthrough, const char *w, size_t *length, float
                ti->colorindex = -1;
                return ti->fontsize * ti->font->maxwidth;
        }
+       /*
        if(maxWidth >= 0)
                return DrawQ_TextWidth_Font_UntilWidth(w, length, false, ti->font, maxWidth / ti->fontsize) * ti->fontsize;
        else if(maxWidth == -1)
                return DrawQ_TextWidth_Font(w, *length, false, ti->font) * ti->fontsize;
+       */
+       if(maxWidth >= 0)
+               return DrawQ_TextWidth_Font_UntilWidth_Size(w, ti->fontsize, ti->fontsize, length, false, ti->font, maxWidth);
+       else if(maxWidth == -1)
+               return DrawQ_TextWidth_Font_Size(w, ti->fontsize, ti->fontsize, *length, false, ti->font);
        else
        {
                printf("Con_WordWidthFunc: can't get here (maxWidth should never be %f)\n", maxWidth);
@@ -1593,20 +1616,23 @@ void Con_DrawNotify (void)
        if(numChatlines)
        {
                v = chatstart + numChatlines * con_chatsize.value;
-               Con_DrawNotifyRect(CON_MASK_CHAT, CON_MASK_INPUT, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, "^3\014\014\014 "); // 015 is ·> character in conchars.tga
+               Con_DrawNotifyRect(CON_MASK_CHAT, CON_MASK_INPUT, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, /*"^3\014\014\014 "*/ "^3\xee\x80\x8d\xee\x80\x8d\xee\x80\x8d "); // 015 is ·> character in conchars.tga
        }
 
        if (key_dest == key_message)
        {
+               //static char *cursor[2] = { "\xee\x80\x8a", "\xee\x80\x8b" }; // { off, on }
                int colorindex = -1;
+               const char *cursor;
+               cursor = u8_encodech(0xE00A + ((int)(realtime * con_cursorspeed)&1), NULL);
 
                // LordHavoc: speedup, and other improvements
                if (chat_mode < 0)
-                       dpsnprintf(temptext, sizeof(temptext), "]%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+                       dpsnprintf(temptext, sizeof(temptext), "]%s%s", chat_buffer, cursor);
                else if(chat_mode)
-                       dpsnprintf(temptext, sizeof(temptext), "say_team:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+                       dpsnprintf(temptext, sizeof(temptext), "say_team:%s%s", chat_buffer, cursor);
                else
-                       dpsnprintf(temptext, sizeof(temptext), "say:%s%c", chat_buffer, (int) 10+((int)(realtime*con_cursorspeed)&1));
+                       dpsnprintf(temptext, sizeof(temptext), "say:%s%s", chat_buffer, cursor);
 
                // FIXME word wrap
                inputsize = (numChatlines ? con_chatsize : con_notifysize).value;