added Con_MaskPrintf, Con_Printf/Con_DPrintf and friends are now just
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Dec 2009 11:33:49 +0000 (11:33 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 27 Dec 2009 11:33:49 +0000 (11:33 +0000)
wrappers for these
added console text filtering - the developer cvar now shows/hides
developer prints (Con_DPrintf) on the fly, these are still logged to
files and terminal output regardless of the cvar though

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9704 d7cf8633-e32d-0410-b094-e92efae38249

cd_shared.c
console.c
console.h
cvar.c
gl_draw.c
host.c
netconn.c
sv_main.c
sys_shared.c

index b87cd29..e86653f 100644 (file)
@@ -121,7 +121,7 @@ qboolean CDAudio_Play_real (int track, qboolean looping, qboolean complain)
                if (!cdValid)
                {
                        if(complain)
-                               Con_Print ("No CD in player.\n");
+                               Con_DPrint ("No CD in player.\n");
                        return false;
                }
        }
@@ -233,7 +233,7 @@ void CDAudio_Play_byName (const char *trackname, qboolean looping)
                }
                else
                {
-                       Con_Print ("No CD in player.\n");
+                       Con_DPrint ("No CD in player.\n");
                }
                return;
        }
index d8912dd..32cacb1 100644 (file)
--- a/console.c
+++ b/console.c
@@ -1008,13 +1008,13 @@ static char Sys_Con_NearestColor(const unsigned char _r, const unsigned char _g,
 
 /*
 ================
-Con_Print
+Con_MaskPrint
 ================
 */
 extern cvar_t timestamps;
 extern cvar_t timeformat;
 extern qboolean sys_nostdout;
-void Con_Print(const char *msg)
+void Con_MaskPrint(int additionalmask, const char *msg)
 {
        static int mask = 0;
        static int index = 0;
@@ -1023,6 +1023,8 @@ void Con_Print(const char *msg)
        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)
                {
@@ -1272,6 +1274,32 @@ void Con_Print(const char *msg)
        }
 }
 
+/*
+================
+Con_MaskPrintf
+================
+*/
+void Con_MaskPrintf(int mask, const char *fmt, ...)
+{
+       va_list argptr;
+       char msg[MAX_INPUTLINE];
+
+       va_start(argptr,fmt);
+       dpvsnprintf(msg,sizeof(msg),fmt,argptr);
+       va_end(argptr);
+
+       Con_MaskPrint(mask, msg);
+}
+
+/*
+================
+Con_Print
+================
+*/
+void Con_Print(const char *msg)
+{
+       Con_MaskPrint(CON_MASK_PRINT, msg);
+}
 
 /*
 ================
@@ -1287,7 +1315,7 @@ void Con_Printf(const char *fmt, ...)
        dpvsnprintf(msg,sizeof(msg),fmt,argptr);
        va_end(argptr);
 
-       Con_Print(msg);
+       Con_MaskPrint(CON_MASK_PRINT, msg);
 }
 
 /*
@@ -1297,9 +1325,7 @@ Con_DPrint
 */
 void Con_DPrint(const char *msg)
 {
-       if (!developer.integer)
-               return;                 // don't confuse non-developers with techie stuff...
-       Con_Print(msg);
+       Con_MaskPrint(CON_MASK_DEVELOPER, msg);
 }
 
 /*
@@ -1316,7 +1342,7 @@ void Con_DPrintf(const char *fmt, ...)
        dpvsnprintf(msg,sizeof(msg),fmt,argptr);
        va_end(argptr);
 
-       Con_DPrint(msg);
+       Con_MaskPrint(CON_MASK_DEVELOPER, msg);
 }
 
 
@@ -1601,7 +1627,7 @@ void Con_DrawNotify (void)
                chatstart = 0; // shut off gcc warning
        }
 
-       v = notifystart + con_notifysize.value * Con_DrawNotifyRect(0, CON_MASK_INPUT | CON_MASK_HIDENOTIFY | (numChatlines ? CON_MASK_CHAT : 0), con_notifytime.value, 0, notifystart, vid_conwidth.value, con_notify.value * con_notifysize.value, con_notifysize.value, align, 0.0, "");
+       v = notifystart + con_notifysize.value * Con_DrawNotifyRect(0, CON_MASK_INPUT | CON_MASK_HIDENOTIFY | (numChatlines ? CON_MASK_CHAT : 0) | CON_MASK_DEVELOPER, con_notifytime.value, 0, notifystart, vid_conwidth.value, con_notify.value * con_notifysize.value, con_notifysize.value, align, 0.0, "");
 
        // chat?
        if(numChatlines)
@@ -1689,6 +1715,8 @@ int Con_DrawConsoleLine(float y, int lineno, float ymin, float ymax)
 
        //if(con.lines[lineno].mask & CON_MASK_LOADEDHISTORY)
        //      return 0;
+       if ((con.lines[lineno].mask & CON_MASK_DEVELOPER) && !developer.integer)
+               return 0;
 
        ti.continuationString = "";
        ti.alignment = 0;
index 338690e..f86ae15 100644 (file)
--- a/console.h
+++ b/console.h
@@ -39,6 +39,12 @@ void Con_Init_Commands (void);
 void Con_Shutdown (void);
 void Con_DrawConsole (int lines);
 
+/// Prints to a chosen console target
+void Con_MaskPrint(int mask, const char *msg);
+
+// Prints to a chosen console target
+void Con_MaskPrintf(int mask, const char *fmt, ...) DP_FUNC_PRINTF(2);
+
 /// Prints to all appropriate console targets, and adds timestamps
 void Con_Print(const char *txt);
 
@@ -81,9 +87,13 @@ void Log_DestBuffer_Flush (void); ///< call this once per frame to send out repl
 void Log_Printf(const char *logfilename, const char *fmt, ...) DP_FUNC_PRINTF(2);
 //@}
 
+// CON_MASK_PRINT is the default (Con_Print/Con_Printf)
+// CON_MASK_DEVELOPER is used by Con_DPrint/Con_DPrintf
 #define CON_MASK_HIDENOTIFY 128
 #define CON_MASK_CHAT 1
 #define CON_MASK_INPUT 2
+#define CON_MASK_DEVELOPER 4
+#define CON_MASK_PRINT 8
 
 typedef struct con_lineinfo_s
 {
diff --git a/cvar.c b/cvar.c
index 859e37b..8f3abc3 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -461,7 +461,7 @@ void Cvar_RegisterVariable (cvar_t *variable)
                        Z_Free(cvar);
                }
                else
-                       Con_Printf("Can't register variable %s, already defined\n", variable->name);
+                       Con_DPrintf("Can't register variable %s, already defined\n", variable->name);
                return;
        }
 
index a6108ef..dd13d5e 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -558,7 +558,7 @@ static void LoadFont(qboolean override, const char *name, dp_font_t *fnt)
        if(fnt->req_face != -1)
        {
                if(!Font_LoadFont(fnt->texpath, fnt))
-                       Con_Printf("Failed to load font-file for '%s', it will not support as many characters.\n", fnt->texpath);
+                       Con_DPrintf("Failed to load font-file for '%s', it will not support as many characters.\n", fnt->texpath);
        }
 
        fnt->tex = Draw_CachePic_Flags(fnt->texpath, CACHEPICFLAG_QUIET | CACHEPICFLAG_NOCOMPRESSION)->tex;
diff --git a/host.c b/host.c
index 0914423..2cc6595 100644 (file)
--- a/host.c
+++ b/host.c
@@ -660,7 +660,7 @@ void Host_Main(void)
                                svs.perf_offset_avg = svs.perf_acc_offset / svs.perf_acc_offset_samples;
                                svs.perf_offset_sdev = sqrt(svs.perf_acc_offset_squared / svs.perf_acc_offset_samples - svs.perf_offset_avg * svs.perf_offset_avg);
                        }
-                       if(svs.perf_lost > 0)
+                       if(svs.perf_lost > 0 && developer_extra.integer)
                                Con_DPrintf("Server can't keep up: %s\n", Host_TimingReport());
                        svs.perf_acc_realtime = svs.perf_acc_sleeptime = svs.perf_acc_lost = svs.perf_acc_offset = svs.perf_acc_offset_squared = svs.perf_acc_offset_max = svs.perf_acc_offset_samples = 0;
                }
index 865bcb8..f36dec1 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -859,7 +859,8 @@ void NetConn_OpenClientPort(const char *addressstring, lhnetaddresstype_t addres
                {
                        cl_sockets[cl_numsockets++] = s;
                        LHNETADDRESS_ToString(LHNET_AddressFromSocket(s), addressstring2, sizeof(addressstring2), true);
-                       Con_Printf("Client opened a socket on address %s\n", addressstring2);
+                       if (addresstype != LHNETADDRESSTYPE_LOOP)
+                               Con_Printf("Client opened a socket on address %s\n", addressstring2);
                }
                else
                {
@@ -884,7 +885,9 @@ void NetConn_OpenClientPorts(void)
                Con_Printf("Client using port %i\n", port);
        NetConn_OpenClientPort(NULL, LHNETADDRESSTYPE_LOOP, 2);
        NetConn_OpenClientPort(net_address.string, LHNETADDRESSTYPE_INET4, port);
+#ifdef SUPPORTIPV6
        NetConn_OpenClientPort(net_address_ipv6.string, LHNETADDRESSTYPE_INET6, port);
+#endif
 }
 
 void NetConn_CloseServerPorts(void)
@@ -914,7 +917,8 @@ qboolean NetConn_OpenServerPort(const char *addressstring, lhnetaddresstype_t ad
                        {
                                sv_sockets[sv_numsockets++] = s;
                                LHNETADDRESS_ToString(LHNET_AddressFromSocket(s), addressstring2, sizeof(addressstring2), true);
-                               Con_Printf("Server listening on address %s\n", addressstring2);
+                               if (addresstype != LHNETADDRESSTYPE_LOOP)
+                                       Con_Printf("Server listening on address %s\n", addressstring2);
                                return true;
                        }
                        else
@@ -948,8 +952,12 @@ void NetConn_OpenServerPorts(int opennetports)
                NetConn_OpenServerPort(NULL, LHNETADDRESSTYPE_LOOP, 1, 1);
        if (opennetports)
        {
+#ifdef SUPPORTIPV6
                qboolean ip4success = NetConn_OpenServerPort(net_address.string, LHNETADDRESSTYPE_INET4, port, 100);
                NetConn_OpenServerPort(net_address_ipv6.string, LHNETADDRESSTYPE_INET6, port, ip4success ? 1 : 100);
+#else
+               NetConn_OpenServerPort(net_address.string, LHNETADDRESSTYPE_INET4, port, 100);
+#endif
        }
        if (sv_numsockets == 0)
                Host_Error("NetConn_OpenServerPorts: unable to open any ports!");
index f25c85b..21d5590 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2895,31 +2895,29 @@ void SV_Prepare_CSQC(void)
        svs.csqc_progdata = NULL;
        svs.csqc_progdata_deflated = NULL;
        
-       Con_Print("Loading csprogs.dat\n");
-
        sv.csqc_progname[0] = 0;
        svs.csqc_progdata = FS_LoadFile(csqc_progname.string, sv_mempool, false, &progsize);
 
        if(progsize > 0)
        {
                size_t deflated_size;
-               
+
                sv.csqc_progsize = (int)progsize;
                sv.csqc_progcrc = CRC_Block(svs.csqc_progdata, progsize);
                strlcpy(sv.csqc_progname, csqc_progname.string, sizeof(sv.csqc_progname));
-               Con_Printf("server detected csqc progs file \"%s\" with size %i and crc %i\n", sv.csqc_progname, sv.csqc_progsize, sv.csqc_progcrc);
+               Con_DPrintf("server detected csqc progs file \"%s\" with size %i and crc %i\n", sv.csqc_progname, sv.csqc_progsize, sv.csqc_progcrc);
 
-               Con_Print("Compressing csprogs.dat\n");
+               Con_DPrint("Compressing csprogs.dat\n");
                //unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool);
                svs.csqc_progdata_deflated = FS_Deflate(svs.csqc_progdata, progsize, &deflated_size, -1, sv_mempool);
                svs.csqc_progsize_deflated = (int)deflated_size;
                if(svs.csqc_progdata_deflated)
                {
-                       Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize));
+                       Con_DPrintf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize));
                        Con_DPrintf("Uncompressed: %u\nCompressed:   %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated);
                }
                else
-                       Con_Printf("Cannot compress - need zlib for this. Using uncompressed progs only.\n");
+                       Con_DPrintf("Cannot compress - need zlib for this. Using uncompressed progs only.\n");
        }
 }
 
index a52b942..b917e60 100644 (file)
@@ -80,7 +80,7 @@ qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllf
                                dlclose(dllhandle);
                                goto notfound;
                        }
-               Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
+               Con_DPrintf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]);
                *handle = dllhandle;
                return true;
        }
@@ -93,10 +93,10 @@ notfound:
                *func->funcvariable = NULL;
 
        // Try every possible name
-       Con_Printf ("Trying to load library...");
+       Con_DPrintf ("Trying to load library...");
        for (i = 0; dllnames[i] != NULL; i++)
        {
-               Con_Printf (" \"%s\"", dllnames[i]);
+               Con_DPrintf (" \"%s\"", dllnames[i]);
 #ifdef WIN32
                dllhandle = LoadLibrary (dllnames[i]);
 #else
@@ -118,7 +118,7 @@ notfound:
                        char temp[MAX_OSPATH];
                        strlcpy(temp, path, sizeof(temp));
                        strlcat(temp, dllnames[i], sizeof(temp));
-                       Con_Printf (" \"%s\"", temp);
+                       Con_DPrintf (" \"%s\"", temp);
 #ifdef WIN32
                        dllhandle = LoadLibrary (temp);
 #else
@@ -132,17 +132,17 @@ notfound:
        // No DLL found
        if (! dllhandle)
        {
-               Con_Printf(" - failed.\n");
+               Con_DPrintf(" - failed.\n");
                return false;
        }
 
-       Con_Printf(" - loaded.\n");
+       Con_DPrintf(" - loaded.\n");
 
        // Get the function adresses
        for (func = fcts; func && func->name != NULL; func++)
                if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name)))
                {
-                       Con_Printf ("Missing function \"%s\" - broken library!\n", func->name);
+                       Con_DPrintf ("Missing function \"%s\" - broken library!\n", func->name);
                        Sys_UnloadLibrary (&dllhandle);
                        return false;
                }