engine: common: netchan: only compress with BZip2 when it's efficient
This commit is contained in:
parent
9188905145
commit
6bdc1941e6
1 changed files with 12 additions and 8 deletions
|
@ -744,14 +744,18 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
|
|||
{
|
||||
#if !XASH_DEDICATED
|
||||
byte pbOut[0x10000];
|
||||
uint uSourceSize = MSG_GetNumBytesWritten( msg );
|
||||
uint uCompressedSize = MSG_GetNumBytesWritten( msg ) - 4;
|
||||
if( !BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), MSG_GetNumBytesWritten( msg ), 9, 0, 30 ))
|
||||
if( !BZ2_bzBuffToBuffCompress( pbOut, &uCompressedSize, MSG_GetData( msg ), uSourceSize, 9, 0, 30 ))
|
||||
{
|
||||
Con_Reportf( "Compressing split packet with BZip2 (%d -> %d bytes)\n", MSG_GetNumBytesWritten( msg ), uCompressedSize );
|
||||
if( uCompressedSize < uSourceSize )
|
||||
{
|
||||
Con_Reportf( "Compressing split packet with BZip2 (%d -> %d bytes)\n", uSourceSize, uCompressedSize );
|
||||
memcpy( msg->pData, "BZ2", 4 );
|
||||
memcpy( msg->pData + 4, pbOut, uCompressedSize );
|
||||
MSG_SeekToBit( msg, uCompressedSize << 3, SEEK_SET );
|
||||
}
|
||||
}
|
||||
#else
|
||||
Host_Error( "%s: BZ2 compression is not supported for server", __func__ );
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue