summaryrefslogtreecommitdiff
path: root/src/cl_demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cl_demo.c')
-rw-r--r--src/cl_demo.c801
1 files changed, 412 insertions, 389 deletions
diff --git a/src/cl_demo.c b/src/cl_demo.c
index f53878e..82df171 100644
--- a/src/cl_demo.c
+++ b/src/cl_demo.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
@@ -40,47 +40,49 @@ Dumps the current demo message, prefixed by the length.
Stops demo recording and returns false on write error.
====================
*/
-qboolean CL_WriteDemoMessage( sizebuf_t *buf ) {
+qboolean CL_WriteDemoMessage(sizebuf_t *buf)
+{
uint32_t msglen;
ssize_t ret;
- if( buf->overflowed ) {
- SZ_Clear( buf );
- Com_WPrintf( "Demo message overflowed (should never happen).\n" );
+ if (buf->overflowed) {
+ SZ_Clear(buf);
+ Com_WPrintf("Demo message overflowed (should never happen).\n");
return qtrue;
}
- if( !buf->cursize )
+ if (!buf->cursize)
return qtrue;
- msglen = LittleLong( buf->cursize );
- ret = FS_Write( &msglen, 4, cls.demo.recording );
- if( ret != 4 )
+ msglen = LittleLong(buf->cursize);
+ ret = FS_Write(&msglen, 4, cls.demo.recording);
+ if (ret != 4)
goto fail;
- ret = FS_Write( buf->data, buf->cursize, cls.demo.recording );
- if( ret != buf->cursize )
+ ret = FS_Write(buf->data, buf->cursize, cls.demo.recording);
+ if (ret != buf->cursize)
goto fail;
- Com_DDPrintf( "%s: wrote %"PRIz" bytes\n", __func__, buf->cursize );
+ Com_DDPrintf("%s: wrote %"PRIz" bytes\n", __func__, buf->cursize);
- SZ_Clear( buf );
+ SZ_Clear(buf);
return qtrue;
fail:
- SZ_Clear( buf );
- Com_EPrintf( "Couldn't write demo: %s\n", Q_ErrorString( ret ) );
+ SZ_Clear(buf);
+ Com_EPrintf("Couldn't write demo: %s\n", Q_ErrorString(ret));
CL_Stop_f();
return qfalse;
}
// writes a delta update of an entity_state_t list to the message.
-static void emit_packet_entities( server_frame_t *from, server_frame_t *to ) {
+static void emit_packet_entities(server_frame_t *from, server_frame_t *to)
+{
entity_state_t *oldent, *newent;
int oldindex, newindex;
int oldnum, newnum;
int i, from_num_entities;
- if( !from )
+ if (!from)
from_num_entities = 0;
else
from_num_entities = from->numEntities;
@@ -88,88 +90,89 @@ static void emit_packet_entities( server_frame_t *from, server_frame_t *to ) {
newindex = 0;
oldindex = 0;
oldent = newent = 0;
- while( newindex < to->numEntities || oldindex < from_num_entities ) {
- if( newindex >= to->numEntities ) {
+ while (newindex < to->numEntities || oldindex < from_num_entities) {
+ if (newindex >= to->numEntities) {
newnum = 9999;
} else {
- i = ( to->firstEntity + newindex ) & PARSE_ENTITIES_MASK;
+ i = (to->firstEntity + newindex) & PARSE_ENTITIES_MASK;
newent = &cl.entityStates[i];
newnum = newent->number;
}
- if( oldindex >= from_num_entities ) {
+ if (oldindex >= from_num_entities) {
oldnum = 9999;
} else {
- i = ( from->firstEntity + oldindex ) & PARSE_ENTITIES_MASK;
+ i = (from->firstEntity + oldindex) & PARSE_ENTITIES_MASK;
oldent = &cl.entityStates[i];
oldnum = oldent->number;
}
- if( newnum == oldnum ) {
+ if (newnum == oldnum) {
// delta update from old position
// because the force parm is false, this will not result
// in any bytes being emited if the entity has not changed at all
// note that players are always 'newentities' in compatibility mode,
// this updates their oldorigin always and prevents warping
- MSG_WriteDeltaEntity( oldent, newent,
- newent->number <= cl.maxclients ? MSG_ES_NEWENTITY : 0 );
+ MSG_WriteDeltaEntity(oldent, newent,
+ newent->number <= cl.maxclients ? MSG_ES_NEWENTITY : 0);
oldindex++;
newindex++;
continue;
}
- if( newnum < oldnum ) {
+ if (newnum < oldnum) {
// this is a new entity, send it from the baseline
- MSG_WriteDeltaEntity( &cl.baselines[newnum], newent,
- MSG_ES_FORCE|MSG_ES_NEWENTITY );
+ MSG_WriteDeltaEntity(&cl.baselines[newnum], newent,
+ MSG_ES_FORCE | MSG_ES_NEWENTITY);
newindex++;
continue;
}
- if( newnum > oldnum ) {
+ if (newnum > oldnum) {
// the old entity isn't present in the new message
- MSG_WriteDeltaEntity( oldent, NULL, MSG_ES_FORCE );
+ MSG_WriteDeltaEntity(oldent, NULL, MSG_ES_FORCE);
oldindex++;
continue;
}
}
- MSG_WriteShort( 0 ); // end of packetentities
+ MSG_WriteShort(0); // end of packetentities
}
-static void emit_delta_frame( server_frame_t *from, server_frame_t *to,
- int fromnum, int tonum )
+static void emit_delta_frame(server_frame_t *from, server_frame_t *to,
+ int fromnum, int tonum)
{
- MSG_WriteByte( svc_frame );
- MSG_WriteLong( tonum );
- MSG_WriteLong( fromnum ); // what we are delta'ing from
- MSG_WriteByte( 0 ); // rate dropped packets
+ MSG_WriteByte(svc_frame);
+ MSG_WriteLong(tonum);
+ MSG_WriteLong(fromnum); // what we are delta'ing from
+ MSG_WriteByte(0); // rate dropped packets
// send over the areabits
- MSG_WriteByte( to->areabytes );
- MSG_WriteData( to->areabits, to->areabytes );
+ MSG_WriteByte(to->areabytes);
+ MSG_WriteData(to->areabits, to->areabytes);
// delta encode the playerstate
- MSG_WriteByte( svc_playerinfo );
- MSG_WriteDeltaPlayerstate_Default( from ? &from->ps : NULL, &to->ps );
+ MSG_WriteByte(svc_playerinfo);
+ MSG_WriteDeltaPlayerstate_Default(from ? &from->ps : NULL, &to->ps);
// delta encode the entities
- MSG_WriteByte( svc_packetentities );
- emit_packet_entities( from, to );
+ MSG_WriteByte(svc_packetentities);
+ emit_packet_entities(from, to);
}
// the only place where last_frame is updated
-static void flush_demo_frame( void ) {
- if( cls.demo.buffer.cursize + msg_write.cursize > cls.demo.buffer.maxsize ) {
- Com_DPrintf( "Demo frame overflowed\n" );
+static void flush_demo_frame(void)
+{
+ if (cls.demo.buffer.cursize + msg_write.cursize > cls.demo.buffer.maxsize) {
+ Com_DPrintf("Demo frame overflowed\n");
cls.demo.frames_dropped++;
} else {
- SZ_Write( &cls.demo.buffer, msg_write.data, msg_write.cursize );
+ SZ_Write(&cls.demo.buffer, msg_write.data, msg_write.cursize);
cls.demo.last_frame = cl.frame.number;
cls.demo.frames_written++;
}
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
}
// frames_written counter starts at 0, but we add 1 to every frame number
@@ -184,13 +187,14 @@ CL_EmitDemoFrame
Writes delta from the last frame we got to the current frame.
====================
*/
-void CL_EmitDemoFrame( void ) {
+void CL_EmitDemoFrame(void)
+{
server_frame_t *oldframe;
player_state_t *oldstate;
int lastframe;
// the first frame is delta uncompressed
- if( FRAME_PRE == 0 ) {
+ if (FRAME_PRE == 0) {
oldframe = NULL;
oldstate = NULL;
lastframe = -1;
@@ -198,9 +202,8 @@ void CL_EmitDemoFrame( void ) {
oldframe = &cl.frames[cls.demo.last_frame & UPDATE_MASK];
oldstate = &oldframe->ps;
lastframe = FRAME_PRE;
- if( oldframe->number != cls.demo.last_frame || !oldframe->valid ||
- cl.numEntityStates - oldframe->firstEntity > MAX_PARSE_ENTITIES )
- {
+ if (oldframe->number != cls.demo.last_frame || !oldframe->valid ||
+ cl.numEntityStates - oldframe->firstEntity > MAX_PARSE_ENTITIES) {
oldframe = NULL;
oldstate = NULL;
lastframe = -1;
@@ -208,55 +211,57 @@ void CL_EmitDemoFrame( void ) {
}
// emit and flush frame
- emit_delta_frame( oldframe, &cl.frame, lastframe, FRAME_CUR );
+ emit_delta_frame(oldframe, &cl.frame, lastframe, FRAME_CUR);
flush_demo_frame();
}
-static void emit_zero_frame( void ) {
+static void emit_zero_frame(void)
+{
int lastframe;
// the first frame is delta uncompressed
- if( FRAME_PRE == 0 )
+ if (FRAME_PRE == 0)
lastframe = -1;
else
lastframe = FRAME_PRE;
- MSG_WriteByte( svc_frame );
- MSG_WriteLong( FRAME_CUR );
- MSG_WriteLong( lastframe ); // what we are delta'ing from
- MSG_WriteByte( 0 ); // rate dropped packets
+ MSG_WriteByte(svc_frame);
+ MSG_WriteLong(FRAME_CUR);
+ MSG_WriteLong(lastframe); // what we are delta'ing from
+ MSG_WriteByte(0); // rate dropped packets
// send over the areabits
- MSG_WriteByte( cl.frame.areabytes );
- MSG_WriteData( cl.frame.areabits, cl.frame.areabytes );
+ MSG_WriteByte(cl.frame.areabytes);
+ MSG_WriteData(cl.frame.areabits, cl.frame.areabytes);
- MSG_WriteByte( svc_playerinfo );
- MSG_WriteShort( 0 );
- MSG_WriteLong( 0 );
+ MSG_WriteByte(svc_playerinfo);
+ MSG_WriteShort(0);
+ MSG_WriteLong(0);
- MSG_WriteByte( svc_packetentities );
- MSG_WriteShort( 0 );
+ MSG_WriteByte(svc_packetentities);
+ MSG_WriteShort(0);
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (!CL_WriteDemoMessage(&msg_write))
return;
cls.demo.frames_written++;
}
-static size_t format_demo_status( char *buffer, size_t size ) {
- off_t pos = FS_Tell( cls.demo.recording );
- size_t len = Com_FormatSizeLong( buffer, size, pos );
+static size_t format_demo_status(char *buffer, size_t size)
+{
+ off_t pos = FS_Tell(cls.demo.recording);
+ size_t len = Com_FormatSizeLong(buffer, size, pos);
int min, sec, frames = cls.demo.frames_written;
sec = frames / 10; frames %= 10;
min = sec / 60; sec %= 60;
- len += Q_scnprintf( buffer + len, size - len, ", %d:%02d.%d",
- min, sec, frames );
+ len += Q_scnprintf(buffer + len, size - len, ", %d:%02d.%d",
+ min, sec, frames);
- if( cls.demo.frames_dropped || cls.demo.messages_dropped ) {
- len += Q_scnprintf( buffer + len, size - len, ", %d/%d dropped",
- cls.demo.frames_dropped, cls.demo.messages_dropped );
+ if (cls.demo.frames_dropped || cls.demo.messages_dropped) {
+ len += Q_scnprintf(buffer + len, size - len, ", %d/%d dropped",
+ cls.demo.frames_dropped, cls.demo.messages_dropped);
}
return len;
@@ -269,31 +274,32 @@ CL_Stop_f
stop recording a demo
====================
*/
-void CL_Stop_f( void ) {
+void CL_Stop_f(void)
+{
uint32_t msglen;
char buffer[MAX_QPATH];
- if( !cls.demo.recording ) {
- Com_Printf( "Not recording a demo.\n" );
+ if (!cls.demo.recording) {
+ Com_Printf("Not recording a demo.\n");
return;
}
- if( cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2) {
// tell the server we finished recording
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_RECORDING );
- MSG_WriteShort( 0 );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_RECORDING);
+ MSG_WriteShort(0);
+ MSG_FlushTo(&cls.netchan->message);
}
// finish up
- msglen = ( uint32_t )-1;
- FS_Write( &msglen, 4, cls.demo.recording );
+ msglen = (uint32_t)-1;
+ FS_Write(&msglen, 4, cls.demo.recording);
- format_demo_status( buffer, sizeof( buffer ) );
+ format_demo_status(buffer, sizeof(buffer));
// close demofile
- FS_FCloseFile( cls.demo.recording );
+ FS_FCloseFile(cls.demo.recording);
cls.demo.recording = 0;
cls.demo.paused = qfalse;
cls.demo.frames_written = 0;
@@ -301,7 +307,7 @@ void CL_Stop_f( void ) {
cls.demo.messages_dropped = 0;
// print some statistics
- Com_Printf( "Stopped demo (%s).\n", buffer );
+ Com_Printf("Stopped demo (%s).\n", buffer);
}
static const cmd_option_t o_record[] = {
@@ -321,7 +327,8 @@ record <demoname>
Begins recording a demo from the current position
====================
*/
-static void CL_Record_f( void ) {
+static void CL_Record_f(void)
+{
char buffer[MAX_OSPATH];
int i, c;
size_t len;
@@ -330,16 +337,16 @@ static void CL_Record_f( void ) {
qhandle_t f;
unsigned mode = FS_MODE_WRITE;
size_t size = Cvar_ClampInteger(
- cl_demomsglen,
- MIN_PACKETLEN,
- MAX_PACKETLEN_WRITABLE );
+ cl_demomsglen,
+ MIN_PACKETLEN,
+ MAX_PACKETLEN_WRITABLE);
- while( ( c = Cmd_ParseOptions( o_record ) ) != -1 ) {
- switch( c ) {
+ while ((c = Cmd_ParseOptions(o_record)) != -1) {
+ switch (c) {
case 'h':
- Cmd_PrintUsage( o_record, "<filename>" );
- Com_Printf( "Begin client demo recording.\n" );
- Cmd_PrintHelp( o_record );
+ Cmd_PrintUsage(o_record, "<filename>");
+ Com_Printf("Begin client demo recording.\n");
+ Cmd_PrintHelp(o_record);
return;
case 'z':
mode |= FS_FLAG_GZIP;
@@ -354,50 +361,50 @@ static void CL_Record_f( void ) {
}
}
- if( cls.demo.recording ) {
- format_demo_status( buffer, sizeof( buffer ) );
- Com_Printf( "Already recording (%s).\n", buffer );
+ if (cls.demo.recording) {
+ format_demo_status(buffer, sizeof(buffer));
+ Com_Printf("Already recording (%s).\n", buffer);
return;
}
- if( !cmd_optarg[0] ) {
- Com_Printf( "Missing filename argument.\n" );
+ if (!cmd_optarg[0]) {
+ Com_Printf("Missing filename argument.\n");
Cmd_PrintHint();
return;
}
- if( cls.state != ca_active ) {
- Com_Printf( "You must be in a level to record.\n" );
+ if (cls.state != ca_active) {
+ Com_Printf("You must be in a level to record.\n");
return;
}
//
// open the demo file
//
- f = FS_EasyOpenFile( buffer, sizeof( buffer ), mode,
- "demos/", cmd_optarg, ".dm2" );
- if( !f ) {
+ f = FS_EasyOpenFile(buffer, sizeof(buffer), mode,
+ "demos/", cmd_optarg, ".dm2");
+ if (!f) {
return;
}
- Com_Printf( "Recording client demo to %s.\n", buffer );
+ Com_Printf("Recording client demo to %s.\n", buffer);
cls.demo.recording = f;
cls.demo.paused = qfalse;
- SZ_Init( &cls.demo.buffer, demo_buffer, size );
+ SZ_Init(&cls.demo.buffer, demo_buffer, size);
demo_extra = 0;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
- if( cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2 ) {
+ if (cls.netchan && cls.serverProtocol >= PROTOCOL_VERSION_R1Q2) {
// tell the server we are recording
- MSG_WriteByte( clc_setting );
- MSG_WriteShort( CLS_RECORDING );
- MSG_WriteShort( 1 );
- MSG_FlushTo( &cls.netchan->message );
+ MSG_WriteByte(clc_setting);
+ MSG_WriteShort(CLS_RECORDING);
+ MSG_WriteShort(1);
+ MSG_FlushTo(&cls.netchan->message);
}
//
@@ -405,134 +412,137 @@ static void CL_Record_f( void ) {
//
// send the serverdata
- MSG_WriteByte( svc_serverdata );
- MSG_WriteLong( PROTOCOL_VERSION_DEFAULT );
- MSG_WriteLong( 0x10000 + cl.servercount );
- MSG_WriteByte( 1 ); // demos are always attract loops
- MSG_WriteString( cl.gamedir );
- MSG_WriteShort( cl.clientNum );
- MSG_WriteString( cl.configstrings[CS_NAME] );
+ MSG_WriteByte(svc_serverdata);
+ MSG_WriteLong(PROTOCOL_VERSION_DEFAULT);
+ MSG_WriteLong(0x10000 + cl.servercount);
+ MSG_WriteByte(1); // demos are always attract loops
+ MSG_WriteString(cl.gamedir);
+ MSG_WriteShort(cl.clientNum);
+ MSG_WriteString(cl.configstrings[CS_NAME]);
// configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
s = cl.configstrings[i];
- if( !*s )
+ if (!*s)
continue;
- len = strlen( s );
- if( len > MAX_QPATH )
+ len = strlen(s);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- if( msg_write.cursize + len + 4 > size ) {
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (msg_write.cursize + len + 4 > size) {
+ if (!CL_WriteDemoMessage(&msg_write))
return;
}
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( s, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(s, len);
+ MSG_WriteByte(0);
}
// baselines
- for( i = 1; i < MAX_EDICTS; i++ ) {
+ for (i = 1; i < MAX_EDICTS; i++) {
ent = &cl.baselines[i];
- if( !ent->number )
+ if (!ent->number)
continue;
- if( msg_write.cursize + 64 > size ) {
- if( !CL_WriteDemoMessage( &msg_write ) )
+ if (msg_write.cursize + 64 > size) {
+ if (!CL_WriteDemoMessage(&msg_write))
return;
}
- MSG_WriteByte( svc_spawnbaseline );
- MSG_WriteDeltaEntity( NULL, ent, MSG_ES_FORCE );
+ MSG_WriteByte(svc_spawnbaseline);
+ MSG_WriteDeltaEntity(NULL, ent, MSG_ES_FORCE);
}
- MSG_WriteByte( svc_stufftext );
- MSG_WriteString( "precache\n" );
+ MSG_WriteByte(svc_stufftext);
+ MSG_WriteString("precache\n");
// write it to the demo file
- CL_WriteDemoMessage( &msg_write );
+ CL_WriteDemoMessage(&msg_write);
// the rest of the demo file will be individual frames
}
// resumes demo recording after pause or seek. tries to fit flushed
// configstrings and frame into single packet for seamless 'stitch'
-static void resume_record( void ) {
+static void resume_record(void)
+{
int i, j, index;
size_t len;
char *s;
// write dirty configstrings
- for( i = 0; i < CS_BITMAP_LONGS; i++ ) {
- if( ((uint32_t *)cl.dcs)[i] == 0 )
+ for (i = 0; i < CS_BITMAP_LONGS; i++) {
+ if (((uint32_t *)cl.dcs)[i] == 0)
continue;
index = i << 5;
- for( j = 0; j < 32; j++, index++ ) {
- if( !Q_IsBitSet( cl.dcs, index ) )
+ for (j = 0; j < 32; j++, index++) {
+ if (!Q_IsBitSet(cl.dcs, index))
continue;
s = cl.configstrings[index];
- len = strlen( s );
- if( len > MAX_QPATH )
+ len = strlen(s);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- if( cls.demo.buffer.cursize + len + 4 > cls.demo.buffer.maxsize ) {
- if( !CL_WriteDemoMessage( &cls.demo.buffer ) )
+ if (cls.demo.buffer.cursize + len + 4 > cls.demo.buffer.maxsize) {
+ if (!CL_WriteDemoMessage(&cls.demo.buffer))
return;
// multiple packets = not seamless
}
- SZ_WriteByte( &cls.demo.buffer, svc_configstring );
- SZ_WriteShort( &cls.demo.buffer, index );
- SZ_Write( &cls.demo.buffer, s, len );
- SZ_WriteByte( &cls.demo.buffer, 0 );
+ SZ_WriteByte(&cls.demo.buffer, svc_configstring);
+ SZ_WriteShort(&cls.demo.buffer, index);
+ SZ_Write(&cls.demo.buffer, s, len);
+ SZ_WriteByte(&cls.demo.buffer, 0);
}
}
// emit and flush delta uncompressed frame
- if( cl.frame.valid ) {
- emit_delta_frame( NULL, &cl.frame, -1, FRAME_CUR );
+ if (cl.frame.valid) {
+ emit_delta_frame(NULL, &cl.frame, -1, FRAME_CUR);
flush_demo_frame();
}
// FIXME: write layout if it fits? most likely it won't
// write it to the demo file
- CL_WriteDemoMessage( &cls.demo.buffer );
+ CL_WriteDemoMessage(&cls.demo.buffer);
}
-static void CL_Suspend_f( void ) {
- if( !cls.demo.recording ) {
- Com_Printf( "Not recording a demo.\n" );
+static void CL_Suspend_f(void)
+{
+ if (!cls.demo.recording) {
+ Com_Printf("Not recording a demo.\n");
return;
}
- if( !cls.demo.paused ) {
- Com_Printf( "Suspended demo recording.\n" );
+ if (!cls.demo.paused) {
+ Com_Printf("Suspended demo recording.\n");
cls.demo.paused = qtrue;
return;
}
resume_record();
- if( !cls.demo.recording )
+ if (!cls.demo.recording)
// write failed
return;
- Com_Printf( "Resumed demo recording.\n" );
+ Com_Printf("Resumed demo recording.\n");
cls.demo.paused = qfalse;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
}
-static int read_first_message( qhandle_t f ) {
+static int read_first_message(qhandle_t f)
+{
uint32_t ul;
uint16_t us;
size_t msglen;
@@ -541,127 +551,131 @@ static int read_first_message( qhandle_t f ) {
int type;
// read magic/msglen
- read = FS_Read( &ul, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&ul, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
// check for gzip header
- if( CHECK_GZIP_HEADER( ul ) ) {
- ret = FS_FilterFile( f );
- if( ret ) {
+ if (CHECK_GZIP_HEADER(ul)) {
+ ret = FS_FilterFile(f);
+ if (ret) {
return ret;
}
- read = FS_Read( &ul, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&ul, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
}
// determine demo type
- if( ul == MVD_MAGIC ) {
- read = FS_Read( &us, 2, f );
- if( read != 2 ) {
+ if (ul == MVD_MAGIC) {
+ read = FS_Read(&us, 2, f);
+ if (read != 2) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
- if( !us ) {
+ if (!us) {
return Q_ERR_UNEXPECTED_EOF;
}
- msglen = LittleShort( us );
+ msglen = LittleShort(us);
type = 1;
} else {
- if( ul == ( uint32_t )-1 ) {
+ if (ul == (uint32_t)-1) {
return Q_ERR_UNEXPECTED_EOF;
}
- msglen = LittleLong( ul );
+ msglen = LittleLong(ul);
type = 0;
}
- if( msglen < 64 || msglen > sizeof( msg_read_buffer ) ) {
+ if (msglen < 64 || msglen > sizeof(msg_read_buffer)) {
return Q_ERR_INVALID_FORMAT;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
// read packet data
- read = FS_Read( msg_read.data, msglen, f );
- if( read != msglen ) {
+ read = FS_Read(msg_read.data, msglen, f);
+ if (read != msglen) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
return type;
}
-static int read_next_message( qhandle_t f ) {
+static int read_next_message(qhandle_t f)
+{
uint32_t msglen;
ssize_t read;
// read msglen
- read = FS_Read( &msglen, 4, f );
- if( read != 4 ) {
+ read = FS_Read(&msglen, 4, f);
+ if (read != 4) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
// check for EOF packet
- if( msglen == ( uint32_t )-1 ) {
+ if (msglen == (uint32_t)-1) {
return 0;
}
- msglen = LittleLong( msglen );
- if( msglen > sizeof( msg_read_buffer ) ) {
+ msglen = LittleLong(msglen);
+ if (msglen > sizeof(msg_read_buffer)) {
return Q_ERR_INVALID_FORMAT;
}
- SZ_Init( &msg_read, msg_read_buffer, sizeof( msg_read_buffer ) );
+ SZ_Init(&msg_read, msg_read_buffer, sizeof(msg_read_buffer));
msg_read.cursize = msglen;
// read packet data
- read = FS_Read( msg_read.data, msglen, f );
- if( read != msglen ) {
+ read = FS_Read(msg_read.data, msglen, f);
+ if (read != msglen) {
return read < 0 ? read : Q_ERR_UNEXPECTED_EOF;
}
return 1;
}
-static void finish_demo( int ret ) {
- char *s = Cvar_VariableString( "nextserver" );
+static void finish_demo(int ret)
+{
+ char *s = Cvar_VariableString("nextserver");
- if( !s[0] ) {
- if( ret == 0 ) {
- Com_Error( ERR_DISCONNECT, "Demo finished" );
+ if (!s[0]) {
+ if (ret == 0) {
+ Com_Error(ERR_DISCONNECT, "Demo finished");
} else {
- Com_Error( ERR_DROP, "Couldn't read demo: %s", Q_ErrorString( ret ) );
+ Com_Error(ERR_DROP, "Couldn't read demo: %s", Q_ErrorString(ret));
}
}
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
- Cvar_Set( "nextserver", "" );
+ Cvar_Set("nextserver", "");
- Cbuf_AddText( &cmd_buffer, s );
- Cbuf_AddText( &cmd_buffer, "\n" );
- Cbuf_Execute( &cmd_buffer );
+ Cbuf_AddText(&cmd_buffer, s);
+ Cbuf_AddText(&cmd_buffer, "\n");
+ Cbuf_Execute(&cmd_buffer);
}
-static void update_status( void ) {
- if( cls.demo.file_size ) {
- off_t pos = FS_Tell( cls.demo.playback );
+static void update_status(void)
+{
+ if (cls.demo.file_size) {
+ off_t pos = FS_Tell(cls.demo.playback);
- if( pos > cls.demo.file_offset )
- cls.demo.file_percent = ( pos - cls.demo.file_offset ) * 100 / cls.demo.file_size;
+ if (pos > cls.demo.file_offset)
+ cls.demo.file_percent = (pos - cls.demo.file_offset) * 100 / cls.demo.file_size;
else
cls.demo.file_percent = 0;
}
}
-static void parse_next_message( void ) {
+static void parse_next_message(void)
+{
int ret;
- ret = read_next_message( cls.demo.playback );
- if( ret <= 0 ) {
- finish_demo( ret );
+ ret = read_next_message(cls.demo.playback);
+ if (ret <= 0) {
+ finish_demo(ret);
return;
}
@@ -675,62 +689,64 @@ static void parse_next_message( void ) {
CL_PlayDemo_f
====================
*/
-static void CL_PlayDemo_f( void ) {
+static void CL_PlayDemo_f(void)
+{
char name[MAX_OSPATH];
qhandle_t f;
int type;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s <filename>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s <filename>\n", Cmd_Argv(0));
return;
}
- f = FS_EasyOpenFile( name, sizeof( name ), FS_MODE_READ,
- "demos/", Cmd_Argv( 1 ), ".dm2" );
- if( !f ) {
+ f = FS_EasyOpenFile(name, sizeof(name), FS_MODE_READ,
+ "demos/", Cmd_Argv(1), ".dm2");
+ if (!f) {
return;
}
- type = read_first_message( f );
- if( type < 0 ) {
- Com_Printf( "Couldn't read %s: %s\n", name, Q_ErrorString( type ) );
- FS_FCloseFile( f );
+ type = read_first_message(f);
+ if (type < 0) {
+ Com_Printf("Couldn't read %s: %s\n", name, Q_ErrorString(type));
+ FS_FCloseFile(f);
return;
}
- if( type == 1 ) {
+ if (type == 1) {
#if USE_MVD_CLIENT
- Cbuf_InsertText( &cmd_buffer, va( "mvdplay --replace @@ \"/%s\"\n", name ) );
+ Cbuf_InsertText(&cmd_buffer, va("mvdplay --replace @@ \"/%s\"\n", name));
#else
- Com_Printf( "MVD support was not compiled in.\n" );
+ Com_Printf("MVD support was not compiled in.\n");
#endif
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return;
}
// if running a local server, kill it and reissue
- SV_Shutdown( "Server was killed.\n", ERR_DISCONNECT );
+ SV_Shutdown("Server was killed.\n", ERR_DISCONNECT);
- CL_Disconnect( ERR_RECONNECT );
+ CL_Disconnect(ERR_RECONNECT);
cls.demo.playback = f;
cls.state = ca_connected;
- Q_strlcpy( cls.servername, COM_SkipPath( name ), sizeof( cls.servername ) );
+ Q_strlcpy(cls.servername, COM_SkipPath(name), sizeof(cls.servername));
cls.serverAddress.type = NA_LOOPBACK;
Con_Popup();
SCR_UpdateScreen();
CL_ParseServerMessage();
- while( cls.state == ca_connected ) {
- Cbuf_Execute( &cl_cmdbuf );
+ while (cls.state == ca_connected) {
+ Cbuf_Execute(&cl_cmdbuf);
parse_next_message();
}
}
-static void CL_Demo_c( genctx_t *ctx, int argnum ) {
- if( argnum == 1 ) {
- FS_File_g( "demos", "*.dm2;*.dm2.gz;*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx );
+static void CL_Demo_c(genctx_t *ctx, int argnum)
+{
+ if (argnum == 1) {
+ FS_File_g("demos", "*.dm2;*.dm2.gz;*.mvd2;*.mvd2.gz", FS_SEARCH_SAVEPATH | FS_SEARCH_BYFILTER, ctx);
}
}
@@ -750,7 +766,8 @@ Periodically builds a fake demo packet used to reconstruct delta compression
state, configstrings and layouts at the given server frame.
====================
*/
-void CL_EmitDemoSnapshot( void ) {
+void CL_EmitDemoSnapshot(void)
+{
demosnap_t *snap;
off_t pos;
char *from, *to;
@@ -758,86 +775,86 @@ void CL_EmitDemoSnapshot( void ) {
server_frame_t *lastframe, *frame;
int i, j, lastnum;
- if( cl_demosnaps->integer <= 0 )
+ if (cl_demosnaps->integer <= 0)
return;
- if( cls.demo.frames_read < cls.demo.last_snapshot + cl_demosnaps->integer * 10 )
+ if (cls.demo.frames_read < cls.demo.last_snapshot + cl_demosnaps->integer * 10)
return;
- if( !cl.frame.valid )
+ if (!cl.frame.valid)
return;
- if( !cls.demo.file_size )
+ if (!cls.demo.file_size)
return;
- pos = FS_Tell( cls.demo.playback );
- if( pos < cls.demo.file_offset )
+ pos = FS_Tell(cls.demo.playback);
+ if (pos < cls.demo.file_offset)
return;
// write all the backups, since we can't predict what frame the next
// delta will come from
lastframe = NULL;
lastnum = -1;
- for( i = 0; i < UPDATE_BACKUP; i++ ) {
- j = cl.frame.number - ( UPDATE_BACKUP - 1 ) + i;
+ for (i = 0; i < UPDATE_BACKUP; i++) {
+ j = cl.frame.number - (UPDATE_BACKUP - 1) + i;
frame = &cl.frames[j & UPDATE_MASK];
- if( frame->number != j || !frame->valid ||
- cl.numEntityStates - frame->firstEntity > MAX_PARSE_ENTITIES )
- {
+ if (frame->number != j || !frame->valid ||
+ cl.numEntityStates - frame->firstEntity > MAX_PARSE_ENTITIES) {
continue;
}
- emit_delta_frame( lastframe, frame, lastnum, j );
+ emit_delta_frame(lastframe, frame, lastnum, j);
lastframe = frame;
lastnum = frame->number;
}
// write configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = cl.baseconfigstrings[i];
to = cl.configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- len = strlen( to );
- if( len > MAX_QPATH )
+ len = strlen(to);
+ if (len > MAX_QPATH)
len = MAX_QPATH;
- MSG_WriteByte( svc_configstring );
- MSG_WriteShort( i );
- MSG_WriteData( to, len );
- MSG_WriteByte( 0 );
+ MSG_WriteByte(svc_configstring);
+ MSG_WriteShort(i);
+ MSG_WriteData(to, len);
+ MSG_WriteByte(0);
}
// write layout
- MSG_WriteByte( svc_layout );
- MSG_WriteString( cl.layout );
+ MSG_WriteByte(svc_layout);
+ MSG_WriteString(cl.layout);
- snap = Z_Malloc( sizeof( *snap ) + msg_write.cursize - 1 );
+ snap = Z_Malloc(sizeof(*snap) + msg_write.cursize - 1);
snap->framenum = cls.demo.frames_read;
snap->filepos = pos;
snap->msglen = msg_write.cursize;
- memcpy( snap->data, msg_write.data, msg_write.cursize );
- List_Append( &cls.demo.snapshots, &snap->entry );
+ memcpy(snap->data, msg_write.data, msg_write.cursize);
+ List_Append(&cls.demo.snapshots, &snap->entry);
- Com_DPrintf( "[%d] snaplen %"PRIz"\n", cls.demo.frames_read, msg_write.cursize );
+ Com_DPrintf("[%d] snaplen %"PRIz"\n", cls.demo.frames_read, msg_write.cursize);
- SZ_Clear( &msg_write );
+ SZ_Clear(&msg_write);
cls.demo.last_snapshot = cls.demo.frames_read;
}
-static demosnap_t *find_snapshot( int framenum ) {
+static demosnap_t *find_snapshot(int framenum)
+{
demosnap_t *snap, *prev;
- if( LIST_EMPTY( &cls.demo.snapshots ) )
+ if (LIST_EMPTY(&cls.demo.snapshots))
return NULL;
- prev = LIST_FIRST( demosnap_t, &cls.demo.snapshots, entry );
+ prev = LIST_FIRST(demosnap_t, &cls.demo.snapshots, entry);
- LIST_FOR_EACH( demosnap_t, snap, &cls.demo.snapshots, entry ) {
- if( snap->framenum > framenum )
+ LIST_FOR_EACH(demosnap_t, snap, &cls.demo.snapshots, entry) {
+ if (snap->framenum > framenum)
break;
prev = snap;
}
@@ -852,24 +869,25 @@ CL_FirstDemoFrame
Called after the first valid frame is parsed from the demo.
====================
*/
-void CL_FirstDemoFrame( void ) {
+void CL_FirstDemoFrame(void)
+{
ssize_t len, ofs;
- Com_DPrintf( "[%d] first frame\n", cl.frame.number );
+ Com_DPrintf("[%d] first frame\n", cl.frame.number);
// save base configstrings
- memcpy( cl.baseconfigstrings, cl.configstrings, sizeof( cl.baseconfigstrings ) );
+ memcpy(cl.baseconfigstrings, cl.configstrings, sizeof(cl.baseconfigstrings));
// obtain file length and offset of the second frame
- len = FS_Length( cls.demo.playback );
- ofs = FS_Tell( cls.demo.playback );
- if( len > 0 && ofs > 0 ) {
+ len = FS_Length(cls.demo.playback);
+ ofs = FS_Tell(cls.demo.playback);
+ if (len > 0 && ofs > 0) {
cls.demo.file_offset = ofs;
cls.demo.file_size = len - ofs;
}
// begin timedemo
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
cls.demo.time_frames = 0;
cls.demo.time_start = Sys_Milliseconds();
}
@@ -878,49 +896,50 @@ void CL_FirstDemoFrame( void ) {
cls.demo.last_snapshot = INT_MIN;
}
-static void CL_Seek_f( void ) {
+static void CL_Seek_f(void)
+{
demosnap_t *snap;
int i, j, ret, index, frames, dest, prev;
char *from, *to;
- if( Cmd_Argc() < 2 ) {
- Com_Printf( "Usage: %s [+-]<timespec>\n", Cmd_Argv( 0 ) );
+ if (Cmd_Argc() < 2) {
+ Com_Printf("Usage: %s [+-]<timespec>\n", Cmd_Argv(0));
return;
}
#if USE_MVD_CLIENT
- if( sv_running->integer == ss_broadcast ) {
- Cbuf_InsertText( &cmd_buffer, va( "mvdseek \"%s\" @@\n", Cmd_Argv( 1 ) ) );
+ if (sv_running->integer == ss_broadcast) {
+ Cbuf_InsertText(&cmd_buffer, va("mvdseek \"%s\" @@\n", Cmd_Argv(1)));
return;
}
#endif
- if( !cls.demo.playback ) {
- Com_Printf( "Not playing a demo.\n" );
+ if (!cls.demo.playback) {
+ Com_Printf("Not playing a demo.\n");
return;
}
- to = Cmd_Argv( 1 );
+ to = Cmd_Argv(1);
- if( *to == '-' || *to == '+' ) {
+ if (*to == '-' || *to == '+') {
// relative to current frame
- if( !Com_ParseTimespec( to + 1, &frames ) ) {
- Com_Printf( "Invalid relative timespec.\n" );
+ if (!Com_ParseTimespec(to + 1, &frames)) {
+ Com_Printf("Invalid relative timespec.\n");
return;
}
- if( *to == '-' )
+ if (*to == '-')
frames = -frames;
dest = cls.demo.frames_read + frames;
} else {
// relative to first frame
- if( !Com_ParseTimespec( to, &dest ) ) {
- Com_Printf( "Invalid absolute timespec.\n" );
+ if (!Com_ParseTimespec(to, &dest)) {
+ Com_Printf("Invalid absolute timespec.\n");
return;
}
frames = dest - cls.demo.frames_read;
}
- if( !frames )
+ if (!frames)
// already there
return;
@@ -928,7 +947,7 @@ static void CL_Seek_f( void ) {
cls.demo.seeking = qtrue;
// clear dirty configstrings
- memset( cl.dcs, 0, sizeof( cl.dcs ) );
+ memset(cl.dcs, 0, sizeof(cl.dcs));
// stop sounds
S_StopAllSounds();
@@ -936,49 +955,49 @@ static void CL_Seek_f( void ) {
// save previous server frame number
prev = cl.frame.number;
- Com_DPrintf( "[%d] seeking to %d\n", cls.demo.frames_read, dest );
+ Com_DPrintf("[%d] seeking to %d\n", cls.demo.frames_read, dest);
// seek to the previous most recent snapshot
- if( frames < 0 || cls.demo.last_snapshot > cls.demo.frames_read ) {
- snap = find_snapshot( dest );
-
- if( snap ) {
- Com_DPrintf( "found snap at %d\n", snap->framenum );
- ret = FS_Seek( cls.demo.playback, snap->filepos );
- if( ret < 0 ) {
- Com_EPrintf( "Couldn't seek demo: %s\n", Q_ErrorString( ret ) );
+ if (frames < 0 || cls.demo.last_snapshot > cls.demo.frames_read) {
+ snap = find_snapshot(dest);
+
+ if (snap) {
+ Com_DPrintf("found snap at %d\n", snap->framenum);
+ ret = FS_Seek(cls.demo.playback, snap->filepos);
+ if (ret < 0) {
+ Com_EPrintf("Couldn't seek demo: %s\n", Q_ErrorString(ret));
goto done;
}
// reset configstrings
- for( i = 0; i < MAX_CONFIGSTRINGS; i++ ) {
+ for (i = 0; i < MAX_CONFIGSTRINGS; i++) {
from = cl.baseconfigstrings[i];
to = cl.configstrings[i];
- if( !strcmp( from, to ) )
+ if (!strcmp(from, to))
continue;
- Q_SetBit( cl.dcs, i );
- strcpy( to, from );
+ Q_SetBit(cl.dcs, i);
+ strcpy(to, from);
}
- SZ_Init( &msg_read, snap->data, snap->msglen );
+ SZ_Init(&msg_read, snap->data, snap->msglen);
msg_read.cursize = snap->msglen;
CL_SeekDemoMessage();
cls.demo.frames_read = snap->framenum;
- Com_DPrintf( "[%d] after snap parse %d\n", cls.demo.frames_read, cl.frame.number );
- } else if( frames < 0 ) {
- Com_Printf( "Couldn't seek backwards without snapshots!\n" );
+ Com_DPrintf("[%d] after snap parse %d\n", cls.demo.frames_read, cl.frame.number);
+ } else if (frames < 0) {
+ Com_Printf("Couldn't seek backwards without snapshots!\n");
goto done;
}
}
// skip forward to destination frame
- while( cls.demo.frames_read < dest ) {
- ret = read_next_message( cls.demo.playback );
- if( ret <= 0 ) {
- finish_demo( ret );
+ while (cls.demo.frames_read < dest) {
+ ret = read_next_message(cls.demo.playback);
+ if (ret <= 0) {
+ finish_demo(ret);
return;
}
@@ -986,24 +1005,24 @@ static void CL_Seek_f( void ) {
CL_EmitDemoSnapshot();
}
- Com_DPrintf( "[%d] after skip %d\n", cls.demo.frames_read, cl.frame.number );
+ Com_DPrintf("[%d] after skip %d\n", cls.demo.frames_read, cl.frame.number);
// update dirty configstrings
- for( i = 0; i < CS_BITMAP_LONGS; i++ ) {
- if( ((uint32_t *)cl.dcs)[i] == 0 )
+ for (i = 0; i < CS_BITMAP_LONGS; i++) {
+ if (((uint32_t *)cl.dcs)[i] == 0)
continue;
index = i << 5;
- for( j = 0; j < 32; j++, index++ ) {
- if( Q_IsBitSet( cl.dcs, index ) )
- CL_UpdateConfigstring( index );
+ for (j = 0; j < 32; j++, index++) {
+ if (Q_IsBitSet(cl.dcs, index))
+ CL_UpdateConfigstring(index);
}
}
// don't lerp to old
- memset( &cl.oldframe, 0, sizeof( cl.oldframe ) );
+ memset(&cl.oldframe, 0, sizeof(cl.oldframe));
#if USE_FPS
- memset( &cl.oldkeyframe, 0, sizeof( cl.oldkeyframe ) );
+ memset(&cl.oldkeyframe, 0, sizeof(cl.oldkeyframe));
#endif
// clear old effects
@@ -1016,7 +1035,7 @@ static void CL_Seek_f( void ) {
// fire up destination frame
CL_DeltaFrame();
- if( cls.demo.recording && !cls.demo.paused )
+ if (cls.demo.recording && !cls.demo.paused)
resume_record();
update_status();
@@ -1027,23 +1046,24 @@ done:
cls.demo.seeking = qfalse;
}
-static void parse_info_string( demoInfo_t *info, int clientNum, int index, const char *string ) {
+static void parse_info_string(demoInfo_t *info, int clientNum, int index, const char *string)
+{
size_t len;
char *p;
- if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS ) {
- if( index - CS_PLAYERSKINS == clientNum ) {
- Q_strlcpy( info->pov, string, sizeof( info->pov ) );
- p = strchr( info->pov, '\\' );
- if( p ) {
+ if (index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + MAX_CLIENTS) {
+ if (index - CS_PLAYERSKINS == clientNum) {
+ Q_strlcpy(info->pov, string, sizeof(info->pov));
+ p = strchr(info->pov, '\\');
+ if (p) {
*p = 0;
}
}
- } else if( index == CS_MODELS + 1 ) {
- len = strlen( string );
- if( len > 9 ) {
- memcpy( info->map, string + 5, len - 9 ); // skip "maps/"
- info->map[ len - 9 ] = 0; // cut off ".bsp"
+ } else if (index == CS_MODELS + 1) {
+ len = strlen(string);
+ if (len > 9) {
+ memcpy(info->map, string + 5, len - 9); // skip "maps/"
+ info->map[len - 9] = 0; // cut off ".bsp"
}
}
}
@@ -1053,126 +1073,128 @@ static void parse_info_string( demoInfo_t *info, int clientNum, int index, const
CL_GetDemoInfo
====================
*/
-demoInfo_t *CL_GetDemoInfo( const char *path, demoInfo_t *info ) {
+demoInfo_t *CL_GetDemoInfo(const char *path, demoInfo_t *info)
+{
qhandle_t f;
int c, index;
char string[MAX_QPATH];
int clientNum, type;
- FS_FOpenFile( path, &f, FS_MODE_READ );
- if( !f ) {
+ FS_FOpenFile(path, &f, FS_MODE_READ);
+ if (!f) {
return NULL;
}
- type = read_first_message( f );
- if( type < 0 ) {
+ type = read_first_message(f);
+ if (type < 0) {
goto fail;
}
- if( type == 0 ) {
- if( MSG_ReadByte() != svc_serverdata ) {
+ if (type == 0) {
+ if (MSG_ReadByte() != svc_serverdata) {
goto fail;
}
- if( MSG_ReadLong() != PROTOCOL_VERSION_DEFAULT ) {
+ if (MSG_ReadLong() != PROTOCOL_VERSION_DEFAULT) {
goto fail;
}
MSG_ReadLong();
MSG_ReadByte();
- MSG_ReadString( NULL, 0);
+ MSG_ReadString(NULL, 0);
clientNum = MSG_ReadShort();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
- while( 1 ) {
+ while (1) {
c = MSG_ReadByte();
- if( c == -1 ) {
- if( read_next_message( f ) <= 0 ) {
+ if (c == -1) {
+ if (read_next_message(f) <= 0) {
break;
}
continue; // parse new message
}
- if( c != svc_configstring ) {
+ if (c != svc_configstring) {
break;
}
index = MSG_ReadShort();
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
goto fail;
}
- MSG_ReadString( string, sizeof( string ) );
- parse_info_string( info, clientNum, index, string );
+ MSG_ReadString(string, sizeof(string));
+ parse_info_string(info, clientNum, index, string);
}
info->mvd = qfalse;
} else {
- if( ( MSG_ReadByte() & SVCMD_MASK ) != mvd_serverdata ) {
+ if ((MSG_ReadByte() & SVCMD_MASK) != mvd_serverdata) {
goto fail;
}
- if( MSG_ReadLong() != PROTOCOL_VERSION_MVD ) {
+ if (MSG_ReadLong() != PROTOCOL_VERSION_MVD) {
goto fail;
}
MSG_ReadShort();
MSG_ReadLong();
- MSG_ReadString( NULL, 0 );
+ MSG_ReadString(NULL, 0);
clientNum = MSG_ReadShort();
- while( 1 ) {
+ while (1) {
index = MSG_ReadShort();
- if( index == MAX_CONFIGSTRINGS ) {
+ if (index == MAX_CONFIGSTRINGS) {
break;
}
- if( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+ if (index < 0 || index >= MAX_CONFIGSTRINGS) {
goto fail;
}
- MSG_ReadString( string, sizeof( string ) );
- parse_info_string( info, clientNum, index, string );
+ MSG_ReadString(string, sizeof(string));
+ parse_info_string(info, clientNum, index, string);
}
info->mvd = qtrue;
}
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return info;
fail:
- FS_FCloseFile( f );
+ FS_FCloseFile(f);
return NULL;
}
// =========================================================================
-void CL_CleanupDemos( void ) {
+void CL_CleanupDemos(void)
+{
demosnap_t *snap, *next;
size_t total;
- if( cls.demo.recording ) {
+ if (cls.demo.recording) {
CL_Stop_f();
}
- if( cls.demo.playback ) {
- FS_FCloseFile( cls.demo.playback );
+ if (cls.demo.playback) {
+ FS_FCloseFile(cls.demo.playback);
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
unsigned msec = Sys_Milliseconds();
- float sec = ( msec - cls.demo.time_start ) * 0.001f;
+ float sec = (msec - cls.demo.time_start) * 0.001f;
float fps = cls.demo.time_frames / sec;
- Com_Printf( "%u frames, %3.1f seconds: %3.1f fps\n",
- cls.demo.time_frames, sec, fps );
+ Com_Printf("%u frames, %3.1f seconds: %3.1f fps\n",
+ cls.demo.time_frames, sec, fps);
}
}
total = 0;
- LIST_FOR_EACH_SAFE( demosnap_t, snap, next, &cls.demo.snapshots, entry ) {
+ LIST_FOR_EACH_SAFE(demosnap_t, snap, next, &cls.demo.snapshots, entry) {
total += snap->msglen;
- Z_Free( snap );
+ Z_Free(snap);
}
- if( total )
- Com_DPrintf( "Freed %"PRIz" bytes of snaps\n", total );
+ if (total)
+ Com_DPrintf("Freed %"PRIz" bytes of snaps\n", total);
- memset( &cls.demo, 0, sizeof( cls.demo ) );
+ memset(&cls.demo, 0, sizeof(cls.demo));
- List_Init( &cls.demo.snapshots );
+ List_Init(&cls.demo.snapshots);
}
/*
@@ -1180,29 +1202,29 @@ void CL_CleanupDemos( void ) {
CL_DemoFrame
====================
*/
-void CL_DemoFrame( int msec ) {
- if( cls.state < ca_connected ) {
+void CL_DemoFrame(int msec)
+{
+ if (cls.state < ca_connected) {
return;
}
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
parse_next_message();
return;
}
- if( cls.demo.recording && cl_paused->integer == 2 &&
- !cls.demo.paused && cls.demo.frames_written )
- {
+ if (cls.demo.recording && cl_paused->integer == 2 &&
+ !cls.demo.paused && cls.demo.frames_written) {
// XXX: record zero frames when manually paused
// for syncing with audio comments, etc
demo_extra += msec;
- if( demo_extra > 100 ) {
+ if (demo_extra > 100) {
emit_zero_frame();
demo_extra = 0;
}
}
- if( com_timedemo->integer ) {
+ if (com_timedemo->integer) {
parse_next_message();
cl.time = cl.servertime;
cls.demo.time_frames++;
@@ -1211,9 +1233,9 @@ void CL_DemoFrame( int msec ) {
// cl.time has already been advanced for this client frame
// read the next frame to start lerp cycle again
- while( cl.servertime < cl.time ) {
+ while (cl.servertime < cl.time) {
parse_next_message();
- if( cls.state != ca_active ) {
+ if (cls.state != ca_active) {
break;
}
}
@@ -1234,12 +1256,13 @@ static const cmdreg_t c_demo[] = {
CL_InitDemos
====================
*/
-void CL_InitDemos( void ) {
- cl_demosnaps = Cvar_Get( "cl_demosnaps", "10", 0 );
- cl_demomsglen = Cvar_Get( "cl_demomsglen", va( "%d", MAX_PACKETLEN_WRITABLE_DEFAULT ), 0 );
+void CL_InitDemos(void)
+{
+ cl_demosnaps = Cvar_Get("cl_demosnaps", "10", 0);
+ cl_demomsglen = Cvar_Get("cl_demomsglen", va("%d", MAX_PACKETLEN_WRITABLE_DEFAULT), 0);
- Cmd_Register( c_demo );
- List_Init( &cls.demo.snapshots );
+ Cmd_Register(c_demo);
+ List_Init(&cls.demo.snapshots);
}