X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=console.c;h=2f7e99b72f96d41a0d22c861a256247d1385a858;hb=bc33af16978d2aca67b4d0bf337bb35ebfff4a08;hp=4421def862bf2d708c35c546f3d40600589ed7d5;hpb=59f4e5291192d918f06fe0b2f86c462441c9e204;p=xonotic%2Fdarkplaces.git diff --git a/console.c b/console.c index 4421def8..2f7e99b7 100644 --- a/console.c +++ b/console.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "quakedef.h" +#include "thread.h" // for u8_encodech #include "ft2.h" @@ -35,6 +36,7 @@ float con_cursorspeed = 4; int con_backscroll; conbuffer_t con; +void *con_mutex = NULL; #define CON_LINES(i) CONBUFFER_LINES(&con, i) #define CON_LINES_LAST CONBUFFER_LINES_LAST(&con) @@ -126,8 +128,10 @@ ConBuffer_Shutdown void ConBuffer_Shutdown(conbuffer_t *buf) { buf->active = false; - Mem_Free(buf->text); - Mem_Free(buf->lines); + if (buf->text) + Mem_Free(buf->text); + if (buf->lines) + Mem_Free(buf->lines); buf->text = NULL; buf->lines = NULL; } @@ -594,6 +598,10 @@ Con_ToggleConsole_f */ void Con_ToggleConsole_f (void) { + if (COM_CheckParm ("-noconsole")) + if (!(key_consoleactive & KEY_CONSOLEACTIVE_USER)) + return; // only allow the key bind to turn off console + // toggle the 'user wants console' bit key_consoleactive ^= KEY_CONSOLEACTIVE_USER; Con_ClearNotify(); @@ -621,8 +629,11 @@ void Con_MessageMode_f (void) { key_dest = key_message; chat_mode = 0; // "say" - chat_bufferlen = 0; - chat_buffer[0] = 0; + if(Cmd_Argc() > 1) + { + dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); + chat_bufferlen = strlen(chat_buffer); + } } @@ -635,8 +646,11 @@ void Con_MessageMode2_f (void) { key_dest = key_message; chat_mode = 1; // "say_team" - chat_bufferlen = 0; - chat_buffer[0] = 0; + if(Cmd_Argc() > 1) + { + dpsnprintf(chat_buffer, sizeof(chat_buffer), "%s ", Cmd_Args()); + chat_bufferlen = strlen(chat_buffer); + } } /* @@ -714,17 +728,21 @@ void Con_ConDump_f (void) Con_Printf("condump: unable to write file \"%s\"\n", Cmd_Argv(1)); return; } + if (con_mutex) Thread_LockMutex(con_mutex); for(i = 0; i < CON_LINES_COUNT; ++i) { FS_Write(file, CON_LINES(i).start, CON_LINES(i).len); FS_Write(file, "\n", 1); } + if (con_mutex) Thread_UnlockMutex(con_mutex); FS_Close(file); } void Con_Clear_f (void) { + if (con_mutex) Thread_LockMutex(con_mutex); ConBuffer_Clear(&con); + if (con_mutex) Thread_UnlockMutex(con_mutex); } /* @@ -736,6 +754,8 @@ void Con_Init (void) { con_linewidth = 80; ConBuffer_Init(&con, CON_TEXTSIZE, CON_MAXLINES, zonemempool); + if (Thread_HasThreads()) + con_mutex = Thread_CreateMutex(); // Allocate a log queue, this will be freed after configs are parsed logq_size = MAX_INPUTLINE; @@ -792,7 +812,10 @@ void Con_Init (void) void Con_Shutdown (void) { + if (con_mutex) Thread_LockMutex(con_mutex); ConBuffer_Shutdown(&con); + if (con_mutex) Thread_UnlockMutex(con_mutex); + if (con_mutex) Thread_DestroyMutex(con_mutex);con_mutex = NULL; } /* @@ -817,6 +840,7 @@ void Con_PrintToHistory(const char *txt, int mask) if(!con.text) // FIXME uses a non-abstracted property of con return; + if (con_mutex) Thread_LockMutex(con_mutex); for(; *txt; ++txt) { if(cr_pending) @@ -847,6 +871,7 @@ void Con_PrintToHistory(const char *txt, int mask) break; } } + if (con_mutex) Thread_UnlockMutex(con_mutex); } /*! The translation table between the graphical font and plain ASCII --KB */ @@ -899,7 +924,7 @@ void Con_Rcon_Redirect_Init(lhnetsocket_t *sock, lhnetaddress_t *dest, qboolean rcon_redirect_buffer[2] = 0; rcon_redirect_buffer[3] = 0; // this is a reply to a CCREQ_RCON - rcon_redirect_buffer[4] = CCREP_RCON; + rcon_redirect_buffer[4] = (char)CCREP_RCON; } else memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print @@ -914,7 +939,7 @@ void Con_Rcon_Redirect_Flush(void) // update the length in the packet header StoreBigLong((unsigned char *)rcon_redirect_buffer, NETFLAG_CTL | (rcon_redirect_bufferpos & NETFLAG_LENGTH_MASK)); } - NetConn_WriteString(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_dest); + NetConn_Write(rcon_redirect_sock, rcon_redirect_buffer, rcon_redirect_bufferpos, rcon_redirect_dest); memcpy(rcon_redirect_buffer, "\377\377\377\377n", 5); // QW rcon print rcon_redirect_bufferpos = 5; rcon_redirect_proquakeprotocol = false; @@ -1045,11 +1070,12 @@ void Con_MaskPrint(int additionalmask, const char *msg) static int index = 0; static char line[MAX_INPUTLINE]; + if (con_mutex) + Thread_LockMutex(con_mutex); + for (;*msg;msg++) { Con_Rcon_AddChar(*msg); - if (index == 0) - mask |= additionalmask; // if this is the beginning of a new line, print timestamp if (index == 0) { @@ -1094,6 +1120,8 @@ void Con_MaskPrint(int additionalmask, const char *msg) for (;*timestamp;index++, timestamp++) if (index < (int)sizeof(line) - 2) line[index] = *timestamp; + // add the mask + mask |= additionalmask; } // append the character line[index++] = *msg; @@ -1108,16 +1136,29 @@ void Con_MaskPrint(int additionalmask, const char *msg) if (con_initialized && cls.state != ca_dedicated) { Con_PrintToHistory(line, mask); - mask = 0; } // send to terminal or dedicated server window if (!sys_nostdout) + if (developer.integer || !(mask & CON_MASK_DEVELOPER)) { - unsigned char *p; if(sys_specialcharactertranslation.integer) { - for (p = (unsigned char *) line;*p; p++) - *p = qfont_table[*p]; + char *p; + const char *q; + p = line; + while(*p) + { + int ch = u8_getchar(p, &q); + if(ch >= 0xE000 && ch <= 0xE0FF) + { + *p = qfont_table[ch - 0xE000]; + if(q > p+1) + memmove(p+1, q, strlen(q)+1); + p = p + 1; + } + else + p = p + (q - p); + } } if(sys_colortranslation.integer == 1) // ANSI @@ -1295,8 +1336,12 @@ void Con_MaskPrint(int additionalmask, const char *msg) } // empty the line buffer index = 0; + mask = 0; } } + + if (con_mutex) + Thread_UnlockMutex(con_mutex); } /* @@ -1642,6 +1687,7 @@ void Con_DrawNotify (void) int numChatlines; int chatpos; + if (con_mutex) Thread_LockMutex(con_mutex); ConBuffer_FixTimes(&con); numChatlines = con_chat.integer; @@ -1732,6 +1778,7 @@ void Con_DrawNotify (void) x = min(xr, x); DrawQ_String(x, v, temptext, 0, inputsize, inputsize, 1.0, 1.0, 1.0, 1.0, 0, &colorindex, false, FONT_CHAT); } + if (con_mutex) Thread_UnlockMutex(con_mutex); } /* @@ -1850,6 +1897,8 @@ void Con_DrawConsole (int lines) if (lines <= 0) return; + if (con_mutex) Thread_LockMutex(con_mutex); + if (con_backscroll < 0) con_backscroll = 0; @@ -1956,6 +2005,7 @@ void Con_DrawConsole (int lines) Con_DrawInput (); r_draw2d_force = false; + if (con_mutex) Thread_UnlockMutex(con_mutex); } /* @@ -2806,11 +2856,11 @@ void Con_CompleteCommandLine (void) } else { - stringlistsort(&resultbuf); // dirbuf is already sorted + stringlistsort(&resultbuf, true); // dirbuf is already sorted Con_Printf("\n%i possible filenames\n", resultbuf.numstrings + dirbuf.numstrings); for(i = 0; i < dirbuf.numstrings; ++i) { - Con_Printf("%s/\n", dirbuf.strings[i]); + Con_Printf("^4%s^7/\n", dirbuf.strings[i]); } for(i = 0; i < resultbuf.numstrings; ++i) {