Skip to content

Commit a0e6451

Browse files
committed
client: autoRecordDemo: name prefix on \stoprecord
This change only takes effect when `cl_autoRecordDemo 1`. If during auto-recording the user runs `\stoprecord`, prefix the resulting demo file name with `clip-` so that the user can easily tell apart manually clipped demos (e.g. created after a highlight) from auto-recorded ones. This also adds the file path to the "Stopped demo recording." message.
1 parent d108922 commit a0e6451

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

code/client/cl_main.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,19 @@ static void CL_WriteDemoMessage( msg_t *msg, int headerBytes ) {
235235

236236
/*
237237
====================
238-
CL_StopRecording_f
238+
CL_StopRecord2
239239
240240
stop recording a demo
241241
====================
242242
*/
243-
void CL_StopRecord_f( void ) {
243+
static void CL_StopRecord2( const char* prefix ) {
244244

245245
if ( clc.recordfile != FS_INVALID_HANDLE ) {
246246
char tempPath[MAX_OSPATH];
247247
char finalPath[MAX_OSPATH];
248+
// Slice of `finalPath`, so writing to this will write to `finalPath`.
249+
char *finalFilename;
250+
int finalFilenameSize;
248251
int protocol;
249252
int len, sequence;
250253

@@ -268,31 +271,58 @@ void CL_StopRecord_f( void ) {
268271

269272
Com_sprintf( tempPath, sizeof( tempPath ), "%s.tmp", clc.recordName );
270273

271-
Com_sprintf( finalPath, sizeof( finalPath ), "%s.%s%d", clc.recordName, DEMOEXT, protocol );
274+
// e.g. `demos/2026123123123`
275+
Q_strncpyz( finalPath, clc.recordName, sizeof( finalPath ) );
276+
// From now on leave the `demos/` part as is,
277+
// and override the `2026123123123` part
278+
finalFilename = COM_SkipPath( finalPath );
279+
finalFilenameSize = sizeof( finalPath ) - ( finalFilename - finalPath );
280+
281+
Com_sprintf( finalFilename, finalFilenameSize, "%s%s.%s%d",
282+
prefix, COM_SkipPath( clc.recordName ), DEMOEXT, protocol );
272283

273284
if ( clc.explicitRecordName ) {
274285
FS_Remove( finalPath );
275286
} else {
276287
// add sequence suffix to avoid overwrite
277288
sequence = 0;
278289
while ( FS_FileExists( finalPath ) && ++sequence < 1000 ) {
279-
Com_sprintf( finalPath, sizeof( finalPath ), "%s-%02d.%s%d",
280-
clc.recordName, sequence, DEMOEXT, protocol );
290+
Com_sprintf( finalFilename, finalFilenameSize, "%s%s-%02d.%s%d",
291+
prefix, COM_SkipPath( clc.recordName ), sequence, DEMOEXT, protocol );
281292
}
282293
}
283294

284295
FS_Rename( tempPath, finalPath );
296+
297+
Com_Printf( "Stopped demo recording %s.\n", finalPath );
285298
}
286299

287300
if ( !clc.demorecording ) {
288301
Com_Printf( "Not recording a demo.\n" );
289-
} else {
290-
Com_Printf( "Stopped demo recording.\n" );
291302
}
292303

293304
clc.demorecording = qfalse;
294305
clc.spDemoRecording = qfalse;
295306
}
307+
static void CL_StopRecord_f( void ) {
308+
// User executed the `\stoprecord` command: add a file name prefix
309+
// so that the user can easily tell apart manually clipped demos
310+
// (e.g. created after a highlight) from auto-recorded ones.
311+
const char *prefix = cl_autoRecordDemo->integer & 0x1
312+
? "clip-"
313+
: "";
314+
CL_StopRecord2( prefix );
315+
}
316+
/*
317+
====================
318+
CL_StopRecord
319+
320+
For stopping the demo automatically, e.g. on game quit.
321+
====================
322+
*/
323+
void CL_StopRecord( void ) {
324+
CL_StopRecord2( "" );
325+
}
296326

297327

298328
/*
@@ -1213,7 +1243,7 @@ qboolean CL_Disconnect( qboolean showMainMenu ) {
12131243

12141244
// Stop demo recording
12151245
if ( clc.demorecording ) {
1216-
CL_StopRecord_f();
1246+
CL_StopRecord();
12171247
}
12181248

12191249
// Stop demo playback
@@ -1788,7 +1818,7 @@ static void CL_Vid_Restart( refShutdownCode_t shutdownCode ) {
17881818
CL_CloseAVI( qfalse );
17891819

17901820
if ( clc.demorecording )
1791-
CL_StopRecord_f();
1821+
CL_StopRecord();
17921822

17931823
// clear and mute all sounds until next registration
17941824
S_DisableSounds();
@@ -3080,7 +3110,7 @@ void CL_Frame( int msec, int realMsec ) {
30803110
}
30813111
else if ( cls.state != CA_ACTIVE && clc.demorecording ) {
30823112
// Recording, but not CA_ACTIVE, so stop recording
3083-
CL_StopRecord_f();
3113+
CL_StopRecord();
30843114
}
30853115
}
30863116

code/client/cl_parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static void CL_ParseGamestate( msg_t *msg ) {
597597
// stop recording now so the demo won't have an unnecessary level load at the end.
598598
if ( cl_autoRecordDemo->integer && clc.demorecording ) {
599599
if ( !clc.demoplaying ) {
600-
CL_StopRecord_f();
600+
CL_StopRecord();
601601
}
602602
}
603603

@@ -685,7 +685,7 @@ static void CL_ParseDownload( msg_t *msg ) {
685685
}
686686

687687
if ( clc.recordfile != FS_INVALID_HANDLE ) {
688-
CL_StopRecord_f();
688+
CL_StopRecord();
689689
}
690690

691691
// read the data

code/client/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void CL_StartHunkUsers( void );
447447

448448
void CL_Disconnect_f( void );
449449
void CL_ReadDemoMessage( void );
450-
void CL_StopRecord_f( void );
450+
void CL_StopRecord( void );
451451

452452
void CL_InitDownloads( void );
453453
void CL_NextDownload( void );

0 commit comments

Comments
 (0)