From 38c82a3f7632a746ce704131abc17fa6f7f6e5f1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 14 Jan 2025 11:55:28 +0300 Subject: [PATCH] engine: don't bother calculating crc32 for local clients for better performance (thanks @tyabus for the idea) --- engine/client/cl_main.c | 2 +- engine/server/sv_client.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 83ceb6bc..8253b92b 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -825,7 +825,7 @@ static void CL_WritePacket( void ) buf.pData[key] = CRC32_BlockSequence( &buf.pData[key + 1], size, cls.netchan.outgoing_sequence ); COM_Munge( &buf.pData[key + 1], Q_min( size, 255 ), cls.netchan.outgoing_sequence ); } - else + else if( !Host_IsLocalClient( )) { int size = MSG_GetRealBytesWritten( &buf ) - key - 1; buf.pData[key] = CRC32_BlockSequence( &buf.pData[key + 1], size, cls.netchan.outgoing_sequence ); diff --git a/engine/server/sv_client.c b/engine/server/sv_client.c index 09e8acd1..b3cc22be 100644 --- a/engine/server/sv_client.c +++ b/engine/server/sv_client.c @@ -3227,7 +3227,7 @@ each of the backup packets. static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg ) { client_frame_t *frame; - int key, size, checksum1, checksum2; + int key, checksum1; int i, numbackup, totalcmds, numcmds; usercmd_t nullcmd, *to, *from; usercmd_t cmds[CMD_BACKUP]; @@ -3270,14 +3270,17 @@ static void SV_ParseClientMove( sv_client_t *cl, sizebuf_t *msg ) if( cl->state != cs_spawned ) return; - // if the checksum fails, ignore the rest of the packet - size = MSG_GetRealBytesRead( msg ) - key - 1; - checksum2 = CRC32_BlockSequence( msg->pData + key + 1, size, cl->netchan.incoming_sequence ); - - if( checksum2 != checksum1 ) + if( !Host_IsLocalClient( )) { - Con_Reportf( S_ERROR "%s: failed command checksum for %s (%d != %d)\n", __func__, cl->name, checksum2, checksum1 ); - return; + // if the checksum fails, ignore the rest of the packet + int size = MSG_GetRealBytesRead( msg ) - key - 1; + int checksum2 = CRC32_BlockSequence( msg->pData + key + 1, size, cl->netchan.incoming_sequence ); + + if( checksum2 != checksum1 ) + { + Con_Reportf( S_ERROR "%s: failed command checksum for %s (%d != %d)\n", __func__, cl->name, checksum2, checksum1 ); + return; + } } cl->packet_loss = packet_loss;