shithub: qk1

Download patch

ref: 8ca1692ee9591fdce58c9f501783a4e3bebe53c4
parent: b9433d70b674a205e2de51d2fdf93f90185f795c
author: qwx <>
date: Sun Dec 16 13:13:25 EST 2018

fix qw screenshot code, add current time to filenames

--- a/qw/screen.c
+++ b/qw/screen.c
@@ -629,54 +629,12 @@
 	else
 		COM_WriteFile (filename, pcx, length);
 } 
- 
 
-
-/* 
-================== 
-SCR_ScreenShot_f
-================== 
-*/  
 void SCR_ScreenShot_f (void) 
-{ 
-	int     i; 
-	char		pcxname[80]; 
-	char		checkname[MAX_OSPATH];
+{
+	dumpwin = 1;
+}
 
-// 
-// find a file name to save it to 
-// 
-	strcpy(pcxname,"quake00.pcx");
-		
-	for (i=0 ; i<=99 ; i++) 
-	{ 
-		pcxname[5] = i/10 + '0'; 
-		pcxname[6] = i%10 + '0'; 
-		sprintf (checkname, "%s/%s", com_gamedir, pcxname);
-		if (Sys_FileTime(checkname) == -1)
-			break;	// file doesn't exist
-	} 
-	if (i==100) 
-	{
-		Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); 
-		return;
-	}
- 
-// 
-// save the pcx file 
-// 
-	D_EnableBackBufferAccess ();	// enable direct drawing of console to back
-									//  buffer
-
-	WritePCXfile (pcxname, vid.buffer, vid.width, vid.height, vid.rowbytes,
-				  host_basepal, false);
-
-	D_DisableBackBufferAccess ();	// for adapters that can't stay mapped in
-									//  for linear writes all the time
-
-	Con_Printf ("Wrote %s\n", pcxname);
-} 
-
 /*
 Find closest color in the palette for named color
 */
@@ -785,27 +743,6 @@
 	}
 
 	Con_Printf("Remote screen shot requested.\n");
-
-/*
-// 
-// find a file name to save it to 
-// 
-	strcpy(pcxname,"mquake00.pcx");
-		
-	for (i=0 ; i<=99 ; i++) 
-	{ 
-		pcxname[6] = i/10 + '0'; 
-		pcxname[7] = i%10 + '0'; 
-		sprintf (checkname, "%s/%s", com_gamedir, pcxname);
-		if (Sys_FileTime(checkname) == -1)
-			break;	// file doesn't exist
-	} 
-	if (i==100) 
-	{
-		Con_Printf ("SCR_ScreenShot_f: Couldn't create a PCX"); 
-		return;
-	}
-*/
  
 // 
 // save the pcx file 
--- a/qw/vid.c
+++ b/qw/vid.c
@@ -189,6 +189,27 @@
 	freeimage(fbi);
 }
 
+/* only exists to allow taking tear-free screenshots ingame... */
+static int
+writebit(void)
+{
+	int n, fd;
+	char *s;
+
+	s = va("%s/quake.%d.bit", com_gamedir, time(nil));
+	if(access(s, AEXIST) != -1){
+		fprint(2, "writebit: not overwriting %s\n", s);
+		return -1;
+	}
+	if(fd = create(s, OWRITE, 0644), fd < 0)
+		return -1;
+	n = writeimage(fd, fbi, 0);
+	close(fd);
+	if(n >= 0)
+		Con_Printf("Wrote %s\n", s);
+	return n;
+}
+
 void
 VID_Update(vrect_t *)
 {
@@ -220,6 +241,11 @@
 		}
 	}
 	flushimage(display, 1);
+	if(dumpwin){
+		if(writebit() < 0)
+			Con_Printf("Could not write screenshot.\n");
+		dumpwin = 0;
+	}
 }
 
 /* direct drawing of the "accessing disk" icon */
--- a/qw/vid.h
+++ b/qw/vid.h
@@ -35,6 +35,7 @@
 } viddef_t;
 
 extern	viddef_t	vid;				// global video state
+extern int dumpwin;
 
 void	VID_SetPalette (unsigned char *palette);
 // called at startup and after any gamma correction
--- a/vid.c
+++ b/vid.c
@@ -148,13 +148,9 @@
 	int n, fd;
 	char *s;
 
-	for(n=0, s=nil; n<100; n++){
-		s = va("%s/quake%02d.bit", fsdir, n);
-		if(access(s, AEXIST) == -1)
-			break;
-	}
-	if(n == 100){
-		werrstr("at static file limit");
+	s = va("%s/quake.%ld.bit", fsdir, time(nil));
+	if(access(s, AEXIST) != -1){
+		werrstr("writebit: not overwriting %s", s);
 		return -1;
 	}
 	if(fd = create(s, OWRITE, 0644), fd < 0)