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,13 +744,17 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
|
||||||
{
|
{
|
||||||
#if !XASH_DEDICATED
|
#if !XASH_DEDICATED
|
||||||
byte pbOut[0x10000];
|
byte pbOut[0x10000];
|
||||||
|
uint uSourceSize = MSG_GetNumBytesWritten( msg );
|
||||||
uint uCompressedSize = MSG_GetNumBytesWritten( msg ) - 4;
|
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 )
|
||||||
memcpy( msg->pData, "BZ2", 4 );
|
{
|
||||||
memcpy( msg->pData + 4, pbOut, uCompressedSize );
|
Con_Reportf( "Compressing split packet with BZip2 (%d -> %d bytes)\n", uSourceSize, uCompressedSize );
|
||||||
MSG_SeekToBit( msg, uCompressedSize << 3, SEEK_SET );
|
memcpy( msg->pData, "BZ2", 4 );
|
||||||
|
memcpy( msg->pData + 4, pbOut, uCompressedSize );
|
||||||
|
MSG_SeekToBit( msg, uCompressedSize << 3, SEEK_SET );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Host_Error( "%s: BZ2 compression is not supported for server", __func__ );
|
Host_Error( "%s: BZ2 compression is not supported for server", __func__ );
|
||||||
|
@ -758,9 +762,9 @@ static void Netchan_CreateFragments_( netchan_t *chan, sizebuf_t *msg )
|
||||||
}
|
}
|
||||||
else if( !chan->use_bz2 && !LZSS_IsCompressed( MSG_GetData( msg )))
|
else if( !chan->use_bz2 && !LZSS_IsCompressed( MSG_GetData( msg )))
|
||||||
{
|
{
|
||||||
uint uCompressedSize = 0;
|
uint uCompressedSize = 0;
|
||||||
uint uSourceSize = MSG_GetNumBytesWritten( msg );
|
uint uSourceSize = MSG_GetNumBytesWritten( msg );
|
||||||
byte *pbOut = LZSS_Compress( msg->pData, uSourceSize, &uCompressedSize );
|
byte *pbOut = LZSS_Compress( msg->pData, uSourceSize, &uCompressedSize );
|
||||||
|
|
||||||
if( pbOut && uCompressedSize > 0 && uCompressedSize < uSourceSize )
|
if( pbOut && uCompressedSize > 0 && uCompressedSize < uSourceSize )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue