]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sys: optimise printing to stdout
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 9 Jan 2024 05:46:37 +0000 (15:46 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sun, 21 Jan 2024 11:15:03 +0000 (21:15 +1000)
Signed-off-by: bones_was_here <bones_was_here@xonotic.au>
cl_screen.c
console.c
console.h
sys.h
sys_shared.c

index 202a520e4423df3bd94ea46cf7899d13e07a0456..1d1280e990808143a612042a05a0dda7f20de5ba 100644 (file)
@@ -1224,19 +1224,13 @@ static void SCR_CaptureVideo_VideoFrame(int newframestepframenum)
        cls.capturevideo.videoframes(newframestepframenum - cls.capturevideo.framestepframe);
        cls.capturevideo.framestepframe = newframestepframenum;
 
-       if(cl_capturevideo_printfps.integer)
+       if(cl_capturevideo_printfps.integer && host.realtime > cls.capturevideo.lastfpstime + 1)
        {
-               char buf[80];
-               double t = host.realtime;
-               if(t > cls.capturevideo.lastfpstime + 1)
-               {
-                       double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (t - cls.capturevideo.lastfpstime + 0.0000001);
-                       double fps  = (cls.capturevideo.frame                                ) / (t - cls.capturevideo.starttime   + 0.0000001);
-                       dpsnprintf(buf, sizeof(buf), "capturevideo: (%.1fs) last second %.3ffps, total %.3ffps\n", cls.capturevideo.frame / cls.capturevideo.framerate, fps1, fps);
-                       Sys_Print(buf);
-                       cls.capturevideo.lastfpstime = t;
-                       cls.capturevideo.lastfpsframe = cls.capturevideo.frame;
-               }
+               double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (host.realtime - cls.capturevideo.lastfpstime + 0.0000001);
+               double fps  = (cls.capturevideo.frame                                ) / (host.realtime - cls.capturevideo.starttime   + 0.0000001);
+               Sys_Printf("capturevideo: (%.1fs) last second %.3ffps, total %.3ffps\n", cls.capturevideo.frame / cls.capturevideo.framerate, fps1, fps);
+               cls.capturevideo.lastfpstime = host.realtime;
+               cls.capturevideo.lastfpsframe = cls.capturevideo.frame;
        }
 }
 
index 99414a215cf5737dba10ace9c5ef791175063600..01c371af49aa8460f418f001dca3a0f54fa1ac26 100644 (file)
--- a/console.c
+++ b/console.c
@@ -1356,12 +1356,12 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                                *out++ = '[';
                                                *out++ = 'm';
                                        }
-                                       *out++ = 0;
-                                       Sys_Print(printline);
+                                       *out = '\0';
+                                       Sys_Print(printline, out - printline);
                                }
                                else if(sys_colortranslation.integer == 2) // Quake
                                {
-                                       Sys_Print(line);
+                                       Sys_Print(line, index);
                                }
                                else // strip
                                {
@@ -1411,8 +1411,8 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                                                break;
                                                }
                                        }
-                                       *out++ = 0;
-                                       Sys_Print(printline);
+                                       *out = '\0';
+                                       Sys_Print(printline, out - printline);
                                }
                        }
                        // empty the line buffer
index 8ce079351f2b15d354fde1fb035001b8714e9285..093fd8c663b8b716be65ab7e4c7e5a9e22427318 100644 (file)
--- a/console.h
+++ b/console.h
@@ -46,7 +46,7 @@ void Con_Shutdown (void);
 void Con_DrawConsole (int lines);
 
 /// Prints to a chosen console target
-void Con_MaskPrint(int mask, const char *msg);
+void Con_MaskPrint(int additionalmask, const char *msg);
 
 // Prints to a chosen console target
 void Con_MaskPrintf(int mask, const char *fmt, ...) DP_FUNC_PRINTF(2);
diff --git a/sys.h b/sys.h
index 119748ed8448c41ca241c3c012c37825389c3dfe..2255a6a3064502f597341232da317e9eb089d470 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -208,8 +208,9 @@ char *Sys_TimeString(const char *timeformat);
 void Sys_Error (const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
 
 /// (may) output text to terminal which launched program
-void Sys_Print(const char *text);
-/// for the console to report failures inside Con_Printf()
+/// textlen excludes any (optional) \0 terminator
+void Sys_Print(const char *text, size_t textlen);
+/// used to report failures inside Con_Printf()
 void Sys_Printf(const char *fmt, ...);
 
 /// INFO: This is only called by Host_Shutdown so we dont need testing for recursion
index f9f118bf5180e88a79d936e1a9421acc276d5bdc..26bd27c25e440a57bef9fe50d3632c72bedddd0b 100644 (file)
@@ -596,7 +596,7 @@ STDIO
 ===============================================================================
 */
 
-void Sys_Print(const char *text)
+void Sys_Print(const char *text, size_t textlen)
 {
 #ifdef __ANDROID__
        if (developer.integer > 0)
@@ -618,7 +618,7 @@ void Sys_Print(const char *text)
   #endif
                while(*text)
                {
-                       fs_offset_t written = (fs_offset_t)write(sys.outfd, text, (int)strlen(text));
+                       fs_offset_t written = (fs_offset_t)write(sys.outfd, text, textlen);
                        if(written <= 0)
                                break; // sorry, I cannot do anything about this error - without an output
                        text += written;
@@ -632,17 +632,18 @@ void Sys_Print(const char *text)
 #endif
 }
 
-/// for the console to report failures inside Con_Printf()
 void Sys_Printf(const char *fmt, ...)
 {
        va_list argptr;
        char msg[MAX_INPUTLINE];
+       int msglen;
 
        va_start(argptr,fmt);
-       dpvsnprintf(msg,sizeof(msg),fmt,argptr);
+       msglen = dpvsnprintf(msg, sizeof(msg), fmt, argptr);
        va_end(argptr);
 
-       Sys_Print(msg);
+       if (msglen >= 0)
+               Sys_Print(msg, msglen);
 }
 
 /// Reads a line from POSIX stdin or the Windows console